You are at a $$$1$$$ dollar supermarket where there are $$$n$$$ sub-shops, each second a new customer comes in every shop, $$$\bf {\text{inititally all of them are empty}}$$$.
Since this is a $$$1$$$ dollar supermarket there is only one worker. Each second this worker chooses uniformaly randomly a shop and serves all it's customers instantly.
To do some savings the boss doesn't hire extra workers unless $$$\bf{\text{all}}$$$ the shops are all floaded. That is if we denote the number of customers of the $$$i-$$$th shop to be $$$a_i$$$.
Then the shops are floaded whenever forall $$$i \in [1, n], a_i \ge b_i$$$ for some pre-fixed $$$b_i$$$.
- $$$\bf{\text{Extra constraints : }}$$$ we assume that $$$b_1 = 0$$$.
One may prove that the shops will be floaded almost certaintly, your task is to calculate the expected time at which the boss will have to hire extra workers.
It can be shown that the answer can be represented as $$$\frac{P}{Q}$$$, where P and Q are coprime integers and $$$Q \not \equiv 0$$$ mod $$$10^9 + 7$$$. Print the value of $$$P\cdot Q^{-1}$$$ mod $$$10^9+7$$$.
The first line of the input you will be given $$$1 \le n \le 2 \cdot 10^5$$$ the number of shops.
The second line of the input contains $$$n$$$ space separated integers $$$b_1, ... b_n (0 \le b_i \le 10^{18})$$$ and $$$b_1 = 0$$$.
Output a single integer the expected time at which the boss will have to hire extra workers modulo $$$10^9 + 7$$$.
3 0 1 1
3
8 0 7 5 6 7 10 6 7
149135259
In a busy data center, lamps are essential for smooth server operations. One day, several lamps go out, making it hard for technicians to work. To fix this, the facility uses a special control panel that can toggle all lamps in a selected row or column — flipping each lamp from on to off or off to on.
Your task is to help restore full lighting using the fewest toggles. If it's impossible to turn all lamps on, output $$$-1$$$.
You're given an $$$n \times m$$$ grid representing lamp states: $$$1$$$ for on, $$$0$$$ for off. With each operation, you can toggle any row or column to flip all its lamp states.
Determine the minimum number of toggles needed to turn every lamp on, or report $$$-1$$$ if it's not possible.
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2500$$$) — the number of rows and columns in the grid.
The next $$$n$$$ lines each contain $$$m$$$ integers (either $$$0$$$ or $$$1$$$) describing the grid.
For each test case, print a single integer $$$-$$$ the minimum number of toggles required to make all lamps on, or $$$-1$$$ if it is impossible.
3 30 1 01 0 10 1 0
3
4 40 0 1 10 0 1 11 1 0 01 1 0 0
4
4 40 0 0 10 0 0 10 0 0 00 0 0 0
-1
$$$$$$ \begin{matrix} 0 & 1 & 0 \\ 1 & 0 & 1 \\ 0 & 1 & 0 \end{matrix} \xrightarrow{\text{Row 2}} \begin{matrix} 0 & 1 & 0 \\ 0 & 1 & 0 \\ 0 & 1 & 0 \end{matrix} \xrightarrow{\text{Col 1}} \begin{matrix} 1 & 1 & 0 \\ 1 & 1 & 0 \\ 1 & 1 & 0 \end{matrix} \xrightarrow{\text{Col 3}} \begin{matrix} 1 & 1 & 1 \\ 1 & 1 & 1 \\ 1 & 1 & 1 \end{matrix} $$$$$$
Imran is working with arrays and bitwise operations. One day, he discovered an interesting property in subarrays. He calls a segment Cool if it satisfies a unique condition involving the maximum value and the bitwise OR of the elements.
You're given an array of integers $$$a$$$. A cool segment is a subarray $$$[l,r]$$$ such that: $$$$$$ \max(a_l, a_{l+1}, \dots, a_r) = a_l \,|\, a_{l+1} \,|\, \dots \,|\, a_r $$$$$$
In simple terms, the maximum value in the segment must be exactly equal to the bitwise OR of all the elements in that segment.
Your task is to count how many such cool segments exist in the array.
The first line contains an integer $$$T$$$ $$$(1 \leq T \leq 10^3)$$$ — the number of test cases.
For each test case:
The first line contains an integer $$$n$$$ $$$(1 \leq n \leq 2 \cdot 10^5)$$$ — the number of elements in the array.
The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \cdots, a_n$$$ $$$(0 \leq a_i \lt 2^{30})$$$ — the elements of the array.
The total sum of $$$n$$$ across all test cases does not exceed $$$2 \cdot 10^5$$$
For each test case, output a single integer — the number of cool segments in the array.
341 2 3 251 2 4 8 1665 9 1 3 6 12
9 5 8
All Subarrays: $$$[1], [2], [3], [2], [1,2]$$$ (Not Cool), $$$[2,3], [3,2], [1,2,3], [2,3,2], [1,2,3,2]$$$
Total Cool Segments: $$$9$$$
Imran owns a magical tree with $$$n$$$ nodes, where the root node is numbered $$$1$$$. Each node in this tree is colored either Red (R), Green (G), or Blue (B).
Imran has a magic wand that allows him to invert the colors of a node and all its descendants in the tree (i.e., the entire subtree rooted at that node). The color inversion follows this cyclic pattern:
$$$$$$\textbf{Red (R)} \to \textbf{Green (G)} \to \textbf{Blue (B)} \to \textbf{Red (R)}$$$$$$
Imran will perform $$$q$$$ operations on the tree. For each operation, he selects a node and uses his wand to invert the colors of all nodes in the subtree rooted at that node.
Your task is to determine the final color of each node after all $$$q$$$ operations have been completed.
The first line contains a positive integer $$$n$$$ $$$(1 \leq n \leq 2 \cdot 10^5)$$$, representing the number of nodes in the tree.
The second line contains $$$n-1$$$ integers $$$p_i$$$ $$$(1 \leq p_i \leq n)$$$, where $$$p_i$$$ indicates the parent of node $$$i+1$$$ in the tree.
The third line is a string of length $$$n$$$ consisting of the characters R, G, and B, where the $$$i$$$-th character represents the initial color of the $$$i$$$-th node.
The fourth line contains a positive integer $$$q$$$ $$$(1 \leq q \leq 2 \cdot 10^5)$$$, representing the number of operations.
The next $$$q$$$ lines each contain a single integer $$$q_i$$$ $$$(1 \leq q_i \leq n)$$$, specifying the node on which the $$$i$$$-th operation is performed.
Output a single string of length $$$n$$$, where the $$$i$$$-th character represents the final color of the $$$i$$$-th node after all operations.
71 1 2 3 3 2RGBGRRB45127
GRRRBGB
After the 1st query, the tree becomes: RGBGGRB.
After the 2nd query, the tree becomes: GBRBBGR.
After the 3rd query, the tree becomes: GRRRBGG.
After the 4th query, the tree becomes: GRRRBGB.
Welcome to the Binary Mirror Maze!
We start with an empty bit string: $$$s_0$$$ = ""
Then, for each integer $$$i \geq 0$$$, construct the next string as follows: $$$s_{i+1} = s_i +$$$ "$$$0$$$" + mirror($$$s_i$$$) Here, mirror(s) means that we first reverse the string s, and then invert each bit (swap every "$$$0$$$" with "$$$1$$$" and every "$$$1$$$" with "$$$0$$$").
For example:
Your task is: Given an integer k, find the k-th character (1-indexed) of the string t.
In the first line you will be given an integer $$$T (1 \le T \le 10^5)$$$ the number of test cases. Each of the next $$$T$$$ following lines you will be given a single integer $$$k(1 \le k \le 10^{18})$$$.
For each integer $$$k$$$ output the $$$k-th$$$ caracter in the infinitely long string $$$t$$$.
5 2 9 6 4 5
0 0 1 0 0
- Imagine you have $$$n$$$ students lined up, each with an integer value. Your challenge is to split this line into one or more consecutive groups (the number of groups $$$m$$$ is not fixed) such that each group meets a special "hull" condition:
- Your task: Compute the number of ways to form such a segmentation of the students, and output your answer modulo $$$10^9 + 7$$$.
The first line contains an integer $$$n$$$ ($$$1 \le n \le 5*10^3$$$) — the number of students.
Print a single integer: the number of valid segmentations, modulo $$$10^9 + 7$$$.
7
5
5
5
Find the number of finite arithmetic sequences with a common difference of $$$D$$$ and a total sum $$$S$$$.
That is find the number of sequences $$$u_0, ... u_n$$$ for some such that forall $$$0 \le i \lt n, u_{i + 1} - u_{i} = D$$$ and $$$u_0 + ... u_n = S$$$.
Input you will be given two integers $$$D, S (1 \le S \le 10^{12}, 1 \le D \le 10^{18})$$$
Output the number of finite arithmetic sequences with a common difference of $$$D$$$ and a total sum of $$$S$$$.
1 8
1
At the scene of a strange break-in, Korombo finds a slip of paper with cryptic clues, all pointing to a secret locker containing the key to the case. The lockers are numbered with integers from $$$-\infty$$$ to $$$+\infty$$$, and each clue gives an inequality that narrows down the possible number $$$x$$$ of the locker.
The inequalities are of the form:
$$$$$$ \texttt{x \gt a} \quad \quad \quad \texttt{x \gt = a} \quad \quad \quad \texttt{x \lt a} \quad \quad \quad \texttt{x \lt = a} $$$$$$ Your task is to help Korombo determine whether there is exactly one integer $$$x$$$ that satisfies all the clues.
The first line contains a single integer $$$n$$$ $$$(1 \leq n \leq 10^5)$$$ — the number of constraints.
Each of the next $$$n$$$ lines contains a constraint in one of the following four forms:
Where $$$a$$$ is an integer with absolute value at most $$$10^9$$$.
Print the result on a single line:
The answer is case-insensitive. For example, IMPOSSIBLE, Impossible, or impossible will all be accepted.
4> 5>= 6< 8<= 6
6
2> 2<= 5
NOT UNIQUE
2>= 10< 10
IMPOSSIBLE
You work at a secret communications office, where every day you handle mysterious messages encoded in lowercase letters. One day, you receive two messages, both containing exactly the same number of letters. Your mission is to transform the first message $$$S$$$ into the second message $$$T$$$ using a very special operation.
The operation you can perform consists of two parts:
Note: If the chosen indices $$$i$$$ and $$$j$$$ are adjacent, the operation simply swaps the two letters, as there are no letters between them to flip.
Your goal is to determine the minimum number of operations required to transform $$$S$$$ into $$$T$$$. If it is impossible to transform $$$S$$$ into $$$T$$$ using these operations, output $$$-1$$$.
The first line contains an integer $$$n$$$ ($$$2 \le n \le 7$$$) — the length of the strings.
The second line contains a string $$$S$$$ of length $$$n$$$, consisting of lowercase English letters.
The third line contains a string $$$T$$$ of length $$$n$$$, also consisting of lowercase English letters.
Print a single integer: the minimum number of operations required to transform $$$S$$$ into $$$T$$$, or $$$-1$$$ if it is impossible.
3abcxyz
7
6codemimeowic
6
3cdeeyd
-1
Testcase 1: $$$$$$ \begin{array}{rcl} \texttt{abc} \xrightarrow{\text{1}} \texttt{cya} \xrightarrow{\text{2}} \texttt{yca} \xrightarrow{\text{3}} \texttt{axy} \xrightarrow{\text{4}} \texttt{xay} \xrightarrow{\text{5}} \texttt{yzx} \xrightarrow{\text{6}} \texttt{yxz} \xrightarrow{\text{7}} \texttt{xyz} \end{array}$$$$$$
You are given Speed, Haste, Strength, Instant Health, Regeneration, Resistance, Fire Resistance, Jump Boost, Nausea, Weakness, Poison, Wither, Health Boost, Absorption, Saturation, Glowing, Bad Omen, Levitation, Dolphin's Grace, Conduit Power, Water Breathing, Slow Falling, Luck, Bad Luck.
Since the answer can be very small, print it modulo answer+1.
A lot of pairs of positif integers
A lot of single integers
6 0 3 0 4 0 5 4 9 73267 73267 23 1238916
6 10 15 39 73267 767457046733