SMRT Information Sign The MRT Information System tells commuters when the next train will arrive. However, Bob is worried that displaying the next train's arrival time too directly may encourage commuters to run towards the platform, which is dangerous.
Bob is a software developer working on the next iteration of these information signs with safety in mind.
A day starts at time $$$0$$$. There are $$$n$$$ platforms. For platform $$$j$$$, trains arrive every $$$t_j$$$ minutes; that is, trains serving platform $$$j$$$ arrive at times $$$$$$0, t_j, 2t_j, 3t_j, \cdots$$$$$$ The station also has $$$m$$$ information signs. A commuter is estimated to take $$$d_{i,j}$$$ minutes to walk from sign $$$i$$$ to platform $$$j$$$.
Suppose a commuter leaves sign $$$i$$$ at time $$$x$$$ and walks to platform $$$j$$$. The sign displays the number of minutes from time $$$x$$$ until the earliest train they can catch. Formally, a commuter who starts walking from sign $$$i$$$ reaches platform $$$j$$$ at time $$$$$$ x + d_{i,j}. $$$$$$ The sign should display the difference between time $$$x$$$ and the arrival time of the earliest train at platform $$$j$$$ that arrives at or after time $$$x + d_{i,j}$$$.
For example, suppose it takes $$$d_{1,1} = 5$$$ minutes to walk from sign $$$1$$$ to platform $$$1$$$, and trains arrive at platform 1 every $$$t_{1} = 6$$$ minutes.
Help Bob answer $$$q$$$ queries. For each query $$$(x,i,j)$$$, output the number of minutes displayed on sign $$$i$$$ for platform $$$j$$$ at time $$$x$$$ minutes from the start of the day.
$$$q$$$ lines, where the $$$i$$$-th line ($$$1\leq i \leq q$$$) contains the answer to the $$$i$$$-th query.
3 25 7 11 2 35 7 1080 1 14 1 15 1 16 1 27 2 21000 1 30 2 13 2 1
5 1 5 8 7 3 5 7
Once upon a time, Billy had an array $$$a$$$ of length $$$n$$$ such that $$$a_i = i$$$ for all $$$1\leq i \leq n$$$, and an integer $$$m$$$ ($$$m \gt n$$$). The array $$$a$$$ was then cyclically shifted to the right by $$$k$$$ positions to form the array $$$b$$$.
For example, when $$$n= 5$$$ and $$$k = 2$$$, the arrays $$$a$$$ and $$$b$$$ are given as follows: $$$$$$ a = [1,2,3,4,5] \longrightarrow \text{cyclic right-shift by 2} \longrightarrow b=[4,5,1,2,3] $$$$$$
Billy may perform one type of operation on array $$$b$$$, consisting of two steps:
Billy especially loves arrays in which every element is $$$0$$$. Help Billy find the minimum number of operations required to transform $$$b$$$ into $$$[0, 0,\cdots, 0]$$$.
The first line contains an integer $$$t$$$ ($$$1\leq t \leq 2\times 10^5$$$), the number of test cases.
Each test case consists of a single line containing three integers $$$n, k, m$$$ ($$$1\leq n \lt m \leq 10^9$$$, $$$0 \leq k \leq n-1$$$), denoting the size of the array $$$b$$$, the right-shift offset $$$k$$$ and the modulus $$$m$$$.
$$$t$$$ lines, the answer to each test case on a single line.
21 0 35 2 6
2 6
There are $$$2$$$ test cases.
In the first test case, $$$a = [1]$$$ and since $$$k = 0$$$, $$$b = a = [1]$$$. Let $$$f(l,r)$$$ denote one application of the operation to the subarray from index $$$l$$$ to index $$$r$$$:
After these two operations, $$$b = [0]$$$. Therefore the minimum number of operations is $$$2$$$.
At Britain's Got Talent 2026, Rafferty wants to perform a card trick using a deck of $$$n$$$ cards in a predetermined order.
Each card has:
The trick begins with all cards in the deck face-up.
from left to right.
Final result of the trick$$$^{1}$$$. The face-down letters of the cards at positions $$$i$$$ to $$$i+6$$$ spell BELIEVE when arranged in ascending order of face-up numbers. The BGT crowd goes wild — somehow, this is inspirational. In other words, for the chosen window of $$$7$$$ cards:
Your task is to construct the entire deck so that this works for every valid choice of $$$i$$$ ($$$1\leq i \leq n-6$$$).
$$$^{1}$$$ Watch the trick at https://www.youtube.com/watch?v=BCHkMexXu40&t=6m14s.
The input consists of a single line containing an integer $$$n$$$ ($$$n=7$$$ or $$$n=52$$$), the number of cards in the deck. There are exactly 2 tests for this problem. The sample has $$$n = 7$$$ and one hidden test case has $$$n=52$$$.
Output 2 lines:
Your output must satisfy all of the following:
7
7 5 4 3 2 1 6 E E I L E B V
The sample is only meant to illustrate the output format.
For $$$n=7$$$, the only valid choice is $$$i=1$$$. Sorting the $$$7$$$ cards by face-up number gives the numbers
$$$$$$ 1,2,3,4,5,6,7 $$$$$$
with corresponding letters
$$$$$$ \texttt{B},\texttt{E},\texttt{L},\texttt{I},\texttt{E},\texttt{V},\texttt{E} $$$$$$
so the word BELIEVE is formed.
Since there are only two possible inputs, you may output this exact construction for $$$n=7$$$ and focus on your construction for $$$n=52$$$.
Alice and Bob play a Duel of Ten on an array $$$a$$$ of length $$$n$$$ ($$$\boldsymbol{-10^9} \leq a_i \leq 10^9$$$). They take turns making moves, with Alice going first. The rules of "Duel-of-Ten" are as follows:
The game ends when the array $$$a$$$ contains only one element. If the remaining element has an absolute value less than 10, Alice wins. Otherwise, Bob wins.
Given an array $$$a$$$, determine who wins if both players play optimally.
The first line contains a single integer $$$t$$$ ($$$1\leq t \leq 10^3$$$) — the number of test cases. For each test case,
$$$t$$$ lines. For each test case, output Alice if Alice wins, and Bob otherwise, assuming both players play optimally.
241 10 1 1041 -10 1 -10
Alice Bob
There are 2 test cases. For each test case, we show one possible sequence of moves that ends with the stated winner. These sequences are included only to illustrate the rules; the players do not necessarily play optimally.
Alice initially has a weighted undirected tree $$$T$$$ of $$$n$$$ nodes and $$$n-1$$$ edges. Each edge has a positive integer weight.
Alice wants to design a route so that she can walk for as long as possible, but she does not want to walk forever. To do so, she chooses a direction for every edge of the tree. In other words, for each undirected edge $$$(u,v)$$$, she replaces it with exactly one of the directed edges $$$u\rightarrow v$$$ or $$$v\rightarrow u$$$, preserving its weight $$$w_{uv}$$$. This produces a directed graph $$$T'$$$.
After constructing $$$T'$$$, Alice chooses a starting vertex $$$r$$$ ($$$1\leq r\leq n$$$), and performs the following walk:
Over all possible choices of edge directions and the starting vertex $$$r$$$, help Alice maximize the expected total distance she walks, modulo $$$10^9 + 7$$$.
It can be shown that the answer can always be written as a fraction $$$\frac{P}{Q}$$$, where $$$Q \not\equiv 0 \pmod{10^9+7}$$$. Therefore, output the value $$$$$$ P\cdot Q^{-1} \text{ mod }(10^9 + 7) $$$$$$
The first line of the input contains an integer $$$t$$$ ($$$1\leq t \leq 10^3$$$), the number of test cases. For each test case,
For each test case, output a single integer on a line, denoting the maximum expected total distance she walks, modulo $$$10^9+7$$$. Note that the answer should be maximized before taking modulo $$$10^9 + 7$$$.
192 1 37 9 58 7 57 3 13 4 14 5 35 6 23 2 3
12
There is $$$1$$$ test case. One possible edge orientation is shown in the figure below.
Illustration of Sample Test Case. Visualization created using CSAcademy's graph editor. When Alice starts from $$$r = 6$$$, she is forced to traverse $$$6\rightarrow 5 \rightarrow 4 \rightarrow 3$$$, contributing $$$2+3+1= 6$$$ to her expected distance.
From node $$$3$$$, she chooses node $$$2$$$ or node $$$7$$$ with probability $$$\frac{1}{2}$$$ each.
Therefore, the expected total distance is $$$$$$ 6+\frac{1}{2}\cdot 6 + \frac{1}{2}\cdot 6 = 12 $$$$$$ which can be shown to be the maximum expected total distance of her walk.
Jon has $$$n$$$ tasks and $$$m$$$ units of time. There are also $$$m$$$ cash prizes, where prize $$$j$$$ is worth $$$v_j$$$ dollars.
Task $$$i$$$ requires a duration of $$$a_i$$$ to complete. If Jon completes task $$$i$$$, he becomes eligible for cash prize $$$p_i$$$ where $$$$$$ p_i = \lfloor\frac{m}{a_i}\rfloor, $$$$$$ receiving $$$v_{p_i}$$$ dollars. If several completed tasks correspond to the same prize, Jon receives that prize only once.
Jon may choose any subset of tasks and complete them in any order, as long as the total time taken by the chosen tasks does not exceed $$$m$$$.
Find the maximum amount of money, in dollars, that Jon can receive today.
The first line contains a single integer $$$t$$$ ($$$1\leq t \leq 300$$$), the number of test cases. For each test case,
$$$t$$$ lines. For each test case, output a single integer: the maximum amount of money, in dollars, that Jon can receive today.
26 101 2 3 4 6 101 5 20 1 30 1 1 1 1 607 122 3 4 5 6 11 121 8 18 35 1 40 1 1 1 1 1 1
115 93
There are two test cases.
You live in a city with a mysterious transportation network consisting of $$$n$$$ locations and $$$m$$$ bi-directional roads. For the $$$i$$$-th road ($$$1\leq i \leq m$$$), the time taken to travel across it is $$$2^{i-1}$$$ minutes.
Alice is new to the city and is getting ready for her road trips. However, to her horror, Google Maps is not available in this city!
Alice turns to you, an aspiring competitive programmer. Alice's house is located at location $$$1$$$. For every location $$$v$$$ ($$$2\leq v \leq n$$$), please help Alice find the minimum travel time from location $$$1$$$ to location $$$v$$$, and output that time modulo $$$998244353$$$.
The first line contains a single integer $$$t$$$ ($$$1\leq t \leq 10^3$$$), the number of test cases. For each test case,
$$$t$$$ lines. For each test case, output one line containing $$$n-1$$$ integers $$$d_2, d_3,\cdots, d_n$$$, where $$$d_i$$$ is defined by:
16 72 33 42 44 52 51 51 2
43 42 40 32 -1
There is $$$1$$$ test case. The figure below provides a visualisation.
Illustration of the sample test case The minimum travel time routes from location $$$1$$$ are as follows:
Apollo, the god of prophecy, has hidden an integer $$$n$$$ ($$$1\leq n\leq 10^8$$$). Mortals are not allowed to know $$$n$$$ directly, but Apollo may answer queries and perform divisions for you.
One of Apollo's prophecies states that an integer $$$x$$$ is sacred if and only if $$$x$$$ has at most $$$8$$$ positive divisors.
Although mortals do not know Apollo's value of $$$n$$$, Apollo believes you are no mere mortal. Prove your worthiness by reducing $$$n$$$ to a sacred value $$$n'$$$ (where $$$n' \leq n$$$).
For the purposes of this interaction, the jury acts on Apollo's behalf.
The interaction begins when you ask your first query. On your turn, you can make one of three types of queries:
In the event that you read -1 instead of valid data, your program must terminate immediately. This indicates that your submission has made an invalid query or has otherwise received a Wrong Answer verdict.
0 # reply 1 1 # reply 2 1 # reply 3 16 # reply 4
div 3 # query 1 div 4 # query 2 div 4 # query 3 gcd 16 # query 4 ! # answer
The following sample interaction is meant to showcase the interaction between your program and the jury, but does not show how the answer was derived. Note that comments (marked by #) are there for readability and are not part of the actual interaction.
Apollo's integer was initially $$$n = 256$$$. The sample makes a total of $$$4$$$ out of $$$7$$$ queries.
You are given an infinite sequence of points $$$p_0, p_1, p_2,\cdots$$$ defined as: $$$$$$ p_0=(1,0), \quad p_1=(1,\frac{1}{2}), \quad p_i=(\frac{1}{i}, \frac{1}{i+1}) \quad \mathrm{for}\ i\geq 1 $$$$$$ The sequence continues indefinitely and approaches the point $$$(0,0)$$$. See the figure in the sample test case for an illustration of the sequence and the polygon $$${\cal P}$$$.
The polygon $$${\cal P}$$$ is created by connecting the points in order with line segments $$$$$$ p_0\rightarrow p_1\rightarrow p_2\rightarrow \cdots $$$$$$ The boundary is completed by adding the segment from $$$(0,0)$$$ to $$$p_0$$$.
Answer $$$q$$$ queries. Each query $$$(n_x, d_x, n_y, d_y)$$$ represents a point $$$$$$ Q =(\frac{n_x}{d_x},\frac{n_y}{d_y} ). $$$$$$ For each query, compute the minimum Euclidean distance from $$$Q$$$ to the region enclosed by $$${\cal P}$$$. Thus, if $$$Q$$$ lies inside or on the boundary of $$${\cal P}$$$, the distance is $$$0$$$.
$$$q$$$ lines. The $$$i$$$-th line should contain your answer for the $$$i$$$-th query. Your answer will be accepted if its absolute or relative error is at most $$$10^{-6}$$$.
13 9 10 1 4 1 2 -1 5 1 1 1 3 3 4 1 2 6 5 1 5 -1 10 0 1 -1 10 -1 10 1 100 1 100 38 1 1 1 -71 75 44 851407 -79 839169 35 925573 38 406091 44 579238 -72 71073 49 159480
0 0.2 0 0.079056941 0.2 0.1 0.141421356 0.0000707071 37.003378224 0.9466666681 0.0001014515 0 0.0010586112
Refer to the figure below for an illustration. This visualization includes the first four query points: $$$Q_1 = (\frac{9}{10}, \frac{1}{4})$$$, $$$Q_2 = (\frac{1}{2}, \frac{1}{5})$$$, $$$Q_3 = (1, \frac{1}{3})$$$ and $$$Q_4 = (\frac{3}{4},\frac{1}{2})$$$.
Illustration of polygon $$${\cal P}$$$ and query points $$$Q_1$$$, $$$Q_2$$$, $$$Q_3$$$ and $$$Q_4$$$. $$$O$$$ denotes the point $$$(0,0)$$$. Thick lines denote the illustrated portion of the boundary of polygon $$${\cal P}$$$. Query points $$$Q_1, Q_2, Q_3, Q_4$$$ are marked with an X. The minimum Euclidean distance to $$${\cal P}$$$ for each point is illustrated by thin lines.
There are $$$n$$$ streets in a city, numbered from $$$1$$$ to $$$n$$$. For every $$$1\leq i \leq n-1$$$, street $$$i$$$ and $$$i+1$$$ are connected by a two-way road with travel time $$$t_i$$$ units.
There is also one police station on each street. The $$$i$$$-th station is located on street $$$i$$$, has a forwarding time delay of $$$f_i$$$ units, and a response time delay of $$$r_i$$$ units.
Station $$$s$$$ receives an emergency call reporting a crime at street $$$d$$$. The receiving station then chooses one of the following actions:
The city receives $$$q$$$ emergency calls of the form $$$(s,d)$$$. For each call, find the minimum total response time if station $$$s$$$ initially receives a call of a crime at street $$$d$$$.
$$$q$$$ lines. For each query $$$(s,d)$$$, output the minimum total response time if station $$$s$$$ first receives the call reporting a crime at street $$$d$$$.
5 54 7 10000 2 69 6 8 10000 12 3 10000 61 51 33 44 55 1
12 13 10007 3 10012
There are $$$5$$$ streets and police stations, and $$$5$$$ emergency calls.
Illustration of Sample Test Case For the first emergency call $$$(1,5)$$$, the call is initially received by station $$$1$$$ and the crime is at street $$$5$$$. There are 3 possible ways to respond to the call.
One possible sequence of events is as follows:
Another possible sequence of events is as follows:
Lastly, the only other sequence of events is as follows:
Therefore, the minimum total response time for the first call is $$$12$$$ units.
A suspicious streamer named TLE Creators proposed an algorithm to sort a permutation. Note that the code below uses one-indexed positions.
Function CyclicSort(arr):
pos = 1
WHILE (arr is not sorted) DO
index = find the index of the minimum element in arr[pos...n]
shifts = index - pos
FOR (i = 1...shifts) DO
cyclically shift left arr[pos...n] by one position
END
pos = pos + 1
END
END
Let's consider an example by performing CyclicSort on the permutation $$$p = [2,4,1,3,5]$$$.
TLE Creators proved that CyclicSort always sorts any permutation in ascending order, but they are having difficulty determining the number of cyclic left-shift operations that CyclicSort will perform. They are going live right after your contest, and desperately need your help!
Given a permutation $$$p$$$ of length $$$n$$$, please help TLE Creators determine the number of cyclic left-shift operations that CyclicSort will perform.
The first line contains a single integer $$$t$$$ ($$$1\leq t \leq 10^3$$$), the number of test cases. For each test case,
$$$t$$$ lines. For each test case, output a single integer, the number of cyclic left-shift operations performed by CyclicSort.
452 4 1 3 562 3 1 4 5 666 5 4 3 2 171 2 3 4 5 6 7
6 5 15 0
There are $$$4$$$ test cases.