prob_desc_time_limit
stringclasses
21 values
prob_desc_sample_outputs
stringlengths
5
329
src_uid
stringlengths
32
32
prob_desc_notes
stringlengths
31
2.84k
βŒ€
prob_desc_description
stringlengths
121
3.8k
prob_desc_output_spec
stringlengths
17
1.16k
βŒ€
prob_desc_input_spec
stringlengths
38
2.42k
βŒ€
prob_desc_output_to
stringclasses
3 values
prob_desc_input_from
stringclasses
3 values
lang
stringclasses
5 values
lang_cluster
stringclasses
1 value
difficulty
int64
-1
3.5k
βŒ€
file_name
stringclasses
111 values
code_uid
stringlengths
32
32
prob_desc_memory_limit
stringclasses
11 values
prob_desc_sample_inputs
stringlengths
5
802
exec_outcome
stringclasses
1 value
source_code
stringlengths
29
58.4k
prob_desc_created_at
stringlengths
10
10
tags
listlengths
1
5
hidden_unit_tests
stringclasses
1 value
labels
listlengths
8
8
1 second
["252", "2"]
c408b1d198c7c88fc635936d960c962a
NoteIn the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself.In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself.
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming.Little Tommy has n lanterns and Big Banba...
Print a single integerΒ β€” the brightness of the chosen pair.
The first line contains two space-separated integers n and m (2 ≀ n, m ≀ 50). The second line contains n space-separated integers a1, a2, ..., an. The third line contains m space-separated integers b1, b2, ..., bm. All the integers range from  - 109 to 109.
standard output
standard input
Python 3
Python
1,400
train_007.jsonl
14763b37feb2c8be8f7c21dc565cfcbb
256 megabytes
["2 2\n20 18\n2 14", "5 3\n-1 0 1 2 3\n-1 0 1"]
PASSED
n, m = [int(x) for x in input().split()] lstT = [int(x) for x in input().split()] lstB = [int(x) for x in input().split()] z=-9999999999999999999999999999 T=0 B=0 for i in range(n): for j in range(m): if z<lstT[i]*lstB[j]: T=i B=j ...
1518609900
[ "games" ]
[ 1, 0, 0, 0, 0, 0, 0, 0 ]
1 second
["1.000000000000", "-1", "1.250000000000"]
1bcf130890495bcca67b4b0418476119
NoteYou can see following graphs for sample 1 and sample 3.
There is a polyline going through points (0, 0) – (x, x) – (2x, 0) – (3x, x) – (4x, 0) – ... - (2kx, 0) – (2kx + x, x) – .... We know that the polyline passes through the point (a, b). Find minimum positive value x such that it is true or determine that there is no such x.
Output the only line containing the answer. Your answer will be considered correct if its relative or absolute error doesn't exceed 10 - 9. If there is no such x then output  - 1 as the answer.
Only one line containing two positive integers a and b (1 ≀ a, b ≀ 109).
standard output
standard input
Python 3
Python
1,700
train_026.jsonl
5daf35b34ff84e5c03e13edc0a45162e
256 megabytes
["3 1", "1 3", "4 1"]
PASSED
from math import floor def main(): a, b = map(int, input().split()) if (b > a): print(-1) return y = (a + b) / 2 k = y // b print(y / k) main()
1442416500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["0 1\n1 1\n0 7"]
09625e65e62fc1c618d12969932508de
NoteIn the first test case, Alice serves the ball and spends $$$1$$$ stamina. Then Bob returns the ball and also spends $$$1$$$ stamina. Alice can't return the ball since she has no stamina left and loses the play. Both of them ran out of stamina, so the game is over with $$$0$$$ Alice's wins and $$$1$$$ Bob's wins.In ...
Alice and Bob play ping-pong with simplified rules.During the game, the player serving the ball commences a play. The server strikes the ball then the receiver makes a return by hitting the ball back. Thereafter, the server and receiver must alternately make a return until one of them doesn't make a return.The one who ...
For each test case, print two integersΒ β€” the resulting number of Alice's and Bob's wins, if both of them play optimally.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of test cases. The first and only line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^6$$$)Β β€” Alice's and Bob's initial stamina.
standard output
standard input
PyPy 2
Python
null
train_006.jsonl
057db5c181c20c60a13051da023f68b6
256 megabytes
["3\n1 1\n2 1\n1 7"]
PASSED
from collections import Counter, defaultdict, deque import bisect from sys import stdin, stdout from itertools import repeat import math def inp(force_list=False): re = map(int, raw_input().split()) if len(re) == 1 and not force_list: return re[0] return re def inst(): return raw_input().stri...
1606746900
[ "math", "games" ]
[ 1, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["8\n2\n4"]
a4f183775262fdc42dc5fc621c196ec9
NoteIn the first query you have to get string $$$\text{DSAWW}\underline{D}\text{AW}$$$.In second and third queries you can not decrease the area of $$$Grid(s)$$$.
You have a string $$$s$$$ β€” a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands: 'W' β€” move one cell up; 'S' β€” move one cell down; 'A' β€” move one cell left; 'D' β€” move one cell right. Let $$$Grid(s)$$$ be the grid of minimum possible area s...
Print $$$T$$$ integers: one per query. For each query print the minimum area of $$$Grid(s)$$$ you can achieve.
The first line contains one integer $$$T$$$ ($$$1 \le T \le 1000$$$) β€” the number of queries. Next $$$T$$$ lines contain queries: one per line. This line contains single string $$$s$$$ ($$$1 \le |s| \le 2 \cdot 10^5$$$, $$$s_i \in \{\text{W}, \text{A}, \text{S}, \text{D}\}$$$) β€” the sequence of commands. It's guarantee...
standard output
standard input
PyPy 2
Python
2,100
train_004.jsonl
74f687aef1c1cd1ad27b5c6c7f0e8b99
256 megabytes
["3\nDSAWWAW\nD\nWA"]
PASSED
import sys import math import bisect import atexit import io import heapq from collections import defaultdict, Counter MOD = int(1e9+7) # n = map(int, raw_input().split()) # input = map(int, raw_input().split()) def main(): n = map(int, raw_input().split())[0] for i in range(n): st = raw_input() ...
1565188500
[ "math", "strings" ]
[ 0, 0, 0, 1, 0, 0, 1, 0 ]
4 seconds
["42", "30"]
5179d7554a08d713da7597db41f0ed43
NoteThe following figure shows all $$$10$$$ possible paths for which one endpoint is an ancestor of another endpoint. The sum of beauties of all these paths is equal to $$$42$$$:
Kamil likes streaming the competitive programming videos. His MeTube channel has recently reached $$$100$$$ million subscribers. In order to celebrate this, he posted a video with an interesting problem he couldn't solve yet. Can you help him?You're given a tree β€” a connected undirected graph consisting of $$$n$$$ vert...
Output the sum of the beauties on all paths $$$(u, v)$$$ such that $$$u$$$ is ancestor of $$$v$$$. This sum should be printed modulo $$$10^9 + 7$$$.
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 100\,000$$$) β€” the number of vertices in the tree. The following line contains $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$0 \le x_i \le 10^{12}$$$). The value $$$x_v$$$ denotes the beauty of vertex $$$v$$$. The following $$$n - 1$$$ lines describe th...
standard output
standard input
PyPy 2
Python
2,000
train_023.jsonl
1f4f2d3e8d4997aa850c286fe1a02901
768 megabytes
["5\n4 5 6 0 8\n1 2\n1 3\n1 4\n4 5", "7\n0 2 3 0 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7"]
PASSED
from __future__ import division, print_function from collections import deque def main(): def gcd(a,b): if a<b: a,b=b,a while b: a,b=b,a%b return a n=int(input()) val=list(map(int,input().split())) gcds=[ {} for _ in range(n) ] edges={} for i ...
1569143100
[ "number theory", "math", "trees", "graphs" ]
[ 0, 0, 1, 1, 1, 0, 0, 1 ]
1 second
["01001"]
332902284154faeaf06d5d05455b7eb6
null
Little Chris is a huge fan of linear algebra. This time he has been given a homework about the unusual square of a square matrix.The dot product of two integer number vectors x and y of size n is the sum of the products of the corresponding components of the vectors. The unusual square of an n × n square matrix A is de...
Let the number of the 3rd type queries in the input be m. Output a single string s of length m, where the i-th symbol of s is the value of the unusual square of A for the i-th query of the 3rd type as it appears in the input.
The first line of input contains an integer n (1 ≀ n ≀ 1000), the number of rows and the number of columns in the matrix A. The next n lines describe the matrix: the i-th line contains n space-separated bits and describes the i-th row of A. The j-th number of the i-th line aij (0 ≀ aij ≀ 1) is the element on the inters...
standard output
standard input
Python 3
Python
1,600
train_013.jsonl
26e3467d20650f5f137acf9338ed9db5
256 megabytes
["3\n1 1 1\n0 1 1\n1 0 0\n12\n3\n2 3\n3\n2 2\n2 2\n1 3\n3\n3\n1 2\n2 1\n1 1\n3"]
PASSED
from sys import stdin n = int(stdin.readline()) dot = 0 j = 0 for i in range(n): line = stdin.readline() if line[j] == '1': dot ^= 1 j += 2 out = [] stdin.readline() for query in stdin: if len(query) < 3: out.append('1' if dot else '0') else: dot ^= 1 print(''.join(out))
1395502200
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["1 -1 3 4"]
b08f925e09a9c2e7ccc6a8c5c143fc5f
NoteIf initially Pak Chanek's left hand is on vertex $$$1$$$ and his right hand is on vertex $$$5$$$, Pak Chanek can do the following moves: Move his right hand to vertex $$$4$$$ in $$$1$$$ second. Move his left hand to vertex $$$2$$$ in $$$2$$$ seconds. Move his left hand to vertex $$$4$$$ in $$$1$$$ second. In to...
Pak Chanek is playing one of his favourite board games. In the game, there is a directed graph with $$$N$$$ vertices and $$$M$$$ edges. In the graph, edge $$$i$$$ connects two different vertices $$$U_i$$$ and $$$V_i$$$ with a length of $$$W_i$$$. By using the $$$i$$$-th edge, something can move from $$$U_i$$$ to $$$V_i...
Output a line containing $$$N-1$$$ integers. The $$$j$$$-th integer represents the minimum time in seconds needed by Pak Chanek to end the game if initially Pak Chanek's left hand and right hand are placed on vertex $$$1$$$ and vertex $$$j+1$$$, or $$$-1$$$ if it is impossible.
The first line contains two integers $$$N$$$ and $$$M$$$ ($$$2 \leq N \leq 10^5$$$, $$$0 \leq M \leq 2 \cdot 10^5$$$) β€” the number of vertices and edges in the graph. The $$$i$$$-th of the next $$$M$$$ lines contains three integers $$$U_i$$$, $$$V_i$$$, and $$$W_i$$$ ($$$1 \le U_i, V_i \le N$$$, $$$U_i \neq V_i$$$, $$$...
standard output
standard input
PyPy 3-64
Python
1,800
train_093.jsonl
76c7a785a67de7d4e66b3123ddeb6ade
256 megabytes
["5 7\n1 2 2\n2 4 1\n4 1 4\n2 5 3\n5 4 1\n5 2 4\n2 1 1"]
PASSED
import sys from array import array from heapq import * class graph: def __init__(self, n): self.n = n self.gdict = [array('i') for _ in range(n + 1)] self.weight = [array('i') for _ in range(n + 1)] self.dir = [array('b') for _ in range(n + 1)] def add_edge(self, n...
1662298500
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["0", "2"]
b81e7a786e4083cf7188f718bc045a85
NoteIn the second sample Joe can act like this:The diamonds' initial positions are 4 1 3.During the first period of time Joe moves a diamond from the 1-th cell to the 2-th one and a diamond from the 3-th cell to his pocket.By the end of the first period the diamonds' positions are 3 2 2. The check finds no difference a...
It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive numbers from 1 to n from the left to the right.Unfortunately, Joe di...
Print a single number β€” the maximum number of diamonds Joe can steal.
The first line contains integers n, m and k (1 ≀ n ≀ 104, 1 ≀ m, k ≀ 109). The next line contains n numbers. The i-th number is equal to the amount of diamonds in the i-th cell β€” it is an integer from 0 to 105.
standard output
standard input
Python 3
Python
1,800
train_007.jsonl
8c9e73e8b6fb5e5c62105be1bded11e6
256 megabytes
["2 3 1\n2 3", "3 2 2\n4 1 3"]
PASSED
n, m, k = map(int, input().split()) a = list(map(int, input().split())) if n % 2 == 0: print('0') else: print(min(m // (n // 2 + 1) * k, min(a[::2]))) # Made By Mostafa_Khaled
1308236400
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["2\n80\n5\ncomposite", "58\n59\n78\n78\n2\nprime"]
8cf479fd47050ba96d21f3d8eb43c8f0
NoteThe hidden number in the first query is 30. In a table below you can see a better form of the provided example of the communication process.The hidden number is divisible by both 2 and 5. Thus, it must be composite. Note that it isn't necessary to know the exact value of the hidden number. In this test, the hidden ...
This is an interactive problem. In the output section below you will see the information about flushing the output.Bear Limak thinks of some hidden numberΒ β€” an integer from interval [2, 100]. Your task is to say if the hidden number is prime or composite.Integer x &gt; 1 is called prime if it has exactly two distinct d...
Up to 20 times you can ask a queryΒ β€” print an integer from interval [2, 100] in one line. You have to both print the end-of-line character and flush the output. After flushing you should read a response from the input. In any moment you can print the answer "prime" or "composite" (without the quotes). After that, flush...
After each query you should read one string from the input. It will be "yes" if the printed integer is a divisor of the hidden number, and "no" otherwise.
standard output
standard input
Python 3
Python
1,400
train_017.jsonl
65f48ef53786850316f3d6ea62b265bb
256 megabytes
["yes\nno\nyes", "no\nyes\nno\nno\nno"]
PASSED
counter = 0; for i in [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,4,9,25,49]: print(i); counter += (input() == 'yes'); if counter > 1: print("composite"); break; else: print("prime");
1465403700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["6\n1\n2"]
fb0a4c8f737c36596c2d8c1ae0d1e34e
NoteIn the first query, we have to take at least $$$6$$$ eggs because there are $$$5$$$ eggs with only toy inside and, in the worst case, we'll buy all of them.In the second query, all eggs have both a sticker and a toy inside, that's why it's enough to buy only one egg.In the third query, we have to buy both eggs: one...
Your favorite shop sells $$$n$$$ Kinder Surprise chocolate eggs. You know that exactly $$$s$$$ stickers and exactly $$$t$$$ toys are placed in $$$n$$$ eggs in total.Each Kinder Surprise can be one of three types: it can contain a single sticker and no toy; it can contain a single toy and no sticker; it can contain b...
Print $$$T$$$ integers (one number per query) β€” the minimum number of Kinder Surprise Eggs you have to buy to be sure that, whichever types they are, you'll obtain at least one sticker and one toy
The first line contains the single integer $$$T$$$ ($$$1 \le T \le 100$$$) β€” the number of queries. Next $$$T$$$ lines contain three integers $$$n$$$, $$$s$$$ and $$$t$$$ each ($$$1 \le n \le 10^9$$$, $$$1 \le s, t \le n$$$, $$$s + t \ge n$$$) β€” the number of eggs, stickers and toys. All queries are independent.
standard output
standard input
PyPy 3
Python
900
train_006.jsonl
07e67f263ee975feb396e9f7d7837706
256 megabytes
["3\n10 5 7\n10 10 10\n2 1 1"]
PASSED
for _ in range(int(input().strip())): n, s, t = map(int, input().strip().split()) if s == t == n: print(1) else: common = s+t-n print(max(s, t)-common+1)
1561905900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["2\n1 2\n2 3", "4\n1 2\n2 3\n3 4\n4 1"]
3f86b3cec02aafb24c5aeb2648cc3df9
null
During a recent research Berland scientists found out that there were n cities in Ancient Berland, joined by two-way paths. Any two cities are joined by no more than one path. No path joins a city with itself. According to a well-known tradition, the road network was built so that it would be impossible to choose three...
On the first line must be printed number m β€” the maximal number of roads in Berland. Then print m lines containing two numbers each β€” the numbers of cities that the given road joins. The cities are numbered with integers from 1 to n. If there are several variants of solving the problem, print any of them.
The first line contains an integer n (1 ≀ n ≀ 100) β€” the number of cities in Berland.
standard output
standard input
Python 3
Python
1,900
train_023.jsonl
69157ad433338658d945d09cab6f1303
256 megabytes
["3", "4"]
PASSED
###### https://codeforces.com/problemset/problem/41/E n = int(input()) a = list(range(1, n+1)) edge = [] used = [] for i, u in enumerate(a): for j in range(1, n, 2): if i + j >= n : continue ind = i+j edge.append([u, a[ind]]) print(len(edge)) for u, v in edge: ...
1289232000
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["hHheidi Hei", "bbbba ba", "aaabb ab"]
fa626fb33f04323ec2dbbc235cabf7d3
NoteAn occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5...
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she...
The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solution...
The first and only line of input contains a single integer n (1 ≀ n ≀ 1 000 000).
standard output
standard input
Python 3
Python
2,200
train_079.jsonl
bfdb3b5506c749b292c0228724db6f98
256 megabytes
["2", "4", "6"]
PASSED
def getstr(n): if n==1: return 'a','',1 elif n==2: return 'ab','b',2 else: if n%2==0: p,u,now=getstr((n-2)//2) c = chr(ord('a')+now) return p+c,c+u+c+c,now+1 else: p,u,now=getstr((n-1)//2) c = chr(ord('a')+now) ...
1495958700
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["2\n1 4\n4 1\n1\n4 2\n0\n0\n1\n2 10\n0"]
5f0f79e39aaf4abc8c7414990d1f8be1
NoteIn the first example, two possible ways to divide $$$a$$$ into permutations are $$$\{1\} + \{4, 3, 2, 1\}$$$ and $$$\{1,4,3,2\} + \{1\}$$$.In the second example, the only way to divide $$$a$$$ into permutations is $$$\{2,4,1,3\} + \{2,1\}$$$.In the third example, there are no possible ways.
The sequence of $$$m$$$ integers is called the permutation if it contains all integers from $$$1$$$ to $$$m$$$ exactly once. The number $$$m$$$ is called the length of the permutation.Dreamoon has two permutations $$$p_1$$$ and $$$p_2$$$ of non-zero lengths $$$l_1$$$ and $$$l_2$$$.Now Dreamoon concatenates these two pe...
For each test case, the first line of output should contain one integer $$$k$$$: the number of ways to divide $$$a$$$ into permutations $$$p_1$$$ and $$$p_2$$$. Each of the next $$$k$$$ lines should contain two integers $$$l_1$$$ and $$$l_2$$$ ($$$1 \leq l_1, l_2 \leq n, l_1 + l_2 = n$$$), denoting, that it is possible...
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10\,000$$$) denoting the number of test cases in the input. Each test case contains two lines. The first line contains one integer $$$n$$$ ($$$2 \leq n \leq 200\,000$$$): the length of $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$...
standard output
standard input
PyPy 3
Python
1,400
train_008.jsonl
5999fe995fe1ff8007f207f1cda16b1f
256 megabytes
["6\n5\n1 4 3 2 1\n6\n2 4 1 3 2 1\n4\n2 1 1 3\n4\n1 3 3 1\n12\n2 1 3 4 5 6 7 8 9 1 10 2\n3\n1 1 1"]
PASSED
import os, sys, atexit from io import BytesIO, StringIO input = BytesIO(os.read(0, os.fstat(0).st_size)).readline _OUTPUT_BUFFER = StringIO() sys.stdout = _OUTPUT_BUFFER @atexit.register def write(): sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) t = int(input()) while t: t += -1 n = int(input()) l...
1585924500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["io", "ooo"]
214cdb73c2fb5ab995eb5aec76e5f4fb
null
It is well known that Berland has n cities, which form the Silver ring β€” cities i and i + 1 (1 ≀ i &lt; n) are connected by a road, as well as the cities n and 1. The goverment have decided to build m new roads. The list of the roads to build was prepared. Each road will connect two cities. Each road should be a curve ...
If it is impossible to build the roads in such a way that no two roads intersect, output Impossible. Otherwise print m characters. i-th character should be i, if the road should be inside the ring, and o if the road should be outside the ring. If there are several solutions, output any of them.
The first line contains two integers n and m (4 ≀ n ≀ 100, 1 ≀ m ≀ 100). Each of the following m lines contains two integers ai and bi (1 ≀ ai, bi ≀ n, ai ≠ bi). No two cities will be connected by more than one road in the list. The list will not contain the roads which exist in the Silver ring.
standard output
standard input
Python 3
Python
2,200
train_006.jsonl
f92c26db33d04e7f848e57b8f11d9088
256 megabytes
["4 2\n1 3\n2 4", "6 3\n1 3\n3 5\n5 1"]
PASSED
n, m = map(int, input().split()) road = [[] for i in range(m)] for i in range(m): road[i] = [i] + list(map(int, input().split())) + ['NONE'] for i in road: if i[2] < i[1]: i[1], i[2] = i[2], i[1] i[1], i[2] = i[1] - 1, i[2] - 1 participation = [[] for i in range(m)] for i in range(len(road)): f...
1284130800
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["2\n3 4 \n4\n4 5 6 7"]
6e0ca509476a3efa3a352ca08c43023e
NoteIn the first sample case, closing any two spots is suitable.In the second sample case, closing only the spot $$$1$$$ is also suitable.
Arthur owns a ski resort on a mountain. There are $$$n$$$ landing spots on the mountain numbered from $$$1$$$ to $$$n$$$ from the top to the foot of the mountain. The spots are connected with one-directional ski tracks. All tracks go towards the foot of the mountain, so there are no directed cycles formed by the tracks...
For each test case, print a single integer $$$k$$$ ($$$0 \leq k \leq \frac{4}{7}n$$$)Β β€” the number of spots to be closed. In the next line, print $$$k$$$ distinct integersΒ β€” indices of all spots to be closed, in any order. If there are several answers, you may output any of them. Note that you don't have to minimize $$...
The first line contains a single positive integer $$$T$$$Β β€” the number of test cases. $$$T$$$ test case description follows. The first line of each description contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$)Β β€” the number of landing spots and tracks respectively. The following $$$m$$$ lines ...
standard output
standard input
PyPy 3
Python
2,500
train_014.jsonl
60417202e4069bfd0b129bf017b45bb2
512 megabytes
["2\n4 6\n1 2\n1 3\n2 3\n2 4\n3 4\n3 4\n7 6\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7"]
PASSED
import io import os from collections import Counter, defaultdict, deque import random from heapq import heappush, heappop, heapify def solve(N, M, tracks): stops = range(1, N + 1) graph = [[] for i in range(N + 1)] graphT = [[] for i in range(N + 1)] for u, v in tracks: graph[u].append(v) ...
1592491500
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["2 2"]
44542e73195573debb4ab113bab5ee23
null
Two villages are separated by a river that flows from the north to the south. The villagers want to build a bridge across the river to make it easier to move across the villages.The river banks can be assumed to be vertical straight lines x = a and x = b (0 &lt; a &lt; b).The west village lies in a steppe at point O = ...
Print two integers β€” the numbers of points on the left (west) and right (east) banks, respectively, between which you need to build a bridge. You can assume that the points on the west bank are numbered from 1 to n, in the order in which they are given in the input. Similarly, the points on the east bank are numbered f...
The first line contains integers n, m, a, b (1 ≀ n, m ≀ 105, 0 &lt; a &lt; b &lt; 106). The second line contains n integers in the ascending order: the i-th integer determines the coordinate of point Ai and equals yi (|yi| ≀ 106). The third line contains m integers in the ascending order: the i-th integer determines ...
standard output
standard input
Python 3
Python
1,900
train_016.jsonl
f67ff61d0f2a1dbc5a5a44804acf4e6e
256 megabytes
["3 2 3 5\n-2 -1 4\n-1 2\n7 3"]
PASSED
import sys from math import * def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) n, m, a, b = mints() A = list(mints()) B = list(mints()) l = list(mints()) j = -1 r = (1e100,-1,-1) for i in range(m): while not((j == -1 or a*B[i]-b*A[j] >= ...
1353938400
[ "geometry" ]
[ 0, 1, 0, 0, 0, 0, 0, 0 ]
3 seconds
["15 33\n6 6"]
2d1ad0dc72496b767b9f3d901b6aa36a
NoteFor the sample test case, we have a minimum sum equal to $$$G = 15$$$. One way this can be achieved is with the following assignment: The first pair of people get assigned to houses $$$5$$$ and $$$6$$$, giving us $$$f(1) = 5$$$; The second pair of people get assigned to houses $$$1$$$ and $$$4$$$, giving us $$$f(...
Welcome! Everything is fine.You have arrived in The Medium Place, the place between The Good Place and The Bad Place. You are assigned a task that will either make people happier or torture them for eternity.You have a list of $$$k$$$ pairs of people who have arrived in a new inhabited neighborhood. You need to assign ...
For each test case, output a single line containing two space-separated integers $$$G$$$ and $$$B$$$.
The first line of input contains a single integer $$$t$$$ ($$$1 \le t \le 500$$$) denoting the number of test cases. The next lines contain descriptions of the test cases. The first line of each test case contains a single integer $$$k$$$ denoting the number of pairs of people ($$$1 \le k \le 10^5$$$). The next $$$2k -...
standard output
standard input
PyPy 2
Python
2,000
train_024.jsonl
74090ff2fd340b555706f0b301910bcc
256 megabytes
["2\n3\n1 2 3\n3 2 4\n2 4 3\n4 5 6\n5 6 5\n2\n1 2 1\n1 3 2\n1 4 3"]
PASSED
from collections import Counter,defaultdict from sys import stdin, stdout raw_input = stdin.readline pr = stdout.write for t in xrange(input()): n=input() d=defaultdict(list) n*=2 for i in xrange(n-1): u,v,w=map(int, raw_input().split()) d[u].append((v,w)) d[v].append((u,w)) ...
1576386300
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
3 seconds
["5", "3", "2"]
fade6204af3e346db543f59d40a70ad6
null
One day, ZS the Coder wrote down an array of integers a with elements a1,  a2,  ...,  an.A subarray of the array a is a sequence al,  al  +  1,  ...,  ar for some integers (l,  r) such that 1  ≀  l  ≀  r  ≀  n. ZS the Coder thinks that a subarray of a is beautiful if the bitwise xor of all the elements in the subarray ...
Print the only integer c β€” the number of beautiful subarrays of the array a.
The first line contains two integers n and k (1 ≀ n ≀ 106, 1 ≀ k ≀ 109) β€” the number of elements in the array a and the value of the parameter k. The second line contains n integers ai (0 ≀ ai ≀ 109) β€” the elements of the array a.
standard output
standard input
PyPy 2
Python
2,100
train_055.jsonl
585078fcbaba8e6ad4ed8b2c74ab1446
512 megabytes
["3 1\n1 2 3", "3 2\n1 2 3", "3 3\n1 2 3"]
PASSED
import sys range = xrange input = raw_input L = [-1, -1] count = [0,0] def check(i): if L[i] == -1: L[i] = len(L) L.append(-1) L.append(-1) count.append(0) count.append(0) def add(x, i = 0, bits = 30): count[i] += 1 for bit in reversed(range(bits)): check(i)...
1461164400
[ "trees", "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 1 ]
1 second
["red\nred\ncyan\ncyan\ncyan\nred"]
5bc07d2efb7453e51f4931cc7ec3aac7
NoteIn the first example, there is one rearrangement that yields a number divisible by $$$60$$$, and that is $$$360$$$.In the second example, there are two solutions. One is $$$060$$$ and the second is $$$600$$$.In the third example, there are $$$6$$$ possible rearrangments: $$$025$$$, $$$052$$$, $$$205$$$, $$$250$$$, ...
Bob is a competitive programmer. He wants to become red, and for that he needs a strict training regime. He went to the annual meeting of grandmasters and asked $$$n$$$ of them how much effort they needed to reach red."Oh, I just spent $$$x_i$$$ hours solving problems", said the $$$i$$$-th of them. Bob wants to train h...
Output $$$n$$$ lines. For each $$$i$$$, output the following. If it is possible to rearrange the digits of $$$y_i$$$ such that the resulting number is divisible by $$$60$$$, output "red" (quotes for clarity). Otherwise, output "cyan".
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 418$$$)Β β€” the number of grandmasters Bob asked. Then $$$n$$$ lines follow, the $$$i$$$-th of which contains a single integer $$$y_i$$$Β β€” the number that Alice wrote down. Each of these numbers has between $$$2$$$ and $$$100$$$ digits '0' through '9'. Th...
standard output
standard input
Python 3
Python
1,000
train_001.jsonl
2ad746b6571d5eb1ab1f69d4a5e3eefe
256 megabytes
["6\n603\n006\n205\n228\n1053\n0000000000000000000000000000000000000000000000"]
PASSED
t = int(input()) for x in range(t): s = input() ans = 0 f = 0 fl = 0 for i in s: q = int(i) if i == '0': f += 1 elif q % 2 == 0 : fl = 1 ans += q if (ans % 3 == 0 and f and fl) or ans == 0 or (ans % 3 == 0 and f > 1): print('red') else: print('cyan')
1576595100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["1", "0"]
a34f2aa89fe0e78b495b20400d73acf1
NoteThe first test case corresponds to the tree shown in the statement. As we have seen before, we can transform the tree into a star with center at vertex $$$5$$$ by applying a single operation to vertices $$$2$$$, $$$4$$$, and $$$5$$$.In the second test case, the given tree is already a star with the center at vertex...
You are given a tree with $$$n$$$ vertices. You are allowed to modify the structure of the tree through the following multi-step operation: Choose three vertices $$$a$$$, $$$b$$$, and $$$c$$$ such that $$$b$$$ is adjacent to both $$$a$$$ and $$$c$$$. For every vertex $$$d$$$ other than $$$b$$$ that is adjacent to $$$...
Print a single integer Β β€” the minimum number of operations needed to transform the tree into a star. It can be proven that under the given constraints, it is always possible to transform the tree into a star using at most $$$10^{18}$$$ operations.
The first line contains an integer $$$n$$$ ($$$3 \le n \le 2 \cdot 10^5$$$) Β β€” the number of vertices in the tree. The $$$i$$$-th of the following $$$n - 1$$$ lines contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \le u_i, v_i \le n$$$, $$$u_i \neq v_i$$$) denoting that there exists an edge connecting vertices $$$u_...
standard output
standard input
PyPy 3
Python
2,800
train_005.jsonl
62ef7edca328924e63757b39c5d42156
256 megabytes
["6\n4 5\n2 6\n3 2\n1 2\n2 4", "4\n2 4\n4 1\n3 4"]
PASSED
import sys from collections import defaultdict def rl(): return sys.stdin.readline().strip() def BFS(s,nbrs): level = defaultdict(int) ind = 0 level[ind] += 1 frontier = [s] visited = {s} while frontier: next = [] ind += 1 for u in frontier: for v in nbrs[u...
1593873900
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
2 seconds
["-1\n6\n3\n2"]
a4be9b3484f3f24014392a1c3ad23f2f
NoteIn the first test case, there are no subarrays of length at least $$$2$$$, so the answer is $$$-1$$$.In the second test case, the whole array is dominated (by $$$1$$$) and it's the only dominated subarray.In the third test case, the subarray $$$a_4, a_5, a_6$$$ is the shortest dominated subarray.In the fourth test ...
Let's call an array $$$t$$$ dominated by value $$$v$$$ in the next situation.At first, array $$$t$$$ should have at least $$$2$$$ elements. Now, let's calculate number of occurrences of each number $$$num$$$ in $$$t$$$ and define it as $$$occ(num)$$$. Then $$$t$$$ is dominated (by $$$v$$$) if (and only if) $$$occ(v) &g...
Print $$$T$$$ integers β€” one per test case. For each test case print the only integer β€” the length of the shortest dominated subarray, or $$$-1$$$ if there are no such subarrays.
The first line contains single integer $$$T$$$ ($$$1 \le T \le 1000$$$) β€” the number of test cases. Each test case consists of two lines. The first line contains single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β€” the length of the array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$...
standard output
standard input
PyPy 2
Python
1,200
train_003.jsonl
039259d4e1197bfc0723d0a5937e69e9
256 megabytes
["4\n1\n1\n6\n1 2 3 4 5 1\n9\n4 1 2 4 5 4 3 2 1\n4\n3 3 3 3"]
PASSED
def count(b): freq={} for i in b: if(i in freq): freq[i]+=1 else: freq[i]=1 return freq if __name__=="__main__": t=int(input()) while t!=0: t-=1 n=int(input()) a=list() a=raw_input() if n==1: print(-1) ...
1573655700
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["1\n1 1 1\n2\n2 1\n11\n4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6"]
c3cd949c99e96c9da186a34d49bd6197
NoteIn the first test case, $$$\gcd(6,10)=2$$$, $$$\gcd(6,15)=3$$$ and $$$\gcd(10,15)=5$$$. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case.In the second test case there is only one element of each color, so the coloring...
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than $$$1$$$. For example, the following numbers are composite: $$$6$$$, $$$4$$$, $$$120$$$, $$$27$$$. The following numbers aren't: $$$1$$$, $$$2$$$, $$$3$$$, $$$17$$$, $$$97$$$.Alice is given a sequence...
For each test case print $$$2$$$ lines. The first line should contain a single integer $$$m$$$ ($$$1 \le m \le 11$$$) β€” the number of used colors. Consider colors to be numbered from $$$1$$$ to $$$m$$$. The second line should contain any coloring that satisfies the above conditions. Print $$$n$$$ integers $$$c_1, c_2, ...
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β€” the amount of numbers in a sequence $$$a$$$. The second line of the test case...
standard output
standard input
PyPy 3
Python
1,400
train_010.jsonl
7968018c0d576e10c8520a27ce7d92d5
512 megabytes
["3\n3\n6 10 15\n2\n4 9\n23\n437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961"]
PASSED
def answer(n,A): dp=[1]*32 dp[0]=dp[1]=0 for i in range(2,32): if dp[i]==1: p=2*i while p<=31: if dp[p]==1: dp[p]=0 p+=i count=1 res=[0]*n for i in range(2,32): if dp[i]==1: flag=0 ...
1585661700
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["4\n5\n6\n0\n12"]
7458f44802c134de6fed7b4de84ea68c
NoteIn the first test case, there exists only $$$3$$$ strings of length $$$3$$$, which has exactly $$$1$$$ symbol, equal to "1". These strings are: $$$s_1 = $$$"100", $$$s_2 = $$$"010", $$$s_3 = $$$"001". The values of $$$f$$$ for them are: $$$f(s_1) = 3, f(s_2) = 4, f(s_3) = 3$$$, so the maximum value is $$$4$$$ and t...
Ayoub thinks that he is a very smart person, so he created a function $$$f(s)$$$, where $$$s$$$ is a binary string (a string which contains only symbols "0" and "1"). The function $$$f(s)$$$ is equal to the number of substrings in the string $$$s$$$ that contains at least one symbol, that is equal to "1".More formally,...
For every test case print one integer numberΒ β€” the maximum value of $$$f(s)$$$ over all strings $$$s$$$ of length $$$n$$$, which has exactly $$$m$$$ symbols, equal to "1".
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$) Β β€” the number of test cases. The description of the test cases follows. The only line for each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n \leq 10^{9}$$$, $$$0 \leq m \leq n$$$)Β β€” the...
standard output
standard input
PyPy 3
Python
1,700
train_010.jsonl
4da03af02b617c514d497ffc15be614b
256 megabytes
["5\n3 1\n3 2\n3 3\n4 0\n5 2"]
PASSED
""" #If FastIO not needed, used this and don't forget to strip #import sys, math #input = sys.stdin.readline """ import os import sys from io import BytesIO, IOBase import heapq as h from bisect import bisect_left, bisect_right from types import GeneratorType BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 ...
1581604500
[ "math", "strings" ]
[ 0, 0, 0, 1, 0, 0, 1, 0 ]
2 seconds
["5.000000000000000\n3.000000000000000\n0.000000000000000\n1.500000000000000\n2.000000000000000"]
2863d7304de4a07a8f6cd95bffaf590c
Note The 1-st point is always in the shade; the 2-nd point is in the shade while light source is moving from $$$(3, -3)$$$ to $$$(6, -3)$$$; the 3-rd point is in the shade while light source is at point $$$(6, -3)$$$. the 4-th point is in the shade while light source is moving from $$$(1, -3)$$$ to $$$(2.5, -3)$$$ ...
There is a light source on the plane. This source is so small that it can be represented as point. The light source is moving from point $$$(a, s_y)$$$ to the $$$(b, s_y)$$$ $$$(s_y &lt; 0)$$$ with speed equal to $$$1$$$ unit per second. The trajectory of this light source is a straight segment connecting these two poi...
Print $$$q$$$ lines. The $$$i$$$-th line should contain one real number β€” total time of the $$$i$$$-th point being in the shade, while the light source is moving from $$$(a, s_y)$$$ to the $$$(b, s_y)$$$. The answer is considered as correct if its absolute of relative error doesn't exceed $$$10^{-6}$$$.
First line contains three space separated integers $$$s_y$$$, $$$a$$$ and $$$b$$$ ($$$-10^9 \le s_y &lt; 0$$$, $$$1 \le a &lt; b \le 10^9$$$) β€” corresponding coordinates of the light source. Second line contains single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β€” number of segments in the fence. Next $$$n$$$ line...
standard output
standard input
PyPy 2
Python
2,400
train_056.jsonl
970ad33eb15b8e23250c2b5a384d1b58
256 megabytes
["-3 1 6\n2\n2 4\n6 7\n5\n3 1\n1 3\n6 1\n6 4\n7 6"]
PASSED
from __future__ import division import sys range = xrange input = sys.stdin.readline sy,a,b = [int(x) for x in input().split()] n = int(input()) inp = [int(x) for line in sys.stdin for x in line.split()] ii = 0 L = [] R = [] for _ in range(n): l = inp[ii] r = inp[ii+1] ii+=2 L.append(l) R.append...
1533307500
[ "geometry" ]
[ 0, 1, 0, 0, 0, 0, 0, 0 ]
1 second
["42", "428101984"]
0ffa96d83e63d20bdfa2ecbf535adcdd
NoteConsider the first example.Vova can choose to remove $$$1$$$, $$$0$$$, $$$7$$$, $$$10$$$, $$$07$$$, or $$$107$$$. The results are $$$07$$$, $$$17$$$, $$$10$$$, $$$7$$$, $$$1$$$, $$$0$$$. Their sum is $$$42$$$.
Sometimes it is not easy to come to an agreement in a bargain. Right now Sasha and Vova can't come to an agreement: Sasha names a price as high as possible, then Vova wants to remove as many digits from the price as possible. In more details, Sasha names some integer price $$$n$$$, Vova removes a non-empty substring of...
In the only line print the required sum modulo $$$10^9 + 7$$$.
The first and only line contains a single integer $$$n$$$ ($$$1 \le n &lt; 10^{10^5}$$$).
standard output
standard input
PyPy 3
Python
1,700
train_037.jsonl
f8d95d09ad196d044975066ebe7d6ff3
256 megabytes
["107", "100500100500"]
PASSED
s=input() mod=int(1e9+7) l=len(s) a,b=0,0 ss=s[::-1] for i in range(l): c=int(ss[i]) p=l-1-i a+=p*(p+1)//2*c*pow(10,i,mod) a+=b*c a%=mod b+=(i+1)*pow(10,i,mod) b%=mod print(a)
1601827500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["1 3 2", "4 1 2 3", "3 1 2 4 5"]
e29742df22068606228db4dda8a40df5
null
You are given a directed acyclic graph with n vertices and m edges. There are no self-loops or multiple edges between any pair of vertices. Graph can be disconnected.You should assign labels to all vertices in such a way that: Labels form a valid permutation of length n β€” an integer sequence such that each integer fro...
Print n numbers β€” lexicographically smallest correct permutation of labels of vertices.
The first line contains two integer numbers n, m (2 ≀ n ≀ 105, 1 ≀ m ≀ 105). Next m lines contain two integer numbers v and u (1 ≀ v, u ≀ n, v ≠ u) β€” edges of the graph. Edges are directed, graph doesn't contain loops or multiple edges.
standard output
standard input
Python 3
Python
2,300
train_011.jsonl
64f42ac1dda18e3277357e596e642c32
256 megabytes
["3 3\n1 2\n1 3\n3 2", "4 5\n3 1\n4 1\n2 3\n3 4\n2 4", "5 4\n3 1\n2 1\n2 3\n4 5"]
PASSED
from queue import Queue import heapq n, m = input().split() n = int(n) m = int(m) f = [0] * (n + 1) sol = [0] * (n + 1) adya = [[] for _ in range(n + 1)] for i in range(m): n1, n2 = input().split() n1 = int(n1) n2 = int(n2) adya[n2].append(n1) f[n1] += 1 cola = [] cnt = 0 for i in range(1, n + ...
1500217500
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["1", "2"]
3def8503f4e7841d33be5b4890065526
NoteIn the first example it is possible that only the first worker made a mistake. Then: the immediate superior of the first worker is the second worker, the immediate superior of the third worker is the first worker, the second worker is the chief.
There are n workers in a company, each of them has a unique id from 1 to n. Exaclty one of them is a chief, his id is s. Each worker except the chief has exactly one immediate superior.There was a request to each of the workers to tell how how many superiors (not only immediate). Worker's superiors are his immediate su...
Print the minimum number of workers that could make a mistake.
The first line contains two positive integers n and s (1 ≀ n ≀ 2Β·105, 1 ≀ s ≀ n)Β β€” the number of workers and the id of the chief. The second line contains n integers a1, a2, ..., an (0 ≀ ai ≀ n - 1), where ai is the number of superiors (not only immediate) the worker with id i reported about.
standard output
standard input
Python 3
Python
1,900
train_022.jsonl
739f033b377b434d25dd47a805d3a7f5
256 megabytes
["3 2\n2 0 2", "5 3\n1 0 0 4 1"]
PASSED
n,s=[int(i) for i in input().split()] s-=1 n-=1 d=0 l=[int(i) for i in input().split()] if l[s]!=0:d+=1 l=l[:s]+l[s+1:] for i in range(0,len(l)): if(l[i]==0):l[i]=n+5 l.sort() j=0 i=0 c=0 while 1: while i<len(l) and j==l[i]: i+=1 if i>=len(l): break elif l[i]-j==1: j+=1 i+=1 continue ...
1479632700
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["1-3,6", "1-3", "10,20,30"]
3969ba3e3eb55a896663d2c5a5bc4a84
null
Β«BersoftΒ» company is working on a new version of its most popular text editor β€” Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces).Your task is to wri...
Output the sequence in the required format.
The only line contains the sequence, keyed by the user. The sequence contains at least one and at most 100 positive integer numbers. It's guaranteed, that this sequence consists of positive integer numbers, not exceeding 1000, separated with a comma, doesn't contain any other characters, apart from digits and commas, c...
standard output
standard input
Python 2
Python
1,300
train_002.jsonl
fae3026ac6742bdd7582c5651dca3f3e
256 megabytes
["1,2,3,1,1,2,6,6,2", "3,2,1", "30,20,10"]
PASSED
inp = raw_input() #inp = '996,999,998,984,989,1000,996,993,1000,983,992,999,999,1000,979,992,987,1000,996,1000,1000,989,981,996,995,999,999,989,999,1000' num_list = sorted(set(map(int, inp.split(',')))) #print num_list result = [] finish = True for elem in num_list: if finish: start = elem end = ...
1286802000
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["5", "1", "3"]
bbc2683d207f147a2a0abedc67ff157a
NoteIn the first sample the following substrings have the sought digital root: s[1... 2] = "3 2", s[1... 3] = "3 2 0", s[3... 4] = "0 5", s[4... 4] = "5" and s[2... 6] = "2 0 5 6 1".
You know that the Martians use a number system with base k. Digit b (0 ≀ b &lt; k) is considered lucky, as the first contact between the Martians and the Earthlings occurred in year b (by Martian chronology).A digital root d(x) of number x is a number that consists of a single digit, resulting after cascading summing o...
Print a single integer β€” the number of substrings that are lucky numbers. 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 three integers k, b and n (2 ≀ k ≀ 109, 0 ≀ b &lt; k, 1 ≀ n ≀ 105). The second line contains string s as a sequence of n integers, representing digits in the k-base notation: the i-th integer equals ai (0 ≀ ai &lt; k) β€” the i-th digit of string s. The numbers in the lines are space-separated.
standard output
standard input
Python 3
Python
2,000
train_070.jsonl
31ce615f8a97d028795e56076994ba2d
256 megabytes
["10 5 6\n3 2 0 5 6 1", "7 6 4\n3 5 0 4", "257 0 3\n0 0 256"]
PASSED
k, b, n = map(int, input().split()) digits = list(map(int, input().split())) def ans0(): j = -1 answer = 0 for i in range(n): if digits[i] != 0 or i < j: continue j = i while j < n and digits[j] == 0: j += 1 r = j - i answer += r * (r + 1) ...
1344958200
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["0\n3\n1000000\n0\n1\n0"]
f98d1d426f68241bad437eb221f617f4
NoteIn the first test case (picture above), if we set the coordinate of $$$B$$$ as $$$2$$$ then the absolute difference will be equal to $$$|(2 - 0) - (4 - 2)| = 0$$$ and we don't have to move $$$A$$$. So the answer is $$$0$$$.In the second test case, we can increase the coordinate of $$$A$$$ by $$$3$$$ and set the coo...
We have a point $$$A$$$ with coordinate $$$x = n$$$ on $$$OX$$$-axis. We'd like to find an integer point $$$B$$$ (also on $$$OX$$$-axis), such that the absolute difference between the distance from $$$O$$$ to $$$B$$$ and the distance from $$$A$$$ to $$$B$$$ is equal to $$$k$$$. The description of the first test case. ...
For each test case, print the minimum number of steps to make point $$$B$$$ exist.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 6000$$$)Β β€” the number of test cases. The only line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$0 \le n, k \le 10^6$$$)Β β€” the initial position of point $$$A$$$ and desirable absolute difference.
standard output
standard input
Python 3
Python
900
train_007.jsonl
98be7d52ce17342be19d418150db536f
256 megabytes
["6\n4 0\n5 8\n0 1000000\n0 0\n1 0\n1000000 1000000"]
PASSED
T = int(input()) for _ in range(T): n, k = tuple(map(int, input().split())) if n < k: print(k - n) continue if n == k: print(0) continue if n > k: if n % 2 == k % 2: print(0) else: print(1)
1598020500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["12", "13", "11"]
1fb69f26fb14076df31534c77bf40c1e
NoteIn the first example you can obtain the text "TB or not TB".In the second example you can obtain the text "a AAAB AAAB c".In the third example you can obtain the text "AB aa AB bb".
You are given a text consisting of $$$n$$$ space-separated words. There is exactly one space character between any pair of adjacent words. There are no spaces before the first word and no spaces after the last word. The length of text is the number of letters and spaces in it. $$$w_i$$$ is the $$$i$$$-th word of text. ...
Print one integer β€” the minimum length of the text after at most one abbreviation.
The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 300$$$) β€” the number of words in the text. The next line contains $$$n$$$ space-separated words of the text $$$w_1, w_2, \dots, w_n$$$. Each word consists only of lowercase Latin letters. It is guaranteed that the length of text does not exceed $$...
standard output
standard input
PyPy 2
Python
2,200
train_045.jsonl
1bf899395b53d8820b0b15dc0beceef4
256 megabytes
["6\nto be or not to be", "10\na ab a a b ab a a b c", "6\naa bb aa aa bb bb"]
PASSED
n = int(raw_input()) arr = raw_input() final = len(arr) arr = arr.split() lens = [0 for x in range(n)] visit = [0 for x in range(n)] cnt = 0 ans = 0 for i in range(n): if visit[i]: continue lens[cnt] = len(arr[i]) for j in range(i+1,n): if arr[j]==arr[i]: arr[j] = cnt visit[j] = 1 arr[i] = c...
1530628500
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
6 seconds
["1", "3"]
6090c7745184ede5a9997dc0dff39ac2
NoteIn the first example, there is only $$$1$$$ fence. That fence is interesting since its area is $$$4$$$ and there is $$$1$$$ enclosed cow, marked in red. In the second example, there are $$$3$$$ interesting fences. $$$(0,0)$$$ β€” $$$(30,14)$$$ β€” $$$(2,10)$$$ $$$(2,16)$$$ β€” $$$(30,14)$$$ β€” $$$(2,10)$$$ $$$(30,14)...
This is the easy version of the problem. The only difference from the hard version is that in this version all coordinates are even.There are $$$n$$$ fence-posts at distinct coordinates on a plane. It is guaranteed that no three fence posts lie on the same line.There are an infinite number of cows on the plane, one at ...
Print a single integer, the number of interesting fences. Two fences are considered different if they are constructed with a different set of three fence posts.
The first line contains the integer $$$n$$$ ($$$3 \le n \le 6000$$$), the number of fence posts which Gregor can choose to form the vertices of a fence. Each of the next $$$n$$$ line contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x,y \le 10^7$$$, $$$x$$$ and $$$y$$$ are even), where $$$(x,y)$$$ is the coordinate o...
standard output
standard input
PyPy 3-64
Python
2,300
train_083.jsonl
139bc23aab5f49407a7c642c59ce233a
256 megabytes
["3\n0 0\n2 0\n0 4", "5\n0 0\n2 16\n30 14\n4 6\n2 10"]
PASSED
import sys input = sys.stdin.readline n = int(input()) a = 0 b = 0 c = 0 d = 0 for i in range(n): x, y = [int(xx) for xx in input().split()] if x % 4 and y % 4: a += 1 elif y % 4: b += 1 elif x % 4: c += 1 else: d += 1 print(a * (a - 1) // 2 * (b + c ...
1627828500
[ "number theory", "math", "geometry" ]
[ 0, 1, 0, 1, 1, 0, 0, 0 ]
2 seconds
["possible", "impossible"]
5fde461bbb54302cfa5e8d5d3e29b9db
NoteIn the first sample, there are n = 5 vertices. The degree of vertex 1 should be k = 2. All conditions are satisfied for a tree with edges 1 - 5, 5 - 2, 1 - 3 and 3 - 4.In the second sample, Limak remembers that none of the following edges existed: 1 - 2, 1 - 3, 1 - 4, 1 - 5 and 1 - 6. Hence, vertex 1 couldn't be co...
A tree is a connected undirected graph consisting of n vertices and n  -  1 edges. Vertices are numbered 1 through n.Limak is a little polar bear. He once had a tree with n vertices but he lost it. He still remembers something about the lost tree though.You are given m pairs of vertices (a1, b1), (a2, b2), ..., (am, bm...
Print "possible" (without quotes) if there exists at least one tree satisfying the given conditions. Otherwise, print "impossible" (without quotes).
The first line of the input contains three integers n, m and k ()Β β€” the number of vertices in Limak's tree, the number of forbidden pairs of vertices, and the degree of vertex 1, respectively. The i-th of next m lines contains two distinct integers ai and bi (1 ≀ ai, bi ≀ n, ai ≠ bi)Β β€” the i-th pair that is forbidden. ...
standard output
standard input
Python 2
Python
2,400
train_012.jsonl
285ec371e9d40d7dc9d2c86d6dfea1d5
256 megabytes
["5 4 2\n1 2\n2 3\n4 2\n4 1", "6 5 3\n1 2\n1 3\n1 4\n1 5\n1 6"]
PASSED
import sys n,m,k = map(int, sys.stdin.readline().split(' ')) V = map(set, [set()]*n) for _ in range(m): u,v = map(int, sys.stdin.readline().rstrip('\n').split(' ')) u-=1 v-=1 V[u].add(v) V[v].add(u) if n-1-len(V[0])<k: print 'impossible' exit() visited = set(range(1,n)) comp = 0 for i in range(1,n): ...
1458376500
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
0.5 second
["a@a,a@a", "No solution", "No solution"]
71b4674e91e0bc5521c416cfc570a090
null
Email address in Berland is a string of the form A@B, where A and B are arbitrary strings consisting of small Latin letters. Bob is a system administrator in Β«BersoftΒ» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitrary order, ...
If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of the...
The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters Β«@Β».
standard output
standard input
PyPy 2
Python
1,500
train_005.jsonl
21461df770b0c62aabc8ca7ecd96f87e
256 megabytes
["a@aa@a", "a@a@a", "@aa@a"]
PASSED
import sys, re s = raw_input().strip() match = re.match('^(\w+@\w+)+$', s) if not match: print('No solution') sys.exit() previous = 0 last_at = None result = [] for pos, ch in enumerate(s): if ch == '@': result.append(s[previous:pos + 2]) previous = pos + 2 last_at = pos result[-1]...
1285599600
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
3 seconds
["0.500000 0.500000", "1.000000 0.000000 0.000000 0.000000 0.000000"]
da2d76d47c1ed200982495dc4a234014
null
n fish, numbered from 1 to n, live in a lake. Every day right one pair of fish meet, and the probability of each other pair meeting is the same. If two fish with indexes i and j meet, the first will eat up the second with the probability aij, and the second will eat up the first with the probability aji = 1 - aij. The ...
Output n space-separated real numbers accurate to not less than 6 decimal places. Number with index i should be equal to the probability that fish with index i will survive to be the last in the lake.
The first line contains integer n (1 ≀ n ≀ 18) β€” the amount of fish in the lake. Then there follow n lines with n real numbers each β€” matrix a. aij (0 ≀ aij ≀ 1) β€” the probability that fish with index i eats up fish with index j. It's guaranteed that the main diagonal contains zeros only, and for other elements the fol...
standard output
standard input
PyPy 3
Python
1,900
train_075.jsonl
5ba7e1e664325b63ff3a545a4f2004b4
128 megabytes
["2\n0 0.5\n0.5 0", "5\n0 1 1 1 1\n0 0 0.5 0.5 0.5\n0 0.5 0 0.5 0.5\n0 0.5 0.5 0 0.5\n0 0.5 0.5 0.5 0"]
PASSED
import sys from array import array # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') n = int(input()) prob = [tuple(map(float, input().split())) for _ in range(n)] full_bit = (1 << n) - 1 dp = [0.0] * full_bit + [1.0] for bit in range(full_bit, 0, -1): popcount = len([1 for i in...
1275570000
[ "probabilities" ]
[ 0, 0, 0, 0, 0, 1, 0, 0 ]
1 second
["2", "1"]
6d940cb4b54f63a7aaa82f21e4c5b994
NoteIn the first sample testcase, possible forest is: 1-2 3-4-5. There are 2 trees overall.In the second sample testcase, the only possible graph is one vertex and no edges. Therefore, there is only one tree.
PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note that one vertex is a valid tree.There is exactly one relative living in each vertex of each tree, they have unique ids from 1 to n. For eac...
You should output the number of trees in the forest where PolandBall lives.
The first line contains single integer n (1 ≀ n ≀ 104)Β β€” the number of Balls living in the forest. The second line contains a sequence p1, p2, ..., pn of length n, where (1 ≀ pi ≀ n) holds and pi denotes the most distant from Ball i relative living on the same tree. If there are several most distant relatives living on...
standard output
standard input
Python 2
Python
1,300
train_001.jsonl
1377c4c1bef490fcb75430c63cce3ad8
256 megabytes
["5\n2 1 5 3 3", "1\n1"]
PASSED
import sys sys.setrecursionlimit(10000000) nBalls = int(raw_input()) edge = [None] + map(int, raw_input().split()) group = [0] * (nBalls + 1) def dfs(ball): if not group[ball]: group[ball] = groupNum dfs(edge[ball]) groupNum = 0 for ball in xrange(1, nBalls + 1): if not group[ball]: i...
1484499900
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
1 second
["3\n6\n1\n1287\n1287\n715"]
930b296d11d6d5663a14144a491f2c0a
NoteIn the first test case the strings "1100", "0110" and "0011" are reachable from the initial state with some sequence of operations.
Cirno gave AquaMoon a chessboard of size $$$1 \times n$$$. Its cells are numbered with integers from $$$1$$$ to $$$n$$$ from left to right. In the beginning, some of the cells are occupied with at most one pawn, and other cells are unoccupied.In each operation, AquaMoon can choose a cell $$$i$$$ with a pawn, and do eit...
For each test case, print the number of states that reachable from the initial state with some sequence of operations modulo $$$998\,244\,353$$$.
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10\,000$$$) β€” the number of test cases. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) β€” the size of the chessboard. The second line contains a string of $$$n$$$ characters, consist...
standard output
standard input
PyPy 3-64
Python
1,900
train_086.jsonl
4a2f24c837119edcbae8adfb580f9c58
256 megabytes
["6\n4\n0110\n6\n011011\n5\n01010\n20\n10001111110110111000\n20\n00110110100110111101\n20\n11101111011000100010"]
PASSED
import sys input = lambda: sys.stdin.readline().strip() ints = lambda: list(map(int, input().split())) Int = lambda: int(input()) MOD = 998244353 def inv(a, m): if a == 1: return 1 return inv(m % a, m) * (m - m // a) % m F = [1] rF = [1] for i in range(1, 100000+1): F.append(...
1626012300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1.5 seconds
["40", "5", "0"]
8c5d9b4fd297706fac3be83fc85028a0
NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill.
Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one do...
Output one integerΒ β€” the minimum number of rubles Andrew can have after buying dollar and euro bills optimally.
The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β€” the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β€” the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq ...
standard output
standard input
PyPy 3
Python
1,400
train_018.jsonl
c4bfd7b31f76b2331b4f20ba6396be3e
512 megabytes
["100\n60\n70", "410\n55\n70", "600\n60\n70"]
PASSED
n = int(input()) d = int(input()) e = int(input()) dollar = 1*d euro = 5*e # using_dollar = n%dollar # using_euro = n%euro # using_dollar_euro = using_dollar % euro # using_euro_dollar = using_euro % dollar # print(min(using_dollar, using_euro, using_dollar_euro, using_euro_dollar)) ans = 1e15 temp = 0 while (temp<...
1567587900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["FIRST\n1 0 1 1", "SECOND"]
a7fa7a5ab71690fb3b5301bebc19956b
null
Two players play the following game. Initially, the players have a knife and a rectangular sheet of paper, divided into equal square grid cells of unit size. The players make moves in turn, the player who can't make a move loses. In one move, a player can take the knife and cut the paper along any segment of the grid l...
If the second player wins, print "SECOND". Otherwise, in the first line print "FIRST", and in the second line print any winning move of the first player (the coordinates of the cut ends, follow input format to print them).
The first line contains three integers n, m, k (1 ≀ n, m ≀ 109, 0 ≀ k ≀ 105) β€” the sizes of the piece of paper and the number of cuts. Then follow k lines, each containing 4 integers xbi, ybi, xei, yei (0 ≀ xbi, xei ≀ n, 0 ≀ ybi, yei ≀ m) β€” the coordinates of the ends of the existing cuts. It is guaranteed that each c...
standard output
standard input
Python 2
Python
2,400
train_069.jsonl
cb2fe6e222a22ee09939e5d7c2db22ad
256 megabytes
["2 1 0", "2 2 4\n0 1 2 1\n0 1 2 1\n1 2 1 0\n1 1 1 2"]
PASSED
from sys import stdin from collections import defaultdict def emp(l, a): cnt = pos = x = 0 for y in a: if y[1]: cnt -= 1 else: if not cnt: x += y[0] - pos cnt += 1 pos = y[0] x += l - pos return x def check(x, b): return x ^...
1362065400
[ "games" ]
[ 1, 0, 0, 0, 0, 0, 0, 0 ]
2 seconds
["3", "-2", "5", "No solution"]
8a9adc116abbd387a6a64dd754436f8a
null
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself.The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a los...
Output the required integer coefficient X, or Β«No solutionΒ», if such a coefficient does not exist or it is fractional. If there are several possible solutions, output any of them.
The input contains three integers A, B, n (|A|, |B| ≀ 1000, 1 ≀ n ≀ 10).
standard output
standard input
Python 3
Python
1,400
train_024.jsonl
aa90364ec139c411aaf5b63af1f824d8
256 megabytes
["2 18 2", "-1 8 3", "0 0 10", "1 16 5"]
PASSED
a,b,n = map(int,input().split()) ans = "No solution" if a == 0 and b == 0: ans =5 elif a == 0 and b!= 0: ans elif a != 0 and b == 0: ans = 0 elif b%a != 0: ans else: a = b / a if a < 0 : a = abs(a) b = 0 for i in range(1001): if i ** n == a: ans = i ...
1285340400
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1.5 seconds
["2 2\n1 2\n2 3", "2 1\n1 2", "2 1\n3 4"]
bc8b4b74c2f2d486e2d2f03982ef1013
null
There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is necessary to include into the exposition only those books that were pub...
In the first line of the output data print two numbers a and b (separate them by a space), where a is the maximum amount of books the organizers can include into the exposition, and b β€” the amount of the time periods, during which Berlbury published a books, and the height difference between the lowest and the highest ...
The first line of the input data contains two integer numbers separated by a space n (1 ≀ n ≀ 105) and k (0 ≀ k ≀ 106) β€” the amount of books by Berlbury in the library, and the maximum allowed height difference between the lowest and the highest books. The second line contains n integer numbers separated by a space. Ea...
standard output
standard input
Python 3
Python
1,900
train_019.jsonl
b95cf3dbc11991755548cba067a87d36
64 megabytes
["3 3\n14 12 10", "2 0\n10 10", "4 5\n8 19 10 13"]
PASSED
from bisect import * n,k=map(int,input().split()) h=list(map(int,input().split())) l=[] q=[] aa=-1 j=0 for i in range(n): l.insert(bisect(l,h[i]),h[i]) while l[-1]-l[0]>k: l.pop(bisect(l,h[j])-1) j+=1 if i-j+1>aa: aa=i-j+1 q=[] if i-j+1==aa: q.append([j+1,i+1]) pr...
1269673200
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
2 seconds
["499122177 0", "499122193 249561095 249561092 873463811 499122178 124780545 623902721 0"]
a3a14dbb486a26d015b69187f87c53d4
NoteIn the first example the exact values of minimum expected values are: $$$\frac 1 2$$$, $$$\frac 0 2$$$.In the second example the exact values of minimum expected values are: $$$\frac{132} 8$$$, $$$\frac{54} 8$$$, $$$\frac{30} 8$$$, $$$\frac{17} 8$$$, $$$\frac{12} 8$$$, $$$\frac 7 8$$$, $$$\frac 3 8$$$, $$$\frac 0 8...
You are creating a level for a video game. The level consists of $$$n$$$ rooms placed in a circle. The rooms are numbered $$$1$$$ through $$$n$$$. Each room contains exactly one exit: completing the $$$j$$$-th room allows you to go the $$$(j+1)$$$-th room (and completing the $$$n$$$-th room allows you to go the $$$1$$$...
Print $$$n$$$ integersΒ β€” the $$$k$$$Β -th value should be equal to the minimum possible expected value of players earnings if the chests are placed into the rooms in some order and exactly $$$k$$$ of the chests are mimics. It can be shown that it is in the form of $$$\frac{P}{Q}$$$ where $$$P$$$ and $$$Q$$$ are non-nega...
The first contains a single integer $$$n$$$ ($$$2 \le n \le 3 \cdot 10^5$$$)Β β€” the number of rooms and the number of chests. The second line contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 10^6$$$)Β β€” the treasure values of each chest.
standard output
standard input
PyPy 2
Python
2,600
train_066.jsonl
e36f04e429be1e796479b688dff526df
256 megabytes
["2\n1 2", "8\n10 4 3 6 5 10 7 5"]
PASSED
# Author: yumtam # Created at: 2020-09-11 00:33 from __future__ import division, print_function _interactive = False def main(): n = int(input()) ar = [ModInt(int(c)) for c in input().split()] ar.sort() prfsum = [ModInt(0)] for x in ar: prfsum.append(prfsum[-1]+x) def rsum(l, r):...
1594565100
[ "probabilities", "math" ]
[ 0, 0, 0, 1, 0, 1, 0, 0 ]
3 seconds
["YES\nNO\nNO"]
146c856f8de005fe280e87f67833c063
null
Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with n strings. Then the mechanism should be able to process queries of the following type: "Given string s, determine if the memory of the mech...
For each query print on a single line "YES" (without the quotes), if the memory of the mechanism contains the required string, otherwise print "NO" (without the quotes).
The first line contains two non-negative numbers n and m (0 ≀ n ≀ 3Β·105, 0 ≀ m ≀ 3Β·105) β€” the number of the initial strings and the number of queries, respectively. Next follow n non-empty strings that are uploaded to the memory of the mechanism. Next follow m non-empty strings that are the queries to the mechanism. Th...
standard output
standard input
PyPy 3
Python
2,000
train_002.jsonl
d84cd12087f44d4a7f680d22ff9701f0
256 megabytes
["2 3\naaaaa\nacacaca\naabaa\nccacacc\ncaaac"]
PASSED
from collections import defaultdict from math import ceil,floor import sys memory = set() mod = 1000000000000000003 p = 3 def hash_(s): pp = p result = 0 for ch in s: result += pp*(ord(ch)-ord('a')-1) pp = (pp*p)%mod; result %= mod return result % mod; def find(q): hash_0 ...
1423931400
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["YES\n1 -2 3 -4\nNO\nYES\n1 1 -1 1 -1\nYES\n-40 13 40 0 -9 -31"]
e57345f5757654749b411727ebb99c80
NoteExplanation of the first testcase: An array with the desired properties is $$$b=[1,-2,3,-4]$$$. For this array, it holds: The first element of $$$b$$$ is $$$1$$$. The sum of the first two elements of $$$b$$$ is $$$-1$$$. The sum of the first three elements of $$$b$$$ is $$$2$$$. The sum of the first four eleme...
You are given an array of $$$n$$$ integers $$$a_1,a_2,\dots,a_n$$$.You have to create an array of $$$n$$$ integers $$$b_1,b_2,\dots,b_n$$$ such that: The array $$$b$$$ is a rearrangement of the array $$$a$$$, that is, it contains the same values and each value appears the same number of times in the two arrays. In ot...
For each testcase, if there is not an array $$$b_1,b_2,\dots,b_n$$$ with the required properties, print a single line with the word NO. Otherwise print a line with the word YES, followed by a line with the $$$n$$$ integers $$$b_1,b_2,\dots,b_n$$$. If there is more than one array $$$b_1,b_2,\dots,b_n$$$ satisfying the ...
Each test contains multiple test cases. The first line contains an integer $$$t$$$ ($$$1\le t \le 1000$$$) β€” the number of test cases. The description of the test cases follows. The first line of each testcase contains one integer $$$n$$$ ($$$1\le n\le 50$$$) Β β€” the length of the array $$$a$$$. The second line of each ...
standard output
standard input
Python 3
Python
900
train_008.jsonl
ef311609473c6aac1e10ffc4056a6e90
256 megabytes
["4\n4\n1 -2 3 -4\n3\n0 0 0\n5\n1 -1 1 -1 1\n6\n40 -31 -9 0 13 -40"]
PASSED
def all_perms(elements): if len(elements) <= 1: yield elements else: for perm in all_perms(elements[1:]): for i in range(len(elements)): # nb elements[0:1] works in both string and list contexts yield perm[:i] + elements[0:1] + perm[i:] tests_no = in...
1602341400
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
3 seconds
["YES\n2 3 1 1", "YES\n1 1 1 1 1", "NO"]
bb7ecc5dbb922007bc0c25491aaa53d9
NoteFor the first sample, x1 = 2, x2 = 3, x3 = x4 = 1 is a valid labeling. Indeed, (3, 4), (1, 2), (1, 3), (1, 4) are the only pairs of cities with difference of labels not greater than 1, and these are precisely the roads of Bankopolia.For the second sample, all pairs of cities have difference of labels not greater th...
Oleg the bank client lives in Bankopolia. There are n cities in Bankopolia and some pair of cities are connected directly by bi-directional roads. The cities are numbered from 1 to n. There are a total of m roads in Bankopolia, the i-th road connects cities ui and vi. It is guaranteed that from each city it is possible...
If the required labeling is not possible, output a single line containing the string "NO" (without quotes). Otherwise, output the string "YES" (without quotes) on the first line. On the next line, output n space-separated integers, x1, x2, ..., xn. The condition 1 ≀ xi ≀ 109 must hold for all i, and for all pairs of ci...
The first line of input contains two space-separated integers n and m (2 ≀ n ≀ 3Β·105, 1 ≀ m ≀ 3Β·105)Β β€” the number of cities and the number of roads. Next, m lines follow. The i-th line contains two space-separated integers ui and vi (1 ≀ ui, vi ≀ n, ui ≠ vi)Β β€” the cities connected by the i-th road. It is guaranteed tha...
standard output
standard input
PyPy 2
Python
2,400
train_027.jsonl
8e64cfedd36167546a8c39a145640b9d
256 megabytes
["4 4\n1 2\n1 3\n1 4\n3 4", "5 10\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n5 4", "4 3\n1 2\n1 3\n1 4"]
PASSED
import collections import sys readline = sys.stdin.readline write = sys.stdout.write n, m = map(int, readline().split()) g = [[i] for i in xrange(n)] for i in xrange(m): u, v = map(int, readline().split()) g[u-1].append(v-1) g[v-1].append(u-1) for i in xrange(n): g[i] = tuple(sorted(g[i])) s = {e: i for...
1494668100
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["010", "010", "0000000", "0011001100001011101000"]
b52cecae4e40e652523d05b002af1c3d
NoteIn the first example: For the substrings of the length $$$1$$$ the length of the longest non-decreasing subsequnce is $$$1$$$; For $$$l = 1, r = 2$$$ the longest non-decreasing subsequnce of the substring $$$s_{1}s_{2}$$$ is $$$11$$$ and the longest non-decreasing subsequnce of the substring $$$t_{1}t_{2}$$$ is $...
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.Kirk has a binary string $$$s$$$ (a string which consists of zeroes and ones) of length $$$n$$$ and he is asking you to find a binary string $$$t$$$ of the same length which satisfie...
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
The first line contains a binary string of length not more than $$$2\: 000$$$.
standard output
standard input
Python 3
Python
2,000
train_024.jsonl
093c5cedf31c29750615bd45bd0ebc66
256 megabytes
["110", "010", "0001111", "0111001100111011101000"]
PASSED
s=input() s=list(s) l=len(s)-1 z=0 for i in range(l,-1,-1): if(s[i]=='0'): z=z+1 elif z: z-=1 else: s[i]='0' s="".join(s) print(s)
1566311700
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["9", "4"]
566b91c278449e8eb3c724a6f00797e8
NoteThe figure below shows the nine possible positions of the gang headquarters from the first sample: For example, the following movements can get the car from point (1, 0) to point (0, 0):
Sensation, sensation in the two-dimensional kingdom! The police have caught a highly dangerous outlaw, member of the notorious "Pihters" gang. The law department states that the outlaw was driving from the gang's headquarters in his car when he crashed into an ice cream stall. The stall, the car, and the headquarters e...
Print a single integer β€” the number of different possible locations of the gang's headquarters.
The first line contains a single integer n (1 ≀ n ≀ 2Β·105) β€” the number of the car's movements from the headquarters to the stall. Each of the following n lines describes the car's possible movements. It is guaranteed that each possible movement is one of the following strings: "UL", "UR", "DL", "DR" or "ULDR". All mo...
standard output
standard input
Python 3
Python
1,700
train_024.jsonl
db4ff7f3d05bac3fd8858b5203fa2958
256 megabytes
["3\nUR\nUL\nULDR", "2\nDR\nDL"]
PASSED
#!/usr/local/bin/python3 n = int(input()) w = 1 h = 1 for _ in range(n): s = input() if s == 'ULDR': w += 1 h += 1 continue if s == 'UR' or s == 'DL': w += 1 continue h += 1 print(w * h)
1335532800
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["2", "2"]
783df1df183bf182bf9acbb99208cdb7
NotePictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po...
Output the answer to the problem.
The first line contains two space-separated integers x1, y1 ( - 106 ≀ x1, y1 ≀ 106) β€” the coordinates of your home. The second line contains two integers separated by a space x2, y2 ( - 106 ≀ x2, y2 ≀ 106) β€” the coordinates of the university you are studying at. The third line contains an integer n (1 ≀ n ≀ 300) β€” the ...
standard output
standard input
Python 3
Python
1,700
train_007.jsonl
a4cd8626e886baf95565e9f52dc16b6e
256 megabytes
["1 1\n-1 -1\n2\n0 1 0\n1 0 0", "1 1\n-1 -1\n3\n1 0 0\n0 1 0\n1 1 -3"]
PASSED
def town(): x1, y1= [int(i) for i in input().split()] x2, y2= [int(i) for i in input().split()] n= int(input()) ans= 0 for i in range(n): a, b, c= [int(k) for k in input().split()] if (a*x1 + b*y1 + c< 0 and a*x2 + b*y2 + c> 0) or (a*x1 + b*y1 + c> 0 and a*x2 + b*y2 + c< 0): ...
1419438600
[ "geometry", "math" ]
[ 0, 1, 0, 1, 0, 0, 0, 0 ]
2 seconds
["2 3 1", "4 1 3 2"]
0da021cfe88c5a333db99064de12acbf
NoteIn the first example, $$$p = [2, 3, 4, 1]$$$, $$$m = 3$$$ and given swaps are $$$[(1, 4), (2, 1), (1, 3)]$$$.There is only one correct order of swaps i.e $$$[2, 3, 1]$$$. First we perform the swap $$$2$$$ from the input i.e $$$(2, 1)$$$, $$$p$$$ becomes $$$[3, 2, 4, 1]$$$. Then we perform the swap $$$3$$$ from th...
Alice had a permutation $$$p$$$ of numbers from $$$1$$$ to $$$n$$$. Alice can swap a pair $$$(x, y)$$$ which means swapping elements at positions $$$x$$$ and $$$y$$$ in $$$p$$$ (i.e. swap $$$p_x$$$ and $$$p_y$$$). Alice recently learned her first sorting algorithm, so she decided to sort her permutation in the minimum ...
Print a permutation of $$$m$$$ integers Β β€” a valid order of swaps written by Alice that sorts the permutation $$$p$$$. See sample explanation for better understanding. In case of multiple possible answers, output any.
The first line contains $$$2$$$ integers $$$n$$$ and $$$m$$$ $$$(2 \le n \le 2 \cdot 10^5, 1 \le m \le n - 1)$$$ Β β€” the size of permutation and the minimum number of swaps required to sort the permutation. The next line contains $$$n$$$ integers $$$p_1, p_2, ..., p_n$$$ ($$$1 \le p_i \le n$$$, all $$$p_i$$$ are distinc...
standard output
standard input
Python 3
Python
2,700
train_101.jsonl
64057e6bf83be5025b9ae84095a2ff5f
256 megabytes
["4 3\n2 3 4 1\n1 4\n2 1\n1 3", "6 4\n6 5 1 3 2 4\n3 1\n2 5\n6 3\n6 4"]
PASSED
import copy import gc import itertools from array import array from fractions import Fraction import heapq import math import operator import os, sys import profile import cProfile import random import re import string from bisect import bisect_left, bisect_right from collections import defaultdict, dequ...
1653230100
[ "math", "trees", "graphs" ]
[ 0, 0, 1, 1, 0, 0, 0, 1 ]
2 seconds
["1 1 3 8\n-1\n0 0 0 0 0"]
f4b790bef9a6cbcd5d1f9235bcff7c8f
NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.
For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.
For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.
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 one integer $$$n$$$ ($$$1 \le n \le 100$$$)Β β€” the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le ...
standard output
standard input
PyPy 3-64
Python
1,100
train_109.jsonl
ebd0536d3f01c09266c968c2c9e3844a
256 megabytes
["3\n\n4\n\n1 0 2 5\n\n3\n\n2 6 3\n\n5\n\n0 0 0 0 0"]
PASSED
for _ in range(int(input())): n=int(input()) d=list(map(int,input().split())) ans=[] ans.append(d[0]) count=0 # print(ans[1]+d[2]) for i in range(1,n): first=ans[i-1]+d[i] second=ans[i-1]-d[i] if first>=0 and second>=0 and first!=se...
1664462100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["BAAAABAB", "ABAAAABBBAABAAB"]
cd22a61e8288275abac47ee68d6098c3
NoteIn the first sample, if Bob puts the token on the number (not position): $$$1$$$: Alice can move to any number. She can win by picking $$$7$$$, from which Bob has no move. $$$2$$$: Alice can move to $$$3$$$ and $$$5$$$. Upon moving to $$$5$$$, Bob can win by moving to $$$8$$$. If she chooses $$$3$$$ instead, she...
After a long day, Alice and Bob decided to play a little game. The game board consists of $$$n$$$ cells in a straight line, numbered from $$$1$$$ to $$$n$$$, where each cell contains a number $$$a_i$$$ between $$$1$$$ and $$$n$$$. Furthermore, no two cells contain the same number. A token is placed in one of the cells....
Print $$$s$$$Β β€” a string of $$$n$$$ characters, where the $$$i$$$-th character represents the outcome of the game if the token is initially placed in the cell $$$i$$$. If Alice wins, then $$$s_i$$$ has to be equal to "A"; otherwise, $$$s_i$$$ has to be equal to "B".
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β€” the number of numbers. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$). Furthermore, there are no pair of indices $$$i \neq j$$$ such that $$$a_i = a_j$$$.
standard output
standard input
PyPy 3
Python
1,600
train_036.jsonl
032fca37d8c85d7751ead9e0b08db985
256 megabytes
["8\n3 6 5 4 2 7 1 8", "15\n3 11 2 5 10 9 7 13 15 8 4 12 6 1 14"]
PASSED
n=int(input()) a=[*map(int,input().split())] s=[0]*n m=n while m: for i,x in enumerate(a): if s[i]==0: r=range(i%x,n,x) if all(a[j]<=x or s[j]=='A'for j in r):s[i]='B';m-=1 if any(a[j]>x and s[j]=='B'for j in r):s[i]='A';m-=1 print(''.join(s))
1538931900
[ "games" ]
[ 1, 0, 0, 0, 0, 0, 0, 0 ]
2 seconds
["3\n1 2 4", "11\n1 2 4 2 4 2 4 2 4 2 4", "7\n1 2 3 1 3 2 1", "2\n1 4"]
c9d07fdf0d3293d5564275ebbabbcf12
NoteBelow you can see the graph from the first example:The given path is passing through vertexes $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$. The sequence $$$1-2-4$$$ is good because it is the subsequence of the given path, its first and the last elements are equal to the first and the last elements of the given path respectiv...
The main characters have been omitted to be short.You are given a directed unweighted graph without loops with $$$n$$$ vertexes and a path in it (that path is not necessary simple) given by a sequence $$$p_1, p_2, \ldots, p_m$$$ of $$$m$$$ vertexes; for each $$$1 \leq i &lt; m$$$ there is an arc from $$$p_i$$$ to $$$p_...
In the first line output a single integer $$$k$$$ ($$$2 \leq k \leq m$$$)Β β€” the length of the shortest good subsequence. In the second line output $$$k$$$ integers $$$v_1$$$, $$$\ldots$$$, $$$v_k$$$ ($$$1 \leq v_i \leq n$$$)Β β€” the vertexes in the subsequence. If there are multiple shortest subsequences, print any. Any ...
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 100$$$)Β β€” the number of vertexes in a graph. The next $$$n$$$ lines define the graph by an adjacency matrix: the $$$j$$$-th character in the $$$i$$$-st line is equal to $$$1$$$ if there is an arc from vertex $$$i$$$ to the vertex $$$j$$$ else it is equal...
standard output
standard input
PyPy 2
Python
1,700
train_003.jsonl
d149f7c4d7e511a632579b453f282d36
256 megabytes
["4\n0110\n0010\n0001\n1000\n4\n1 2 3 4", "4\n0110\n0010\n1001\n1000\n20\n1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4", "3\n011\n101\n110\n7\n1 2 3 1 3 2 1", "4\n0110\n0001\n0001\n1000\n3\n1 2 4"]
PASSED
from collections import defaultdict def all_path_shortest(adj_list): src_to_dst = {node: defaultdict(lambda: float('inf')) for node in adj_list} for src in adj_list: for dest in adj_list[src]: src_to_dst[src][dest] = 1 for src in adj_list: src_to_dst[src][src] = 0 # Usi...
1566311700
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["YES\nNO\nNO\nYES"]
b116ab1cae8d64608641b339b8654e21
NoteThe first test case is pictured above.In the second test case, the tree is a path. We can show that the snake cannot reverse itself.In the third test case, we can show that the snake cannot reverse itself.In the fourth test case, an example solution is:$$$(15,12)\to (16,11)\to (15,13)\to (10,14)\to (8,13)\to (4,11)...
There is an undirected tree of $$$n$$$ vertices, connected by $$$n-1$$$ bidirectional edges. There is also a snake stuck inside of this tree. Its head is at vertex $$$a$$$ and its tail is at vertex $$$b$$$. The snake's body occupies all vertices on the unique simple path between $$$a$$$ and $$$b$$$.The snake wants to k...
For each test case, output "YES" if it is possible for the snake to reverse itself, or "NO" otherwise.
The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) Β β€” the number of test cases. The next lines contain descriptions of test cases. The first line of each test case contains three integers $$$n,a,b$$$ ($$$2\le n\le 10^5,1\le a,b\le n,a\ne b$$$). Each of the next $$$n-1$$$ lines contains two integers ...
standard output
standard input
PyPy 3
Python
3,000
train_060.jsonl
ed674f9696a8d18b4dde49ca909a2d3c
256 megabytes
["4\n8 4 7\n1 2\n2 3\n1 4\n4 5\n4 6\n1 7\n7 8\n4 3 2\n4 3\n1 2\n2 3\n9 3 5\n1 2\n2 3\n3 4\n1 5\n5 6\n6 7\n1 8\n8 9\n16 15 12\n1 2\n2 3\n1 4\n4 5\n5 6\n6 7\n4 8\n8 9\n8 10\n10 11\n11 12\n11 13\n13 14\n10 15\n15 16"]
PASSED
from sys import stdin import itertools input = stdin.readline def getint(): return int(input()) def getints(): return list(map(int, input().split())) def getint1(): return list(map(lambda x: int(x) - 1, input().split())) def getstr(): return input()[:-1] def solve(): n, a, b = getint1() n += 1 adj = [[] f...
1595342100
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
2 seconds
["8", "0", "10000800015"]
0e162ea665732714283317e7c052e234
null
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length li.Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that maximi...
The first line of the output must contain a single non-negative integerΒ β€”Β the maximum total area of the rectangles that Ilya can make from the available sticks.
The first line of the input contains a positive integer n (1 ≀ n ≀ 105)Β β€”Β the number of the available sticks. The second line of the input contains n positive integers li (2 ≀ li ≀ 106)Β β€”Β the lengths of the sticks.
standard output
standard input
Python 3
Python
1,600
train_010.jsonl
8931ecfe16ea421314b2adfadf7456d7
256 megabytes
["4\n2 4 4 2", "4\n2 2 3 5", "4\n100003 100004 100005 100006"]
PASSED
n=int(input()) l=list(map(int,input().split())) l=sorted(l) l=l[::-1] k=0 b=-1 for i in range(n-1) : if l[i]==l[i+1] and b==-1 : b=l[i] l[i+1]=-1 if l[i]==l[i+1] and b!=-1 : k+=b*l[i] b=-1 l[i+1]=-1 if l[i]==l[i+1]+1 and b==-1: b=l[i]-1 l[i+1]=-1 ...
1427387400
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["1 2", "0 0", "0 3"]
19a0c05eb2d1559ccfe60e210c6fcd6a
null
The map of Bertown can be represented as a set of $$$n$$$ intersections, numbered from $$$1$$$ to $$$n$$$ and connected by $$$m$$$ one-way roads. It is possible to move along the roads from any intersection to any other intersection. The length of some path from one intersection to another is the number of roads that o...
Print two integers: the minimum and the maximum number of rebuilds that could have happened during the journey.
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le m \le 2 \cdot 10^5$$$) β€” the number of intersections and one-way roads in Bertown, respectively. Then $$$m$$$ lines follow, each describing a road. Each line contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$, $$$u \ne v$$$) denotin...
standard output
standard input
Python 3
Python
1,700
train_007.jsonl
e631289020649365f59f8d4d2dc8f7ba
512 megabytes
["6 9\n1 5\n5 4\n1 2\n2 3\n3 4\n4 1\n2 6\n6 4\n4 2\n4\n1 2 3 4", "7 7\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 1\n7\n1 2 3 4 5 6 7", "8 13\n8 7\n8 6\n7 5\n7 4\n6 5\n6 4\n5 3\n5 2\n4 3\n4 2\n3 1\n2 1\n1 8\n5\n8 7 5 2 1"]
PASSED
from collections import deque n, m = map(int, input().split()) graph = [[] for _ in range(n + 1)] inverse = [[] for _ in range(n + 1)] for _ in range(m): u, v = map(int, input().split()) graph[u].append(v) inverse[v].append(u) k = int(input()) way = list(map(int, input().split())) s = way[0] t = way[-1] que...
1583068500
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["3 1", "3 1", "9 3", "18 4", "No solution"]
763aa950a9a8e5c975a6028e014de20f
NoteIn the first sample there is only one longest good substring: "Abo" itself. The other good substrings are "b", "Ab", "bo", but these substrings have shorter length.In the second sample there is only one longest good substring: "EIS". The other good substrings are: "S", "IS".
Having read half of the book called "Storm and Calm" on the IT lesson, Innocentius was absolutely determined to finish the book on the maths lessons. All was fine until the math teacher Ms. Watkins saw Innocentius reading fiction books instead of solving equations of the fifth degree. As during the last maths class Inn...
Print on a single line two numbers without a space: the maximum length of a good substring and the number of good substrings with this length. If no good substring exists, print "No solution" without the quotes. Two substrings are considered different if their positions of occurrence are different. So if some string oc...
The only input line contains a non-empty string s consisting of no more than 2Β·105 uppercase and lowercase Latin letters. We shall regard letters "a", "e", "i", "o", "u" and their uppercase variants as vowels.
standard output
standard input
Python 2
Python
2,000
train_035.jsonl
0f18aae08a1e206c4f427e500a355de7
256 megabytes
["Abo", "OEIS", "auBAAbeelii", "AaaBRAaaCAaaDAaaBRAaa", "EA"]
PASSED
line = raw_input().lower() line_len = len(line) f = [[0,i] for i in xrange(line_len+1)] for index in xrange(line_len): f[index+1][0] = f[index][0] f[index+1][0] += -1 if line[index] in 'aeiou' else 2 f.sort() ans_len, ans_cnt = 0, 0 min_used = f[0][1] for index in xrange(1,line_len+1): if f[index][1]-min_us...
1324015200
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["2", "0", "1"]
64d85fcafab0e1b477bc888408f54eb5
NoteThe tree corresponding to the first example: The answer is $$$2$$$, some of the possible answers are the following: $$$[(1, 5), (1, 6)]$$$, $$$[(1, 4), (1, 7)]$$$, $$$[(1, 6), (1, 7)]$$$.The tree corresponding to the second example: The answer is $$$0$$$.The tree corresponding to the third example: The answer is...
You are given an undirected tree consisting of $$$n$$$ vertices. An undirected tree is a connected undirected graph with $$$n - 1$$$ edges.Your task is to add the minimum number of edges in such a way that the length of the shortest path from the vertex $$$1$$$ to any other vertex is at most $$$2$$$. Note that you are ...
Print a single integer β€” the minimum number of edges you have to add in order to make the shortest distance from the vertex $$$1$$$ to any other vertex at most $$$2$$$. Note that you are not allowed to add loops and multiple edges.
The first line contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) β€” the number of vertices in the tree. The following $$$n - 1$$$ lines contain edges: edge $$$i$$$ is given as a pair of vertices $$$u_i, v_i$$$ ($$$1 \le u_i, v_i \le n$$$). It is guaranteed that the given edges form a tree. It is guaranteed t...
standard output
standard input
PyPy 2
Python
2,100
train_014.jsonl
102d89c3bc1df14041a2a244925bac17
256 megabytes
["7\n1 2\n2 3\n2 4\n4 5\n4 6\n5 7", "7\n1 2\n1 3\n2 4\n2 5\n3 6\n1 7", "7\n1 2\n2 3\n3 4\n3 5\n3 6\n3 7"]
PASSED
import sys range = xrange input = raw_input inp = [int(x) for x in sys.stdin.read().split()]; ii = 0 n = inp[ii]; ii += 1 coupl = [[] for _ in range(n)] for _ in range(n - 1): u = inp[ii] - 1; ii += 1 v = inp[ii] - 1; ii += 1 coupl[u].append(v) coupl[v].append(u) root = 0 found = [0]*n found[roo...
1535122200
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["3\nhello test one \nok bye two \na b", "2\na \nA a A a A", "4\nA K M \nB F H L N O \nC D G I P \nE J"]
da08dd34ac3c05af58926f70abe5acd0
NoteThe first example is explained in the statements.
A rare article in the Internet is posted without a possibility to comment it. On a Polycarp's website each article has comments feed.Each comment on Polycarp's website is a non-empty string consisting of uppercase and lowercase letters of English alphabet. Comments have tree-like structure, that means each comment exce...
Print comments in a format that is given in the statement. For each level of nesting, comments should be printed in the order they are given in the input.
The first line contains non-empty comments feed in the described format. It consists of uppercase and lowercase letters of English alphabet, digits and commas. It is guaranteed that each comment is a non-empty string consisting of uppercase and lowercase English characters. Each of the number of comments is integer (c...
standard output
standard input
Python 3
Python
1,700
train_009.jsonl
031560f123208442d5117ddda142778d
256 megabytes
["hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0", "a,5,A,0,a,0,A,0,a,0,A,0", "A,3,B,2,C,0,D,1,E,0,F,1,G,0,H,1,I,1,J,0,K,1,L,0,M,2,N,0,O,1,P,0"]
PASSED
#!/usr/bin/env python3 import collections def solve(): comments = input().split(",") comments_by_depth = collections.defaultdict(list) current_depth = 0 current_depth_limit = [10000000] cur_cmt = [0] * 2 for i, item in enumerate(comments): cur_cmt[i % 2] = item if i % 2 == ...
1482113100
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
3 seconds
["6\n5\n375000012\n500000026\n958557139\n0\n49735962"]
32ab22abbbce760be53ea8928876431c
NoteIn the first test case, the entire game has $$$3$$$ turns, and since $$$m = 3$$$, Bob has to add in each of them. Therefore Alice should pick the biggest number she can, which is $$$k = 2$$$, every turn.In the third test case, Alice has a strategy to guarantee a score of $$$\frac{75}{8} \equiv 375000012 \pmod{10^9 ...
This is the hard version of the problem. The difference is the constraints on $$$n$$$, $$$m$$$ and $$$t$$$. You can make hacks only if all versions of the problem are solved.Alice and Bob are given the numbers $$$n$$$, $$$m$$$ and $$$k$$$, and play a game as follows:The game has a score that Alice tries to maximize, an...
For each test case output a single integer number β€” the score of the optimal game modulo $$$10^9 + 7$$$. Formally, let $$$M = 10^9 + 7$$$. It can be shown that the answer can be expressed as an irreducible fraction $$$\frac{p}{q}$$$, where $$$p$$$ and $$$q$$$ are integers and $$$q \not \equiv 0 \pmod{M}$$$. Output the ...
The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) β€” the number of test cases. The description of test cases follows. Each test case consists of a single line containing the three integers, $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1 \le m \le n \le 10^6, 0 \le k &lt; 10^9 + 7$$$) β€” the numb...
standard output
standard input
PyPy 3-64
Python
2,400
train_093.jsonl
066d4783637a1bd8ba08968ced234c5f
256 megabytes
["7\n\n3 3 2\n\n2 1 10\n\n6 3 10\n\n6 4 10\n\n100 1 1\n\n4 4 0\n\n69 4 20"]
PASSED
import sys import os from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if se...
1642862100
[ "games" ]
[ 1, 0, 0, 0, 0, 0, 0, 0 ]
2 seconds
["2", "3"]
05f251de93536024c05fbd77ed01b70b
null
Let's imagine: there is a chess piece billiard ball. Its movements resemble the ones of a bishop chess piece. The only difference is that when a billiard ball hits the board's border, it can reflect from it and continue moving.More formally, first one of four diagonal directions is chosen and the billiard ball moves in...
Print a single number, the maximum possible number of billiard balls that do not pairwise beat each other. Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is preferred to use cin (also you may use the %I64d specificator).
The first line contains two integers n and m (2 ≀ n, m ≀ 106).
standard output
standard input
Python 2
Python
2,100
train_056.jsonl
e8a4b8e7484a3d8edb2be847208d4ae0
256 megabytes
["3 4", "3 3"]
PASSED
def gcd(x,y): return y and gcd(y,x%y) or x n,m=map(int,raw_input().split()) print gcd(n-1,m-1)+1
1302879600
[ "number theory", "graphs" ]
[ 0, 0, 1, 0, 1, 0, 0, 0 ]
2 seconds
["3\n6 2 4", "-1", "0", "2\n2 1"]
3336662e6362693b8ac9455d4c2fe158
NoteIn the first example, it is possible to make all blocks black in $$$3$$$ operations. Start with changing blocks $$$6$$$ and $$$7$$$, so the sequence is "BWWWWBBB". Then change blocks $$$2$$$ and $$$3$$$, so the sequence is "BBBWWBB". And finally, change blocks $$$4$$$ and $$$5$$$, so all blocks are black.It is impo...
There are $$$n$$$ blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of o...
If it is impossible to make all the blocks having the same color, print $$$-1$$$. Otherwise, print an integer $$$k$$$ ($$$0 \le k \le 3 \cdot n$$$) β€” the number of operations. Then print $$$k$$$ integers $$$p_1, p_2, \dots, p_k$$$ $$$(1 \le p_j \le n - 1)$$$, where $$$p_j$$$ is the position of the left block in the pai...
The first line contains one integer $$$n$$$ ($$$2 \le n \le 200$$$) β€” the number of blocks. The second line contains one string $$$s$$$ consisting of $$$n$$$ characters, each character is either "W" or "B". If the $$$i$$$-th character is "W", then the $$$i$$$-th block is white. If the $$$i$$$-th character is "B", then ...
standard output
standard input
PyPy 2
Python
1,300
train_026.jsonl
eaa1e3df065007dc9c2e536e873df6d4
256 megabytes
["8\nBWWWWWWB", "4\nBWBB", "5\nWWWWW", "3\nBWB"]
PASSED
#!/usr/bin/env pypy from __future__ import division, print_function from collections import defaultdict, Counter, deque from future_builtins import ascii, filter, hex, map, oct, zip from itertools import imap as map, izip as zip from __builtin__ import xrange as range from math import ceil, log from _continuation impor...
1576401300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
3 seconds
["3 2", "0 0"]
9a365e26f58ecb22a1e382fad3062387
NoteIn the first sample the game went like this: R - R. Draw. P - S. Nikephoros loses. S - P. Polycarpus loses. R - P. Nikephoros loses. P - R. Polycarpus loses. S - S. Draw. R - P. Nikephoros loses. Thus, in total Nikephoros has 3 losses (and 3 red spots), and Polycarpus only has 2.
Nikephoros and Polycarpus play rock-paper-scissors. The loser gets pinched (not too severely!).Let us remind you the rules of this game. Rock-paper-scissors is played by two players. In each round the players choose one of three items independently from each other. They show the items with their hands: a rock, scissors...
Print two space-separated integers: the numbers of red spots Nikephoros and Polycarpus have.
The first line contains integer n (1 ≀ n ≀ 2Β·109) β€” the number of the game's rounds. The second line contains sequence A as a string of m characters and the third line contains sequence B as a string of k characters (1 ≀ m, k ≀ 1000). The given lines only contain characters "R", "S" and "P". Character "R" stands for th...
standard output
standard input
Python 3
Python
1,300
train_043.jsonl
d87b306ee5562691c3987bc0c9d98ef1
256 megabytes
["7\nRPS\nRSPP", "5\nRRRRRRRR\nR"]
PASSED
n = int(input()) a = input() b = input() ai = 0 alen = len(a) bi = 0 blen = len(b) nik = 0 pol = 0 if alen == blen: rnd = alen else: rnd = alen*blen numofrounds = 0 for i in range(n): #print(i,rnd) if i == rnd: numofrounds = n//rnd # print(numofrounds) nik *= numofrounds pol *= n...
1333724400
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["2 2\n1 3", "3 3\n3 4 7"]
f1121338e84c757d1165d1d645bb26ed
NoteThere are two simple cycles in the first example: $$$1 \rightarrow 5 \rightarrow 2 \rightarrow 1$$$ and $$$2 \rightarrow 3 \rightarrow 4 \rightarrow 5 \rightarrow 2$$$. One traffic controller can only reverse the road $$$2 \rightarrow 1$$$ and he can't destroy the second cycle by himself. Two traffic controllers ca...
Andrew prefers taxi to other means of transport, but recently most taxi drivers have been acting inappropriately. In order to earn more money, taxi drivers started to drive in circles. Roads in Andrew's city are one-way, and people are not necessary able to travel from one part to another, but it pales in comparison to...
In the first line output two integers the minimal amount of traffic controllers required to complete the task and amount of roads $$$k$$$ which should be reversed. $$$k$$$ should not be minimized. In the next line output $$$k$$$ integers separated by spaces β€” numbers of roads, the directions of which should be reversed...
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \leq n \leq 100\,000$$$, $$$1 \leq m \leq 100\,000$$$)Β β€” the number of crossroads and the number of roads in the city, respectively. Each of the following $$$m$$$ lines contain three integers $$$u_{i}$$$, $$$v_{i}$$$ and $$$c_{i}$$$ ($$$1 \leq u_{i}, v_{i} ...
standard output
standard input
PyPy 2
Python
2,200
train_011.jsonl
9235da61381a1a77c30b68120ea2f0db
256 megabytes
["5 6\n2 1 1\n5 2 6\n2 3 2\n3 4 3\n4 5 5\n1 5 4", "5 7\n2 1 5\n3 2 3\n1 3 3\n2 4 1\n4 3 5\n5 4 1\n1 5 3"]
PASSED
import sys import random, math from collections import defaultdict #n=int(raw_input()) #arr = [int(_) for _ in raw_input().split()] #a = [int(_) for _ in raw_input().split()] N,M = [int(_) for _ in raw_input().split()] table=[] for i in range(M): s,t,c=[int(_) for _ in raw_input().split()] s,t=s-1,t-1 ta...
1547390100
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["6\n3\n5\n4\n15\n10"]
819aebac427c2c0f96e58bca60b81e33
NoteThe first test case is explained in the statement.In the second test case, a $$$6$$$-beautiful necklace can be assembled from all the letters.In the third test case, a $$$1000$$$-beautiful necklace can be assembled, for example, from beads "abzyo".
The store sells $$$n$$$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.A necklace is a set of beads connected in a circle.For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse...
Output $$$t$$$ answers to the test cases. Each answer is a positive integerΒ β€” the maximum length of the $$$k$$$-beautiful necklace you can assemble.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β€” the number of test cases in the test. Then $$$t$$$ test cases follow. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 2000$$$). The second line of each test case contains the string $$$s$$$ containin...
standard output
standard input
Python 3
Python
1,900
train_009.jsonl
9bd5ec1239b41d2b14aaf4ca36aeb98a
256 megabytes
["6\n6 3\nabcbac\n3 6\naaa\n7 1000\nabczgyo\n5 4\nababa\n20 10\naaebdbabdbbddaadaadc\n20 5\necbedececacbcbccbdec"]
PASSED
import math import collections t = int(input()) for _ in range(t): n,k = map(int, input().split()) s = input() ctr = collections.Counter(s) ans = 0 for i in range(1,n+1): g = math.gcd(i, k) l = i // g cnt = sum([(v//l)*l for v in ctr.values()]) if cnt >= i: ...
1592318100
[ "number theory", "graphs" ]
[ 0, 0, 1, 0, 1, 0, 0, 0 ]
1 second
["3", "2"]
a548737890b4bf322d0f8989e5cd25ac
NoteThe picture below shows all three operations for the first sample test. Each time boundary blocks are marked with red color. After first operation there are four blocks left and only one remains after second operation. This last block is destroyed in third operation.
Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built n towers in a row. The i-th tower is made of hi identical blocks. For clarification see picture for the first sample.Limak will repeat the following operation till everything is destroyed.Block is called internal if it ha...
Print the number of operations needed to destroy all towers.
The first line contains single integer n (1 ≀ n ≀ 105). The second line contains n space-separated integers h1, h2, ..., hn (1 ≀ hi ≀ 109) β€” sizes of towers.
standard output
standard input
Python 2
Python
1,600
train_007.jsonl
72b7f3ac2843bef89f104f31d346b51f
256 megabytes
["6\n2 1 4 6 2 2", "7\n3 3 3 1 3 3 3"]
PASSED
N = raw_input() N = int(N) h = raw_input().split(' ') for i in range(len(h)): h[i] = int(h[i]) k = [0]*N for i in range(len(h)): if i != 0 and i != N-1: k[i] = min(k[i-1] + 1, h[i]) else: k[i] = 1 for i in range(len(h)): if i != 0 and i != N-1: k[N - i - 1] = min(k[N-i] + 1, k[N ...
1440865800
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["3", "2"]
89c27a5c76f4ddbd14af2d30ac8b6330
null
You've got an undirected graph, consisting of n vertices and m edges. We will consider the graph's vertices numbered with integers from 1 to n. Each vertex of the graph has a color. The color of the i-th vertex is an integer ci.Let's consider all vertices of the graph, that are painted some color k. Let's denote a set ...
Print the number of the color which has the set of neighbours with the maximum cardinality. It there are multiple optimal colors, print the color with the minimum number. Please note, that you want to find such color, that the graph has at least one vertex with such color.
The first line contains two space-separated integers n, m (1 ≀ n, m ≀ 105) β€” the number of vertices end edges of the graph, correspondingly. The second line contains a sequence of integers c1, c2, ..., cn (1 ≀ ci ≀ 105) β€” the colors of the graph vertices. The numbers on the line are separated by spaces. Next m lines co...
standard output
standard input
PyPy 2
Python
1,600
train_005.jsonl
4894047dbffb65f6bd1c8b2f40e557cd
256 megabytes
["6 6\n1 1 2 3 5 8\n1 2\n3 2\n1 4\n4 3\n4 5\n4 6", "5 6\n4 2 5 2 4\n1 2\n2 3\n3 1\n5 3\n5 4\n3 4"]
PASSED
n,m=map(int,raw_input().split()) c=map(int,raw_input().split()) adj=[[] for i in xrange(n+1)] for i in xrange(m): u,v=map(int,raw_input().split()) adj[u].append(v) adj[v].append(u) ans=111111111111111111111111111111111111111111111111111111111111111110 color=[set() for i in xrange(100010)] count=-1 vis=set()...
1353511800
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
4 seconds
["2\n1\n5\n3\n1"]
f260d0885319a146904b43f89e253f0c
null
You are given a rooted tree, consisting of $$$n$$$ vertices. The vertices are numbered from $$$1$$$ to $$$n$$$, the root is the vertex $$$1$$$.You can perform the following operation at most $$$k$$$ times: choose an edge $$$(v, u)$$$ of the tree such that $$$v$$$ is a parent of $$$u$$$; remove the edge $$$(v, u)$$$;...
For each testcase, print a single integerΒ β€” the smallest height of the tree that can achieved by performing at most $$$k$$$ operations.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of testcases. The first line of each testcase contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 2 \cdot 10^5$$$; $$$0 \le k \le n - 1$$$)Β β€” the number of vertices in the tree and the maximum number of operations you can perfo...
standard output
standard input
Python 3
Python
1,900
train_109.jsonl
5c9aa84b9f75bae04351012635ff0310
256 megabytes
["5\n\n5 1\n\n1 1 2 2\n\n5 2\n\n1 1 2 2\n\n6 0\n\n1 2 3 4 5\n\n6 1\n\n1 2 3 4 5\n\n4 3\n\n1 1 1"]
PASSED
for _ in range(int(input())): n,k=map(int,input().split()) arr=[-1,0]+[int(i) for i in input().split()] l,r=1,n-1 while l<r: mid=(l+r)//2 tot=0 h=[0]*(n+1) for i in range(n,1,-1): if h[i]==mid-1 and arr[i]!=1: tot+=1 else...
1664462100
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
3 seconds
["1\n3\n1", "1", "547558588\n277147129\n457421435\n702277623"]
0afd29ef1b720d2baad2f1c91a583933
NoteIn the first example: The first query is only the empty path β€” length $$$0$$$; The second query are paths $$$[(12, 4), (4, 2), (2, 1)]$$$ (length $$$3+1+1=5$$$), $$$[(12, 6), (6, 2), (2, 1)]$$$ (length $$$2+2+1=5$$$) and $$$[(12, 6), (6, 3), (3, 1)]$$$ (length $$$2+2+1=5$$$). The third query is only the path $$...
You are given a positive integer $$$D$$$. Let's build the following graph from it: each vertex is a divisor of $$$D$$$ (not necessarily prime, $$$1$$$ and $$$D$$$ itself are also included); two vertices $$$x$$$ and $$$y$$$ ($$$x &gt; y$$$) have an undirected edge between them if $$$x$$$ is divisible by $$$y$$$ and $...
Print $$$q$$$ integers β€” for each query output the number of the shortest paths between the two given vertices modulo $$$998244353$$$.
The first line contains a single integer $$$D$$$ ($$$1 \le D \le 10^{15}$$$) β€” the number the graph is built from. The second line contains a single integer $$$q$$$ ($$$1 \le q \le 3 \cdot 10^5$$$) β€” the number of queries. Each of the next $$$q$$$ lines contains two integers $$$v$$$ and $$$u$$$ ($$$1 \le v, u \le D$$$)...
standard output
standard input
PyPy 2
Python
2,200
train_056.jsonl
12061450f6c37e564559281f95b37b1c
256 megabytes
["12\n3\n4 4\n12 1\n3 4", "1\n1\n1 1", "288807105787200\n4\n46 482955026400\n12556830686400 897\n414 12556830686400\n4443186242880 325"]
PASSED
import sys, __pypy__ range = xrange input = raw_input MOD = 998244353 mulmod = __pypy__.intop.int_mulmod inp = [int(x) for x in sys.stdin.read().split()]; ii = 0 D = inp[ii]; ii += 1 q = inp[ii]; ii += 1 U = inp[ii + 0: ii + 2 * q: 2] V = inp[ii + 1: ii + 2 * q: 2] Pdiv = [] if D & 1 == 0: Pdiv.append(2) w...
1586529300
[ "number theory", "math", "graphs" ]
[ 0, 0, 1, 1, 1, 0, 0, 0 ]
1 second
["4\n10\n420\n9969128"]
a24aac9152417527d43b9b422e3d2303
NoteIn the first test case, $$$4 \bmod 4 = 8 \bmod 4 = 0$$$.In the second test case, $$$10 \bmod 4 = 2 \bmod 10 = 2$$$.In the third test case, $$$420 \bmod 420 = 420 \bmod 420 = 0$$$.
YouKn0wWho has two even integers $$$x$$$ and $$$y$$$. Help him to find an integer $$$n$$$ such that $$$1 \le n \le 2 \cdot 10^{18}$$$ and $$$n \bmod x = y \bmod n$$$. Here, $$$a \bmod b$$$ denotes the remainder of $$$a$$$ after division by $$$b$$$. If there are multiple such integers, output any. It can be shown that s...
For each test case, print a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^{18}$$$) that satisfies the condition mentioned in the statement. If there are multiple such integers, output any. It can be shown that such an integer always exists under the given constraints.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) Β β€” the number of test cases. The first and only line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$2 \le x, y \le 10^9$$$, both are even).
standard output
standard input
PyPy 3-64
Python
1,600
train_083.jsonl
cbf2879d49a74d458942c14af7d8f3e7
256 megabytes
["4\n4 8\n4 2\n420 420\n69420 42068"]
PASSED
import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer...
1635604500
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
4 seconds
["11\n10\n14\n13"]
add040eecd8322630fbbce0a2a1de45e
NoteAfter first five operations multiset A contains integers 0, 8, 9, 11, 6 and 1.The answer for the sixth query is integer Β β€” maximum among integers , , , and .
Author has gone out of the stories about Vasiliy, so here is just a formal task description.You are given q queries and a multiset A, initially containing only integer 0. There are three types of queries: "+ x"Β β€” add integer x to multiset A. "- x"Β β€” erase one occurrence of integer x from multiset A. It's guaranteed th...
For each query of the type '?' print one integerΒ β€” the maximum value of bitwise exclusive OR (XOR) of integer xi and some integer from the multiset A.
The first line of the input contains a single integer q (1 ≀ q ≀ 200 000)Β β€” the number of queries Vasiliy has to perform. Each of the following q lines of the input contains one of three characters '+', '-' or '?' and an integer xi (1 ≀ xi ≀ 109). It's guaranteed that there is at least one query of the third type. Note...
standard output
standard input
PyPy 3
Python
1,800
train_008.jsonl
d489a1b855cc03857894602daa8d2ff0
256 megabytes
["10\n+ 8\n+ 9\n+ 11\n+ 6\n+ 1\n? 3\n- 8\n? 3\n? 8\n? 11"]
PASSED
# Why do we fall ? So we can learn to pick ourselves up. class Node: def __init__(self): self.left = None self.right = None self.cnt = 0 class Trie: def __init__(self): self.root = Node() def insert(self,x): self.temp = self.root for i in range(31,-1,-1):...
1470933300
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
3 seconds
["6\n1 3 2", "-1", "9\n1 3 2 1 3"]
644f1469a9a9dcdb94144062ba616c59
NoteAll vertices should be painted in different colors in the first example. The optimal way to do it is to paint the first vertex into color $$$1$$$, the second vertex β€” into color $$$3$$$, and the third vertex β€” into color $$$2$$$. The cost of this painting is $$$3 + 2 + 1 = 6$$$.
You are given a tree consisting of $$$n$$$ vertices. A tree is an undirected connected acyclic graph. Example of a tree. You have to paint each vertex into one of three colors. For each vertex, you know the cost of painting it in every color.You have to paint the vertices so that any path consisting of exactly three...
If there is no good painting, print $$$-1$$$. Otherwise, print the minimum cost of a good painting in the first line. In the second line print $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ $$$(1 \le b_i \le 3)$$$, where the $$$i$$$-th integer should denote the color of the $$$i$$$-th vertex. If there are multiple good pa...
The first line contains one integer $$$n$$$ $$$(3 \le n \le 100\,000)$$$ β€” the number of vertices. The second line contains a sequence of integers $$$c_{1, 1}, c_{1, 2}, \dots, c_{1, n}$$$ $$$(1 \le c_{1, i} \le 10^{9})$$$, where $$$c_{1, i}$$$ is the cost of painting the $$$i$$$-th vertex into the first color. The thi...
standard output
standard input
Python 3
Python
1,800
train_009.jsonl
bc63fee3ecd6696c16bd08868c23f52f
256 megabytes
["3\n3 2 3\n4 3 2\n3 1 3\n1 2\n2 3", "5\n3 4 2 1 2\n4 2 1 5 4\n5 3 2 1 1\n1 2\n3 2\n4 3\n5 3", "5\n3 4 2 1 2\n4 2 1 5 4\n5 3 2 1 1\n1 2\n3 2\n4 3\n5 4"]
PASSED
from collections import defaultdict, deque from itertools import permutations class Graph: def __init__(self): self.E = {} self.V = defaultdict(list) def put(self, v1, v2): if v1 not in self.E: self.E[v1] = 1 if v2 not in self.E: self.E[v2] = 1 ...
1570957500
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
2 seconds
["7\n20"]
996b7f2afdf868dd04b40888008241c8
NoteIn the first example, Polycarp can get score of $$$7$$$ as follows: Firstly he trains for $$$4$$$ minutes, increasing $$$s$$$ to the value of $$$5$$$; Then he decides to solve $$$4$$$-th problem: he watches one episode in $$$10$$$ minutes, his skill level decreases to $$$s=5*0.9=4.5$$$ and then he solves the prob...
Polycarp, Arkady's friend, prepares to the programming competition and decides to write a contest. The contest consists of $$$n$$$ problems and lasts for $$$T$$$ minutes. Each of the problems is defined by two positive integers $$$a_i$$$ and $$$p_i$$$Β β€” its difficulty and the score awarded by its solution.Polycarp's ex...
Print $$$tc$$$ integersΒ β€” the maximum possible score in each test case.
The first line contains one integer $$$tc$$$ ($$$1 \le tc \le 20$$$)Β β€” the number of test cases. Then $$$tc$$$ test cases follow. The first line of each test contains one integer $$$n$$$ ($$$1 \le n \le 100$$$)Β β€” the number of problems in the contest. The second line of the test contains two real values $$$C, T$$$ ($$$...
standard output
standard input
PyPy 3
Python
2,500
train_054.jsonl
c3f27ca0911a958189e297b39edd9117
256 megabytes
["2\n4\n1.000 31.000\n12 3\n20 6\n30 1\n5 1\n3\n1.000 30.000\n1 10\n10 10\n20 8"]
PASSED
from math import sqrt class pro(object): def __init__(self,dif,sc): self.dif=dif self.sc=sc def __lt__(self,other): return self.dif>other.dif T=int(input()) mul=[1] for i in range(100): mul.append(mul[i]*10/9) inf=1000000007 for t in range(T): n=int(input()) effi,tim=map(fl...
1543163700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["1 2 1 \n1 3 2 3 \n1"]
afb43928545743b497b1a9975768f8e5
NoteIn the second test case, the lexicographically minimum cycle looks like: $$$1, 2, 1, 3, 2, 3, 1$$$.In the third test case, it's quite obvious that the cycle should start and end in vertex $$$1$$$.
You are given a complete directed graph $$$K_n$$$ with $$$n$$$ vertices: each pair of vertices $$$u \neq v$$$ in $$$K_n$$$ have both directed edges $$$(u, v)$$$ and $$$(v, u)$$$; there are no self-loops.You should find such a cycle in $$$K_n$$$ that visits every directed edge exactly once (allowing for revisiting verti...
For each test case print the segment $$$v_l, v_{l + 1}, \dots, v_r$$$ of the lexicographically smallest cycle that visits every edge exactly once.
The first line contains the single integer $$$T$$$ ($$$1 \le T \le 100$$$) β€” the number of test cases. Next $$$T$$$ lines contain test cases β€” one per line. The first and only line of each test case contains three integers $$$n$$$, $$$l$$$ and $$$r$$$ ($$$2 \le n \le 10^5$$$, $$$1 \le l \le r \le n(n - 1) + 1$$$, $$$r ...
standard output
standard input
PyPy 3
Python
1,800
train_002.jsonl
85ba21ba1cf20679f6b2fa61b85b452e
256 megabytes
["3\n2 1 3\n3 3 6\n99995 9998900031 9998900031"]
PASSED
def solve(): n, l, r = [int(i) for i in input().split()] seq = [] i = 1 while l <= r: while l > 2 * n - 2: if l == 3: i = 1 break l -= 2 * n - 2 r -= 2 * n - 2 n -= 1 i += 1 if l%2 =...
1586529300
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["YES\nNO\nYES\nNO\nYES\nNO\nNO"]
6fbf41dc32d1c28351d78a9ec5fc0026
NoteIn the first test case, one possible solution is $$$a_1=qw$$$ and $$$a_2=q$$$.In the third test case, one possible solution is $$$a_1=i$$$ and $$$a_2=o$$$.In the fifth test case, one possible solution is $$$a_1=dokidokiliteratureclub$$$.
Kawashiro Nitori is a girl who loves competitive programming.One day she found a string and an integer. As an advanced problem setter, she quickly thought of a problem.Given a string $$$s$$$ and a parameter $$$k$$$, you need to check if there exist $$$k+1$$$ non-empty strings $$$a_1,a_2...,a_{k+1}$$$, such that $$$$$$s...
For each test case, print "YES" (without quotes), if it is possible to find $$$a_1,a_2,\ldots,a_{k+1}$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower).
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case description contains two integers $$$n$$$, $$$k$$$ ($$$1\le n\le 100$$$, $$$0\le k\le \lfloor \frac{n...
standard output
standard input
Python 3
Python
900
train_104.jsonl
e4cb3baf5bbc56a627985e73b5d1c1e1
256 megabytes
["7\n5 1\nqwqwq\n2 1\nab\n3 1\nioi\n4 2\nicpc\n22 0\ndokidokiliteratureclub\n19 8\nimteamshanghaialice\n6 3\naaaaaa"]
PASSED
ans_list = [] for i in range(int(input())): n, k = map(int, input().split()) strings = input() skip = False if(n == 2 * k): ans_list.append("NO") continue for i in range(k): if(strings[i] == strings[n - 1 - i]): pass else: ans_list.append("NO") skip = True break if(skip ==...
1615377900
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["1", "0"]
cb4dbff31d967c3dab8fe0495eb871dc
null
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves...
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
The first line of input contains a single integer n (1 ≀ n ≀ 100) β€” the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≀ xi, yi ≀ 1000) β€” the coordinates of the i-th snow drift. Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсide...
standard output
standard input
Python 3
Python
1,200
train_004.jsonl
ed64ae5b7587331da7cbaff06c56186c
256 megabytes
["2\n2 1\n1 2", "2\n2 1\n4 1"]
PASSED
n = int(input()) coodenadas = [] for i in range(n): x, y = [ int(i) for i in input().split() ] coodenadas.append({ 'x': { x }, 'y': { y } }) for i in range(n-1, -1, -1): j = i - 1 while j >= 0 and i < len(coodenadas): if len(coodenadas[j]['x'].intersection(coodenadas[i]['x'...
1345273500
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["1 2\n2 1\n1 2"]
49a78893ea2849aa59647846b4eaba7c
null
Note that girls in Arpa’s land are really attractive.Arpa loves overnight parties. In the middle of one of these parties Mehrdad suddenly appeared. He saw n pairs of friends sitting around a table. i-th pair consisted of a boy, sitting on the ai-th chair, and his girlfriend, sitting on the bi-th chair. The chairs were ...
If there is no solution, print -1. Otherwise print n lines, the i-th of them should contain two integers which represent the type of food for the i-th pair. The first integer in the line is the type of food the boy had, and the second integer is the type of food the girl had. If someone had Kooft, print 1, otherwise pr...
The first line contains an integer n (1  ≀  n  ≀  105)Β β€” the number of pairs of guests. The i-th of the next n lines contains a pair of integers ai and bi (1  ≀ ai, bi ≀  2n)Β β€” the number of chair on which the boy in the i-th pair was sitting and the number of chair on which his girlfriend was sitting. It's guaranteed ...
standard output
standard input
Python 2
Python
2,600
train_018.jsonl
c5022f2cbc3af8dfbc8a7267a7cf5d05
256 megabytes
["3\n1 4\n2 5\n3 6"]
PASSED
n=int(raw_input()) g=[[]for i in range(n+n)] c=[-1 for i in range(n+n)] e=[] for i in range(n): u,v=map(int,raw_input().split()) u-=1 v-=1 e.append([u,v]) g[u].append(v) g[v].append(u) for i in range(n): g[2*i].append(2*i+1) g[2*i+1].append(2*i) q=[-1 for i in range(2*n)] for i in range(...
1481034900
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
3 seconds
["3.000000000000000\n3.666666666666667\n2.047619047619048\n329737645.750000000000000\n53.700000000000000"]
700cfc8d20794ca38d73ccff31e5292c
NoteIn the first test case cars will meet in the coordinate $$$5$$$.The first car will be in the coordinate $$$1$$$ in $$$1$$$ second and after that its speed will increase by $$$1$$$ and will be equal to $$$2$$$ meters per second. After $$$2$$$ more seconds it will be in the coordinate $$$5$$$. So, it will be in the c...
There is a road with length $$$l$$$ meters. The start of the road has coordinate $$$0$$$, the end of the road has coordinate $$$l$$$.There are two cars, the first standing at the start of the road and the second standing at the end of the road. They will start driving simultaneously. The first car will drive from the s...
For each test case print a single real number: the time required for cars to meet. Your answer will be considered correct, if its absolute or relative error does not exceed $$$10^{-6}$$$. More formally, if your answer is $$$a$$$ and jury's answer is $$$b$$$, your answer will be considered correct if $$$\frac{|a-b|}{\ma...
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$): the number of test cases. The first line of each test case contains two integers $$$n$$$, $$$l$$$ ($$$1 \leq n \leq 10^5$$$, $$$1 \leq l \leq 10^9$$$): the number of flags and the length of the road. The second line contains $$$n$$$ integers $$$a_1...
standard output
standard input
Python 3
Python
1,500
train_035.jsonl
7c288c41453450f015d064cd8289f43b
256 megabytes
["5\n2 10\n1 9\n1 10\n1\n5 7\n1 2 3 4 6\n2 1000000000\n413470354 982876160\n9 478\n1 10 25 33 239 445 453 468 477"]
PASSED
for __ in range(int(input())): n,l=map(int,input().split()) a=list(map(int,input().split())) a.insert(0,0) a.append(l) i,j,va,vb,pra,prb,ta,tb=1,n,1,1,0,l,0,0 res,t=0,0 while True: if abs(j-i)==0: res=1 tempa=(a[i]-pra)/va tempb=(prb-a[j])/vb ta+=t...
1601476500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["5", "47", "62"]
04f75aa0ae4a015b87ac8521cd1d34fc
NoteIn the first example, the chandeliers will have different colors at days $$$1$$$, $$$2$$$, $$$3$$$ and $$$5$$$. That's why the answer is $$$5$$$.
Vasya is a CEO of a big construction company. And as any other big boss he has a spacious, richly furnished office with two crystal chandeliers. To stay motivated Vasya needs the color of light at his office to change every day. That's why he ordered both chandeliers that can change its color cyclically. For example: r...
Print the single integerΒ β€” the index of day when Vasya will become angry.
The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \le n, m \le 500\,000$$$; $$$1 \le k \le 10^{12}$$$)Β β€” the number of colors in the first and the second chandeliers and how many times colors should differ to anger Vasya. The second line contains $$$n$$$ different integers $$$a_i$$$ ($$$1 \le a_...
standard output
standard input
Python 3
Python
2,200
train_095.jsonl
e11402d340c85be30e177cd0869d8ab6
256 megabytes
["4 2 4\n4 2 3 1\n2 1", "3 8 41\n1 3 2\n1 6 4 3 5 7 2 8", "1 2 31\n1\n1 2"]
PASSED
def mcd(a,b): if a==0: return(b) if b==0: return(a) return mcd(b,a%b) def solve(n,m,k,a,b): d = mcd(n,m) mcm = n*m//d [x,y] = BuscarIndices(n,m,d) collection = {} matchings = [] for i in range(n): collection[a[i]] = i for j in range(m): if b[j] in collection and (collection[b[j]]...
1615626300
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["Yes\nYes\nNo\nNo\nNo\nNo\nYes"]
76b3667cce9e23675e21caf6926f608d
NoteIn the first test case, $$$[1,2,3]$$$ is already sorted in non-descending order.In the second test case, we can choose $$$i = 1,j = 2,k = 3$$$. Since $$$a_1 \le a_3$$$, swap $$$a_2$$$ and $$$a_3$$$, the array then becomes $$$[1,2,3]$$$, which is sorted in non-descending order.In the seventh test case, we can do the...
You are given a permutation $$$a_1, a_2, \ldots, a_n$$$ of size $$$n$$$, where each integer from $$$1$$$ to $$$n$$$ appears exactly once.You can do the following operation any number of times (possibly, zero): Choose any three indices $$$i, j, k$$$ ($$$1 \le i &lt; j &lt; k \le n$$$). If $$$a_i &gt; a_k$$$, replace $...
For each test case, output "Yes" (without quotes) if the array can be sorted in non-descending order, and "No" (without quotes) otherwise. You can output "Yes" and "No" in any case (for example, strings "YES", "yEs" and "yes" will be recognized as a positive response).
Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 5000$$$) β€” the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 10$$$) β€” the length of the array $$$a$$$. The second ...
standard output
standard input
Python 3
Python
800
train_101.jsonl
ca3636b92d4fcabeec673b443e461109
256 megabytes
["7\n\n3\n\n1 2 3\n\n3\n\n1 3 2\n\n7\n\n5 3 4 7 6 2 1\n\n7\n\n7 6 5 4 3 2 1\n\n5\n\n2 1 4 5 3\n\n5\n\n2 1 3 4 5\n\n7\n\n1 2 6 7 4 3 5"]
PASSED
for i in range(int(input())): n=int(input()) x=list(map(int,input().split())) if x[0]==min(x): print('YES') else: print('NO')
1667745300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["1", "0", "4"]
fd6b73a2c15f5b009fa350eea9bf0c0a
NoteIn the first example Arkady should block at least one hole. After that, $$$\frac{10 \cdot 2}{6} \approx 3.333$$$ liters of water will flow out of the first hole, and that suits Arkady.In the second example even without blocking any hole, $$$\frac{80 \cdot 3}{10} = 24$$$ liters will flow out of the first hole, that ...
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $$$n$$$ flowers and so it looks like a pipe with $$$n$$$ holes. Arkady can only use the water that flows from the first hole.Arkady can block some of the holes, and then pour $$$A$$$ liters of water into the p...
Print a single integerΒ β€” the number of holes Arkady should block.
The first line contains three integers $$$n$$$, $$$A$$$, $$$B$$$ ($$$1 \le n \le 100\,000$$$, $$$1 \le B \le A \le 10^4$$$)Β β€” the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole. The second line contains $$$n$$$ integers $$$s_1, s_2, \ldots, s_...
standard output
standard input
Python 3
Python
1,000
train_024.jsonl
25e036cc498fe7bbc17317a3c7d98d72
256 megabytes
["4 10 3\n2 2 2 2", "4 80 20\n3 2 1 4", "5 10 10\n1000 1 1 1 1"]
PASSED
I = lambda: map(int, input().split()) n, A, B = I() s1, *S = I() if S: S = sorted(S) total = s1 i = 0 while i < n-1 and s1*A >= B*(total+S[i]): total += S[i] i += 1 print(n-i-1) else: print(0)
1525007700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["YES\n1 5\n1 4\n5 3\n4 3\n5 4", "YES\n3 1\n3 2\n5 3\n3 4\n4 5", "NO"]
29a9015981b39df9db40d41c73286e9f
NoteIn the first example, the array $$$b$$$ will change as follows: $$$[0,0,0,0,0] \rightarrow [-1,0,0,1,0] \rightarrow [-2,0,0,1,1] \rightarrow [-2,0,1,0,1] \rightarrow [-2,0,2,0,0] \rightarrow [-2,0,2,1,-1]$$$. $$$a_i = b_i$$$ for all indices $$$i$$$ from $$$1$$$ to $$$5$$$.In the second example, it is enough for us ...
Oh no, on the first exam Madoka got this hard problem:Given integer $$$n$$$ and $$$m$$$ pairs of integers ($$$v_i, u_i$$$). Also there is an array $$$b_1, b_2, \ldots, b_n$$$, initially filled with zeros.Then for each index $$$i$$$, where $$$1 \leq i \leq m$$$, perform either $$$b_{v_i} := b_{v_i} - 1$$$ and $$$b_{u_i}...
In the first line print "YES" if it is possible to perform operations in the required way, and "NO" otherwise. You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as positive answer). In case you printed "YES", print $$$m$$$ pairs of integers. If for pair $$$(v_i, u_i)$...
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \leq n \leq 10000, 1 \leq m \leq 10000$$$) β€” the length of the array $$$a$$$ and the number of pair of integers. The second line contains $$$n$$$ integers $$$s_1, s_2, \ldots s_n$$$ ($$$0 \le s_i \le 1$$$) β€” the elements of the array $$$s$$$. The third line...
standard output
standard input
PyPy 3-64
Python
2,500
train_104.jsonl
1daf45157599c0131049e21058c209db
256 megabytes
["5 5\n1 1 1 1 1\n-2 0 2 1 -1\n1 5\n1 4\n3 5\n3 4\n4 5", "5 5\n0 1 0 1 0\n0 1 0 0 0\n1 3\n2 3\n3 5\n3 4\n4 5", "4 4\n1 1 1 1\n0 2 -2 2\n1 3\n1 4\n2 3\n2 4"]
PASSED
from collections import deque import sys sys.setrecursionlimit(10**4+10) class mf_graph: n=1 g=[[] for i in range(1)] pos=[] def __init__(self,N): self.n=N self.g=[[] for i in range(N)] self.pos=[] def add_edge(self,From,To,cap): assert 0<=From and From<...
1662129300
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["2", "5"]
bc1e2d9dba07b2ac6b0a118bdbdd063b
NoteIn the first sample test, the optimal solution is to divide the second chemical volume by two, and multiply the third chemical volume by two to make all the volumes equal 4.In the second sample test, the optimal solution is to divide the first chemical volume by two, and divide the second and the third chemical vol...
Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment.Amr has n different types of chemicals. Each chemical i has an initial volume of ai liters. For this experiment, Amr has to mix all the chemicals together, but all the chemicals volumes must be equal first. So his tas...
Output one integer the minimum number of operations required to make all the chemicals volumes equal.
The first line contains one number n (1 ≀ n ≀ 105), the number of chemicals. The second line contains n space separated integers ai (1 ≀ ai ≀ 105), representing the initial volume of the i-th chemical in liters.
standard output
standard input
Python 3
Python
1,900
train_015.jsonl
18e205aef950064cb982cc96b64c37f2
256 megabytes
["3\n4 8 2", "3\n3 5 6"]
PASSED
n = int(input()) s = list(map(int, input().split())) l = [bin(i)[2:] for i in s] length = [len(i) for i in l] maxLen = max(length) minLen = min(length) loc = 0 flag = False for j in range(minLen): for i in range(n): if l[i][j] != l[0][j]: flag = True break if flag: ...
1436886600
[ "math", "graphs" ]
[ 0, 0, 1, 1, 0, 0, 0, 0 ]
4 seconds
["10", "12", "8", "2"]
5d0a985a0dced0734aff6bb0cd1b695d
NoteThese are possible progressions for the first test of examples: 1; 2; 3; 4; 5; 6; 7; 8; 9; 10. These are possible progressions for the second test of examples: 6, 7; 6, 8; 6, 9; 7, 6; 7, 8; 7, 9; 8, 6; 8, 7; 8, 9; 9, 6; 9, 7; 9, 8. These are possible progressions for the third test of exampl...
For given n, l and r find the number of distinct geometrical progression, each of which contains n distinct integers not less than l and not greater than r. In other words, for each progression the following must hold: l ≀ ai ≀ r and ai ≠ aj , where a1, a2, ..., an is the geometrical progression, 1 ≀ i, j ≀ n and i ≠ j...
Print the integer KΒ β€” is the answer to the problem.
The first and the only line cotains three integers n, l and r (1 ≀ n ≀ 107, 1 ≀ l ≀ r ≀ 107).
standard output
standard input
PyPy 2
Python
2,400
train_054.jsonl
71a8f34b5c20ddb936bed761459a216e
256 megabytes
["1 1 10", "2 6 9", "3 1 10", "3 3 10"]
PASSED
rr=raw_input rrI = lambda: int(rr()) rrM = lambda: map(int,rr().split()) debug=0 if debug: fi = open('t.txt','r') rr=lambda: fi.readline().replace('\n','') from fractions import gcd def multi(lower, upper, factor): #How many x: lower <= x <= upper #have factor divide them? return int(upper / facto...
1484838300
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
2 seconds
["2 2 2 2 2 1 1 0 2", "0 -1 1 -1"]
cb8895ddd54ffbd898b1bf5e169feb63
NoteThe first example is shown below:The black vertices have bold borders.In the second example, the best subtree for vertices $$$2, 3$$$ and $$$4$$$ are vertices $$$2, 3$$$ and $$$4$$$ correspondingly. And the best subtree for the vertex $$$1$$$ is the subtree consisting of vertices $$$1$$$ and $$$3$$$.
You are given a tree consisting of $$$n$$$ vertices. A tree is a connected undirected graph with $$$n-1$$$ edges. Each vertex $$$v$$$ of this tree has a color assigned to it ($$$a_v = 1$$$ if the vertex $$$v$$$ is white and $$$0$$$ if the vertex $$$v$$$ is black).You have to solve the following problem for each vertex ...
Print $$$n$$$ integers $$$res_1, res_2, \dots, res_n$$$, where $$$res_i$$$ is the maximum possible difference between the number of white and black vertices in some subtree that contains the vertex $$$i$$$.
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) β€” the number of vertices in the tree. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i$$$ is the color of the $$$i$$$-th vertex. Each of the next $$$n-1$$$ lin...
standard output
standard input
PyPy 3
Python
1,800
train_003.jsonl
46ae57b411205531acb24f463a626d40
256 megabytes
["9\n0 1 1 1 0 0 0 0 1\n1 2\n1 3\n3 4\n3 5\n2 6\n4 7\n6 8\n5 9", "4\n0 0 1 0\n1 2\n1 3\n1 4"]
PASSED
# NOT MY CODE # https://codeforces.com/contest/1324/submission/73179914 ## PYRIVAL BOOTSTRAP # https://github.com/cheran-senthil/PyRival/blob/master/pyrival/misc/bootstrap.py # This decorator allows for recursion without actually doing recursion from types import GeneratorType def bootstrap(f, stack=[]): def wr...
1584018300
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
1 second
["3\n4 6 12", "-1"]
dfe5af743c9e23e98e6c9c5c319d2126
NoteIn the first example 2 = gcd(4, 6), the other elements from the set appear in the sequence, and we can show that there are no values different from 2, 4, 6 and 12 among gcd(ai, ai + 1, ..., aj) for every 1 ≀ i ≀ j ≀ n.
In a dream Marco met an elderly man with a pair of black glasses. The man told him the key to immortality and then disappeared with the wind of time.When he woke up, he only remembered that the key was a sequence of positive integers of some length n, but forgot the exact sequence. Let the elements of the sequence be a...
If there is no solution, print a single line containing -1. Otherwise, in the first line print a single integer n denoting the length of the sequence, n should not exceed 4000. In the second line print n integers a1, a2, ..., an (1 ≀ ai ≀ 106)Β β€” the sequence. We can show that if a solution exists, then there is a solut...
The first line contains a single integer m (1 ≀ m ≀ 1000)Β β€” the size of the set S. The second line contains m integers s1, s2, ..., sm (1 ≀ si ≀ 106)Β β€” the elements of the set S. It's guaranteed that the elements of the set are given in strictly increasing order, that means s1 &lt; s2 &lt; ... &lt; sm.
standard output
standard input
Python 3
Python
1,900
train_012.jsonl
39544a59f4811e66a7ba6090a916e087
256 megabytes
["4\n2 4 6 12", "2\n2 3"]
PASSED
n=int(input()) a=list(map(int,input().split())) cur=a[-1] from math import gcd for i in range(1,n-1): cur=gcd(cur,a[i]) if (cur %a[0]!=0) and (a[0]!=1): print(-1) else: print(2*n) for i in a: print(i,a[0],end=' ')
1511099700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["3"]
52863d45ad223687e6975344ab9d3124
NoteSample 1. The damage range of the Book of Evil equals 3 and its effects have been noticed in settlements 1 and 2. Thus, it can be in settlements 3, 4 or 5.
Paladin Manao caught the trail of the ancient Book of Evil in a swampy area. This area contains n settlements numbered from 1 to n. Moving through the swamp is very difficult, so people tramped exactly n - 1 paths. Each of these paths connects some pair of settlements and is bidirectional. Moreover, it is possible to r...
Print a single number β€” the number of settlements that may contain the Book of Evil. It is possible that Manao received some controversial information and there is no settlement that may contain the Book. In such case, print 0.
The first line contains three space-separated integers n, m and d (1 ≀ m ≀ n ≀ 100000;Β 0 ≀ d ≀ n - 1). The second line contains m distinct space-separated integers p1, p2, ..., pm (1 ≀ pi ≀ n). Then n - 1 lines follow, each line describes a path made in the area. A path is described by a pair of space-separated integer...
standard output
standard input
Python 3
Python
2,000
train_017.jsonl
02ee61856c25477c51d643db6e14d300
256 megabytes
["6 2 3\n1 2\n1 5\n2 3\n3 4\n4 5\n5 6"]
PASSED
import collections class Graph: def __init__(self, n, dir): self.node_cnt = n self.__directed = dir self.__adjList = [] for i in range(n): self.__adjList.append([]) def addEdge(self, u, v): self.__adjList[u].append(v) if not self.__directed: self.__adjList[v].append(u) def getDistances(self, start, e...
1376668800
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
2 seconds
["4\n5\n8", "7\n10\n5"]
37e2bb1c7caeeae7f8a7c837a2b390c9
null
There is a system of n vessels arranged one above the other as shown in the figure below. Assume that the vessels are numbered from 1 to n, in the order from the highest to the lowest, the volume of the i-th vessel is ai liters. Initially, all the vessels are empty. In some vessels water is poured. All the water that ...
For each query, print on a single line the number of liters of water in the corresponding vessel.
The first line contains integer n β€” the number of vessels (1 ≀ n ≀ 2Β·105). The second line contains n integers a1, a2, ..., an β€” the vessels' capacities (1 ≀ ai ≀ 109). The vessels' capacities do not necessarily increase from the top vessels to the bottom ones (see the second sample). The third line contains integer m ...
standard output
standard input
PyPy 3
Python
1,800
train_043.jsonl
737bd9d084eac06ecf5bed158a9be7c9
256 megabytes
["2\n5 10\n6\n1 1 4\n2 1\n1 2 5\n1 1 4\n2 1\n2 2", "3\n5 10 8\n6\n1 1 12\n2 2\n1 1 6\n1 3 2\n2 2\n2 3"]
PASSED
'''input 2 5 10 6 1 1 4 2 1 1 2 5 1 1 4 2 1 2 2 ''' # its dsu from sys import stdin, setrecursionlimit import math from collections import defaultdict, deque setrecursionlimit(15000) def process_query(node, x, max_capacity, cur_capacity, link): i = node while link[i] != n + 1 and x > 0 : if cur_capacity[lin...
1386493200
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
3 seconds
["8\n4\n6\n11"]
2e7d4deeeb700d7ad008875779d6f969
NoteIn the first test case, YouKn0wWho can select the sequence $$$[0, 2, 6]$$$. So $$$f(6, 2) = c(1, 2) + c(3, 6) = 3 + 5 = 8$$$ which is the minimum possible.
For two positive integers $$$l$$$ and $$$r$$$ ($$$l \le r$$$) let $$$c(l, r)$$$ denote the number of integer pairs $$$(i, j)$$$ such that $$$l \le i \le j \le r$$$ and $$$\operatorname{gcd}(i, j) \ge l$$$. Here, $$$\operatorname{gcd}(i, j)$$$ is the greatest common divisor (GCD) of integers $$$i$$$ and $$$j$$$.YouKn0wW...
For each test case, print a single integerΒ β€” $$$f(n, k)$$$.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3 \cdot 10^5$$$)Β β€” the number of test cases. The first and only line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^5$$$).
standard output
standard input
PyPy 3-64
Python
3,000
train_110.jsonl
1dfa86aa93dd171ae6b5b8eea2b0b0bc
1024 megabytes
["4\n6 2\n4 4\n3 1\n10 3"]
PASSED
# 1603D from itertools import accumulate from collections import Counter from math import floor, sqrt import io, os, sys input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n, n2, n3 = 100009, 320, 18 phi = list(range(n)) root = [0]*n for i in range(2, n): if phi[i] == i: for j i...
1635604500
[ "number theory" ]
[ 0, 0, 0, 0, 1, 0, 0, 0 ]
3 seconds
["3\n1 4 1\n5 6 2\n3 4 3\n-1\n2\n1 2 1\n2 3 1\n-1\n3\n1 3 2\n5 6 3\n3 4 1"]
a4f4ad94387b16e8760e7c7fd45b93b3
NoteThe example from the statement.In the second case, it is impossible to represent by segments of known numbers of length 2 or more.In the third case, you can get the segments '12' and '21' from the first phone number.
Masha meets a new friend and learns his phone numberΒ β€” $$$s$$$. She wants to remember it as soon as possible. The phone numberΒ β€” is a string of length $$$m$$$ that consists of digits from $$$0$$$ to $$$9$$$. The phone number may start with 0.Masha already knows $$$n$$$ phone numbers (all numbers have the same length $$...
You need to print the answers to $$$t$$$ test cases. The first line of the answer should contain one number $$$k$$$, corresponding to the number of segments into which you split the phone number $$$s$$$. Print -1 if you cannot get such a split. If the answer is yes, then follow $$$k$$$ lines containing triples of numbe...
The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€”the number of test cases. Before each test case there is a blank line. Then there is a line containing integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^3$$$)Β β€”the number of phone numbers that Masha knows and the number of digits in eac...
standard output
standard input
PyPy 3
Python
2,000
train_102.jsonl
bf0b6e31df55c0f6196000eec2f4fcf7
256 megabytes
["5\n\n4 8\n12340219\n20215601\n56782022\n12300678\n12345678\n\n2 3\n134\n126\n123\n\n1 4\n1210\n1221\n\n4 3\n251\n064\n859\n957\n054\n\n4 7\n7968636\n9486033\n4614224\n5454197\n9482268"]
PASSED
import math,sys;input=sys.stdin.readline;S=lambda:input().rstrip();I=lambda:int(S());M=lambda:map(int,S().split());L=lambda:list(M());mod1=1000000007;mod2=998244353 for _ in range(I()): S();n,m=M();have={};pos={};dp=[0]*(m+1);pr=[0]*(m+1);dp[0]=1 for i in range(n): cur=S() for j in range(m): t=cur[j] ...
1641825300
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["-3 5 1 2 2\n1 1 1"]
fa24700412a8532b5b92c1e72d8a2e2d
NoteIn the first case, when removing vertex $$$1$$$ all remaining connected components have sum $$$5$$$ and when removing vertex $$$3$$$ all remaining connected components have sum $$$2$$$. When removing other vertices, there is only one remaining connected component so all remaining connected components have the same ...
You are given an undirected unrooted tree, i.e. a connected undirected graph without cycles.You must assign a nonzero integer weight to each vertex so that the following is satisfied: if any vertex of the tree is removed, then each of the remaining connected components has the same sum of weights in its vertices.
For each test case, you must output one line with $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$, where $$$a_i$$$ is the weight assigned to vertex $$$i$$$. The weights must satisfy $$$-10^5 \leq a_i \leq 10^5$$$ and $$$a_i \neq 0$$$. It can be shown that there always exists a solution satisfying these con...
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) β€” the number of test cases. Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3 \leq n \leq 10^5$$$) β€” the number of vertices of the tree. The next...
standard output
standard input
PyPy 3-64
Python
2,200
train_092.jsonl
6853dc337b70dbcddcfb51dfd4903043
256 megabytes
["2\n5\n1 2\n1 3\n3 4\n3 5\n3\n1 2\n1 3"]
PASSED
import os,sys from io import BytesIO, IOBase from collections import deque, Counter,defaultdict as dft from heapq import heappop ,heappush from math import log,sqrt,factorial,cos,tan,sin,radians,log2,ceil,floor,gcd from bisect import bisect,bisect_left,bisect_right from decimal import * import sys,thre...
1648132500
[ "math", "trees" ]
[ 0, 0, 0, 1, 0, 0, 0, 1 ]
1 second
["YES\na\nba\naba\naba\nabacaba", "NO", "YES\nqwerty\nqwerty\nqwerty"]
5c33d1f970bcc2ffaea61d5407b877b2
NoteIn the second example you cannot reorder the strings because the string "abab" is not a substring of the string "abacaba".
You are given $$$n$$$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings.String $$$a$$$ is a substring of string $$$b$$$ if it is possible to choose several consecutive letters in...
If it is impossible to reorder $$$n$$$ given strings in required order, print "NO" (without quotes). Otherwise print "YES" (without quotes) and $$$n$$$ given strings in required order.
The first line contains an integer $$$n$$$ ($$$1 \le n \le 100$$$) β€” the number of strings. The next $$$n$$$ lines contain the given strings. The number of letters in each string is from $$$1$$$ to $$$100$$$, inclusive. Each string consists of lowercase English letters. Some strings might be equal.
standard output
standard input
PyPy 2
Python
1,100
train_002.jsonl
91eff6545e8e939cd34817c18228732a
256 megabytes
["5\na\naba\nabacaba\nba\naba", "5\na\nabacaba\nba\naba\nabab", "3\nqwerty\nqwerty\nqwerty"]
PASSED
n = input() ll = [] for i in xrange(n): ll.append(raw_input()) ll.sort(key=lambda x: len(x)) check = False for i in xrange(n): for j in xrange(i+1, n): if ll[i] not in ll[j]: check = True break if not check: print "YES" print "\n".join(ll) else: print "NO"
1614692100
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
4 seconds
["YES\nYES\nNO\nYES\nNO"]
c53e3b38a345dcf65bf984e819c289ef
NoteThe image below describes the tree (circles and solid lines) and the added edges for each query (dotted lines). Possible paths for the queries with "YES" answers are: $$$1$$$-st query: $$$1$$$ – $$$3$$$ – $$$2$$$ $$$2$$$-nd query: $$$1$$$ – $$$2$$$ – $$$3$$$ $$$4$$$-th query: $$$3$$$ – $$$4$$$ – $$$2$$$ – $$$3...
Gildong was hiking a mountain, walking by millions of trees. Inspired by them, he suddenly came up with an interesting idea for trees in data structures: What if we add another edge in a tree?Then he found that such tree-like graphs are called 1-trees. Since Gildong was bored of solving too many tree problems, he wante...
For each query, print "YES" if there exists a path that contains exactly $$$k$$$ edges from vertex $$$a$$$ to $$$b$$$ after adding an edge between vertices $$$x$$$ and $$$y$$$. Otherwise, print "NO". You can print each letter in any case (upper or lower).
The first line contains an integer $$$n$$$ ($$$3 \le n \le 10^5$$$), the number of vertices of the tree. Next $$$n-1$$$ lines contain two integers $$$u$$$ and $$$v$$$ ($$$1 \le u,v \le n$$$, $$$u \ne v$$$) each, which means there is an edge between vertex $$$u$$$ and $$$v$$$. All edges are bidirectional and distinct. N...
standard output
standard input
Python 3
Python
2,000
train_009.jsonl
598575b1787c458d287272021f730065
512 megabytes
["5\n1 2\n2 3\n3 4\n4 5\n5\n1 3 1 2 2\n1 4 1 3 2\n1 4 1 3 3\n4 2 3 3 9\n5 2 3 3 9"]
PASSED
import sys # LCA implementation found from: # https://github.com/cheran-senthil/PyRival/blob/1971590e96b351288cacb09852896f2383862ab6/pyrival/graphs/lca.py class RangeQuery: def __init__(self, data, func=min): self.func = func self._data = _data = [list(data)] i, n = 1, len(_data[0]) ...
1581771900
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
2 seconds
["YES\nNO\nYES\nYES"]
53a3313f5d6ce19413d72473717054fc
NoteThe first test case of the example field is shown below:Gray lines are bounds of the Tetris field. Note that the field has no upper bound.One of the correct answers is to first place the figure in the first column. Then after the second step of the process, the field becomes $$$[2, 0, 2]$$$. Then place the figure i...
You are given some Tetris field consisting of $$$n$$$ columns. The initial height of the $$$i$$$-th column of the field is $$$a_i$$$ blocks. On top of these columns you can place only figures of size $$$2 \times 1$$$ (i.e. the height of this figure is $$$2$$$ blocks and the width of this figure is $$$1$$$ block). Note ...
For each test case, print the answer β€” "YES" (without quotes) if you can clear the whole Tetris field and "NO" otherwise.
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases. The next $$$2t$$$ lines describe test cases. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) β€” the number of columns in the Tetris field. The second line of the test case con...
standard output
standard input
PyPy 3
Python
900
train_007.jsonl
06468094bbaa2db78f3cefb55047df7d
256 megabytes
["4\n3\n1 1 3\n4\n1 1 2 1\n2\n11 11\n1\n100"]
PASSED
import sys def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def main(): for k in range(inp()): n=inp() col=inlt() i=0 for b in col: if(n-1!=i): if(col[i+1]-b)%2==1: print("NO") ...
1584018300
[ "number theory" ]
[ 0, 0, 0, 0, 1, 0, 0, 0 ]
2 seconds
["1\n2\n2\n2"]
3b8678d118c90d34c99ffa9259cc611f
NoteIn the first test case, $$$s_1$$$ is palindrome, so the answer is $$$1$$$.In the second test case you can't make all three strings palindromic at the same time, but you can make any pair of strings palindromic. For example, let's make $$$s_1 = \text{0110}$$$, $$$s_2 = \text{111111}$$$ and $$$s_3 = \text{010000}$$$....
A palindrome is a string $$$t$$$ which reads the same backward as forward (formally, $$$t[i] = t[|t| + 1 - i]$$$ for all $$$i \in [1, |t|]$$$). Here $$$|t|$$$ denotes the length of a string $$$t$$$. For example, the strings 010, 1001 and 0 are palindromes.You have $$$n$$$ binary strings $$$s_1, s_2, \dots, s_n$$$ (each...
Print $$$Q$$$ integers β€” one per test case. The $$$i$$$-th integer should be the maximum number of palindromic strings you can achieve simultaneously performing zero or more swaps on strings from the $$$i$$$-th test case.
The first line contains single integer $$$Q$$$ ($$$1 \le Q \le 50$$$) β€” the number of test cases. The first line on each test case contains single integer $$$n$$$ ($$$1 \le n \le 50$$$) β€” the number of binary strings you have. Next $$$n$$$ lines contains binary strings $$$s_1, s_2, \dots, s_n$$$ β€” one per line. It's gu...
standard output
standard input
PyPy 3
Python
1,400
train_001.jsonl
2b752b2bd363a0151af8db9e5d90d9af
256 megabytes
["4\n1\n0\n3\n1110\n100110\n010101\n2\n11111\n000001\n2\n001\n11100111"]
PASSED
#!/usr/bin/env python import os import operator from collections import defaultdict import sys from io import BytesIO, IOBase import bisect # def power(x, p): # res = 1 # while p: # if p & 1: # res = res * x % 1000000007 # x = x * x % 1000000007 # p >>= 1 # return res; ...
1571929500
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["1 2", "4 2 2 4"]
d2d21871c068e04469047e959dcf0d09
null
During the programming classes Vasya was assigned a difficult problem. However, he doesn't know how to code and was unable to find the solution in the Internet, so he asks you to help.You are given a sequence $$$a$$$, consisting of $$$n$$$ distinct integers, that is used to construct the binary search tree. Below is th...
Output $$$n - 1$$$ integers. For all $$$i &gt; 1$$$ print the value written in the node that is the parent of the node with value $$$a_i$$$ in it.
The first line of the input contains a single integer $$$n$$$ ($$$2 \leq n \leq 100\,000$$$)Β β€” the length of the sequence $$$a$$$. The second line contains $$$n$$$ distinct integers $$$a_i$$$ ($$$1 \leq a_i \leq 10^9$$$)Β β€” the sequence $$$a$$$ itself.
standard output
standard input
PyPy 3
Python
1,800
train_024.jsonl
0e42650e13b95048df3d04e46cf6c2c6
256 megabytes
["3\n1 2 3", "5\n4 2 3 1 6"]
PASSED
# pylint: disable=redefined-builtin, ungrouped-imports from __future__ import print_function from bisect import bisect_left, bisect_right, insort from collections import Sequence, MutableSequence from functools import wraps from itertools import chain, repeat, starmap from math import log as log_e import operator as op...
1463416500
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
2 seconds
["0\n2\n13\n3\n20"]
36aec7a06c02052f562ea3d44d4a62e4
null
You are given the strings $$$a$$$ and $$$b$$$, consisting of lowercase Latin letters. You can do any number of the following operations in any order: if $$$|a| &gt; 0$$$ (the length of the string $$$a$$$ is greater than zero), delete the first character of the string $$$a$$$, that is, replace $$$a$$$ with $$$a_2 a_3 ...
For each test case, output the minimum number of operations that can make the strings $$$a$$$ and $$$b$$$ equal.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$). Then $$$t$$$ test cases follow. The first line of each test case contains the string $$$a$$$ ($$$1 \le |a| \le 20$$$), consisting of lowercase Latin letters. The second line of each test case contains the string $$$b$$$ ($$$1 \le |b| \le 20$$$), ...
standard output
standard input
Python 3
Python
1,000
train_101.jsonl
cbcd2027912233e68fe65867ce7731c8
256 megabytes
["5\na\na\nabcd\nbc\nhello\ncodeforces\nhello\nhelo\ndhjakjsnasjhfksafasd\nadjsnasjhfksvdafdser"]
PASSED
import sys def stringComparator(a, b): n = len(a) m = len(b) size = 0 for i in range(1, min(n,m) + 1): for j in range(0, n - i + 1): for k in range(0, m - i + 1): if (a[j: j + i] == b[k: k + i]): size = max(size, i) #print("fina...
1616682900
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["2 1", "1 3 2"]
f35d7f9c12eea4364891e0449613f6b0
null
Vasya bought the collected works of a well-known Berland poet Petya in n volumes. The volumes are numbered from 1 to n. He thinks that it does not do to arrange the book simply according to their order. Vasya wants to minimize the number of the disposition’s divisors β€” the positive integers i such that for at least one...
Print n numbers β€” the sought disposition with the minimum divisor number. The j-th number (1 ≀ j ≀ n) should be equal to p(j) β€” the number of tome that stands on the j-th place. If there are several solutions, print any of them.
The first line contains number n (1 ≀ n ≀ 100000) which represents the number of volumes and free places.
standard output
standard input
PyPy 3
Python
1,700
train_007.jsonl
17218f3206b7060ec4739761660fdf0a
256 megabytes
["2", "3"]
PASSED
#Code by Sounak, IIESTS #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase from fractions import Fraction from collections import defaultdict BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): ...
1292601600
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["XXX\n..X\nXXX\nXXXX\n.X.X\n.X..\n.XXX\n.X...\n.XXXX\n.X...\n.X...\nXXXXX\nXXXXXXXXXX\n..\n.."]
669390a40a6ef9bf1547c71823da169b
NoteLet's use $$$(x,y)$$$ to describe the cell on $$$x$$$-th row and $$$y$$$-th column.In the following pictures white, yellow, and blue cells stand for the cells that grow a sunflower, the cells lightning stroke, and the cells sunflower on which are removed, respectively.In the first test case, one possible solution i...
There are many sunflowers in the Garden of the Sun.Garden of the Sun is a rectangular table with $$$n$$$ rows and $$$m$$$ columns, where the cells of the table are farmlands. All of the cells grow a sunflower on it. Unfortunately, one night, the lightning stroke some (possibly zero) cells, and sunflowers on those cells...
For each test case, print $$$n$$$ lines. Each should contain $$$m$$$ characters, representing one row of the table. Each character should be either 'X' or '.', representing an empty cell and a cell with a sunflower, respectively. If there are multiple answers, you can print any. It can be shown that the answer always e...
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line contains two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$)Β β€” the number of rows and columns. Each of the next $$...
standard output
standard input
PyPy 3
Python
2,300
train_085.jsonl
3b758af957b840cfe4bce60eff7a5d8b
256 megabytes
["5\n3 3\nX.X\n...\nX.X\n4 4\n....\n.X.X\n....\n.X.X\n5 5\n.X...\n....X\n.X...\n.....\nX.X.X\n1 10\n....X.X.X.\n2 2\n..\n.."]
PASSED
import sys input = sys.stdin.readline t=int(input()) for tests in range(t): n,m=map(int,input().split()) MAP=[list(input().strip()) for i in range(n)] if m<=1: for i in range(n): MAP[i][0]="X" for j in range(1,m,3): for i in range(n): MAP[i][j]=...
1615377900
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["8\n141093479"]
5c3eb78a7e15d9afe6d745e1a77d7451
null
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).You've got some numbe...
Print the sought number of operations for each pair on a single line.
The first line contains the number of pairs n (1  ≀  n  ≀  1000). Then follow n lines, each line contains a pair of positive integers ai, bi (1  ≀  ai,  bi  ≀  109).
standard output
standard input
Python 3
Python
900
train_002.jsonl
87bff2ba34b4208ed96986b662590d89
256 megabytes
["2\n4 17\n7 987654321"]
PASSED
def solve(a, b): holder = [a, b] times = 0 while holder[0] > 0 and holder[1] > 0: smaller = 0 if holder[0] < holder[1] else 1 other = 1 - smaller # how many times does smaller go into bigger? times += holder[other] // holder[smaller] # guaranteed to be smaller than `smaller` now holder[o...
1358002800
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
2 seconds
["1\n12\n13\n28\n55\n85\n500099995000"]
7d774a003d2e3e8ae6fe1912b3998c96
NoteIn the first test case the only possible path consists of a single cell $$$(1, 1)$$$.The path with the minimal cost in the second test case is shown in the statement.In the fourth and the fifth test cases there is only one path from $$$(1, 1)$$$ to $$$(n, m)$$$. Both paths visit every cell in the table.
You are given a table $$$a$$$ of size $$$n \times m$$$. We will consider the table rows numbered from top to bottom from $$$1$$$ to $$$n$$$, and the columns numbered from left to right from $$$1$$$ to $$$m$$$. We will denote a cell that is in the $$$i$$$-th row and in the $$$j$$$-th column as $$$(i, j)$$$. In the cell ...
For each test case output a single integer β€” a minimal possible cost of a path from the cell $$$(1, 1)$$$ to the cell $$$(n, m)$$$.
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) β€” the number of test cases. The description of test cases follows. A single line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 10^4$$$) β€” the number of rows and columns of the table $$$a$$$ respectively.
standard output
standard input
PyPy 3-64
Python
800
train_094.jsonl
6ae99e03dfee779a013589b2966d2b43
256 megabytes
["7\n\n1 1\n\n2 3\n\n3 2\n\n7 1\n\n1 10\n\n5 5\n\n10000 10000"]
PASSED
t = int(input()) list = [] for i in range(1,t+1): pair = input().split() list.append(pair) for i in range(1,t+1): n = int(list[i-1][0]) m = int(list[i-1][1]) sum = 0 for x in range(1,m): sum = sum + x for y in range(1,n+1): sum = sum + (y*m) print(sum)
1655629500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]