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 | ["4 5 9 13 18", "10 11 12 13 14 15 16 17", "-1"] | b8c440664f8073d3e273878b0ca1e810 | NoteIn the first example, there are $$$3$$$ triples $$$(i, j, k)$$$ that contribute to the balance of the score distribution. $$$(1, 2, 3)$$$ $$$(1, 3, 4)$$$ $$$(2, 4, 5)$$$ | Kuroni is the coordinator of the next Mathforces round written by the "Proof by AC" team. All the preparation has been done, and he is discussing with the team about the score distribution for the round.The round consists of $$$n$$$ problems, numbered from $$$1$$$ to $$$n$$$. The problems are ordered in increasing orde... | If there is no solution, print a single integer $$$-1$$$. Otherwise, print a line containing $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, representing a score distribution that satisfies all the requirements. If there are multiple answers, print any of them. | The first and single line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 5000$$$, $$$0 \leq m \leq 10^9$$$)Β β the number of problems and the required balance. | standard output | standard input | Python 3 | Python | 2,200 | train_075.jsonl | f989312c23fe7001d6dfd1a1a53b1167 | 256 megabytes | ["5 3", "8 0", "4 10"] | PASSED | def main():
n, m = map(int, input().split())
x = []
i = 1
while (n > 0 and m >= len(x) // 2):
m -= len(x) // 2
n -= 1
x.append(i)
i += 1
k = i - 1
if (m == 0 and n == 0):
print(*x)
return
elif (n == 0):
print(-1)
return
else... | 1583246100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1\n......\n.X.XX.\n......", "2\n..........\n..........\n...XX.....\n..........\n..........\n..........\n.....XX...\n..........\n..........\n..........", "0\nX....\n..XXX\n..XXX\n..XXX"] | 9602fa7b9d05560959ee5fdeeb1f6507 | null | The Berland Forest can be represented as an infinite cell plane. Every cell contains a tree. That is, contained before the recent events.A destructive fire raged through the Forest, and several trees were damaged by it. Precisely speaking, you have a $$$n \times m$$$ rectangle map which represents the damaged part of t... | In the first line print the single integer $$$T$$$ β the maximum time the Forest was on fire. In the next $$$n$$$ lines print the certificate: the map ($$$n \times m$$$ rectangle) where the trees that were set on fire are marked as "X" and all other trees are marked as ".". | The first line contains two integer $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^6$$$, $$$1 \le n \cdot m \le 10^6$$$) β the sizes of the map. Next $$$n$$$ lines contain the map. The $$$i$$$-th line corresponds to the $$$i$$$-th row of the map and contains $$$m$$$-character string. The $$$j$$$-th character of the $$$i$$$-... | standard output | standard input | PyPy 3 | Python | 2,200 | train_067.jsonl | 6ab4bf3de7c1e5d4fee2159522fbe4b7 | 512 megabytes | ["3 6\nXXXXXX\nXXXXXX\nXXXXXX", "10 10\n.XXXXXX...\n.XXXXXX...\n.XXXXXX...\n.XXXXXX...\n.XXXXXXXX.\n...XXXXXX.\n...XXXXXX.\n...XXXXXX.\n...XXXXXX.\n..........", "4 5\nX....\n..XXX\n..XXX\n..XXX"] | PASSED | import sys
input = lambda:sys.stdin.readline().rstrip()
h,w=map(int,input().split())
d=w+2
b=[0]*(w+2)
for i in range(h):
b+=([0]+[int(j=="X") for j in input()]+[0])
b+=([0]*(w+2))
co=sum(b)
t=10**10
for i in range(1,h+1):
f=0
for j in range(w+2):
f+=b[i*d+j]
if b[i*d+j]==0 and f:
t=min(t,(f-1)//2)... | 1574582700 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["YES\nNO", "NO\nYES\nNO\nYES"] | c6633581d7424d670eaa0f8a5c8cc366 | NoteIn the first example we can replace "?" with good letters "a" and "b", so we can see that the answer for the first query is "YES", and the answer for the second query is "NO", because we can't match the third letter.Explanation of the second example. The first query: "NO", because character "*" can be replaced wi... | It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one..There is a glob pattern in the statements (a string consisting of lowercase English letters, characters "?" and "*"). It is known... | Print n lines: in the i-th of them print "YES" if the pattern matches the i-th query string, and "NO" otherwise. You can choose the case (lower or upper) for each letter arbitrary. | The first line contains a string with length from 1 to 26 consisting of distinct lowercase English letters. These letters are good letters, all the others are bad. The second line contains the patternΒ β a string s of lowercase English letters, characters "?" and "*" (1ββ€β|s|ββ€β105). It is guaranteed that character "*" ... | standard output | standard input | Python 2 | Python | 1,600 | train_002.jsonl | 1ccf82b55190a55c7d8c939691ba149d | 256 megabytes | ["ab\na?a\n2\naaa\naab", "abc\na?a?a*\n4\nabacaba\nabaca\napapa\naaaaax"] | PASSED |
def check(g1,g2,s,star):
for idx,char in enumerate(g1):
if char==s[idx]:
continue
elif char=='?':
if alpha[ord(s[idx])-97]==1:
continue
else:
return "NO"
else:
return "NO"
ss=s[::-1]
for idx,char in enu... | 1500906900 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["8", "10"] | 13574507efa5089f3420cf002c3f8077 | NoteIn the first sample, the optimal labeling gives 8 different subsequences: "" (the empty string), "a", "c", "b", "ac", "ab", "cb", and "acb". In the second sample, the entire sidewalk is already labeled. The are 10 possible different subsequences: "" (the empty string), "a", "b", "aa", "ab", "ba", "aaa", "aab", "ab... | After getting kicked out of her reporting job for not knowing the alphabet, Bessie has decided to attend school at the Fillet and Eggs Eater Academy. She has been making good progress with her studies and now knows the first k English letters.Each morning, Bessie travels to school along a sidewalk consisting of mβ+βn t... | Determine the maximum number of distinct subsequences Bessie can form after labeling the last n sidewalk tiles each with one of the first k lowercase English letters. Since this number can be rather large, you should print it modulo 109β+β7. Please note, that you are not asked to maximize the remainder modulo 109β+β7! ... | The first line of the input contains two integers n and k (0ββ€βnββ€β1β000β000, 1ββ€βkββ€β26). The second line contains a string t (|t|β=βm,β1ββ€βmββ€β1β000β000) consisting of only first k lowercase English letters. | standard output | standard input | PyPy 2 | Python | 2,200 | train_037.jsonl | eea3af4b392f7a80448d73b36a242770 | 256 megabytes | ["1 3\nac", "0 2\naaba"] | PASSED | #
# http://codeforces.com/problemset/problem/655/E
MOD = 10 ** 9 + 7
def read_ints():
return map(int, raw_input().split())
N, K = read_ints()
counts, indexes = [0] * K, [-1] * K
count = 1
for i, c in enumerate(raw_input()):
c = ord(c) - ord('a')
counts[c], count, indexes[c] = count, (2 * count - counts... | 1458318900 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["3", "8", "-1"] | bc93c89cf41c8e44584045ac52b9acc6 | NoteIn the first sample Olya should run 3 meters to the right in the first second, 2 meters down in the second second and 3 meters to the left in the third second.In second sample Olya should run to the right for 3 seconds, then down for 2 seconds and then to the left for 3 seconds.Olya does not recommend drinking ener... | Olya loves energy drinks. She loves them so much that her room is full of empty cans from energy drinks.Formally, her room can be represented as a field of nβΓβm cells, each cell of which is empty or littered with cans.Olya drank a lot of energy drink, so now she can run k meters per second. Each second she chooses one... | Print a single integer β the minimum time it will take Olya to get from (x1,βy1) to (x2,βy2). If it's impossible to get from (x1,βy1) to (x2,βy2), print -1. | The first line contains three integers n, m and k (1ββ€βn,βm,βkββ€β1000) β the sizes of the room and Olya's speed. Then n lines follow containing m characters each, the i-th of them contains on j-th position "#", if the cell (i,βj) is littered with cans, and "." otherwise. The last line contains four integers x1,βy1,βx2,... | standard output | standard input | PyPy 2 | Python | 2,100 | train_003.jsonl | 11795e61c46fbd7c96ba6a38cddb554b | 256 megabytes | ["3 4 4\n....\n###.\n....\n1 1 3 1", "3 4 1\n....\n###.\n....\n1 1 3 1", "2 2 1\n.#\n#.\n1 1 2 2"] | PASSED | from sys import *
f = lambda: map(int,raw_input().split())
n, m, k = f()
t = [[1e9 * (q == '.') for q in stdin.readline()] for i in range(n)]
t.append([0] * m)
a, b, c, d = [q - 1 for q in f()]
u = [(a, b)]
t[a][b] = l = 0
def g(i, x, y):
if i > k or t[x][y] < l: return 0
if t[x][y] > l:
t[x][y] = l
... | 1508773500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["aaaaa", ":(", "ababacac", ":("] | b5bcb6d78daacd56362fd76e35b903ac | NoteIn the first example, we have $$$s = $$$ "aaaaa", and $$$s' = $$$ "".In the second example, no such $$$s$$$ can work that will generate the given $$$t$$$.In the third example, we have $$$s = $$$ "ababacac", and $$$s' = $$$ "bbcc", and $$$t = s + s' = $$$ "ababacacbbcc". | Bob has a string $$$s$$$ consisting of lowercase English letters. He defines $$$s'$$$ to be the string after removing all "a" characters from $$$s$$$ (keeping all other characters in the same order). He then generates a new string $$$t$$$ by concatenating $$$s$$$ and $$$s'$$$. In other words, $$$t=s+s'$$$ (look at note... | Print a string $$$s$$$ that could have generated $$$t$$$. It can be shown if an answer exists, it is unique. If no string exists, print ":(" (without double quotes, there is no space between the characters). | The first line of input contains a string $$$t$$$ ($$$1 \leq |t| \leq 10^5$$$) consisting of lowercase English letters. | standard output | standard input | Python 3 | Python | 1,100 | train_019.jsonl | 60c369d078d2239e0bb1331ab3a79f74 | 256 megabytes | ["aaaaa", "aacaababc", "ababacacbbcc", "baba"] | PASSED | s = input()
import re
r = re.sub('a','',s)
if r == 2*r[:len(r)//2] and (s[-len(r)//2:].count('a') == 0 or r == ''):
print(s[:len(s)-len(r)//2])
else: print(':(') | 1555783500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["a\nabcdfdcba\nxyzyx\nc\nabba"] | beaccd2c0213a330538fe741d1f4b5bf | NoteIn the first test, the string $$$s = $$$"a" satisfies all conditions.In the second test, the string "abcdfdcba" satisfies all conditions, because: Its length is $$$9$$$, which does not exceed the length of the string $$$s$$$, which equals $$$11$$$. It is a palindrome. "abcdfdcba" $$$=$$$ "abcdfdc" $$$+$$$ "ba", ... | This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.You are given a string $$$s$$$, consisting of lowercase English letters. Find the longest string, $$$t$$$, which satisfi... | For each test case, print the longest string which satisfies the conditions described above. If there exists multiple possible solutions, print any of them. | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$), the number of test cases. The next $$$t$$$ lines each describe a test case. Each test case is a non-empty string $$$s$$$, consisting of lowercase English letters. It is guaranteed that the sum of leng... | standard output | standard input | Python 3 | Python | 1,800 | train_014.jsonl | 52285b8521d672b951c513d14d9f3570 | 256 megabytes | ["5\na\nabcdfdcecba\nabbaxyzyx\ncodeforces\nacbba"] | PASSED | #!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
import threading
from math import floor
# from bisect import bisect_right
from collections import Counter
from math import gcd
mod=998244353
def kmp(pat,M):
len = 0
lps=[0]*M
i = 1
while i < M:
if pat[i]== pat[le... | 1584628500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["6", "1"] | f52a416cdf09f69995112126c312da6f | null | Recently a serious bug has been found in the FOS code. The head of the F company wants to find the culprit and punish him. For that, he set up an organizational meeting, the issue is: who's bugged the code? Each of the n coders on the meeting said: 'I know for sure that either x or y did it!'The head of the company dec... | Print a single integer β the number of possible two-suspect sets. Note that the order of the suspects doesn't matter, that is, sets (1,β2) and (2,β1) are considered identical. | The first line contains integers n and p (3ββ€βnββ€β3Β·105;Β 0ββ€βpββ€βn) β the number of coders in the F company and the minimum number of agreed people. Each of the next n lines contains two integers xi, yi (1ββ€βxi,βyiββ€βn) β the numbers of coders named by the i-th coder. It is guaranteed that xiββ βi,βΒ yiββ βi,βΒ xiββ βyi. | standard output | standard input | PyPy 3 | Python | 1,900 | train_081.jsonl | f956809a41258e17e8e0385653c752f2 | 256 megabytes | ["4 2\n2 3\n1 4\n1 4\n2 1", "8 6\n5 6\n5 7\n5 8\n6 2\n2 1\n7 3\n1 3\n1 4"] | PASSED | from collections import defaultdict
from bisect import bisect_left as lower
import sys
input = sys.stdin.readline
def put():
return map(int, input().split())
try:
n,m = put()
cnt, mp, ans = [0]*n, defaultdict(), [0]*n
for _ in range(n):
x,y = put()
x,y = x-1,y-1
key = (min(x,y),... | 1398169200 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["10.0000000000", "-1", "74.6757620881"] | d1c53bd1359efa662604d55176d8af75 | null | Once upon a time in the galaxy of far, far away...Darth Wader found out the location of a rebels' base. Now he is going to destroy the base (and the whole planet that the base is located at), using the Death Star.When the rebels learnt that the Death Star was coming, they decided to use their new secret weapon β space ... | If the rebels will succeed in stopping the Death Star using space mines, print the time from the moment the Death Star was noticed to the blast. If the Death Star will not touch a mine, print "-1" (without quotes). For the answer the absolute or relative error of 10β-β6 is acceptable. | The first input data line contains 7 integers Ax,βAy,βAz,βvx,βvy,βvz,βR. They are the Death Star's initial position, the direction of its movement, and its radius (β-β10ββ€βvx,βvy,βvzββ€β10, |v|β>β0, 0β<βRββ€β100). The second line contains an integer n, which is the number of mines (1ββ€βnββ€β100). Then follow n data ... | standard output | standard input | Python 2 | Python | 2,500 | train_014.jsonl | 278e65412a7f02f990c5b80560c2481e | 256 megabytes | ["0 0 0 1 0 0 5\n2\n10 8 0 2 2\n0 -3 0\n2 2 0\n20 0 0 4 3\n2 4 0\n-4 3 0\n1 -5 0", "8 8 4 4 4 2 6\n1\n-2 -2 -1 3 0", "30 30 2 1 2 1 20\n3\n0 0 40 5 1\n1 4 4\n-10 -40 -5 7 0\n100 200 95 8 1\n-10 0 0"] | PASSED | import math
inf = float('inf')
ax,ay,az,vx,vy,vz,R=map(int,raw_input().split())
n=input()
t=inf
def check(ox,oy,oz,r):
x,y,z=ax-ox,ay-oy,az-oz
a=vx**2+vy**2+vz**2
b=2*(x*vx+y*vy+z*vz)
c=x**2+y**2+z**2-r**2
d=b*b-4*a*c
if d<0: return
x1=(-b+d**0.5)/a/2
x2=(-b-d**0.5)/a/2
global t
if x1>=0: t=min(t,x1)
... | 1308236400 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["2\n3\n1\n1"] | 1b13c9d9fa0c5a44d035bcf6d70e1a60 | NoteIn the first test case there are two possible sums: $$$1+2+5=8$$$ and $$$1+3+5=9$$$. | During the quarantine, Sicromoft has more free time to create the new functions in "Celex-2021". The developers made a new function GAZ-GIZ, which infinitely fills an infinite table to the right and down from the upper left corner as follows: The cell with coordinates $$$(x, y)$$$ is at the intersection of $$$x$$$-th... | For each test case, in a separate line, print the number of possible different sums on the way from the start cell to the end cell. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 57179$$$) β the number of test cases. Each of the following $$$t$$$ lines contains four natural numbers $$$x_1$$$, $$$y_1$$$, $$$x_2$$$, $$$y_2$$$ ($$$1 \le x_1 \le x_2 \le 10^9$$$, $$$1 \le y_1 \le y_2 \le 10^9$$$) β coordinates of the start and the end cells... | standard output | standard input | PyPy 3 | Python | 1,600 | train_025.jsonl | b8a67074c94cdbb67563dd4d3b22f3c1 | 256 megabytes | ["4\n1 1 2 2\n1 2 2 4\n179 1 179 100000\n5 7 5 7"] | PASSED | import sys
# sys.setrecursionlimit(10**6)
input=sys.stdin.readline
t=int(input())
import math
def f(a,b):
z2=min(a-1,b-1)
z4=math.pow(2,z2)
return int(z4)
for t1 in range(t):
x,y,a,b=list(map(int,input().split(" ")))
# z1=min(x-1,y-1)
x-=1
y-=1
a-=x
b-=y
ans=... | 1590503700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1 2\n2 3\n3 4\n4 5\n1 3\n3 5", "-1"] | 959709bfe7b26a4b9f2e7430350650a9 | null | Bob got a job as a system administrator in X corporation. His first task was to connect n servers with the help of m two-way direct connection so that it becomes possible to transmit data from one server to any other server via these connections. Each direct connection has to link two different servers, each pair of se... | If it is impossible to connect the servers in the required way, output -1. Otherwise output m lines with 2 numbers each β description of all the direct connections in the system. Each direct connection is described by two numbers β indexes of two servers, linked by this direct connection. The servers are numbered from ... | The first input line contains 3 space-separated integer numbers n, m, v (3ββ€βnββ€β105,β0ββ€βmββ€β105,β1ββ€βvββ€βn), n β amount of servers, m β amount of direct connections, v β index of the server that fails and leads to the failure of the whole system. | standard output | standard input | Python 3 | Python | 1,700 | train_020.jsonl | c7e790cfa80b3d52252f3629ede63c30 | 256 megabytes | ["5 6 3", "6 100 1"] | PASSED | n,m,v=map(int,input().split())
if m<n-1 or m>(n-1)*(n-2)//2+1:
print(-1)
exit()
if v==1:
print(1,2)
t=[1]+[i for i in range(3,n+1)]
s=1
i,j=0,1
k=len(t)
while s<m and i<k-1:
print(t[i],t[j])
j+=1
if j==k:
i+=1
j=i+1
s+=1
else:
print(1,v)
t=[i for i in range(v,n+1)]+[i for i in range(2,v)]
s=1
... | 1277823600 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["1", "12"] | 6e85f83d544eeb16f57523eb532abf04 | null | Tomash keeps wandering off and getting lost while he is walking along the streets of Berland. It's no surprise! In his home town, for any pair of intersections there is exactly one way to walk from one intersection to the other one. The capital of Berland is very different!Tomash has noticed that even simple cases of a... | Print the required number of "damn rhombi". | The first line of the input contains a pair of integers n, m (1ββ€βnββ€β3000,β0ββ€βmββ€β30000) β the number of intersections and roads, respectively. Next m lines list the roads, one per line. Each of the roads is given by a pair of integers ai,βbi (1ββ€βai,βbiββ€βn;aiββ βbi) β the number of the intersection it goes out from ... | standard output | standard input | PyPy 2 | Python | 1,700 | train_059.jsonl | 90f8b927bb2f9e41dc07e18f5cb6aedf | 256 megabytes | ["5 4\n1 2\n2 3\n1 4\n4 3", "4 12\n1 2\n1 3\n1 4\n2 1\n2 3\n2 4\n3 1\n3 2\n3 4\n4 1\n4 2\n4 3"] | PASSED | from __future__ import division, print_function
import bisect
import math
import itertools
import sys
from atexit import register
if sys.version_info[0] < 3:
from io import BytesIO as stream
else:
from io import StringIO as stream
if sys.version_info[0] < 3:
class dict(dict):
"""dict() -> new ... | 1416238500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["9", "17"] | ad9fd71025c5f91cece740ea95b0eb6f | NoteIn the first example the mayor can change p2 to 3 and p3 to 1, so there will be 9 pairs: (1,β1), (1,β2), (1,β3), (2,β1), (2,β2), (2,β3), (3,β1), (3,β2), (3,β3).In the second example the mayor can change p2 to 4 and p3 to 5. | The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself.There are n stations in the subway. It was built according to the Bertown Transport Law: For each station i there exists exactly one train that goes from this station. Its dest... | Print one number β the maximum possible value of convenience. | The first line contains one integer number n (1ββ€βnββ€β100000) β the number of stations. The second line contains n integer numbers p1, p2, ..., pn (1ββ€βpiββ€βn) β the current structure of the subway. All these numbers are distinct. | standard output | standard input | Python 3 | Python | 1,500 | train_011.jsonl | e5c24d3c9ed17ec970f4f49dd7c2a852 | 256 megabytes | ["3\n2 1 3", "5\n1 5 4 3 2"] | PASSED | input()
l = [[int(x)-1,False] for x in input().split()]
loop = []
for begin in l:
if begin[1]:
continue
count = 0;
nextI = begin[0];
while not l[nextI][1]:
l[nextI][1]=True
nextI = l[nextI][0]
count += 1
loop.append(count)
s = sorted(loop,reverse=True)
total = sum(map... | 1509113100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["2", "1\n6", "1\n0"] | f0a138b9f6ad979c5ca32437e05d6f43 | NoteNumber 6 has only two non-trivial divisors: 2 and 3. It is impossible to make a move after the numbers 2 and 3 are written, so both of them are winning, thus, number 6 is the losing number. A player can make a move and write number 6 after number 30; 6, as we know, is a losing number. Thus, this move will bring us ... | You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer q. During a move a player should write any integer number that is a non-trivial divisor of the last written number. Then he should run this number of circl... | In the first line print the number of the winning player (1 or 2). If the first player wins then the second line should contain another integer β his first move (if the first player can't even make the first move, print 0). If there are multiple solutions, print any of them. | The first line contains the only integer q (1ββ€βqββ€β1013). Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specificator. | standard output | standard input | Python 2 | Python | 1,400 | train_003.jsonl | 014bef652a4312c3f91993d5fe8a26f3 | 256 megabytes | ["6", "30", "1"] | PASSED | #!/usr/bin/env python
from sys import stdin as cin
def find_div(q):
d = 0
if q == 1:
return 1
if q % 2 == 0:
return 2
else:
for d in range(3, int(q**0.5) + 3, 2):
if q % d == 0:
return d
return q
def main():
q = int(next(cin))
if q == 1:
return 1,0
d = find_div(q)
if d in (1, q):
return 1... | 1329490800 | [
"number theory",
"math",
"games"
] | [
1,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["4\n1\n146981438\n747093407"] | ff4fce15470e5dbd1153bd23b26896f1 | NoteYou have to minimize the difference, not it's remainder. For example, if the minimum difference is equal to $$$2$$$, but there is also a distribution where the difference is $$$10^9 + 8$$$, then the answer is $$$2$$$, not $$$1$$$.In the first test case of the example, there're the following numbers: $$$4$$$, $$$8$$... | Johnny has just found the new, great tutorial: "How to become a grandmaster?". The tutorial tells many strange and unexpected for Johnny things, such as you have to be patient or that very important is solving many harder and harder problems. The boy has found an online judge with tasks divided by topics they cover. He... | Output one integerΒ β the reminder of division the answer by $$$1\,000\,000\,007$$$. | Input consists of multiple test cases. The first line contains one integer $$$t$$$ $$$(1 \leq t \leq 10^5)$$$Β β the number of test cases. Each test case is described as follows: The first line contains two integers $$$n$$$ and $$$p$$$ $$$(1 \leq n, p \leq 10^6)$$$. The second line contains $$$n$$$ integers $$$k_i$$$ $$... | standard output | standard input | PyPy 3 | Python | 1,900 | train_016.jsonl | 6e323ae8e3dc57a21ff2c0cc34eddaf9 | 256 megabytes | ["4\n5 2\n2 3 4 4 3\n3 1\n2 10 1000\n4 5\n0 1 1 100\n1 8\n89"] | PASSED | from sys import stdin, stdout
import math
from collections import defaultdict
def main():
MOD7 = 1000000007
t = int(stdin.readline())
pw = [0] * 21
for w in range(20,-1,-1):
pw[w] = int(math.pow(2,w))
for ks in range(t):
n,p = list(map(int, stdin.readline().split()))
arr = l... | 1591281300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["4 13"] | 28b031722c279783ec44c755ef933836 | NoteIn the first test the initial coordinates of people are $$$9$$$, $$$6$$$, $$$6$$$, $$$9$$$, $$$9$$$ and their speeds are $$$1$$$, $$$2$$$, $$$1$$$, $$$1$$$, $$$1$$$. So, it's easy to see, that at the moment $$$4$$$ one coordinate was modified from $$$13$$$ to $$$12$$$.This is the first test in the hack format:5 79 ... | Cirno gives AquaMoon a problem. There are $$$m$$$ people numbered from $$$0$$$ to $$$m - 1$$$. They are standing on a coordinate axis in points with positive integer coordinates. They are facing right (i.e. in the direction of the coordinate increase). At this moment everyone will start running with the constant speed ... | Print a single line with two integers $$$y$$$, $$$p$$$ β the moment that contains the modified coordinate and the original coordinate. | This problem is made as interactive. It means, that your solution will read the input, given by the interactor. But the interactor will give you the full input at the beginning and after that, you should print the answer. So you should solve the problem, like as you solve the usual, non-interactive problem because you ... | standard output | standard input | PyPy 3-64 | Python | 3,000 | train_086.jsonl | c7cd001fc5adce73aef24db2fea3faa4 | 256 megabytes | ["5 7\n6 9 9 6 9\n10 7 10 8 10\n11 11 11 10 8\n12 12 12 12 9\n14 13 12 10 13\n11 14 16 14 14\n12 15 18 15 15"] | 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... | 1626012300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
4 seconds | ["2 5 5", "1 2 2"] | f3ed9a3d4566cdb04cdc26be51027d44 | NoteIn the first test case, the minimum number of exchanges needed to exchange a chocolate of type $$$6$$$ to a chocolate of type $$$9$$$ is $$$5$$$. The sequence of exchanges is as follows: $$$6 \rightarrow 2 \rightarrow 0 \rightarrow 1 \rightarrow 7 \rightarrow 9$$$.In the second test case, the minimum number of exch... | Christmas is coming, Icy has just received a box of chocolates from her grandparents! The box contains $$$n$$$ chocolates. The $$$i$$$-th chocolate has a non-negative integer type $$$a_i$$$.Icy believes that good things come in pairs. Unfortunately, all types of chocolates are distinct (all $$$a_i$$$ are distinct). Icy... | Output three integers $$$x$$$, $$$y$$$, and $$$m$$$. $$$x$$$ and $$$y$$$ are indices of the optimal chocolates to perform exchanges on. Your output must satisfy $$$1 \le x, y \le n$$$, $$$x \ne y$$$. $$$m$$$ is the number of exchanges needed to obtain $$$a_x = a_y$$$. We can show that $$$m \le 10^9$$$ for any pair of c... | The first line of the input contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$)Β β the number of chocolates. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that all $$$a_i$$$ are distinct. | standard output | standard input | PyPy 3 | Python | 2,700 | train_100.jsonl | d4bca23d181485f9f5095ca56ac22a5e | 512 megabytes | ["5\n5 6 7 8 9", "2\n4 8"] | PASSED | from sys import *
n = int(stdin.readline())
tree = [{} for _ in range(31)]
idx, iid = {}, 0
for x in map(int, stdin.readline().split()):
iid += 1
idx[x] = iid
tree[x.bit_length()][x] = (x, 0)
x, y, m = 0, 0, 0
for i in range(30, 0, -1):
if not tree[i]:
continue
k, mp ... | 1639661700 | [
"number theory",
"graphs",
"trees",
"math",
"games"
] | [
1,
0,
1,
1,
1,
0,
0,
1
] | |
1 second | ["? 2 2\n? 5 5\n? 4 7\n? 1 5\n! 2 3 4 5"] | 7d72a14dd0429e5f8ad9b75c1e35f1e7 | null | This is an interactive problem!As part of your contribution in the Great Bubble War, you have been tasked with finding the newly built enemy fortress. The world you live in is a giant $$$10^9 \times 10^9$$$ grid, with squares having both coordinates between $$$1$$$ and $$$10^9$$$. You know that the enemy base has the s... | null | The input contains the answers to your queries. | standard output | standard input | Python 3 | Python | 2,100 | train_085.jsonl | c5b9c0e78622270eeec9dd7222e37ae3 | 256 megabytes | ["1\n1\n2\n1"] | PASSED | from sys import stdout
from math import ceil, floor
endv = 1000000000
print("? 1 1")
stdout.flush()
dstart = int(input())
print(("? 1000000000 1000000000"))
stdout.flush()
dend = int(input())
start, end = 1, min(endv, dstart)
while start < end:
midx = int(ceil((start + end) / 2))
print(f"? {mi... | 1633770300 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["3 0 3", "0 0 0", "4 14 4 16 10"] | d0cb479bbe2fca382a439148af77e082 | NoteIn the first example, there will be only one team consisting of persons $$$1$$$ and $$$3$$$. The optimal strategy for them is to assign the first task to the $$$3$$$-rd person and the second task to the $$$1$$$-st person, this will lead to score equal to $$$1 + 2 = 3$$$.In the second example, nobody likes anyone, s... | Zibi is a competitive programming coach. There are $$$n$$$ competitors who want to be prepared well. The training contests are quite unusualΒ β there are two people in a team, two problems, and each competitor will code exactly one of them. Of course, people in one team will code different problems.Rules of scoring also... | Output $$$n$$$ integersΒ β the sum of scores for all participants in the same order as they appear in the input. | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 300\,000$$$, $$$0 \le m \le 300\,000$$$)Β β the number of participants and the number of pairs of people who will not write a contest together. Each of the next $$$n$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$-10^9 \le x_i, y_i \le ... | standard output | standard input | Python 3 | Python | 1,900 | train_013.jsonl | 0539420ef6df4b7505adfd2d1a4e6c60 | 256 megabytes | ["3 2\n1 2\n2 3\n1 3\n1 2\n2 3", "3 3\n1 2\n2 3\n1 3\n1 2\n2 3\n1 3", "5 3\n-1 3\n2 4\n1 1\n3 5\n2 2\n1 4\n2 3\n3 5"] | PASSED | from sys import stdin
from operator import add
from itertools import repeat
def main():
n, m = map(int, stdin.readline().split())
inp = list(map(int, stdin.read().split(), repeat(10, 2*n+2*m)))
xys = inp[:2*n]
exc = list(map(add, inp[2*n:], repeat(-1)))
a = list(range(n))
a.sort(key=lambda i: ... | 1540740900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["4", "10", "16"] | da2fb0ea61808905a133021223f6148d | NoteExample $$$1$$$: you can subtract $$$a_1$$$ from $$$b_1$$$, and add $$$a_3$$$, $$$a_4$$$, and $$$a_5$$$ to $$$b_3$$$, $$$b_4$$$, and $$$b_5$$$ respectively. The final array will be [$$$-1$$$, $$$0$$$, $$$3$$$, $$$4$$$, $$$5$$$] after $$$4$$$ moves.Example $$$2$$$: you can reach [$$$-3$$$, $$$-2$$$, $$$-1$$$, $$$0$$... | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers, and an array $$$b$$$, with length $$$n$$$. Initially $$$b_i=0$$$ for each $$$1 \leq i \leq n$$$.In one move you can choose an integer $$$i$$$ ($$$1 \leq i \leq n$$$), and add $$$a_i$$$ to $$$b_i$$$ or subtract $$$a_i$$$ from $$$b_i$$$. What is the ... | Print a single integer, the minimum number of moves to make $$$b$$$ increasing. | The first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 5000$$$). The second line contains $$$n$$$ integers, $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) β the elements of the array $$$a$$$. | standard output | standard input | PyPy 3-64 | Python | 1,300 | train_084.jsonl | 756614fc06ef48dd47bf82310eec8489 | 256 megabytes | ["5\n1 2 3 4 5", "7\n1 2 1 2 1 2 1", "8\n1 8 2 7 3 6 4 5"] | PASSED | n = int(input())
a = list(map(int, input().split()))
Min = 1e18
for l in range(n - 1):
m = a[l]
answer = 1
for i in range(l-1, -1, -1):
answer += (m + a[i]) // a[i]
m = a[i] * ((m + a[i]) // a[i])
# if l + 1 < n:
m = 0
for i in range(l + 2, n):
answer += (m + a... | 1650378900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["6", "8", "28"] | 869f94e76703cde502bd908b476d970e | NoteConsider the first sample case. There are 3 towns and 3 roads. The towns are numbered from 1 to 3 and the roads are , , initially. Number the roads 1 to 3 in this order. The sets of roads that ZS the Coder can flip (to make them not confusing) are {1},β{2},β{3},β{1,β2},β{1,β3},β{2,β3}. Note that the empty set is i... | ZS the Coder and Chris the Baboon has explored Udayland for quite some time. They realize that it consists of n towns numbered from 1 to n. There are n directed roads in the Udayland. i-th of them goes from town i to some other town ai (aiββ βi). ZS the Coder can flip the direction of any road in Udayland, i.e. if it go... | Print a single integerΒ β the number of ways to flip some set of the roads so that the resulting whole set of all roads is not confusing. Since this number may be too large, print the answer modulo 109β+β7. | The first line of the input contains single integer n (2ββ€βnββ€β2Β·105)Β β the number of towns in Udayland. The next line contains n integers a1,βa2,β...,βan (1ββ€βaiββ€βn,βaiββ βi), ai denotes a road going from town i to town ai. | standard output | standard input | Python 3 | Python | 1,900 | train_068.jsonl | d1c862939fc505a46c9470f6884facc9 | 256 megabytes | ["3\n2 3 1", "4\n2 1 1 1", "5\n2 4 2 5 3"] | PASSED | n = int(input())
l = list(map(int, input().split()))
l.insert(0,0)
mark = {}
loop, pos, res , mod= 0, 1, 1, int(1e9+7)
for i in range(1, n+1):
if not i in mark:
start, j = pos, i
while not j in mark:
mark[j] = pos
pos+= 1
j = l[j]
if mark[j]>=start:
... | 1472472300 | [
"math",
"graphs"
] | [
0,
0,
1,
1,
0,
0,
0,
0
] | |
2 seconds | ["YES", "NO", "NO"] | 6214a85d2be0a908dcbfe089327cf51a | null | Volodya and Vlad play the following game. There are k pies at the cells of nββΓββm board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the borde... | Output only one word: "YES" β if Volodya wins, "NO" β otherwise. | First line contains 3 integers, separated by space: 1ββ€βn,βmββ€β100 β dimensions of the board and 0ββ€βkββ€β100 β the number of pies. Each of the next k lines contains 2 integers, separated by space: 1ββ€βxββ€βn, 1ββ€βyββ€βm β coordinates of the corresponding pie. There could be more than one pie at a cell. | standard output | standard input | Python 3 | Python | 1,900 | train_019.jsonl | 64026f537185d01954e0f04eb41ccf29 | 256 megabytes | ["2 2 1\n1 2", "3 4 0", "100 50 2\n50 25\n50 25"] | PASSED | n, m, k = map(int, input().split())
win = False
for i in range(k):
x, y = map(int, input().split())
if abs(x - 1) <= 4 or abs(y - 1) <= 4 or \
abs(n - x) <= 4 or abs(m - y) <= 4:
win = True
print('YES' if win else 'NO')
| 1294992000 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["3\n1 3 2", "5\n1 3 2 5 4", "3\n1 2 3 1 2"] | 2aaa31d52d69ff3703f93177b25671a3 | NoteIn the first sample the park consists of three squares: 1βββ3βββ2. Thus, the balloon colors have to be distinct. Illustration for the first sample. In the second example there are following triples of consequently connected squares: 1βββ3βββ2 1βββ3βββ4 1βββ3βββ5 2βββ3βββ4 2βββ3βββ5 4βββ3βββ5 We can see t... | Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he decided to decorate them.The park consists of n squares connected with (nβ-β1) bidirectional paths in such a way that any square is reachable from any other using these paths. Andryusha decided to hang a colored b... | In the first line print single integer kΒ β the minimum number of colors Andryusha has to use. In the second line print n integers, the i-th of them should be equal to the balloon color on the i-th square. Each of these numbers should be within range from 1 to k. | The first line contains single integer n (3ββ€βnββ€β2Β·105)Β β the number of squares in the park. Each of the next (nβ-β1) lines contains two integers x and y (1ββ€βx,βyββ€βn)Β β the indices of two squares directly connected by a path. It is guaranteed that any square is reachable from any other using the paths. | standard output | standard input | Python 3 | Python | 1,600 | train_010.jsonl | 8dceb524d18acfc8dea92ba97b9d3674 | 256 megabytes | ["3\n2 3\n1 3", "5\n2 3\n5 3\n4 3\n1 3", "5\n2 1\n3 2\n4 3\n5 4"] | PASSED | import sys
sys.setrecursionlimit(200000)
n = int(input())
arr = [[] for i in range(n)]
for i in range(n - 1):
a, b = map(int, input().split())
arr[a - 1].append(b - 1)
arr[b - 1].append(a - 1)
s = max([len(p) for p in arr]) + 1
print(s)
colored = [0] * n
def dfs(v, c, d):
colored[v] = p = c
for u ... | 1488705300 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
2 seconds | ["5\n6\n3\n4\n4\n-1"] | 81abcdc77ffcf8858b4e81f3db5ee7fb | null | You wanted to write a text $$$t$$$ consisting of $$$m$$$ lowercase Latin letters. But instead, you have written a text $$$s$$$ consisting of $$$n$$$ lowercase Latin letters, and now you want to fix it by obtaining the text $$$t$$$ from the text $$$s$$$.Initially, the cursor of your text editor is at the end of the text... | For each test case, print one integer β the minimum number of moves required to obtain the text $$$t$$$ from the text $$$s$$$ using the given set of actions, or -1 if it is impossible to obtain the text $$$t$$$ from the text $$$s$$$ in the given test case. | The first line of the input contains one integer $$$T$$$ ($$$1 \le T \le 5000$$$) β the number of test cases. Then $$$T$$$ test cases follow. The first line of the test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le m \le n \le 5000$$$) β the length of $$$s$$$ and the length of $$$t$$$, respectively. The seco... | standard output | standard input | PyPy 3-64 | Python | 2,500 | train_098.jsonl | 799d33c9b735098e3233747f89e79b81 | 256 megabytes | ["6\n\n9 4\n\naaaaaaaaa\n\naaaa\n\n7 3\n\nabacaba\n\naaa\n\n5 4\n\naabcd\n\nabcd\n\n4 2\n\nabba\n\nbb\n\n6 4\n\nbaraka\n\nbaka\n\n8 7\n\nquestion\n\nproblem"] | PASSED | #!/usr/bin/env PyPy3
from collections import Counter, defaultdict, deque
import itertools
import re
import math
from functools import reduce
import operator
import bisect
from heapq import *
import functools
mod=998244353
import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO... | 1657290900 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
4 seconds | ["314"] | 202396838c98654c4e40179f21a225a0 | null | Let's denote the size of the maximum matching in a graph $$$G$$$ as $$$\mathit{MM}(G)$$$.You are given a bipartite graph. The vertices of the first part are numbered from $$$1$$$ to $$$n$$$, the vertices of the second part are numbered from $$$n+1$$$ to $$$2n$$$. Each vertex's degree is $$$2$$$.For a tuple of four inte... | Print one integerΒ β the sum of $$$\mathit{MM}(G(l, r, L, R))$$$ over all tuples of integers $$$(l, r, L, R)$$$ having $$$1 \le l \le r \le n$$$ and $$$n+1 \le L \le R \le 2n$$$. | The first line contains one integer $$$n$$$ ($$$2 \le n \le 1500$$$)Β β the number of vertices in each part. Then $$$2n$$$ lines follow, each denoting an edge of the graph. The $$$i$$$-th line contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i \le n$$$; $$$n + 1 \le y_i \le 2n$$$)Β β the endpoints of the $$$i$$$... | standard output | standard input | PyPy 3-64 | Python | 2,600 | train_104.jsonl | 41bd3f73363cc3d11f0b33d92c75e8c2 | 512 megabytes | ["5\n4 6\n4 9\n2 6\n3 9\n1 8\n5 10\n2 7\n3 7\n1 10\n5 8"] | PASSED |
class unionfind:
def __init__(self,uni_num):
self.uni_num=uni_num
self.union_root = [-1 for i in range(self.uni_num + 1)]
self.union_depth = [0] * (self.uni_num + 1)
self.e_num=[0]*(self.uni_num+1)
def find(self,x): # θ¦ͺγ―θͺ°οΌ
if self.union_root[x] < 0:
retur... | 1646922900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["14", "14", "18"] | d8349ff9b695612473b2ba00d08e505b | NoteIn the first example, the farmer can reduce the power of the $$$4$$$-th machine by $$$2$$$ times, and increase the power of the $$$1$$$-st machine by $$$2$$$ times, then the powers will be: $$$[2, 2, 3, 2, 5]$$$.In the second example, the farmer can reduce the power of the $$$3$$$-rd machine by $$$2$$$ times, and i... | One day Sasha visited the farmer 2D and his famous magnetic farm. On this farm, the crop grows due to the influence of a special magnetic field. Maintaining of the magnetic field is provided by $$$n$$$ machines, and the power of the $$$i$$$-th machine is $$$a_i$$$. This year 2D decided to cultivate a new culture, but w... | Print one integerΒ β minimum total power. | The first line contains one integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$)Β β the number of machines. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 100$$$)Β β the powers of the machines. | standard output | standard input | PyPy 2 | Python | 1,300 | train_034.jsonl | df477ca32bad7a0409760aaaa8e838e5 | 256 megabytes | ["5\n1 2 3 4 5", "4\n4 2 4 4", "5\n2 4 2 3 7"] | PASSED | n=int(raw_input())
a=list(map(int,raw_input().split()))
a = sorted(a)
ans=99999999999999999999999999999999999999999999999999999999999999999999
i=n-1
total=sum(a)
if n > 1:
while i > 0:
for j in xrange(1,101):
if a[i]%j==0:
minn=a[0]*j
maxx=a[i]/j
a... | 1550334900 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
1 second | ["12", "1"] | 482d128baf37eeeb28b874934aded534 | NoteIn the first example, the leaf nodes are $$$2,3,4,5$$$. The ways to partition the leaves are in the following image In the second example, the only leaf is node $$$10$$$ so there is only one partition. Note that node $$$1$$$ is not a leaf. | You are given a rooted tree with $$$n$$$ nodes, labeled from $$$1$$$ to $$$n$$$. The tree is rooted at node $$$1$$$. The parent of the $$$i$$$-th node is $$$p_i$$$. A leaf is node with no children. For a given set of leaves $$$L$$$, let $$$f(L)$$$ denote the smallest connected subgraph that contains all leaves $$$L$$$.... | Print a single integer, the number of ways to partition the leaves, modulo $$$998244353$$$. | The first line contains an integer $$$n$$$ ($$$2 \leq n \leq 200\,000$$$)Β β the number of nodes in the tree. The next line contains $$$n-1$$$ integers $$$p_2, p_3, \ldots, p_n$$$ ($$$1 \leq p_i < i$$$). | standard output | standard input | Python 2 | Python | 2,500 | train_022.jsonl | fd9e70b728166d44f0b8cc4c48670ee4 | 256 megabytes | ["5\n1 1 1 1", "10\n1 2 3 4 5 6 7 8 9"] | PASSED | from sys import stdin
from itertools import repeat
def main():
n = int(stdin.readline())
p = [-1, -1] + map(int, stdin.readline().split(), repeat(10, n - 1))
ch = [[] for _ in xrange(n + 1)]
for i in xrange(2, n + 1):
ch[p[i]].append(i)
st = []
pu = st.append
po = st.pop
pu(1)
... | 1555783500 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["1\n2 1\n1 2 3"] | d253d8efc344b0848a19876ff52c09a8 | NoteIn the first test case, Eikooc has only one choice. Sushi will have no moves to play after Eikooc chooses this node and Eikooc will win.In the second test case, $$$1 \oplus 2 = 3 \nleq min(1, 2)$$$. Hence, after Eikooc picks either of the nodes, Sushi will have no moves to play and Eikooc will win. Both $$$\{1, 2\}... | Eikooc and Sushi play a game.The game is played on a tree having $$$n$$$ nodes numbered $$$1$$$ to $$$n$$$. Recall that a tree having $$$n$$$ nodes is an undirected, connected graph with $$$n-1$$$ edges.They take turns alternately moving a token on the tree. Eikooc makes the first move, placing the token on any node of... | For each test case print any suitable relabeling Β β a permutation of length $$$n$$$ which maximizes the number of nodes that can be chosen in the first turn that guarantee a win for Eikooc. If there are multiple such relabelings, you may print any of them. | The first line contains a single integer $$$t~(1 \le t \le 10^5)$$$ Β β the number of test cases. The description of each test case is as follows. The first line of each test case contains an integer $$$n~(1 \le n \le 2 \cdot 10^5)$$$ Β β the number of nodes in the tree. The next $$$n-1$$$ lines contain two integers $$$u... | standard output | standard input | PyPy 3-64 | Python | 2,100 | train_097.jsonl | fced03019ab1e250bc154008823b972f | 256 megabytes | ["3\n1\n2\n1 2\n3\n1 2\n1 3"] | PASSED | import sys
from collections import deque
ipt=sys.stdin.readline
T=int(ipt())
for _ in range(T):
n=int(input())
lg=0
while 2**lg<=n:
lg+=1
lg-=1
t=[[] for i in range(n+1)]
for i in range(n-1):
x, y=map(int, ipt().split())
t[x].append(y)
t[y].append(... | 1636727700 | [
"games",
"trees"
] | [
1,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["1\n2\n4\n4\n8\n8\n15\n6"] | d55660b8091bca2211fa1ad56402aebd | NoteThe first test case contains exactly one subsegment and $$$mex({0}) = 1 > med({0}) = 0$$$ on it.In the third test case, on the following subsegments: $$$[1, 0]$$$, $$$[0]$$$, $$$[1, 0, 2]$$$ and $$$[0, 2]$$$, $$$mex$$$ is greater than $$$med$$$.In the fourth test case, on the following subsegments: $$$[0, 2]$$$,... | You are given a permutation $$$p_1, p_2, \ldots, p_n$$$ of length $$$n$$$ of numbers $$$0, \ldots, n - 1$$$. Count the number of subsegments $$$1 \leq l \leq r \leq n$$$ of this permutation such that $$$mex(p_l, p_{l+1}, \ldots, p_r) > med(p_l, p_{l+1}, \ldots, p_r)$$$.$$$mex$$$ of $$$S$$$ is the smallest non-negati... | For each test case print the answer in a single line: the number of subsegments $$$1 \leq l \leq r \leq n$$$ of this permutation such that $$$mex(p_l, p_{l+1}, \ldots, p_r) > med(p_l, p_{l+1}, \ldots, p_r)$$$. | The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4$$$), the number of test cases. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$), the length of the permutation $$$p$$$. The second line of ... | standard output | standard input | PyPy 3-64 | Python | 2,000 | train_094.jsonl | 670eb5cd4649deb067d7b6043f13bc46 | 256 megabytes | ["8\n\n1\n\n0\n\n2\n\n1 0\n\n3\n\n1 0 2\n\n4\n\n0 2 1 3\n\n5\n\n3 1 0 2 4\n\n6\n\n2 0 4 1 3 5\n\n8\n\n3 7 2 6 0 1 5 4\n\n4\n\n2 0 1 3"] | PASSED | m=int(input())
for _ in range(m):
n=int(input())
s=dict(zip(map(int,input().split()),range(n)))
mi=s[0]
ma=mi
lists=0
n0=int(n/2)+n%2
for i in range(n0):
si=s[i]
mi=min(mi,si)
ma=max(ma,si)
b1=2*i+1
b2=b1+1
a1=min(b1-ma+mi,mi+1,n-... | 1665930900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["4\n2\n31\n7"] | 5b40c60ba54c7bb9a649b15588ef6510 | NoteIn the first example, the valid subsequences are $$$[0]$$$, $$$[1]$$$, $$$[0,1]$$$ and $$$[0,2]$$$.In the second example, the valid subsequences are $$$[0]$$$ and $$$[1]$$$.In the third example, any non-empty subsequence is valid. | Let's call a sequence of integers $$$x_1, x_2, \dots, x_k$$$ MEX-correct if for all $$$i$$$ ($$$1 \le i \le k$$$) $$$|x_i - \operatorname{MEX}(x_1, x_2, \dots, x_i)| \le 1$$$ holds. Where $$$\operatorname{MEX}(x_1, \dots, x_k)$$$ is the minimum non-negative integer that doesn't belong to the set $$$x_1, \dots, x_k$$$. ... | For each test case, print a single integerΒ β the number of non-empty MEX-correct subsequences of a given array, taken modulo $$$998244353$$$. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$)Β β the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 5 \cdot 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le n$$$). The sum of $$$n$$$ over... | standard output | standard input | PyPy 3-64 | Python | 1,900 | train_090.jsonl | 0d4b2c83f1d4316b89955f4a20c758ca | 256 megabytes | ["4\n3\n0 2 1\n2\n1 0\n5\n0 0 0 0 0\n4\n0 1 2 3"] | PASSED | import sys
import os
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
... | 1638369300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["2\n1\n0\n3\n17\n1111"] | e8f12eb9144ac2ea1c18fbfb15a84a0e | NoteIn query one the suitable numbers are 1 and 4. | You're given Q queries of the form (L,βR). For each query you have to find the number of such x that Lββ€βxββ€βR and there exist integer numbers aβ>β0, pβ>β1 such that xβ=βap. | Output Q lines β the answers to the queries. | The first line contains the number of queries Q (1ββ€βQββ€β105). The next Q lines contains two integers L, R each (1ββ€βLββ€βRββ€β1018). | standard output | standard input | PyPy 2 | Python | 2,100 | train_005.jsonl | ebd2486e36fcde356f15297619cc17b8 | 256 megabytes | ["6\n1 4\n9 9\n5 7\n12 29\n137 591\n1 1000000"] | PASSED | import math
from sys import stdin, stdout
q = int(stdin.readline())
D = set()
#v.append(1)
mv = int(1e18)
for i in range(2,1000001):
j = i*i*i
while(j<=mv):
y = int(math.sqrt(j))
if(y*y == j):
j=j*i
continue
D.add(j)
j = j*i
v=[]
for key in D:
v.appen... | 1521822900 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["a\nz"] | b663dadb1033d435775bf000c2041d43 | NoteTest case 1:Initially $$$s$$$ is "a". In the first operation, Keine chooses "a", and replaces it with "ab". $$$s$$$ becomes "ab". In the second operation, Keine chooses "b", and replaces it with "cd". $$$s$$$ becomes "acd".So the final string is "acd", and $$$t=[$$$"a", "ab", "b", "cd"$$$]$$$ before being shuffled.... | As a human, she can erase history of its entirety. As a Bai Ze (Hakutaku), she can create history out of nothingness.βPerfect Memento in Strict SenseKeine has the ability to manipulate history. The history of Gensokyo is a string $$$s$$$ of length $$$1$$$ initially. To fix the chaos caused by Yukari, she needs to do th... | For each test case, print the initial string in one line. | Each test contains multiple test cases. The first line contains a single integer $$$T$$$ ($$$1 \leq T \leq 10^3$$$) β the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n < 10 ^ 5$$$) β the number of operations. The next $... | standard output | standard input | PyPy 3-64 | Python | 1,700 | train_091.jsonl | d913e274e1869d4367950f1c8da0dd29 | 256 megabytes | ["2\n\n2\n\na\n\nab\n\nb\n\ncd\n\nacd\n\n3\n\nz\n\na\n\na\n\naa\n\nyakumo\n\nran\n\nyakumoran"] | PASSED | from __future__ import print_function
from collections import defaultdict
import os,sys,io
import random
#from io import BytesIO, IOBase
input = lambda: sys.stdin.readline().rstrip("\r\n")
def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().strip().split(" "))
def m... | 1654266900 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["1\n1 1", "1\n1 1", "2\n1 1\n1 2"] | e40774a2c34251eec2df869611731a48 | NoteExample $$$1$$$: one half-queen is enough. Note: a half-queen on $$$(1, 1)$$$ attacks $$$(1, 1)$$$.Example $$$2$$$: one half-queen is enough too. $$$(1, 2)$$$ or $$$(2, 1)$$$ would be wrong solutions, because a half-queen on $$$(1, 2)$$$ does not attack the cell $$$(2, 1)$$$ and vice versa. $$$(2, 2)$$$ is also a v... | You are given a board with $$$n$$$ rows and $$$n$$$ columns, numbered from $$$1$$$ to $$$n$$$. The intersection of the $$$a$$$-th row and $$$b$$$-th column is denoted by $$$(a, b)$$$.A half-queen attacks cells in the same row, same column, and on one diagonal. More formally, a half-queen on $$$(a, b)$$$ attacks the cel... | In the first line print a single integer $$$k$$$ β the minimum number of half-queens. In each of the next $$$k$$$ lines print two integers $$$a_i$$$, $$$b_i$$$ ($$$1 \le a_i, b_i \le n$$$) β the position of the $$$i$$$-th half-queen. If there are multiple solutions, print any. | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) β the size of the board. | standard output | standard input | PyPy 3-64 | Python | 2,400 | train_084.jsonl | 025a37247651d6d69ae8d886816565eb | 256 megabytes | ["1", "2", "3"] | PASSED | import sys
# import numpy
input = sys.stdin.readline
inf = float('inf')
def getInt():
return int(input())
def getStr():
return input().strip()
def getList(split=True):
s = getStr()
if split:
s = s.split()
return map(int, s)
# t = getInt()
t = 1
def solve():
n = int(input())
... | 1650378900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["0\n12\n5\n0\n16", "3\n0\n3"] | 859d66fc2c204a8c002012b1fb206645 | null | Shaass has decided to hunt some birds. There are n horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to n from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are ai oskols ... | On the i-th line of the output print the number of birds on the i-th wire. | The first line of the input contains an integer n, (1ββ€βnββ€β100). The next line contains a list of space-separated integers a1,βa2,β...,βan, (0ββ€βaiββ€β100). The third line contains an integer m, (0ββ€βmββ€β100). Each of the next m lines contains two integers xi and yi. The integers mean that for the i-th time Shaass sho... | standard output | standard input | PyPy 2 | Python | 800 | train_000.jsonl | ee56c03ada685ee50fc42b7e71105e4a | 256 megabytes | ["5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6", "3\n2 4 1\n1\n2 2"] | PASSED | n = input()
a = map(int, raw_input().split())
m = input()
def shoot(m):
x = m[0]
y = m[1]
x -= 1
if x < (n - 1):
a[x + 1] += a[x] - y
if x > 0:
a[x - 1] += y - 1
a[x] = 0
map(shoot, [map(int, raw_input().split()) for i in range(m)])
for i in a:
print i | 1365348600 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2.5 seconds | ["2\n1 2", "2\n3 2"] | 0f181629eb10c5b2718f7a8f79043543 | null | You are given an undirected connected weighted graph consisting of $$$n$$$ vertices and $$$m$$$ edges. Let's denote the length of the shortest path from vertex $$$1$$$ to vertex $$$i$$$ as $$$d_i$$$. You have to erase some edges of the graph so that at most $$$k$$$ edges remain. Let's call a vertex $$$i$$$ good if ther... | In the first line print $$$e$$$ β the number of edges that should remain in the graph ($$$0 \le e \le k$$$). In the second line print $$$e$$$ distinct integers from $$$1$$$ to $$$m$$$ β the indices of edges that should remain in the graph. Edges are numbered in the same order they are given in the input. The number of ... | The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$2 \le n \le 3 \cdot 10^5$$$, $$$1 \le m \le 3 \cdot 10^5$$$, $$$n - 1 \le m$$$, $$$0 \le k \le m$$$) β the number of vertices and edges in the graph, and the maximum number of edges that can be retained in the graph, respectively. Then $$$m$$$ line... | standard output | standard input | PyPy 2 | Python | 1,800 | train_020.jsonl | f365a5f39a7e93a833f20b3f20b291ad | 256 megabytes | ["3 3 2\n1 2 1\n3 2 1\n1 3 3", "4 5 2\n4 1 8\n2 4 1\n2 1 3\n3 4 9\n3 1 5"] | PASSED | from sys import stdin
from collections import defaultdict
from heapq import heappop, heappush
n, m, k = map(int, stdin.readline().split())
graph = defaultdict(list)
for i, line in enumerate(stdin.readlines()):
x, y, w = map(int, line.split())
graph[x].append((y, w, i))
graph[y].append((x, w, i))
res... | 1542033300 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["8\n3\n1 2 3 \n0", "27\n1\n2 \n2\n1 2\n2 3"] | 4750f5a5aaa1ef727ebf2376641bd8ed | NoteFor the answers given in the samples, refer to the following diagrams (cities with power stations are colored green, other cities are colored blue, and wires are colored red):For the first example, the cost of building power stations in all cities is $$$3 + 2 + 3 = 8$$$. It can be shown that no configuration costs ... | Shichikuji is the new resident deity of the South Black Snail Temple. Her first job is as follows:There are $$$n$$$ new cities located in Prefecture X. Cities are numbered from $$$1$$$ to $$$n$$$. City $$$i$$$ is located $$$x_i$$$ km North of the shrine and $$$y_i$$$ km East of the shrine. It is possible that $$$(x_i, ... | In the first line print a single integer, denoting the minimum amount of yen needed. Then, print an integer $$$v$$$ β the number of power stations to be built. Next, print $$$v$$$ space-separated integers, denoting the indices of cities in which a power station will be built. Each number should be from $$$1$$$ to $$$n$... | First line of input contains a single integer $$$n$$$ ($$$1 \leq n \leq 2000$$$) β the number of cities. Then, $$$n$$$ lines follow. The $$$i$$$-th line contains two space-separated integers $$$x_i$$$ ($$$1 \leq x_i \leq 10^6$$$) and $$$y_i$$$ ($$$1 \leq y_i \leq 10^6$$$) β the coordinates of the $$$i$$$-th city. The n... | standard output | standard input | PyPy 2 | Python | 1,900 | train_071.jsonl | a9367e148609f475d7836a85dbe9961e | 256 megabytes | ["3\n2 3\n1 1\n3 2\n3 2 3\n3 2 3", "3\n2 1\n1 2\n3 3\n23 2 23\n3 2 3"] | PASSED | import os
import sys
from atexit import register
from io import BytesIO
range = xrange
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
def mst(mat):
n = len(mat)
root = 0
f... | 1572618900 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
2 seconds | ["14 4 4 15"] | 5c844c0dc0eb718aea7b2446e90ce250 | NoteLet's consider each $$$a_i$$$: $$$a_1 = 19$$$. You can, firstly, increase it by one to get $$$20$$$ and then multiply it by two $$$13$$$ times. You'll get $$$0$$$ in $$$1 + 13 = 14$$$ steps. $$$a_2 = 32764$$$. You can increase it by one $$$4$$$ times: $$$32764 \rightarrow 32765 \rightarrow 32766 \rightarrow 3276... | Suppose you have an integer $$$v$$$. In one operation, you can: either set $$$v = (v + 1) \bmod 32768$$$ or set $$$v = (2 \cdot v) \bmod 32768$$$. You are given $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. What is the minimum number of operations you need to make each $$$a_i$$$ equal to $$$0$$$? | Print $$$n$$$ integers. The $$$i$$$-th integer should be equal to the minimum number of operations required to make $$$a_i$$$ equal to $$$0$$$. | The first line contains the single integer $$$n$$$ ($$$1 \le n \le 32768$$$)Β β the number of integers. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i < 32768$$$). | standard output | standard input | Python 3 | Python | 1,300 | train_092.jsonl | 66531e10d663c9c0bfaa64eb98415e11 | 256 megabytes | ["4\n19 32764 10240 49"] | PASSED | from math import ceil, log
res =[]
int(input())
l = list(map(int, input().split()) )
c = 32768
def nexp(i, max):
exp = ceil(log(i, 2))
if 2**exp -i < 15 and 2**exp -i + 15 - exp < 15:
return 2**exp -i + 15 - exp
else:
tmp = i
steps=0
if i%2 !=0:
... | 1649514900 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["-1\n-1\n0 0 19\n0 3 3 3 29\n-1\n-1\n0\n0 0 0 1000000000000000000"] | b7ed6f296536d7cd464768b6f315fb99 | NoteIn the first, the second, the fifth and the sixth test cases of the example it is possible to show that such array does not exist.In the third testcase of the example $$$a = [0, 0, 19]$$$. The sum of elements in it is equal to 19, the beauty of it is equal to $$$\left ( \left \lfloor \frac{0}{6} \right \rfloor + \l... | Stanley defines the beauty of an array $$$a$$$ of length $$$n$$$, which contains non-negative integers, as follows: $$$$$$\sum\limits_{i = 1}^{n} \left \lfloor \frac{a_{i}}{k} \right \rfloor,$$$$$$ which means that we divide each element by $$$k$$$, round it down, and sum up the resulting values.Stanley told Sam the in... | For each test case print $$$-1$$$ if such array $$$a$$$ does not exist. Otherwise print $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_{i} \leq 10^{18}$$$)Β β the answer. | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains integers $$$n$$$, $$$k$$$, $$$b$$$, $$$s$$$ ($$$1 \leq n \leq 10^{5}$$$, $$$1 \leq k \leq 10^{9}$$$, $$$0 \leq b \le... | standard output | standard input | PyPy 3-64 | Python | 1,000 | train_082.jsonl | 99fc57ddfe9a5d704b9d4376938fc9e0 | 256 megabytes | ["8\n\n1 6 3 100\n\n3 6 3 12\n\n3 6 3 19\n\n5 4 7 38\n\n5 4 7 80\n\n99978 1000000000 100000000 1000000000000000000\n\n1 1 0 0\n\n4 1000000000 1000000000 1000000000000000000"] | PASSED | t = int(input())
for _ in range(t):
a = list(map(int, input().split()))
n = a[0]
k = a[1]
b = a[2]
s = a[3]
f = []
import math
if n == 1:
if math.floor(s / k) == b:
print(s)
else:
print(-1)
else:
for __ in range(n - 1):
... | 1661006100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["YES\n1 2\nYES\n2 1 3 2\nYES\n1 3 1 3 1\nYES\n1 2 1 3 4 1 4\nNO"] | 79b629047e674883a9bc04b1bf0b7f09 | NoteThe graph from the first three test cases is shown below: In the first test case, the answer sequence is $$$[1,2]$$$ which means that the path is:$$$$$$1 \xrightarrow{\text{b}} 2$$$$$$So the string that is obtained by the given path is b.In the second test case, the answer sequence is $$$[2,1,3,2]$$$ which means t... | Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given... | For each test case, if it is possible to find such path, print "YES" and the path itself as a sequence of $$$m + 1$$$ integers: indices of vertices in the path in the appropriate order. If there are several valid paths, print any of them. Otherwise, (if there is no answer) print "NO". | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 500$$$)Β β the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \leq n \leq 1000$$$; $$$1 \leq m \leq 10^{5}$$$)Β β the number of vertices in the graph and desirable length of the palindrome. Each of the... | standard output | standard input | PyPy 3 | Python | 2,000 | train_107.jsonl | 8ef38d02bf9d86fa98934b694153b453 | 256 megabytes | ["5\n3 1\n*ba\nb*b\nab*\n3 3\n*ba\nb*b\nab*\n3 4\n*ba\nb*b\nab*\n4 6\n*aaa\nb*ba\nab*a\nbba*\n2 6\n*a\nb*"] | PASSED | import sys
def read_ints():
return [int(i) for i in sys.stdin.readline().strip().split()]
def read_int():
return int(sys.stdin.readline().strip())
def check_and_output(lines, nodes):
route = [lines[int(i)-1][int(j)-1] for i, j in zip(nodes[:-1],
nodes[1:])]
in_reverse = list(reversed(route))
... | 1612535700 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["2 2 1 1 0 0", "0 1 1 2 1 1 0 0"] | abdf06347e6db23932ef07020f49aa52 | NoteFor the first sample, the corresponding optimal values of s' after removal 0 through |s|β=β5 characters from s are {"aaaaa", "aaaa", "aaa", "aa", "a", ""}. For the second sample, possible corresponding optimal values of s' are {"axbaxxb", "abaxxb", "axbab", "abab", "aba", "ab", "a", ""}. | Dreamoon has a string s and a pattern string p. He first removes exactly x characters from s obtaining string s' as a result. Then he calculates that is defined as the maximal number of non-overlapping substrings equal to p that can be found in s'. He wants to make this number as big as possible.More formally, let's d... | Print |s|β+β1 space-separated integers in a single line representing the for all x from 0 to |s|. | The first line of the input contains the string s (1ββ€β|s|ββ€β2β000). The second line of the input contains the string p (1ββ€β|p|ββ€β500). Both strings will only consist of lower case English letters. | standard output | standard input | PyPy 3 | Python | 2,200 | train_055.jsonl | c4262816dbcc14465cb603acff4888b6 | 256 megabytes | ["aaaaa\naa", "axbaxxb\nab"] | PASSED | s, p = input(), input()
n, m = len(s) + 1, len(p)
d = [[0] * n for t in range(n)]
for x in range(1, n):
i, j = x, m
while i and j:
j -= s[i - 1] == p[j - 1]
i -= 1
if not j:
for y in range(i + 1): d[x][y + x - i - m] = d[i][y] + 1
for y in range(x): d[x][y] = max(d[x][y], d[x - 1... | 1413122400 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["2", "4"] | d17d2fcfb088bf51e9c1f3fce4133a94 | NoteIn the first sample, we can choose $$$X = 3$$$.In the second sample, we can choose $$$X = 5$$$. | Today, as a friendship gift, Bakry gave Badawy $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ and challenged him to choose an integer $$$X$$$ such that the value $$$\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$$$ is minimum possible, where $$$\oplus$$$ denotes the bitwise XOR operation.As always, Badawy is too lazy, so... | Print one integer β the minimum possible value of $$$\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$$$. | The first line contains integer $$$n$$$ ($$$1\le n \le 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 2^{30}-1$$$). | standard output | standard input | PyPy 3 | Python | 1,900 | train_012.jsonl | a66c042093eb5581f3d89fd2f361f199 | 256 megabytes | ["3\n1 2 3", "2\n1 5"] | PASSED | t=int(input())
lst=[int(ele) for ele in input().split()]
maxn=max(lst)
n=len(bin(maxn)[2:])
newlst=["0"*(n-len(bin(ele)[2:]))+bin(ele)[2:] for ele in lst]
def catchEvil(lstrino,loc):
count0,count1=[],[]
for ele in lstrino:
if ele[n-1-loc]=='1':
count1.append(ele)
else:
... | 1578665100 | [
"strings",
"trees"
] | [
0,
0,
0,
0,
0,
0,
1,
1
] | |
1 second | ["11 6 4 0", "13"] | 14fd47f6f0fcbdb16dbd73dcca8a782f | NoteIn the first testcase, value of the array $$$[11, 6, 4, 0]$$$ is $$$f(f(f(11, 6), 4), 0) = f(f(9, 4), 0) = f(9, 0) = 9$$$.$$$[11, 4, 0, 6]$$$ is also a valid answer. | Anu has created her own function $$$f$$$: $$$f(x, y) = (x | y) - y$$$ where $$$|$$$ denotes the bitwise OR operation. For example, $$$f(11, 6) = (11|6) - 6 = 15 - 6 = 9$$$. It can be proved that for any nonnegative numbers $$$x$$$ and $$$y$$$ value of $$$f(x, y)$$$ is also nonnegative. She would like to research more a... | Output $$$n$$$ integers, the reordering of the array with maximum value. If there are multiple answers, print any. | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). Elements of the array are not guaranteed to be different. | standard output | standard input | PyPy 2 | Python | 1,500 | train_005.jsonl | 1c00423cdb5c32287ca07ba1abb07fb6 | 256 megabytes | ["4\n4 0 11 6", "1\n13"] | PASSED | from __future__ import division,print_function
#from sortedcontainers import SortedList
import sys
#sys.__stdout__.flush()
le=sys.__stdin__.read().split("\n")
le.pop()
le=le[::-1]
n=int(le.pop())
l=list(map(bin,map(int,le.pop().split())))
d=max(map(len,l))
l=['0'*(d-len(k))+k[2:] for k in l]
d-=2
#print(l)
tab=[0]*d
fo... | 1581257100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["3", "9"] | acff03fe274e819a74b5e9350a859471 | NoteThere are three non-empty subsets in the first sample test:, and . The first and the second subset increase the sum by 0 and the third subset increases the sum by 7β-β4β=β3. In total the answer is 0β+β0β+β3β=β3.There are seven non-empty subsets in the second sample test. Among them only the following subsets incre... | Leha decided to move to a quiet town ViΔkopolis, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha managed to get access to n computers throughout the town. Incidentally all the computers, which were hacked by Leha, lie on the... | Print a single integerΒ β the required sum modulo 109β+β7. | The first line contains one integer n (1ββ€βnββ€β3Β·105) denoting the number of hacked computers. The second line contains n integers x1,βx2,β...,βxn (1ββ€βxiββ€β109) denoting the coordinates of hacked computers. It is guaranteed that all xi are distinct. | standard output | standard input | PyPy 3 | Python | 1,500 | train_013.jsonl | 2700e20e0d52fece931e3897db14f53f | 256 megabytes | ["2\n4 7", "3\n4 3 1"] | PASSED | #!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
n=int(input())
A=list(map(int,input().split()))
A.sort()
for i in range(n):
ans-=pow(2,n-i-1,mod)*A[... | 1495303500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["8"] | c277a257b3621249098e67c1546a8bc4 | NoteIn the first query there is a good subtree of size $$$8$$$. The vertices belonging to this subtree are $$${9, 4, 10, 2, 5, 1, 6, 3}$$$. | Assume that you have $$$k$$$ one-dimensional segments $$$s_1, s_2, \dots s_k$$$ (each segment is denoted by two integers β its endpoints). Then you can build the following graph on these segments. The graph consists of $$$k$$$ vertexes, and there is an edge between the $$$i$$$-th and the $$$j$$$-th vertexes ($$$i \neq ... | For each query print one integer β the maximum size of a good subtree of the given tree. | The first line contains one integer $$$q$$$ ($$$1 \le q \le 15 \cdot 10^4$$$) β the number of the queries. The first line of each query contains one integer $$$n$$$ ($$$2 \le n \le 3 \cdot 10^5$$$) β the number of vertices in the tree. Each of the next $$$n - 1$$$ lines contains two integers $$$x$$$ and $$$y$$$ ($$$1 ... | standard output | standard input | PyPy 2 | Python | 2,200 | train_044.jsonl | 1f46dccdb4706b1b55e5b500e21c84cc | 256 megabytes | ["1\n10\n1 2\n1 3\n1 4\n2 5\n2 6\n3 7\n3 8\n4 9\n4 10"] | PASSED | from __future__ import division,print_function
import sys
le=sys.__stdin__.read().split("\n")[::-1]
aff=[]
#basculer en non enracinΓ©
def f():
n=int(le.pop())
ar=[[] for k in range(n)]
for k in range(n-1):
a,b=map(int,le.pop().split())
a-=1
b-=1
ar[a].append(b)
ar[b].a... | 1570545300 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
1 second | ["4\n5\n4\n1\n3\n4"] | a4b170cc058c485a50bf18982fd96851 | NoteIn the first test case, one of the longest strange subsequences is $$$(a_1, a_2, a_3, a_4)$$$In the second test case, one of the longest strange subsequences is $$$(a_1, a_3, a_4, a_5, a_7)$$$.In the third test case, one of the longest strange subsequences is $$$(a_1, a_3, a_4, a_5)$$$.In the fourth test case, one ... | A sequence $$$(b_1, b_2, \ldots, b_k)$$$ is called strange, if the absolute difference between any pair of its elements is greater than or equal to the maximum element in the sequence. Formally speaking, it's strange if for every pair $$$(i, j)$$$ with $$$1 \le i<j \le k$$$, we have $$$|a_i-a_j|\geq MAX$$$, where $$... | For each test case output a single integer β the length of the longest strange subsequence of $$$a$$$. | The first line contains an integer $$$t$$$ $$$(1\le t\le 10^4)$$$ β the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ $$$(1\le n\le 10^5)$$$ β the length of the array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a... | standard output | standard input | PyPy 3-64 | Python | 1,100 | train_085.jsonl | 04562af0a57f7a24132e3ca507d86d84 | 256 megabytes | ["6\n4\n-1 -2 0 0\n7\n-3 4 -2 0 -4 6 1\n5\n0 5 -3 2 -5\n3\n2 3 1\n4\n-3 0 2 0\n6\n-3 -2 -1 1 1 1"] | PASSED | tcs = int(input())
for _ in range(tcs):
n = int(input())
a = list(map(int, input().split()))
a.sort()
if a[n-1] <= 0:
print(n)
else:
flag = 0
pi = 0
while(a[pi] <= 0):
pi += 1
for i in range(pi):
... | 1621866900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1\n0"] | d8c4c2d118e07c3b148495fc04d8fcb5 | null | Petya and Gena play a very interesting game "Put a Knight!" on a chessboard nβΓβn in size. In this game they take turns to put chess pieces called "knights" on the board so that no two knights could threat each other. A knight located in square (r,βc) can threat squares (rβ-β1,βcβ+β2), (rβ-β1,βcβ-β2), (rβ+β1,βcβ+β2), (... | For each niβΓβni board print on a single line "0" if Petya wins considering both players play optimally well. Otherwise, print "1". | The first line contains integer T (1ββ€βTββ€β100) β the number of boards, for which you should determine the winning player. Next T lines contain T integers ni (1ββ€βniββ€β10000) β the sizes of the chessboards. | output.txt | input.txt | PyPy 2 | Python | 1,400 | train_015.jsonl | cc6a140c4011ea48c54eefd058feb15b | 256 megabytes | ["2\n2\n1"] | PASSED | import sys
sys.stdin, sys.stdout=open('input.txt','r'),open('output.txt','w')
for _ in range(input()):print 1-(input()&1)
| 1318919400 | [
"math",
"games"
] | [
1,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["2\n-1\n3\n2\n-1"] | 7c6e8bc160a17dbc6d55c6dc40fe0988 | Note In the $$$1$$$-st test case Koa: selects positions $$$1$$$ and $$$2$$$ and sets $$$A_1 = A_2 = $$$ b ($$$\color{red}{aa}b \rightarrow \color{blue}{bb}b$$$). selects positions $$$2$$$ and $$$3$$$ and sets $$$A_2 = A_3 = $$$ c ($$$b\color{red}{bb} \rightarrow b\color{blue}{cc}$$$). In the $$$2$$$-nd test case ... | Note that the only difference between String Transformation 1 and String Transformation 2 is in the move Koa does. In this version the letter $$$y$$$ Koa selects must be strictly greater alphabetically than $$$x$$$ (read statement for better understanding). You can make hacks in these problems independently.Koa the Koa... | For each test case: Print on a single line the smallest number of moves she has to do to make strings equal to each other ($$$A = B$$$) or $$$-1$$$ if there is no way to make them equal. | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of strings $$$A$$$ and $$$B$$$. The second line of each te... | standard output | standard input | PyPy 3 | Python | 1,700 | train_025.jsonl | 34c8b34c0663b882165dd89e65ea2980 | 256 megabytes | ["5\n3\naab\nbcc\n4\ncabc\nabcb\n3\nabc\ntsr\n4\naabd\ncccd\n5\nabcbd\nbcdda"] | PASSED | import sys
input = sys.stdin.readline
def print(val):
sys.stdout.write(str(val) + '\n')
def prog():
for _ in range(int(input())):
n = int(input())
a = list(input().strip())
b = input().strip()
fail = False
for i in range(n):
if b[i] < a[i]:
fai... | 1595601300 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
2 seconds | ["4 5 2 3 1", "12 13 14 7 3 1", "4 5 2 6 3 1"] | 1ccbcc5986bf7e7272b7dd65e061d66d | null | You are given a set Y of n distinct positive integers y1,βy2,β...,βyn.Set X of n distinct positive integers x1,βx2,β...,βxn is said to generate set Y if one can transform X to Y by applying some number of the following two operation to integers in X: Take any integer xi and multiply it by two, i.e. replace xi with 2Β·x... | Print n integersΒ β set of distinct integers that generate Y and the maximum element of which is minimum possible. If there are several such sets, print any of them. | The first line of the input contains a single integer n (1ββ€βnββ€β50β000)Β β the number of elements in Y. The second line contains n integers y1,β...,βyn (1ββ€βyiββ€β109), that are guaranteed to be distinct. | standard output | standard input | Python 3 | Python | 1,900 | train_072.jsonl | 9eef3b1df0206d66c8676af17ace3276 | 256 megabytes | ["5\n1 2 3 4 5", "6\n15 14 3 13 1 12", "6\n9 7 13 17 5 11"] | PASSED | def main():
from heapq import heapify, heapreplace
input()
s = set(map(int, input().split()))
xx = [-x for x in s]
heapify(xx)
while True:
x = -xx[0]
while x != 1:
x //= 2
if x not in s:
s.add(x)
heapreplace(xx, -x)
... | 1475330700 | [
"strings",
"trees"
] | [
0,
0,
0,
0,
0,
0,
1,
1
] | |
2 seconds | ["3", "1"] | c02922c33eb816eea872b4d8a3c1dc0e | NoteThe first example is illustrated by the following: For example, you can add roads ($$$6, 4$$$), ($$$7, 9$$$), ($$$1, 7$$$) to make all the cities reachable from $$$s = 1$$$.The second example is illustrated by the following: In this example, you can add any one of the roads ($$$5, 1$$$), ($$$5, 2$$$), ($$$5, 3$$$... | There are $$$n$$$ cities and $$$m$$$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way.What is the minimum number of new roads that need to be built to make all the cities reachable from the capital?New roads will also be one-way. | Print one integer β the minimum number of extra roads needed to make all the cities reachable from city $$$s$$$. If all the cities are already reachable from $$$s$$$, print 0. | The first line of input consists of three integers $$$n$$$, $$$m$$$ and $$$s$$$ ($$$1 \le n \le 5000, 0 \le m \le 5000, 1 \le s \le n$$$) β the number of cities, the number of roads and the index of the capital. Cities are indexed from $$$1$$$ to $$$n$$$. The following $$$m$$$ lines contain roads: road $$$i$$$ is given... | standard output | standard input | Python 3 | Python | 2,000 | train_016.jsonl | 02b94c121d4f3b644bf724703312d5aa | 256 megabytes | ["9 9 1\n1 2\n1 3\n2 3\n1 5\n5 6\n6 1\n1 8\n9 8\n7 1", "5 4 5\n1 2\n2 3\n3 4\n4 1"] | PASSED | from collections import defaultdict
import sys
def dfs(u):
avail[u] = False
for v in g[u]:
if avail[v]:
dfs(v)
topo.append(u)
sys.setrecursionlimit(6000)
n, m, s = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(m):
u, v = map(int, input().split())
g[u - 1].... | 1529591700 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["4 3 2 1\n5 2 4 3 1\n6 1 5 3 4 2\n1"] | 1637670255f8bd82a01e2ab20cdcc9aa | NoteIn the first test case, one of the optimal strategies is the next one: take $$$1$$$ card from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[1, 2, 3]$$$, $$$p'$$$ becomes $$$[4]$$$; take $$$1$$$ card from the top of $$$p$$$: $$$p$$$ becomes $$$[1, 2]$$$, $$$p'$$$ becomes $$$[4, 3]$$$; take $$$1... | You have a deck of $$$n$$$ cards, and you'd like to reorder it to a new one.Each card has a value between $$$1$$$ and $$$n$$$ equal to $$$p_i$$$. All $$$p_i$$$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i.Β e. $$$p_1$$$ stands for the bottom card, $$$p_n$$$ is the top card. In each step you ... | For each test case print the deck with maximum possible order. Print values of cards in the deck from bottom to top. If there are multiple answers, print any of them. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)Β β the number of test cases. The first line of each test case contains the single integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the size of deck you have. The second line contains $$$n$$$ integers $$$p_1, p_2,\dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$... | standard output | standard input | PyPy 3-64 | Python | 1,100 | train_109.jsonl | 9153a8cff9a8a4b0fa95e1499a8ea9d5 | 512 megabytes | ["4\n4\n1 2 3 4\n5\n1 5 2 4 3\n6\n4 2 5 3 6 1\n1\n1"] | PASSED | from collections import deque
t = int(input())
for klmn in range(t):
n = int(input())
used = [0 for i in range(n)]
p = list(map(int, input().split()))
ans = deque([])
dob = deque([])
m = n
le = n
while le > 0:
if used[m-1] == 0:
num = p[-1]
dob.appendleft(num)
used[num-1] = 1
p.po... | 1614071100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["3", "10"] | 35bd08a2f5350890b2a520672538d712 | NoteIn the first example, one can achieve the maximum $$$S$$$ with the following assignment: With this assignment, $$$mex(1, 2) = 0$$$, $$$mex(1, 3) = 2$$$ and $$$mex(2, 3) = 1$$$. Therefore, $$$S = 0 + 2 + 1 = 3$$$.In the second example, one can achieve the maximum $$$S$$$ with the following assignment: With this as... | INSPION FullBand Master - INSPION INSPION - IOLITE-SUNSTONEOn another floor of the A.R.C. Markland-N, the young man Simon "Xenon" Jackson, takes a break after finishing his project early (as always). Having a lot of free time, he decides to put on his legendary hacker "X" instinct and fight against the gangs of the cyb... | Print the maximum possible value of $$$S$$$Β β the number of password layers in the gangs' network. | The first line contains an integer $$$n$$$ ($$$2 \leq n \leq 3000$$$), the number of gangs in the network. Each of the next $$$n - 1$$$ lines contains integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \leq u_i, v_i \leq n$$$; $$$u_i \neq v_i$$$), indicating there's a direct link between gangs $$$u_i$$$ and $$$v_i$$$. It's guarant... | standard output | standard input | PyPy 2 | Python | 2,300 | train_065.jsonl | 93f9160eff0905e90868f8be926d0e60 | 512 megabytes | ["3\n1 2\n2 3", "5\n1 2\n1 3\n1 4\n3 5"] | PASSED | import sys
range = xrange
input = raw_input
# Read input and build the graph
inp = [int(x) for x in sys.stdin.read().split()]; ii = 0
n = inp[ii]; ii += 1
coupl = [[] for _ in range(n)]
for _ in range(n - 1):
u = inp[ii] - 1; ii += 1
v = inp[ii] - 1; ii += 1
coupl[u].append(v)
coupl[v].append(u)
# R... | 1579440900 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["YES\n2 1\n1 2"] | 1e061d8c4bff217047ddc58e88be0c3f | NoteIn the sample from the statement there is a suitable graph consisting of two vertices, connected by a single edge. | An undirected graph is called k-regular, if the degrees of all its vertices are equal k. An edge of a connected graph is called a bridge, if after removing it the graph is being split into two connected components.Build a connected undirected k-regular graph containing at least one bridge, or else state that such graph... | Print "NO" (without quotes), if such graph doesn't exist. Otherwise, print "YES" in the first line and the description of any suitable graph in the next lines. The description of the made graph must start with numbers n and m β the number of vertices and edges respectively. Each of the next m lines must contain two i... | The single line of the input contains integer k (1ββ€βkββ€β100) β the required degree of the vertices of the regular graph. | standard output | standard input | PyPy 3 | Python | 1,900 | train_036.jsonl | b7522beb4ed6f6e57bb66f80627c6b5e | 256 megabytes | ["1"] | PASSED | k = int(input())
if k % 2 == 0:
print('NO')
else:
print('YES')
reb = [[1, 2]]
for v in range(3, k + 2):
reb.append([1, v])
reb.append([v, k + 2 * v - 4])
reb.append([v, k + 2 * v - 3])
reb.append([k + 2 * v - 4, k + 2 * v - 3])
for u in range(v + 1, k + 2):
... | 1433435400 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["6\n15"] | 648ec67565c506c3e2ffd007ad44e8c3 | NoteIn the first test case, integer $$$6$$$ have following divisors: $$$[1, 2, 3, 6]$$$. There are $$$4$$$ of them and the difference between any two of them is at least $$$1$$$. There is no smaller integer with at least $$$4$$$ divisors.In the second test case, integer $$$15$$$ have following divisors: $$$[1, 3, 5, 15... | Positive integer $$$x$$$ is called divisor of positive integer $$$y$$$, if $$$y$$$ is divisible by $$$x$$$ without remainder. For example, $$$1$$$ is a divisor of $$$7$$$ and $$$3$$$ is not divisor of $$$8$$$.We gave you an integer $$$d$$$ and asked you to find the smallest positive integer $$$a$$$, such that $$$a$$$ ... | For each test case print one integer $$$a$$$Β β the answer for this test case. | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 3000$$$)Β β the number of test cases. The first line of each test case contains a single integer $$$d$$$ ($$$1 \leq d \leq 10000$$$). | standard output | standard input | Python 3 | Python | 1,000 | train_100.jsonl | 82bfeebd63c6cfa61dbf5a71fc773227 | 256 megabytes | ["2\n1\n2"] | PASSED | t = int(input())
for i in range(t):
d = int(input())
p1 = 1 + d
while True:
m = True
for j in range(2, int(p1 ** 0.5) + 1):
if p1 % j != 0:
continue
else:
m = False
break
if m != False:
b... | 1611066900 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["YES\n1\n1 3 4", "NO"] | 623f12b8c5a5c850c7edd9875af56f32 | NoteIn the first example, the array becomes $$$[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$$$. | Ksenia has an array $$$a$$$ consisting of $$$n$$$ positive integers $$$a_1, a_2, \ldots, a_n$$$. In one operation she can do the following: choose three distinct indices $$$i$$$, $$$j$$$, $$$k$$$, and then change all of $$$a_i, a_j, a_k$$$ to $$$a_i \oplus a_j \oplus a_k$$$ simultaneously, where $$$\oplus$$$ denotes... | Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $$$n$$$ operations. If it is possible, print an integer $$$m$$$ ($$$0 \leq m \leq n$$$), which denotes the number of operations you do. In each of the next $$$m$$$ lines, print three distinct integers $$$i, j, k$... | The first line contains one integer $$$n$$$ ($$$3 \leq n \leq 10^5$$$)Β β the length of $$$a$$$. The second line contains $$$n$$$ integers, $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$)Β β elements of $$$a$$$. | standard output | standard input | Python 3 | Python | 2,200 | train_017.jsonl | 6e8680c9864ea16650dbcd69703e50a4 | 256 megabytes | ["5\n4 2 1 7 2", "4\n10 4 49 22"] | PASSED | # abc means a xor b xor c
#
# a b c -> abc abc abc
#
#
# a b c d -> abc abc abc d
# -> abc d d d only YES if abc=d (abcd=0)
#
#
# a b c d e -> abc abc abc d e
# -> abc abc abcde abcde abcde
# ^ ^ ^
# -> abcde abcde abcde abcde abcde
#
#
# a b c d e f -> abc abc abc d ... | 1605278100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1.5 seconds | ["0\n3\n4\n4"] | b62586b55bcfbd616d936459c30579a6 | NoteThe resulting matrices in the first three test cases: $$$\begin{pmatrix} 1 & 1\\ 0 & 1 \end{pmatrix}$$$ $$$\begin{pmatrix} 0 & 0 & 0\\ 0 & 0 & 0 \end{pmatrix}$$$ $$$\begin{pmatrix} 1 & 0 & 1 & 1 & 1 & 1 & 1\\ 0 & 1 & 1 & 0 & 1 & 1 & 0\\ 1 &am... | You are given a matrix with $$$n$$$ rows (numbered from $$$1$$$ to $$$n$$$) and $$$m$$$ columns (numbered from $$$1$$$ to $$$m$$$). A number $$$a_{i, j}$$$ is written in the cell belonging to the $$$i$$$-th row and the $$$j$$$-th column, each number is either $$$0$$$ or $$$1$$$.A chip is initially in the cell $$$(1, 1)... | For each test case, print one integer β the minimum number of cells you have to change so that every path in the matrix is palindromic. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 200$$$) β the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 30$$$) β the dimensions of the matrix. Then $$$n$$$ lines follow, the $$$i$$$-th line contains $$$m$$$ integers $$$a_{i, 1}$$$, $$... | standard output | standard input | Python 3 | Python | 1,500 | train_003.jsonl | ab3ef230e4d2fb5592007bd0e0d9f3c7 | 256 megabytes | ["4\n2 2\n1 1\n0 1\n2 3\n1 1 0\n1 0 0\n3 7\n1 0 1 1 1 1 1\n0 0 0 0 0 0 0\n1 1 1 1 1 0 1\n3 5\n1 0 1 0 0\n1 1 1 1 0\n0 0 1 0 0"] | PASSED | # import sys
# sys.stdin = open('inputf.in','r')
#sys.stdout = open('outputf.in','w')
t = int(input())
while(t):
t -= 1
n,m = map(int, input().split(' '))
d0 = {}
d1 = {}
for i in range(1, n + 1):
l = list(map(int, input().split(' ')))
for j in range(1, m + 1):
x = i + j
if x not in d0:
d0[x] = 0
... | 1591886100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["8\n2\n4", "0\n3\n1"] | 951b6dfb8d9839857c0c8abd550e9b15 | NoteConsider the first example. In the first query of second type all characters coincide, so the answer is 8. In the second query we compare string "TTTTT..." and the substring "TGCAT". There are two matches. In the third query, after the DNA change, we compare string "TATAT..."' with substring "TGTAT". There are 4 ma... | Everyone knows that DNA strands consist of nucleotides. There are four types of nucleotides: "A", "T", "G", "C". A DNA strand is a sequence of nucleotides. Scientists decided to track evolution of a rare species, which DNA strand was string s initially. Evolution of the species is described as a sequence of changes in ... | For each scientists' query (second type query) print a single integer in a new lineΒ β the value of impact of the infection on the DNA. | The first line contains the string s (1ββ€β|s|ββ€β105) that describes the initial DNA strand. It consists only of capital English letters "A", "T", "G" and "C". The next line contains single integer q (1ββ€βqββ€β105)Β β the number of events. After that, q lines follow, each describes one event. Each of the lines has one of ... | standard output | standard input | PyPy 2 | Python | 2,100 | train_077.jsonl | 14ec79f4ed94ae56b99b0580cccc4a2f | 512 megabytes | ["ATGCATGC\n4\n2 1 8 ATGC\n2 2 6 TTT\n1 4 T\n2 2 6 TA", "GAGTTGTTAA\n6\n2 3 4 TATGGTG\n1 1 T\n1 6 G\n2 5 9 AGTAATA\n1 10 G\n2 2 6 TTGT"] | PASSED | import sys
range = xrange
input = raw_input
class segtree:
def __init__(s, data):
s.n = len(data)
s.m = 1
while s.m < s.n: s.m *= 2
s.data = [0]*s.m
s.data += data
for i in reversed(range(2, s.n + s.m)):
s.data[i >> 1] += s.data[i]
def add(s, i, x):
... | 1499791500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
4 seconds | ["1 3 6", "3 14 15 92 6"] | 584f7008e27dde53037396d2459efd84 | null | You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that: First we build by the array a an array s of partial sums, consisting of n elements. Element number i (1ββ€βiββ€βn) of array s equals . The operation xΒ modΒ y means that we take the ... | Print n integers Β β elements of the array a after the operations are applied to it. Print the elements in the order of increasing of their indexes in the array a. Separate the printed numbers by spaces. | The first line contains two space-separated integers n and k (1ββ€βnββ€β2000, 0ββ€βkββ€β109). The next line contains n space-separated integers a1,βa2,β...,βanΒ β elements of the array a (0ββ€βaiββ€β109). | standard output | standard input | PyPy 3 | Python | 1,900 | train_014.jsonl | ea7c0d005e4cc2b4aae06d7f4ff80b83 | 256 megabytes | ["3 1\n1 2 3", "5 0\n3 14 15 92 6"] | PASSED | leng, repeat=list(map(int,input().split()))
Lis = list(map(int,input().split()))
mod = 10**9 + 7
cum = [1]
ans = [0]*leng
for i in range(1, 2001):
cum.append((cum[-1] * (repeat + i - 1) * pow(i, mod-2, mod)) % mod)
for i in range(leng):
for j in range(i + 1):
ans[i] = (ans[i] + cum[i-j] * Lis[j]) % mod... | 1347809400 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["3 2", "3 4"] | 38dc16395b742f2a0e9f359a8bf33061 | NoteIn the first sample the appropriate pairs are (0,β3) and (0,β4). In the second sample the appropriate pairs are (0,β4), (1,β4), (2,β4) and (3,β4). | Petya is a beginner programmer. He has already mastered the basics of the C++ language and moved on to learning algorithms. The first algorithm he encountered was insertion sort. Petya has already written the code that implements this algorithm and sorts the given integer zero-indexed array a of size n in the non-decre... | Print two integers: the minimum number of times the swap function is executed and the number of such pairs (i,βj) that swapping the elements of the input permutation with indexes i and j leads to the minimum number of the executions. | The first line contains a single integer n (2ββ€βnββ€β5000) β the length of the permutation. The second line contains n different integers from 0 to nβ-β1, inclusive β the actual permutation. | standard output | standard input | PyPy 3 | Python | 1,900 | train_044.jsonl | 6110a275ecf73d262745aae08323ca65 | 256 megabytes | ["5\n4 0 3 1 2", "5\n1 2 3 4 0"] | PASSED | arr = [0 for i in range(5001)]
def insertion_sort(n, a):
def modify(t):
while t > 0:
arr[t] += 1
t -= t & (-t)
def query(t):
res = 0
while t < 5001:
res += arr[t]
t += t & (-t)
return res
s = 0
ans = 0
way = 0
f... | 1384443000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["YES", "YES", "NO"] | 4b352854008a9378551db60b76d33cfa | NoteIn the first example PolandBall knows much more words and wins effortlessly.In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins. | PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, if ... | In a single line of print the answerΒ β "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally. | The first input line contains two integers n and m (1ββ€βn,βmββ€β103)Β β number of words PolandBall and EnemyBall know, respectively. Then n strings follow, one per lineΒ β words familiar to PolandBall. Then m strings follow, one per lineΒ β words familiar to EnemyBall. Note that one Ball cannot know a word more than once (... | standard output | standard input | PyPy 2 | Python | 1,100 | train_002.jsonl | 60ee2f26b2117bf42c92911ad22307f8 | 256 megabytes | ["5 1\npolandball\nis\na\ncool\ncharacter\nnope", "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska", "1 2\na\na\nb"] | PASSED | n, m = [int(x) for x in raw_input().split()]
wp = set()
for _ in range(n):
wp.add(raw_input().strip())
we = set()
for _ in range(m):
we.add(raw_input().strip())
nb = len(wp & we)
np = len(wp - we)
ne = len(we - wp)
mp = (nb + 1) // 2 + np
me = nb // 2 + ne
print "YES" if mp > me else "NO"
| 1484499900 | [
"games",
"strings"
] | [
1,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["1.000000000000", "1.500000000000"] | 260666df22ee510fcce3ebdfbb8b71a2 | NoteIn the second example, the best scenario would be: one contestant fails at the first question, the other fails at the next one. The total reward will be $$$\displaystyle \frac{1}{2} + \frac{1}{1} = 1.5$$$ dollars. | 3R2 - Standby for ActionOur dear Cafe's owner, JOE Miller, will soon take part in a new game TV-show "1 vs. $$$n$$$"!The game goes in rounds, where in each round the host asks JOE and his opponents a common question. All participants failing to answer are eliminated. The show ends when only JOE remains (we assume that ... | Print a number denoting the maximum prize (in dollars) JOE could have. Your answer will be considered correct if it's absolute or relative error won't exceed $$$10^{-4}$$$. In other words, if your answer is $$$a$$$ and the jury answer is $$$b$$$, then it must hold that $$$\frac{|a - b|}{max(1, b)} \le 10^{-4}$$$. | The first and single line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$), denoting the number of JOE's opponents in the show. | standard output | standard input | Python 3 | Python | 1,000 | train_001.jsonl | 1dd1189937de9239f23e95213123b5de | 256 megabytes | ["1", "2"] | PASSED | n = int(input())
num = n
cash = 0.0
for i in range(n):
if num!=0:
cash+=1/num
num-=1
print(cash)
| 1579440900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["0\n40\n41664916690999888"] | b4b69320c6040d2d264ac32e9ba5196f | null | You are given a board of size $$$n \times n$$$, where $$$n$$$ is odd (not divisible by $$$2$$$). Initially, each cell of the board contains one figure.In one move, you can select exactly one figure presented in some cell and move it to one of the cells sharing a side or a corner with the current cell, i.e. from the cel... | For each test case print the answer β the minimum number of moves needed to get all the figures into one cell. | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 200$$$) β the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains one integer $$$n$$$ ($$$1 \le n < 5 \cdot 10^5$$$) β the size of the board. It is guaranteed that $$$n$$$ is odd (not divisible by $$$2$... | standard output | standard input | PyPy 3 | Python | 1,000 | train_004.jsonl | f0dc0e065f9ba49f75d3876417fdeb92 | 256 megabytes | ["3\n1\n5\n499993"] | PASSED |
def fun():
n=int(input())
x=0
i=3
while(i<=n):
x=int((i*i-(i-2)*(i-2))*(i-1)/2+x)
i=i+2
print(x)
t=int(input())
i=0
for i in range(t):
fun()
| 1589466900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["3", "-1", "4"] | db5a99701dabe3516f97fd172118807e | NoteIn the first sample, the path with largest value is $$$1 \to 3 \to 4 \to 5$$$. The value is $$$3$$$ because the letter 'a' appears $$$3$$$ times. | You are given a graph with $$$n$$$ nodes and $$$m$$$ directed edges. One lowercase letter is assigned to each node. We define a path's value as the number of the most frequently occurring letter. For example, if letters on a path are "abaca", then the value of that path is $$$3$$$. Your task is find a path whose value ... | Output a single line with a single integer denoting the largest value. If the value can be arbitrarily large, output -1 instead. | The first line contains two positive integers $$$n, m$$$ ($$$1 \leq n, m \leq 300\,000$$$), denoting that the graph has $$$n$$$ nodes and $$$m$$$ directed edges. The second line contains a string $$$s$$$ with only lowercase English letters. The $$$i$$$-th character is the letter assigned to the $$$i$$$-th node. Then $$... | standard output | standard input | PyPy 2 | Python | 1,700 | train_037.jsonl | ec63a955276c3bb781bee10661a10341 | 256 megabytes | ["5 4\nabaca\n1 2\n1 3\n3 4\n4 5", "6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4", "10 14\nxzyzyzyzqx\n1 2\n2 4\n3 5\n4 5\n2 6\n6 8\n6 5\n2 10\n3 9\n10 9\n4 6\n1 10\n2 8\n3 7"] | PASSED | def dfs(dp,node,edges,s,visited):
stack = [node]
while stack:
node = stack[-1]
if node not in visited:
count = 0
for kid in edges[node]:
if kid in visited:
count += 1
stack.append(kid)
if count == len(edges[... | 1517403900 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2.5 seconds | ["1", "1"] | 31d95251cd79d889ff9f0a624ef31394 | NoteThe first example corresponds to the matrix: $$$11100111$$$ $$$11100111$$$ $$$11100111$$$ $$$00000000$$$ $$$00000000$$$ $$$11100111$$$ $$$11100111$$$ $$$11100111$$$ It is easy to see that the answer on this example is $$$1$$$. | You are given a binary matrix $$$A$$$ of size $$$n \times n$$$. Let's denote an $$$x$$$-compression of the given matrix as a matrix $$$B$$$ of size $$$\frac{n}{x} \times \frac{n}{x}$$$ such that for every $$$i \in [1, n], j \in [1, n]$$$ the condition $$$A[i][j] = B[\lceil \frac{i}{x} \rceil][\lceil \frac{j}{x} \rceil]... | Print one number: maximum $$$x$$$ such that an $$$x$$$-compression of the given matrix is possible. | The first line contains one number $$$n$$$ ($$$4 \le n \le 5200$$$) β the number of rows and columns in the matrix $$$A$$$. It is guaranteed that $$$n$$$ is divisible by $$$4$$$. Then the representation of matrix follows. Each of $$$n$$$ next lines contains $$$\frac{n}{4}$$$ one-digit hexadecimal numbers (that is, thes... | standard output | standard input | PyPy 2 | Python | 1,800 | train_068.jsonl | 4f0295c75b98ab5e89f426ed61e45873 | 256 megabytes | ["8\nE7\nE7\nE7\n00\n00\nE7\nE7\nE7", "4\n7\nF\nF\nF"] | PASSED | import atexit, io, sys
# A stream implementation using an in-memory bytes
# buffer. It inherits BufferedIOBase.
buffer = io.BytesIO()
sys.stdout = buffer
# print via here
@atexit.register
def write():
sys.__stdout__.write(buffer.getvalue())
def gcd(a,b):
if(a>b):
temp=b
b=a
a=temp
if(a==0):
... | 1548516900 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["1\n5\n2"] | ab99c564f98bc6caea26b28280858c21 | NoteIn the first test case, $$$p^1 = p = [1, 3, 4, 2]$$$ and the sequence starting from $$$1$$$: $$$1, p[1] = 1, \dots$$$ is an infinite path.In the second test case, $$$p^5 = [1, 2, 3, 4, 5]$$$ and it obviously contains several infinite paths.In the third test case, $$$p^2 = [3, 6, 1, 8, 7, 2, 5, 4]$$$ and the sequenc... | You are given a colored permutation $$$p_1, p_2, \dots, p_n$$$. The $$$i$$$-th element of the permutation has color $$$c_i$$$.Let's define an infinite path as infinite sequence $$$i, p[i], p[p[i]], p[p[p[i]]] \dots$$$ where all elements have same color ($$$c[i] = c[p[i]] = c[p[p[i]]] = \dots$$$).We can also define a mu... | Print $$$T$$$ integers β one per test case. For each test case print minimum $$$k > 0$$$ such that $$$p^k$$$ has at least one infinite path. | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) β the number of test cases. Next $$$3T$$$ lines contain test cases β one per three lines. The first line contains single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the size of the permutation. The second line contains $$$n$$$ integers $$$p_... | standard output | standard input | PyPy 3 | Python | 2,200 | train_024.jsonl | 4462e4f18351498791a6cf1b45513bdd | 256 megabytes | ["3\n4\n1 3 4 2\n1 2 2 3\n5\n2 3 4 5 1\n1 2 3 4 5\n8\n7 4 5 6 1 8 3 2\n5 3 6 4 7 5 8 4"] | PASSED | import sys
input = lambda: sys.stdin.readline().rstrip()
from math import sqrt
def primeFactor(n):
ret, i, d, sq = {}, 2, 2, int(sqrt(n)) + 1
while i < 4:
k = 0
while n % i == 0:
n, k = n//i, k+1
ret[i], sq = k, int(sqrt(n)) + 1
i = i * 2 - 1
while i <= sq:
... | 1584974100 | [
"number theory",
"math",
"graphs"
] | [
0,
0,
1,
1,
1,
0,
0,
0
] | |
3 seconds | ["YES\n1\n1\n0", "NO", "YES\n1\n2\n0", "YES\n1\n4\n1\n156"] | 0ef5e0621f13107d0c8786766ae2ac56 | null | Berland scientists noticed long ago that the world around them depends on Berland population. Due to persistent research in this area the scientists managed to find out that the Berland chronology starts from the moment when the first two people came to that land (it is considered to have happened in the first year). A... | On the first output line print YES, if there could be a year in which the total population of the country equaled A, otherwise print NO. If the answer is YES, then you also have to print number k β the number of years in which the population could equal A. On the next line you have to output precisely k space-separate... | The first line contains integer A (1ββ€βAβ<β10300). It is guaranteed that the number doesn't contain leading zeros. | standard output | standard input | Python 3 | Python | 2,600 | train_006.jsonl | 3c215cb03465bf6ce217e8bfe929c854 | 256 megabytes | ["2", "3", "13", "1729"] | PASSED | a = int(input())
ans = set()
def work(i, z, y):
z.add(y)
# print(">>", i, y)
if y == a:
ans.add(i)
if len(z) > 1000:
z.remove(max(z))
pos = [set(), set([2])]
for i in range(2):
for x in pos[i]:
if x == a:
ans.add(i)
def dfs(i, last, cur):
if i > 988:
... | 1288972800 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["2", "10"] | 3b42ca8bf066e9c5b6f5ff822cdc9214 | NoteThe first example can be solved by transposing the graph and moving the token to vertex $$$4$$$, taking $$$2$$$ seconds.The best way to solve the second example is the following: transpose the graph, move the token to vertex $$$2$$$, transpose the graph again, move the token to vertex $$$3$$$, transpose the graph o... | You are given a directed graph of $$$n$$$ vertices and $$$m$$$ edges. Vertices are numbered from $$$1$$$ to $$$n$$$. There is a token in vertex $$$1$$$.The following actions are allowed: Token movement. To move the token from vertex $$$u$$$ to vertex $$$v$$$ if there is an edge $$$u \to v$$$ in the graph. This action... | Print one integer: the minimum required time modulo $$$998\,244\,353$$$. | The first line of input contains two integers $$$n, m$$$ ($$$1 \le n, m \le 200\,000$$$). The next $$$m$$$ lines contain two integers each: $$$u, v$$$ ($$$1 \le u, v \le n; u \ne v$$$), which represent the edges of the graph. It is guaranteed that all ordered pairs $$$(u, v)$$$ are distinct. It is guaranteed that it is... | standard output | standard input | Python 3 | Python | 2,400 | train_020.jsonl | ac9b1fe8dc6cbe624a860dabccc1da64 | 512 megabytes | ["4 4\n1 2\n2 3\n3 4\n4 1", "4 3\n2 1\n2 3\n4 3"] | PASSED | from heapq import heappush, heappop;mod = 998244353;N, M = map(int, input().split());E1 = [[] for _ in range(N)];E2 = [[] for _ in range(N)]
for _ in range(M):u, v = map(int, input().split());u -= 1;v -= 1;E1[u].append(v);E2[v].append(u)
mask1 = (1<<23) - 1;mask2 = (1<<18) - 1;inf = 1<<62;dist = [inf] * (1<<23);start =... | 1604327700 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["8 4 2 1 \n5 2 1 3 4 5 5 \n101 1 \n4 3 2 2 3 4 \n7 1 4 2 3 4 5 1"] | 64458fc3c2bf40ca911b566092f544e8 | null | You are given an array $$$a$$$ consisting of $$$n$$$ nonnegative integers. Let's define the prefix OR array $$$b$$$ as the array $$$b_i = a_1~\mathsf{OR}~a_2~\mathsf{OR}~\dots~\mathsf{OR}~a_i$$$, where $$$\mathsf{OR}$$$ represents the bitwise OR operation. In other words, the array $$$b$$$ is formed by computing the $$... | For each test case print $$$n$$$ integers β any rearrangement of the array $$$a$$$ that obtains the lexicographically maximum prefix OR array. | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) β the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) β the length of the array $$$a$$$. The second line of each test c... | standard output | standard input | PyPy 3-64 | Python | 1,500 | train_099.jsonl | 309763d395e83373324228c487df8ea2 | 256 megabytes | ["5\n\n4\n\n1 2 4 8\n\n7\n\n5 1 2 3 4 5 5\n\n2\n\n1 101\n\n6\n\n2 3 4 2 3 4\n\n8\n\n1 4 2 3 4 5 7 1"] | PASSED | import sys
input = lambda: sys.stdin.readline().rstrip()
# ----------------------- #
def main():
n = int(input())
A = tuple(map(int, input().split()))
B = []
seen = [False] * n
ok_bit = set()
for i in range(29, -1, -1):
if i in ok_bit:
continue
bits = [[a, j] for j, a in enum... | 1665671700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["10", "996"] | 1d58ae45a677023dc8fd6c9473a89737 | NoteFor the first test, two examples of good subsequences are $$$[2, 7]$$$ and $$$[2, 2, 4, 7]$$$:For $$$b = [2, 7]$$$ we can use $$$(-3, -4)$$$ as the first sequence and $$$(-2, -1, \ldots, 4)$$$ as the second. Note that subsequence $$$[2, 7]$$$ appears twice in $$$[2, 2, 4, 7]$$$, so we have to count it twice. Green... | Lee couldn't sleep lately, because he had nightmares. In one of his nightmares (which was about an unbalanced global round), he decided to fight back and propose a problem below (which you should solve) to balance the round, hopefully setting him free from the nightmares.A non-empty array $$$b_1, b_2, \ldots, b_m$$$ is... | Print a single integerΒ β the number of nonempty good subsequences of $$$a$$$, modulo $$$10^9 + 7$$$. | The first line contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$)Β β the size of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$)Β β elements of the array. | standard output | standard input | PyPy 3-64 | Python | 2,000 | train_085.jsonl | a8a6ae1c973ecdb434f85d251e5d1b11 | 256 megabytes | ["4\n2 2 4 7", "10\n12391240 103904 1000000000 4142834 12039 142035823 1032840 49932183 230194823 984293123"] | PASSED | import sys
input = sys.stdin.readline
n = int(input().split('\n')[0])
a = [int(x) for x in input().split()]
o = [x for x in a if x%2 == 1]
e = [x for x in a if x%2 == 0]
ans = 0
ans += 2**(len(e))*(2**(len(o))-1)
while len(e)>=2:
o = [x//2 for x in e if (x//2)%2==1]
e = [x//2 for x in e if (x... | 1637678100 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["2.000000000000000000", "0.500000000000000000", "3.333333333333333333"] | 7bdd8f0cf42855bebda4ccc56d8fe788 | NoteIn the first example it is necessary to put weights like this: It is easy to see that the diameter of this tree is $$$2$$$. It can be proved that it is the minimum possible diameter.In the second example it is necessary to put weights like this: | You are given a tree (an undirected connected graph without cycles) and an integer $$$s$$$.Vanya wants to put weights on all edges of the tree so that all weights are non-negative real numbers and their sum is $$$s$$$. At the same time, he wants to make the diameter of the tree as small as possible.Let's define the dia... | Print the minimum diameter of the tree that Vanya can get by placing some non-negative real weights on its edges with the sum equal to $$$s$$$. Your answer will be 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$$$. ... | The first line contains two integer numbers $$$n$$$ and $$$s$$$ ($$$2 \leq n \leq 10^5$$$, $$$1 \leq s \leq 10^9$$$) β the number of vertices in the tree and the sum of edge weights. Each of the following $$$nβ1$$$ lines contains two space-separated integer numbers $$$a_i$$$ and $$$b_i$$$ ($$$1 \leq a_i, b_i \leq n$$$,... | standard output | standard input | Python 3 | Python | 1,700 | train_019.jsonl | b693d62494d48d4dac2458e83a325761 | 256 megabytes | ["4 3\n1 2\n1 3\n1 4", "6 1\n2 1\n2 3\n2 5\n5 4\n5 6", "5 5\n1 2\n2 3\n3 4\n3 5"] | PASSED | n,s = [int(x) for x in input().split()]
v=[ [] ]
for i in range(n):
v.append([])
for i in range(n-1):
a, b =[int(x) for x in input().split()]
v[a].append(b)
v[b].append(a)
ans =0
for i in range(1,n+1):
if len(v[i])==1:
ans+=1
print(2*s/ans)
| 1545572100 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
3 seconds | ["YES\n2 1\n2 3\n3 4", "YES\n1 2\n1 3\n4 1", "NO"] | 0cfaaa70b7990e4f170eb397cd8756f8 | NoteThe picture corresponding to the first and second examples: The picture corresponding to the third example: | You are given an undirected unweighted connected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. It is guaranteed that there are no self-loops or multiple edges in the given graph.Your task is to find any spanning tree of this graph such that the degree of the first vertex (vertex with label $$$1$$$ on it) is e... | If there is no spanning tree satisfying the condition from the problem statement, print "NO" in the first line. Otherwise print "YES" in the first line and then print $$$n-1$$$ lines describing the edges of a spanning tree such that the degree of the first vertex (vertex with label $$$1$$$ on it) is equal to $$$D$$$. M... | The first line contains three integers $$$n$$$, $$$m$$$ and $$$D$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$n - 1 \le m \le min(2 \cdot 10^5, \frac{n(n-1)}{2}), 1 \le D < n$$$) β the number of vertices, the number of edges and required degree of the first vertex, respectively. The following $$$m$$$ lines denote edges: e... | standard output | standard input | PyPy 2 | Python | 1,900 | train_006.jsonl | 22953516921e89fcc3812eb5129415a5 | 256 megabytes | ["4 5 1\n1 2\n1 3\n1 4\n2 3\n3 4", "4 5 3\n1 2\n1 3\n1 4\n2 3\n3 4", "4 4 3\n1 2\n1 4\n2 3\n3 4"] | PASSED | from sys import stdin
from io import BytesIO
class disjointset:
def __init__(self, n):
self.rank, self.parent, self.n = [0] * (n + 1), [i for i in range(n + 1)], n
def find(self, x):
xcopy = x
while x != self.parent[x]:
x = self.parent[x]
while xcopy != x:
... | 1551971100 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["NO\nNO\nNO\nYES\nYES\nYES\nYES\nNO"] | b3c08abbaeec9ecbcc71fe34336d039a | null | A wild basilisk just appeared at your doorstep. You are not entirely sure what a basilisk is and you wonder whether it evolved from your favorite animal, the weasel. How can you find out whether basilisks evolved from weasels? Certainly, a good first step is to sequence both of their DNAs. Then you can try to check whe... | For each test case, print YES if there is a sequence of mutations to get from $$$u$$$ to $$$v$$$ and NO otherwise. | Each test contains multiple test cases. The first line contains an integer $$$t$$$ ($$$1\le t\le 100$$$) β the number of test cases. The descriptions of the $$$t$$$ test cases follow. The first line of each test case contains a string $$$u$$$ ($$$1\le |u|\le 200$$$) β the DNA of the weasel. The second line of each test... | standard output | standard input | PyPy 3 | Python | -1 | train_085.jsonl | 26b502e1ada23435d429648113436a7f | 256 megabytes | ["8\n\nA\n\nB\n\nB\n\nC\n\nC\n\nA\n\nAA\n\nBB\n\nBB\n\nCC\n\nCC\n\nAA\n\nABAB\n\nBCBC\n\nABC\n\nCBA"] | PASSED |
strings = ['AA', 'BB', 'CC', 'ABAB', 'BCBC']
reduction = [['AA', ''], ['BB', ''], ['CC', ''], ['ABAB', ''], ['BCBC', ''],
['CB', 'BC'], ['AB', 'BA']] # move all Bs left
# def simulator():
# s = 'CA'
# # get all possible outcomes from s
# l = len(s)
# vi = set()
# vi.add(s)
... | 1650798300 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["1", "-1", "0.666667"] | ffafd385ec79aa28b8d30224baf6bcfe | NoteIn the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department.In the second example, there are not enough players.In the third example, there are three possi... | As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different ... | Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10β-β6. | The first line contains three integers n, m and h (1ββ€βnββ€β100,β1ββ€βmββ€β1000,β1ββ€βhββ€βm) β the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly. The second line contains a single-space-separated list of m integers si (1ββ€βsiββ€β100), denoting the number of stud... | standard output | standard input | Python 2 | Python | 1,600 | train_022.jsonl | cb1224ae076041cad9c68790088ed1d2 | 256 megabytes | ["3 2 1\n2 1", "3 2 1\n1 1", "3 2 1\n2 2"] | PASSED | from fractions import *
def C(n, k):
res = 1
for i in xrange(1, k+1):
res = res*(n-i+1)/i
return res
def calc(a, b, n):
s = a + b
if s < n:
return -1
if b == 0:
return 0
good = 0
for i in xrange(0, min(a+1, n)):
good += C(a, i)*C(b, n-i)
return float(Fraction(good, C(s, n)))
n, m... | 1314111600 | [
"probabilities",
"math"
] | [
0,
0,
0,
1,
0,
1,
0,
0
] | |
4 seconds | ["Yes\n3 2\n1 3", "Yes\n1 3\n5 7\n3 2\n7 4\n2 4\n6 1"] | 40720fb6da02d5da97df2b90719c5559 | null | You are given an undirected connected graph consisting of n vertices and m edges. There are no loops and no multiple edges in the graph.You are also given two distinct vertices s and t, and two values ds and dt. Your task is to build any spanning tree of the given graph (note that the graph is not weighted), such that ... | If the answer doesn't exist print "No" (without quotes) in the only line of the output. Otherwise, in the first line print "Yes" (without quotes). In the each of the next (nβ-β1) lines print two integers β the description of the edges of the spanning tree. Each of the edges of the spanning tree must be printed exactly... | The first line of the input contains two integers n and m (2ββ€βnββ€β200β000, 1ββ€βmββ€βmin(400β000,βnΒ·(nβ-β1)β/β2))Β β the number of vertices and the number of edges in the graph. The next m lines contain the descriptions of the graph's edges. Each of the lines contains two integers u and v (1ββ€βu,βvββ€βn, uββ βv)Β β the end... | standard output | standard input | Python 2 | Python | 2,300 | train_041.jsonl | de58341e427c6aace0631df40ebec0df | 256 megabytes | ["3 3\n1 2\n2 3\n3 1\n1 2 1 1", "7 8\n7 4\n1 3\n5 4\n5 7\n3 2\n2 4\n6 1\n1 2\n6 4 1 4"] | PASSED | n, m = map(int, raw_input().split(" "))
edge = (map(int, raw_input().split(" ")) for i in xrange(m))
mapuv = [[] for i in xrange(n + 1)]
for u, v in edge:
mapuv[u].append(v)
mapuv[v].append(u)
#print mapuv
s, t, ds, dt = map(int, raw_input().split(" "))
colors = [-1 for i in xrange(n + 1)]
total_color = 0
ans =... | 1475494500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["5.0000000000"] | 979e1b735d1c152d01955e27ee8d0b8a | NoteFollowing image describes initial position in the first sample case: | And while Mishka is enjoying her trip...Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend.Once walking with his friend, John gave Chris the following problem:At... | Print the single real tΒ β the time the pedestrian needs to croos the road and not to be hit by the bus. The answer is considered correct if its relative or absolute error doesn't exceed 10β-β6. | The first line of the input contains four integers n, w, v, u (3ββ€βnββ€β10β000, 1ββ€βwββ€β109, 1ββ€βv,ββuββ€β1000)Β β the number of the bus polygon vertices, road width, bus speed and pedestrian speed respectively. The next n lines describes polygon vertices in counter-clockwise order. i-th of them contains pair of integers ... | standard output | standard input | Python 2 | Python | 2,100 | train_059.jsonl | 997f6f1659afdef199bae92a9522756c | 256 megabytes | ["5 5 1 2\n1 2\n3 1\n4 3\n3 4\n1 4"] | PASSED | n,w,v,u = map(int,raw_input().split(' '))
later = []
flag = True
for i in range(n):
p = map(int,raw_input().split(' '))
if p[0] >= 0:
reach = p[0]/float(v)
if p[1] > u*reach:
flag = False
if p[1] <= u*reach:
later.append((reach,p[1]))
if p[0] < 0:
flag... | 1470323700 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
1 second | ["Mike\nJoe"] | 0a187d80fdc3df579909840e9111ac7e | NoteIn the first test case, Mike just takes all $$$37$$$ stones on his first turn.In the second test case, Joe can just copy Mike's moves every time. Since Mike went first, he will hit $$$0$$$ on the first pile one move before Joe does so on the second pile. | Mike and Joe are playing a game with some stones. Specifically, they have $$$n$$$ piles of stones of sizes $$$a_1, a_2, \ldots, a_n$$$. These piles are arranged in a circle.The game goes as follows. Players take turns removing some positive number of stones from a pile in clockwise order starting from pile $$$1$$$. For... | For each test case print the winner of the game, either "Mike" or "Joe" on its own line (without quotes). | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 50$$$) Β β the number of piles. The second line contains $$$n$$$ integers $$... | standard output | standard input | Python 3 | Python | 1,000 | train_089.jsonl | a67d50e5bc9c80d7addf97de7762ab8a | 256 megabytes | ["2\n\n1\n\n37\n\n2\n\n100 100"] | PASSED | t = int(input())
ar = [[] for i in range(t)]
p1, p2 = 'Mike', 'Joe'
for i in range(t):
n = int(input())
ar[i] += [int(o) for o in input().split()]
for i in range(t):
if (len(ar[i]) % 2 == 1):
print("Mike")
else:
smallest = 0
for j in range(len(ar[i])):
... | 1655562900 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
7 seconds | ["5927", "24812", "25267"] | 88607047027bab73ea56352969b02242 | NoteIn the first example, any two events form a line, and the table will be winning if any two events happen. The probability of this is $$$\frac{11}{16}$$$, and $$$5927 \cdot 16 \equiv 11 \pmod{31\,607}$$$. | Getting ready for VK Fest 2021, you prepared a table with $$$n$$$ rows and $$$n$$$ columns, and filled each cell of this table with some event related with the festival that could either happen or not: for example, whether you will win a prize on the festival, or whether it will rain.Forecasting algorithms used in VK h... | Print the probability that your table will be winning, modulo $$$31\,607$$$. Formally, let $$$M = 31\,607$$$. It can be shown that the answer can be expressed as an irreducible fraction $$$\frac{p}{q}$$$, where $$$p$$$ and $$$q$$$ are integers and $$$q \not \equiv 0 \pmod{M}$$$. Output the integer equal to $$$p \cdot q... | The first line contains a single integer $$$n$$$Β ($$$2 \le n \le 21$$$)Β β the dimensions of the table. The $$$i$$$-th of the next $$$n$$$ lines contains $$$n$$$ integers $$$a_{i, 1}, a_{i, 2}, \ldots, a_{i, n}$$$ ($$$0 < a_{i, j} < 10^4$$$). The probability of event in cell $$$(i, j)$$$ to happen is $$$a_{i, j} \... | standard output | standard input | PyPy 3 | Python | 2,600 | train_105.jsonl | 5ebb98f747554df336d581b08b363fe3 | 512 megabytes | ["2\n5000 5000\n5000 5000", "2\n2500 6000\n3000 4000", "3\n1000 2000 3000\n4000 5000 6000\n7000 8000 9000"] | PASSED | import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import gcd,log
input = lambda :sys.stdin.readline().rstrip()
def cmb(n, r, mod):
if r < 0 or r > n:return 0
r = min(r, n-r);return g1[n] * g2[r] * g2... | 1626532500 | [
"probabilities",
"math"
] | [
0,
0,
0,
1,
0,
1,
0,
0
] | |
1 second | ["8\n11\n19\n1\n3999999999987"] | 2a4f4c91522d83bc8f1ca2f086d24c3c | NoteFor $$$n = 5$$$ we calculate unfairness of the following sequence (numbers from $$$0$$$ to $$$5$$$ written in binary with extra leading zeroes, so they all have the same length): $$$000$$$ $$$001$$$ $$$010$$$ $$$011$$$ $$$100$$$ $$$101$$$ The differences are equal to $$$1$$$, $$$2$$$, $$$1$$$, $$$3$$$, $$$1$... | The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills.The boy is now looking at the ratings of consecutive participants... | Output $$$t$$$ lines. For each test case, you should output a single line with one integerΒ β the unfairness of the contest if the rating sequence equals to $$$0$$$, $$$1$$$, ..., $$$n - 1$$$, $$$n$$$. | The input consists of multiple test cases. The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10\,000$$$)Β β the number of test cases. The following $$$t$$$ lines contain a description of test cases. The first and only line in each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^{18})$$$. | standard output | standard input | PyPy 3 | Python | 1,400 | train_002.jsonl | 82ef88cc10c290a6b20ff966fae3efdf | 256 megabytes | ["5\n5\n7\n11\n1\n2000000000000"] | PASSED | t = int(input())
for iteration in range(0, t):
n = int(input())
res = 0
for _pow in range(0, 65):
if (n + 1) % (1 << _pow) == 0:
res += (n + 1) // (1 << _pow) - 1
else:
res += (n + 1) // (1 << _pow)
print(res)
| 1591281300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["6 7\n14 21\n2 4\n-1 -1"] | e8ba3fb95800806465386ecbfbe924e9 | null | Let $$$LCM(x, y)$$$ be the minimum positive integer that is divisible by both $$$x$$$ and $$$y$$$. For example, $$$LCM(13, 37) = 481$$$, $$$LCM(9, 6) = 18$$$.You are given two integers $$$l$$$ and $$$r$$$. Find two integers $$$x$$$ and $$$y$$$ such that $$$l \le x < y \le r$$$ and $$$l \le LCM(x, y) \le r$$$. | For each test case, print two integers: if it is impossible to find integers $$$x$$$ and $$$y$$$ meeting the constraints in the statement, print two integers equal to $$$-1$$$; otherwise, print the values of $$$x$$$ and $$$y$$$ (if there are multiple valid answers, you may print any of them). | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10000$$$) β the number of test cases. Each test case is represented by one line containing two integers $$$l$$$ and $$$r$$$ ($$$1 \le l < r \le 10^9$$$). | standard output | standard input | Python 3 | Python | 800 | train_003.jsonl | 66d97768b57188dcf4a32970c11aec51 | 256 megabytes | ["4\n1 1337\n13 69\n2 4\n88 89"] | PASSED |
# def hcf(a,b):
# if(b==0):
# return a
# else:
# return hcf(b,a%b)
#
#
# def lcm(a,b):
# return (a*b)//hcf(a,b)
#
# x=int(input())
# for i in range(x):
# a,b=map(int,input().split())
# for i in range(a,b+1):
# for j in range(a+1,b+1):
# if(lcm(i,j)*2<=r):
# ... | 1596033300 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
3 seconds | ["1", "3"] | f14e81618a81946dcaab281e1aa1ff9f | NoteIn the first example, the only pair of points $$$(-3, 0)$$$, $$$(3, 0)$$$ is suitable. The distance to the segment between these points from the points $$$(0, 1)$$$ and $$$(0, -1)$$$ is equal to $$$1$$$, which is less than $$$R=2$$$.In the second example, all possible pairs of points are eligible. | You are given $$$n$$$ distinct points $$$p_1, p_2, \ldots, p_n$$$ on the plane and a positive integer $$$R$$$. Find the number of pairs of indices $$$(i, j)$$$ such that $$$1 \le i < j \le n$$$, and for every possible $$$k$$$ ($$$1 \le k \le n$$$) the distance from the point $$$p_k$$$ to the segment between points $... | Print the number of suitable pairs $$$(i, j)$$$. | The first line contains two integers $$$n$$$, $$$R$$$ ($$$1 \le n \le 3000$$$, $$$1 \le R \le 10^5$$$)Β β the number of points and the maximum distance between a point and a segment. Each of the next $$$n$$$ lines contains two integers $$$x_i$$$, $$$y_i$$$ ($$$-10^5 \le x_i, y_i \le 10^5$$$) that define the $$$i$$$-th p... | standard output | standard input | PyPy 3-64 | Python | 3,200 | train_109.jsonl | cfc06de167e0e52f03ba1a2731a85256 | 256 megabytes | ["4 2\n0 1\n0 -1\n3 0\n-3 0", "3 3\n1 -1\n-1 -1\n0 1"] | PASSED | from math import atan2, asin
def dist(a, b):
return ((a[0]-b[0])**2 + (a[1]-b[1])**2)**0.5
def check(R, p, i, dp):
left, right = float("-inf"), float("inf")
for j in range(len(p)):
if j == i:
continue
d = dist(p[i], p[j])
if R >= d:
continue
... | 1636869900 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["5", "16", "18"] | e52ec2fa5bcf5d2027d57b0694b4e15a | NoteIn the first example it is possible to connect $$$1$$$ to $$$2$$$ using special offer $$$2$$$, and then $$$1$$$ to $$$3$$$ without using any offers.In next two examples the optimal answer may be achieved without using special offers. | You are given an undirected graph consisting of $$$n$$$ vertices. A number is written on each vertex; the number on vertex $$$i$$$ is $$$a_i$$$. Initially there are no edges in the graph.You may add some edges to this graph, but you have to pay for them. The cost of adding an edge between vertices $$$x$$$ and $$$y$$$ i... | Print one integer β the minimum number of coins you have to pay to make the graph connected. | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le m \le 2 \cdot 10^5$$$) β the number of vertices in the graph and the number of special offers, respectively. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^{12}$$$) β the numbers... | standard output | standard input | Python 3 | Python | 1,900 | train_000.jsonl | d045b0ecd6aaad78a2574780f55d22a1 | 256 megabytes | ["3 2\n1 3 3\n2 3 5\n2 1 1", "4 0\n1 3 3 7", "5 4\n1 2 3 4 5\n1 2 8\n1 3 10\n1 4 7\n1 5 15"] | PASSED | def read_nums():
return [int(x) for x in input().split()]
class UnionFind:
def __init__(self, size):
self._parents = list(range(size))
# number of elements rooted at i
self._sizes = [1 for _ in range(size)]
def _root(self, a):
while a != self._parents[a]:
self... | 1545921300 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
3 seconds | ["2", "3"] | 941ef8c3dd64e269d18fc4dfce7165e0 | null | Masha lives in a country with $$$n$$$ cities numbered from $$$1$$$ to $$$n$$$. She lives in the city number $$$1$$$. There is a direct train route between each pair of distinct cities $$$i$$$ and $$$j$$$, where $$$i \neq j$$$. In total there are $$$n(n-1)$$$ distinct routes. Every route has a cost, cost for route from ... | Output a single integerΒ β total cost of the cheapest Masha's successful journey. | First line of input had two integer numbers $$$n,k$$$ ($$$2 \leq n \leq 80; 2 \leq k \leq 10$$$): number of cities in the country and number of routes in Masha's journey. It is guaranteed that $$$k$$$ is even. Next $$$n$$$ lines hold route descriptions: $$$j$$$-th number in $$$i$$$-th line represents the cost of route ... | standard output | standard input | PyPy 2 | Python | 2,300 | train_025.jsonl | 53b279a96dc2e892e5ca3de827c4f349 | 256 megabytes | ["5 8\n0 1 2 2 0\n0 0 1 1 2\n0 1 0 0 0\n2 1 1 0 0\n2 0 1 2 0", "3 2\n0 1 1\n2 0 1\n2 2 0"] | PASSED | import sys
range = xrange
input = raw_input
n,k = [int(x) for x in input().split()]
inp = [int(x) for x in sys.stdin.read().split()]; ii = 0
mat = [[] for _ in range(n)]
for i in range(n):
for j in range(n):
mat[j].append(inp[i*n + j])
inf = 10**9 + 100
def randomer(odd, even):
best = [inf]*n
be... | 1582473900 | [
"probabilities",
"graphs"
] | [
0,
0,
1,
0,
0,
1,
0,
0
] | |
2 seconds | ["IMPROVE\n4 4\nIMPROVE\n1 1\nOPTIMAL\nOPTIMAL\nOPTIMAL"] | 38911652b3c075354aa8adb2a4c6e362 | NoteThe first test case is depicted in the statement. Adding the fourth kingdom to the list of the fourth daughter makes her marry the prince of the fourth kingdom.In the second test case any new entry will increase the number of marriages from $$$0$$$ to $$$1$$$.In the third and the fourth test cases there is no way t... | The King of Berland Polycarp LXXXIV has $$$n$$$ daughters. To establish his power to the neighbouring kingdoms he wants to marry his daughters to the princes of these kingdoms. As a lucky coincidence there are $$$n$$$ other kingdoms as well.So Polycarp LXXXIV has enumerated his daughters from $$$1$$$ to $$$n$$$ and the... | For each test case print the answer to it. Print "IMPROVE" in the first line if Polycarp LXXXIV can add some kingdom to some of his daughter's list so that the total number of married couples increases. The second line then should contain two integers β the index of the daughter and the index of the kingdom Polycarp LX... | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) β the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) β the number of daughters and the number of kingdoms. Each of the next $$$n$$$ lines contains ... | standard output | standard input | Python 3 | Python | 1,200 | train_013.jsonl | 39330a33b699704969083e7f98b9044f | 256 megabytes | ["5\n4\n2 2 3\n2 1 2\n2 3 4\n1 3\n2\n0\n0\n3\n3 1 2 3\n3 1 2 3\n3 1 2 3\n1\n1 1\n4\n1 1\n1 2\n1 3\n1 4"] | PASSED | import math
from collections import defaultdict
for _ in range(int(input())):
n=int(input())
d=defaultdict(int)
used=[False]*n
noUsed=[]
q=0
for i in range(n):
a=[int(i) for i in input().split()]
b=a[1:]
f=0
for j in b:
if used[j-1]==False:
... | 1584974100 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["0\n1\n16\n1"] | b5985b619652e606ac96554ecfb9346a | NoteIn the first test case, we don't need to add any element because the arithmetic mean of the array is already $$$1$$$, so the answer is $$$0$$$.In the second test case, the arithmetic mean is not $$$1$$$ initially so we need to add at least one more number. If we add $$$0$$$ then the arithmetic mean of the whole arr... | An array $$$b$$$ of length $$$k$$$ is called good if its arithmetic mean is equal to $$$1$$$. More formally, if $$$$$$\frac{b_1 + \cdots + b_k}{k}=1.$$$$$$Note that the value $$$\frac{b_1+\cdots+b_k}{k}$$$ is not rounded up or down. For example, the array $$$[1,1,1,2]$$$ has an arithmetic mean of $$$1.25$$$, which is n... | For each test case, output a single integer β the minimum number of non-negative integers you have to append to the array so that the arithmetic mean of the array will be exactly $$$1$$$. | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) β the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$) β the length of the initial array $$$a$$$. The second line of each test case contains $$$n$$... | standard output | standard input | PyPy 3-64 | Python | 800 | train_084.jsonl | c78ab82d9f2ea4425a25d262cd9256d9 | 256 megabytes | ["4\n3\n1 1 1\n2\n1 2\n4\n8 4 6 2\n1\n-2"] | PASSED | from functools import reduce
import sys
from os import path
if(path.exists('input.txt')):
sys.stdin = open("input.txt", 'r')
sys.stdout = open("output.txt", 'w')
input = iter(sys.stdin.readlines())
n = int(next(input))
for _ in range(n):
l = int(next(input))
a = (int(i) for i in next(i... | 1624026900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["? 1 2\n\n? 12 4\n\n! 4\n? 2000000000 1999999999\n\n! 1000000000"] | 442015fe13f7f75876d7163f438960d8 | NoteThe first hidden number is $$$4$$$, that's why the answers for the queries are:"? 1 2"Β β $$$\gcd(4 + 1, 4 + 2) = \gcd(5, 6) = 1$$$."? 12 4"Β β $$$\gcd(4 + 12, 4 + 4) = \gcd(16, 8) = 8$$$.The second hidden number is $$$10^9$$$, that's why the answer for the query is:"? 2000000000 1999999999"Β β $$$\gcd(3 \cdot 10^9, 3... | This is an interactive problem.There is a positive integer $$$1 \le x \le 10^9$$$ that you have to guess.In one query you can choose two positive integers $$$a \neq b$$$. As an answer to this query you will get $$$\gcd(x + a, x + b)$$$, where $$$\gcd(n, m)$$$ is the greatest common divisor of the numbers $$$n$$$ and $$... | null | The first line of input contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) denoting the number of test cases. The integer $$$x$$$ that you have to guess satisfies the constraints: ($$$1 \le x \le 10^9$$$). | standard output | standard input | Python 3 | Python | 2,000 | train_096.jsonl | d84f7b54b5f8bdc02ef65d0d65f2640f | 256 megabytes | ["2\n\n1\n\n8\n\n\n1"] | PASSED | if True:
from math import gcd
from sys import stdout
t = int(input())
for _ in range(t):
num = 0
for i in range(30):
print(f'? {2**i-num} {3*2**i-num}')
stdout.flush()
if int(input()) == 2**(i+1):
num += 2**i
print(f'... | 1649428500 | [
"number theory",
"math",
"games"
] | [
1,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["5\n3\n3\n1999999999000000000"] | 4df38c9b42b0f0963a121829080d3571 | NoteIn the first example the first participant starts at $$$0$$$ and finishes at time $$$5$$$. By that time the second and the third participants start, so the dissatisfaction of the first participant is $$$2$$$. The second participant starts at time $$$2$$$ and finishes at time $$$7$$$. By that time the third the four... | There are $$$n$$$ people participating in some contest, they start participating in $$$x$$$ minutes intervals. That means the first participant starts at time $$$0$$$, the second participant starts at time $$$x$$$, the thirdΒ β at time $$$2 \cdot x$$$, and so on.Duration of contest is $$$t$$$ minutes for each participan... | Print $$$k$$$ lines, in the $$$i$$$-th line print the total dissatisfaction of participants in the $$$i$$$-th test case. | The first line contains a single integer $$$k$$$ ($$$1 \le k \le 1000$$$)Β β the number of test cases. Each of the next $$$k$$$ lines contains three integers $$$n$$$, $$$x$$$, $$$t$$$ ($$$1 \le n, x, t \le 2 \cdot 10^9$$$)Β β the number of participants, the start interval and the contest duration. | standard output | standard input | Python 3 | Python | 1,000 | train_096.jsonl | 825ec541fe94fdd049cf75b74ad3cb5e | 256 megabytes | ["4\n4 2 5\n3 1 2\n3 3 10\n2000000000 1 2000000000"] | PASSED |
def main():
test_case = int(input())
for i in range(0, test_case):
inputs = tuple(map(int, input().split()))
n = inputs[0]
x = inputs[1]
t = inputs[2]
f = t // x
if n < f:
f = n
sum = (2*n*f - f**2 - f)//2
... | 1624183500 | [
"geometry",
"math"
] | [
0,
1,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1.5000000000000", "2.6666666666667"] | 2cd5807e3f9685d4eff88f2283904f0d | null | While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly $$$H$$$ centimeters above the water surface. Inessa grabbed the flower and sailed the distance of $$$L$$$ centimeters. Exactly at this point the flower touched the ... | Print a single numberΒ β the depth of the lake at point $$$A$$$. The absolute or relative error should not exceed $$$10^{-6}$$$. Formally, let your answer be $$$A$$$, and the jury's answer be $$$B$$$. Your answer is accepted if and only if $$$\frac{|A - B|}{\max{(1, |B|)}} \le 10^{-6}$$$. | The only line contains two integers $$$H$$$ and $$$L$$$ ($$$1 \le H < L \le 10^{6}$$$). | standard output | standard input | Python 3 | Python | 1,000 | train_000.jsonl | aaf31816c1b7efb05e590ad2ecde2230 | 256 megabytes | ["1 2", "3 5"] | PASSED | from math import sqrt
h, l = map(int, input().split())
print((l * l - h * h) / (2 * h)) | 1564497300 | [
"geometry",
"math"
] | [
0,
1,
0,
1,
0,
0,
0,
0
] | |
1 second | ["0\n2 1 4", "1\n1 1"] | 4c387ab2a0d028141634ade32ae97d03 | NoteIn the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and ... | Petya has n integers: 1,β2,β3,β...,βn. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible. Help Petya to split the integers. Each of n integers should be exactly in one group. | Print the smallest possible absolute difference in the first line. In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them. | The first line contains a single integer n (2ββ€βnββ€β60β000) β the number of integers Petya has. | standard output | standard input | Python 3 | Python | 1,300 | train_001.jsonl | cae2f6e4ef82c129ccefc1208ca57dad | 256 megabytes | ["4", "2"] | PASSED | n=int(input())
f=[]
f1=s1=0
for i in range(n,0,-1):
if f1<=s1:
f1+=i
f.append(i)
else:
s1+=i
print(abs(f1-s1))
print(str(len(f)),*f)
| 1513492500 | [
"math",
"graphs"
] | [
0,
0,
1,
1,
0,
0,
0,
0
] | |
3 seconds | ["b\nac\nabcdebfadg\nbcdefghijklmnopqrstuvwxyza\nbcdefghijklmnopqrstuvwxyaz"] | faf5ec909f5147c11454e1ecb9c372ee | NoteIn the first test case, we couldn't have the string "a", since the letter a would transit to itself. Lexicographically the second string "b" is suitable as an answer.In the second test case, the string "aa" is not suitable, since a would transit to itself. "ab" is not suitable, since the circle would be closed with... | There was a string $$$s$$$ which was supposed to be encrypted. For this reason, all $$$26$$$ lowercase English letters were arranged in a circle in some order, afterwards, each letter in $$$s$$$ was replaced with the one that follows in clockwise order, in that way the string $$$t$$$ was obtained. You are given a strin... | For each test case, output a single line containing the lexicographically smallest string $$$s$$$ which could be a prototype of $$$t$$$. | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 3 \cdot 10^4$$$) β the number of test cases. The description of test cases follows. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) β the length of the string $$$t$$$. The next line contains the string $... | standard output | standard input | PyPy 3-64 | Python | 1,400 | train_098.jsonl | 6b8c2604c15164ef477a37f2187dc8fe | 256 megabytes | ["5\n\n1\n\na\n\n2\n\nba\n\n10\n\ncodeforces\n\n26\n\nabcdefghijklmnopqrstuvwxyz\n\n26\n\nabcdefghijklmnopqrstuvwxzy"] | PASSED | from heapq import _heapify_max, heapify, heappush, heappop
from bisect import bisect_left, bisect_right, bisect, insort
import math, sys, os
from string import ascii_lowercase
from re import A, L
from collections import defaultdict, Counter
from math import log, ceil, sqrt, floor, gcd, log2, factorial
from itert... | 1664721300 | [
"strings",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
1,
0
] | |
4 seconds | ["3\n2\n0\n2\n3\n2"] | 18ac51a009c907fe8e4cd2bb8612da20 | NoteIn the first test case of the example, all $$$3$$$ words can be used to make an interesting story. The interesting story is "bac aaada e".In the second test case of the example, the $$$1$$$-st and the $$$3$$$-rd words can be used to make an interesting story. The interesting story is "aba aba". Stephen can't use al... | Stephen Queen wants to write a story. He is a very unusual writer, he uses only letters 'a', 'b', 'c', 'd' and 'e'!To compose a story, Stephen wrote out $$$n$$$ words consisting of the first $$$5$$$ lowercase letters of the Latin alphabet. He wants to select the maximum number of words to make an interesting story.Let ... | For each test case, output the maximum number of words that compose an interesting story. Print 0 if there's no way to make a non-empty interesting story. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 5000$$$) β the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the number of the words in the sequence. Then $$$n$$$ lines follow, each of them contains a wo... | standard output | standard input | PyPy 3-64 | Python | 1,500 | train_099.jsonl | 8fd50b67079b4c7396bf6c3942dcbd95 | 256 megabytes | ["6\n3\nbac\naaada\ne\n3\naba\nabcde\naba\n2\nbaba\nbaba\n4\nab\nab\nc\nbc\n5\ncbdca\nd\na\nd\ne\n3\nb\nc\nca"] | PASSED | from sys import stdin, stdout
t = int(stdin.readline())
for tt in range(t):
n = int(stdin.readline())
a = [stdin.readline().strip() for i in range(n)]
chars = 'abcde'
# c_count = [{c: 0 for c in chars} for i in range(n)]
# not_c_count = [{c: 0 for c in chars} for i in range(n)]
# for i i... | 1627050900 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["abab\n1\nertyqw\n3\naaaaa\n1\naksala\n6\navjsmbpfl\n5\np\n1"] | f501e17271a220f3bcd69377c01721a1 | NoteIn the first testcase of the first sample, the string modification results for the sample abab are as follows : for $$$k = 1$$$ : abab for $$$k = 2$$$ : baba for $$$k = 3$$$ : abab for $$$k = 4$$$ : babaThe lexicographically smallest string achievable through modification is abab for $$$k = 1$$$ and $$$3$$$. S... | Vasya has a string $$$s$$$ of length $$$n$$$. He decides to make the following modification to the string: Pick an integer $$$k$$$, ($$$1 \leq k \leq n$$$). For $$$i$$$ from $$$1$$$ to $$$n-k+1$$$, reverse the substring $$$s[i:i+k-1]$$$ of $$$s$$$. For example, if string $$$s$$$ is qwer and $$$k = 2$$$, below is the... | For each testcase output two lines: In the first line output the lexicographically smallest string $$$s'$$$ achievable after the above-mentioned modification. In the second line output the appropriate value of $$$k$$$ ($$$1 \leq k \leq n$$$) that you chose for performing the modification. If there are multiple values ... | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5000$$$). The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 5000$$$)Β β the length of the string $$$s$$$. The second line of each t... | standard output | standard input | PyPy 3 | Python | 1,400 | train_003.jsonl | e32df1e3fc5766bbd06a42a886f0c73c | 256 megabytes | ["6\n4\nabab\n6\nqwerty\n5\naaaaa\n6\nalaska\n9\nlfpbavjsm\n1\np"] | PASSED | # cook your dish here
for _ in range(int(input())):
n=int(input())
s=input()
ch=s[0]
for i in range(1,n):
if ch>s[i]:
ch=s[i]
ks=[]
for i in range(n):
if(s[i]==ch):
ks.append(i+1)
low=-1
for k in ks:
rev=False... | 1583332500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["6 9 3\n21 39 3\n29 43 1\n49 35 7\n146 219 73\n28622 122661788 2"] | d4f4d6341f52cceb862faa89e85a42a3 | NoteIn the first test case, $$$6 + 9 + 3 = 18$$$ and $$$\operatorname{gcd}(6, 9) = 3$$$.In the second test case, $$$21 + 39 + 3 = 63$$$ and $$$\operatorname{gcd}(21, 39) = 3$$$.In the third test case, $$$29 + 43 + 1 = 73$$$ and $$$\operatorname{gcd}(29, 43) = 1$$$. | Given a positive integer $$$n$$$. Find three distinct positive integers $$$a$$$, $$$b$$$, $$$c$$$ such that $$$a + b + c = n$$$ and $$$\operatorname{gcd}(a, b) = c$$$, where $$$\operatorname{gcd}(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$. | For each test case, output three distinct positive integers $$$a$$$, $$$b$$$, $$$c$$$ satisfying the requirements. If there are multiple solutions, you can print any. We can show that an answer always exists. | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$)Β β the number of test cases. Description of the test cases follows. The first and only line of each test case contains a single integer $$$n$$$ ($$$10 \le n \le 10^9$$$). | standard output | standard input | PyPy 3-64 | Python | 900 | train_100.jsonl | e769df5794ee4ae7bfe5b1cc709f5bbe | 256 megabytes | ["6\n18\n63\n73\n91\n438\n122690412"] | PASSED | import math
case = int(input())
i=1
while i <= case:
i=i+1
n = int(input())
j=1
while (n-1)%j ==0:
j=j+1
else:
if j==2:
print(math.floor(n/2),math.floor(n/2)-1,1)
else:
k = 2
while math.gcd(k, n - 1) != 1:
k =... | 1639661700 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["2 3 6 \n1\n2 4 \n0\n2 30 6 3 15 5 10 \n0"] | 406f8f662d2013d87b36dacca663bef5 | NoteIn the first test case $$$6$$$ has three divisors, which are greater than $$$1$$$: $$$2, 3, 6$$$. Regardless of the initial order, numbers $$$2$$$ and $$$3$$$ are adjacent, so it's needed to place their least common multiple between them. After that the circle becomes $$$2, 6, 3, 6$$$, and every two adjacent number... | An agent called Cypher is decrypting a message, that contains a composite number $$$n$$$. All divisors of $$$n$$$, which are greater than $$$1$$$, are placed in a circle. Cypher can choose the initial order of numbers in the circle.In one move Cypher can choose two adjacent numbers in a circle and insert their least co... | For each test case in the first line output the initial order of divisors, which are greater than $$$1$$$, in the circle. In the second line output, the minimal number of moves needed to decrypt the message. If there are different possible orders with a correct answer, print any of them. | The first line contains an integer $$$t$$$ $$$(1 \le t \le 100)$$$Β β the number of test cases. Next $$$t$$$ lines describe each test case. In a single line of each test case description, there is a single composite number $$$n$$$ $$$(4 \le n \le 10^9)$$$Β β the number from the message. It's guaranteed that the total num... | standard output | standard input | PyPy 3 | Python | 2,100 | train_014.jsonl | 6cf9fb3ad5068af8600c2de91c801dc2 | 256 megabytes | ["3\n6\n4\n30"] | PASSED | import sys, math
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
def getInts():
return [int(s) for s in input().split()]
def getInt():
return int(input())
def getStrs():
return [s for s in input().split()]
def getStr():
return input()
def listStr():
return list(input())
... | 1600526100 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["42\n487\n519\n528\n544\n564\n588\n628"] | 7a48218582b90f735a09083df9e15b96 | Note$$$a_{1} = 487$$$ $$$a_{2} = a_{1} + minDigit(a_{1}) \cdot maxDigit(a_{1}) = 487 + \min (4, 8, 7) \cdot \max (4, 8, 7) = 487 + 4 \cdot 8 = 519$$$ $$$a_{3} = a_{2} + minDigit(a_{2}) \cdot maxDigit(a_{2}) = 519 + \min (5, 1, 9) \cdot \max (5, 1, 9) = 519 + 1 \cdot 9 = 528$$$ $$$a_{4} = a_{3} + minDigit(a_{3}) \cdo... | Let's define the following recurrence: $$$$$$a_{n+1} = a_{n} + minDigit(a_{n}) \cdot maxDigit(a_{n}).$$$$$$Here $$$minDigit(x)$$$ and $$$maxDigit(x)$$$ are the minimal and maximal digits in the decimal representation of $$$x$$$ without leading zeroes. For examples refer to notes.Your task is calculate $$$a_{K}$$$ for g... | For each test case print one integer $$$a_{K}$$$ on a separate line. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$)Β β the number of independent test cases. Each test case consists of a single line containing two integers $$$a_{1}$$$ and $$$K$$$ ($$$1 \le a_{1} \le 10^{18}$$$, $$$1 \le K \le 10^{16}$$$) separated by a space. | standard output | standard input | PyPy 3 | Python | 1,200 | train_004.jsonl | 4fc44835588788a606f3efe22c9737df | 256 megabytes | ["8\n1 4\n487 1\n487 2\n487 3\n487 4\n487 5\n487 6\n487 7"] | PASSED | t=int(input())
for _ in range(t):
a1,k=map(int,input().split())
for i in range(k-1):
mi=9
ma=0
for d in str(a1):
if int(d)>ma:
ma=int(d)
if int(d)<mi:
mi=int(d)
if mi==0:
break
a1=a1+(ma*mi)
print(a1) | 1589628900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1\n11\n21\n10973\n13716\n1111111111"] | 0beecbd62aa072a2f3aab542eeb56373 | null | Mishka wants to buy some food in the nearby shop. Initially, he has $$$s$$$ burles on his card. Mishka can perform the following operation any number of times (possibly, zero): choose some positive integer number $$$1 \le x \le s$$$, buy food that costs exactly $$$x$$$ burles and obtain $$$\lfloor\frac{x}{10}\rfloor$$$... | For each test case print the answer on it β the maximum number of burles Mishka can spend if he buys food optimally. | 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 on a separate line and consists of one integer $$$s$$$ ($$$1 \le s \le 10^9$$$) β the number of burles Mishka initially has. | standard output | standard input | PyPy 3 | Python | 900 | train_004.jsonl | 6b28909462269516b2475b6436c53c9c | 256 megabytes | ["6\n1\n10\n19\n9876\n12345\n1000000000"] | PASSED | n = int(input())
for i in range(0, n):
m = int(input())
print(int(m//0.9))
| 1580826900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["? 3 5 6\n? 32 24 37\n! 5"] | c7f31e0c57cf15f71c401d826c3ee0ef | NoteThe example of interaction is not correct β you should sumbit exactly $$$100$$$ integers in each query. Everything else is correct.Hacks are forbidden in this problem. | This is an interactive problem. Remember to flush your output while communicating with the testing program. You may use fflush(stdout) in C++, system.out.flush() in Java, stdout.flush() in Python or flush(output) in Pascal to flush the output. If you use some other programming language, consult its documentation. You m... | To give the answer, your program should print one line $$$!$$$ $$$x$$$ with a line break in the end. After that, it should flush the output and terminate gracefully. | null | standard output | standard input | PyPy 2 | Python | 1,900 | train_030.jsonl | e5909c1623b5df2aa9435eca9539946b | 256 megabytes | ["0\n32"] | PASSED | import sys
import math
import bisect
import atexit
import io
import heapq
from collections import defaultdict, Counter
MOD = int(1e9+7)
# n = map(int, raw_input().split())
# input = map(int, raw_input().split())
def main():
print '?',
for i in range(1, 101):
print i*(2**7),
n1 = map(int, raw_i... | 1566484500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["2\n2 4\n3 3\n3 1"] | 591372383cf3624f69793c41370022de | null | Numbers $$$1, 2, 3, \dots n$$$ (each integer from $$$1$$$ to $$$n$$$ once) are written on a board. In one operation you can erase any two numbers $$$a$$$ and $$$b$$$ from the board and write one integer $$$\frac{a + b}{2}$$$ rounded up instead.You should perform the given operation $$$n - 1$$$ times and make the result... | For each test case, in the first line, print the minimum possible number left on the board after $$$n - 1$$$ operations. Each of the next $$$n - 1$$$ lines should contain two integersΒ β numbers $$$a$$$ and $$$b$$$ chosen and erased in each operation. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$)Β β the number of test cases. The only line of each test case contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$)Β β the number of integers written on the board initially. It's guaranteed that the total sum of $$$n$$$ over test cases doesn't ex... | standard output | standard input | Python 3 | Python | 1,000 | train_000.jsonl | 88084dde61bbebdebe163309a2bda179 | 256 megabytes | ["1\n4"] | PASSED |
def ii(): return int(input())
def mi(): return map(int, input().split())
if __name__ == '__main__':
for _ in range(ii()):
n = ii()
# if n == 3:
# print("2\n3 1\n2 2")
# continue
if n == 2:
print("2\n2 1")
continue
l = list(range(1, ... | 1602407100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["3 2 0 2 0", "2 3 4 0"] | e544ed0904e2def0c1b2d91f94acbc56 | null | The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row.Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all t... | Print n integers a1,βa2,β...,βan, where number ai is the number of floors that need to be added to the house number i to make it luxurious. If the house is already luxurious and nothing needs to be added to it, then ai should be equal to zero. All houses are numbered from left to right, starting from one. | The first line of the input contains a single number n (1ββ€βnββ€β105) β the number of houses in the capital of Berland. The second line contains n space-separated positive integers hi (1ββ€βhiββ€β109), where hi equals the number of floors in the i-th house. | standard output | standard input | Python 3 | Python | 1,100 | train_001.jsonl | 5995d4c0bb90ec2b3026b9108a50f587 | 256 megabytes | ["5\n1 2 3 1 2", "4\n3 2 1 4"] | PASSED | n = int(input())
h = map(int, input().split()[::-1])
m_h = 0
res = []
for h in h:
if m_h < h:
res.append(0)
m_h = h
else:
res.append(m_h - h + 1)
print(" ".join(map(str, res[::-1]))) | 1443430800 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["Yes", "No", "No"] | e5f422a4247b90af7b42b64875a0f87e | NoteIn the first sample string t can occur in the string s as a subsequence in three ways: abab, abab and abab. In these occurrences each character of string s occurs at least once.In the second sample the 4-th character of the string s doesn't occur in any occurrence of string t.In the third sample there is no occurre... | A subsequence of length |x| of string sβ=βs1s2... s|s| (where |s| is the length of string s) is a string xβ=βsk1sk2... sk|x| (1ββ€βk1β<βk2β<β...β<βk|x|ββ€β|s|).You've got two stringsΒ β s and t. Let's consider all subsequences of string s, coinciding with string t. Is it true that each character of string s occur... | Print "Yes" (without the quotes), if each character of the string s occurs in at least one of the described subsequences, or "No" (without the quotes) otherwise. | The first line contains string s, the second line contains string t. Each line consists only of lowercase English letters. The given strings are non-empty, the length of each string does not exceed 2Β·105. | standard output | standard input | Python 3 | Python | 1,900 | train_034.jsonl | 6b329a3d711113132010b94250e12283 | 256 megabytes | ["abab\nab", "abacaba\naba", "abc\nba"] | PASSED | import bisect
import string
s = input()
t = input()
max_match = [0 for i in range(len(s))]
min_match = [0 for i in range(len(s))]
char_idx = [0 for i in range(30)]
char_occur = [ [] for i in range(30) ]
for (i, ch) in enumerate(t):
idx = ord(ch) - ord('a')
char_occur[idx].append(i)
for ch in string.ascii_lo... | 1347809400 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["1", "6", "2", "1", "24"] | cff3074a82bffdd49579a47c7491f972 | NoteIn the first case, the only possible evolution plan is: In the second case, any permutation of (1,ββ2,ββ3) is valid.In the third case, there are two possible plans: In the fourth case, the only possible evolution plan is: | It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has n gyms. The i-th gym has gi Pokemon in it. There are m distinct Pokemon types in the Himalayan region numbered from 1 to m. There is a special evolution camp set up in t... | Output the number of valid evolution plans modulo 109β+β7. | The first line contains two integers n and m (1ββ€βnββ€β105, 1ββ€βmββ€β106)Β β the number of gyms and the number of Pokemon types. The next n lines contain the description of Pokemons in the gyms. The i-th of these lines begins with the integer gi (1ββ€βgiββ€β105)Β β the number of Pokemon in the i-th gym. After that gi integer... | standard output | standard input | Python 3 | Python | 1,900 | train_004.jsonl | d94a233013eb65bb040d0a21a5bca39d | 256 megabytes | ["2 3\n2 1 2\n2 2 3", "1 3\n3 1 2 3", "2 4\n2 1 2\n3 2 3 4", "2 2\n3 2 2 1\n2 1 2", "3 7\n2 1 2\n2 3 4\n3 5 6 7"] | PASSED | # ---------------------------iye ha aam zindegi---------------------------------------------
import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict,Counter
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10... | 1484235300 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["-1", "3\n2\n1\n3"] | 700b654a2ead672cba715653425029b4 | NoteThe first sample explanation: if there would be no 1 in the list then the first and the third man's wishes would not be satisfied (a1β=βa3β=β1); if there would be no 2 in the list then the second man wish would not be satisfied (a2β=β2); if 1 would stay before 2 in the answer then the second man would have to g... | Sasha lives in a big happy family. At the Man's Day all the men of the family gather to celebrate it following their own traditions. There are n men in Sasha's family, so let's number them with integers from 1 to n.Each man has at most one father but may have arbitrary number of sons.Man number A is considered to be th... | Print an integer k (1ββ€βkββ€βn)Β β the number of the men in the list of candidates, in the first line. Print then k pairwise different positive integers not exceeding n β the numbers of the men in the list in an order satisfying every of the men's wishes, one per line. If there are more than one appropriate lists, print ... | In the first line of the input two integers n and m (0ββ€βmβ<βnββ€β100β000) are givenΒ β the number of the men in the Sasha's family and the number of family relations in it respectively. The next m lines describe family relations: the (iβ+β1)th line consists of pair of integers pi and qi (1ββ€βpi,βqiββ€βn, piββ βqi) mean... | standard output | standard input | Python 3 | Python | 2,000 | train_051.jsonl | c0d22b1a8cf95aa6bdb15cf41476b480 | 256 megabytes | ["3 2\n1 2\n2 3\n1 2 1", "4 2\n1 2\n3 4\n1 2 3 3"] | PASSED | n, m = map(int, input().split())
adj = [[] for _ in range(n)]
cp = [-1] * n
for i in range(m):
p, c = map(int, input().split())
adj[p - 1].append(c - 1)
cp[c - 1] = p - 1
pres = [i - 1 for i in map(int, input().split())]
level = [0] * n
from collections import deque
def bfs(v):
q = deque([v])
whi... | 1465922100 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.