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 | ["? 1 2\n\n? 1 3\n\n? 1 4\n\n! 3"] | 8590f40e7509614694486165ee824587 | NoteIn the first example, the graph could look like this The lengths of the simple paths between all pairs of vertices in this case are $$$1$$$ or $$$2$$$. The first query finds out that one of the simple paths from vertex $$$1$$$ to vertex $$$2$$$ has a length of $$$1$$$. With the second query, we find out that on... | This is an interactive problem.I want to play a game with you...We hid from you a cyclic graph of $$$n$$$ vertices ($$$3 \le n \le 10^{18}$$$). A cyclic graph is an undirected graph of $$$n$$$ vertices that form one cycle. Each vertex belongs to the cycle, i.e. the length of the cycle (the number of edges in it) is exa... | null | null | standard output | standard input | PyPy 3-64 | Python | 1,800 | train_110.jsonl | c5d8cd50f4f067925b59f3cf404756a3 | 256 megabytes | ["1\n\n2\n\n-1"] | PASSED | for i in range(3, 26):
print(f"? 1 {i}", flush=True)
a = int(input())
if (a == -1):
print(f'! {i - 1}')
exit()
print(f"? {i} 1", flush=True)
b = int(input())
if a != b:
print(f'! {a + b}')
exit() | 1662993300 | [
"probabilities"
] | [
0,
0,
0,
0,
0,
1,
0,
0
] | |
1 second | ["YES\nNO\nYES\nNO\nYES\nYES"] | e5a0005e0832e2ca3dd248f6aefb2238 | NoteHere's the solution for the first test case. The red square denotes where the crickets need to reach. Note that in chess horizontals are counted from bottom to top, as well as on this picture. | Ela likes Chess a lot. During breaks, she usually challenges her co-worker in DTL to some chess games. She's not an expert at classic chess, but she's very interested in Chess variants, where she has to adapt to new rules and test her tactical mindset to win the game.The problem, which involves a non-standard chess pie... | For each test case, print "YES" or "NO" to denotes whether Ela can put a cricket on the target square. | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows. The first line of each test case contains $$$n$$$ ($$$4 \le n \le 10^5$$$) — denotes the size of the chessboard. The second line of each test case contain... | standard output | standard input | Python 3 | Python | 1,500 | train_094.jsonl | 350f6c381ca6dcf04e7abf300381d9e6 | 256 megabytes | ["6\n\n8\n\n7 2 8 2 7 1\n\n5 1\n\n8\n\n2 2 1 2 2 1\n\n5 5\n\n8\n\n2 2 1 2 2 1\n\n6 6\n\n8\n\n1 1 1 2 2 1\n\n5 5\n\n8\n\n2 2 1 2 2 1\n\n8 8\n\n8\n\n8 8 8 7 7 8\n\n4 8"] | PASSED | import math
import collections
import bisect
import heapq
from collections import deque
from math import sqrt,ceil, floor
def inp_arr():
return list(map(int, input().strip().split(" ")))
def inp_int():
return int(input())
def inp_str():
return input()
'''...................... | 1665153300 | [
"math",
"games"
] | [
1,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["3 4\n1 1 1 1", "2 3\n1 1 1", "2 2\n1 1", "6 11\n1 1 1 1 1 1 1 3 1"] | dc3848faf577c5a49273020a14b343e1 | NoteThis is the tree for the first test case: In this case, if you assign a weight of $$$1$$$ to each vertex, then the good vertices (which are painted black) are $$$1$$$, $$$3$$$ and $$$4$$$. It impossible to assign weights so that all vertices are good vertices. The minimum sum of weights in this case is $$$1+1+1+... | You are given a tree of $$$n$$$ vertices numbered from $$$1$$$ to $$$n$$$. A tree is a connected undirected graph without cycles. For each $$$i=1,2, \ldots, n$$$, let $$$w_i$$$ be the weight of the $$$i$$$-th vertex. A vertex is called good if its weight is equal to the sum of the weights of all its neighbors.Initially... | In the first line print two integers — the maximum number of good vertices and the minimum possible sum of weights for that maximum. In the second line print $$$n$$$ integers $$$w_1, w_2, \ldots, w_n$$$ ($$$1\le w_i\le 10^9$$$) — the corresponding weight assigned to each vertex. It can be proven that there exists an ... | The first line contains one integer $$$n$$$ ($$$2\le n\le 2\cdot 10^5$$$) — the number of vertices in the tree. Then, $$$n−1$$$ lines follow. Each of them contains two integers $$$u$$$ and $$$v$$$ ($$$1\le u,v\le n$$$) denoting an edge between vertices $$$u$$$ and $$$v$$$. It is guaranteed that the edges form a tree. | standard output | standard input | PyPy 3-64 | Python | 2,000 | train_110.jsonl | 2468b1e1f237837269e5f3138f497cb3 | 256 megabytes | ["4\n1 2\n2 3\n2 4", "3\n1 2\n1 3", "2\n1 2", "9\n3 4\n7 6\n2 1\n8 3\n5 6\n1 8\n8 6\n9 6"] | PASSED | #!/usr/bin/env python3
import sys
# import getpass # not available on codechef
# import math, random
# import functools, itertools, collections, heapq, bisect
from collections import defaultdict
input = sys.stdin.readline # to read input quickly
# available on Google, AtCoder Python3, not available on Codeforces
# i... | 1646408100 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["1110011110\n0011\n0110001100101011\n10\n0000111\n1111\n000"] | 4bbb078b66b26d6414e30b0aae845b98 | null | For some binary string $$$s$$$ (i.e. each character $$$s_i$$$ is either '0' or '1'), all pairs of consecutive (adjacent) characters were written. In other words, all substrings of length $$$2$$$ were written. For each pair (substring of length $$$2$$$), the number of '1' (ones) in it was calculated.You are given three ... | Print $$$t$$$ lines. Each of the lines should contain a binary string corresponding to a test case. If there are several possible solutions, print any of them. | The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the input. Then test cases follow. Each test case consists of one line which contains three integers $$$n_0, n_1, n_2$$$ ($$$0 \le n_0, n_1, n_2 \le 100$$$; $$$n_0 + n_1 + n_2 > 0$$$). It is guaranteed that the answer f... | standard output | standard input | Python 3 | Python | 1,500 | train_000.jsonl | ab934202d948056f7e8caca09d32dc3d | 256 megabytes | ["7\n1 3 5\n1 1 1\n3 9 3\n0 1 0\n3 1 2\n0 0 3\n2 0 0"] | PASSED | def ans_v2(n_0, n_1, n_2):
ans_left = ''
ans_center = ''
ans_right = ''
if n_1 == 0:
if n_0 > 0:
ans_left = '0'*(n_0 + 1)
else:
ans_right = '1'*(n_2 + 1)
else:
if n_0 == 0:
if (n_1 % 2 == 0):
ans_left = '10'*(n_1 // 2)
... | 1589034900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["codeforces round letter round", "hbnyiyc joll joll un joll"] | edd556d60de89587f1b8daa893538530 | null | You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consist... | Output exactly n words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. | The first line contains two integers, n and m (1 ≤ n ≤ 3000, 1 ≤ m ≤ 3000) — the number of words in the professor's lecture and the number of words in each of these languages. The following m lines contain the words. The i-th line contains two strings ai, bi meaning that the word ai belongs to the first language, the w... | standard output | standard input | Python 2 | Python | 1,000 | train_000.jsonl | 40a2a72adab2d9497e4db77cd8db391c | 256 megabytes | ["4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest", "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll"] | PASSED | n, m = map(int, raw_input().split())
a = dict()
for i in xrange(m):
s1, s2 = raw_input().split()
if len(s2) < len(s1):
a[s1] = s2
else:
a[s1] = s1
for s in raw_input().split():
print a[s],
| 1419438600 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["YES\nNO\nYES\nNO\nYES", "YES\nNO\nYES\nYES"] | e2db2e7470a24c17158772be94eef12c | null | This is an easy version of the problem. The only difference between an easy and a hard version is in the number of queries.Polycarp grew a tree from $$$n$$$ vertices. We remind you that a tree of $$$n$$$ vertices is an undirected connected graph of $$$n$$$ vertices and $$$n-1$$$ edges that does not contain cycles.He ca... | Output $$$q$$$ lines, each of which contains the answer to the corresponding query. As an answer, output "YES" if the set is passable, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer). | The first line of input contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — number of vertices. Following $$$n - 1$$$ lines a description of the tree.. Each line contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$, $$$u \ne v$$$) — indices of vertices connected by an edge. Following line ... | standard output | standard input | PyPy 3-64 | Python | 1,900 | train_089.jsonl | d15fdd310b6b0d01b4e2e7f7d4fdc839 | 256 megabytes | ["5\n1 2\n2 3\n2 4\n4 5\n5\n3\n3 2 5\n5\n1 2 3 4 5\n2\n1 4\n3\n1 3 5\n3\n1 5 4", "5\n1 2\n3 2\n2 4\n5 2\n4\n2\n3 1\n3\n3 4 5\n3\n2 3 5\n1\n1"] | PASSED | import sys
from typing import List
input = sys.stdin.readline
class LowestCommonAncestor:
def __init__(self, n, E):
assert n >= 1 and len(E) == n - 1
self.n = n
self.adj = [[] for _ in range(self.n)]
for e in E:
u, v = e
self.adj[u].append(v)
... | 1657463700 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["2\n6 3\n2 4", "3\n9 3\n2 4\n6 8", "0"] | 72d70a1c2e579bf81954ff932a9bc16e | null | Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to an apple store. Jzzhu will pack his apples into groups and then sell them. Each group must contain two apples, and the greatest common divisor of numbers of the apples in each group must be greater t... | The first line must contain a single integer m, representing the maximum number of groups he can get. Each of the next m lines must contain two integers — the numbers of apples in the current group. If there are several optimal answers you can print any of them. | A single integer n (1 ≤ n ≤ 105), the number of the apples. | standard output | standard input | Python 3 | Python | 2,500 | train_061.jsonl | 518b832d348d773e7dad1d2cf87185f5 | 256 megabytes | ["6", "9", "2"] | PASSED | """
Codeforces Round 257 Div 1 Problem C
Author : chaotic_iak
Language: Python 3.3.4
"""
def read(mode=2):
# 0: String
# 1: List of strings
# 2: List of integers
inputs = input().strip()
if mode == 0:
return inputs
if mode == 1:
return inputs.split()
if mode == 2:
... | 1405774800 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
1 second | ["10\n9\n1000\n42000000000000"] | beab56c5f7d2996d447320a62b0963c2 | null | Polycarp wants to cook a soup. To do it, he needs to buy exactly $$$n$$$ liters of water.There are only two types of water bottles in the nearby shop — $$$1$$$-liter bottles and $$$2$$$-liter bottles. There are infinitely many bottles of these two types in the shop.The bottle of the first type costs $$$a$$$ burles and ... | Print $$$q$$$ integers. The $$$i$$$-th integer should be equal to the minimum amount of money (in burles) Polycarp needs to buy exactly $$$n_i$$$ liters of water in the nearby shop if the bottle of the first type costs $$$a_i$$$ burles and the bottle of the second type costs $$$b_i$$$ burles. | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. The next $$$q$$$ lines contain queries. The $$$i$$$-th query is given as three space-separated integers $$$n_i$$$, $$$a_i$$$ and $$$b_i$$$ ($$$1 \le n_i \le 10^{12}, 1 \le a_i, b_i \le 1000$$$) — how many liters Po... | standard output | standard input | Python 3 | Python | 800 | train_002.jsonl | c534a3f7bd14b891392c8d80a7f09d9a | 256 megabytes | ["4\n10 1 3\n7 3 2\n1 1000 1\n1000000000000 42 88"] | PASSED | q=int(input())
for x in range(q):
price=0
arr = [int(xx) for xx in input().split()]
if arr[1]>=arr[2]:
if arr[0]%2==0:
price=(arr[0]/2)*arr[2]
else:
price=((arr[0]-1)/2)*arr[2]+arr[1]
else:
if arr[0]%2==0:
if arr[0]*arr[1]<=(arr[0]/2)*arr[2]:
price=arr[0]*arr[1]
else:
price=(arr[0]/2)*arr[... | 1550586900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["4", "251", "47464146"] | 4ce699a5633d6d3073c2daa7e10060bd | NoteIn the first example, there are $$$4$$$ different mathematical states of this constellation: $$$a_1=1$$$, $$$a_2=1$$$. $$$a_1=1$$$, $$$a_2=2$$$. $$$a_1=2$$$, $$$a_2=1$$$. $$$a_1=3$$$, $$$a_2=1$$$. | Mocha wants to be an astrologer. There are $$$n$$$ stars which can be seen in Zhijiang, and the brightness of the $$$i$$$-th star is $$$a_i$$$. Mocha considers that these $$$n$$$ stars form a constellation, and she uses $$$(a_1,a_2,\ldots,a_n)$$$ to show its state. A state is called mathematical if all of the following... | Print a single integer — the number of different mathematical states of this constellation, modulo $$$998\,244\,353$$$. | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 50$$$, $$$1 \le m \le 10^5$$$) — the number of stars and the upper bound of the sum of the brightness of stars. Each of the next $$$n$$$ lines contains two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le m$$$) — the range of the brightn... | standard output | standard input | PyPy 3-64 | Python | 2,200 | train_095.jsonl | 182067a428f77a6560e6827c21e4ab60 | 256 megabytes | ["2 4\n1 3\n1 2", "5 10\n1 10\n1 10\n1 10\n1 10\n1 10", "5 100\n1 94\n1 96\n1 91\n4 96\n6 97"] | PASSED |
import sys
input=sys.stdin.readline #文字列入力はするな!
mod=998244353
n,m=map(int,input().split())
l=[0]
r=[0]
for i in range(n):
x,y=map(int,input().split())
l.append(x)
r.append(y)
f=[0]*(m+10)
for g in range(m,0,-1):
if m//g<n:continue
dp=[0]*(n+3)*(m//g+2)
def _(i,k):
return k*(n+2)+i
... | 1629038100 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["yes", "no"] | 36fb3a01860ef0cc2a1065d78e4efbd5 | NotePlease note that Dima got a good old kick in the pants for the second sample from the statement. | Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other.Dima and Inna are using a secret code in their text messages. Wh... | In a single line, print "yes" (without the quotes), if Dima decoded the text message correctly, and "no" (without the quotes) otherwise. | The first line contains integer n (1 ≤ n ≤ 105) — the number of words in Dima's message. Next n lines contain non-empty words, one word per line. The words only consist of small English letters. The total length of all words doesn't exceed 105. The last line contains non-empty text message that Inna has got. The numbe... | standard output | standard input | PyPy 2 | Python | 1,500 | train_022.jsonl | 4906ce3358718027adc682dfec9d56de | 256 megabytes | ["3\ni\nlove\nyou\n<3i<3love<23you<3", "7\ni\nam\nnot\nmain\nin\nthe\nfamily\n<3i<>3am<3the<3<main<3in<3the<3><3family<3"] | PASSED | s=list('<3'+'<3'.join(raw_input() for _ in range(input()))+'<3')
t=list(raw_input())
while s and t:
if s[-1]==t[-1]:s.pop()
t.pop()
print 'no' if s else 'yes' | 1382715000 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
3 seconds | ["acb", "baa"] | adbfdb0d2fd9e4eb48a27d43f401f0e0 | NoteLet's consider the first sample. Initially we have name "bacbac"; the first operation transforms it into "bacbc", the second one — to "acbc", and finally, the third one transforms it into "acb". | One popular website developed an unusual username editing procedure. One can change the username only by deleting some characters from it: to change the current name s, a user can pick number p and character c and delete the p-th occurrence of character c from the name. After the user changed his name, he can't undo th... | Print a single string — the user's final name after all changes are applied to it. | The first line contains an integer k (1 ≤ k ≤ 2000). The second line contains a non-empty string s, consisting of lowercase Latin letters, at most 100 characters long. The third line contains an integer n (0 ≤ n ≤ 20000) — the number of username changes. Each of the next n lines contains the actual changes, one per lin... | standard output | standard input | Python 3 | Python | 1,400 | train_029.jsonl | 5e465d8da04331defe9de9ddb148f8ef | 256 megabytes | ["2\nbac\n3\n2 a\n1 b\n2 c", "1\nabacaba\n4\n1 a\n1 a\n1 c\n2 b"] | PASSED | #copied... idea
def main():
mode="filee"
if mode=="file":f=open("test.txt","r")
get = lambda :[int(x) for x in (f.readline() if mode=="file" else input()).split()]
gets = lambda :[str(x) for x in (f.readline() if mode=="file" else input()).split()]
[k]=get()
[g]=gets()
h = g*k
h = list(... | 1331280000 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["66.666666666667", "37.500000000000"] | 580596d05a2eaa36d630d71ef1055c43 | NoteNote to the first sample: let's assume that Vasya takes x milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal milliliters. The total cocktail's volume equals 3·x milliliters, so the volume fraction of the juice in the cocktail equals , that is, 66.(6) percent. | Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are n drinks in his fridge, the volume fraction of orange juice in the i-th drink equals pi percent.One day Vasya decided to make himself an orange cocktail. He took equal proportions of each... | Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10 - 4. | The first input line contains a single integer n (1 ≤ n ≤ 100) — the number of orange-containing drinks in Vasya's fridge. The second line contains n integers pi (0 ≤ pi ≤ 100) — the volume fraction of orange juice in the i-th drink, in percent. The numbers are separated by a space. | standard output | standard input | Python 3 | Python | 800 | train_004.jsonl | 8d0eb9e97df415d54e47a1030a6fefbe | 256 megabytes | ["3\n50 50 100", "4\n0 25 50 75"] | PASSED | n=int(input())
l=map(int,input().split())
k=sum(l)/n
print('%.12f'%k) | 1340551800 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["9 12\n7 10\n3 11\n1 5\n2 4\n6 8", "1 2"] | 739e60a2fa71aff9a5c7e781db861d1e | null | We had a really tough time generating tests for problem D. In order to prepare strong tests, we had to solve the following problem.Given an undirected labeled tree consisting of $$$n$$$ vertices, find a set of segments such that: both endpoints of each segment are integers from $$$1$$$ to $$$2n$$$, and each integer fr... | Print $$$n$$$ pairs of integers, the $$$i$$$-th pair should contain two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i < r_i \le 2n$$$) — the endpoints of the $$$i$$$-th segment. All $$$2n$$$ integers you print should be unique. It is guaranteed that the answer always exists. | The first line contains one integer $$$n$$$ ($$$1 \le n \le 5 \cdot 10^5$$$) — the number of vertices in the tree. Then $$$n - 1$$$ lines follow, each containing two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i, y_i \le n$$$, $$$x_i \ne y_i$$$) denoting the endpoints of the $$$i$$$-th edge. It is guaranteed that the ... | standard output | standard input | PyPy 2 | Python | 2,200 | train_000.jsonl | 479155577366530719b3898b47485a1a | 256 megabytes | ["6\n1 2\n1 3\n3 4\n3 5\n2 6", "1"] | PASSED | import sys
import os
range = xrange
input = raw_input
S = sys.stdin.read()
n = len(S)
A = []
i = 0
while i < n:
c = 0
while ord(S[i]) >= 48:
c = 10 * c + ord(S[i]) - 48
i += 1
A.append(c)
i += 1 + (S[i] == '\r')
inp = A; ii = 0
n = inp[ii]; ii += 1
coupl = [[] for _ in range(n)]
for _... | 1576766100 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["Yes\nNo\nNo\nYes\nYes\nYes"] | 7224ffd4776af4129739e1b28f696050 | NoteIn the first test case, one valid exercising walk is $$$$$$(0,0)\rightarrow (-1,0) \rightarrow (-2,0)\rightarrow (-2,1) \rightarrow (-2,2)\rightarrow (-1,2)\rightarrow(0,2)\rightarrow (0,1)\rightarrow (0,0) \rightarrow (-1,0)$$$$$$ | Alice has a cute cat. To keep her cat fit, Alice wants to design an exercising walk for her cat! Initially, Alice's cat is located in a cell $$$(x,y)$$$ of an infinite grid. According to Alice's theory, cat needs to move: exactly $$$a$$$ steps left: from $$$(u,v)$$$ to $$$(u-1,v)$$$; exactly $$$b$$$ steps right: fro... | For each test case, output "YES" in a separate line, if there exists a walk satisfying her wishes. Otherwise, output "NO" in a separate line. You can print each letter in any case (upper or lower). | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of testcases. The first line of each test case contains four integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ ($$$0 \le a,b,c,d \le 10^8$$$, $$$a+b+c+d \ge 1$$$). The second line of the test case contains six integers $$$x$$$, $$$y$$$, $... | standard output | standard input | Python 3 | Python | 1,100 | train_004.jsonl | 7f5cd367e8cf07513163d9a19ff084f7 | 512 megabytes | ["6\n3 2 2 2\n0 0 -2 -2 2 2\n3 1 4 1\n0 0 -1 -1 1 1\n1 1 1 1\n1 1 1 1 1 1\n0 0 0 1\n0 0 0 0 0 1\n5 1 1 1\n0 0 -100 -100 0 100\n1 1 5 1\n0 0 -100 -100 100 0"] | PASSED | for _ in " "*int(input()):
left,right,down,up=map(int,input().split())
x,y,x1,y1,x2,y2=map(int,input().split())
if (x1==x2 and left+right>0) or (y1==y2 and up+down>0):
print("NO")
elif x1<=x+(right-left)<=x2 and y1<=y+(up-down)<=y2:
print("YES")
else:
print("NO") | 1585661700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["0", "3", "2"] | 80fdb95372c1e8d558b8c8f31c9d0479 | null | After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third ro... | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin le... | standard output | standard input | Python 2 | Python | 1,100 | train_013.jsonl | 3a30455087b879302a052fd22b2a65bf | 256 megabytes | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | PASSED | from collections import defaultdict
n = input()
s = raw_input()
d = defaultdict(int)
c = 0
for i in range(1,2*n-2+1):
if i%2:
d[s[i-1]] += 1
elif i%2 == 0 and d[s[i-1].lower()] == 0:
c += 1
elif i%2 ==0 and d[s[i-1].lower()] != 0:
d[s[i-1].lower()] -= 1
print c
| 1427387400 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["BOB\nBOB"] | 42b425305ccc28b0d081b4c417fe77a1 | NoteIn the first test case of the example, in the $$$1$$$-st move Alice has to perform the $$$1$$$-st operation, since the string is currently a palindrome. in the $$$2$$$-nd move Bob reverses the string. in the $$$3$$$-rd move Alice again has to perform the $$$1$$$-st operation. All characters of the string are '1... | The only difference between the easy and hard versions is that the given string $$$s$$$ in the easy version is initially a palindrome, this condition is not always true for the hard version.A palindrome is a string that reads the same left to right and right to left. For example, "101101" is a palindrome, while "0101" ... | For each test case print a single word in a new line: "ALICE", if Alice will win the game, "BOB", if Bob will win the game, "DRAW", if the game ends in a draw. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^3$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^3$$$). The second line of each test case contains the string $$$s$$$ of length $$$n$$$, consisting of the characters '0' and '1... | standard output | standard input | Python 3 | Python | 1,200 | train_085.jsonl | 37ee0dff6babbdad80d093f740ebc7e7 | 256 megabytes | ["2\n4\n1001\n1\n0"] | PASSED | t = int(input())
while t:
int(input())
s = input().count('0')
if s%2 == 1 and s > 1: print('ALICE')
else: print('BOB')
t-=1 | 1621521300 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["1 2 3", "2 1 3", "4 1 2"] | 3cdd85f86c77afd1d3b0d1e951a83635 | NoteIn first sample test vertices of regular triangle can create only angle of 60 degrees, that's why every possible angle is correct.Vertices of square can create 45 or 90 degrees angles only. That's why in second sample test the angle of 45 degrees was chosen, since |45 - 67| < |90 - 67|. Other correct answers are... | On one quiet day all of sudden Mister B decided to draw angle a on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex n-gon (regular convex polygon with n sides).That's why Mister B decided to use this polygon. Now Mister B must find th... | Print three space-separated integers: the vertices v1, v2, v3, which form . If there are multiple optimal solutions, print any of them. The vertices are numbered from 1 to n in clockwise order. | First and only line contains two space-separated integers n and a (3 ≤ n ≤ 105, 1 ≤ a ≤ 180) — the number of vertices in the polygon and the needed angle, in degrees. | standard output | standard input | PyPy 3 | Python | 1,300 | train_034.jsonl | b187677178f990618f073a8662744b74 | 256 megabytes | ["3 15", "4 67", "4 68"] | PASSED | from sys import stdin, stdout
n, a = map(int, stdin.readline().split())
ans = 180 * (n - 2) / n
f, s, t = 1, 2, 3
dif = 180 / n
cnt = dif
for i in range(n - 2):
if abs(a - ans) > abs(a - cnt):
ans = cnt
f, s, t = 2, 1, 3 + i
cnt += dif
stdout.write(str(f) + ' ' + str(s) + ' ' + str(t)) | 1498574100 | [
"geometry",
"math"
] | [
0,
1,
0,
1,
0,
0,
0,
0
] | |
1 second | ["YES\nNO"] | 6b37fc623110e49a5e311a2d186aae46 | Note The first test case of the example It can be shown that the answer for the second test case of the example is "NO". | You are given two integers $$$n$$$ and $$$m$$$ ($$$m < n$$$). Consider a convex regular polygon of $$$n$$$ vertices. Recall that a regular polygon is a polygon that is equiangular (all angles are equal in measure) and equilateral (all sides have the same length). Examples of convex regular polygons Your task is to ... | For each test case, print the answer — "YES" (without quotes), if it is possible to build another convex regular polygon with $$$m$$$ vertices such that its center coincides with the center of the initial polygon and each of its vertices is some vertex of the initial polygon and "NO" otherwise. | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. Each test case is given as two space-separated integers $$$n$$$ and $$$m$$$ ($$$3 \le m < n \le 100$$$) — the number of vertices in the initial polygon and the num... | standard output | standard input | Python 2 | Python | 800 | train_009.jsonl | 4926b486b614502b3a59856d9bd3cbb4 | 256 megabytes | ["2\n6 3\n7 3"] | PASSED | '''
'''
from sys import stdin, stdout
def main():
n = int(stdin.readline())
for x in range(n):
n, m = [int(x) for x in stdin.readline().split()]
if n / float(m) == n / m:
stdout.write('YES\n')
else:
stdout.write('NO\n')
if __name__ == "__main__":
main() | 1583764500 | [
"number theory",
"geometry",
"math"
] | [
0,
1,
0,
1,
1,
0,
0,
0
] | |
1 second | ["2\n1\n1\n4\n72"] | a58ad54eaf4912f530a7d25a503640d3 | NoteFor the first test case, the only permutations similar to $$$a=[4,0,3,2,1]$$$ are $$$[4,0,3,2,1]$$$ and $$$[4,0,2,3,1]$$$.For the second and third test cases, the given permutations are only similar to themselves.For the fourth test case, there are $$$4$$$ permutations similar to $$$a=[1,2,4,0,5,3]$$$: $$$[1,2,4,... | You are given a permutation $$$a_1,a_2,\ldots,a_n$$$ of integers from $$$0$$$ to $$$n - 1$$$. Your task is to find how many permutations $$$b_1,b_2,\ldots,b_n$$$ are similar to permutation $$$a$$$. Two permutations $$$a$$$ and $$$b$$$ of size $$$n$$$ are considered similar if for all intervals $$$[l,r]$$$ ($$$1 \le l \... | For each test case, print a single integer, the number of permutations similar to permutation $$$a$$$, taken modulo $$$10^9+7$$$. | Each test contains multiple test cases. The first line of input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following lines contain the descriptions of the test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the size of perm... | standard output | standard input | PyPy 3-64 | Python | 1,700 | train_088.jsonl | 678772c2986c01d36f6cca116ead1758 | 256 megabytes | ["5\n\n5\n\n4 0 3 2 1\n\n1\n\n0\n\n4\n\n0 1 2 3\n\n6\n\n1 2 4 0 5 3\n\n8\n\n1 3 7 2 5 0 6 4"] | PASSED | import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split(' ')))
mod = 10 ** 9 + 7
if n <= 3:
print(1)
continue
indices = [0] * n
for i in range(n):
indices[a[i]] = i
res, l, r = 1, min(indi... | 1656945300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["2\n1 2 5\n1 3 5", "1\n2 3 5", "2\n1 2 12\n3 4 8", "1\n2 3 15"] | 6f7bee466780e6e65b2841bfccad28b0 | NoteIn the first example the optimal sequence of operations can be the following: Perform an operation of the first type with $$$a = 1$$$, $$$b = 2$$$, $$$c = 2$$$, $$$d = 3$$$ and $$$z = 5$$$. The resulting debts are: $$$d(1, 2) = 5$$$, $$$d(2, 2) = 5$$$, $$$d(1, 3) = 5$$$, all other debts are $$$0$$$; Perform an op... | There are $$$n$$$ people in this world, conveniently numbered $$$1$$$ through $$$n$$$. They are using burles to buy goods and services. Occasionally, a person might not have enough currency to buy what he wants or needs, so he borrows money from someone else, with the idea that he will repay the loan later with interes... | On the first line print an integer $$$m'$$$ ($$$0 \leq m' \leq 3\cdot 10^5$$$), representing the number of debts after the consolidation. It can be shown that an answer always exists with this additional constraint. After that print $$$m'$$$ lines, $$$i$$$-th of which contains three space separated integers $$$u_i, v_i... | The first line contains two space separated integers $$$n$$$ ($$$1 \leq n \leq 10^5$$$) and $$$m$$$ ($$$0 \leq m \leq 3\cdot 10^5$$$), representing the number of people and the number of debts, respectively. $$$m$$$ lines follow, each of which contains three space separated integers $$$u_i$$$, $$$v_i$$$ ($$$1 \leq u_i,... | standard output | standard input | PyPy 3 | Python | 2,000 | train_050.jsonl | aa6337013b9b73f3540702e457a1f00c | 256 megabytes | ["3 2\n1 2 10\n2 3 5", "3 3\n1 2 10\n2 3 15\n3 1 10", "4 2\n1 2 12\n3 4 8", "3 4\n2 3 1\n2 3 2\n2 3 4\n2 3 8"] | PASSED | import io,os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from collections import defaultdict as dd
I = lambda : list(map(int,input().split()))
n,m=I()
fi=[0]*(n+1)
for i in range(m):
u,v,w=I()
fi[u]-=w
fi[v]+=w
p=[];m=[]
for i in range(1,n+1):
if fi[i]<0:
m.append([-fi[i],i])
elif fi[i]>0:
p.a... | 1576595100 | [
"math",
"graphs"
] | [
0,
0,
1,
1,
0,
0,
0,
0
] | |
2 seconds | ["4"] | 22319b83f5874287e3aeaa6dd339e7cb | null | The pandemic is upon us, and the world is in shortage of the most important resource: toilet paper. As one of the best prepared nations for this crisis, BubbleLand promised to help all other world nations with this valuable resource. To do that, the country will send airplanes to other countries carrying toilet paper.I... | If there are no solutions, output -1. If there exists a solution, output the minimal number of days to complete all roads, equal to maximal $$$d$$$ among all chosen roads. | The first line contains two integers $$$N$$$ $$$(1 \leq N \leq 10^4)$$$ - number of airports/factories, and $$$M$$$ $$$(1 \leq M \leq 10^5)$$$ - number of available pairs to build a road between. On next $$$M$$$ lines, there are three integers $$$u$$$, $$$v$$$ $$$(1 \leq u,v \leq N)$$$, $$$d$$$ $$$(1 \leq d \leq 10^9)$... | standard output | standard input | PyPy 3 | Python | 1,900 | train_002.jsonl | e5788a6c4f240a69a3df5835ece2cbf9 | 256 megabytes | ["3 5\n1 2 1\n2 3 2\n3 3 3\n2 1 4\n2 2 5"] | PASSED | import os
import sys
from io import BytesIO, IOBase
# region fastio
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.wri... | 1601903100 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["210", "30"] | 816a82bee65cf79ba8e4d61babcd0301 | NoteIn the first example we can choose next parameters: $$$a = [1, 1, 1, 1]$$$, $$$b = [1, 1, 1, 1]$$$, $$$x = [0, 0, 0, 0]$$$, then $$$f_i^{(k)} = k \bmod p_i$$$.In the second example we can choose next parameters: $$$a = [1, 1, 2]$$$, $$$b = [1, 1, 0]$$$, $$$x = [0, 0, 1]$$$. | You are given a tuple generator $$$f^{(k)} = (f_1^{(k)}, f_2^{(k)}, \dots, f_n^{(k)})$$$, where $$$f_i^{(k)} = (a_i \cdot f_i^{(k - 1)} + b_i) \bmod p_i$$$ and $$$f^{(0)} = (x_1, x_2, \dots, x_n)$$$. Here $$$x \bmod y$$$ denotes the remainder of $$$x$$$ when divided by $$$y$$$. All $$$p_i$$$ are primes.One can see that... | Print one integer — the maximum number of different tuples modulo $$$10^9 + 7$$$. | The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of elements in the tuple. The second line contains $$$n$$$ space separated prime numbers — the modules $$$p_1, p_2, \ldots, p_n$$$ ($$$2 \le p_i \le 2 \cdot 10^6$$$). | standard output | standard input | Python 2 | Python | 2,900 | train_000.jsonl | a6c9d900ce4a35b98ae2dd0c1b114598 | 512 megabytes | ["4\n2 3 5 7", "3\n5 3 3"] | PASSED | import sys
import time
mod=1000000007
def sieve(s):
is_not_prime=[False]*(s+1)
prime=[]
small=[0]*(s+1)
cnt=[0]*(s+1)
other=[0]*(s+1)
for i in xrange(2, s+1):
if not is_not_prime[i]:
prime.append(i)
small[i]=i
cnt[i]=1
other[i]=1
for p in prime:
next=p*i
if next>s:
break
is_not_prime[... | 1537707900 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
1 second | ["No\nYes\nYes\nYes"] | 749a106d462555543c91753f00a5a479 | NoteIn the first test case, you're not able to do any operation and you can never arrange three balls of distinct colors into a palindrome.In the second test case, after doing one operation, changing $$$(8,1,9,3)$$$ to $$$(7,0,8,6)$$$, one of those possible palindromes may be "rrrwwwbbbbrbbbbwwwrrr".A palindrome is a w... | Boboniu gives you $$$r$$$ red balls, $$$g$$$ green balls, $$$b$$$ blue balls, $$$w$$$ white balls. He allows you to do the following operation as many times as you want: Pick a red ball, a green ball, and a blue ball and then change their color to white. You should answer if it's possible to arrange all the balls... | For each test case, print "Yes" if it's possible to arrange all the balls into a palindrome after doing several (possibly zero) number of described operations. Otherwise, print "No". | The first line contains one integer $$$T$$$ ($$$1\le T\le 100$$$) denoting the number of test cases. For each of the next $$$T$$$ cases, the first line contains four integers $$$r$$$, $$$g$$$, $$$b$$$ and $$$w$$$ ($$$0\le r,g,b,w\le 10^9$$$). | standard output | standard input | Python 3 | Python | 1,000 | train_002.jsonl | e8d52f18fd3b1fbaa6d7079300714eda | 256 megabytes | ["4\n0 1 1 1\n8 1 9 3\n0 0 0 0\n1000000000 1000000000 1000000000 1000000000"] | PASSED | Nombre = int(input()) ;
for m in range(Nombre) :
Tab = list(map(int,input().split())) ;
odd = 0 ;
null = 0 ;
for n in Tab :
if (n % 2) == 1 :
odd += 1 ;
if (odd ==1) or (odd== 4) or (odd ==0) :
print("Yes") ;
elif (odd == 3) :
for n in range(3) :
... | 1597242900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1\n0\n2\n0\n1\n1\n1\n1"] | c2a506d58a80a0fb6a16785605b075ca | NoteIn the first case, Burenka can multiply $$$c$$$ by $$$2$$$, then the fractions will be equal.In the second case, fractions are already equal.In the third case, Burenka can multiply $$$a$$$ by $$$4$$$, then $$$b$$$ by $$$3$$$. Then the fractions will be equal ($$$\frac{1 \cdot 4}{2 \cdot 3} = \frac{2}{3}$$$). | Burenka came to kindergarden. This kindergarten is quite strange, so each kid there receives two fractions ($$$\frac{a}{b}$$$ and $$$\frac{c}{d}$$$) with integer numerators and denominators. Then children are commanded to play with their fractions.Burenka is a clever kid, so she noticed that when she claps once, she ca... | For each test case print a single integer — the minimal number of claps Burenka needs to make her fractions equal. | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then follow the descriptions of each test case. The only line of each test case contains four integers $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$ ($$$0 \leq a, c \leq 10^9$$$, $$$1 \leq b, d \leq 10^9$$$) — numerators and deno... | standard output | standard input | Python 3 | Python | 900 | train_098.jsonl | c3ad00a9e17baa2d010651904032176c | 256 megabytes | ["8\n\n2 1 1 1\n\n6 3 2 1\n\n1 2 2 3\n\n0 1 0 100\n\n0 1 228 179\n\n100 3 25 6\n\n999999999 300000000 666666666 100000000\n\n33 15 0 84"] | PASSED | #comment
n = int(input())
def do(a, b, c, d):
if a==0 and c!=0:
return 1
if c==0 and a!=0:
return 1
fst, snd = a * d, b * c
if fst == snd:
return 0
if fst % snd == 0 or snd % fst == 0:
return 1
else:
return 2
for i in range(n):
... | 1660829700 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["1.000000000000000", "0.333333333333333", "0.100000000000000"] | 4c92218ccbab7d142c2cbb6dd54c510a | NoteIn the first example Vasya can always open the second letter after opening the first letter, and the cyclic shift is always determined uniquely.In the second example if the first opened letter of t is "t" or "c", then Vasya can't guess the shift by opening only one other letter. On the other hand, if the first lett... | Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this string s, and then shifts it k letters to the left, i. e. creates a new string ... | Print the only number — the answer for the problem. You answer is considered correct, if its absolute or relative error does not exceed 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if | The only string contains the string s of length l (3 ≤ l ≤ 5000), consisting of small English letters only. | standard output | standard input | PyPy 2 | Python | 1,600 | train_000.jsonl | e1a75b52a4e1b51adf1d97dd49b4f9a3 | 256 megabytes | ["technocup", "tictictactac", "bbaabaabbb"] | PASSED | from __future__ import print_function, division
from sys import stdin, stdout
from collections import *
chrs = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:;?!"#&\'()*+,-./ '
rstr = lambda: stdin.readline().strip()
s, ans = rstr(), 0
le = len(s)
mem = [[[0 for _ in range(le)] for _ in range(26)] for... | 1520177700 | [
"probabilities",
"math"
] | [
0,
0,
0,
1,
0,
1,
0,
0
] | |
2.5 seconds | ["odfrces\nezakmi\ncba\nconvexhul\nwfldjgpaxs\nmyneocktxqjpz"] | a30f6f5273fc6c02ac1f2bc2b0ee893e | null | You are given a string $$$s$$$, consisting of lowercase Latin letters. While there is at least one character in the string $$$s$$$ that is repeated at least twice, you perform the following operation: you choose the index $$$i$$$ ($$$1 \le i \le |s|$$$) such that the character at position $$$i$$$ occurs at least two ... | For each test case, output the lexicographically maximum string that can be obtained after applying a certain sequence of operations after which all characters in the string become unique. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. Each test case is characterized by a string $$$s$$$, consisting of lowercase Latin letters ($$$1 \le |s| \le 2 \cdot 10^5$$$). It is guaranteed that the sum of the lengths of the strings in all test cases does not exce... | standard output | standard input | PyPy 3-64 | Python | 2,000 | train_101.jsonl | fbc7c54ee1d523b84717d0fce5281904 | 256 megabytes | ["6\ncodeforces\naezakmi\nabacaba\nconvexhull\nswflldjgpaxs\nmyneeocktxpqjpz"] | PASSED | in1 = lambda : int(input())
in2 = lambda : list(map(int, input().split()))
#Solve
import math
def solve():
s = input()
#print("RES: ", end='')
n = len(s)
stack = []
seen = set()
d = {c : idx for idx, c in enumerate(s)}
for i in range(n):
if s[i] not in seen:
... | 1616682900 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["14\n45\n163\n123"] | 1ff25abd9d49de5e5ce3f7338ddef18c | NoteIn the first test case, an optimal solution is to: move $$$1$$$: $$$r = 4$$$, $$$b = 2$$$; no swap; move $$$2$$$: $$$r = 7$$$, $$$b = 6$$$; swap (after it $$$r = 6$$$, $$$b = 7$$$); move $$$3$$$: $$$r = 11$$$, $$$b = 9$$$; no swap. The total number of points is $$$|7 - 2| + |6 - 9| + |3 - 9| = 14$$$. In the se... | You are given $$$n - 1$$$ integers $$$a_2, \dots, a_n$$$ and a tree with $$$n$$$ vertices rooted at vertex $$$1$$$. The leaves are all at the same distance $$$d$$$ from the root. Recall that a tree is a connected undirected graph without cycles. The distance between two vertices is the number of edges on the simple pat... | For each test case, print a single integer: the maximum number of points you can gain after $$$d$$$ moves. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$2 \leq n \leq 2 \cdot 10^5$$$) — the number of vertices in the tree. The second line of each test case contains $$$n-1$$$ integers $$$v_2, v_3, \do... | standard output | standard input | PyPy 3 | Python | 2,500 | train_092.jsonl | b97b6491b5a52140c6088795f877f62c | 256 megabytes | ["4\n14\n1 1 1 2 3 4 4 5 5 6 7 8 8\n2 3 7 7 6 9 5 9 7 3 6 6 5\n6\n1 2 2 3 4\n32 78 69 5 41\n15\n1 15 1 10 4 9 11 2 4 1 8 6 10 11\n62 13 12 43 39 65 42 86 25 38 19 19 43 62\n15\n11 2 7 6 9 8 10 1 1 1 5 3 15 2\n50 19 30 35 9 45 13 24 8 44 16 26 10 40"] | PASSED | import sys
I=lambda:[*map(int,sys.stdin.readline().split())]
t, = I()
for _ in range(t):
n, = I()
par = [0,0]+I()
a = [0,0]+I()
children = [[] for _ in range(n+1)]
for i in range(2, n+1):
children[par[i]].append(i)
layers = [[1]]
while 1:
nextlayer = []
for v in layers[-1]:
for u in children[v]:
ne... | 1613141400 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
4 seconds | ["14", "131"] | db8855495d22c26296351fe310281df2 | NoteIn the first example, it's optimal to rearrange the elements of the given array in the following order: $$$[6, \, 2, \, 2, \, 2, \, 3, \, 1]$$$:$$$$$$\operatorname{gcd}(a_1) + \operatorname{gcd}(a_1, \, a_2) + \operatorname{gcd}(a_1, \, a_2, \, a_3) + \operatorname{gcd}(a_1, \, a_2, \, a_3, \, a_4) + \operatorname{... | This is the hard version of the problem. The only difference is maximum value of $$$a_i$$$.Once in Kostomuksha Divan found an array $$$a$$$ consisting of positive integers. Now he wants to reorder the elements of $$$a$$$ to maximize the value of the following function: $$$$$$\sum_{i=1}^n \operatorname{gcd}(a_1, \, a_2,... | Output the maximum value of the function that you can get by reordering elements of the array $$$a$$$. | The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the size of the array $$$a$$$. The second line contains $$$n$$$ integers $$$a_{1}, \, a_{2}, \, \dots, \, a_{n}$$$ ($$$1 \le a_{i} \le 2 \cdot 10^7$$$) — the array $$$a$$$. | standard output | standard input | PyPy 3-64 | Python | 2,300 | train_098.jsonl | 7736a2859ec0cf55791414e12971808e | 1024 megabytes | ["6\n2 3 1 2 6 2", "10\n5 7 10 3 1 10 100 3 42 54"] | PASSED | ''' D2. Divan and Kostomuksha (hard version)
https://codeforces.com/contest/1614/problem/D2
'''
import io, os, sys
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline # decode().strip() if str
output = sys.stdout.write
INF = float('inf')
def sieve(N):
'''return all primes in [2..N] in O(N)'''
pri... | 1637925300 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
2 seconds | ["3", "-1"] | c5592080d0f98bf8d88feb4d98762311 | NoteIn the first sample case, a path of three edges is obtained after merging paths 2 - 1 - 6 and 2 - 4 - 5.It is impossible to perform any operation in the second sample case. For example, it is impossible to merge paths 1 - 3 - 4 and 1 - 5 - 6, since vertex 6 additionally has a neighbour 7 that is not present in the ... | Vanya wants to minimize a tree. He can perform the following operation multiple times: choose a vertex v, and two disjoint (except for v) paths of equal length a0 = v, a1, ..., ak, and b0 = v, b1, ..., bk. Additionally, vertices a1, ..., ak, b1, ..., bk must not have any neighbours in the tree other than adjacent verti... | If it is impossible to obtain a path, print -1. Otherwise, print the minimum number of edges in a possible path. | The first line of input contains the number of vertices n (2 ≤ n ≤ 2·105). Next n - 1 lines describe edges of the tree. Each of these lines contains two space-separated integers u and v (1 ≤ u, v ≤ n, u ≠ v) — indices of endpoints of the corresponding edge. It is guaranteed that the given graph is a tree. | standard output | standard input | Python 3 | Python | 2,200 | train_033.jsonl | bd904a83bac9b163c1f12fe51045a011 | 512 megabytes | ["6\n1 2\n2 3\n2 4\n4 5\n1 6", "7\n1 2\n1 3\n3 4\n1 5\n5 6\n6 7"] | PASSED | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def main():
n = II()
d = ... | 1487059500 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["1", "2"] | a0a6cdda2ce201767bf5418f445a44eb | NoteIn the first example you need to move the first chip by $$$2$$$ to the right and the second chip by $$$1$$$ to the right or move the third chip by $$$2$$$ to the left and the second chip by $$$1$$$ to the left so the answer is $$$1$$$.In the second example you need to move two chips with coordinate $$$3$$$ by $$$1$... | You are given $$$n$$$ chips on a number line. The $$$i$$$-th chip is placed at the integer coordinate $$$x_i$$$. Some chips can have equal coordinates.You can perform each of the two following types of moves any (possibly, zero) number of times on any chip: Move the chip $$$i$$$ by $$$2$$$ to the left or $$$2$$$ to th... | Print one integer — the minimum total number of coins required to move all $$$n$$$ chips to the same coordinate. | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of chips. The second line of the input contains $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$), where $$$x_i$$$ is the coordinate of the $$$i$$$-th chip. | standard output | standard input | Python 3 | Python | 900 | train_004.jsonl | 467c1f4c308fff6b7594758f24d6b94a | 256 megabytes | ["3\n1 2 3", "5\n2 2 2 3 3"] | PASSED | m=input()
n=input()
c1=0
c2=0
k=n.split(" ")
for mm in k:
if(int(mm)%2==0):
c1+=1
else:
c2+=1
if(c1>c2):
print(c2)
else:
print(c1) | 1567175700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["4", "-1"] | 6126d9533abd466545d8153233b14192 | NoteIn the second sample test one of the progressions contains only powers of two, the other one contains only powers of three. | Geometric progression with the first element a and common ratio b is a sequence of numbers a, ab, ab2, ab3, ....You are given n integer geometric progressions. Your task is to find the smallest integer x, that is the element of all the given progressions, or else state that such integer does not exist. | If the intersection of all progressions is empty, then print - 1, otherwise print the remainder of the minimal positive integer number belonging to all progressions modulo 1000000007 (109 + 7). | The first line contains integer (1 ≤ n ≤ 100) — the number of geometric progressions. Next n lines contain pairs of integers a, b (1 ≤ a, b ≤ 109), that are the first element and the common ratio of the corresponding geometric progression. | standard output | standard input | Python 2 | Python | 3,200 | train_034.jsonl | 06762491a581df862d3167c84537c143 | 256 megabytes | ["2\n2 2\n4 1", "2\n2 2\n3 3"] | PASSED |
def primes(n):
size = n/3 + (n%6==2)
plist = size * [True]
plist[0] = False
for i in xrange(int(n**0.5)/3+1):
if plist[i]:
k=3*i+1|1
for j in xrange((k*k)/3,size,2*k):
plist[j] = False
for j in xrange((k*k+4*k-2*k*(i&1))/3,size,2*k):
plist[j] = False
ans = [2,3]
for i in xrange(size):
if pli... | 1440261000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["00\n01\n11111\n1010"] | 679a1e455073d3ea3856aa16516ba8ba | NoteIn the first and second test cases, $$$s = t$$$ since it's already one of the optimal solutions. Answers have periods equal to $$$1$$$ and $$$2$$$, respectively.In the third test case, there are shorter optimal solutions, but it's okay since we don't need to minimize the string $$$s$$$. String $$$s$$$ has period eq... | Let's say string $$$s$$$ has period $$$k$$$ if $$$s_i = s_{i + k}$$$ for all $$$i$$$ from $$$1$$$ to $$$|s| - k$$$ ($$$|s|$$$ means length of string $$$s$$$) and $$$k$$$ is the minimum positive integer with this property.Some examples of a period: for $$$s$$$="0101" the period is $$$k=2$$$, for $$$s$$$="0000" the perio... | Print one string for each test case — string $$$s$$$ you needed to find. If there are multiple solutions print any one of them. | The first line contains single integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of test cases. Next $$$T$$$ lines contain test cases — one per line. Each line contains string $$$t$$$ ($$$1 \le |t| \le 100$$$) consisting only of 0's and 1's. | standard output | standard input | Python 3 | Python | 1,100 | train_000.jsonl | c21eb008ed077af0fd3539cb1cb2dacb | 256 megabytes | ["4\n00\n01\n111\n110"] | PASSED | t=int(input())
for i in range(t):
t=input()
one=t.count('1')
zero=t.count('0')
if(zero>0 and one>0):
if(zero>=one):
print('01'*len(t))
else:
print('10'*len(t))
else:
print(t)
| 1587911700 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
4 seconds | ["1 2 3 3 3 4 4 4 4 4", "2 2 2 1 1"] | 5c17e01d02df26148e87dcba60ddf499 | NoteFor the first test, the optimal answer is $$$f=-269$$$. Note that a larger $$$f$$$ value is possible if we ignored the constraint $$$\sum\limits_{i=1}^n b_i=k$$$.For the second test, the optimal answer is $$$f=9$$$. | Uh oh! Applications to tech companies are due soon, and you've been procrastinating by doing contests instead! (Let's pretend for now that it is actually possible to get a job in these uncertain times.)You have completed many programming projects. In fact, there are exactly $$$n$$$ types of programming projects, and yo... | In a single line, output $$$n$$$ integers $$$b_1,\ldots, b_n$$$ that achieve the maximum value of $$$f(b_1,\ldots,b_n)$$$, while satisfying the requirements $$$0\le b_i\le a_i$$$ and $$$\sum\limits_{i=1}^n b_i=k$$$. If there are multiple solutions, output any. Note that you do not have to output the value $$$f(b_1,\ldo... | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1\le n\le 10^5$$$, $$$1\le k\le \sum\limits_{i=1}^n a_i$$$) — the number of types of programming projects and the résumé size, respectively. The next line contains $$$n$$$ integers $$$a_1,\ldots,a_n$$$ ($$$1\le a_i\le 10^9$$$) — $$$a_i$$$ is equal to the numb... | standard output | standard input | PyPy 2 | Python | 2,700 | train_013.jsonl | 2c147c018b86f7ed4b89af37783e5ff1 | 256 megabytes | ["10 32\n1 2 3 4 5 5 5 5 5 5", "5 8\n4 4 8 2 1"] | PASSED | import sys,math
range = xrange
input = raw_input
n, k = [int(x) for x in input().split()]
A = [int(x) for x in sys.stdin.read().split()]
# pick as few as possible
def f1(lam):
s = 0
for a in A:
# (b + 1) * (a + lam - (b + 1) ^ 2) - b * (a + lam - b ^ 2)
def g(b):
return a + lam - 3... | 1588775700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["3\n1 3\n3 5\n5 4\n3 2\n2 1\n3\n2 4\n3 7"] | 4f2c2d67c1a84bf449959b06789bb3a7 | null | There are n cities and m two-way roads in Berland, each road connects two cities. It is known that there is no more than one road connecting each pair of cities, and there is no road which connects the city with itself. It is possible that there is no way to get from one city to some other city using only these roads.T... | For each testset print the maximum number of such cities that the number of roads that begins in the city, is equal to the number of roads that ends in it. In the next m lines print oriented roads. First print the number of the city where the road begins and then the number of the city where the road ends. If there are... | The first line contains a positive integer t (1 ≤ t ≤ 200) — the number of testsets in the input. Each of the testsets is given in the following way. The first line contains two integers n and m (1 ≤ n ≤ 200, 0 ≤ m ≤ n·(n - 1) / 2) — the number of cities and the number of roads in Berland. The next m lines contain the... | standard output | standard input | Python 3 | Python | 2,200 | train_022.jsonl | c0b82ff3423cffa685c7741e1c184ca4 | 256 megabytes | ["2\n5 5\n2 1\n4 5\n2 3\n1 3\n3 5\n7 2\n3 7\n4 2"] | PASSED | from collections import defaultdict, Counter
T = int(input())
for _ in range(T):
global lst
N, M = map(int, input().split())
visit = set()
oddNodes = []
directed = []
G = defaultdict(list)
oriG = defaultdict(list)
Gra = [[0] * (N+1) for _ in range(N+1)]
deg = [0] * (N+1)
for k ... | 1475494500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["YES\nNO\nYES\nYES"] | fbb4e1cf1cad47481c6690ce54b27a1e | NoteFor the first test case, we can increment the elements with an even index, obtaining the array $$$[1, 3, 1]$$$, which contains only odd numbers, so the answer is "YES".For the second test case, we can show that after performing any number of operations we won't be able to make all elements have the same parity, so ... | Given an array $$$a=[a_1,a_2,\dots,a_n]$$$ of $$$n$$$ positive integers, you can do operations of two types on it: Add $$$1$$$ to every element with an odd index. In other words change the array as follows: $$$a_1 := a_1 +1, a_3 := a_3 + 1, a_5 := a_5+1, \dots$$$. Add $$$1$$$ to every element with an even index. In o... | Output $$$t$$$ lines, each of which contains the answer to the corresponding test case. As an answer, output "YES" if after any number of operations it is possible to make the final array contain only even numbers or only odd numbers, and "NO" otherwise. You can output the answer in any case (for example, the strings "... | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$2 \leq n \leq 50$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^... | standard output | standard input | PyPy 3-64 | Python | 800 | train_084.jsonl | 8f350a81ad93c6635f2620eb065ecd4b | 256 megabytes | ["4\n\n3\n\n1 2 1\n\n4\n\n2 2 2 3\n\n4\n\n2 2 2 2\n\n5\n\n1000 1 1000 1 1000"] | PASSED | casenum = int(input())
def eachissame(numlist):
parity = numlist[0] % 2
for i in numlist:
if i % 2 != parity:
return False
return True
for i in range(casenum):
arraylen = int(input())
array = [int(x) for x in input().split()]
oddnums = [array[i] for i in range(a... | 1650551700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["6\n5\n375000012\n500000026\n958557139\n0\n49735962"] | ee4038a896565a82d2d0d5293fce2a18 | 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 easy 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 1000$$$) — 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 2000, 0 \le k < 10^9 + 7$$$) — the numb... | standard output | standard input | PyPy 3 | Python | 2,100 | train_093.jsonl | 739510c8a71e2896f4b8121002835310 | 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 | mxn=10**9 + 7
def modI(a, m):
m0=m
y=0
x=1;
if(m==1): return 0;
while(a>1):
q=a//m;
t=m;
m=a%m;
a=t;
t=y;
y=x-q*y;
x=t;
if(x<0):x+=m0;
return x;
def fastfrac(a,b,M):
numb = modI(b,M)
return ((... | 1642862100 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["3", "3"] | dc044b8fe01b0a94638139cea034b1a8 | NoteThe graph for the first example is shown below. The special fields are denoted by red. It is optimal for Farmer John to add a road between fields $$$3$$$ and $$$5$$$, and the resulting shortest path from $$$1$$$ to $$$5$$$ is length $$$3$$$. The graph for the second example is shown below. Farmer John must add ... | Bessie is out grazing on the farm, which consists of $$$n$$$ fields connected by $$$m$$$ bidirectional roads. She is currently at field $$$1$$$, and will return to her home at field $$$n$$$ at the end of the day.The Cowfederation of Barns has ordered Farmer John to install one extra bidirectional road. The farm has $$$... | Output one integer, the maximum possible length of the shortest path from field $$$1$$$ to $$$n$$$ after Farmer John installs one road optimally. | The first line contains integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$n-1 \le m \le 2 \cdot 10^5$$$, $$$2 \le k \le n$$$) — the number of fields on the farm, the number of roads, and the number of special fields. The second line contains $$$k$$$ integers $$$a_1, a_2, \ldots, a_k$$$ ($$$1 ... | standard output | standard input | PyPy 3 | Python | 1,900 | train_022.jsonl | 7d3adca4b7a738d4f862048a9a57bbb1 | 256 megabytes | ["5 5 3\n1 3 5\n1 2\n2 3\n3 4\n3 5\n2 4", "5 4 2\n2 4\n1 2\n2 3\n3 4\n4 5"] | PASSED | from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
... | 1581953700 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
3 seconds | ["7", "4", "12"] | 09da15ac242c9a599221e205d1b92fa9 | NoteIn the first sample case, you can set $$$t_{1} =$$$ 'a', $$$t_{2} =$$$ 'b', $$$t_{3} =$$$ 'a' and pay $$$3 + 3 + 1 = 7$$$ coins, since $$$t_{3}$$$ is a substring of $$$t_{1}t_{2}$$$.In the second sample, you just need to compress every character by itself.In the third sample, you set $$$t_{1} = t_{2} =$$$ 'a', $$$t... | Suppose you are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters. You need to compress it using the smallest possible number of coins.To compress the string, you have to represent $$$s$$$ as a concatenation of several non-empty strings: $$$s = t_{1} t_{2} \ldots t_{k}$$$. The $$$i$$$-th ... | Output a single integer — the smallest possible number of coins you need to spend to compress $$$s$$$. | The first line contains three positive integers, separated by spaces: $$$n$$$, $$$a$$$ and $$$b$$$ ($$$1 \leq n, a, b \leq 5000$$$) — the length of the string, the cost to compress a one-character string and the cost to compress a string that appeared before. The second line contains a single string $$$s$$$, consisting... | standard output | standard input | Python 3 | Python | 2,100 | train_012.jsonl | 4541e68a238233a7f923adb56314badb | 256 megabytes | ["3 3 1\naba", "4 1 1\nabcd", "4 10 1\naaaa"] | PASSED | import sys
sys.setrecursionlimit(10 ** 8)
n, a, b = map(int,input().split())
s = input()
def calc(j):
if (j >= n): return 0
if (dp[j] != -1): return dp[j]
dp[j] = a + calc(j + 1)
lo = j
hi = n
farthest = -1
# finding best string to reach from a given j such that it eist before i using b... | 1551627300 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["YES\nNO"] | bcdd7862b718d6bcc25c9aba8716d487 | NoteIn the first test case you need to delete the first and the third digits. Then the string 7818005553535 becomes 88005553535. | A telephone number is a sequence of exactly 11 digits, where the first digit is 8. For example, the sequence 80011223388 is a telephone number, but the sequences 70011223388 and 80000011223388 are not.You are given a string $$$s$$$ of length $$$n$$$, consisting of digits.In one operation you can delete any character fr... | For each test print one line. If there is a sequence of operations, after which $$$s$$$ becomes a telephone number, print YES. Otherwise, print NO. | The first line contains one 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 length of string $$$s$$$. The second line of each test case contains the string $$$s$$$ ($$$|s| = n$$$) consisting of digits. | standard output | standard input | PyPy 3 | Python | 800 | train_004.jsonl | 6b5201810dc038313e30aab9163944f4 | 256 megabytes | ["2\n13\n7818005553535\n11\n31415926535"] | PASSED | for i in range(int(input())):
n = int(input())
s = input()
print('YES' if '8' in s and n - s.index('8') >= 11 else 'NO') | 1557930900 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["7", "12", "0"] | 1eb41e764a4248744edce6a9e7e3517a | NoteIn the first example pairs $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(2, 3)$$$, $$$(3, 1)$$$, $$$(3, 4)$$$, $$$(4, 2)$$$, $$$(4, 3)$$$ suffice. They produce numbers $$$451$$$, $$$4510$$$, $$$110$$$, $$$1045$$$, $$$1012$$$, $$$121$$$, $$$1210$$$, respectively, each of them is divisible by $$$11$$$.In the second example all $$$... | You are given an array $$$a$$$, consisting of $$$n$$$ positive integers.Let's call a concatenation of numbers $$$x$$$ and $$$y$$$ the number that is obtained by writing down numbers $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, a concatenation of numbers $$$12$$$ and $$$3456$$$ is... | Print a single integer — the number of ordered pairs of positions $$$(i, j)$$$ ($$$i \neq j$$$) in array $$$a$$$ such that the concatenation of $$$a_i$$$ and $$$a_j$$$ is divisible by $$$k$$$. | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$2 \le k \le 10^9$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). | standard output | standard input | PyPy 2 | Python | 1,900 | train_041.jsonl | ece6a7eed64e489890b03bcf111c4557 | 256 megabytes | ["6 11\n45 1 10 12 11 7", "4 2\n2 78 4 10", "5 2\n3 7 19 3 3"] | PASSED | from sys import stdin, stdout
ti = lambda : stdin.readline().strip()
os = lambda i : stdout.write(str(i) + '\n')
ma = lambda fxn, ti : map(fxn, ti.split())
ol = lambda arr : stdout.write(' '.join(element for element in arr) + '\n')
olws = lambda arr : stdout.write(''.join(element for element in arr) + '\n')
class Di... | 1535122200 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["YES\nNO"] | 3ef23f114be223255bd10131b2375b86 | NoteIn the first test case of the example, there is only one possible move for every player: the first player will put $$$2$$$, the second player will put $$$1$$$. $$$2>1$$$, so the first player will get both cards and will win.In the second test case of the example, it can be shown that it is the second player who ... | Two players decided to play one interesting card game.There is a deck of $$$n$$$ cards, with values from $$$1$$$ to $$$n$$$. The values of cards are pairwise different (this means that no two different cards have equal values). At the beginning of the game, the deck is completely distributed between players such that e... | For each test case, output "YES" in a separate line, if the first player wins. Otherwise, output "NO" in a separate line. You can print each letter in any case (upper or lower). | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). The description of the test cases follows. The first line of each test case contains three integers $$$n$$$, $$$k_1$$$, $$$k_2$$$ ($$$2 \le n \le 100, 1 \le k_1 \le n - 1, 1 \le k_2 \le n - 1, k_1 +... | standard output | standard input | PyPy 2 | Python | 800 | train_010.jsonl | 87e6dc2700e8eb0e22bb256115ef2f6e | 256 megabytes | ["2\n2 1 1\n2\n1\n5 2 3\n2 3\n1 4 5"] | PASSED | t=input()
for i in xrange(t):
n,k1,k2=map(int, raw_input().split())
a=map(int, raw_input().split())
b=map(int, raw_input().split())
if n in a:
print "YES"
else:
print "NO" | 1577628300 | [
"math",
"games"
] | [
1,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["0", "5555555550"] | 409b27044d5ec97b5315c92d4112376f | NoteIn the first test you can make only one number that is a multiple of 90 — 0.In the second test you can make number 5555555550, it is a multiple of 90. | Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?Jeff must make the number without leading zero. At that, we assume that number 0 ... | In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1. | The first line contains integer n (1 ≤ n ≤ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card. | standard output | standard input | Python 3 | Python | 1,000 | train_003.jsonl | 58e47b5256fc03df2924d9a99eb27be5 | 256 megabytes | ["4\n5 0 5 0", "11\n5 5 5 5 5 5 5 5 0 5 5"] | PASSED | n=int(input())
l=list(map(int,input().split()))
a,b=0,0
s=""
for i in l:
if i==5:
a=a+1
if i==0:
b=b+1
for i in range(a//9):
s=s+"555555555"
if a<9:
if b>0:
s="0"
else:
for i in range(b):
s=s+"0"
if b>0:
print(s)
else:
print("-1") | 1380900600 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["NNOTA\nAANN\nAAAAAA\nTNNTAOOA"] | f17445aca588e5fbc1dc6a595c811bd6 | NoteFor the first testcase, it takes $$$7$$$ seconds for Anton's body to transform NNOTA to ANTON: NNOTA $$$\to$$$ NNOAT $$$\to$$$ NNAOT $$$\to$$$ NANOT $$$\to$$$ NANTO $$$\to$$$ ANNTO $$$\to$$$ ANTNO $$$\to$$$ ANTON. Note that you cannot output strings such as AANTON, ANTONTRYGUB, AAAAA and anton as it is not a permut... | After rejecting $$$10^{100}$$$ data structure problems, Errorgorn is very angry at Anton and decided to kill him.Anton's DNA can be represented as a string $$$a$$$ which only contains the characters "ANTON" (there are only $$$4$$$ distinct characters). Errorgorn can change Anton's DNA into string $$$b$$$ which must be ... | For each testcase, print a single string, $$$b$$$. If there are multiple answers, you can output any one of them. $$$b$$$ must be a permutation of the string $$$a$$$. | The first line of input contains a single integer $$$t$$$ $$$(1 \leq t \leq 100000)$$$ — the number of testcases. The first and only line of each testcase contains $$$1$$$ string $$$a$$$ ($$$1 \leq |a| \leq 100000$$$). $$$a$$$ consists of only the characters "A", "N", "O" and "T". It is guaranteed that the sum of $$$|a... | standard output | standard input | PyPy 2 | Python | 2,200 | train_105.jsonl | fe06f76b8f10ce8623638aa7d8174ff4 | 512 megabytes | ["4\nANTON\nNAAN\nAAAAAA\nOAANTTON"] | PASSED | from __future__ import division, print_function
import os,sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
from bisect import bisect_left as lower_bound, bisect_right as upper_bound
... | 1622210700 | [
"math",
"strings"
] | [
0,
0,
0,
1,
0,
0,
1,
0
] | |
1 second | ["6", "20"] | 240a2b88ded6016d0fd7157d0ee2beea | NoteIn the first sample, the following pairs (i, j) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9).In the second sample, the following pairs (i, j) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9), (1, 10), (1, 11), (2, 10), (2, 11), (3, 10), (3, 11), (4, 10), (4, 11), (5, 10), (5, 11), (6, ... | The bear has a string s = s1s2... s|s| (record |s| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices i, j (1 ≤ i ≤ j ≤ |s|), that string x(i, j) = sisi + 1... sj contains at least one string "bear" as a substring.String x(i, j) contains string ... | Print a single number — the answer to the problem. | The first line contains a non-empty string s (1 ≤ |s| ≤ 5000). It is guaranteed that the string only consists of lowercase English letters. | standard output | standard input | Python 2 | Python | 1,200 | train_008.jsonl | 9c43fb84415cac25180fee36d0902b6b | 256 megabytes | ["bearbtear", "bearaabearc"] | PASSED | import sys, math
def rs():
return sys.stdin.readline().strip()
def ri():
return int(sys.stdin.readline().strip())
def ras():
return list(sys.stdin.readline().strip())
def rai():
return map(int,sys.stdin.readline().strip().split())
def solve():
# s = "bear"*(5000/4)
s = rs()
l = len(s)
... | 1390577700 | [
"math",
"strings"
] | [
0,
0,
0,
1,
0,
0,
1,
0
] | |
2 seconds | ["2\n16\n0\n6\n16"] | f48d55c60c12136979fe6db1e15c6053 | NoteLet's consider the example test.In the first test case, one way to obtain a score of $$$2$$$ is the following one: choose $$$a_7 = 1$$$ and $$$a_4 = 2$$$ for the operation; the score becomes $$$0 + \lfloor \frac{1}{2} \rfloor = 0$$$, the array becomes $$$[1, 1, 1, 1, 3]$$$; choose $$$a_1 = 1$$$ and $$$a_5 = 3$$$ ... | You are given an array $$$a$$$ of $$$n$$$ integers, and another integer $$$k$$$ such that $$$2k \le n$$$.You have to perform exactly $$$k$$$ operations with this array. In one operation, you have to choose two elements of the array (let them be $$$a_i$$$ and $$$a_j$$$; they can be equal or different, but their position... | Print one integer — the minimum possible score you can get. | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 500$$$) — the number of test cases. Each test case consists of two lines. The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100$$$; $$$0 \le k \le \lfloor \frac{n}{2} \rfloor$$$). The second line contains $$$n$$$ integers $$... | standard output | standard input | Python 3 | Python | 1,300 | train_087.jsonl | 3a6517e91434d732be16912e079a43a8 | 512 megabytes | ["5\n7 3\n1 1 1 2 1 3 1\n5 1\n5 5 5 5 5\n4 2\n1 3 3 7\n2 0\n4 2\n9 2\n1 10 10 1 10 2 7 10 3"] | PASSED | cases = int(input())
finalstring = ''
for case in range(cases):
nk = [int(x) for x in input().split(' ')]
caselist = [int(x) for x in input().split(' ')]
caselist.sort(reverse=True)
score = 0
for case in range(nk[1]):
score+=int(caselist[case+nk[1]]/caselist[case])
finalstring += f'{sum(caselis... | 1639492500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["11", "4"] | 8476fd1d794448fb961248cd5afbc92d | null | You are given a tree, which consists of $$$n$$$ vertices. Recall that a tree is a connected undirected graph without cycles. Example of a tree. Vertices are numbered from $$$1$$$ to $$$n$$$. All vertices have weights, the weight of the vertex $$$v$$$ is $$$a_v$$$.Recall that the distance between two vertices in the... | Print one integer — the maximum total weight of the subset in which all pairs of vertices have distance more than $$$k$$$. | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 200$$$) — the number of vertices in the tree and the distance restriction, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the weight of... | standard output | standard input | PyPy 2 | Python | 2,200 | train_014.jsonl | 26c0930853a343431dd92fae6f53baf4 | 256 megabytes | ["5 1\n1 2 3 4 5\n1 2\n2 3\n3 4\n3 5", "7 2\n2 1 2 1 2 1 1\n6 4\n1 5\n3 1\n2 3\n7 5\n7 4"] | PASSED |
visited = [0]*205
dp = [[0]*205 for i in range(205)]
def dfs(node,g):
sons = []
for nb in g[node]:
if not visited[nb]:
visited[nb] = 1
dfs(nb,g)
sons.append(nb)
dp[node][0] = ws[node-1]
for s in sons:
dp[node][0] += dp[s][k]
ls = len(sons)
... | 1571754900 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["? 1\n? 2\n? 3\n? 4\n? 5\n! 81"] | 8aba8c09ed1b1b25fa92cdad32d6fec3 | NoteYou can read more about singly linked list by the following link: https://en.wikipedia.org/wiki/Linked_list#Singly_linked_list The illustration for the first sample case. Start and finish elements are marked dark. | This is an interactive problem.You are given a sorted in increasing order singly linked list. You should find the minimum integer in the list which is greater than or equal to x.More formally, there is a singly liked list built on an array of n elements. Element with index i contains two integers: valuei is the integer... | To print the answer for the problem, print ! ans, where ans is the minimum integer in the list greater than or equal to x, or -1, if there is no such integer. | The first line contains three integers n, start, x (1 ≤ n ≤ 50000, 1 ≤ start ≤ n, 0 ≤ x ≤ 109) — the number of elements in the list, the index of the first element and the integer x. | standard output | standard input | Python 3 | Python | 2,000 | train_007.jsonl | b139fa626aaf0e9a3f39a1e7a2572264 | 256 megabytes | ["5 3 80\n97 -1\n58 5\n16 2\n81 1\n79 4"] | PASSED | from random import sample
def R():
return map(int, input().split())
def ask(i):
print('?', i, flush=True)
v, nxt = R()
if v < 0:
exit()
return v, nxt
def ans(v):
print('!', v)
exit()
n, s, x = R()
mv = -1
i = s
S = 800
q = range(1, n + 1)
if n > S:
q = sample(q, S)
if s n... | 1503592500 | [
"probabilities"
] | [
0,
0,
0,
0,
0,
1,
0,
0
] | |
5 seconds | ["0", "0", "1"] | 560d70425c765c325f412152c8124d2d | NoteIn the first example only one province exists, so it is not necessary to build any tunnels or roads.In the second example two provinces exist. It is possible to merge the provinces by building a tunnel between cities 1 and 3.In the third example at least one additional road is necessary. For example it is possible ... | Vasya plays FreeDiv. In this game he manages a huge state, which has n cities and m two-way roads between them. Unfortunately, not from every city you can reach any other one moving along these roads. Therefore Vasya decided to divide the state into provinces so that in every province, one could reach from every city a... | Print a single number, the minimum number of additional roads. | The first line contains three integers n, m and k (1 ≤ n, k ≤ 106, 0 ≤ m ≤ 106). Each of the next m lines contains two integers. They are the numbers of cities connected by a corresponding road. No road connects city to itself and there is at most one road between each pair of cities. | standard output | standard input | Python 2 | Python | 2,200 | train_059.jsonl | c930ed4d60cfc161a7bab429152e9249 | 256 megabytes | ["3 3 2\n1 2\n2 3\n3 1", "4 2 2\n1 2\n3 4", "4 0 2"] | PASSED | import sys
rl=sys.stdin.readline
n,m,k=map(int,rl().split())
c = [-1]*n
def root(x):
p = x
while c[p]>=0: p=c[p]
while c[x]>=0:
t = c[x]
c[x] = p
x = t
return p
#def root(x):
# if c[x]<0: return x
# c[x]=root(c[x])
# return c[x]
for i in xrange(m):
x,y=rl().split()
... | 1302422400 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["3.500000000", "2", "3439.031415943"] | ca417ff967dcd4594de66ade1a06acf0 | NoteIn the first example, Bob's counter has a 62.5% chance of being 3, a 25% chance of being 4, and a 12.5% chance of being 5. | A number of skyscrapers have been built in a line. The number of skyscrapers was chosen uniformly at random between 2 and 314! (314 factorial, a very large number). The height of each skyscraper was chosen randomly and independently, with height i having probability 2 - i for all positive integers i. The floors of a sk... | Output a single real value giving the expected value of the Alice's counter if you were given Bob's counter, or Bob's counter if you were given Alice's counter. You answer will be considered correct if its absolute or relative error doesn't exceed 10 - 9. | The first line of input will be a name, either string "Alice" or "Bob". The second line of input contains two integers n and h (2 ≤ n ≤ 30000, 0 ≤ h ≤ 30). If the name is "Alice", then n represents the value of Alice's counter when she reaches the rightmost skyscraper, otherwise n represents the value of Bob's counter ... | standard output | standard input | Python 2 | Python | 2,800 | train_037.jsonl | 9b790c17b97d12a8be06594dea096ac1 | 256 megabytes | ["Alice\n3 1", "Bob\n2 30", "Alice\n2572 10"] | PASSED | s=raw_input()
n,h=map(int,raw_input().split())
if s == "Bob": print n;exit()
ans=n
ti=1.0
for i in xrange(1,h+1):
ti *= 0.5
if ti < 0.1**50: break
tj = 1.0/(1.0-ti)
for j in xrange(1,n+1):
tj *= 1.0-ti
ans += (n-j)*tj*(ti-0.5*ti*(1.0+(j-1.0)*ti/(1.0-ti)))
print ans
| 1375549200 | [
"probabilities",
"math"
] | [
0,
0,
0,
1,
0,
1,
0,
0
] | |
2 seconds | ["2", "8"] | 609c531258612e58c4911c650e90891c | null | Kuzya started going to school. He was given math homework in which he was given an array $$$a$$$ of length $$$n$$$ and an array of symbols $$$b$$$ of length $$$n$$$, consisting of symbols '*' and '/'.Let's denote a path of calculations for a segment $$$[l; r]$$$ ($$$1 \le l \le r \le n$$$) in the following way: Let $... | Print a single integer — the number of simple segments $$$[l;r]$$$. | The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^6$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^6$$$). The third line contains $$$n$$$ symbols without spaces between them — the array $$$b_1, b_2 \ldots b_n$$$ ($$$b_i=$$$ '/' or $$$b_i=$$$ '*' for eve... | standard output | standard input | PyPy 3-64 | Python | 2,600 | train_106.jsonl | 869da5d6c010f857b6d363df21d28fb6 | 512 megabytes | ["3\n1 2 3\n*/*", "7\n6 4 10 1 2 15 1\n*/*/*//"] | PASSED | import sys,math
from collections import defaultdict
N = 1000005
maxf = [0] * N
for i in range(2,int(math.sqrt(N))+2):
if maxf[i] == 0:
for j in range(i+i, N, i):
maxf[j] = i
for i in range(2, N):
if maxf[i] == 0: maxf[i] = i
n = int(sys.stdin.readline())
a = [int(i) for i in sys.s... | 1635069900 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
1 second | ["0\n1", "0\n3\n2\n4\n1"] | 5ef966b7d9fbf27e6197b074eca31b15 | NoteThe tree from the second sample: | You are given a tree consisting of $$$n$$$ nodes. You want to write some labels on the tree's edges such that the following conditions hold: Every label is an integer between $$$0$$$ and $$$n-2$$$ inclusive. All the written labels are distinct. The largest value among $$$MEX(u,v)$$$ over all pairs of nodes $$$(u,v)$... | Output $$$n-1$$$ integers. The $$$i^{th}$$$ of them will be the number written on the $$$i^{th}$$$ edge (in the input order). | The first line contains the integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of nodes in the tree. Each of the next $$$n-1$$$ lines contains two space-separated integers $$$u$$$ and $$$v$$$ ($$$1 \le u,v \le n$$$) that mean there's an edge between nodes $$$u$$$ and $$$v$$$. It's guaranteed that the given graph is ... | standard output | standard input | Python 3 | Python | 1,500 | train_011.jsonl | 63c07907fa7dbcc961ddde96bfbd5e44 | 256 megabytes | ["3\n1 2\n1 3", "6\n1 2\n1 3\n2 4\n2 5\n5 6"] | PASSED |
data = input().rstrip().split()
n = int(data[0])
edges = []
g = {i+1: [] for i in range(n)}
leafes = set()
for _ in range(n-1):
data = input().rstrip().split()
a, b = int(data[0]), int(data[1])
a, b = sorted([a, b])
edges.append((a, b))
g[a].append(b)
g[b].append(a)
for k, v in g.items():
... | 1584196500 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["YES\nabc", "NO", "YES\nxxxxxxy"] | 64700ca85ef3b7408d7d7ad1132f8f81 | NoteIn the first sample any of the six possible strings will do: "abc", "acb", "bac", "bca", "cab" or "cba".In the second sample no letter permutation will satisfy the condition at p = 2 (s2 = s4).In the third test any string where character "y" doesn't occupy positions 2, 3, 4, 6 will be valid. | You are given a string s, consisting of small Latin letters. Let's denote the length of the string as |s|. The characters in the string are numbered starting from 1. Your task is to find out if it is possible to rearrange characters in string s so that for any prime number p ≤ |s| and for any integer i ranging from 1 t... | If it is possible to rearrange the characters in the string so that the above-mentioned conditions were fulfilled, then print in the first line "YES" (without the quotes) and print on the second line one of the possible resulting strings. If such permutation is impossible to perform, then print the single string "NO". | The only line contains the initial string s, consisting of small Latin letters (1 ≤ |s| ≤ 1000). | standard output | standard input | Python 3 | Python | 1,300 | train_066.jsonl | 9d64aede4bd7e0e878d70f4f09ab1eae | 256 megabytes | ["abc", "abcd", "xxxyxxx"] | PASSED | from collections import Counter
def is_prime(x):
if x < 2:
return 0
for i in range(2, x):
if x % i == 0:
return False
return True
def proc(s):
n = len(s)
same = set()
for p in range(2,n+1):
if not is_prime(p):
continue
if p * 2 > n:
... | 1320333000 | [
"number theory",
"strings"
] | [
0,
0,
0,
0,
1,
0,
1,
0
] | |
2 seconds | ["2.683281573000", "2.267786838055"] | 18b1814234b05bae56ea4446506b543b | NoteIn the first sample the jury should choose the following values: r1 = 3, p1 = 2, p2 = 1. | The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of r1 cm, inner radius of r2 cm, (0 < r2 < r1) made of metal with density p1 g/cm3. The second part is an inner disk with radius r2 cm, it is made of metal with density p2 g/cm3. The disk is n... | Print a single real number — the sought value r2 with absolute or relative error of at most 10 - 6. It is guaranteed that the solution that meets the problem requirements exists. | The first input line contains an integer n and a sequence of integers x1, x2, ..., xn. The second input line contains an integer m and a sequence of integers y1, y2, ..., ym. The third input line contains an integer k and a sequence of integers z1, z2, ..., zk. The last line contains two integers A and B. All numbers g... | standard output | standard input | PyPy 2 | Python | 1,300 | train_000.jsonl | 6a6bb6cdaa6a0cc8db980f87b4189cd7 | 256 megabytes | ["3 1 2 3\n1 2\n3 3 2 1\n1 2", "4 2 3 6 4\n2 1 2\n3 10 6 8\n2 1"] | PASSED | #!/usr/bin/env pypy
from __future__ import division, print_function
from collections import defaultdict, Counter, deque
from future_builtins import ascii, filter, hex, map, oct, zip
from itertools import imap as map, izip as zip, permutations, combinations, combinations_with_replacement
from __builtin__ import xrange a... | 1344267000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["abca", "aabbbcba", "abdbdccacbdbdccb", "cccccffffcccccffccfcffcccccfffff", "zz"] | bc145a67268b42c00835dc2370804ec9 | NoteIn the first test, the lexicographically minimal xoration $$$t$$$ of $$$s =$$$"acba" is "abca". It's a xoration because, for $$$j = 3$$$, $$$t_0 = s_{0 \oplus j} = s_3 =$$$ "a"; $$$t_1 = s_{1 \oplus j} = s_2 =$$$ "b"; $$$t_2 = s_{2 \oplus j} = s_1 =$$$ "c"; $$$t_3 = s_{3 \oplus j} = s_0 =$$$ "a". There isn't ... | You are given an integer $$$n$$$ and a string $$$s$$$ consisting of $$$2^n$$$ lowercase letters of the English alphabet. The characters of the string $$$s$$$ are $$$s_0s_1s_2\cdots s_{2^n-1}$$$.A string $$$t$$$ of length $$$2^n$$$ (whose characters are denoted by $$$t_0t_1t_2\cdots t_{2^n-1}$$$) is a xoration of $$$s$$... | Print a single line containing the lexicographically minimal xoration of $$$s$$$. | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 18$$$). The second line contains a string $$$s$$$ consisting of $$$2^n$$$ lowercase letters of the English alphabet. | standard output | standard input | PyPy 3-64 | Python | 2,800 | train_105.jsonl | 37d7150d1a865df973d983a4ad17cfe3 | 512 megabytes | ["2\nacba", "3\nbcbaaabb", "4\nbdbcbccdbdbaaccd", "5\nccfcffccccccffcfcfccfffffcccccff", "1\nzz"] | PASSED | r=range
n=int(input())
N=1<<n
s=input()
a=sorted([ord(s[i])*N+i for i in r(N)])
for j in r(n):
p=1<<j;v=[0]*N;c=0;l=0
for i in r(N):
if a[i]//N>c:c=a[i]//N;l+=1
v[a[i]%N]=l
a=sorted([v[i]*N*N+v[i^p]*N+i for i in r(N)])
print(''.join([s[j^(a[0]%N)]for j in r(N)])) | 1647764100 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["6.4641016", "1.0000000", "3.2429391"] | e27cff5d681217460d5238bf7ef6a876 | null | NN is an experienced internet user and that means he spends a lot of time on the social media. Once he found the following image on the Net, which asked him to compare the sizes of inner circles: It turned out that the circles are equal. NN was very surprised by this fact, so he decided to create a similar picture him... | Output a single number $$$R$$$ — the radius of the outer circle required for building the required picture. Your answer will be accepted if its relative or absolute error does not exceed $$$10^{-6}$$$. Formally, if your answer is $$$a$$$ and the jury's answer is $$$b$$$. Your answer is accepted if and only when $$$\fr... | The first and the only line of the input file contains two numbers $$$n$$$ and $$$r$$$ ($$$3 \leq n \leq 100$$$, $$$1 \leq r \leq 100$$$) — the number of the outer circles and the radius of the inner circle respectively. | standard output | standard input | Python 3 | Python | 1,200 | train_006.jsonl | 3cab2a35d6eaf514095fb2166c897ab7 | 256 megabytes | ["3 1", "6 1", "100 100"] | PASSED | import math
def quadratic(a, b, c):
return (-1 * b + math.sqrt(b * b - 4 * a * c))/(2 * a)
PI = 3.14159265
x = input().split()
n = int(x[0])
r = int(x[1])
k = 360.0/n;
R = quadratic((2/(1-math.cos(k * PI/180)))-1, - 2 * r, - r * r);
print(R) | 1547390100 | [
"geometry",
"math"
] | [
0,
1,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["2\n3", "2\n4"] | bda7d223eabfcc519a60801012c58616 | NoteIn the first sample, there are two possibilities to finish the Super M's job in 3 krons. They are: and .However, you should choose the first one as it starts in the city with the lower number. | Ari the monster is not an ordinary monster. She is the hidden identity of Super M, the Byteforces’ superhero. Byteforces is a country that consists of n cities, connected by n - 1 bidirectional roads. Every road connects exactly two distinct cities, and the whole road system is designed in a way that one is able to go ... | First print the number of the city Super M should teleport to. If there are many possible optimal answers, print the one with the lowest city number. Then print the minimum possible time needed to scare all humans in cities being attacked, measured in Krons. Note that the correct answer is always unique. | The first line of the input contains two integers n and m (1 ≤ m ≤ n ≤ 123456) - the number of cities in Byteforces, and the number of cities being attacked respectively. Then follow n - 1 lines, describing the road system. Each line contains two city numbers ui and vi (1 ≤ ui, vi ≤ n) - the ends of the road i. The las... | standard output | standard input | PyPy 3 | Python | 2,200 | train_035.jsonl | d16078dc38d3deb760329bde5ce21a2e | 256 megabytes | ["7 2\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n2 7", "6 4\n1 2\n2 3\n2 4\n4 5\n4 6\n2 4 5 6"] | PASSED | from heapq import *
INF = float('inf')
n, m = map(int, input().split())
adj = [[] for _ in range(n+1)]
wg= ng = [0 for _ in range(n+1)]
for _ in range(n-1):
a, b = map(int, input().split())
adj[a].append(b)
adj[b].append(a)
aaa = set(map(int, input().split()))
if len(aaa) == 1:print(min(aaa));print(0);exi... | 1446309000 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
2 seconds | ["7"] | dced53eba154855fa0f203178574990c | Note The sample is like this: | There is a square of size $$$10^6 \times 10^6$$$ on the coordinate plane with four points $$$(0, 0)$$$, $$$(0, 10^6)$$$, $$$(10^6, 0)$$$, and $$$(10^6, 10^6)$$$ as its vertices.You are going to draw segments on the plane. All segments are either horizontal or vertical and intersect with at least one side of the square.... | Print the number of pieces the square is divided into after drawing all the segments. | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$0 \le n, m \le 10^5$$$) — the number of horizontal segments and the number of vertical segments. The next $$$n$$$ lines contain descriptions of the horizontal segments. The $$$i$$$-th line contains three integers $$$y_i$$$, $$$lx_i$$$ and $$$rx_i$$$ ($$$0 <... | standard output | standard input | PyPy 2 | Python | 2,400 | train_019.jsonl | a08ae7ac349d92b8b4a979685f8076a0 | 384 megabytes | ["3 3\n2 3 1000000\n4 0 4\n3 0 1000000\n4 0 1\n2 0 5\n3 1 1000000"] | PASSED | from __future__ import division, print_function
_interactive = False
def main():
MAX = 1000000
h, v = input_as_list()
hs = input_as_matrix(h, 3)
vs = input_as_matrix(v, 3)
hs += [(0, 0, MAX), (MAX, 0, MAX)]
vs += [(0, 0, MAX), (MAX, 0, MAX)]
# Event types
VST, H, VEN = (0, 1, 2)
e... | 1598020500 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
3 seconds | ["? 1 2 3\n\n? 3 4 5\n\n! 3 4 1 2\n\n? 7 1 9\n\n! 4 2 3 6 8"] | 98c584b0479eb26d8b0307bd72fc48fd | NoteExplanation for example interaction (note that this example only exists to demonstrate the interaction procedure and does not provide any hint for the solution):For the first test case:Question "? 1 2 3" returns $$$0$$$, so there are more impostors than crewmates among players $$$1$$$, $$$2$$$ and $$$3$$$.Question ... | This is an interactive problem. The only difference between the easy and hard version is the limit on number of questions.There are $$$n$$$ players labelled from $$$1$$$ to $$$n$$$. It is guaranteed that $$$n$$$ is a multiple of $$$3$$$.Among them, there are $$$k$$$ impostors and $$$n-k$$$ crewmates. The number of impo... | null | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of each test case contains a single integer $$$n$$$ ($$$6 \le n < 10^4$$$, $$$n$$$ is a multiple of $$$3$$$) — the number of players... | standard output | standard input | Python 3 | Python | 2,400 | train_100.jsonl | a7cdcddaf4eef3765ca1223327e66c49 | 256 megabytes | ["2\n6\n\n0\n\n1\n\n9\n\n1"] | PASSED | def ask(a, b, c):
print(f'? {a} {b} {c}', flush=True)
s = input()
if s == '-1':
exit()
else:
return int(s)
for _ in range(int(input())):
n = int(input())
ans = [0]*n
fp = [0]*2
sp = [0]*2
tp = [0]*2
fop= [0]*2
fp[0]= ['0000', '0010', '0100', '1... | 1639661700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["Rublo", "Rublo", "Furlo"] | cc23f07b6539abbded7e120793bef6a7 | null | Furlo and Rublo play a game. The table has n piles of coins lying on it, the i-th pile has ai coins. Furlo and Rublo move in turns, Furlo moves first. In one move you are allowed to: choose some pile, let's denote the current number of coins in it as x; choose some integer y (0 ≤ y < x; x1 / 4 ≤ y ≤ x1 / 2) and de... | If both players play optimally well and Furlo wins, print "Furlo", otherwise print "Rublo". Print the answers without the quotes. | The first line contains integer n (1 ≤ n ≤ 77777) — the number of piles. The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 777777777777) — the sizes of piles. The numbers are separated by single spaces. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the c... | standard output | standard input | Python 2 | Python | 2,200 | train_001.jsonl | ffca4bac4e0e73f25ac7c01ea5dd17f9 | 256 megabytes | ["1\n1", "2\n1 2", "10\n1 2 3 4 5 6 7 8 9 10"] | PASSED | from bisect import *
input()
r = [3, 15, 81, 6723, 15 ** 4, 15 ** 8]
v = [0, 1, 2, 0, 3, 1, 2]
print ['Rublo', 'Furlo'][reduce(lambda x, y : x ^ y, map(lambda x : v[bisect_left(r, x)], map(int, raw_input().split()))) > 0] | 1355671800 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["R\nL\nL\nD\nU\nU\nU\nR\nR\nD"] | 79879630a9358ea152a6f1616ef9b630 | NoteIn first test case all four directions swapped with their opposite directions. Protocol of interaction In more convenient form:This test could be presenter for hack in following way: 4 3 1 1...**.F*.... | This is an interactive problem.Vladik has favorite game, in which he plays all his free time.Game field could be represented as n × m matrix which consists of cells of three types: «.» — normal cell, player can visit it. «F» — finish cell, player has to finish his way there to win. There is exactly one cell of this ... | null | First line contains two space-separated integers n and m (1 ≤ n, m ≤ 100) — number of rows and columns respectively. Each of next n lines contains m characters describing corresponding row of field. Set of characters in field is described above. Guaranteed that cell with coordinates (1, 1) is normal and there is at lea... | standard output | standard input | Python 3 | Python | 2,100 | train_007.jsonl | 4af6cf8adc7c898bcbbcb1ba62767f35 | 256 megabytes | ["4 3\n...\n**.\nF*.\n...\n1 1\n1 2\n1 3\n1 3\n2 3\n3 3\n4 3\n4 2\n4 1\n3 1"] | PASSED | import sys
sys.setrecursionlimit(2*10**5)
n, m=map(int, input().split())
g=[input() for i in range(n)]
vis=[[0]*m for i in range(n)]
mp={}
l=[]
def dfs(i, j):
vis[i][j]=1
l.append((i, j))
if g[i][j]=='F':
return 1
for d in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
if not (i+d[0]<0 or i+d[0]>=n... | 1495877700 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["6\n2\n3"] | c358bce566a846bd278329ef2c029dff | NoteIn the first test case, it is possible to achieve $$$a_k = 1$$$ for every $$$k$$$. To do so, you may use the following operations: swap $$$a_k$$$ and $$$a_4$$$; swap $$$a_2$$$ and $$$a_2$$$; swap $$$a_5$$$ and $$$a_5$$$. In the second test case, only $$$k = 1$$$ and $$$k = 2$$$ are possible answers. To achieve $... | You are given an array consisting of $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$. Initially $$$a_x = 1$$$, all other elements are equal to $$$0$$$.You have to perform $$$m$$$ operations. During the $$$i$$$-th operation, you choose two indices $$$c$$$ and $$$d$$$ such that $$$l_i \le c, d \le r_i$$$, and swap ... | For each test case print one integer — the number of indices $$$k$$$ such that it is possible to choose the operations so that $$$a_k = 1$$$ in the end. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then the description of $$$t$$$ testcases follow. The first line of each test case contains three integers $$$n$$$, $$$x$$$ and $$$m$$$ ($$$1 \le n \le 10^9$$$; $$$1 \le m \le 100$$$; $$$1 \le x \le n$$$). Each of next ... | standard output | standard input | Python 3 | Python | 1,300 | train_001.jsonl | 99716b2822970c255965782ba88caa05 | 256 megabytes | ["3\n6 4 3\n1 6\n2 3\n5 5\n4 1 2\n2 4\n1 2\n3 3 2\n2 3\n1 2"] | PASSED | for _ in range(int(input())):
n,x,m = map(int,input().split())
lst = []
for i in range(m):
tmp = list(map(int,input().split()))
lst.append(tmp)
while lst and not lst[0][0]<=x<=lst[0][1]:
lst.pop(0)
if not lst:
print(1)
els... | 1591886100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["17\n82\n23\n210", "2\n0\n22\n59\n16\n8"] | e02938670cb1d586d065ca9750688404 | NoteIn the first query of the first sample, the Lipschitz constants of subarrays of with length at least 2 are: The answer to the query is their sum. | A function is called Lipschitz continuous if there is a real constant K such that the inequality |f(x) - f(y)| ≤ K·|x - y| holds for all . We'll deal with a more... discrete version of this term.For an array , we define it's Lipschitz constant as follows: if n < 2, if n ≥ 2, over all 1 ≤ i < j ≤ n In other ... | Print the answers to all queries in the order in which they are given in the input. For the i-th query, print one line containing a single integer — the sum of Lipschitz constants of all subarrays of . | The first line of the input contains two space-separated integers n and q (2 ≤ n ≤ 100 000 and 1 ≤ q ≤ 100) — the number of elements in array and the number of queries respectively. The second line contains n space-separated integers (). The following q lines describe queries. The i-th of those lines contains two spa... | standard output | standard input | PyPy 3 | Python | 2,100 | train_024.jsonl | ca65e3064d0735787897814f0f5ccb24 | 256 megabytes | ["10 4\n1 5 2 9 1 3 4 2 1 7\n2 4\n3 8\n7 10\n1 9", "7 6\n5 7 7 4 6 6 2\n1 2\n2 3\n2 6\n1 7\n4 7\n3 5"] | PASSED | f = lambda: map(int, input().split())
n, m = f()
t = list(f())
p = [1e9] + [abs(b - a) for a, b in zip(t, t[1:])] + [1e9]
L, R = [0] * n, [0] * n
for i in range(1, n):
j = n - i
x, y = i - 1, j + 1
a, b = p[i], p[j]
while a > p[x]: x = L[x]
while b >= p[y]: y = R[y]
L[i], R[j] = x, y
for k in ra... | 1448382900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["2", "1", "1"] | 00db0111fd80ce1820da2af07a6cb8f1 | NoteIn the second example hacker need to use any of the passwords to access the system. | One unknown hacker wants to get the admin's password of AtForces testing system, to get problems from the next contest. To achieve that, he sneaked into the administrator's office and stole a piece of paper with a list of $$$n$$$ passwords — strings, consists of small Latin letters.Hacker went home and started preparin... | In a single line print the minimal number of passwords, the use of which will allow guaranteed to access the system. | The first line contain integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — number of passwords in the list. Next $$$n$$$ lines contains passwords from the list – non-empty strings $$$s_i$$$, with length at most $$$50$$$ letters. Some of the passwords may be equal. It is guaranteed that the total length of all passwords ... | standard output | standard input | PyPy 3 | Python | 1,500 | train_023.jsonl | ef3d465a611ab310c1135cf44d1ba8b8 | 256 megabytes | ["4\na\nb\nab\nd", "3\nab\nbc\nabc", "1\ncodeforces"] | PASSED | def union(x, y):
xr = find(x)
yr = find(y)
root[yr] = xr
def find(x):
if root[x] != x:
x = find(root[x])
return x
import sys
input = sys.stdin.readline
used = set()
root = dict()
for _ in range(int(input())):
s = input().rstrip()
for j in s:
if ord(j) - 97 not in root:
... | 1575038100 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["3\n2 2\n1 1\n2 4\n-1\n4\n1 1\n2 6\n3 3\n3 7\n4\n3 1\n1 2\n2 3\n1 4\n2\n4 5\n2 1\n4\n3 1\n4 5\n2 9\n1 13"] | c08933fdaceb220f4ef3ba8c5f09fe12 | NoteThe first test case is explained in the problem statement.In the second test case, it is impossible to color all the letters of the text in red. | You are given some text $$$t$$$ and a set of $$$n$$$ strings $$$s_1, s_2, \dots, s_n$$$. In one step, you can choose any occurrence of any string $$$s_i$$$ in the text $$$t$$$ and color the corresponding characters of the text in red. For example, if $$$t=\texttt{bababa}$$$ and $$$s_1=\texttt{ba}$$$, $$$s_2=\texttt{aba... | For each test case, print the answer on a separate line. If it is impossible to color all the letters of the text in red, print a single line containing the number -1. Otherwise, on the first line, print the number $$$m$$$ — the minimum number of steps it will take to turn all the letters $$$t$$$ red. Then in the next ... | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 100$$$) —the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains the text $$$t$$$ ($$$1 \le |t| \le 100$$$), consisting only of lowercase Latin letters, where $$$|t|$$$ is the lengt... | standard output | standard input | PyPy 3-64 | Python | 1,600 | train_102.jsonl | 6458d49857e833dafc7b4e2f8e83baee | 256 megabytes | ["6\n\nbababa\n\n2\n\nba\n\naba\n\ncaba\n\n2\n\nbac\n\nacab\n\nabacabaca\n\n3\n\naba\n\nbac\n\naca\n\nbaca\n\n3\n\na\n\nc\n\nb\n\ncodeforces\n\n4\n\ndef\n\ncode\n\nefo\n\nforces\n\naaaabbbbcccceeee\n\n4\n\neeee\n\ncccc\n\naaaa\n\nbbbb"] | PASSED | import sys
input=lambda: sys.stdin.readline().strip()
for _ in range(int(input())):
t = input()
n = int(input())
l = list()
for i in range(n):
inp = input()
l.append((inp,len(inp),i+1))
l.sort(key=lambda p: p[1],reverse=True)
ans = list() # (id, pos)
mai = 0
i = 0
while i <= mai < len(t):
... | 1659364500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2.5 seconds | ["8", "3"] | e4a2cfe3e76a7fafb8116c1972394c46 | NoteDo keep in mind that k0 = 1.In the first sample, Molly can get following different affection values: 2: segments [1, 1], [2, 2], [3, 3], [4, 4]; 4: segments [1, 2], [2, 3], [3, 4]; 6: segments [1, 3], [2, 4]; 8: segments [1, 4]. Out of these, 2, 4 and 8 are powers of k = 2. Therefore, the answer is 8.In the second... | Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The i-th of them has affection value ai.Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total affection ... | Output a single integer — the number of valid segments. | The first line of input contains two integers, n and k, the number of chemicals and the number, such that the total affection value is a non-negative power of this number k. (1 ≤ n ≤ 105, 1 ≤ |k| ≤ 10). Next line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — affection values of chemicals. | standard output | standard input | PyPy 2 | Python | 1,800 | train_017.jsonl | 329fc7d9a02bdd39dde9621ace99b5c0 | 512 megabytes | ["4 2\n2 2 2 2", "4 -3\n3 -6 -3 12"] | PASSED | from sys import stdin
from collections import *
def arr_sum(arr):
tem = [0]
for i in range(len(arr)):
tem.append(tem[i] + arr[i])
return tem
rints = lambda: [int(x) for x in stdin.readline().split()]
mi, ma = -10 ** 14, 10 ** 14
n, k = rints()
a = rints()
mem, ans, lst, val = arr_sum(a), 0, 0, ... | 1487861100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["3.849644710502\n1.106060157705"] | 3882f2c02e83bd2d55de8004ea3bbd88 | null | For months Maxim has been coming to work on his favorite bicycle. And quite recently he decided that he is ready to take part in a cyclists' competitions.He knows that this year n competitions will take place. During the i-th competition the participant must as quickly as possible complete a ride along a straight line ... | Print n real numbers, the i-th number should be equal to the minimum possible time measured by the time counter. Your answer will be considered correct if its absolute or relative error will not exceed 10 - 6. Namely: let's assume that your answer equals a, and the answer of the jury is b. The checker program will con... | The first line contains three integers n, r and v (1 ≤ n ≤ 100 000, 1 ≤ r, v ≤ 109) — the number of competitions, the radius of the front wheel of Max's bike and his maximum speed, respectively. Next n lines contain the descriptions of the contests. The i-th line contains two integers si and fi (1 ≤ si < fi ≤ 109) ... | standard output | standard input | PyPy 2 | Python | 2,500 | train_022.jsonl | 94ecadbbdec855bac087171a8a62699e | 256 megabytes | ["2 1 2\n1 10\n5 9"] | PASSED | from math import cos,pi
def g(t):
return t+cos(t)
def solve(y):
assert(y>=1 and y<2*pi+1)
low = 0.
high = 2*pi+1
for k in range(64):
mid = (low+high)/2
if g(mid) > y:
high = mid
else:
low = mid
return low
def bestTime(s,f,r,v):
m = int((2.+float(f-s)/r)/pi-0.1)
if (m%2 == 0): m += 1
res = None
... | 1447000200 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
1 second | ["3"] | f33991da3b4a57dd6535af86edeeddc0 | NoteIn the first sample test a clique of size 3 is, for example, a subset of vertexes {3, 6, 18}. A clique of a larger size doesn't exist in this graph. | As you must know, the maximum clique problem in an arbitrary graph is NP-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.Just in case, let us remind you that a clique in a non-directed graph is a subset of the vertices of a graph, such that any two vertices of this subset are connecte... | Print a single number — the maximum size of a clique in a divisibility graph for set A. | The first line contains integer n (1 ≤ n ≤ 106), that sets the size of set A. The second line contains n distinct positive integers a1, a2, ..., an (1 ≤ ai ≤ 106) — elements of subset A. The numbers in the line follow in the ascending order. | standard output | standard input | PyPy 3 | Python | 1,500 | train_007.jsonl | b72301c10d2ea757b84f001aea1a3c0e | 256 megabytes | ["8\n3 4 6 8 10 18 21 24"] | PASSED | #!/usr/bin/env python3
import os
import sys
from io import BytesIO, IOBase
class FastO:
def __init__(self, fd=1):
stream = BytesIO()
self.flush = lambda: os.write(fd, stream.getvalue()) and not stream.truncate(0) and stream.seek(0)
self.write = lambda b: stream.write(b.encode())
class os... | 1438273200 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["NO\nYES\nYES\nNO"] | 08679e44ee5d3c3287230befddf7eced | NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the stri... | You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$... | Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers. | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contain... | standard output | standard input | Python 3 | Python | 800 | train_010.jsonl | 546704727393151a62aa7713147cc6a1 | 256 megabytes | ["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"] | PASSED | n = int(input())
for i in range(n):
a = input()
b = input()
c = input()
flag=1
for j in range(len(c)):
if(c[j]==a[j] or c[j]==b[j]):
flag =1
else:
flag = 0
break
if(flag==1):
print("YES")
else:
print("NO") | 1581604500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["YES\n3 2 1\nYES\n8 1 2 3 4\nNO"] | 85383c9e802348a3153e7f98ce278f09 | NoteIn the first test case, Phoenix puts the gold piece with weight $$$3$$$ on the scale first, then the piece with weight $$$2$$$, and finally the piece with weight $$$1$$$. The total weight on the scale is $$$3$$$, then $$$5$$$, then $$$6$$$. The scale does not explode because the total weight on the scale is never $... | Phoenix has collected $$$n$$$ pieces of gold, and he wants to weigh them together so he can feel rich. The $$$i$$$-th piece of gold has weight $$$w_i$$$. All weights are distinct. He will put his $$$n$$$ pieces of gold on a weight scale, one piece at a time. The scale has an unusual defect: if the total weight on it is... | For each test case, if Phoenix cannot place all $$$n$$$ pieces without the scale exploding, print NO. Otherwise, print YES followed by the rearranged array $$$w$$$. If there are multiple solutions, print any. | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 100$$$; $$$1 \le x \le 10^4$$$) — the number of gold pieces that Phoenix has and the weigh... | standard output | standard input | PyPy 3-64 | Python | 800 | train_097.jsonl | ff607480e89a933be4591b44f14e6966 | 256 megabytes | ["3\n3 2\n3 2 1\n5 3\n1 2 3 4 8\n1 5\n5"] | PASSED | for _ in range(int(input())):
n,x = [int(x) for x in input().split()]
lis = list(map(int,input().split()))
if sum(lis) ==x:
print('NO')
continue
lis = sorted(lis,reverse = True)
value =0
for i in range(n):
value+=lis[i]
if value == x:
lis[i],lis[i+1] = lis[i+1],lis[i]
... | 1619966100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["Possible\n3\n1 2 3\n3\n1 4 3", "Impossible", "Impossible"] | 2847383385097c4ab8e5ee1f06580d0e | null | Leslie and Leon entered a labyrinth. The labyrinth consists of $$$n$$$ halls and $$$m$$$ one-way passages between them. The halls are numbered from $$$1$$$ to $$$n$$$.Leslie and Leon start their journey in the hall $$$s$$$. Right away, they quarrel and decide to explore the labyrinth separately. However, they want to m... | If it is possible to find the desired two paths, output "Possible", otherwise output "Impossible". If the answer exists, output two path descriptions. Each description occupies two lines. The first line of the description contains an integer $$$h$$$ ($$$2 \le h \le n$$$) — the number of halls in a path, and the second ... | The first line contains three integers $$$n$$$, $$$m$$$, and $$$s$$$, where $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) is the number of vertices, $$$m$$$ ($$$0 \le m \le 2 \cdot 10^5$$$) is the number of edges in the labyrinth, and $$$s$$$ ($$$1 \le s \le n$$$) is the starting hall. Then $$$m$$$ lines with descriptions o... | standard output | standard input | PyPy 3-64 | Python | 1,800 | train_091.jsonl | 75d196843daed1b34b5d50f6ba0e4a47 | 512 megabytes | ["5 5 1\n1 2\n2 3\n1 4\n4 3\n3 5", "5 5 1\n1 2\n2 3\n3 4\n2 5\n5 4", "3 3 2\n1 2\n2 3\n3 1"] | PASSED | import sys
input = sys.stdin.readline
def gen_input():
while True:
yield [int(c) for c in input().split()]
def gen_fake1():
yield [5, 5, 1]
yield [1, 2]
yield [2, 3]
yield [1, 4]
yield [4, 3]
yield [3, 5]
def gen_fake():
yield [3, 3, 2]
yield [1, 2]
yield [2, 3]
... | 1649837100 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["Yes\nNo\nNo\nYes\nNo"] | d5bd27c969d9cd910f13baa53c247871 | NoteIn the first test case, a possible way of splitting the set is $$$(2,3)$$$, $$$(4,5)$$$.In the second, third and fifth test case, we can prove that there isn't any possible way.In the fourth test case, a possible way of splitting the set is $$$(2,3)$$$. | You are given a multiset (i. e. a set that can contain multiple equal integers) containing $$$2n$$$ integers. Determine if you can split it into exactly $$$n$$$ pairs (i. e. each element should be in exactly one pair) so that the sum of the two elements in each pair is odd (i. e. when divided by $$$2$$$, the remainder ... | For each test case, print "Yes" if it can be split into exactly $$$n$$$ pairs so that the sum of the two elements in each pair is odd, and "No" otherwise. You can print each letter in any case. | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1\leq t\leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1\leq n\leq 100$$$). The second line of each test case contains $$$2n$$$ i... | standard output | standard input | PyPy 3-64 | Python | 800 | train_083.jsonl | 0bd86eaf6486edde2fb523fcebed8ef1 | 256 megabytes | ["5\n2\n2 3 4 5\n3\n2 3 4 5 5 5\n1\n2 4\n1\n2 3\n4\n1 5 3 2 6 7 3 4"] | PASSED | for _ in range(int(input())):
n = int(input())
# n, m = map(int, input().split())
arr = sorted(list(map(int, input().split())))
odd = 0
even = 0
for i in range(n*2):
if arr[i] % 2 == 0:
even += 1
else:
odd += 1
if odd == 2 and even == ... | 1625317500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["YES\nYES\nNO\nYES\nYES"] | f4267120fce9304fc4c45142b60fb867 | null | You are given $$$n$$$ points with integer coordinates on a coordinate axis $$$OX$$$. The coordinate of the $$$i$$$-th point is $$$x_i$$$. All points' coordinates are distinct and given in strictly increasing order.For each point $$$i$$$, you can do the following operation no more than once: take this point and move it ... | For each test case, print the answer — if the set of points from the test case can be moved to form a consecutive segment of integers, print YES, otherwise print NO. | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of points in the set $$$x$$$. The second line of the test case ... | standard output | standard input | Python 3 | Python | 1,000 | train_087.jsonl | 31dd71f3f425b46936991a1c34b435f2 | 256 megabytes | ["5\n\n2\n\n1 4\n\n3\n\n1 2 3\n\n4\n\n1 2 3 7\n\n1\n\n1000000\n\n3\n\n2 5 6"] | PASSED | import sys
t = int(input())
is_one = 0
is_three = 0
is_two = 0
is_break = 0
for i in range(t):
is_one = 0
is_three = 0
is_two = 0
is_break = 0
fullcount = 0
n = int(input())
arr = list(map(int, input().split()))
# print(arr)
if(n == 1):
print('YES')
c... | 1650638100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["10\n18\n90\n180"] | d11b56fe172110d5dfafddf880e48f18 | NoteThe answer for the first query is on the picture above.The answer for the second query is reached on a regular $$$18$$$-gon. For example, $$$\angle{v_2 v_1 v_6} = 50^{\circ}$$$.The example angle for the third query is $$$\angle{v_{11} v_{10} v_{12}} = 2^{\circ}$$$.In the fourth query, minimal possible $$$n$$$ is $$... | You are given an angle $$$\text{ang}$$$. The Jury asks You to find such regular $$$n$$$-gon (regular polygon with $$$n$$$ vertices) that it has three vertices $$$a$$$, $$$b$$$ and $$$c$$$ (they can be non-consecutive) with $$$\angle{abc} = \text{ang}$$$ or report that there is no such $$$n$$$-gon. If there are several... | For each query print single integer $$$n$$$ ($$$3 \le n \le 998244353$$$) — minimal possible number of vertices in the regular $$$n$$$-gon or $$$-1$$$ if there is no such $$$n$$$. | The first line contains single integer $$$T$$$ ($$$1 \le T \le 180$$$) — the number of queries. Each of the next $$$T$$$ lines contains one integer $$$\text{ang}$$$ ($$$1 \le \text{ang} < 180$$$) — the angle measured in degrees. | standard output | standard input | PyPy 2 | Python | 1,600 | train_026.jsonl | f5192c6cb6362a8930d1960809b9dec3 | 256 megabytes | ["4\n54\n50\n2\n178"] | PASSED | L = [-1] * 181
for i in range(3, 400):
for j in range(1, i-1):
if L[180*j/i] == -1 and 180*j%i==0:
L[180*j/i] = i
T = input()
for i in range(T):
ang = input()
print L[ang] | 1546007700 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | 0c7a476716445c535a61f4e81edc7f75 | null | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$... | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | standard output | standard input | PyPy 2 | Python | 1,400 | train_006.jsonl | f6a9a72c21428dfe6a2da3f8660c20ef | 256 megabytes | ["3\n2\n4\n200"] | PASSED | import sys
import math
range = xrange
input = raw_input
t = int(input())
for _ in range(t):
n = int(input())
r = 0.5 * math.tan(math.pi*(2*n-2)/(4*n))
# r = 1/(2.0 * math.tan(math.pi / 2.0*n))
print 2*r | 1589707200 | [
"geometry",
"math"
] | [
0,
1,
0,
1,
0,
0,
0,
0
] | |
1 second | ["0 1 2 0 3", "1000 1000000000 0", "2 3 5 7 10"] | e22b10cdc33a165fbd73b45dc5fbedce | NoteThe first test was described in the problem statement.In the second test, if Alicia had an array $$$a = \{1000, 1000000000, 0\}$$$, then $$$x = \{0, 1000, 1000000000\}$$$ and $$$b = \{1000-0, 1000000000-1000, 0-1000000000\} = \{1000, 999999000, -1000000000\}$$$. | Alicia has an array, $$$a_1, a_2, \ldots, a_n$$$, of non-negative integers. For each $$$1 \leq i \leq n$$$, she has found a non-negative integer $$$x_i = max(0, a_1, \ldots, a_{i-1})$$$. Note that for $$$i=1$$$, $$$x_i = 0$$$.For example, if Alicia had the array $$$a = \{0, 1, 2, 0, 3\}$$$, then $$$x = \{0, 0, 1, 2, 2\... | Print $$$n$$$ integers, $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 10^9$$$), such that if you calculate $$$x$$$ according to the statement, $$$b_1$$$ will be equal to $$$a_1 - x_1$$$, $$$b_2$$$ will be equal to $$$a_2 - x_2$$$, ..., and $$$b_n$$$ will be equal to $$$a_n - x_n$$$. It is guaranteed that there exists... | The first line contains one integer $$$n$$$ ($$$3 \leq n \leq 200\,000$$$) – the number of elements in Alicia's array. The next line contains $$$n$$$ integers, $$$b_1, b_2, \ldots, b_n$$$ ($$$-10^9 \leq b_i \leq 10^9$$$). It is guaranteed that for the given array $$$b$$$ there is a solution $$$a_1, a_2, \ldots, a_n$$$,... | standard output | standard input | Python 3 | Python | 900 | train_010.jsonl | 3ce30269a0f9307550ac246378a6d166 | 256 megabytes | ["5\n0 1 1 -2 1", "3\n1000 999999000 -1000000000", "5\n2 1 2 2 3"] | PASSED | n = int(input())
b = str(input()).split()
x = []
a = []
for i in range(n):
b[i] = int(b[i])
if i == 0:
m = b[i]
x.append(0)
a.append(b[i])
else:
if a[i-1] > m:
m = a[i-1]
x.append(m)
a.append(b[i] + x[i])
print(a[i], end=' ') | 1584628500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["3\n3"] | e59cddb6c941b1d7556ee9c020701007 | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, ... | You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the f... | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | standard output | standard input | PyPy 2 | Python | 1,100 | train_005.jsonl | c9097d60a41b23272809a3b2b60fabb1 | 256 megabytes | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | PASSED | #import resource
import sys
#resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY])
#import threading
#threading.Thread(target=main).start()
#threading.stack_size(2**26)
#sys.setrecursionlimit(10**6)
mod=(10**9)+7
fact=[1]
#for i in range(1,100001):
# fact.append((fact[-1]*i)%mod)
#ifact=[0... | 1560090900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["35\n30\n42\n0\n0"] | f5a0dbef2aed164d83759e797569aef1 | NoteIn the first test case optimal sequence of solving problems is as follows: $$$1 \rightarrow 2$$$, after that total score is $$$5$$$ and $$$\text{IQ} = 2$$$ $$$2 \rightarrow 3$$$, after that total score is $$$10$$$ and $$$\text{IQ} = 4$$$ $$$3 \rightarrow 1$$$, after that total score is $$$20$$$ and $$$\text{IQ}... | Please note the non-standard memory limit.There are $$$n$$$ problems numbered with integers from $$$1$$$ to $$$n$$$. $$$i$$$-th problem has the complexity $$$c_i = 2^i$$$, tag $$$tag_i$$$ and score $$$s_i$$$.After solving the problem $$$i$$$ it's allowed to solve problem $$$j$$$ if and only if $$$\text{IQ} < |c_i - ... | For each test case print a single integer — the maximum number of points that can be earned. | 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 an integer $$$n$$$ $$$(1 \le n \le 5000)$$$ — the number of problems. The second line of each test case contains $$$n$$$ integers $$$tag_1, tag_2, \ldots, tag_n$$$ $$$(1 \le ... | standard output | standard input | PyPy 3-64 | Python | 2,500 | train_087.jsonl | c0b618e2fcc84f64117b21a2bff7378b | 32 megabytes | ["5\n4\n1 2 3 4\n5 10 15 20\n4\n1 2 1 2\n5 10 15 20\n4\n2 2 4 1\n2 8 19 1\n2\n1 1\n6 9\n1\n1\n666"] | PASSED | import os,sys
from random import randint, shuffle
from io import BytesIO, IOBase
from collections import defaultdict,deque,Counter
from bisect import bisect_left,bisect_right
from heapq import heappush,heappop
from functools import lru_cache
from itertools import accumulate, permutations
import math
# Fast... | 1615991700 | [
"number theory",
"graphs"
] | [
0,
0,
1,
0,
1,
0,
0,
0
] | |
2 seconds | ["...\n.L.\n...\n#++++\n..##L\n...#+\n...++\nL\n++++L++#."] | fa82a5160696616af784b5488c9f69f6 | NoteIn the first testcase there is no free cell that the robot can be forced to reach the lab from. Consider a corner cell. Given any direction, it will move to a neighbouring border grid that's not a corner. Now consider a non-corner free cell. No matter what direction you send to the robot, it can choose a different ... | There is a grid, consisting of $$$n$$$ rows and $$$m$$$ columns. Each cell of the grid is either free or blocked. One of the free cells contains a lab. All the cells beyond the borders of the grid are also blocked.A crazy robot has escaped from this lab. It is currently in some free cell of the grid. You can send one o... | For each testcase find the free cells that the robot can be forced to reach the lab from. Given the grid, replace the free cells (marked with a dot) with a plus sign ('+') for the cells that the robot can be forced to reach the lab from. Print the resulting grid. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of testcases. The first line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^6$$$; $$$n \cdot m \le 10^6$$$) — the number of rows and the number of columns in the grid. The $$$i$$$-th of the next $$$n... | standard output | standard input | PyPy 3-64 | Python | 2,000 | train_090.jsonl | fae7079d6666b2c392586d123d2db2a8 | 512 megabytes | ["4\n3 3\n...\n.L.\n...\n4 5\n#....\n..##L\n...#.\n.....\n1 1\nL\n1 9\n....L..#."] | PASSED | import sys
import os
from io import BytesIO, IOBase
from collections import deque
# region fastio
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... | 1638369300 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["2\n5\n7\n10\n26\n366580019"] | 2b15a299c25254f265cce106dffd6174 | NoteIn the fourth test case $$$n=4$$$, so $$$ans=f(1)+f(2)+f(3)+f(4)$$$. $$$1$$$ is a divisor of $$$1$$$ but $$$2$$$ isn't, so $$$2$$$ is the minimum positive integer that isn't a divisor of $$$1$$$. Thus, $$$f(1)=2$$$. $$$1$$$ and $$$2$$$ are divisors of $$$2$$$ but $$$3$$$ isn't, so $$$3$$$ is the minimum positive ... | Let $$$f(i)$$$ denote the minimum positive integer $$$x$$$ such that $$$x$$$ is not a divisor of $$$i$$$.Compute $$$\sum_{i=1}^n f(i)$$$ modulo $$$10^9+7$$$. In other words, compute $$$f(1)+f(2)+\dots+f(n)$$$ modulo $$$10^9+7$$$. | For each test case, output a single integer $$$ans$$$, where $$$ans=\sum_{i=1}^n f(i)$$$ modulo $$$10^9+7$$$. | The first line contains a single integer $$$t$$$ ($$$1\leq t\leq 10^4$$$), the number of test cases. Then $$$t$$$ cases follow. The only line of each test case contains a single integer $$$n$$$ ($$$1\leq n\leq 10^{16}$$$). | standard output | standard input | PyPy 3-64 | Python | 1,600 | train_083.jsonl | 6ea1fa4c1283422de8827dca1e9cabf9 | 256 megabytes | ["6\n1\n2\n3\n4\n10\n10000000000000000"] | PASSED | from math import gcd
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
i, smallest_divisor, ans = 1, 1, n
while n // i:
i = i * smallest_divisor // gcd(i, smallest_divisor)
ans += n // i
smallest_divisor += 1
print(ans % 1000000007)
| 1625317500 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["2\n0", "2\n0", "8"] | da11e843698b3ad997e12be2dbd0b71f | NoteConsider the first example. For the first question, the possible arrangements are "aabb" and "bbaa", and for the second question, index $$$1$$$ contains 'a' and index $$$2$$$ contains 'b' and there is no valid arrangement in which all 'a' and 'b' are in the same half. | There is a colony of villains with several holes aligned in a row, where each hole contains exactly one villain.Each colony arrangement can be expressed as a string of even length, where the $$$i$$$-th character of the string represents the type of villain in the $$$i$$$-th hole. Iron Man can destroy a colony only if t... | For each question output the number of arrangements possible modulo $$$10^9+7$$$. | The first line contains a string $$$s$$$ ($$$2 \le |s| \le 10^{5}$$$), representing the initial colony arrangement. String $$$s$$$ can have both lowercase and uppercase English letters and its length is even. The second line contains a single integer $$$q$$$ ($$$1 \le q \le 10^{5}$$$) — the number of questions. The $$$... | standard output | standard input | PyPy 3 | Python | 2,600 | train_041.jsonl | c31f7cc49264014d1cbe0de4319a71f1 | 512 megabytes | ["abba\n2\n1 4\n1 2", "AAaa\n2\n1 2\n1 3", "abcd\n1\n1 3"] | PASSED | from sys import stdin
MOD = 1000000007
s = stdin.readline().strip()
n = len(s)
buc = [0] * 101
fac = [0] * (n + 1)
inv = [0] * (n + 1)
dp = [0] * (n + 1)
# temp_dp = [0] * (n+1)
ans = [[0] * 55 for _ in range(55)]
def find(c: 'str') -> 'int':
if 'A' <= c <= 'Z':
return ord(c) - ord('A') + 26
else:
... | 1549208100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["2\n27\n1\n4\n1\n1\n2\n35\n2\n77\n1\n4\n1\n6"] | 22c0489eec3d8e290fcbcf1aeb3bb66c | NoteIn the first test case, you can't delete $$$2$$$ digits from the number $$$237$$$, as all the numbers $$$2$$$, $$$3$$$, and $$$7$$$ are prime. However, you can delete $$$1$$$ digit, obtaining a number $$$27 = 3^3$$$.In the second test case, you can delete all digits except one, as $$$4 = 2^2$$$ is a composite numbe... | During the hypnosis session, Nicholas suddenly remembered a positive integer $$$n$$$, which doesn't contain zeros in decimal notation. Soon, when he returned home, he got curious: what is the maximum number of digits that can be removed from the number so that the number becomes not prime, that is, either composite or ... | For every test case, print two numbers in two lines. In the first line print the number of digits, that you have left in the number. In the second line print the digits left after all delitions. If there are multiple solutions, print any. | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 10^3$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$k$$$ ($$$1 \le k \le 50$$$) — the number of digits in the num... | standard output | standard input | Python 3 | Python | 1,000 | train_086.jsonl | a446a743c141a3f71fab8ddb5e44397f | 256 megabytes | ["7\n3\n237\n5\n44444\n3\n221\n2\n35\n3\n773\n1\n4\n30\n626221626221626221626221626221"] | PASSED | from math import sqrt
"""
def IsPrime(n):
if n==1:
return False
elif n==2:
return True
elif n%2 ==0:
return False
else:
for i in range(3,int(sqrt(n))+1,2):
if n%i ==0:
return False
return True
"""
composite_number=("1",... | 1629988500 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["4\nB 1 1\nR 1 2\nR 2 1\nB 2 3", "5\nB 1 1\nB 1 2\nR 1 3\nD 1 2\nR 1 2"] | 9b9f6d95aecc1b6c95e5d9acca4f5453 | null | After too much playing on paper, Iahub has switched to computer games. The game he plays is called "Block Towers". It is played in a rectangular grid with n rows and m columns (it contains n × m cells). The goal of the game is to build your own city. Some cells in the grid are big holes, where Iahub can't build any bui... | Print an integer k in the first line (0 ≤ k ≤ 106) — the number of operations Iahub should perform to obtain optimal result. Each of the following k lines must contain a single operation in the following format: «B x y» (1 ≤ x ≤ n, 1 ≤ y ≤ m) — building a blue tower at the cell (x, y); «R x y» (1 ≤ x ≤ n, 1 ≤ y ≤ m)... | The first line of the input contains two integers n and m (1 ≤ n, m ≤ 500). Each of the next n lines contains m characters, describing the grid. The j-th character in the i-th line is '.' if you're allowed to build at the cell with coordinates (i, j) a tower (empty cell) or '#' if there is a big hole there. | standard output | standard input | Python 2 | Python | 1,900 | train_080.jsonl | 1e8cf7efc891351032cde7a33fcd02d5 | 256 megabytes | ["2 3\n..#\n.#.", "1 3\n..."] | PASSED | from collections import deque
def main():
n, m = [int(x) for x in raw_input().split()]
bactions, ractions = [], []
sets = [[ 1 if c == '.' else 0 for c in row] for row in [raw_input() for x in xrange(n)]]
q = deque()
qappend = q.append
qpop = q.popleft
rappend = ractions.append
bappen... | 1372941000 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["1\n1\n3"] | 0ce05499cd28f0825580ff48dae9e7a9 | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3... | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integer... | standard output | standard input | PyPy 3-64 | Python | 1,200 | train_107.jsonl | 1e418f0df1b4f6dbadc3c474b5b2cfe7 | 256 megabytes | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | PASSED | for i in range(int(input())):
n=int(input())
L=list(map(int,input().split()))
import math
L=[0]+L
cnt =0
for i in range(1,n+1):
for j in range(L[i]-i,n+1,L[i]):
if(L[i]*L[j])==(i+j) and (j>i):
cnt+=1
print(cnt) | 1624635300 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["1.0000000000 2.0000000000\n2.0000000000 0.0000000000", "2.8819000000 0.0000000000\n4.1470000000 1.6168000000\n3.7953000000 4.1470000000\n0.9134000000 4.1470000000\n0.0000000000 2.1785000000\n0.7034000000 0.0000000000"] | d00b8423c3c52b19fec25bc63e4d4c1c | null | Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose lower left corner is located at point with coordinates (0, 0) and the length of the side equals a meters. The sides of the square are parallel to coordinate axes.As the length of the... | Print n lines, each line should contain two real numbers xi and yi, separated by a space. Numbers xi and yi in the i-th line mean that Valera is at point with coordinates (xi, yi) after he covers i·d meters. Your solution will be considered correct if the absolute or relative error doesn't exceed 10 - 4. Note, that thi... | The first line contains two space-separated real numbers a and d (1 ≤ a, d ≤ 105), given with precision till 4 decimal digits after the decimal point. Number a denotes the length of the square's side that describes the stadium. Number d shows that after each d meters Valera gets an extra drink. The second line contains... | standard output | standard input | Python 3 | Python | 1,500 | train_021.jsonl | 96e0437a48895f65afb3976f2a46364e | 256 megabytes | ["2 5\n2", "4.147 2.8819\n6"] | PASSED | a, d = [float(el) for el in input().split()]
n = int(input())
for i in range(1, n+1):
k = i*d % (4*a)
m = k // a
if m == 0:
x, y = k % a, 0
elif m == 1:
x, y = a , k % a
elif m == 2:
x, y = a - k % a, a
elif m == 3:
x, y = 0, a - k % a
print('%s %s' % (x, y... | 1395243000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["ALICE\nBOB\nALICE"] | aef15a076b04e510e663a41341c8d156 | NoteIn the first test case of example, in the $$$1$$$-st move, Alice will use the $$$2$$$-nd operation to reverse the string, since doing the $$$1$$$-st operation will result in her loss anyway. This also forces Bob to use the $$$1$$$-st operation. in the $$$2$$$-nd move, Bob has to perform the $$$1$$$-st operation,... | The only difference between the easy and hard versions is that the given string $$$s$$$ in the easy version is initially a palindrome, this condition is not always true for the hard version.A palindrome is a string that reads the same left to right and right to left. For example, "101101" is a palindrome, while "0101" ... | For each test case print a single word in a new line: "ALICE", if Alice will win the game, "BOB", if Bob will win the game, "DRAW", if the game ends in a draw. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^3$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^3$$$). The second line of each test case contains the string $$$s$$$ of length $$$n$$$, consisting of the characters '0' and '1... | standard output | standard input | PyPy 3-64 | Python | 1,900 | train_085.jsonl | 91c8c89dec2af98e5131378a2c031d29 | 256 megabytes | ["3\n3\n110\n2\n00\n4\n1010"] | PASSED | import os,sys
from random import randint
from io import BytesIO, IOBase
from collections import defaultdict,deque,Counter
from bisect import bisect_left,bisect_right
from heapq import heappush,heappop
from functools import lru_cache
from itertools import accumulate
import math
# Fast IO Region
BUFSIZE = 8... | 1621521300 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
1 second | ["24", "2835", "0", "46"] | 45d8827bfee3afeeed79741a2c3b0a0f | NoteIn the first example, we can obtain $$$9$$$ strings: "acabac" — there are $$$2$$$ subsequences "abc", "acabbc" — there are $$$4$$$ subsequences "abc", "acabcc" — there are $$$4$$$ subsequences "abc", "acbbac" — there are $$$2$$$ subsequences "abc", "acbbbc" — there are $$$3$$$ subsequences "abc", "acbbcc" — t... | You are given a string $$$s$$$ consisting of lowercase Latin letters "a", "b" and "c" and question marks "?".Let the number of question marks in the string $$$s$$$ be $$$k$$$. Let's replace each question mark with one of the letters "a", "b" and "c". Here we can obtain all $$$3^{k}$$$ possible strings consisting only o... | Print the total number of subsequences "abc" in all strings you can obtain if you replace all question marks with letters "a", "b" and "c", modulo $$$10^{9} + 7$$$. | The first line of the input contains one integer $$$n$$$ $$$(3 \le n \le 200\,000)$$$ — the length of $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$ consisting of lowercase Latin letters "a", "b" and "c" and question marks"?". | standard output | standard input | PyPy 3 | Python | 2,000 | train_009.jsonl | 4e5adc354e27acba72d7110f0b62d8f7 | 256 megabytes | ["6\nac?b?c", "7\n???????", "9\ncccbbbaaa", "5\na???c"] | PASSED | #matthew's bad code
import re
import sys
MOD = 1000000007
# string s of length n
n = input()
s = input()
# number of a sequences, ab sequences, and abc sequences in s
# sets is the total number of distinct sets generated
# e.g. {a, ?, b} branches into three sets {a, a, b}; {a, b, b}; {a, c, b}
num_a = 0
num_ab = 0
n... | 1601280300 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
5 seconds | ["2 1 8 7"] | e01cf98c203b8845312ce30af70d3f2e | NoteLet d(x, y) be the shortest distance between cities x and y. Then in the example d(2, 1) = 3, d(1, 8) = 7, d(8, 7) = 3. The total distance equals 13. | A famous sculptor Cicasso goes to a world tour!Well, it is not actually a world-wide. But not everyone should have the opportunity to see works of sculptor, shouldn't he? Otherwise there will be no any exclusivity. So Cicasso will entirely hold the world tour in his native country — Berland.Cicasso is very devoted to h... | Print four integers — numbers of cities which Cicasso will visit according to optimal choice of the route. Numbers of cities should be printed in the order that Cicasso will visit them. If there are multiple solutions, print any of them. | In the first line there is a pair of integers n and m (4 ≤ n ≤ 3000, 3 ≤ m ≤ 5000) — a number of cities and one-way roads in Berland. Each of the next m lines contains a pair of integers ui, vi (1 ≤ ui, vi ≤ n) — a one-way road from the city ui to the city vi. Note that ui and vi are not required to be distinct. Moreov... | standard output | standard input | PyPy 2 | Python | 2,000 | train_049.jsonl | c92be19baf6f31ad8ad811e1c0efc3ec | 512 megabytes | ["8 9\n1 2\n2 3\n3 4\n4 1\n4 5\n5 6\n6 7\n7 8\n8 5"] | PASSED | #!/usr/bin/env python
from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
from heapq import heappop, heappush
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
INF = float('inf')
... | 1461947700 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["Ashish", "Ayush"] | 1a93a35395436f9e15760400f991f1ce | NoteFor the $$$1$$$st test case, Ayush can only remove node $$$2$$$ or $$$3$$$, after which node $$$1$$$ becomes a leaf node and Ashish can remove it in his turn.For the $$$2$$$nd test case, Ayush can remove node $$$2$$$ in the first move itself. | Ayush and Ashish play a game on an unrooted tree consisting of $$$n$$$ nodes numbered $$$1$$$ to $$$n$$$. Players make the following move in turns: Select any leaf node in the tree and remove it together with any edge which has this node as one of its endpoints. A leaf node is a node with degree less than or equal to... | For every test case, if Ayush wins the game, print "Ayush", otherwise print "Ashish" (without quotes). | The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10)$$$ — the number of testcases. The description of the test cases follows. The first line of each testcase contains two integers $$$n$$$ and $$$x$$$ $$$(1\leq n \leq 1000, 1 \leq x \leq n)$$$ — the number of nodes in the tree and the spec... | standard output | standard input | PyPy 3 | Python | 1,600 | train_001.jsonl | 8aaad8ff047fc842aab1c7fb021a1a4a | 256 megabytes | ["1\n3 1\n2 1\n3 1", "1\n3 2\n1 2\n1 3"] | PASSED | import sys
input = sys.stdin.readline
Q = int(input())
Query = []
for _ in range(Q):
N, X = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(N-1):
a, b = map(int, input().split())
graph[a-1].append(b-1)
graph[b-1].append(a-1)
Query.append((N, X-1, graph))
... | 1590935700 | [
"games",
"trees"
] | [
1,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["2\n1\n1\n2\n99999999\n3\n0\n1\n9"] | be27a43c6844575f1d17487e564803bb | NoteThe first sample is parsed in statement.One of the optimal schedule changes for the second sample: Initial schedule. New schedule.In the third sample, we need to move the exam from day $$$1$$$ to any day from $$$4$$$ to $$$100$$$.In the fourth sample, any change in the schedule will only reduce $$$\mu$$$, so the... | Now Dmitry has a session, and he has to pass $$$n$$$ exams. The session starts on day $$$1$$$ and lasts $$$d$$$ days. The $$$i$$$th exam will take place on the day of $$$a_i$$$ ($$$1 \le a_i \le d$$$), all $$$a_i$$$ — are different. Sample, where $$$n=3$$$, $$$d=12$$$, $$$a=[3,5,9]$$$. Orange — exam days. Before the... | For each test case, output the maximum possible value of $$$\mu$$$ if Dmitry can move any one exam to an arbitrary day. All values of $$$a_i$$$ should remain distinct. | The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of input test cases. The descriptions of test cases follow. An empty line is written in the test before each case. The first line of each test case contains two integers $$$n$$$ and $$$d$$$ ($$$2 \le n \le 2 \cdot 10^5, 1 \le... | standard output | standard input | PyPy 3 | Python | 1,900 | train_104.jsonl | 5834036883962d4542ded40183d3a599 | 256 megabytes | ["9\n\n\n\n\n3 12\n\n3 5 9\n\n\n\n\n2 5\n\n1 5\n\n\n\n\n2 100\n\n1 2\n\n\n\n\n5 15\n\n3 6 9 12 15\n\n\n\n\n3 1000000000\n\n1 400000000 500000000\n\n\n\n\n2 10\n\n3 4\n\n\n\n\n2 2\n\n1 2\n\n\n\n\n4 15\n\n6 11 12 13\n\n\n\n\n2 20\n\n17 20"] | PASSED | import io,os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def main(t):
s = input()
n,d = map(int,input().split())
arr = [0]+list(map(int,input().split()))
distance = [arr[i+1]-arr[i]-1 for i in range(n)]
minleft = [0]*(n+1)
maxleft = [0]... | 1646750100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["8", "4"] | 5ff4275de91b65115666d4a98b9f3b8b | null | Dima loves Inna very much. He decided to write a song for her. Dima has a magic guitar with n strings and m frets. Dima makes the guitar produce sounds like that: to play a note, he needs to hold one of the strings on one of the frets and then pull the string. When Dima pulls the i-th string holding it on the j-th fret... | In a single line print a single number — the maximum possible complexity of the song. | The first line of the input contains four integers n, m, k and s (1 ≤ n, m ≤ 2000, 1 ≤ k ≤ 9, 2 ≤ s ≤ 105). Then follow n lines, each containing m integers aij (1 ≤ aij ≤ k). The number in the i-th row and the j-th column (aij) means a note that the guitar produces on the i-th string and the j-th fret. The last line o... | standard output | standard input | PyPy 3 | Python | 2,200 | train_038.jsonl | 195ce812518164c2ce2c8ad085d61c45 | 256 megabytes | ["4 6 5 7\n3 1 2 2 3 1\n3 2 2 2 5 5\n4 2 2 2 5 3\n3 2 2 1 4 3\n2 3 1 4 1 5 1", "4 4 9 5\n4 7 9 5\n1 2 1 7\n8 3 4 9\n5 7 7 2\n7 1 9 2 5"] | PASSED | def solution() : # 最大的距离来自于角落附近的点
n,m,k,s = map(int, input().split())
dis = lambda a,b : abs(a[0] - b[0]) + abs(a[1] - b[1])
corner = [(0,0), (0,m-1), (n-1,0), (n-1,m-1)]
vertex = [[(n,m), (n,-1), (-1,m), (-1,-1)] for _ in range(k+1)]
for i in range(n) :
for j,note in enumerate(map(int, input().split())) :
ve... | 1385307000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["YES\n2\n1 3 \nNO", "YES\n8\n1 3 4 5 6 9 14 17"] | d4e1ec5445de029895a9c47ab89db3a2 | NoteThe picture below shows the second example test. | Students of Winter Informatics School are going to live in a set of houses connected by underground passages. Teachers are also going to live in some of these houses, but they can not be accommodated randomly. For safety reasons, the following must hold: All passages between two houses will be closed, if there are no ... | For each test case, if there is no way to choose the desired set of houses, output "NO". Otherwise, output "YES", then the total number of houses chosen, and then the indices of the chosen houses in arbitrary order. | The first input line contains a single integer $$$t$$$ — the number of test cases ($$$1 \le t \le 10^5$$$). Each test case starts with two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 3 \cdot 10^5$$$, $$$0 \le m \le 3 \cdot 10^5$$$) — the number of houses and the number of passages. Then $$$m$$$ lines follow, each of ... | standard output | standard input | PyPy 3-64 | Python | 2,200 | train_084.jsonl | 2e4c2d76cda0fd311bdc5dccdb3cc28d | 256 megabytes | ["2\n3 2\n3 2\n2 1\n4 2\n1 4\n2 3", "1\n17 27\n1 8\n2 9\n3 10\n4 11\n5 12\n6 13\n7 14\n8 9\n8 14\n8 15\n9 10\n9 15\n10 11\n10 15\n10 17\n11 12\n11 17\n12 13\n12 16\n12 17\n13 14\n13 16\n14 16\n14 15\n15 16\n15 17\n16 17"] | PASSED | import sys
input=sys.stdin.buffer.readline
t=int(input())
for _ in range(t):
n,m=map(int,input().split())
g=[[] for i in range(n+1)]
for __ in range(m):
u,v=map(int,input().split())
g[u].append(v)
g[v].append(u)
black=[-1 for i in range(n+1)]
ans=[]
path=[1]
... | 1609857300 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["NO", "YES"] | 8ea24f3339b2ec67a769243dc68a47b2 | null | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | The first line contains a positive integer n (1 ≤ n ≤ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 ≤ xi, yi, zi ≤ 100). | standard output | standard input | Python 3 | Python | 1,000 | train_001.jsonl | 07edbc8ad40aed7fb09604d5456befb9 | 256 megabytes | ["3\n4 1 7\n-2 4 -1\n1 -5 -3", "3\n3 -1 7\n-5 2 -4\n2 -1 -3"] | PASSED | n=int(input())
a=[]
for i in range(n):
a.append(list(map(int,input().split())))
c=0
for j in range(3):
s=0
for k in range(n):
s=s+a[k][j]
if s==0:
c+=1
if c==3:
print("YES")
else:
print("NO")
| 1300809600 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["4\n4\n3\n5\n3"] | c0d23fe28ebddbfc960674e3b10122ad | NoteIn the first test case, $$$S=\{0,1,3,4\}$$$, $$$a=\operatorname{mex}(S)=2$$$, $$$b=\max(S)=4$$$, $$$\lceil\frac{a+b}{2}\rceil=3$$$. So $$$3$$$ is added into $$$S$$$, and $$$S$$$ becomes $$$\{0,1,3,3,4\}$$$. The answer is $$$4$$$.In the second test case, $$$S=\{0,1,4\}$$$, $$$a=\operatorname{mex}(S)=2$$$, $$$b=\max(... | You are given a multiset $$$S$$$ initially consisting of $$$n$$$ distinct non-negative integers. A multiset is a set, that can contain some elements multiple times.You will perform the following operation $$$k$$$ times: Add the element $$$\lceil\frac{a+b}{2}\rceil$$$ (rounded up) into $$$S$$$, where $$$a = \operatorn... | For each test case, print the number of distinct elements in $$$S$$$ after $$$k$$$ operations will be done. | 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 contains two integers $$$n$$$, $$$k$$$ ($$$1\le n\le 10^5$$$, $$$0\le k\le 10^9$$$) — the initial size... | standard output | standard input | PyPy 3 | Python | 1,100 | train_104.jsonl | f2791a6ebff39aa743b4272f6457cc43 | 256 megabytes | ["5\n4 1\n0 1 3 4\n3 1\n0 1 4\n3 0\n0 1 4\n3 2\n0 1 2\n3 2\n1 2 3"] | PASSED | def ceil(a,b):
return ((a+b-1)//b)
for _ in range(int(input())):
n,k = map(int,input().split())
a = set(map(int,input().split()))
if k==0:
print(len(a))
continue
maxi = max(a)
for i in range(maxi+2):
if i not in a:
mex = i
break
le... | 1615377900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["9", "8"] | 13fa378c913bb7a15612327099b59f83 | null | Ahmed and Mostafa used to compete together in many programming contests for several years. Their coach Fegla asked them to solve one challenging problem, of course Ahmed was able to solve it but Mostafa couldn't.This problem is similar to a standard problem but it has a different format and constraints.In the standard ... | Print one line containing the maximum sum in the big array after formatting it as described above. You must choose at least one element for the sum, i. e. it cannot be empty. Please, do not use %lld specificator to write 64-bit integers in C++. It is preferred to use cout (also you may use %I64d). | The first line contains two integers n and m, n is the number of the small arrays (1 ≤ n ≤ 50), and m is the number of indexes in the big array (1 ≤ m ≤ 250000). Then follow n lines, the i-th line starts with one integer l which is the size of the i-th array (1 ≤ l ≤ 5000), followed by l integers each one will be great... | standard output | standard input | Python 2 | Python | 2,000 | train_009.jsonl | c25a96faa49e3e48658225110b010057 | 256 megabytes | ["3 4\n3 1 6 -2\n2 3 3\n2 -5 1\n2 3 1 3", "6 1\n4 0 8 -3 -10\n8 3 -2 -5 10 8 -9 -5 -4\n1 0\n1 -3\n3 -8 5 6\n2 9 6\n1"] | PASSED | (n , m) = map(int,raw_input().split())
arr = []
for i in range (n):
arr.append(map(int,raw_input().split())[1:])
seq = map(int,raw_input().split())
def gao(x):
ans = - 2 ** 64
now = 0
for i in range (len(x)):
now += x[i]
ans = max(ans,now)
return ans;
def gao2(x):
now = x[0]
... | 1302706800 | [
"math",
"trees"
] | [
0,
0,
0,
1,
0,
0,
0,
1
] | |
1 second | ["? 4\n0 0\n2 0\n2 3\n0 3\n\n? 4\n0 0\n0 1\n3 1\n3 0\n\n! 1.5 0.5"] | 7921be2d165d9430cedfeadb6e934314 | NoteIn the first test from the statement, the aliens poisoned a square of corn with vertices at points with coordinates $$$(1.5, 0.5)$$$, $$$(1.5, 1.5)$$$, $$$(2.5, 1.5)$$$, $$$(2.5, 0.5)$$$. In the picture, it is red, the polygon selected in the query is blue, and their intersection is green.Picture for the first quer... | This is an interactive problem.Farmer Stanley grows corn on a rectangular field of size $$$ n \times m $$$ meters with corners in points $$$(0, 0)$$$, $$$(0, m)$$$, $$$(n, 0)$$$, $$$(n, m)$$$. This year the harvest was plentiful and corn covered the whole field.The night before harvest aliens arrived and poisoned the c... | null | First line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 100$$$) — field sizes. | standard output | standard input | PyPy 3 | Python | 2,700 | train_082.jsonl | e9d757e6b2150cb1dfe0773e0ad444bb | 256 megabytes | ["3 3\n\n\n\n\n\n0.5\n\n\n\n\n\n0.5"] | PASSED | MIN = '0.000000000000001';n,m=[int(i) for i in input().split()]; print(f'? {2*m+1}',flush=True);print(0,0);
for i in range(m):
print(n,i,flush=True);print(MIN,i+1,flush=True)
hx=float(input());print(f'? {2*n+1}',flush=True);print(0,0)
for i in range(n):
print(i,m,flush=True);print(i+1,MIN,flush=True)
hy =... | 1661006100 | [
"geometry",
"math"
] | [
0,
1,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["First", "Second"] | bbf2dbdea6dd3aa45250ab5a86833558 | null | The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player befor... | In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes. | The input contains a single line, containing string s (1 ≤ |s| ≤ 103). String s consists of lowercase English letters. | standard output | standard input | Python 2 | Python | 1,300 | train_000.jsonl | d696f88cccde2107b2e4aa60d7554307 | 256 megabytes | ["aba", "abca"] | PASSED | s = raw_input()
t = sum( s.count(x)&1 for x in set(s) )
print 'First' if t&1 or t==0 else 'Second'
| 1361719800 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["3\n1\n0"] | adf4239de3b0034cc690dad6160cf1d0 | NoteThe picture shows the lines from the first test case of the example. Black circles denote intersection points with integer coordinates. | DLS and JLS are bored with a Math lesson. In order to entertain themselves, DLS took a sheet of paper and drew $$$n$$$ distinct lines, given by equations $$$y = x + p_i$$$ for some distinct $$$p_1, p_2, \ldots, p_n$$$.Then JLS drew on the same paper sheet $$$m$$$ distinct lines given by equations $$$y = -x + q_i$$$ for... | For each test case in the input print a single integer — the number of line pairs with integer intersection points. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$), the number of test cases in the input. Then follow the test case descriptions. The first line of a test case contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$), the number of lines drawn by DLS. The second line of a test case contains $$$n$$$ disti... | standard output | standard input | Python 3 | Python | 1,000 | train_015.jsonl | 8da0efa55f63ae2fa4ac0a6cef3fffed | 512 megabytes | ["3\n3\n1 3 2\n2\n0 3\n1\n1\n1\n1\n1\n2\n1\n1"] | PASSED | t = int(input())
for i in range(t):
z1=0
f1=0
z2=0
f2=0
s=0
n = int(input())
p = [int(z) for z in input().split(' ')]
m = int(input())
q = [int(z) for z in input().split(' ')]
for j in range(n):
if p[j] % 2 == 0:
z1=z1+1
else:
f1=f1+1
f... | 1571562300 | [
"geometry",
"math"
] | [
0,
1,
0,
1,
0,
0,
0,
0
] | |
4 seconds | ["-31", "1992"] | 6d4e18987326dbb0ef69cd6756965835 | null | A festival will be held in a town's main street. There are n sections in the main street. The sections are numbered 1 through n from left to right. The distance between each adjacent sections is 1.In the festival m fireworks will be launched. The i-th (1 ≤ i ≤ m) launching is on time ti at section ai. If you are at sec... | Print a single integer — the maximum sum of happiness that you can gain from watching all the fireworks. Please, do not write the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | The first line contains three integers n, m, d (1 ≤ n ≤ 150000; 1 ≤ m ≤ 300; 1 ≤ d ≤ n). Each of the next m lines contains integers ai, bi, ti (1 ≤ ai ≤ n; 1 ≤ bi ≤ 109; 1 ≤ ti ≤ 109). The i-th line contains description of the i-th launching. It is guaranteed that the condition ti ≤ ti + 1 (1 ≤ i < m) will be satisf... | standard output | standard input | PyPy 3 | Python | 2,100 | train_012.jsonl | aac7bb81a00dce4b5c5ed985816ade48 | 256 megabytes | ["50 3 1\n49 1 1\n26 1 4\n6 1 10", "10 2 1\n1 1000 4\n9 1000 4"] | PASSED | class SortedList(list):
def add(self, other):
left = -1
right = len(self)
while right - left > 1:
mid = (right + left) >> 1
if other < self[mid]:
right = mid
else:
left = mid
super().insert(right, other)
INF = int... | 1386943200 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["0 0 0 0", "0 0 0 1 1 2"] | 2d4dbada60ebcf0bdaead8d0c1c0e2c1 | null | A subway scheme, classic for all Berland cities is represented by a set of n stations connected by n passages, each of which connects exactly two stations and does not pass through any others. Besides, in the classic scheme one can get from any station to any other one along the passages. The passages can be used to mo... | Print n numbers. Separate the numbers by spaces, the i-th one should be equal to the distance of the i-th station from the ringroad. For the ringroad stations print number 0. | The first line contains an integer n (3 ≤ n ≤ 3000), n is the number of stations (and trains at the same time) in the subway scheme. Then n lines contain descriptions of the trains, one per line. Each line contains a pair of integers xi, yi (1 ≤ xi, yi ≤ n) and represents the presence of a passage from station xi to st... | standard output | standard input | Python 2 | Python | 1,600 | train_012.jsonl | c1e3ebc8b09d7e1cda084b13f5b22546 | 256 megabytes | ["4\n1 3\n4 3\n4 2\n1 2", "6\n1 2\n3 4\n6 4\n2 3\n1 3\n3 5"] | PASSED | from collections import deque
import copy
def bfs(g,root):
Q = deque([root])
visited = [root]
while len(Q) > 0:
v = Q.pop()
for x in g[v]:
if x not in visited and len(g[x]) < 3:
Q.appendleft(x)
visited.append(x)
return visited
def remove(g,ver... | 1322233200 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["8", "28", "0"] | 03907ca0d34a2c80942ed3968b2c067d | NoteIn the first example, the transformations are $$$2 \rightarrow 4 \rightarrow (-2) \rightarrow (-4) \rightarrow 2$$$.In the third example, it is impossible to perform even a single transformation. | You are given a positive integer $$$n$$$ greater or equal to $$$2$$$. For every pair of integers $$$a$$$ and $$$b$$$ ($$$2 \le |a|, |b| \le n$$$), you can transform $$$a$$$ into $$$b$$$ if and only if there exists an integer $$$x$$$ such that $$$1 < |x|$$$ and ($$$a \cdot x = b$$$ or $$$b \cdot x = a$$$), where $$$|... | Print an only integer — the maximum score that can be achieved with the transformations. If it is not possible to perform even a single transformation for all possible starting integers, print $$$0$$$. | A single line contains a single integer $$$n$$$ ($$$2 \le n \le 100\,000$$$) — the given integer described above. | standard output | standard input | Python 3 | Python | 1,800 | train_043.jsonl | 49655470591f72f2fc46c4acdde38e74 | 256 megabytes | ["4", "6", "2"] | PASSED | class IntegersFun():
def __init__(self, n):
self.n = n
def get_value(self):
sm = 0
for i in range(2,self.n+1):
for j in range(2*i, self.n+1, i):
sm += 4*j/i
return int(sm)
n = int(input())
print(IntegersFun(n).get_value()) | 1542209700 | [
"math",
"graphs"
] | [
0,
0,
1,
1,
0,
0,
0,
0
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.