Dataset Viewer
Auto-converted to Parquet Duplicate
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
sequencelengths
1
5
hidden_unit_tests
stringclasses
1 value
labels
sequencelengths
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| &gt; 0, 0 &lt; 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 &lt; 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 &gt; 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) &gt; 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) &gt; 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 &gt; 0, p &gt; 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 &lt; 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 &lt; 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&lt;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 ]
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
10