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
["8\n6\n25"]
639eeeabcb005152035a1fcf09ed3b44
null
You are given a string $$$s$$$ consisting of the characters 0, 1, and ?.Let's call a string unstable if it consists of the characters 0 and 1 and any two adjacent characters are different (i.Β e. it has the form 010101... or 101010...).Let's call a string beautiful if it consists of the characters 0, 1, and ?, and you c...
For each test case, output a single integerΒ β€” the number of beautiful substrings of the string $$$s$$$.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” number of test cases. The first and only line of each test case contains the string $$$s$$$ ($$$1 \le |s| \le 2 \cdot 10^5$$$) consisting of characters 0, 1, and ?. It is guaranteed that the sum of the string lengths over all test cases does no...
standard output
standard input
Python 3
Python
1,400
train_085.jsonl
55574ab9369e8555c146282807e5d35b
256 megabytes
["3\n0?10\n???\n?10??1100"]
PASSED
''' Author: your name Date: 2021-12-10 14:18:39 LastEditTime: 2021-12-27 21:12:35 LastEditors: Please set LastEditors Description: In User Settings Edit FilePath: /code_everyWeek/week3.py ''' def unstable_string(input_str): if len(input_str) == 1: return 1 i = 0 j = 1 res = 0 lastj = 0 ...
1622817300
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["1 10", "2333333 2333333333333"]
52b8d97f216ea22693bc16fadcd46dae
null
Little X has met the following problem recently. Let's define f(x) as the sum of digits in decimal representation of number x (for example, f(1234) = 1 + 2 + 3 + 4). You are to calculate Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the following C++ c...
Print two integers: l, rΒ (1 ≀ l ≀ r < 10200) β€” the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists.
The first line contains a single integer aΒ (1 ≀ a ≀ 1018).
standard output
standard input
Python 3
Python
2,500
train_024.jsonl
db8e385bb243dfd901f89b9483be9204
256 megabytes
["46", "126444381000032"]
PASSED
a=int(input()) d=10**100-1; x=a-100*45*10**99%a print(x,x+d)
1411218000
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["16", "1", "10", "1"]
d666df06a7a7ecbe801c1018b3d482b9
NoteSome strings you can obtain in the first example: to obtain 0110110, you can take the substring from the $$$1$$$-st character to the $$$4$$$-th character, which is 1100, and reorder its characters to get 0110; to obtain 1111000, you can take the substring from the $$$3$$$-rd character to the $$$7$$$-th character,...
You are given a binary string (i. e. a string consisting of characters 0 and/or 1) $$$s$$$ of length $$$n$$$. You can perform the following operation with the string $$$s$$$ at most once: choose a substring (a contiguous subsequence) of $$$s$$$ having exactly $$$k$$$ characters 1 in it, and shuffle it (reorder the char...
Print one integer β€” the number of different strings which can be obtained from $$$s$$$ by performing the described operation at most once. Since the answer can be large, output it modulo $$$998244353$$$.
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 5000$$$; $$$0 \le k \le n$$$). The second line contains the string $$$s$$$ of length $$$n$$$, consisting of characters 0 and/or 1.
standard output
standard input
PyPy 3-64
Python
2,000
train_085.jsonl
9f6e5587e9aec288e916e1128ec1332c
512 megabytes
["7 2\n1100110", "5 0\n10010", "8 1\n10001000", "10 8\n0010011000"]
PASSED
import os,sys from io import BytesIO, IOBase from collections import defaultdict,deque,Counter from bisect import bisect_left,bisect_right from heapq import heappush,heappop from functools import lru_cache from itertools import accumulate import math from tkinter import N # Fast IO Region BUFSIZE = 8192 ...
1640615700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
db4a25159067abd9e3dd22bc4b773385
null
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1...
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates d...
standard output
standard input
Python 3
Python
900
train_012.jsonl
273a886296b7dce8d072b5688db9d8a9
256 megabytes
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
PASSED
inn = list(map(int, input().split(" "))) pnts = inn[0] mult = inn[1] dist = 0 c = list(map(int, input().split(" "))) for i in range(1,pnts): s = list(map(int, input().split(" "))) x1 = c[0] x2 = s[0] y1 = c[1] y2 = s[1] dist += ((((x2 - x1) ** 2) + ((y2 - y1) ** 2)) ** 0.5) c = s tt = (dist/...
1320858000
[ "geometry" ]
[ 0, 1, 0, 0, 0, 0, 0, 0 ]
1 second
["a\nz\n\nbc"]
586a15030f4830c68f2ea1446e80028c
null
Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains $$$26$$$ buttons (one for each letter of the Latin alphabet). Each button is either working fine or malfunctioning. To check which buttons need replacement, Polycarp pressed...
For each test case, print one line containing a string $$$res$$$. The string $$$res$$$ should contain all characters which correspond to buttons that work correctly in alphabetical order, without any separators or repetitions. If all buttons may malfunction, $$$res$$$ should be empty.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases in the input. Then the test cases follow. Each test case is represented by one line containing a string $$$s$$$ consisting of no less than $$$1$$$ and no more than $$$500$$$ lowercase Latin letters.
standard output
standard input
Python 3
Python
1,000
train_000.jsonl
742d9aea83f22f45def1b3e7dff87a55
256 megabytes
["4\na\nzzaaz\nccff\ncbddbb"]
PASSED
t = int(input()) for tt in range(t): s=input() l=set() #l.append(s[0]) n=len(s) if n==1: print(s,end="") else: left = 0 right = 1 while left<n and right<n: if s[left]==s[right]: left+=2 right+=2 else: ...
1571929500
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["160", "645"]
f9c53d180868776b6a2ee3f57c3b3a21
NotePossible partitions in the first sample: {{1, 2, 3}, {4}}, W(R) = 3Β·(w1 + w2 + w3) + 1Β·w4 = 24; {{1, 2, 4}, {3}}, W(R) = 26; {{1, 3, 4}, {2}}, W(R) = 24; {{1, 2}, {3, 4}}, W(R) = 2Β·(w1 + w2) + 2Β·(w3 + w4) = 20; {{1, 3}, {2, 4}}, W(R) = 20; {{1, 4}, {2, 3}}, W(R) = 20; {{1}, {2, 3, 4}}, W(R) = 26; Possible pa...
You are given a set of n elements indexed from 1 to n. The weight of i-th element is wi. The weight of some subset of a given set is denoted as . The weight of some partition R of a given set into k subsets is (recall that a partition of a given set is a set of its subsets such that every element of the given set belo...
Print one integer β€” the sum of weights of all partitions of a given set into k non-empty subsets, taken modulo 109 + 7.
The first line contains two integers n and k (1 ≀ k ≀ n ≀ 2Β·105) β€” the number of elements and the number of subsets in each partition, respectively. The second line contains n integers wi (1 ≀ wi ≀ 109)β€” weights of elements of the set.
standard output
standard input
PyPy 3
Python
2,700
train_024.jsonl
a3d24fe5ccf6a3bfc6cd9d4da3d32767
256 megabytes
["4 2\n2 3 2 3", "5 2\n1 2 3 4 5"]
PASSED
n, k = map(int, input().split()) MOD = 10**9+7 def fast_modinv(up_to, M): ''' Fast modular inverses of 1..up_to modulo M. ''' modinv = [-1 for _ in range(up_to + 1)] modinv[1] = 1 for x in range(2, up_to + 1): modinv[x] = (-(M//x) * modinv[M%x])%M return modinv maxn = 2*10**5 + 10 modi...
1522850700
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
2 seconds
["&gt; 25\n\n&gt; 15\n\n? 1\n\n? 2\n\n? 3\n\n? 4\n\n! 9 5"]
36619f520ea5a523a94347ffd3dc2c70
NoteNote that the example interaction contains extra empty lines so that it's easier to read. The real interaction doesn't contain any empty lines and you shouldn't print any extra empty lines as well.The list in the example test is $$$[14, 24, 9, 19]$$$.
This is an interactive problem!An arithmetic progression or arithmetic sequence is a sequence of integers such that the subtraction of element with its previous element ($$$x_i - x_{i - 1}$$$, where $$$i \ge 2$$$) is constantΒ β€” such difference is called a common difference of the sequence.That is, an arithmetic progres...
null
null
standard output
standard input
PyPy 2
Python
2,200
train_013.jsonl
4023ddebd43f29b8818cc4f2e948b70f
256 megabytes
["4\n\n0\n\n1\n\n14\n\n24\n\n9\n\n19"]
PASSED
from __future__ import division from random import sample from sys import stdin, stdout from fractions import gcd def write(x): stdout.write(str(x) + "\n") stdout.flush() def get(): rec = stdin.readline() if "-1" in rec: [][0] return rec n = int(get()) queries = 0 low = 0 high = 10 **...
1549807500
[ "number theory", "probabilities" ]
[ 0, 0, 0, 0, 1, 1, 0, 0 ]
2 seconds
["1", "4", "0"]
0d95c84e73aa9b6567eadeb16acfda41
NoteHere is the tree from the first example: The only nice edge is edge $$$(2, 4)$$$. Removing it makes the tree fall apart into components $$$\{4\}$$$ and $$$\{1, 2, 3, 5\}$$$. The first component only includes a red vertex and the second component includes blue vertices and uncolored vertices.Here is the tree from t...
You are given an undirected tree of $$$n$$$ vertices. Some vertices are colored blue, some are colored red and some are uncolored. It is guaranteed that the tree contains at least one red vertex and at least one blue vertex.You choose an edge and remove it from the tree. Tree falls apart into two connected components. ...
Print a single integer β€” the number of nice edges in the given tree.
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 3 \cdot 10^5$$$) β€” the number of vertices in the tree. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 2$$$) β€” the colors of the vertices. $$$a_i = 1$$$ means that vertex $$$i$$$ is colored red, $$$a_i = 2$$$ means t...
standard output
standard input
PyPy 2
Python
1,800
train_008.jsonl
9ac6fd4edc3bd0b8f1970ba0d3d6cb25
256 megabytes
["5\n2 0 0 1 2\n1 2\n2 3\n2 4\n2 5", "5\n1 0 0 0 2\n1 2\n2 3\n3 4\n4 5", "3\n1 1 2\n2 3\n1 3"]
PASSED
#!/usr/bin/env python2 """ This file is part of https://github.com/cheran-senthil/PyRival Copyright 2019 Cheran Senthilkumar <hello@cheran.io> """ from __future__ import division, print_function import itertools import os import sys from atexit import register from io import BytesIO range = xrange filter = itertool...
1550586900
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
1 second
["Vivek\nAshish\nVivek\nAshish"]
3ccc98190189b0c8e58a96dd5ad1245d
NoteFor the first case: One possible scenario could be: Ashish claims cell $$$(1, 1)$$$, Vivek then claims cell $$$(2, 2)$$$. Ashish can neither claim cell $$$(1, 2)$$$, nor cell $$$(2, 1)$$$ as cells $$$(1, 1)$$$ and $$$(2, 2)$$$ are already claimed. Thus Ashish loses. It can be shown that no matter what Ashish plays ...
Ashish and Vivek play a game on a matrix consisting of $$$n$$$ rows and $$$m$$$ columns, where they take turns claiming cells. Unclaimed cells are represented by $$$0$$$, while claimed cells are represented by $$$1$$$. The initial state of the matrix is given. There can be some claimed cells in the initial state.In eac...
For each test case if Ashish wins the game print "Ashish" otherwise print "Vivek" (without quotes).
The first line consists of a single integer $$$t$$$ $$$(1 \le t \le 50)$$$Β β€” the number of test cases. The description of the test cases follows. The first line of each test case consists of two space-separated integers $$$n$$$, $$$m$$$ $$$(1 \le n, m \le 50)$$$Β β€” the number of rows and columns in the matrix. The follo...
standard output
standard input
PyPy 3
Python
1,100
train_004.jsonl
348d406e087873dab5e55ffc0182bc74
256 megabytes
["4\n2 2\n0 0\n0 0\n2 2\n0 0\n0 1\n2 3\n1 0 1\n1 1 0\n3 3\n1 0 0\n0 0 0\n1 0 0"]
PASSED
for _ in range(int(input())): n,m=map(int,input().split()) mat=[] r=[0]*n for i in range(n): a=list(map(int,input().split())) if 1 in a: r[i]=1 mat.append(a) #print(mat[0][1]) c=[0]*m for i in range(m): for j in range(n): if mat[j][i]==...
1591540500
[ "games" ]
[ 1, 0, 0, 0, 0, 0, 0, 0 ]
2 seconds
["0 6 2 \n-1 -1 \n1 3"]
ecc9dc229b5d1f93809fb676eb6235c1
null
Polycarp was dismantling his attic and found an old floppy drive on it. A round disc was inserted into the drive with $$$n$$$ integers written on it.Polycarp wrote the numbers from the disk into the $$$a$$$ array. It turned out that the drive works according to the following algorithm: the drive takes one positive nu...
Print $$$m$$$ numbers on a separate line for each test case. The $$$i$$$-th number is: $$$-1$$$ if the drive will run infinitely; the number of seconds the drive will run, otherwise.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case consists of two positive integers $$$n$$$, $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$)Β β€” the number of numbers on the disk and the number of asked questions. ...
standard output
standard input
Python 3
Python
1,900
train_098.jsonl
2769e44e1d60ad2f696f8bd7de190062
256 megabytes
["3\n3 3\n1 -3 4\n1 5 2\n2 2\n-2 0\n1 2\n2 2\n0 1\n1 2"]
PASSED
import sys from bisect import bisect_left from itertools import accumulate def solve(n, m, a, x): p = list(accumulate(a)) s = p[-1] for i in range(1, n): p[i] = max(p[i], p[i-1]) ans = list() for i in range(m): if s <= 0 and x[i] > p[-1]: ans.append(-1...
1613486100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
4 seconds
["3", "1", "0"]
d5913f8208efa1641f53caaee7624622
NoteNote to the first sample test. There are 3 triangles formed: (0, 0) - (1, 1) - (2, 0); (0, 0) - (2, 2) - (2, 0); (1, 1) - (2, 2) - (2, 0).Note to the second sample test. There is 1 triangle formed: (0, 0) - (1, 1) - (2, 0).Note to the third sample test. A single point doesn't form a single triangle.
Vanya got bored and he painted n distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area.
In the first line print an integer β€” the number of triangles with the non-zero area among the painted points.
The first line contains integer n (1 ≀ n ≀ 2000) β€” the number of the points painted on the plane. Next n lines contain two integers each xi, yi ( - 100 ≀ xi, yi ≀ 100) β€” the coordinates of the i-th point. It is guaranteed that no two given points coincide.
standard output
standard input
PyPy 2
Python
1,900
train_015.jsonl
0533264df55564b9a5e65f767480df63
512 megabytes
["4\n0 0\n1 1\n2 0\n2 2", "3\n0 0\n1 1\n2 0", "1\n1 1"]
PASSED
from fractions import gcd N = input() points = [map(int, raw_input().split()) for _ in xrange(N)] ans = N * (N-1) * (N-2) // 6 lines = {} for i in xrange(N-1): for j in range(i+1, N): x1, y1 = points[i] x2, y2 = points[j] g = gcd(x1-x2, y1-y2) dx, dy = (x1-x2)//g, (y1-y2)//g ...
1434645000
[ "geometry", "math" ]
[ 0, 1, 0, 1, 0, 0, 0, 0 ]
2 seconds
["a\nabcdfdcba\nxyzyx\nc\nabba"]
042008e186c5a7265fbe382b0bdfc9bc
NoteIn the first test, the string $$$s = $$$"a" satisfies all conditions.In the second test, the string "abcdfdcba" satisfies all conditions, because: Its length is $$$9$$$, which does not exceed the length of the string $$$s$$$, which equals $$$11$$$. It is a palindrome. "abcdfdcba" $$$=$$$ "abcdfdc" $$$+$$$ "ba", ...
This is the easy version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.You are given a string $$$s$$$, consisting of lowercase English letters. Find the longest string, $$$t$$$, which satisfi...
For each test case, print the longest string which satisfies the conditions described above. If there exists multiple possible solutions, print any of them.
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$), the number of test cases. The next $$$t$$$ lines each describe a test case. Each test case is a non-empty string $$$s$$$, consisting of lowercase English letters. It is guaranteed that the sum of leng...
standard output
standard input
PyPy 3
Python
1,500
train_005.jsonl
13d6438ca59a651779ff99f96e465480
256 megabytes
["5\na\nabcdfdcecba\nabbaxyzyx\ncodeforces\nacbba"]
PASSED
import sys, heapq as h input = sys.stdin.readline def getInts(): return [int(s) for s in input().split()] def getInt(): return int(input()) def getStrs(): return [s for s in input().split()] def getStr(): return input().strip() def listStr(): return list(input().strip()) import collections as ...
1584628500
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
3 seconds
["1 2 2 4", "2 1 4 3 1", "3 4 2 7 7 3"]
4de02364b27e697b5750f0bd88fac821
null
You are given a weighted undirected connected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. It is guaranteed that there are no self-loops or multiple edges in the given graph.Let's define the weight of the path consisting of $$$k$$$ edges with indices $$$e_1, e_2, \dots, e_k$$$ as $$$\sum\limits_{i=1}^{k}{w_{...
Print $$$n-1$$$ integers β€” the minimum weight of the path from $$$1$$$-st vertex to the $$$i$$$-th vertex for each $$$i$$$ ($$$2 \le i \le n$$$).
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 2 \cdot 10^5$$$; $$$1 \le m \le 2 \cdot 10^5$$$) β€” the number of vertices and the number of edges in the graph. Following $$$m$$$ lines contains three integers $$$v_i, u_i, w_i$$$ ($$$1 \le v_i, u_i \le n$$$; $$$1 \le w_i \le 10^9$$$; $$$v_i \neq ...
standard output
standard input
PyPy 3
Python
2,400
train_106.jsonl
a254bf34f9b6d4214757bd9b4c73e7d3
256 megabytes
["5 4\n5 3 4\n2 1 1\n3 2 2\n2 4 2", "6 8\n3 1 1\n3 6 2\n5 4 2\n4 2 2\n6 1 1\n5 2 1\n3 2 3\n1 5 4", "7 10\n7 5 5\n2 3 3\n4 7 1\n5 3 6\n2 7 6\n6 2 6\n3 7 6\n4 2 1\n3 1 4\n1 7 4"]
PASSED
import io import os # import __pypy__ def dijkstra(*args): # return dijkstraHeap(*args) # 2979 ms return dijkstraHeapComparatorWrong(*args) # 2823 ms # return dijkstraHeapComparator(*args) # 2370 ms # return dijkstraSegTree(*args) # 2417 ms with inf=float('inf), 2995 ms with inf=-1 # return d...
1610634900
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["5 3 1 2 4", "7 3 2 1 4 5 6", "7 4 2 3 6 5 1", "2 1 4 5 3"]
bef323e7c8651cc78c49db38e49ba53d
null
There are $$$n$$$ friends who want to give gifts for the New Year to each other. Each friend should give exactly one gift and receive exactly one gift. The friend cannot give the gift to himself.For each friend the value $$$f_i$$$ is known: it is either $$$f_i = 0$$$ if the $$$i$$$-th friend doesn't know whom he wants ...
Print $$$n$$$ integers $$$nf_1, nf_2, \dots, nf_n$$$, where $$$nf_i$$$ should be equal to $$$f_i$$$ if $$$f_i \ne 0$$$ or the number of friend whom the $$$i$$$-th friend wants to give the gift to. All values $$$nf_i$$$ should be distinct, $$$nf_i$$$ cannot be equal to $$$i$$$. Each friend gives exactly one gift and rec...
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) β€” the number of friends. The second line of the input contains $$$n$$$ integers $$$f_1, f_2, \dots, f_n$$$ ($$$0 \le f_i \le n$$$, $$$f_i \ne i$$$, all $$$f_i \ne 0$$$ are distinct), where $$$f_i$$$ is the either $$$f_i = 0$$$ if ...
standard output
standard input
Python 2
Python
1,500
train_005.jsonl
db0bff0f1fc2d9a07f73a948b77a9625
256 megabytes
["5\n5 0 0 2 4", "7\n7 0 0 1 4 0 6", "7\n7 4 0 3 0 5 1", "5\n2 1 0 0 0"]
PASSED
# -*- coding: utf-8 -*- import sys def read_int_list(): return map(int, sys.stdin.readline().strip().split()) def read_int(): return int(sys.stdin.readline().strip()) def solve(): _ = read_int() friends = read_int_list() with_present = set() unknown = set() for idx, f in enumerate(frien...
1577552700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["-1\n330\n-1\n40"]
c01a5ed6a598a1c443611a8f1b1a3db7
NoteAll the subsets of multiset $$$\{20, 300, 10001\}$$$ are balanced, thus the answer is -1.The possible unbalanced subsets in the third query are $$$\{20, 310\}$$$ and $$$\{20, 310, 10001\}$$$. The lowest sum one is $$$\{20, 310\}$$$. Note that you are asked to choose a subset, not a subsegment, thus the chosen eleme...
Let's define a balanced multiset the following way. Write down the sum of all elements of the multiset in its decimal representation. For each position of that number check if the multiset includes at least one element such that the digit of the element and the digit of the sum at that position are the same. If that ho...
For each query of the second type print the lowest sum of the unbalanced subset. Print -1 if no unbalanced subset exists.
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$) β€” the number of elements in the array and the number of queries, respectively. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i &lt; 10^9$$$). Each of the following $$$m$$$ lines contains a que...
standard output
standard input
PyPy 2
Python
2,300
train_045.jsonl
293f8cd68d6c41736e45fbbad469cf4d
256 megabytes
["4 5\n300 10001 20 20\n2 1 3\n1 1 310\n2 1 3\n2 3 3\n2 3 4"]
PASSED
class segtree: def __init__(s, data): s.n = len(data) s.m = 1 while s.m < s.n: s.m *= 2 s.data = [0]*(2*s.m) s.data[s.m : s.m + s.n] = data for i in reversed(range(1, s.m)): s.data[i] = min(s.data[2*i], s.data[2*i + 1]) def set(s,i,val): i ...
1567694100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["First\nSecond\nSecond\nFirst"]
5f5b320c7f314bd06c0d2a9eb311de6c
NoteIn the first sample, the first player should go to (11,10). Then, after a single move of the second player to (1,10), he will take 10 modulo 1 and win.In the second sample the first player has two moves to (1,10) and (21,10). After both moves the second player can win.In the third sample, the first player has no mo...
In some country live wizards. They love playing with numbers. The blackboard has two numbers written on it β€” a and b. The order of the numbers is not important. Let's consider a ≀ b for the sake of definiteness. The players can cast one of the two spells in turns: Replace b with b - ak. Number k can be chosen by the p...
For any of the t input sets print "First" (without the quotes) if the player who moves first wins. Print "Second" (without the quotes) if the player who moves second wins. Print the answers to different data sets on different lines in the order in which they are given in the input.
The first line contains a single integer t β€” the number of input data sets (1 ≀ t ≀ 104). Each of the next t lines contains two integers a, b (0 ≀ a, b ≀ 1018). The numbers are separated by a space. Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout str...
standard output
standard input
Python 2
Python
2,300
train_029.jsonl
7fdb0cb83d1f664f866c7230fe3ddb25
256 megabytes
["4\n10 21\n31 10\n0 1\n10 30"]
PASSED
import sys from math import * def win(a,b): if (a==0): return False if (b==0): return False if (not win(b%a,a)): return True ans=b//a ans%=a+1 ans%=2 if (ans%2==1): return False else: return True try: fi = open("input.txt", "r") fo = open...
1332860400
[ "math", "games" ]
[ 1, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["Yes\n2 1\n1 3 \n2 \nYes\n1 2\n2 \n1 3 \nNo\nNo"]
f91197e474bdc3f2b881d556a330e36b
NoteIn the first test case, we can select the first and the third resident as a jury. Both of them are not acquaintances with a second cat, so we can select it as a contestant.In the second test case, we can select the second resident as a jury. He is not an acquaintances with a first and a third cat, so they can be se...
In the Catowice city next weekend the cat contest will be held. However, the jury members and the contestants haven't been selected yet. There are $$$n$$$ residents and $$$n$$$ cats in the Catowice, and each resident has exactly one cat living in his house. The residents and cats are numbered with integers from $$$1$$$...
For every test case print: "No", if it's impossible to select the jury and contestants. Otherwise print "Yes".In the second line print two integers $$$j$$$ and $$$p$$$ ($$$1 \le j$$$, $$$1 \le p$$$, $$$j + p = n$$$)Β β€” the number of jury members and the number of contest participants.In the third line print $$$j$$$ d...
The first line contains an integer $$$t$$$ ($$$1 \le t \le 100\,000$$$), the number of test cases. Then description of $$$t$$$ test cases follow, where each description is as follows: The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le m \le 10^6$$$), the number of Catowice residents and the number of ...
standard output
standard input
PyPy 2
Python
2,400
train_054.jsonl
2d74438d128084b4838c6352e62d534f
512 megabytes
["4\n3 4\n1 1\n2 2\n3 3\n1 3\n\n3 7\n1 1\n1 2\n1 3\n2 2\n3 1\n3 2\n3 3\n\n1 1\n1 1\n\n2 4\n1 1\n1 2\n2 1\n2 2"]
PASSED
import os import sys from atexit import register from io import BytesIO sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size)) sys.stdout = BytesIO() register(lambda: os.write(1, sys.stdout.getvalue())) input = lambda: sys.stdin.readline().rstrip('\r\n') def add(dic,k,v): if not dic.has_key(k): dic[k] = v ...
1571562300
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["Yes\nNo"]
287505698b6c850a768ee35d2e37753e
NoteYou can pay the donation to the first university with two coins: one of denomination 2 and one of denomination 3 berubleys. The donation to the second university cannot be paid.
Alexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the diversity β€” he has not yet decided what profession he wants to get. At school, he had bad grades in all subjects, and it's only thanks to w...
For each query print on a single line: either "Yes", if Alexey can enter the university, or "No" otherwise.
The first line contains the number of universities t, (1 ≀ t ≀ 1000) Each of the next t lines contain three space-separated integers: ni, li, ri (1 ≀ ni, li, ri ≀ 109;Β li ≀ ri).
standard output
standard input
PyPy 3
Python
null
train_035.jsonl
3088a8da3a98213f12798655cc3e9997
256 megabytes
["2\n5 2 3\n6 4 5"]
PASSED
def possible(numbers): if int(numbers[0])//int(numbers[1])!=0 and int(numbers[0])%int(numbers[1])//(int(numbers[0])//int(numbers[1]))<=int(numbers[2])-int(numbers[1]) and int(numbers[0])%int(numbers[1])%int(numbers[0])//int(numbers[1])+int(numbers[0])%int(numbers[1])%(int(numbers[0])//int(numbers[1]))<=(int(num...
1393428600
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["3\n1 2\n1 3\n3 2", "3\n1 3\n1 4\n2 3", "-1"]
73668a75036dce819ff27c316de378af
null
Valera had an undirected connected graph without self-loops and multiple edges consisting of n vertices. The graph had an interesting property: there were at most k edges adjacent to each of its vertices. For convenience, we will assume that the graph vertices were indexed by integers from 1 to n.One day Valera counted...
If Valera made a mistake in his notes and the required graph doesn't exist, print in the first line number -1. Otherwise, in the first line print integer m (0 ≀ m ≀ 106) β€” the number of edges in the found graph. In each of the next m lines print two space-separated integers ai and bi (1 ≀ ai, bi ≀ n;Β ai ≠ bi), denoting...
The first line contains two space-separated integers n and k (1 ≀ k &lt; n ≀ 105). Number n shows the number of vertices in the original graph. Number k shows that at most k edges were adjacent to each vertex in the original graph. The second line contains space-separated integers d[1], d[2], ..., d[n] (0 ≀ d[i] &lt; n...
standard output
standard input
Python 2
Python
1,800
train_007.jsonl
a50486b8dd4e04bf6e00d2a7d9529bfc
256 megabytes
["3 2\n0 1 1", "4 2\n2 0 1 3", "3 1\n0 0 0"]
PASSED
n, k = map(int, raw_input().split()) numbers = map(int, raw_input().split()) indices = range(1, len(numbers) + 1) pairs = zip(numbers, indices) pairs = sorted(pairs) edges = [] valid = True if pairs[0][0] != 0: valid = False else: parent = 0 remaining_edges = k for i in range(1, len(pairs)): ...
1395243000
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["3", "1\n2", "-1\n-1\n-1"]
0c2550b2df0849a62969edf5b73e0ac5
Note12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands.8 = 4 + 4, 6 can't be split into several composite summands.1, 2, 3 are less than any composite number, so they do not have valid splittings.
You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings.An integer greater than 1 is composite, if it is not prime, i.e. if i...
For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings.
The first line contains single integer q (1 ≀ q ≀ 105)Β β€” the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≀ ni ≀ 109)Β β€” the i-th query.
standard output
standard input
Python 3
Python
1,300
train_001.jsonl
6880fca2fa038169c64afba50294461a
256 megabytes
["1\n12", "2\n6\n8", "3\n1\n2\n3"]
PASSED
dp = [-1, -1, -1, 1, -1, 1, -1, 2, 1, 2, -1, 3, 2, 3, 2, 4, 3, 4, 3, 5, 4, 5, 4, 6, 5, 6, 5, 7, 6, 7, 6, 8, 7, 8, 7, 9, 8, 9, 8, 10, 9, 10, 9, 11, 10, 11, 10, 12, 11, 12, 11, 13, 12, 13, 12, 14, 13, 14, 13, 15, 14, 15, 14, 16, 15, 16, 15, 17, 16, 17, 16, 18, 17, 18, 17, 19, 18, 19, 18, 20, 19, 20, 19, 21, 20, 21, 20, 2...
1508054700
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["1\n3\n7"]
644b8f95b66b7e4cb39af552ec518b3f
NoteThe binary representations of numbers from 1 to 10 are listed below:110 = 12210 = 102310 = 112410 = 1002510 = 1012610 = 1102710 = 1112810 = 10002910 = 100121010 = 10102
Let's denote as the number of bits set ('1' bits) in the binary representation of the non-negative integer x.You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≀ x ≀ r, and is maximum possible. If there are multiple such numbers find the smallest of them.
For each query print the answer in a separate line.
The first line contains integer nΒ β€” the number of queries (1 ≀ n ≀ 10000). Each of the following n lines contain two integers li, riΒ β€” the arguments for the corresponding query (0 ≀ li ≀ ri ≀ 1018).
standard output
standard input
Python 2
Python
1,700
train_008.jsonl
7771eebb89c8ec80001d90e1da43c51e
256 megabytes
["3\n1 2\n2 4\n1 10"]
PASSED
import math import bisect dict = {} #print dir(bisect) List = [] def binary_search(l,r,a): mid = (l+r)/2 if(l==r): return mid+1 if r-l == 1 and List[r]<=a: return r+1 if r-l == 1 and List[r]>a: return l+1 if List[mid]==a: return mid+1 if List[mid]>a: retur...
1415205000
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["YES\nNO\nYES\nNO"]
21a1aada3570f42093c7ed4e06f0766d
NoteThis is the graph of sample: Weight of minimum spanning tree on this graph is 6.MST with edges (1, 3, 4, 6), contains all of edges from the first query, so answer on the first query is "YES".Edges from the second query form a cycle of length 3, so there is no spanning tree including these three edges. Thus, answer...
For a connected undirected weighted graph G, MST (minimum spanning tree) is a subgraph of G that contains all of G's vertices, is a tree, and sum of its edges is minimum possible.You are given a graph G. If you run a MST algorithm on graph it would give you only one MST and it causes other edges to become jealous. You ...
For each query you should print "YES" (without quotes) if there's a MST containing these edges and "NO" (of course without quotes again) otherwise.
The first line contains two integers n, m (2  ≀ n, m  ≀ 5Β·105, n - 1 ≀ m)Β β€” the number of vertices and edges in the graph and the number of queries. The i-th of the next m lines contains three integers ui, vi, wi (ui ≠ vi, 1 ≀ wi ≀ 5Β·105)Β β€” the endpoints and weight of the i-th edge. There can be more than one edges bet...
standard output
standard input
PyPy 2
Python
2,300
train_080.jsonl
5891d9cd989c3433ac7c3fea851489c9
256 megabytes
["5 7\n1 2 2\n1 3 2\n2 3 1\n2 4 1\n3 4 1\n3 5 2\n4 5 2\n4\n2 3 4\n3 3 4 5\n2 1 7\n2 1 2"]
PASSED
import sys, collections range = xrange input = raw_input class DisjointSetUnion0: def __init__(self, n): self.data = [-1] * n def __getitem__(self, a): acopy = a while self.data[a] >= 0: a = self.data[a] while acopy != a: self.data[acopy], acopy = a, sel...
1510929300
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["YES\nYES\nNO"]
b34f29e6fb586c22fa1b9e559c5a6c50
NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO".
For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got ...
For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise.
Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$)Β β€” number of cubes. The ...
standard output
standard input
Python 3
Python
900
train_012.jsonl
88967499f10d35b541afb94078133525
256 megabytes
["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"]
PASSED
t = int(input()) for i in range(t): n = int(input()) lst = list(map(int, input().split())) flag = 0 for i in range(n-1): if lst[i] <= lst[i + 1]: flag = 1 break if flag == 1: print("YES") else: print("NO")
1600958100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["block 192.168.0.1; #replica\nproxy 192.168.0.2; #main", "redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server"]
94501cd676a9214a59943b8ddd1dd31b
null
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has n servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of ...
Print m lines, the commands in the configuration file after Dustin did his task.
The first line of input contains two integers n and m (1 ≀ n, m ≀ 1000). The next n lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1 ≀ |name| ≀ 10, name only consists of English lowercase letters). It is guarant...
standard output
standard input
Python 2
Python
900
train_013.jsonl
1ba0694dd7087e2d6ff52d9982d7ffb3
256 megabytes
["2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;", "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;"]
PASSED
n,m = [int(x) for x in raw_input().split()] arr = {} for i in range(n): a,b = [x for x in raw_input().split()] b += ";" arr[b] = a for i in range(m): a,b = [x for x in raw_input().split()] c = "#" c += arr[b] print a,b,c
1517236500
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["0\n1\n2\n2 \n2 3"]
3b8969f7f2051d559a1e375ce8275c73
NoteLet's describe what happens in the third test case: $$$x_1 = 2$$$: we choose all positions that are not divisible by $$$2$$$ and replace them, i.Β e. bzyx $$$\rightarrow$$$ bzbx; $$$x_2 = 3$$$: we choose all positions that are not divisible by $$$3$$$ and replace them, i.Β e. bzbx $$$\rightarrow$$$ bbbb.
Theofanis has a string $$$s_1 s_2 \dots s_n$$$ and a character $$$c$$$. He wants to make all characters of the string equal to $$$c$$$ using the minimum number of operations.In one operation he can choose a number $$$x$$$ ($$$1 \le x \le n$$$) and for every position $$$i$$$, where $$$i$$$ is not divisible by $$$x$$$, r...
For each test case, firstly print one integer $$$m$$$Β β€” the minimum number of operations required to make all the characters equal to $$$c$$$. Next, print $$$m$$$ integers $$$x_1, x_2, \dots, x_m$$$ ($$$1 \le x_j \le n$$$)Β β€” the $$$x$$$-s that should be used in the order they are given. It can be proved that under give...
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of test cases. The first line of each test case contains the integer $$$n$$$ ($$$3 \le n \le 3 \cdot 10^5$$$) and a lowercase Latin letter $$$c$$$Β β€” the length of the string $$$s$$$ and the character the resulting string should consi...
standard output
standard input
PyPy 3-64
Python
1,200
train_097.jsonl
67ea6d074f1a575ae12073af843c865c
256 megabytes
["3\n4 a\naaaa\n4 a\nbaaa\n4 b\nbzyx"]
PASSED
t = int(input()) while t: n,c = input().split() s = str(input()) copy = str(c) copy*=(int(n)) if s == copy: print(0) else: n = int(n) f = False for i in range(1,n+1): if s[i-1] == str(c) and i*2 > n: f = True ...
1633705500
[ "math", "strings" ]
[ 0, 0, 0, 1, 0, 0, 1, 0 ]
2 seconds
["1", "9"]
422fda519243f084f82fac5488ee4faa
NoteIn the first test case, we can obtain $$$4$$$ bracket sequences by replacing all characters '?' with either '(' or ')': "((". Its depth is $$$0$$$; "))". Its depth is $$$0$$$; ")(". Its depth is $$$0$$$; "()". Its depth is $$$1$$$. So, the answer is $$$1 = 0 + 0 + 0 + 1$$$.In the second test case, we can obtain...
This is the hard version of this problem. The only difference is the limit of $$$n$$$ - the length of the input string. In this version, $$$1 \leq n \leq 10^6$$$.Let's define a correct bracket sequence and its depth as follow: An empty string is a correct bracket sequence with depth $$$0$$$. If "s" is a correct brack...
Print the answer modulo $$$998244353$$$ in a single line.
The only line contains a non-empty string consist of only '(', ')' and '?'. The length of the string is at most $$$10^6$$$.
standard output
standard input
PyPy 2
Python
2,900
train_043.jsonl
61a766ba24d96451eb38ef7ceb8634b6
256 megabytes
["??", "(?(?))"]
PASSED
import sys range = xrange input = raw_input import __pypy__ mulmod = __pypy__.intop.int_mulmod MOD = 998244353 half = pow(2, MOD - 2, MOD) S = input() n = len(S) A = [] for c in S: if c == '?': A.append(0) elif c == '(': A.append(1) else: A.append(2) big = 10**6 + 10 modinv = ...
1575556500
[ "probabilities" ]
[ 0, 0, 0, 0, 0, 1, 0, 0 ]
1 second
["5\n2\n3\n5\n1\n0\n3\n5\n2\n0"]
7374246c559fb7b507b0edeea6ed0c5d
NoteIn the first test case, the program can run $$$5$$$ times as follows: $$$\text{iloveslim} \to \text{ilovslim} \to \text{iloslim} \to \text{ilslim} \to \text{islim} \to \text{slim}$$$In the second test case, the program can run $$$2$$$ times as follows: $$$\text{joobeel} \to \text{oel} \to \text{el}$$$In the third t...
Hosssam decided to sneak into Hemose's room while he is sleeping and change his laptop's password. He already knows the password, which is a string $$$s$$$ of length $$$n$$$. He also knows that there are $$$k$$$ special letters of the alphabet: $$$c_1,c_2,\ldots, c_k$$$.Hosssam made a program that can do the following....
For each test case, print the maximum number of times Hosssam can run the program without displaying the error message, on a new line.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) β€” the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) β€” the initial length of the password. The next line contains a string $$$s$$$ consisting of $$...
standard output
standard input
PyPy 3-64
Python
1,100
train_100.jsonl
021e8104e716bb52211ca06d687161a6
256 megabytes
["10\n\n9\n\niloveslim\n\n1 s\n\n7\n\njoobeel\n\n2 o e\n\n7\n\nbasiozi\n\n2 s i\n\n6\n\nkhater\n\n1 r\n\n7\n\nabobeih\n\n6 a b e h i o\n\n5\n\nzondl\n\n5 a b c e f\n\n6\n\nshoman\n\n2 a h\n\n7\n\nshetwey\n\n2 h y\n\n5\n\nsamez\n\n1 m\n\n6\n\nmouraz\n\n1 m"]
PASSED
import sys t = int(sys.stdin.readline()) for _ in range(t): n = int(sys.stdin.readline()) s = sys.stdin.readline().strip().lower() a = sys.stdin.readline().strip().lower().split() k = int(a[0]) d = [0]*256 for i in range(1, k+1): d[ord(a[i])] = 1 parts = 0 maxlen...
1651847700
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["2\n4\n0\n0"]
f8a8bda80a75ed430465605deff249ca
NoteIn the first test case of the example, we can choose the segment $$$[5;7]$$$ as the answer. It is the shortest segment that has at least one common point with all given segments.
Your math teacher gave you the following problem:There are $$$n$$$ segments on the $$$x$$$-axis, $$$[l_1; r_1], [l_2; r_2], \ldots, [l_n; r_n]$$$. The segment $$$[l; r]$$$ includes the bounds, i.e. it is a set of such $$$x$$$ that $$$l \le x \le r$$$. The length of the segment $$$[l; r]$$$ is equal to $$$r - l$$$.Two s...
For each test case, output one integerΒ β€” the smallest possible length of the segment which has at least one common point with all given segments.
The first line contains integer number $$$t$$$ ($$$1 \le t \le 100$$$)Β β€” the number of test cases in the input. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 10^{5}$$$)Β β€” the number of segments. The following $$$n$$$ lines contain segment descriptions: the...
standard output
standard input
Python 3
Python
1,100
train_001.jsonl
569a676a8f1da2804903df120f97ed87
256 megabytes
["4\n3\n4 5\n5 9\n7 7\n5\n11 19\n4 17\n16 16\n3 12\n14 17\n1\n1 10\n1\n1 1"]
PASSED
t = int(input()) aa = [] bb = [] for i in range(t): n = int(input()) max = 0 min = 10**10 for j in range(n): d = list(map(int, input().split(' '))) if d[1] < min: min = d[1] if d[0] > max: max = d[0] print(max-min if max-min >= 0 else 0)
1574582700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["4\n2\n-2\n-4", "-6\n3\n-1\n2\n2"]
6059cfa13594d47b3e145d7c26f1b0b3
NoteThe first example is explained in the legend.In the second example, we can round the first and fifth numbers up, and the second and third numbers down. We can round the fourth number neither up, nor down.
Vus the Cossack has $$$n$$$ real numbers $$$a_i$$$. It is known that the sum of all numbers is equal to $$$0$$$. He wants to choose a sequence $$$b$$$ the size of which is $$$n$$$ such that the sum of all numbers is $$$0$$$ and each $$$b_i$$$ is either $$$\lfloor a_i \rfloor$$$ or $$$\lceil a_i \rceil$$$. In other word...
In each of the next $$$n$$$ lines, print one integer $$$b_i$$$. For each $$$i$$$, $$$|a_i-b_i|&lt;1$$$ must be met. If there are multiple answers, print any.
The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$)Β β€” the number of numbers. Each of the next $$$n$$$ lines contains one real number $$$a_i$$$ ($$$|a_i| &lt; 10^5$$$). It is guaranteed that each $$$a_i$$$ has exactly $$$5$$$ digits after the decimal point. It is guaranteed that the sum of all the num...
standard output
standard input
PyPy 3
Python
1,500
train_014.jsonl
8d64211582a3c498f2d4a6e340d85d7c
256 megabytes
["4\n4.58413\n1.22491\n-2.10517\n-3.70387", "5\n-6.32509\n3.30066\n-0.93878\n2.00000\n1.96321"]
PASSED
n = int(input()) a = [input() for _ in range(n)] ans = [] ch = [False] * n cur = -1 for i in a: cur += 1 if '.' in i: curi = i.split('.') if curi[1].count("0") == len(curi[1]): ans.append(int(curi[0])) continue ch[cur] = True if curi[0][0] == '-': ...
1561710000
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
4 seconds
["1 3\n2 2 3\n0\n3 1 2 4\n1 2"]
ff84bc8e8e01c82e1ecaa2a39a7f8dc6
NoteGraph of Andarz Gu in the sample case is as follows (ID of people in each city are written next to them):
Recently Duff has been a soldier in the army. Malek is her commander.Their country, Andarz Gu has n cities (numbered from 1 to n) and n - 1 bidirectional roads. Each road connects two different cities. There exist a unique path between any two cities.There are also m people living in Andarz Gu (numbered from 1 to m). E...
For each query, print numbers k, p1, p2, ..., pk separated by spaces in one line.
The first line of input contains three integers, n, m and q (1 ≀ n, m, q ≀ 105). The next n - 1 lines contain the roads. Each line contains two integers v and u, endpoints of a road (1 ≀ v, u ≀ n, v ≠ u). Next line contains m integers c1, c2, ..., cm separated by spaces (1 ≀ ci ≀ n for each 1 ≀ i ≀ m). Next q lines con...
standard output
standard input
PyPy 2
Python
2,200
train_039.jsonl
10e269a3dc6c3dd54a658cb451fd2f09
512 megabytes
["5 4 5\n1 3\n1 2\n1 4\n4 5\n2 1 4 3\n4 5 6\n1 5 2\n5 5 10\n2 3 3\n5 3 1"]
PASSED
import sys range = xrange input = raw_input class Hld: def __init__(self, graph, data, f = min): root = 0 n = len(graph) + 1 self.data = data self.f = f bfs = [root] self.depth = [-1]*n self.depth[root] = 0 self.P = [-1]*n for node in...
1444926600
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
2 seconds
["6\n216"]
33e751f5716cbd666be36ab8f5e3977e
NoteIn the first example, all possible passwords are: "3377", "3737", "3773", "7337", "7373", "7733".
Monocarp has forgotten the password to his mobile phone. The password consists of $$$4$$$ digits from $$$0$$$ to $$$9$$$ (note that it can start with the digit $$$0$$$).Monocarp remembers that his password had exactly two different digits, and each of these digits appeared exactly two times in the password. Monocarp al...
For each testcase, print one integerΒ β€” the number of different $$$4$$$-digit sequences that meet the constraints.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 200$$$)Β β€” the number of testcases. The first line of each testcase contains a single integer $$$n$$$ ($$$1 \le n \le 8$$$)Β β€” the number of digits for which Monocarp remembers that they were not used in the password. The second line contains $$$n$$$ differ...
standard output
standard input
PyPy 3-64
Python
800
train_088.jsonl
4ffe899806a0a1d099398ac023fba041
256 megabytes
["2\n\n8\n\n0 1 2 4 5 6 8 9\n\n1\n\n8"]
PASSED
t = int(input()) for _ in range(t): n = int(input()) a = [int(x) for x in input().split()] alen = 10 - n ans = int(6 * alen * (alen-1) /2) print(ans)
1666017300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["aeren\nari\narousal\naround\nari\nmonogon\nmonogamy\nmonthly\nkevinvu\nkuroni\nkurioni\nkorone\nanton\nloves\nadhoc\nproblems"]
6983823efdc512f8759203460cd6bb4c
NoteIn the $$$1$$$-st test case one of the possible answers is $$$s = [aeren, ari, arousal, around, ari]$$$.Lengths of longest common prefixes are: Between $$$\color{red}{a}eren$$$ and $$$\color{red}{a}ri$$$ $$$\rightarrow 1$$$ Between $$$\color{red}{ar}i$$$ and $$$\color{red}{ar}ousal$$$ $$$\rightarrow 2$$$ Between...
The length of the longest common prefix of two strings $$$s = s_1 s_2 \ldots s_n$$$ and $$$t = t_1 t_2 \ldots t_m$$$ is defined as the maximum integer $$$k$$$ ($$$0 \le k \le min(n,m)$$$) such that $$$s_1 s_2 \ldots s_k$$$ equals $$$t_1 t_2 \ldots t_k$$$.Koa the Koala initially has $$$n+1$$$ strings $$$s_1, s_2, \dots,...
For each test case: Output $$$n+1$$$ lines. In the $$$i$$$-th line print string $$$s_i$$$ ($$$1 \le |s_i| \le 200$$$), consisting of lowercase Latin letters. Length of the longest common prefix of strings $$$s_i$$$ and $$$s_{i+1}$$$ has to be equal to $$$a_i$$$. If there are many answers print any. We can show that ans...
Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 100$$$)Β β€” the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$)Β β€” the number of elements in the list $$$a$$$. The second line of e...
standard output
standard input
PyPy 3
Python
1,200
train_001.jsonl
8d6737fd38ee0c5e10373391e7b6c34c
256 megabytes
["4\n4\n1 2 4 2\n2\n5 3\n3\n1 3 1\n3\n0 0 0"]
PASSED
def listtostring(L): t='' for i in range(0,len(L)): t+=L[i] return t t=int(input()) for i in range(0,t): n=int(input()) L=list(map(int,input().split())) if(max(L)==0): print("a") for i in range(0,n): print(chr(97+(i+1)%26)) else: M=['a' for j in range (1+max(L))] print(listtostring(M)) k=0 f...
1595601300
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["baabcaa"]
501b60c4dc465b8a60fd567b208ea1e3
NoteThe sample is described in problem statement.
You are given a string s and should process m queries. Each query is described by two 1-based indices li, ri and integer ki. It means that you should cyclically shift the substring s[li... ri] ki times. The queries should be processed one after another in the order they are given.One operation of a cyclic shift (rotati...
Print the resulting string s after processing all m queries.
The first line of the input contains the string s (1 ≀ |s| ≀ 10 000) in its initial state, where |s| stands for the length of s. It contains only lowercase English letters. Second line contains a single integer m (1 ≀ m ≀ 300)Β β€” the number of queries. The i-th of the next m lines contains three integers li, ri and ki (...
standard output
standard input
PyPy 3
Python
1,300
train_002.jsonl
1ca4a06fc21a96eb6d5ead571587f45e
256 megabytes
["abacaba\n2\n3 6 1\n1 4 2"]
PASSED
s = input() n = int(input()) for i in range(n): l, r, k = map(int, input().split()) k = k % (r - l + 1) s = s[:l - 1] + s[r - k:r] + s[l - 1:r - k] + s[r:] print(s)
1447426800
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["2\n1\n0", "1\n1\n1\n1\n2"]
e3ec343143419592e73d4be13bcf1cb5
NoteLet's consider the first sample. The figure above shows the first sample. Vertex 1 and vertex 2 are connected by color 1 and 2. Vertex 3 and vertex 4 are connected by color 3. Vertex 1 and vertex 4 are not connected by any single color.
Mr. Kitayuta has just bought an undirected graph consisting of n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi.Mr. Kitayuta wants you to process the following q queries.In the i-th query, he gives you two integers β€” ui and...
For each query, print the answer in a separate line.
The first line of the input contains space-separated two integers β€” n and m (2 ≀ n ≀ 100, 1 ≀ m ≀ 100), denoting the number of the vertices and the number of the edges, respectively. The next m lines contain space-separated three integers β€” ai, bi (1 ≀ ai &lt; bi ≀ n) and ci (1 ≀ ci ≀ m). Note that there can be multipl...
standard output
standard input
Python 2
Python
1,400
train_010.jsonl
d57150c686abc0bf12ea6e99f17ce1a9
256 megabytes
["4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4", "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4"]
PASSED
n, m = map(int, raw_input().split(' ')) mp = [[set() for j in range(0, n)] for i in range(0, n)] for i in range(0, m): a, b, c = map(int, raw_input().split(' ')) a -= 1 b -= 1 if c not in mp[a][b]: mp[a][b].add(c) mp[b][a].add(c) # print mp for k in range(0, n): for i in range(0, n):...
1421586000
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["YES\n4 1 4 4 1\n4 5 5 5 1\n4 5 1 5 4\n1 5 5 5 4\n1 4 4 1 4", "NO", "YES\n4 1\n4 1\n1 4", "YES\n4 4 4 1 4 1 4 1 4\n1 5 5 5 5 5 4 10 1\n4 5 1 4 1 5 4 4 4\n4 5 1 5 5 0 5 5 1\n4 5 1 5 4 5 1 5 4\n4 5 1 5 5 5 4 5 1\n1 5 4 4 1 1 4 5 1\n4 5 5 5 5 5 5 5 4\n1 1 1 1 4 4 1 1 4"]
acbcf0b55f204a12d861936c8a60a8b0
NoteIt can be shown that no such grid exists for the second test.
Alice has an empty grid with $$$n$$$ rows and $$$m$$$ columns. Some of the cells are marked, and no marked cells are adjacent to the edge of the grid. (Two squares are adjacent if they share a side.) Alice wants to fill each cell with a number such that the following statements are true: every unmarked cell contains ...
Output "'NO" if no suitable grid exists. Otherwise, output "'YES"'. Then output $$$n$$$ lines of $$$m$$$ space-separated integersΒ β€” the integers in the grid.
The first line of input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 500$$$)Β β€” the number of rows and the number of columns in the grid, respectively. Then $$$n$$$ lines follow, each containing $$$m$$$ characters. Each of these characters is either '.' or 'X'Β β€” an unmarked and a marked cell, respectiv...
standard output
standard input
PyPy 3-64
Python
2,700
train_089.jsonl
a0bbcec601504cc976dcc1f8718a493f
256 megabytes
["5 5\n.....\n.XXX.\n.X.X.\n.XXX.\n.....", "5 5\n.....\n.XXX.\n.XXX.\n.XXX.\n.....", "3 2\n..\n..\n..", "9 9\n.........\n.XXXXX.X.\n.X...X...\n.X.XXXXX.\n.X.X.X.X.\n.X.XXX.X.\n.X.....X.\n.XXXXXXX.\n........."]
PASSED
#!/usr/bin/env python3 import sys import getpass # not available on codechef import math, random import functools, itertools, collections, heapq, bisect from collections import Counter, defaultdict, deque input = sys.stdin.readline # to read input quickly # import io, os # if all integers, otherwise need to...
1630852500
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["4.500000000\n-12.500000000\n4.000000000\n18.666666667"]
159b9c743d6d8792548645b9f7be2753
NoteIn the first test case, the array is $$$[3, 1, 2]$$$. These are all the possible ways to split this array: $$$a = [3]$$$, $$$b = [1,2]$$$, so the value of $$$f(a) + f(b) = 3 + 1.5 = 4.5$$$. $$$a = [3,1]$$$, $$$b = [2]$$$, so the value of $$$f(a) + f(b) = 2 + 2 = 4$$$. $$$a = [3,2]$$$, $$$b = [1]$$$, so the valu...
Ezzat has an array of $$$n$$$ integers (maybe negative). He wants to split it into two non-empty subsequences $$$a$$$ and $$$b$$$, such that every element from the array belongs to exactly one subsequence, and the value of $$$f(a) + f(b)$$$ is the maximum possible value, where $$$f(x)$$$ is the average of the subsequen...
For each test case, print a single value β€” the maximum value that Ezzat can achieve. Your answer is considered correct if its absolute or relative error does not exceed $$$10^{-6}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is accepted if and only if $$$\frac{|a - b|}{\max{(1...
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^3$$$)β€” the number of test cases. Each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$). It i...
standard output
standard input
PyPy 3-64
Python
800
train_095.jsonl
b3c025660f3879b5dfa615df43e3e4a3
256 megabytes
["4\n3\n3 1 2\n3\n-7 -6 -6\n3\n2 2 2\n4\n17 3 5 -3"]
PASSED
#!/usr/bin/env python3 import io import os import sys input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def printd(*args, **kwargs): #print(*args, **kwargs, file=sys.stderr) print(*args, **kwargs) pass def get_str(): return input().decode().strip() def rint(): return map(int, input().s...
1628519700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["11", "13"]
48f2c0307a29056a5e0fcc26af98f6dc
NoteIn the first test case, we can travel in order $$$1\to 3\to 2\to 1$$$. The flight $$$1\to 3$$$ costs $$$\max(c_1,a_3-a_1)=\max(9,4-1)=9$$$. The flight $$$3\to 2$$$ costs $$$\max(c_3, a_2-a_3)=\max(1,2-4)=1$$$. The flight $$$2\to 1$$$ costs $$$\max(c_2,a_1-a_2)=\max(1,1-2)=1$$$. The total cost is $$$11$$$, and w...
There are $$$n$$$ cities numbered from $$$1$$$ to $$$n$$$, and city $$$i$$$ has beauty $$$a_i$$$.A salesman wants to start at city $$$1$$$, visit every city exactly once, and return to city $$$1$$$.For all $$$i\ne j$$$, a flight from city $$$i$$$ to city $$$j$$$ costs $$$\max(c_i,a_j-a_i)$$$ dollars, where $$$c_i$$$ is...
Output a single integer β€” the minimum total cost.
The first line contains a single integer $$$n$$$ ($$$2\le n\le 10^5$$$) β€” the number of cities. The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$a_i$$$, $$$c_i$$$ ($$$0\le a_i,c_i\le 10^9$$$) β€” the beauty and price floor of the $$$i$$$-th city.
standard output
standard input
PyPy 3-64
Python
2,200
train_100.jsonl
1d71f192585523677bdbb9cf2930c754
256 megabytes
["3\n1 9\n2 1\n4 1", "6\n4 2\n8 4\n3 0\n2 3\n7 1\n0 1"]
PASSED
import sys,os,io input = sys.stdin.readline # for strings # input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline # for non-strings PI = 3.141592653589793238460 INF = float('inf') MOD = 1000000007 # MOD = 998244353 def bin32(num): return '{0:032b}'.format(num) def add(x,y): return (x+...
1617460500
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["YES", "NO"]
46d734178b3acaddf2ee3706f04d603d
null
Haiku is a genre of Japanese traditional poetry.A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllab...
Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes).
The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The i-th line contains the i-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing sp...
standard output
standard input
PyPy 2
Python
800
train_014.jsonl
f45d591916dee8954a941956a72b17b5
256 megabytes
["on codeforces \nbeta round is running\n a rustling of keys", "how many gallons\nof edo s rain did you drink\n cuckoo"]
PASSED
phr1, phr2, phr3 = raw_input(), raw_input(), raw_input() if sum([phr1.count(k) for k in "aeiou"]) == 5 and sum([phr2.count(k) for k in "aeiou"]) == 7 and sum([phr3.count(k) for k in "aeiou"]) == 5: print "YES" else: print "NO"
1303916400
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["1", "2", "3"]
d436c7a3b7f07c9f026d00bdf677908d
null
As Valeric and Valerko were watching one of the last Euro Championship games in a sports bar, they broke a mug. Of course, the guys paid for it but the barman said that he will let them watch football in his bar only if they help his son complete a programming task. The task goes like that.Let's consider a set of funct...
Print a single number β€” the number of angles that do not equal 180 degrees in the graph of the polyline that equals the sum of the given functions.
The first line contains integer n (1 ≀ n ≀ 105) β€” the number of functions. Each of the following n lines contains two space-separated integer numbers ki, bi ( - 109 ≀ ki, bi ≀ 109) that determine the i-th function.
standard output
standard input
Python 3
Python
1,900
train_027.jsonl
2f125ba738b3b397eea01f4af64e0cef
256 megabytes
["1\n1 0", "3\n1 0\n0 2\n-1 1", "3\n-2 -4\n1 7\n-5 1"]
PASSED
from sys import stdin, stdout from decimal import Decimal n = int(stdin.readline()) visit = [] for i in range(n): k, b = map(Decimal, stdin.readline().split()) if not k: continue visit.append(-b/k) visit.sort() if len(visit): ans = 1 else: ans = 0 e = Decimal(10) ** De...
1339342200
[ "geometry", "math" ]
[ 0, 1, 0, 1, 0, 0, 0, 0 ]
2 seconds
["YES\nabb"]
591846c93bd221b732c4645e50fae617
null
Authors have come up with the string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters.You are given two permutations of its indices (not necessary equal) $$$p$$$ and $$$q$$$ (both of length $$$n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exac...
If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$s$$$ on the second line. It should consist of $$$n$$$ lowercase Latin letters, contain at least $$$k$$$ distinct characters and suit the given permutations. If there are multiple answers,...
The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le k \le 26$$$) β€” the length of the string and the number of distinct characters required. The second line of the input contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$, all $$$p_i$$$ are di...
standard output
standard input
PyPy 2
Python
2,100
train_002.jsonl
87d0231268cbbbdd3643788cae9742d5
256 megabytes
["3 2\n1 2 3\n1 3 2"]
PASSED
# adapted some python code from https://www.geeksforgeeks.org/strongly-connected-components/ from collections import defaultdict, deque #This class represents a directed graph using adjacency list representation class Graph: def __init__(self,vertices): self.V= vertices #No. of vertices ...
1567175700
[ "strings", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 1, 0 ]
2 seconds
["0", "2\n2 1", "-1"]
8e6e50d43ed246234d763271f4ae655a
NoteA path is called simple if all huts on it are pairwise different.
After Santa Claus and his assistant Elf delivered all the presents and made all the wishes come true, they returned to the North Pole and found out that it is all covered with snow. Both of them were quite tired and they decided only to remove the snow from the roads connecting huts. The North Pole has n huts connected...
Print "-1" without the quotes if it is impossible to choose the roads that will be cleared by the given rule. Otherwise print in the first line how many roads should be cleared and in the second line print the numbers of those roads (the roads are numbered from 1 in the order of occurrence in the input). It is allowed ...
The first input line contains two positive integers n and m (1 ≀ n ≀ 103, 1 ≀ m ≀ 105) β€” the number of huts and the number of roads. Then follow m lines, each of them contains a road description: the numbers of huts it connects β€” x and y (1 ≀ x, y ≀ n) and the person responsible for clearing out this road ("S" β€” for th...
standard output
standard input
Python 2
Python
2,300
train_058.jsonl
2dc225de4a762f3eb54243fc8a087d55
256 megabytes
["1 2\n1 1 S\n1 1 M", "3 3\n1 2 S\n1 3 M\n2 3 S", "5 6\n1 1 S\n1 2 M\n1 3 S\n1 4 M\n1 5 M\n2 2 S"]
PASSED
class DSU(object): def __init__(self, n): self.pnt = [-1] * n def find(self, x): pnt = self.pnt if pnt[x] == -1: return x pnt[x] = self.find(pnt[x]) return pnt[x] def join(self, u, v): pnt = self.pnt u = self.find(u) v = self.find...
1326034800
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["YES\nYES\nYES\nNO"]
840a4e16454290471faa5a27a3c795d9
NoteThe first example is mentioned in the problem statement.In the second example, one can build the tower by flipping the top dice from the previous tower.In the third example, one can use a single die that has $$$5$$$ on top.The fourth example is impossible.
Bob is playing with $$$6$$$-sided dice. A net of such standard cube is shown below.He has an unlimited supply of these dice and wants to build a tower by stacking multiple dice on top of each other, while choosing the orientation of each dice. Then he counts the number of visible pips on the faces of the dice.For examp...
For each of Bob's favourite integers, output "YES" if it is possible to build the tower, or "NO" otherwise (quotes for clarity).
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$)Β β€” the number of favourite integers of Bob. The second line contains $$$t$$$ space-separated integers $$$x_i$$$ ($$$1 \leq x_i \leq 10^{18}$$$)Β β€” Bob's favourite integers.
standard output
standard input
PyPy 3
Python
1,000
train_011.jsonl
5d0382c76da8c25e3c51261afa016214
256 megabytes
["4\n29 34 19 38"]
PASSED
n=int(input()) l=[int(x) for x in input().split()] for i in l: if(i>14): k=i%14 if(k>0 and k<=6): print("YES") else: print("NO") else: print("NO")
1576595100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["10012\n9"]
6db42771fdd582578194c7b69a4ef575
NoteThe first testcase of the example is already explained in the statement.In the second testcase, there is only one possible reduction: the first and the second digits.
You are given a decimal representation of an integer $$$x$$$ without leading zeros.You have to perform the following reduction on it exactly once: take two neighboring digits in $$$x$$$ and replace them with their sum without leading zeros (if the sum is $$$0$$$, it's represented as a single $$$0$$$).For example, if $$...
For each testcase, print a single integerΒ β€” the largest number that can be obtained after the reduction is applied exactly once. The number should not contain leading zeros.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of testcases. Each testcase consists of a single integer $$$x$$$ ($$$10 \le x &lt; 10^{200000}$$$). $$$x$$$ doesn't contain leading zeros. The total length of the decimal representations of $$$x$$$ over all testcases doesn't exceed $...
standard output
standard input
Python 3
Python
1,100
train_087.jsonl
b2b7c626f5b48e117c1a75dda2c04e9d
256 megabytes
["2\n10057\n90"]
PASSED
''' # Submitted By Ala3rjMo7@gmail.com Don't Copy This Code, Try To Solve It By Yourself ''' # Problem Name = "Minor Reduction" # Class: B def Solve(): lst=[] for t in range(int(input())): n=input()[::-1] lst.append(n) for num in lst: e=True for i in...
1642343700
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
3 seconds
["1", "40", "54"]
3634a3367a1f05d1b3e8e4369e8427fb
NoteFor the first example, $$$t=\{\textrm{lcm}(\{1,1\})\}=\{1\}$$$, so $$$\gcd(t)=1$$$.For the second example, $$$t=\{120,40,80,120,240,80\}$$$, and it's not hard to see that $$$\gcd(t)=40$$$.
For the multiset of positive integers $$$s=\{s_1,s_2,\dots,s_k\}$$$, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of $$$s$$$ as follow: $$$\gcd(s)$$$ is the maximum positive integer $$$x$$$, such that all integers in $$$s$$$ are divisible on $$$x$$$. $$$\textrm{lcm}(s)$$$ is the minimum posi...
Print one integer: $$$\gcd(\{\textrm{lcm}(\{a_i,a_j\})\ |\ i&lt;j\})$$$.
The first line contains one integer $$$n\ (2\le n\le 100\,000)$$$. The second line contains $$$n$$$ integers, $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 200\,000$$$).
standard output
standard input
Python 2
Python
1,600
train_000.jsonl
a0c26afcf00079d2cc95ca1f63f598ea
256 megabytes
["2\n1 1", "4\n10 24 40 80", "10\n540 648 810 648 720 540 594 864 972 648"]
PASSED
def gcd(a,b): while b: a,b=b,a%b return a def rwh_primes2(n): # https://stackoverflow.com/questions/2068372/fastest-way-to-list-all-primes-below-n-in-python/3035188#3035188 """ Input n>=6, Returns a list of primes, 2 <= p < n """ correction = (n%6>1) n = {0:n,1:n-1,2:n+4,3:n+3,4:n+2,5:n+1}[n%6] s...
1589286900
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["2", "1"]
0d212ea4fc9f03fdd682289fca9b517e
NoteIn the first test case, there are two good partitions $$$13+5$$$ and $$$1+3+5$$$.In the second test case, there is one good partition $$$1+0+0+0+0$$$.
Vasya owns three big integers β€” $$$a, l, r$$$. Let's define a partition of $$$x$$$ such a sequence of strings $$$s_1, s_2, \dots, s_k$$$ that $$$s_1 + s_2 + \dots + s_k = x$$$, where $$$+$$$ is a concatanation of strings. $$$s_i$$$ is the $$$i$$$-th element of the partition. For example, number $$$12345$$$ has the foll...
Print a single integer β€” the amount of partitions of number $$$a$$$ such that they match all the given requirements modulo $$$998244353$$$.
The first line contains a single integer $$$a~(1 \le a \le 10^{1000000})$$$. The second line contains a single integer $$$l~(0 \le l \le 10^{1000000})$$$. The third line contains a single integer $$$r~(0 \le r \le 10^{1000000})$$$. It is guaranteed that $$$l \le r$$$. It is also guaranteed that numbers $$$a, l, r$$$ co...
standard output
standard input
PyPy 3
Python
2,600
train_000.jsonl
8fa49b400f05cc20ce305f47184cd1c2
256 megabytes
["135\n1\n15", "10000\n0\n9"]
PASSED
def kmp(pat,text,t): s=pat+"?"+text; #z[i] es el tamaΓ±o del prefijo mas largo de, formado por una subcadena s[i:...] z=[0 for i in range(len(s))] L=0;R=0;n=len(s); for i in range(1,len(s)): if i>R: L=R=i while R<n and s[R-L]==s[R]: R+=1 z[i...
1537454700
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["13\n0\n68\n0\n74"]
7f9853be7ac857bb3c4eb17e554ad3f1
null
You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its...
Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard.
The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$)Β β€” the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboardΒ β€” a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a...
standard output
standard input
Python 3
Python
800
train_108.jsonl
836b9894e221f19e58fa751c335a7986
256 megabytes
["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"]
PASSED
t = int(input()) for j in range(t): letters = str(input()) s = str(input()) dictiony = {} calculating = [] word = [] sum = 0 for m in s: word.append(m) for i in letters: dictiony[i] = letters.index(i) for k in word: calculating.append(dictiony.get...
1635863700
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["11\n8\n35\n0\n200\n4"]
ef2b90d5b1073430795704a7df748ac3
NoteFor the second test case, one can show that the best pair is ("abb","bef"), which has difference equal to $$$8$$$, which can be obtained in the following way: change the first character of the first string to 'b' in one move, change the second character of the second string to 'b' in $$$3$$$ moves and change the th...
You are given $$$n$$$ words of equal length $$$m$$$, consisting of lowercase Latin alphabet letters. The $$$i$$$-th word is denoted $$$s_i$$$.In one move you can choose any position in any single word and change the letter at that position to the previous or next letter in alphabetical order. For example: you can chan...
For each test case, print a single integer β€” the minimum difference over all possible pairs of the given strings.
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 $$$2$$$ integers $$$n$$$ and $$$m$$$ ($$$2 \leq n \leq 50$$$, $$$1 \leq m \leq 8$$$) β€” the number of strings and their length...
standard output
standard input
Python 3
Python
800
train_106.jsonl
0e9539720db50e4607ffb1c99d44c206
256 megabytes
["6\n\n2 4\n\nbest\n\ncost\n\n6 3\n\nabb\n\nzba\n\nbef\n\ncdu\n\nooo\n\nzzz\n\n2 7\n\naaabbbc\n\nbbaezfe\n\n3 2\n\nab\n\nab\n\nab\n\n2 8\n\naaaaaaaa\n\nzzzzzzzz\n\n3 1\n\na\n\nu\n\ny"]
PASSED
for i in range(int(input())): n,m=map(int,input().split()) o=[] ls=[] for i in range(n): a=str(input()) s=[] for j in a: s+=[ord(j)-96] o+=[s] mi = (2**31)-1 for j in range(len(o)): for k in range(len(o)): if(j!=k): ...
1652193900
[ "math", "strings" ]
[ 0, 0, 0, 1, 0, 0, 1, 0 ]
2 seconds
["2\n1\n2"]
aab052bf49da6528641f655342fa4848
null
Polycarp was gifted an array $$$a$$$ of length $$$n$$$. Polycarp considers an array beautiful if there exists a number $$$C$$$, such that each number in the array occurs either zero or $$$C$$$ times. Polycarp wants to remove some elements from the array $$$a$$$ to make it beautiful.For example, if $$$n=6$$$ and $$$a = ...
For each test case, output one integerΒ β€” the minimum number of elements that Polycarp has to remove from the array $$$a$$$ to make it beautiful.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case consists of one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$)Β β€” the length of the array $$$a$$$. The second line of each test case contains $$$n$$$ integer...
standard output
standard input
Python 3
Python
1,500
train_098.jsonl
82792d9090de522418aae5355a424ac5
256 megabytes
["3\n6\n1 3 2 1 4 2\n4\n100 100 4 100\n8\n1 2 3 3 3 2 6 6"]
PASSED
from collections import Counter for _ in range(int(input())): n = int(input()) l = list(map(int , input().split())) occ = [] occ = list( Counter(l).values() ) occ.sort() size = len(occ) behind = [0]*size s = 0 i = 0 while i < size: cur = occ[i] add...
1613486100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
3 seconds
["YES", "NO"]
16a1c5dbe8549313bae6bca630047502
NoteThe first sample is shown on the following picture: In the second sample it is impossible to reach Igor's office using less that 4 turns, thus there exists no path using no more than 2 turns. The path using exactly 4 turns is shown on this picture:
Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, the city where he lives, are closed due to road works. Moreover, Igor has some problems with the steering wheel,...
In the only line print "YES" if there is a path between Igor's home and Igor's office with no more than two turns, and "NO" otherwise.
The first line contains two integers n and m (1 ≀ n, m ≀ 1000)Β β€” the number of rows and the number of columns in the grid. Each of the next n lines contains m characters denoting the corresponding row of the grid. The following characters can occur: "." β€” an empty cell; "*" β€” a cell with road works; "S" β€” the cell...
standard output
standard input
PyPy 2
Python
1,600
train_010.jsonl
29be230384cdd1cb1f6c32390c7be17a
256 megabytes
["5 5\n..S..\n****.\nT....\n****.\n.....", "5 5\nS....\n****.\n.....\n.****\n..T.."]
PASSED
n,m=map(int,raw_input().split()) N=range(n) M=range(m) D=(0,1,2,3) g=[raw_input() for _ in range(n)] I=1<<20 v=[[[I]*4 for _ in M] for _ in N] q=[] for i in N: for j in M: if 'S'==g[i][j]: for d in D: q+=[(i,j,d)] v[i][j][d]=0 if 'T'==g[i][j]: x,y=i,j dr=[-1,0,1,0] dc=[0,1,0,-1] wh...
1492965900
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["YES\nYES\nNO\nYES\nYES\nNO"]
a4c82fffb31bc7e42870fd84e043e815
NoteIn the first test case, you can represent $$$3$$$ as $$$3$$$.In the second test case, the only way to represent $$$4$$$ is $$$1+3$$$.In the third test case, you cannot represent $$$10$$$ as the sum of three distinct positive odd integers.In the fourth test case, you can represent $$$10$$$ as $$$3+7$$$, for example....
You are given two integers $$$n$$$ and $$$k$$$. Your task is to find if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers or not.You have to answer $$$t$$$ independent test cases.
For each test case, print the answer β€” "YES" (without quotes) if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers and "NO" otherwise.
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^5$$$) β€” the number of test cases. The next $$$t$$$ lines describe test cases. The only line of the test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^7$$$).
standard output
standard input
PyPy 3
Python
1,100
train_002.jsonl
875e3c1bdfd197a06af7a67499826260
256 megabytes
["6\n3 1\n4 2\n10 3\n10 2\n16 4\n16 5"]
PASSED
t=int(input()) for i in range(t): n,x=[int(y) for y in input().split()] if (n%2!=x%2 or x**2>n): print('NO') else: print('YES')
1584974100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["1 3 2", "2 1 3 4", "1"]
1cfd0e6504bba7db9ec79e2f243b99b4
NoteIn the first test the numeration is already a permutation, so there is no need to change anything.In the second test there are two pairs of equal numbers, in each pair you need to replace one number.In the third test you need to replace 2 by 1, as the numbering should start from one.
Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the track of everything.During an audit, you were surprised to find out that the i...
Print n numbersΒ β€” the final inventory numbers of the items in the order they occur in the input. If there are multiple possible answers, you may print any of them.
The first line contains a single integer nΒ β€” the number of items (1 ≀ n ≀ 105). The second line contains n numbers a1, a2, ..., an (1 ≀ ai ≀ 105)Β β€” the initial inventory numbers of the items.
standard output
standard input
Python 3
Python
1,200
train_024.jsonl
ae2d1466a74a85886d64d0eb045d3ed0
256 megabytes
["3\n1 3 2", "4\n2 2 3 3", "1\n2"]
PASSED
n = int(input()) l = list(map(int,input().split())) d = {} for i in range(n): if l[i] in d: d[l[i]] += 1 else: d[l[i]] = 1 notpre_ = [] for i in range(1,n+1): if i in d: continue else: notpre_.append(i) k = 0 for i in range(len(notpre_)): for j in range(k,len(l)): if d[l[j]] > 1 or l[j] > n: d[l[j]...
1439224200
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["3", "2"]
15fa49860e978d3b3fb7a20bf9f8aa86
NoteAs you know, students are a special sort of people, and minibuses usually do not hurry. That's why you should not be surprised, if Student's speed is higher than the speed of the minibus.
And again a misfortune fell on Poor Student. He is being late for an exam.Having rushed to a bus stop that is in point (0, 0), he got on a minibus and they drove along a straight line, parallel to axis OX, in the direction of increasing x.Poor Student knows the following: during one run the minibus makes n stops, the...
In the only line output the answer to the problem β€” index of the optimum bus stop.
The first line contains three integer numbers: 2 ≀ n ≀ 100, 1 ≀ vb, vs ≀ 1000. The second line contains n non-negative integers in ascending order: coordinates xi of the bus stop with index i. It is guaranteed that x1 equals to zero, and xn ≀ 105. The third line contains the coordinates of the University, integers xu a...
standard output
standard input
Python 3
Python
1,200
train_013.jsonl
3fa2ad458ee94f7720ea0214ce25d7d9
64 megabytes
["4 5 2\n0 2 4 6\n4 1", "2 1 1\n0 100000\n100000 100000"]
PASSED
from math import sqrt n, v1, v2 = [int(i) for i in input().split()] x = [int(i) for i in input().split()] x1, y1 = [int(i) for i in input().split()] minim = x[1] / v1 + sqrt((x1-x[1])**2 + (y1)**2) / v2 #ВрСмя, Ссли студСн Π²Ρ‹ΠΉΠ΄Π΅Ρ‚ Π½Π° ΠΏΠ΅Ρ€Π²ΠΎΠΉ остановкС ΠΈ ΠΏΠΎΠ±Π΅ΠΆΠΈΡ‚ (Ссли ΠΎΠ½ быстрСС автобуса) res = 2 for i in range(2, n): ...
1270983600
[ "geometry" ]
[ 0, 1, 0, 0, 0, 0, 0, 0 ]
2 seconds
["-1", "4\n1 2\n2 3\n3 4\n4 5"]
ed040061e0e9fd41a7cd05bbd8ad32dd
NoteIn the first sample case, no graph can fulfill PolandBall's requirements.In the second sample case, red graph is a path from 1 to 5. Its diameter is 4. However, white graph has diameter 2, because it consists of edges 1-3, 1-4, 1-5, 2-4, 2-5, 3-5.
PolandBall has an undirected simple graph consisting of n vertices. Unfortunately, it has no edges. The graph is very sad because of that. PolandBall wanted to make it happier, adding some red edges. Then, he will add white edges in every remaining place. Therefore, the final graph will be a clique in two colors: white...
If it's impossible to find a suitable graph, print -1. Otherwise, you can output any graph which fulfills PolandBall's requirements. First, output mΒ β€” the number of red edges in your graph. Then, you should output m lines, each containing two integers ai and bi, (1 ≀ ai, bi ≀ n, ai ≠ bi) which means that there is an un...
The only one input line contains two integers n and k (2 ≀ n ≀ 1000, 1 ≀ k ≀ 1000), representing graph's size and sought colorfulness.
standard output
standard input
Python 3
Python
2,400
train_070.jsonl
d8787e711f89604b5400f7bc796d4018
256 megabytes
["4 1", "5 2"]
PASSED
n, k = map(int, input().split()) if n < 4: print(-1) elif k == 1: print(-1) elif k > 3: print(-1) elif n == 4 and k == 2: print(-1) elif k == 2: print(n - 1) for i in range(n - 1): print(i + 1, i + 2) elif k == 3: print(n - 1) print(1, 2) print(2, 3) for i in range(4, n ...
1484499900
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["1 2 5 3 4"]
a464c3bd13fe9358c2419b17981522f6
NoteHere is the illustration for the first test: Please note that the angle between $$$A_1$$$, $$$A_2$$$ and $$$A_5$$$, centered at $$$A_2$$$, is treated as $$$0$$$ degrees. However, angle between $$$A_1$$$, $$$A_5$$$ and $$$A_2$$$, centered at $$$A_5$$$, is treated as $$$180$$$ degrees.
Nezzar loves the game osu!.osu! is played on beatmaps, which can be seen as an array consisting of distinct points on a plane. A beatmap is called nice if for any three consecutive points $$$A,B,C$$$ listed in order, the angle between these three points, centered at $$$B$$$, is strictly less than $$$90$$$ degrees. Poi...
If there is no solution, print $$$-1$$$. Otherwise, print $$$n$$$ integers, representing a valid permutation $$$p$$$. If there are multiple possible answers, you can print any.
The first line contains a single integer $$$n$$$ ($$$3 \le n \le 5000$$$). Then $$$n$$$ lines follow, $$$i$$$-th of them contains two integers $$$x_i$$$, $$$y_i$$$ ($$$-10^9 \le x_i, y_i \le 10^9$$$) β€” coordinates of point $$$A_i$$$. It is guaranteed that all points are distinct.
standard output
standard input
PyPy 3
Python
2,200
train_088.jsonl
7a471d68ea06013392c9305361869f9b
512 megabytes
["5\n0 0\n5 0\n4 2\n2 1\n3 0"]
PASSED
import sys sys.setrecursionlimit(10**5) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def MI(): return map(int, sys.stdin.buffer.readline().split()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LLI(rows_number): retur...
1611844500
[ "geometry" ]
[ 0, 1, 0, 0, 0, 0, 0, 0 ]
1 second
["12\n12\n0"]
4af206ae108a483bdb643dc24e4bedba
NoteIn the first test case, a possible sequence of moves that uses the minimum number of moves required is shown below. $$$$$$(0,0) \to (1,0) \to (1,1) \to (1, 2) \to (0,2) \to (-1,2) \to (-1,1) \to (-1,0) \to (-1,-1) \to (-1,-2) \to (0,-2) \to (0,-1) \to (0,0)$$$$$$ In the second test case, a possible sequence of mov...
You are living on an infinite plane with the Cartesian coordinate system on it. In one move you can go to any of the four adjacent points (left, right, up, down).More formally, if you are standing at the point $$$(x, y)$$$, you can: go left, and move to $$$(x - 1, y)$$$, or go right, and move to $$$(x + 1, y)$$$, or...
For each test case output a single integer β€” the minimum number of moves required.
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 a single integer $$$n$$$ ($$$1 \le n \le 100$$$) β€” the number of boxes. The $$$i$$$-th line of the following $$$n$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$-100...
standard output
standard input
Python 2
Python
800
train_088.jsonl
55d443b20df5b6227b919f1537897d0b
256 megabytes
["3\n\n4\n\n0 -2\n\n1 0\n\n-1 0\n\n0 2\n\n3\n\n0 2\n\n-3 0\n\n0 -1\n\n1\n\n0 0"]
PASSED
import sys raw_input = iter(sys.stdin.read().splitlines()).next def solution(): n = int(raw_input()) points = [map(int, raw_input().split()) for _ in xrange(n)] return 2*((max(max(x for x, _ in points), 0)-min(min(x for x, _ in points), 0))+\ (max(max(y for _, y in points), 0)-min(min(...
1659796500
[ "geometry" ]
[ 0, 1, 0, 0, 0, 0, 0, 0 ]
3 seconds
["3\n3\n15\n15\n332103349\n99224487"]
81efc64bba6d5a667e453260b83640e9
NoteIn the first test case, the robot has the opportunity to clean the dirty cell every second. Using the geometric distribution, we can find out that with the success rate of $$$25\%$$$, the expected number of tries to clear the dirty cell is $$$\frac 1 {0.25} = 4$$$. But because the first moment the robot has the opp...
The statement of this problem shares a lot with problem A. The differences are that in this problem, the probability is introduced, and the constraint is different.A robot cleaner is placed on the floor of a rectangle room, surrounded by walls. The floor consists of $$$n$$$ rows and $$$m$$$ columns. The rows of the flo...
For each test case, print a single integer β€” the expected time for the robot to clean the dirty cell, modulo $$$10^9 + 7$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10$$$). Description of the test cases follows. A test case consists of only one line, containing $$$n$$$, $$$m$$$, $$$r_b$$$, $$$c_b$$$, $$$r_d$$$, $$$c_d$$$, and $$$p$$$ ($$$4 \le n \cdot m \le 10^5$$$, $$$...
standard output
standard input
PyPy 3-64
Python
2,300
train_106.jsonl
c74a21d33761d54b09b23d24f8972064
256 megabytes
["6\n2 2 1 1 2 1 25\n3 3 1 2 2 2 25\n10 10 1 1 10 10 75\n10 10 10 10 1 1 75\n5 5 1 3 2 2 10\n97 98 3 5 41 43 50"]
PASSED
import os,sys from io import BytesIO, IOBase from collections import defaultdict,deque,Counter from bisect import bisect_left,bisect_right from heapq import heappush,heappop from functools import lru_cache from itertools import accumulate import math # Fast IO Region BUFSIZE = 8192 class FastIO(IOBase): ...
1640698500
[ "probabilities", "math" ]
[ 0, 0, 0, 1, 0, 1, 0, 0 ]
3 seconds
["5\n1 2 4 11 13", "-1", "-1", "3\n9 11 17", "4\n2 2 2 2"]
3a305e2cc38ffd3dc98f21209e83b68d
NoteIn the first example, $$$1 \times 2 \times 4 \times 11 \times 13 = 1144$$$, which is the largest product that ends with the digit 4. The same set of cards without the number 1 is also a valid answer, as well as a set of 8, 11, and 13 with or without 1 that also has the product of 1144.In the second example, all the...
Diana loves playing with numbers. She's got $$$n$$$ cards with positive integer numbers $$$a_i$$$ written on them. She spends her free time multiplying the numbers on the cards. She picks a non-empty subset of the cards and multiplies all the numbers $$$a_i$$$ written on them.Diana is happy when the product of the numb...
On the first line, print the number of chosen cards $$$k$$$ ($$$1\le k\le n$$$). On the next line, print the numbers written on the chosen cards in any order. If it is impossible to choose a subset of cards with the product that ends with the digit $$$d$$$, print the single line with $$$-1$$$.
The first line contains the integers $$$n$$$ and $$$d$$$ ($$$1\le n\le 10^5$$$, $$$0\le d\le 9$$$). The second line contains $$$n$$$ integers $$$a_i$$$ ($$$1\le a_i\le 1000$$$).
standard output
standard input
Python 3
Python
2,100
train_099.jsonl
416770810b56faf50d5436b7b20451ec
512 megabytes
["6 4\n4 11 8 2 1 13", "3 1\n2 4 6", "5 7\n1 3 1 5 3", "6 3\n8 9 4 17 11 5", "5 6\n2 2 2 2 2"]
PASSED
S_133 = [ (0, 0, 0), (0, 0, 1), (0, 0, 2), (0, 0, 3), (0, 1, 0), (0, 2, 0), (0, 3, 0), (1, 0, 0), (1, 0, 1), (1, 0, 2), (1, 0, 3), (1, 1, 0), (1, 2, 0), (1, 3, 0), ] def pow_mod10(b, p): if p == 0: return 1 return pow(b, 4 + p % 4, 10) def solve(a, d): nums_by_units =...
1617523500
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
2 seconds
["1 1 1\n1 1 3\n1 1 4\n2 1 3\n3 1 5\n4 3 12\n1 1 4"]
67c748999e681fa6f60165f411e5149d
null
The robot is located on a checkered rectangular board of size $$$n \times m$$$ ($$$n$$$ rows, $$$m$$$ columns). The rows in the board are numbered from $$$1$$$ to $$$n$$$ from top to bottom, and the columnsΒ β€” from $$$1$$$ to $$$m$$$ from left to right.The robot is able to move from the current cell to one of the four c...
For each test case, output three integers $$$r$$$, $$$c$$$ and $$$d$$$ ($$$1 \le r \le n$$$; $$$1 \le c \le m$$$; $$$d \ge 0$$$), which denote that the robot should start moving from cell $$$(r, c)$$$ to make the maximum number of moves $$$d$$$. If there are several answers, output any of them.
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10000$$$)Β β€” the number of test cases in the test. Each test case's description is preceded by a blank line. Next is a line that contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 2000$$$; $$$1 \le m \le 2000$$$)Β β€” the height and width of the board. This line...
standard output
standard input
PyPy 3-64
Python
2,300
train_108.jsonl
8123388e4691d6309a183e2ce73440ca
256 megabytes
["7\n\n1 1\nR\n\n1 3\nRRL\n\n2 2\nDL\nRU\n\n2 2\nUD\nRU\n\n3 2\nDL\nUL\nRU\n\n4 4\nRRRD\nRUUD\nURUD\nULLR\n\n4 4\nDDLU\nRDDU\nUUUU\nRDLD"]
PASSED
''' F. Robot on the Board 2 https://codeforces.com/contest/1607/problem/F ''' import io, os, sys input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline # decode().strip() if str output = sys.stdout.write from collections import deque def solve(R, C, NEXT): N = R*C # max_dist[r][c] = max moves if start...
1635863700
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["2\n1 2 4 3", "0\n4 5 6 3 2 1", "3\n2 8 4 6 7 1 9 3 10 5"]
0560658d84cbf91c0d86eea4be92a4d9
NoteIn the first example Ivan needs to replace number three in position 1 with number one, and number two in position 3 with number four. Then he will get a permutation [1, 2, 4, 3] with only two changed numbers β€” this permutation is lexicographically minimal among all suitable. In the second example Ivan does not need...
Ivan has an array consisting of n elements. Each of the elements is an integer from 1 to n.Recently Ivan learned about permutations and their lexicographical order. Now he wants to change (replace) minimum number of elements in his array in such a way that his array becomes a permutation (i.e. each of the integers from...
In the first line print q β€” the minimum number of elements that need to be changed in Ivan's array in order to make his array a permutation. In the second line, print the lexicographically minimal permutation which can be obtained from array with q changes.
The first line contains an single integer n (2 ≀ n ≀ 200 000) β€” the number of elements in Ivan's array. The second line contains a sequence of integers a1, a2, ..., an (1 ≀ ai ≀ n) β€” the description of Ivan's array.
standard output
standard input
PyPy 3
Python
1,500
train_009.jsonl
d17bcd0f4836ae66918693521aecd5c4
256 megabytes
["4\n3 2 2 3", "6\n4 5 6 3 2 1", "10\n6 8 4 6 7 1 6 3 4 5"]
PASSED
from collections import Counter def readints(): return [int(item) for item in input().strip().split()] class Solver: def main(self): n = readints()[0] a = readints() c = Counter(a) skipped = set() to_be_added = sorted(set(range(1, n+1)) - set(c.keys())) change...
1506335700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["5", "3", "5"]
0efd4b05b3e2e3bc80c93d37508a5197
NoteIn the first example, you can increase the second element twice. Than array will be $$$[1, 5, 5]$$$ and it's median is $$$5$$$.In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $$$3$$$.In the third example, you can make four operations: incr...
You are given an array $$$a$$$ of $$$n$$$ integers, where $$$n$$$ is odd. You can make the following operation with it: Choose one of the elements of the array (for example $$$a_i$$$) and increase it by $$$1$$$ (that is, replace it with $$$a_i + 1$$$). You want to make the median of the array the largest possible usin...
Print a single integerΒ β€” the maximum possible median after the operations.
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$n$$$ is odd, $$$1 \le k \le 10^9$$$)Β β€” the number of elements in the array and the largest number of operations you can make. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$).
standard output
standard input
PyPy 3
Python
1,400
train_008.jsonl
c8e44d772bafdb88a779bd2e6b7c7eb9
256 megabytes
["3 2\n1 3 5", "5 5\n1 2 1 1 1", "7 7\n4 1 2 4 3 4 4"]
PASSED
# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!! # TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!! # TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!! from sys import stdin, stdout #N = int(input()) #s = input() N,K = [int(x) for x in stdin.readline().split()] arr = [int(x) for x in stdin.readline().split()] arr.sort() half = N//2 s = sum(arr[hal...
1564936500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["1 1 4 4\n-1\n-1\n2 \n-1"]
024d7b1d5f7401080560174003456037
NoteIn the first test case, player $$$1$$$ and player $$$4$$$ won $$$x$$$ times, player $$$2$$$ and player $$$3$$$ won $$$y$$$ times.In the second, third, and fifth test cases, no valid result exists.
There is a badminton championship in which $$$n$$$ players take part. The players are numbered from $$$1$$$ to $$$n$$$. The championship proceeds as follows: player $$$1$$$ and player $$$2$$$ play a game, then the winner and player $$$3$$$ play a game, and then the winner and player $$$4$$$ play a game, and so on. So, ...
Print the answer for each test case, one per line. If there is no result that matches the given information about $$$n$$$, $$$x$$$, $$$y$$$, print $$$-1$$$. Otherwise, print $$$n-1$$$ space separated integers, where the $$$i$$$-th integer is the player number of the winner of the $$$i$$$-th game. If there are multiple...
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^5$$$)Β β€” the number of test cases. The only line of each test case contains three integers $$$n$$$, $$$x$$$, $$$y$$$ ($$$2 \le n \le 10^5$$$, $$$0 \le x, y &lt; n$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^...
standard output
standard input
PyPy 3-64
Python
900
train_104.jsonl
e565a45e0b972d86d79c95ef92a1011f
256 megabytes
["5\n\n5 2 0\n\n8 1 2\n\n3 0 0\n\n2 0 1\n\n6 3 0"]
PASSED
T = int( input()) for t in range(T) : n, x, y = map( int, input().split() ) if x == 0 and y == 0 : print(-1) elif min(x, y) != 0 or max(x, y) >= n : print(-1) elif (n-1) % max(x, y) and max(x, y) != 1 : print(-1) else : j = max(x, y); i = j+2 ans = " 1" * j; ans = an...
1663598100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["Yes", "Yes", "No"]
2b346d5a578031de4d19edb4f8f2626c
NoteIn the first sample, since both 'a' and 'u' are vowels, it is possible to convert string $$$s$$$ to $$$t$$$.In the third sample, 'k' is a consonant, whereas 'a' is a vowel, so it is not possible to convert string $$$s$$$ to $$$t$$$.
We all know that a superhero can transform to certain other superheroes. But not all Superheroes can transform to any other superhero. A superhero with name $$$s$$$ can transform to another superhero with name $$$t$$$ if $$$s$$$ can be made equal to $$$t$$$ by changing any vowel in $$$s$$$ to any other vowel and any co...
Output "Yes" (without quotes) if the superhero with name $$$s$$$ can be transformed to the superhero with name $$$t$$$ and "No" (without quotes) otherwise. You can print each letter in any case (upper or lower).
The first line contains the string $$$s$$$ having length between $$$1$$$ and $$$1000$$$, inclusive. The second line contains the string $$$t$$$ having length between $$$1$$$ and $$$1000$$$, inclusive. Both strings $$$s$$$ and $$$t$$$ are guaranteed to be different and consist of lowercase English letters only.
standard output
standard input
Python 3
Python
1,000
train_002.jsonl
b8374405a2a1df3eb37947d8b85d15ad
256 megabytes
["a\nu", "abc\nukm", "akm\nua"]
PASSED
s1 = input() s2 = input() c=0 v = ['a','e','i','o','u'] if len(s1)==len(s2): i=0 while(i<len(s1)): if (s1[i] in v and s2[i] not in v) or s1[i] not in v and s2[i] in v: c=1 i+=1 if c==1: print("No") else: print("Yes") else: print("No")
1549208100
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
3 seconds
["0 1 2", "0 1 2 3 4", "0 1 2 1 2 3 3"]
d465aec304757dff34a770f7877dd940
NoteIn the first sample case desired sequences are:1: 1; m1 = 0;2: 1, 2; m2 = 1;3: 1, 3; m3 = |3 - 1| = 2.In the second sample case the sequence for any intersection 1 &lt; i is always 1, i and mi = |1 - i|.In the third sample caseΒ β€” consider the following intersection sequences:1: 1; m1 = 0;2: 1, 2; m2 = |2 - 1| = 1;3...
Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city.City consists of n intersections numbered from 1 to n. Mike starts walking from his house located at the intersection number 1 and goes along some sequence of intersections. Walking f...
In the only line print n integers m1, m2, ..., mn, where mi denotes the least amount of total energy required to walk from intersection 1 to intersection i.
The first line contains an integer n (1 ≀ n ≀ 200 000)Β β€” the number of Mike's city intersection. The second line contains n integers a1, a2, ..., an (i ≀ ai ≀ n , , describing shortcuts of Mike's city, allowing to walk from intersection i to intersection ai using only 1 unit of energy. Please note that the shortcuts do...
standard output
standard input
Python 2
Python
1,600
train_000.jsonl
87576c2756b9354a9b092324994d4cd5
256 megabytes
["3\n2 2 3", "5\n1 2 3 4 5", "7\n4 4 4 4 7 7 7"]
PASSED
from Queue import Queue n = int(raw_input()) list = map(int, raw_input().split()) adj = [] dist = [] for i in xrange(n): adj.append([]) dist.append(10**9) for i in xrange(n-1): adj[i].append(i+1) adj[i+1].append(i) for i in xrange(n): element = list[i] if (element-1 != i and element != 0 and element-2 != ...
1467822900
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["1", "2", "39", "0"]
d85c7a8f7e6f5fc6dffed554bffef3ec
null
Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Formerly all n cities of Berland were connected by n two-way roads in the ring, i. e. each city was connected directly to exactly two ot...
Output single integer β€” the smallest amount of money the government should spend on the redirecting of roads so that from every city you can get to any other.
The first line contains integer n (3 ≀ n ≀ 100) β€” amount of cities (and roads) in Berland. Next n lines contain description of roads. Each road is described by three integers ai, bi, ci (1 ≀ ai, bi ≀ n, ai ≠ bi, 1 ≀ ci ≀ 100) β€” road is directed from city ai to city bi, redirecting the traffic costs ci.
standard output
standard input
Python 3
Python
1,400
train_003.jsonl
fe9866a7ff89bec237abe750c3332aaf
256 megabytes
["3\n1 3 1\n1 2 1\n3 2 1", "3\n1 3 1\n1 2 5\n3 2 1", "6\n1 5 4\n5 3 8\n2 4 15\n1 6 16\n2 3 23\n4 6 42", "4\n1 2 9\n2 3 8\n3 4 7\n4 1 5"]
PASSED
# our function def find_next_path(cont, N, path, indx): for i in range(N): if cont[indx][i] != 0 and i not in path or \ cont[i][indx] != 0 and i not in path: return i return -1 # end of fuction N = int(input()) cont = [[0] * N for i in range(N)] for i in range(N): a, b...
1280149200
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["1", "1", "2", "0"]
742e4e6ca047da5f5ebe5d854d6a2024
NoteIn the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column: In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.In the third sample two faces are shown: I...
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them. In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 × ...
In the single line print the number of faces on the image.
The first line contains two space-separated integers, n and m (1 ≀ n, m ≀ 50) β€” the height and the width of the image, respectively. Next n lines define the image. Each line contains m lowercase Latin letters.
standard output
standard input
PyPy 2
Python
900
train_007.jsonl
993cb490e00b48b7cee3708eaaee1a34
256 megabytes
["4 4\nxxxx\nxfax\nxcex\nxxxx", "4 2\nxx\ncf\nae\nxx", "2 3\nfac\ncef", "1 4\nface"]
PASSED
N,M=map(range,map(int,raw_input().split())) a=[raw_input()+'x' for _ in N] + ['x'*64] c=0 for i in N: for j in M: if sorted(a[i][j]+a[i][j+1]+a[i+1][j]+a[i+1][j+1])==['a','c','e','f']: c+=1 print c
1433595600
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["5\n3\n4\n0"]
e26b0b117593c159b7f01cfac66a71d1
NoteIn the first test case, $$$A=\left\{0,1,2\right\},B=\left\{0,1,5\right\}$$$ is a possible choice.In the second test case, $$$A=\left\{0,1,2\right\},B=\varnothing$$$ is a possible choice.In the third test case, $$$A=\left\{0,1,2\right\},B=\left\{0\right\}$$$ is a possible choice.In the fourth test case, $$$A=\left\{...
Given a set of integers (it can contain equal elements).You have to split it into two subsets $$$A$$$ and $$$B$$$ (both of them can contain equal elements or be empty). You have to maximize the value of $$$mex(A)+mex(B)$$$.Here $$$mex$$$ of a set denotes the smallest non-negative integer that doesn't exist in the set. ...
For each test case, print the maximum value of $$$mex(A)+mex(B)$$$.
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1\leq t\leq 100$$$) β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1\leq n\leq 100$$$) β€” the size of the set. The second line of each testcas...
standard output
standard input
Python 3
Python
900
train_010.jsonl
7eb26b147ec9a96f4360f3fd674b179d
512 megabytes
["4\n6\n0 2 1 5 0 1\n3\n0 1 2\n4\n0 2 0 1\n6\n1 2 3 4 5 6"]
PASSED
for _ in range(int(input())): x=[] lsta=[] lstb=[] i=int(input()) x= list(map(int, input().split()[:i])) x.sort() for j in x: if j not in lsta: lsta.append(j) else: lstb.append(j) a=max(lsta)+2 try: b=max(lstb)+2 except: b=...
1599918300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["1", "0", "4"]
6ecf80528aecd95d97583dc1aa309044
NoteIn the first sample, Sagheer can only win if he swapped node 1 with node 3. In this case, both leaves will have 2 apples. If Soliman makes a move in a leaf node, Sagheer can make the same move in the other leaf. If Soliman moved some apples from a root to a leaf, Sagheer will eat those moved apples. Eventually, Sol...
Sagheer is playing a game with his best friend Soliman. He brought a tree with n nodes numbered from 1 to n and rooted at node 1. The i-th node has ai apples. This tree has a special property: the lengths of all paths from the root to any leaf have the same parity (i.e. all paths have even length or all paths have odd ...
On a single line, print the number of different pairs of nodes (u, v), u ≠ v such that if they start playing after swapping the apples of both nodes, Sagheer will win the game. (u, v) and (v, u) are considered to be the same pair.
The first line will contain one integer n (2 ≀ n ≀ 105) β€” the number of nodes in the apple tree. The second line will contain n integers a1, a2, ..., an (1 ≀ ai ≀ 107) β€” the number of apples on each node of the tree. The third line will contain n - 1 integers p2, p3, ..., pn (1 ≀ pi ≀ n) β€” the parent of each node of th...
standard output
standard input
Python 3
Python
2,300
train_013.jsonl
f2b1fa185f73ef26d939af9c6bcb1b11
256 megabytes
["3\n2 2 3\n1 1", "3\n1 2 3\n1 1", "8\n7 2 2 5 4 3 1 1\n1 1 1 4 4 5 6"]
PASSED
n= int(input()) a = [int(_) for _ in input().split()] c = [int(_) for _ in input().split()] depth = [0] * (n) for i in range(1,n): depth[i] = depth[c[i-1]-1] + 1 MAX = max(depth) t = 0 store = {} todo = [] p = 0 for i in range(n): if (MAX-depth[i]) % 2 == 0: # odd, useful t ^= a[i] todo.append(a[...
1496326500
[ "games", "trees" ]
[ 1, 0, 0, 0, 0, 0, 0, 1 ]
1 second
["2", "1"]
a57555f50985c6c3634de1e7c60553bd
NoteIn the first example, one of the optimal solutions is to flip index $$$1$$$ and index $$$3$$$, the string $$$a$$$ changes in the following way: "100" $$$\to$$$ "000" $$$\to$$$ "001". The cost is $$$1 + 1 = 2$$$.The other optimal solution is to swap bits and indices $$$1$$$ and $$$3$$$, the string $$$a$$$ changes th...
You are given two binary strings $$$a$$$ and $$$b$$$ of the same length. You can perform the following two operations on the string $$$a$$$: Swap any two bits at indices $$$i$$$ and $$$j$$$ respectively ($$$1 \le i, j \le n$$$), the cost of this operation is $$$|i - j|$$$, that is, the absolute difference between $$$i...
Output the minimum cost to make the string $$$a$$$ equal to $$$b$$$.
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^6$$$)Β β€” the length of the strings $$$a$$$ and $$$b$$$. The second and third lines contain strings $$$a$$$ and $$$b$$$ respectively. Both strings $$$a$$$ and $$$b$$$ have length $$$n$$$ and contain only '0' and '1'.
standard output
standard input
Python 3
Python
1,300
train_002.jsonl
d025514b8cdffedb2239ee9db4e29a30
256 megabytes
["3\n100\n001", "4\n0101\n0011"]
PASSED
n=int(input()) a=input() b=input() cost=0 i=0 while i<n: if a[i]!=b[i]: cost+=1 if i!=(n-1): if a[i]!=a[i+1] and a[i+1]!=b[i+1]: i+=2 else: i+=1 else: i+=1 else: i+=1 print(cost)
1535898900
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["5\n5\n6", "3\n3\n3\n1", "0\n0\n-1"]
85f5033a045d331c12fc62f9b7816bed
NoteIn the first test: The initial sequence $$$a = (2, -1, 7, 3)$$$. Two sequences $$$b=(-3,-3,5,5),c=(5,2,2,-2)$$$ is a possible choice. After the first change $$$a = (2, -4, 4, 0)$$$. Two sequences $$$b=(-3,-3,5,5),c=(5,-1,-1,-5)$$$ is a possible choice. After the second change $$$a = (2, -4, 6, 2)$$$. Two sequenc...
You are given a sequence of $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$.You have to construct two sequences of integers $$$b$$$ and $$$c$$$ with length $$$n$$$ that satisfy: for every $$$i$$$ ($$$1\leq i\leq n$$$) $$$b_i+c_i=a_i$$$ $$$b$$$ is non-decreasing, which means that for every $$$1&lt;i\leq n$$$, $$$b_i\geq ...
Print $$$q+1$$$ lines. On the $$$i$$$-th ($$$1 \leq i \leq q+1$$$) line, print the answer to the problem for the sequence after $$$i-1$$$ changes.
The first line contains an integer $$$n$$$ ($$$1\leq n\leq 10^5$$$). The secound line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1\leq i\leq n$$$, $$$-10^9\leq a_i\leq 10^9$$$). The third line contains an integer $$$q$$$ ($$$1\leq q\leq 10^5$$$). Each of the next $$$q$$$ lines contains three integers $$$l,r...
standard output
standard input
Python 3
Python
2,200
train_031.jsonl
36035d5dc9f123fbbd08532683a38e75
512 megabytes
["4\n2 -1 7 3\n2\n2 4 -3\n3 4 2", "6\n-9 -10 -9 -6 -5 4\n3\n2 6 -9\n1 2 -10\n4 6 -3", "1\n0\n2\n1 1 -1\n1 1 -1"]
PASSED
n=int(input()) a=list(map(int,input().split())) q=int(input()) b=[0]*n c=[0]*n difn=0 diff=[0]*n for i in range(1,n): if a[i]-a[i-1]>0: difn+=a[i]-a[i-1] diff[i]=a[i]-a[i-1] bo=(a[0]-difn)//2 ans=max(bo+difn,a[0]-bo) print(ans) td=difn for i in range(q): l,r,x=map(int,input().split()) if l!=1: ...
1599918300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["YES\nNO\nNO\nYES"]
e716a5b0536d8f5112fb5f93ab86635b
null
You are given a string $$$s$$$. You can build new string $$$p$$$ from $$$s$$$ using the following operation no more than two times: choose any subsequence $$$s_{i_1}, s_{i_2}, \dots, s_{i_k}$$$ where $$$1 \le i_1 &lt; i_2 &lt; \dots &lt; i_k \le |s|$$$; erase the chosen subsequence from $$$s$$$ ($$$s$$$ can become e...
Print $$$T$$$ answers β€” one per test case. Print YES (case insensitive) if it's possible to build $$$t$$$ and NO (case insensitive) otherwise.
The first line contains the single integer $$$T$$$ ($$$1 \le T \le 100$$$) β€” the number of test cases. Next $$$2T$$$ lines contain test cases β€” two per test case. The first line contains string $$$s$$$ consisting of lowercase Latin letters ($$$1 \le |s| \le 400$$$) β€” the initial string. The second line contains string ...
standard output
standard input
Python 3
Python
2,200
train_003.jsonl
78c8aa31d2f14831994cd249f922c3bc
256 megabytes
["4\nababcd\nabcba\na\nb\ndefi\nfed\nxyz\nx"]
PASSED
tt=int(input()) for _ in range(tt): s=input() t=input() flag='NO' j=0 ptr=0 while(j<len(s) and ptr<len(t)): if(s[j]==t[ptr]): ptr+=1 j+=1 else: j+=1 if(ptr==len(t)): flag='YES' else: pos=[0]*26 for i in range(len...
1581518100
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["3\n0\n4\n1000000000\n1\n1\n1\n5\n0"]
e6eb839ef4e688796050b34f1ca599a5
null
Polycarp has $$$x$$$ of red and $$$y$$$ of blue candies. Using them, he wants to make gift sets. Each gift set contains either $$$a$$$ red candies and $$$b$$$ blue candies, or $$$a$$$ blue candies and $$$b$$$ red candies. Any candy can belong to at most one gift set.Help Polycarp to find the largest number of gift sets...
For each test case, output one numberΒ β€” the maximum number of gift sets that Polycarp can make.
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. Each test case consists of a single string containing four integers $$$x$$$, $$$y$$$, $$$a$$$, and $$$b$$$ ($$$1 \le x, y, a, b \le 10^9$$$).
standard output
standard input
PyPy 3
Python
2,100
train_097.jsonl
fcc75af6236e13ce985d54177bc43d74
256 megabytes
["9\n10 12 2 5\n1 1 2 2\n52 311 13 27\n1000000000 1000000000 1 1\n1000000000 1 1 1000000000\n1 1000000000 1000000000 1\n1 2 1 1\n7 8 1 2\n4 1 2 3"]
PASSED
import math import sys input = sys.stdin.readline t = int(input()) def getList(): return map(int, input().split()) def solve(): x, y, a, b = getList() if a > b: a, b = b, a if a == b: print(min(x, y) // a) else: l = 0 r = (x+y) // (a+b) while l < r: ...
1623335700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"]
0ab1b97a8d2e0290cda31a3918ff86a4
NoteHere is the representation of the graph from the first example:
Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ Β $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T...
If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ...
The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) β€” the number of vertices and the number of edges.
standard output
standard input
Python 3
Python
1,700
train_033.jsonl
d94c78419ebd391bac0ed3c02eea2a5f
256 megabytes
["5 6", "6 12"]
PASSED
from math import gcd n, m = map(int, input().split()) a = [] for i in range(1, n): for j in range(i+1, n+1): if gcd(i, j) == 1: a.append([i, j]) if len(a) == m: break if len(a) == m: break if m < n-1 or len(a) != m: print("Impossible") else: print("Possibl...
1531578900
[ "math", "graphs" ]
[ 0, 0, 1, 1, 0, 0, 0, 0 ]
5 seconds
["Yes\nNo\nYes\nYes", "Yes\nYes\nNo\nYes\nYes\nYes\nYes\nYes", "Yes\nYes\nYes\nYes\nYes\nYes\nNo\nNo\nYes", "Yes"]
7ef1aeb7d4649df98e47d2c26cff251c
NoteExplanation of the first example:In the first testcase the destination rock is the same as the starting rock, thus no jumps are required to reach it.In the second testcase the frog can jump any distance in the range $$$[5 - 2; 5 + 2]$$$. Thus, it can reach rock number $$$5$$$ (by jumping $$$7$$$ to the right) and r...
There is an infinite pond that can be represented with a number line. There are $$$n$$$ rocks in the pond, numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th rock is located at an integer coordinate $$$a_i$$$. The coordinates of the rocks are pairwise distinct. The rocks are numbered in the increasing order of the coordi...
For each of the testcases print an answer. If there is a sequence of jumps from a rock number $$$s$$$ to a rock number $$$i$$$ with the jumping distance range set to $$$k$$$, then print "Yes". Otherwise, print "No".
The first line contains four integers $$$n$$$, $$$q$$$, $$$s$$$ and $$$d$$$ ($$$1 \le n, q \le 2 \cdot 10^5$$$; $$$1 \le s \le n$$$; $$$1 \le d \le 10^6$$$)Β β€” the number of rocks, the number of testcases, the starting rock and the base jumping distance parameter. The second line contains $$$n$$$ integers $$$a_1, a_2, \...
standard output
standard input
PyPy 3
Python
2,700
train_094.jsonl
adabfa41713ba363b06c7feb8a2d1c06
256 megabytes
["7 4 4 5\n1 5 10 13 20 22 28\n4 1\n7 2\n7 3\n3 2", "10 8 6 11\n1 2 4 7 8 9 11 13 19 20\n2 13\n5 8\n8 1\n6 15\n1 15\n2 7\n7 6\n8 9", "6 9 6 6\n1 2 4 9 18 19\n2 17\n1 18\n5 4\n2 11\n5 17\n6 8\n4 3\n3 3\n6 6", "4 1 1 10\n1 8 10 19\n2 1"]
PASSED
from collections import deque import bisect import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def get_root(s): v = [] while not s == root[s]: v.append(s) s = root[s] for i in v: root[i] = s return s def unite(s, t): rs, rt = get_...
1626273300
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["? 1 5\n\u00a0\n? 2 3\n\u00a0\n? 4 1\n\u00a0\n? 5 2\n\u00a0\n? 3 4\n\u00a0\n! 4 6 1 5 5"]
1898e591b40670173e4c33e08ade48ba
NoteThe format of a test to make a hack is: The first line contains an integer number n (3 ≀ n ≀ 5000)Β β€” the length of the array. The second line contains n numbers a1, a2, ..., an (1 ≀ ai ≀ 105)Β β€” the elements of the array to guess.
This is an interactive problem. You should use flush operation after each printed line. For example, in C++ you should use fflush(stdout), in Java you should use System.out.flush(), and in PascalΒ β€” flush(output).In this problem you should guess an array a which is unknown for you. The only information you have initiall...
null
null
standard output
standard input
Python 3
Python
1,400
train_027.jsonl
8d72d82fba78d309261f577f4df5391e
256 megabytes
["5\n\u00a0\n9\n\u00a0\n7\n\u00a0\n9\n\u00a0\n11\n\u00a0\n6"]
PASSED
from math import ceil,gcd,floor from collections import deque,defaultdict as dict from heapq import heappush as hpush,heappop as hpop, heapify from functools import lru_cache import sys inf=float("inf") def inpi(): return(int(input())) def inpa(): return(list(map(int,input().split()))) def inp(): s = input();return(l...
1476522300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["1\n3\n2"]
aca2346553f9e7b6e944ca2c74bb0b3d
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is alread...
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is lo...
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$)Β β€” floor numbers described in the statement.
standard output
standard input
Python 3
Python
800
train_110.jsonl
1b1e97f864667d90d65e854f0609270b
256 megabytes
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
PASSED
for _ in range(int(input())): numbers_a_b_c = input().split() a = int(numbers_a_b_c[0]) b = int(numbers_a_b_c[1]) c = int(numbers_a_b_c[2]) if a == 1: print(1) elif (abs(b - c) + abs(c - 1)) < abs(a - 1): print(2) elif (abs(b - c) + abs(c - 1)) > abs(...
1662993300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["1", "2", "0"]
5e8a5caab28ea491d7ab4a88209172b2
null
Consider the function p(x), where x is an array of m integers, which returns an array y consisting of m + 1 integers such that yi is equal to the sum of first i elements of array x (0 ≀ i ≀ m).You have an infinite sequence of arrays A0, A1, A2..., where A0 is given in the input, and for each i β‰₯ 1 Ai = p(Ai - 1). Also ...
Print the minimum i such that Ai contains a number which is larger or equal than k.
The first line contains two integers n and k (2 ≀ n ≀ 200000, 1 ≀ k ≀ 1018). n is the size of array A0. The second line contains n integers A00, A01... A0n - 1 β€” the elements of A0 (0 ≀ A0i ≀ 109). At least two elements of A0 are positive.
standard output
standard input
Python 3
Python
2,400
train_074.jsonl
a05e63a9c69bb9087182bf0bca2df46b
256 megabytes
["2 2\n1 1", "3 6\n1 1 1", "3 1\n1 0 1"]
PASSED
def p(arr): for i in range(1,len(arr)): arr[i]+=arr[i-1] return arr def max_element(arr): x=0 for i in arr: x=max(x,i) return x def kek(a,b): if (a<=b): return 1 else: return 0 [n,k]=[int(x) for x in input().split()] def matmul(m1,m2): s=0 #сумма t=[] #врСмСнная ΠΌΠ°Ρ‚Ρ€ΠΈΡ†Π° m3=[] # конСчная ΠΌΠ°Ρ‚...
1501773300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["-1", "2 8 14 20 26"]
2deda3a05740e1184735bf437e3850a8
null
Valera had two bags of potatoes, the first of these bags contains x (x β‰₯ 1) potatoes, and the second β€” y (y β‰₯ 1) potatoes. Valera β€” very scattered boy, so the first bag of potatoes (it contains x potatoes) Valera lost. Valera remembers that the total amount of potatoes (x + y) in the two bags, firstly, was not gerater ...
Print the list of whitespace-separated integers β€” all possible values of x in ascending order. You should print each possible value of x exactly once. If there are no such values of x print a single integer -1.
The first line of input contains three integers y, k, n (1 ≀ y, k, n ≀ 109;  ≀ 105).
standard output
standard input
Python 3
Python
1,200
train_004.jsonl
b7661f69887552f3c1b5aa0a8556f6a4
256 megabytes
["10 1 10", "10 6 40"]
PASSED
y, k, n = map(int, input().split()) print(' '.join(map(str, range(y//k*k+k-y, n-y+1, k))) if n//k>y//k else -1)
1352044800
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["36\n44"]
09c8db43681d7bc72f83287897a62f3c
NoteIn the first test case the array initially consists of a single element $$$[12]$$$, and $$$x=2$$$. After the robot processes the first element, the array becomes $$$[12, 6, 6]$$$. Then the robot processes the second element, and the array becomes $$$[12, 6, 6, 3, 3]$$$. After the robot processes the next element, t...
You have given an array $$$a$$$ of length $$$n$$$ and an integer $$$x$$$ to a brand new robot. What the robot does is the following: it iterates over the elements of the array, let the current element be $$$q$$$. If $$$q$$$ is divisible by $$$x$$$, the robot adds $$$x$$$ copies of the integer $$$\frac{q}{x}$$$ to the e...
For each test case output one integerΒ β€” the sum of all elements at the end of the process.
The first input line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)Β β€” the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$x$$$ ($$$1 \leq n \leq 10^5$$$, $$$2 \leq x \leq 10^9$$$)Β β€” the length of the array and the value which is used by the robot. The next line c...
standard output
standard input
Python 3
Python
1,100
train_100.jsonl
06970f20e6942a8f6568074b30bd8c54
256 megabytes
["2\n1 2\n12\n4 2\n4 6 8 2"]
PASSED
#######puzzleVerma####### import sys import math LI=lambda:[int(k) for k in input().split()] input = lambda: sys.stdin.readline().rstrip() IN=lambda:int(input()) S=lambda:input() for i in range(IN()): n,x=LI() a=LI() sm=sum(a) ans=0 ndi=0 co=10**9 for i in range(n):...
1609857300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["1", "0"]
cda1179c51fc69d2c64ee4707b97cbb3
NoteIn the first sample stars in Pavel's records can be $$$(1, 3)$$$, $$$(1, 3)$$$, $$$(2, 3)$$$, $$$(2, 4)$$$. In this case, the minimal area of the rectangle, which contains all these points is $$$1$$$ (rectangle with corners at $$$(1, 3)$$$ and $$$(2, 4)$$$).
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.Strictly speaking, it makes a photo of all points with coordinates $$$(x, y)$$$, such that $$$x_1 \leq x \leq x_2$$$ and $$$y_1 \leq y \leq y_2...
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
The first line of the input contains an only integer $$$n$$$ ($$$1 \leq n \leq 100\,000$$$), the number of points in Pavel's records. The second line contains $$$2 \cdot n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_{2 \cdot n}$$$ ($$$1 \leq a_i \leq 10^9$$$), coordinates, written by Pavel in some order.
standard output
standard input
PyPy 3
Python
1,500
train_001.jsonl
cf6695fd8f2a5aaca0757edb38b1ac2c
256 megabytes
["4\n4 1 3 2 3 2 1 3", "3\n5 8 5 5 7 5"]
PASSED
n=int(input()) s=sorted(list(map(int,input().split()))) ans=(s[n-1]-s[0])*(s[2*n-1]-s[n]) for i in range(n):ans=min(ans,(s[2*n-1]-s[0])*(s[n-1+i]-s[i])) print(ans)
1532938500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["9\n7\n0", "0\n7"]
fe42c7f0222497ce3fff51b3676f42d1
NoteConsider the first sample. Overall, the first sample has 3 queries. The first query l = 2, r = 11 comes. You need to count f(2) + f(3) + f(5) + f(7) + f(11) = 2 + 1 + 4 + 2 + 0 = 9. The second query comes l = 3, r = 12. You need to count f(3) + f(5) + f(7) + f(11) = 1 + 4 + 2 + 0 = 7. The third query comes l = 4...
Recently, the bear started studying data structures and faced the following problem.You are given a sequence of integers x1, x2, ..., xn of length n and m queries, each of them is characterized by two integers li, ri. Let's introduce f(p) to represent the number of such indexes k, that xk is divisible by p. The answer ...
Print m integers β€” the answers to the queries on the order the queries appear in the input.
The first line contains integer n (1 ≀ n ≀ 106). The second line contains n integers x1, x2, ..., xn (2 ≀ xi ≀ 107). The numbers are not necessarily distinct. The third line contains integer m (1 ≀ m ≀ 50000). Each of the following m lines contains a pair of space-separated integers, li and ri (2 ≀ li ≀ ri ≀ 2Β·109) β€” t...
standard output
standard input
PyPy 2
Python
1,700
train_003.jsonl
475b326ad736ab4be71233af8461e00e
512 megabytes
["6\n5 5 7 10 14 15\n3\n2 11\n3 12\n4 4", "7\n2 3 5 7 11 4 8\n2\n8 10\n2 123"]
PASSED
from sys import stdin from collections import * MAX = 10000000 def fast2(): import os, sys, atexit range = xrange from cStringIO import StringIO as BytesIO sys.stdout = BytesIO() atexit.register(lambda: os.write(1, sys.stdout.getvalue())) return BytesIO(os.read(0, os.fstat(0).st_size)).readli...
1390577700
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["10\n0\n990\n7\n4"]
943ce230777aca97266c272bdb9b364c
Note In the first test case, we can rotate the subarray from index $$$3$$$ to index $$$6$$$ by an amount of $$$2$$$ (i.e. choose $$$l = 3$$$, $$$r = 6$$$ and $$$k = 2$$$) to get the optimal array: $$$$$$[1, 3, \underline{9, 11, 5, 7}] \longrightarrow [1, 3, \underline{5, 7, 9, 11}]$$$$$$ So the answer is $$$a_n - a_1 =...
Mainak has an array $$$a_1, a_2, \ldots, a_n$$$ of $$$n$$$ positive integers. He will do the following operation to this array exactly once: Pick a subsegment of this array and cyclically rotate it by any amount. Formally, he can do the following exactly once: Pick two integers $$$l$$$ and $$$r$$$, such that $$$1 \l...
For each test case, output a single integerΒ β€” the maximum value of $$$(a_n - a_1)$$$ that Mainak can obtain by doing the operation exactly once.
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 50$$$)Β β€” the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2000$$$). The second line of each test case contains $$$n$...
standard output
standard input
Python 3
Python
900
train_106.jsonl
8ff7a9ecfa540990f70763b4449a2aa3
256 megabytes
["5\n\n6\n\n1 3 9 11 5 7\n\n1\n\n20\n\n3\n\n9 99 999\n\n4\n\n2 1 8 1\n\n3\n\n2 1 5"]
PASSED
q = int(input()) minak = [] def findMax(n) : if (n == 1) : return 0 mxin = minak.index(max(minak)) mnin = minak.index(min(minak)) mx = 0 l = len(minak) for i in range(l-1) : mx = max(mx, minak[i]-minak[i+1]) mx = max(mx, max(minak[mxin]-minak[0], minak[n-1...
1662474900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["0\n2"]
a98f67141b341152fcf20d803cbd5409
NoteIn the first permutation, it is already sorted so no exchanges are needed.It can be shown that you need at least $$$2$$$ exchanges to sort the second permutation.$$$[3, 2, 4, 5, 1, 6, 7]$$$Perform special exchange on range ($$$1, 5$$$)$$$[4, 1, 2, 3, 5, 6, 7]$$$Perform special exchange on range ($$$1, 4$$$)$$$[1, 2...
Patrick likes to play baseball, but sometimes he will spend so many hours hitting home runs that his mind starts to get foggy! Patrick is sure that his scores across $$$n$$$ sessions follow the identity permutation (ie. in the first game he scores $$$1$$$ point, in the second game he scores $$$2$$$ points and so on). H...
For each test case, output one integer: the minimum number of special exchanges needed to sort the permutation.
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 integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) Β β€” the length of the given permutation. The second line of each te...
standard output
standard input
PyPy 3
Python
1,500
train_000.jsonl
d8498ad02add4a9f32695655e17a004d
256 megabytes
["2\n\n5\n\n1 2 3 4 5\n\n7\n\n3 2 4 5 1 6 7"]
PASSED
from math import * from collections import * from operator import itemgetter import bisect from heapq import * i = lambda: input() ii = lambda: int(input()) iia = lambda: list(map(int,input().split())) isa = lambda: list(input().split()) I = lambda:list(map(int,input().split())) chrIdx = lambda x: ord(x)-96 idxChr = la...
1594479900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["2", "12", "0"]
bcbe9d196a6a6048729d0f967a1e89ba
NoteIn the first sample there are two ways: the first way is not to add anything, the second way is to add a single edge from vertex 2 to vertex 5.
Olya has got a directed non-weighted graph, consisting of n vertexes and m edges. We will consider that the graph vertexes are indexed from 1 to n in some manner. Then for any graph edge that goes from vertex v to vertex u the following inequation holds: v &lt; u.Now Olya wonders, how many ways there are to add an arbi...
Print a single integer β€” the answer to the problem modulo 1000000007 (109 + 7).
The first line contains three space-separated integers n, m, k (2 ≀ n ≀ 106, 0 ≀ m ≀ 105, 1 ≀ k ≀ 106). The next m lines contain the description of the edges of the initial graph. The i-th line contains a pair of space-separated integers ui, vi (1 ≀ ui &lt; vi ≀ n) β€” the numbers of vertexes that have a directed edge fr...
standard output
standard input
Python 2
Python
2,200
train_017.jsonl
9d0e595f17f864a648a715287c6138fb
256 megabytes
["7 8 2\n1 2\n2 3\n3 4\n3 6\n4 5\n4 7\n5 6\n6 7", "7 0 2", "7 2 1\n1 3\n3 5"]
PASSED
from sys import stdin N = 10 ** 6 MOD = 10**9 + 7 def task(): n, m, k = map(int, stdin.readline().split()) Sum = [0] * (N + 1) Power = [0] * (N + 1) for i in xrange(m): u, v = map(int, stdin.readline().split()) if v - u == k + 1: Sum[u - 1] = 1 elif v - u != 1: ...
1368968400
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["3\n3\n2\n0\n2\n7"]
6b92f09df1e35edc80cf1cbf8494b41e
NoteIn the first test case you can remove the characters with indices $$$6$$$, $$$7$$$, and $$$9$$$ to get an even string "aabbddcc".In the second test case, each character occurs exactly once, so in order to get an even string, you must remove all characters from the string.In the third test case, you can get an even ...
A string $$$a=a_1a_2\dots a_n$$$ is called even if it consists of a concatenation (joining) of strings of length $$$2$$$ consisting of the same characters. In other words, a string $$$a$$$ is even if two conditions are satisfied at the same time: its length $$$n$$$ is even; for all odd $$$i$$$ ($$$1 \le i \le n - 1$$...
For each test case, print a single numberΒ β€” the minimum number of characters that must be removed to make $$$s$$$ even.
The first line of input data 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. Each test case consists of one string $$$s$$$ ($$$1 \le |s| \le 2 \cdot 10^5$$$), where $$$|s|$$$Β β€” the length of the string $$$s$$$. The string consists of...
standard output
standard input
PyPy 3-64
Python
1,300
train_105.jsonl
34b8409507d7dcce8d490c4f0d4651b0
256 megabytes
["6\n\naabbdabdccc\n\nzyx\n\naaababbb\n\naabbcc\n\noaoaaaoo\n\nbmefbmuyw"]
PASSED
import sys def f(val, ind): # print(val, ind) if ind == -1: return val - 1 if ind >= len(s) - 1: return val if s[ind] == s[ind + 1]: # print(1) return f(val + 1, ind + 2) else: # print(2) if a[ind + 1][s[ind]] == -1: val1...
1648737300
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["2\n7\n1"]
ca157773d06c7d192589218e2aad6431
NoteIn the first testcase the temperature after $$$2$$$ poured cups: $$$1$$$ hot and $$$1$$$ cold is exactly $$$20$$$. So that is the closest we can achieve.In the second testcase the temperature after $$$7$$$ poured cups: $$$4$$$ hot and $$$3$$$ cold is about $$$29.857$$$. Pouring more water won't get us closer to $$$...
There are two infinite sources of water: hot water of temperature $$$h$$$; cold water of temperature $$$c$$$ ($$$c &lt; h$$$). You perform the following procedure of alternating moves: take one cup of the hot water and pour it into an infinitely deep barrel; take one cup of the cold water and pour it into an infini...
For each testcase print a single positive integerΒ β€” the minimum number of cups required to be poured into the barrel to achieve the closest temperature to $$$t$$$.
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 3 \cdot 10^4$$$)Β β€” the number of testcases. Each of the next $$$T$$$ lines contains three integers $$$h$$$, $$$c$$$ and $$$t$$$ ($$$1 \le c &lt; h \le 10^6$$$; $$$c \le t \le h$$$)Β β€” the temperature of the hot water, the temperature of the cold water and ...
standard output
standard input
Python 3
Python
1,700
train_000.jsonl
6b3c8bae79f91499819460ee98300140
256 megabytes
["3\n30 10 20\n41 15 30\n18 13 18"]
PASSED
from decimal import * getcontext().prec = 28 def solve(): if h == c: return 1 if (h + c) // 2 >= t: print(2) return ans = bs(1, 10 ** 6) a1 = getdif(ans) a2 = getdif(ans - 1) if abs(t - a1) < abs(t - a2): print(2 * ans - 1) else: ans -= 1 pri...
1590676500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["azaz", "-1"]
f5451b19cf835b1cb154253fbe4ea6df
null
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.You are given a string s, co...
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
The first input line contains integer k (1 ≀ k ≀ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≀ |s| ≀ 1000, where |s| is the length of string s.
standard output
standard input
PyPy 2
Python
1,000
train_017.jsonl
316a728e381872f3127868fbe729946d
256 megabytes
["2\naazz", "3\nabcabcabz"]
PASSED
from sys import stdin rr = lambda: stdin.readline().strip() rri = lambda: int(rr()) rrm = lambda: map(int, rr().split()) def rry(N = None, f = rri): for i in xrange(N or rri()): yield f() K = rri() S = rr() from collections import Counter count = Counter(S) if any(v % K for v in count.values()): print -1 ...
1346081400
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["5", "4", "100"]
6ffd7ba12fc6afeeeba80a73a8cf7bd1
NoteIn the first sample Sereja can pay 5 rubles, for example, if Dima constructs the following array: [1, 2, 1, 2, 2]. There are another optimal arrays for this test.In the third sample Sereja can pay 100 rubles, if Dima constructs the following array: [2].
Let's call an array consisting of n integer numbers a1, a2, ..., an, beautiful if it has the following property: consider all pairs of numbers x, y (x ≠ y), such that number x occurs in the array a and number y occurs in the array a; for each pair x, y must exist some position j (1 ≀ j &lt; n), such that at least one...
In a single line print maximum amount of money (in rubles) Sereja can pay. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
The first line contains two integers n and m (1 ≀ n ≀ 2Β·106, 1 ≀ m ≀ 105). Next m lines contain pairs of integers. The i-th line contains numbers qi, wi (1 ≀ qi, wi ≀ 105). It is guaranteed that all qi are distinct.
standard output
standard input
Python 2
Python
2,000
train_023.jsonl
60900c19d2f71169e5ebf50b00bffea3
256 megabytes
["5 2\n1 2\n2 3", "100 3\n1 2\n2 1\n3 1", "1 2\n1 1\n2 100"]
PASSED
#!/usr/bin/env python n, m = map(int, raw_input().split()) w = [] for _ in range(m): _, wi = map(int, raw_input().split()) w.append(wi) def calc(size, r): l = 1 while l+1 < r: v = (l + r) / 2 edges = v * (v-1) / 2 if v % 2 == 0: edges += v / 2 - 1 if edges < size: l = v else: r = v return l v...
1385479800
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["1 3\n2 3", "-1"]
084203d057faedd6a793eec38748aaa8
null
Valera conducts experiments with algorithms that search for shortest paths. He has recently studied the Floyd's algorithm, so it's time to work with it.Valera's already written the code that counts the shortest distance between any pair of vertexes in a non-directed connected graph from n vertexes and m edges, containi...
If the graph doesn't exist, print -1 on a single line. Otherwise, print m lines, each containing two integers u, v β€” the description of the edges of the graph Valera's been looking for.
The first line of the input contains three integers n, m, k (3 ≀ n ≀ 300, 2 ≀ k ≀ n , ) β€” the number of vertexes, the number of edges and the number of marked vertexes. The second line of the input contains k space-separated integers a1, a2, ... ak (1 ≀ ai ≀ n) β€” the numbers of the marked vertexes. It is guaranteed th...
standard output
standard input
PyPy 2
Python
2,200
train_024.jsonl
b4e9b764957d01118fe02c7c2b3c7538
256 megabytes
["3 2 2\n1 2", "3 3 2\n1 2"]
PASSED
import sys range = xrange input = raw_input n,m,k = [int(x) for x in input().split()] if n == k: print -1 sys.exit() A = [int(x) - 1 for x in input().split()] marked = [0]*n for a in A: marked[a] = 1 B = [i for i in range(n) if not marked[i]] free = B.pop() a = A.pop() if A else B.pop() b = A.pop() i...
1380641400
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
6 seconds
["+ 12 16\n\n- 6 10\n\n* 8 15\n\n/ 5 4\n\nsqrt 16\n\nsqrt 5\n\n^ 6 12\n\n! 2 3 7"]
166fbe42dd60317e85e699d9bed76957
NoteWe start by reading the first line containing the integer $$$n = 21$$$. Then, we ask for: $$$(12 + 16) \bmod 21 = 28 \bmod 21 = 7$$$. $$$(6 - 10) \bmod 21 = -4 \bmod 21 = 17$$$. $$$(8 \cdot 15) \bmod 21 = 120 \bmod 21 = 15$$$. $$$(5 \cdot 4^{-1}) \bmod 21 = (5 \cdot 16) \bmod 21 = 80 \bmod 21 = 17$$$. Square ...
Integer factorisation is hard. The RSA Factoring Challenge offered $$$$100\,000$$$ for factoring RSA-$$$1024$$$, a $$$1024$$$-bit long product of two prime numbers. To this date, nobody was able to claim the prize. We want you to factorise a $$$1024$$$-bit number.Since your programming language of choice might not offe...
You can print as many queries as you wish, adhering to the time limit (see the Interaction section for more details). When you think you know the answer, output a single line of form ! k p_1 p_2 ... p_k, where $$$k$$$ is the number of prime factors of $$$n$$$, and $$$p_i$$$ are the distinct prime factors. You may prin...
The only line contains a single integer $$$n$$$Β ($$$21 \leq n \leq 2^{1024}$$$). It is guaranteed that $$$n$$$ is a product of between $$$2$$$ and $$$10$$$ distinct prime numbers, all of form $$$4x + 3$$$ for some integer $$$x$$$.
standard output
standard input
Python 3
Python
3,200
train_003.jsonl
71cd896d09a297825b4fff80b3d25557
256 megabytes
["21\n\n7\n\n17\n\n15\n\n17\n\n11\n\n-1\n\n15"]
PASSED
import random import math n = int(input()) z = [n] for i in range(15): w = random.randint(1, n - 1) print('sqrt', w * w % n) v = int(input()) y = [] for x in z: y.append(math.gcd(w+v, x)) y.append(x // y[-1]) z = y z = list(set(z) - {1}) print('!', len(z), *z)
1546180500
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["7\n8\n62"]
a5063294f814f359f7ab6b7b801eaf3e
NoteThe trees in the example: In the first test case, one possible assignment is $$$a = \{1, 8\}$$$ which results in $$$|1 - 8| = 7$$$.In the second test case, one of the possible assignments is $$$a = \{1, 5, 9\}$$$ which results in a beauty of $$$|1 - 5| + |5 - 9| = 8$$$
Parsa has a humongous tree on $$$n$$$ vertices.On each vertex $$$v$$$ he has written two integers $$$l_v$$$ and $$$r_v$$$.To make Parsa's tree look even more majestic, Nima wants to assign a number $$$a_v$$$ ($$$l_v \le a_v \le r_v$$$) to each vertex $$$v$$$ such that the beauty of Parsa's tree is maximized.Nima's sens...
For each test case print the maximum possible beauty for Parsa's tree.
The first line contains an integer $$$t$$$ $$$(1\le t\le 250)$$$ β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ $$$(2\le n\le 10^5)$$$ β€” the number of vertices in Parsa's tree. The $$$i$$$-th of the following $$$n$$$ lines contai...
standard output
standard input
PyPy 3-64
Python
1,600
train_085.jsonl
b0cb01779c918672f785fe547ac56ba5
256 megabytes
["3\n2\n1 6\n3 8\n1 2\n3\n1 3\n4 6\n7 9\n1 2\n2 3\n6\n3 14\n12 20\n12 19\n2 12\n10 17\n3 17\n3 2\n6 5\n1 5\n2 6\n4 6"]
PASSED
import sys sys.setrecursionlimit(10 ** 5) input = sys.stdin.buffer.readline def dfs(par, x): for u in g[x]: if u == par: continue dfs(x, u) dp[par][0] += max(abs(a[par][0] - a[x][0]) + dp[x][0], abs(a[par][0] - a[x][1]) + dp[x][1]) dp[par][1] += max(abs(a[par][1] - a[x][...
1621866900
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
2 seconds
["-1", "10080"]
386345016773a06b9e190a55cc3717fa
null
Chilly Willy loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7. But Willy grew rather bored of such numbers, so he came up with a few games that were connected with them.Chilly Willy wants to find the minimum number of length n, such that it is simultaneously d...
Print a single integer β€” the answer to the problem without leading zeroes, or "-1" (without the quotes), if the number that meet the problem condition does not exist.
A single input line contains a single integer n (1 ≀ n ≀ 105).
standard output
standard input
Python 2
Python
1,400
train_014.jsonl
b3ef0372713c31683c2872ffcc86a064
256 megabytes
["1", "5"]
PASSED
n = input() if n < 3: print '-1' elif n == 3: print 210 else : x = pow(10, n - 1, 210) y = 210 - x print '1' + '0' * (n - 4) + "%03d" %y
1353857400
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
2e3006d663a3c7ad3781aba1e37be3ca
null
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dic...
For each test case, print one integerΒ β€” the index of the word $$$s$$$ in the dictionary.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$)Β β€” the number of test cases. Each test case consists of one line containing $$$s$$$Β β€” a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
standard output
standard input
PyPy 3-64
Python
800
train_107.jsonl
74c29a63fdbf6d8dd61daee63c626541
512 megabytes
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
PASSED
n = int(input()) li = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] di = {} y = 1 for i in li: for j in li: if i != j: di[i+j]=y y += 1 for i in range(n): print(di[input()])
1651502100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["7\n3\n3"]
7f502f2fd150a2ded948826960d123cd
NoteIn the first sample, two obstacles are at $$$(1, 2)$$$ and $$$(2,2)$$$. You can move the obstacle on $$$(2, 2)$$$ to $$$(2, 3)$$$, then to $$$(1, 3)$$$. The total cost is $$$u+v = 7$$$ coins. In the second sample, two obstacles are at $$$(1, 3)$$$ and $$$(2,2)$$$. You can move the obstacle on $$$(1, 3)$$$ to $$$(2...
There is a graph of $$$n$$$ rows and $$$10^6 + 2$$$ columns, where rows are numbered from $$$1$$$ to $$$n$$$ and columns from $$$0$$$ to $$$10^6 + 1$$$: Let's denote the node in the row $$$i$$$ and column $$$j$$$ by $$$(i, j)$$$.Initially for each $$$i$$$ the $$$i$$$-th row has exactly one obstacle β€” at node $$$(i, a_...
For each test case, output a single integerΒ β€” the minimal number of coins you need to spend to be able to reach node $$$(n, 10^6+1)$$$ from node $$$(1, 0)$$$ by moving through edges of this graph without passing through obstacles. It can be shown that under the constraints of the problem there is always a way to make s...
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β€” the number of test cases. The first line of each test case contains three integers $$$n$$$, $$$u$$$ and $$$v$$$ ($$$2 \le n \le 100$$$, $$$1 \le u, v \le 10^9$$$)Β β€” the number of rows in the graph and the numbers of coins needed to move vertica...
standard output
standard input
Python 3
Python
1,200
train_095.jsonl
22cd544adf02bb97ee02689e0a5db6bb
256 megabytes
["3\n2 3 4\n2 2\n2 3 4\n3 2\n2 4 3\n3 2"]
PASSED
import os , sys,time, collections , math , pprint , itertools as it , operator as op , bisect as bs ,functools as fn maxx , localsys , mod = float('inf'), 0 , int(1e9 + 7) nCr = lambda n, r: reduce(mul, range(n - r + 1, n + 1), 1) // factorial(r) ceil = lambda n , x: (n+x -1 )//x osi, oso = '/home/priyanshu/Docum...
1614519300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["2\n3"]
eb39ac8d703516c7f81f95a989791b21
NoteFor $$$3\times3$$$ grid ponies can make two following moves:
One evening Rainbow Dash and Fluttershy have come up with a game. Since the ponies are friends, they have decided not to compete in the game but to pursue a common goal. The game starts on a square flat grid, which initially has the outline borders built up. Rainbow Dash and Fluttershy have flat square blocks with size...
For each grid of the game print the minimum number of turns required to build a chess coloring pattern out of blocks on it.
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 100$$$): the number of grids of the games. Each of the next $$$T$$$ lines contains a single integer $$$n$$$ ($$$1 \le n \le 10^9$$$): the size of the side of the grid of the game.
standard output
standard input
PyPy 3
Python
800
train_007.jsonl
2357f95e7ad23c982013a9dabec70963
256 megabytes
["2\n3\n4"]
PASSED
for t in range(int(input())): a = int(input()) if (a == 1 or a == 2): print(a) else: print(2+(a-2)//2)
1596810900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["YES\nNO\nYES"]
fc547fc83ebbcc3c058a069ef9fef62c
NoteIn the first testcase strings "ABCAB" or "BCABA" satisfy the requirements. There exist other possible strings.In the second testcase there's no way to put adjacent equal letters if there's no letter that appears at least twice.In the third testcase string "CABBCC" satisfies the requirements. There exist other possi...
You are given four integer values $$$a$$$, $$$b$$$, $$$c$$$ and $$$m$$$.Check if there exists a string that contains: $$$a$$$ letters 'A'; $$$b$$$ letters 'B'; $$$c$$$ letters 'C'; no other letters; exactly $$$m$$$ pairs of adjacent equal letters (exactly $$$m$$$ such positions $$$i$$$ that the $$$i$$$-th letter ...
For each testcase print "YES" if there exists a string that satisfies all the requirements. Print "NO" if there are no such strings. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of testcases. Each of the next $$$t$$$ lines contains the description of the testcaseΒ β€” four integers $$$a$$$, $$$b$$$, $$$c$$$ and $$$m$$$ ($$$1 \le a, b, c \le 10^8$$$; $$$0 \le m \le 10^8$$$).
standard output
standard input
Python 3
Python
1,100
train_088.jsonl
590beb65e026817c7e8fe435606309e8
256 megabytes
["3\n2 2 1 0\n1 1 1 1\n1 2 3 2"]
PASSED
for t in range(int(input())): a,b,c,d=map(int,input().split()) l=[a,b,c];l.sort();m=l[2]-(l[0]+l[1]) n=0 if m<=0 else m-1 q="YES" if n<=d and sum(l)-3>=d else "NO" print(q)
1632148500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["0\n1 2\n2 3 5\n1 2 5\n3 2 3 4\n1 4\n-1"]
c313a305cc229ec23b19c6e4dd46b57b
NoteIn the first test case, $$$b$$$ is empty. So string $$$s$$$ is not changed. Now $$$s^p = s_1 s_2 = \mathtt{10}$$$, and $$$s^q = s_3s_4 = \mathtt{10}$$$.In the second test case, $$$b=[3,5]$$$. Initially $$$s_3=\mathtt{0}$$$, and $$$s_5=\mathtt{1}$$$. On performing the operation, we simultaneously set $$$s_3=\mathtt{...
Everool has a binary string $$$s$$$ of length $$$2n$$$. Note that a binary string is a string consisting of only characters $$$0$$$ and $$$1$$$. He wants to partition $$$s$$$ into two disjoint equal subsequences. He needs your help to do it.You are allowed to do the following operation exactly once. You can choose an...
For each test case, follow the following output format. If there is no solution, print $$$-1$$$. Otherwise, In the first line, print an integer $$$m$$$ ($$$0 \leq m \leq 2n$$$), followed by $$$m$$$ distinct indices $$$b_1$$$, $$$b_2$$$, ..., $$$b_m$$$(in increasing order). In the second line, print $$$n$$$ distinct...
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^5$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$), where $$$2n$$$ is the length of the binary string. The second lin...
standard output
standard input
PyPy 3-64
Python
2,200
train_103.jsonl
be6c1a1808a62a937b0204125c30db6c
256 megabytes
["4\n2\n1010\n3\n100010\n2\n1111\n2\n1110"]
PASSED
import sys import copy input = sys.stdin.readline print = sys.stdout.write for i in range(int(input())): a = int(input()) b = list(input().strip()) stat = 0 for i in range(len(b)): if b[i] == "1": stat+=1 if stat%2 == 1: print("-1\n") continue tb...
1665412500
[ "geometry", "strings" ]
[ 0, 1, 0, 0, 0, 0, 1, 0 ]
2 seconds
["1.75", "12", "3.141592"]
89ef92879ce322251c9734b22a413d36
NoteIn the first example, you should predict teams 1 and 4 to win in round 1, and team 1 to win in round 2. Recall that the winner you predict in round 2 must also be predicted as a winner in round 1.
The annual college sports-ball tournament is approaching, which for trademark reasons we'll refer to as Third Month Insanity. There are a total of 2N teams participating in the tournament, numbered from 1 to 2N. The tournament lasts N rounds, with each round eliminating half the teams. The first round consists of 2N - ...
Print the maximum possible expected score over all possible brackets. Your answer must be correct to within an absolute or relative error of 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer will be considered correct, if .
Input will begin with a line containing N (2 ≀ N ≀ 6). 2N lines follow, each with 2N integers. The j-th column of the i-th row indicates the percentage chance that team i will defeat team j, unless i = j, in which case the value will be 0. It is guaranteed that the i-th column of the j-th row plus the j-th column of th...
standard output
standard input
Python 2
Python
2,100
train_009.jsonl
fe69a3ad2a471eb90fa8197125a83674
256 megabytes
["2\n0 40 100 100\n60 0 40 40\n0 60 0 45\n0 60 55 0", "3\n0 0 100 0 100 0 0 0\n100 0 100 0 0 0 100 100\n0 0 0 100 100 0 0 0\n100 100 0 0 0 0 100 100\n0 100 0 100 0 0 100 0\n100 100 100 100 100 0 0 0\n100 0 100 0 0 100 0 0\n100 0 100 0 100 100 100 0", "2\n0 21 41 26\n79 0 97 33\n59 3 0 91\n74 67 9 0"]
PASSED
import sys N = int(sys.stdin.readline()) P = [] for i in range(2 ** N) : P.append([int(x)/100. for x in sys.stdin.readline().split()]) Prounds = [[1 for i in range(2**N)] for j in range(N+1) ] rounds = [[0 for i in range(2**N)] for j in range(N+1) ] for i in range(1, N+1) : for player_a in range(2 ** N) : to...
1505583300
[ "probabilities", "trees" ]
[ 0, 0, 0, 0, 0, 1, 0, 1 ]
2 seconds
["2\n4\n1\n11"]
3888f8d6cce7037169c340a9fb508cbe
null
Given an undirected connected graph with $$$n$$$ vertices and $$$m$$$ edges. The graph contains no loops (edges from a vertex to itself) and multiple edges (i.e. no more than one edge between each pair of vertices). The vertices of the graph are numbered from $$$1$$$ to $$$n$$$. Find the number of paths from a vertex $...
For each test case, output a single numberΒ β€” the number of paths from $$$s$$$ to $$$t$$$ such that their length differs from the length of the shortest path by no more than $$$1$$$. Since this number may be too large, output it modulo $$$10^9 + 7$$$.
The first line of test contains the number $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€”the number of test cases in the test. Before each test case, there is a blank line. The first line of test case contains two numbers $$$n, m$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$1 \le m \le 2 \cdot 10^5$$$)Β β€”the number of vertices and edges...
standard output
standard input
PyPy 3-64
Python
2,100
train_104.jsonl
d7d90b128bd0c728500ef76b96431ae5
256 megabytes
["4\n\n\n\n\n4 4\n\n1 4\n\n1 2\n\n3 4\n\n2 3\n\n2 4\n\n\n\n\n6 8\n\n6 1\n\n1 4\n\n1 6\n\n1 5\n\n1 2\n\n5 6\n\n4 6\n\n6 3\n\n2 6\n\n\n\n\n5 6\n\n1 3\n\n3 5\n\n5 4\n\n3 1\n\n4 2\n\n2 1\n\n1 4\n\n\n\n\n8 18\n\n5 1\n\n2 1\n\n3 1\n\n4 2\n\n5 2\n\n6 5\n\n7 3\n\n8 4\n\n6 4\n\n8 7\n\n1 4\n\n4 7\n\n1 6\n\n6 7\n\n3 8\n\n8 5\n\n4...
PASSED
import copy import io, os, sys from sys import stdin, stdout def input(): return stdin.readline().rstrip("\r\n") def read_int_list(): return list(map(int, input().split())) def read_int_tuple(): return tuple(map(int, input().split())) def read_int(): return int(input()) from itertools import permutations, ch...
1646750100
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["29\n23\n35\n25\n35"]
d70a774248d9137c30f33fb37c6467a7
NoteAfter the first query $$$a$$$ is equal to $$$[1, 2, 2, 4, 5]$$$, and the answer is $$$29$$$ because we can split each of the subsegments the following way: $$$[1; 1]$$$: $$$[1]$$$, 1 block; $$$[1; 2]$$$: $$$[1] + [2]$$$, 2 blocks; $$$[1; 3]$$$: $$$[1] + [2, 2]$$$, 2 blocks; $$$[1; 4]$$$: $$$[1] + [2, 2] + [4]$...
Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.The awesomeness of an array is the minimum number of blocks of consecutive identical numbers in which the array could be split. For example, the awesomeness of an arra...
Print the answer to each query on a new line.
In the first line you are given with two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$)Β β€” the array $$$a$$$. In the next $$$m$$$ lines you are given the descriptions of queries. Each line contains two integers ...
standard output
standard input
PyPy 3-64
Python
1,700
train_082.jsonl
83495944839b5011b7b1c6873e738bce
256 megabytes
["5 5\n1 2 3 4 5\n3 2\n4 2\n3 1\n2 1\n2 2"]
PASSED
import sys a = list(map(int, sys.stdin.readline().split())) n = a[0] m = a[1] a = list(map(int, sys.stdin.readline().split())) count = 0 s = [] for i in range(n): if i == 0: s.append(0) elif a[i] == a[i - 1]: s.append(0) elif a[i] != a[i - 1]: s.append(1) count = n * ...
1661006100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["b\nazaz\nby"]
c02357c4d959e300f970f66f9b3107eb
NoteIn the first test case: Alice makes the first move and must change the only letter to a different one, so she changes it to 'b'.In the second test case: Alice changes the first letter to 'a', then Bob changes the second letter to 'z', Alice changes the third letter to 'a' and then Bob changes the fourth letter to '...
Homer has two friends Alice and Bob. Both of them are string fans. One day, Alice and Bob decide to play a game on a string $$$s = s_1 s_2 \dots s_n$$$ of length $$$n$$$ consisting of lowercase English letters. They move in turns alternatively and Alice makes the first move.In a move, a player must choose an index $$$i...
For each test case, print the final string in a single line.
Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 1000$$$) Β β€” the number of test cases. Description of the test cases follows. The only line of each test case contains a single string $$$s$$$ ($$$1 \leq |s| \leq 50$$$) consisting of lowercase English letters.
standard output
standard input
Python 3
Python
800
train_101.jsonl
1bc25b74f2fb82300de7d89b1392d18b
512 megabytes
["3\na\nbbbb\naz"]
PASSED
t = int(input()) while t > 0: s = str(input()) arr = [] for i in range(len(s)): if i % 2 == 0 and s[i] != 'a': arr.append('a') elif i % 2 == 0 and s[i] == 'a': arr.append('b') elif i % 2 == 1 and s[i] != 'z': arr.append('z') elif...
1612708500
[ "games", "strings" ]
[ 1, 0, 0, 0, 0, 0, 1, 0 ]