Mario is optimizing the track layout for the next Honeymoon Grand Prix!
He's found a flat, rectangular section of the track measuring $$$x$$$ units long and $$$y$$$ units wide.
He wants to install the largest possible square boost pad entirely within this rectangular section to give racers an extra burst of speed. He is interested in the area of the pad.
Mario's Boost Pad. Given the dimensions $$$x$$$ and $$$y$$$ of the rectangular section, what is the side length of the largest square boost pad Mario can install?
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
Each of the next $$$t$$$ lines contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^3$$$) — the dimensions of the rectangular section of the track.
For each test case, print a single integer — the maximum possible area of the square boost pad.
31 15 37 7
1 9 49
Baran is Mario's new friend, and Baran friends are racing on a new track that's shaped like a tree with $$$n$$$ nodes rooted at $$$1$$$. Each node $$$i$$$ on the track has a "Coin Value" of $$$a_i$$$.
Baran new logo. To calculate the total score for the race, they need to consider every possible pair of nodes $$$(i, j)$$$ on the track (including pairs where $$$i=j$$$).
For each pair, they find the Lowest Common Ancestor (LCA) of $$$i$$$ and $$$j$$$, let's call it $$$l = \text{lca}(i, j)$$$.
The score contributed by the pair $$$(i, j)$$$ is $$$\gcd(a_i, a_j, a_l)$$$.
Your task is to find the sum of these scores for all possible pairs of nodes $$$(i, j)$$$ $$$(i \le j)$$$.
Formally, calculate
$$$$$$\sum_{i=1}^n \sum_{j=i}^n \gcd(a_i, a_j, a_{\text{lca}(i, j)})$$$$$$
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of nodes in the tree.
The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$) — the Coin Values for each node.
The next $$$n-1$$$ lines describe the tree edges. Each line contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$) — representing an edge between nodes $$$u$$$ and $$$v$$$.
Output a single integer, the total sum of $$$\gcd(a_i, a_j, a_{\text{lca}(i, j)})$$$ over all pairs $$$1 \le i, j \le n$$$.
44 2 1 41 21 31 4
22
High above the track, contestants face off on a massive $$$n \times m$$$ grid.
The Queen likes Yellow and Black because they are her colors.
Queen Bee. The grid is initially filled with ('.'). Then, a sequence of moves is played, with each move consisting of painting a cell either Black ('B') or Yellow ('Y'). Each day, two bees compete against each other in a tough match on the grid, where one bee paints cells Yellow and the other paints cells Black.
The game is simple: they fight 1v1, and the winner earns the right to choose any empty cell and paint it with his color.
The tension is great—the first bee to achieve a line of at least $$$k$$$ connected pieces of their color, horizontally, vertically, or diagonally, will not only earn Queen Bee's respect but also the legendary Queen Honey Pot as a prize and victory!
However, due to the intensity of the competition, they forgot about the $$$k$$$-connected-pieces rule, and eventually, they ended up coloring the entire grid (they played exactly $$$n \times m$$$ moves).
Now, they want to iterate through the moves again to determine the actual winner.
Given $$$n$$$, $$$m$$$, $$$k$$$, and the sequence of moves, determine which bee achieves a line of length at least $$$k$$$ first. If neither achieves this, the game results in a draw.
The first line contains three space integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1 \le n, m \le 1000$$$, $$$1 \le k \le \min(n, m)$$$) — denotes the number of rows, is the number of columns, and the number of connected cells of the same color (Black or Yellow) required, respectively.
The next $$$n \cdot m$$$ lines represent the sequence of moves, the $$$i_{th}$$$ line contains three integers $$$p \in$$$ ('B', 'Y') which represents the color of bee that won the $$$i_{th}$$$ move, $$$x$$$ ($$$1 \le x \le n$$$), and $$$y$$$ ($$$1 \le y \le m$$$) — $$$x$$$, $$$y$$$ are the coordinates of the cell respectively.
Print one of the following characters:
3 3 3B 1 1Y 2 1B 1 2Y 2 2B 1 3Y 3 1Y 3 2Y 3 3Y 2 3
B
Mario and Luigi are analyzing segments of the ultimate Mario Kart Grand Prix course.
The course is incredibly long, consisting of sections indexed by positive integers starting from 1.
Mario flying around. For a continuous segment of the course from index $$$l$$$ to index $$$r$$$ (inclusive), they calculate two special values based on the section indices:
Given several queries, each specifying a range $$$[l, r]$$$, determine if the Chaos Factor for that range is greater than or equal to the Stability Factor.
The first line contains an integer $$$q$$$ ($$$1 \le q \le 10^5$$$) — the number of queries.
Each of the following $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^{18}$$$).
For each query, output "YES" if the Chaos Factor is $$$\ge$$$ the Stability Factor, and "NO" otherwise. (case insensitive)
31 11 22 3
Yes Yes No
You are given an $$$N \times N$$$ grid representing a section of a Mario Kart track. Each cell contains a non-negative integer.
Each racer is positioned at a fixed cell (with value 0) and cannot move to any other location. From this position, they can instantly collect all strawberry mushrooms from their immediately adjacent cells (up, down, left, and right). Each racer collects mushrooms independently, so the same mushroom block can be fully collected by multiple racers if it is adjacent to more than one of them.
Red Mushroom fan club Find a single racer who can collect the maximum total number of strawberry mushrooms from their adjacent cells. Output their 0-indexed row and column.
If multiple racers can collect the same maximum amount, output the one with the lowest coordinates. Coordinates $$$(r_1, c_1)$$$ are considered lower than $$$(r_2, c_2)$$$ if $$$r_1 \lt r_2$$$, or if $$$r_1 = r_2$$$ and $$$c_1 \lt c_2$$$.
Note: It is guaranteed that the grid has at least one racer in it.
The first line contains a single integer $$$N$$$ ($$$2 \le N \le 1000$$$) — the size of the grid.
Then $$$N$$$ lines follow, each with $$$N$$$ non-negative $$$a_{i,j}$$$ ($$$0 \le a_{i,j} \le 10^6$$$) — the number written in each cell.
Output two space-separated integers: the row and column of a racer who can collect the most mushrooms (0-indexed).
If multiple racers can collect the same maximum amount, output the one with the lowest coordinates. Coordinates $$$(r_1, c_1)$$$ are considered lower than $$$(r_2, c_2)$$$ if $$$r_1 \lt r_2$$$, or if $$$r_1 = r_2$$$ and $$$c_1 \lt c_2$$$.
30 2 01 0 30 4 0
1 1
310 0 105 5 510 0 12
2 1
Moon had the worst breakup ever, again. His ex was way smarter than him, which devastated him.
So, he needed advice from the one and only Apple, again. Apple decided to take Moon to Couple Therapy since he has been in too much relationships issues.
Moon said, "4 JAYYED."
Apple introduced Moon to Mario and Peach, and as Moon began to open up, Mario and Peach decided to help Moon.
Mario and Peach discussing how to help Moon. They gave Moon an array of $$$n$$$ non-negative integers, Moon has to find the minimum $$$\operatorname{MEX}$$$ (Minimum EXcluded value) among all its non-empty sub-arrays, and count how many non-empty sub-arrays achieve this minimum $$$\operatorname{MEX}$$$.
Can you help Moon solve this problem?
Note: The $$$\operatorname{MEX}$$$ (Minimum EXcluded value) of an array is the smallest non-negative integer that is not in the array. For example:
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases.
For each test case:
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the size of the array.
The second line contains $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le n$$$) — the elements of the array.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
For each test case, output the count how many non-empty sub-arrays achieve the minimum $$$\operatorname{MEX}$$$
320 031 2 341 0 3 4
3 6 4
An array $$$b$$$ is a sub-array of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.
In particular, an array is a sub-array of itself.
During a brief break from racing, Mario is making $$$n$$$ delicious tuna sandwiches.
Each sandwich requires exactly two slices of cheese. There are two types of cheese available: Mushroom Cheese and Star Cheese.
Mario follows a specific, repeating pattern for the cheese slices in his sandwiches:
Mario Kart Sandwich. Mario wants to make $$$n$$$ sandwiches, determine the total number of Mushroom Cheese slices and the total number of Star Cheese slices he will need.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
The only line of each test case contain a single integer $$$n$$$ ($$$3 \le n \le 10^9$$$) — representing the total number of sandwiches.
Output $$$t$$$ lines each line contain two space-separated integers: the total number of Mushroom Cheese slices followed by the total number of Star Cheese slices required.
238
3 3 9 7
Welcome to the Mario Elite League!
You're preparing your kart for the upcoming races, the kart has $$$n$$$ item slots.
Mario Elite League Each slot $$$i$$$ must be filled with an item of "Power Level" $$$A_i$$$.
To achieve peak performance, the array of Power Levels $$$[A_1, A_2, \dots, A_n]$$$ must satisfy the following conditions based on their combined effects:
Given integers $$$n, g, l$$$, Mario wants to count the number of distinct arrays $$$[A_1, A_2, \dots, A_n]$$$ satisfying these conditions.
Since the number of such arrays can be very large, output the answer modulo $$$10^9 + 7$$$.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
The only line in each test case contains four space-separated integers $$$n$$$ ($$$1 \le n \le 10^6$$$), $$$g, l$$$ ($$$1 \le g, l \le 10^{12}$$$) — the number of items, the gcd, and the lcm respectively.
It's guaranteed that the sum of $$$g, l$$$ over all test cases does not exceed $$$1 \cdot 10^{12}$$$.
For each test case, Print a single integer, the number of valid arrays modulo $$$10^9 + 7$$$.
32 2 63 1 46 6 24
2 12 602
In preparation for the next Grand Prix, racers are forming teams.
Each racer has a rating. Leah, the one managing the race has one rule for team formation:
If a racer's rating is greater than or equal to 1500, they compete in the Grand Prix solo. Otherwise, they must form teams of up to 3 members.
Teams Given the rating scores of all racers, determine the minimum total number of teams required for the Grand Prix.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of racers.
The second line contains $$$n$$$ integers $$$r_1, r_2, \dots, r_n$$$ ($$$100 \le r_i \le 3500$$$) — where $$$r_i$$$ is the rating score of the $$$i$$$-th racer.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$
Output $$$t$$$ integer representing the minimum total number of teams for each test case.
341339 1664 1414 163231000 1000 100051600 1400 1200 1700 1500
3 1 4
As you race along the track, represented by an array $$$a$$$ of $$$n$$$ integers, each element $$$a[i]$$$ signifies a power-up available at position $$$i$$$. These power-ups have special bitwise properties.
For each possible range size $$$k$$$, from $$$1$$$ to $$$n$$$, a temporary array $$$b$$$ is created to evaluate the potential of power-ups.
Mario Bashing. For each position $$$i$$$ on the track (from $$$1$$$ to $$$n$$$), the power-up at $$$b[i]$$$ is the bitwise OR of all power-ups $$$a[j]$$$ such that the absolute difference between your current position $$$i$$$ and the power-up's position $$$j$$$ is less than $$$k$$$.
Formally, for a given $$$k$$$: $$$$$$b[i] = \text{OR}_{1 \le j \le n, |i - j| \lt k} (a[j])$$$$$$
Your goal is to determine, for each value of $$$k$$$ from 1 to $$$n$$$, the bitwise AND of all elements in the array $$$b$$$.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases.
The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of positions on the track.
The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_{n}$$$ ($$$0 \le a_i \lt 2^{30}$$$) — representing the power-ups at each position.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$
Output $$$n$$$ integers, where the $$$k$$$-th integer is the bitwise AND of array $$$b$$$ for each $$$k$$$.
236 1 3410 5 12 8
0 3 7 0 12 13 15
Mario is embarking on a new adventure through the Mushroom Kingdom, and this time he's exploring a level made of $$$n$$$ blocks lined up in a row. Each block $$$i$$$ has a specific height $$$a_i$$$. The blocks are indexed from $$$1$$$ to $$$n$$$.
block. For any continuous sequence of blocks, known as a sub-array, from index $$$l$$$ to $$$r$$$ (where $$$1 \le l \le r \le n$$$), its "beauty" is defined as the sum of height differences between adjacent blocks within that sub-array. Specifically, if $$$l \lt r$$$, the beauty is $$$(a_{l+1} - a_l) + (a_{l+2} - a_{l+1}) + \dots + (a_r - a_{r-1})$$$. If $$$l = r$$$ (a subarray with a single block), the beauty is $$$0$$$.
More formally, the beauty function for $$$l \lt r$$$ , $$$F(l,r)$$$ can be written as: $$$$$$ \sum_{i=l}^{r-1} (a_{i+1} - a_i) $$$$$$
The definition of beauty for the whole array is: $$$$$$ \sum_{l=1}^{n-1} \sum_{r=l+1}^{n} F(l,r) $$$$$$
Your goal is to find the beauty for the whole array.
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of test cases.
For each test case: The first line contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of blocks.
The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_N$$$ ($$$1 \le a_i \le 10^9$$$) — representing the heights of the blocks.
It's guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, print a single integer representing the total sum of the beauty of all contiguous sub-arrays.
221 236 5 10
1 8