For Halloween, Mondialu went to each of his neighbors to ask for candies. In order to receive the maximum number of candies, he needs to be as scary as possible.
Mondialu has $$$n$$$ Halloween costumes $$$a_1, a_2, a_3, ... , a_n$$$. He needs to choose a subsequence (a sequence that can be derived from the array by deleting some or no elements without changing the order of the remaining elements) from the $$$n$$$ costumes (yes, Mondialu can wear multiple costumes, this is the level of scariness we are dealing with).
A subsequence is the scariest if it has the following properties:
An array $$$X$$$ is lexicographically larger than an array $$$Y$$$ if there exist an $$$i$$$ so that $$$x_1 = y_1, x_2 = y_2, ... , x_{i-1} = y_{i-1}$$$ and $$$x_i \gt y_i$$$ or if $$$Y$$$ is a prefix of $$$X$$$.
The first line of each test case contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the length of the array.
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, a_3, ... , a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the elements of the array.
Output a single line, the elements of the scariest subsequence separated by spaces. If no such subsequence exists, print $$$-1$$$.
8 3 1 2 3 2 3 3 3
3 3 3 3
3 1 2 3
-1
In the first example, the subsequence $$$3\ 3\ 3\ 3$$$ has an even positive length ($$$4$$$) and the first half $$$3\ 3$$$ is equal to the second half $$$3\ 3$$$. This is the lexicographically largest subsequence which respects the conditions.
In the second example, we cannot generate any subsequence which would respect the conditions, so the output is $$$-1$$$.
Nitoiu found out that he sings really reaally bad so he wants a career change. While expanding his skillset, he discovered that he is very good at arithmetic operations.
His old producer Sake doesn't like the idea of losing a long time collaborator so he wants to discourage Nitoiu by proving that he is not as good at arithmetics as he thinks he is.
Sake gives Nitoiu two integers $$$N$$$, $$$K$$$ and asks him the minimum number of concatenations of $$$N$$$ with itself such that the result is divisible by $$$K$$$. If by concatenating $$$N$$$ with itself any number of times it is impossible to find a multiple of $$$K$$$ the answer is considered $$$-1$$$.
Nitoiu promises that he will cover your favorite song if you help him with this task.
The only line contains two integers $$$N$$$ and $$$K$$$ ($$$1 \leq N \leq 10^9$$$, $$$1 \leq K \leq 10^5$$$).
Output a single integer - the minimum number of concatenations needed to obtain a multiple of $$$K$$$ or $$$-1$$$ if this is impossible.
2 6
2
The minimum number of concatenations needed is $$$2$$$ because $$$222$$$ is divisible by $$$6$$$ and $$$22$$$ is not divisible by $$$6$$$.
Besides the delicacy that is freshmen blood drank during the Halloween night, Luna also enjoys prime numbers a lot... and the number 3... so she gives you a number $$$N$$$ and demands the number of different ways that the number $$$N$$$ can be written as a sum of 3 prime numbers.
Because you won't risk getting your blood drank by Luna, you decide to answer her demands.
The only line of input contains one integer $$$N$$$ ($$$ 1 \leq N \leq 5\cdot 10^4$$$)
Output a single integer - the number of ways to write $$$N$$$ as sum of 3 prime numbers.
7
1
The only correct way of expressing 7 as sum of 3 prime numbers is $$$7=2+2+3$$$. Permutations of the same prime numbers won't count (such as $$$2+3+2$$$)
While searching in the garbage cans, Jean found a sequence of $$$N$$$ positive integers. Because he has no use for this, he gifted it to Nicusor Gioconda, and gave him a challenge too.
Nicusor has to chose pairwise distinct substrings of length $$$2$$$ such that every index is taken at least once. If he will give a correct partitioning, he will get the ultimate prize: the magical chicken wing!
In this problem, we consider that a substring is a contiguous subset of indices $$$[i,i+1,\cdots j-1, j]$$$.
Because he is far better at singing than he is at solving problems, he asks for your help.
First line will contain a single number $$$N$$$ ($$$1 \leq N \leq 10^5$$$) - the length of the sequence. The next line contains a sequence $$$A$$$ of $$$N$$$ positive values ($$$1 \leq A_i \leq 500$$$).
The first line will contain a string that is either "YES" or "NO", that represents the existence of a correct partitioning.
5 1 2 1 2 3
YES
5 1 2 2 2 2
NO
For the first example, a valid partitioning is $$$[1,2], [2,1], [2,3]$$$ corresponding to the indices $$$[1,2], [2,3], [4,5]$$$.
RMN wasted all his money on sports betting...again. However, he still feels the need of betting just one more time in order to at least recover his losses.
The only issue is that he needs a big sum to get a good return on his last "safe" bet. Because he doesn't have a lot of skills, he can't get this money too easily. Luckily, a man in the parking spot of a gas station offered him 100 RON if he can count how many substrings of an integer sequence have their maximum value between two given values.
More formally, RMN receives an integer sequence $$$A$$$ of $$$N$$$ numbers, and two integers $$$L$$$ and $$$U$$$. He is asked to count how many substrings $$$S = A[i,i+1\cdots j]$$$ have $$$L \leq max(S) \leq U$$$.
Help RMN retire in glory by winning the 100 RON needed for his first win!
P.S. He will probably lose anyway :(
The first line will contain 3 integers $$$N$$$ ($$$ 1 \leq N \leq 10^5$$$), $$$L$$$ ($$$-10^{18} \leq L \leq 10^{18}$$$), $$$U$$$ ($$$-10^{18} \leq U \leq 10^{18}$$$) - the length of the array $$$A$$$, the lower and the upper bounds for the maximum of the substrings that need to be counted. The following line will contain $$$N$$$ integers between $$$-10^{18}$$$ and $$$10^{18}$$$ - the values of the sequence $$$A$$$.
The only line will contain a single integer - the number of substrings of $$$A$$$ with their maximum value between $$$L$$$ and $$$U$$$.
5 3 4 1 5 2 4 3
5
The substrings with their maximum value between 3 and 4 are: $$$[4], [2,4], [4,3], [4,3,2], [3]$$$
In Scundu, two boys were playing basketball. They are not very good at the game, so they got bored and decided to rest on a bench. While sitting there, they wondered: if a game of basketball ends with the score $$$A$$$ and $$$B$$$, where $$$A$$$ is the score of the first team and $$$B$$$ is the score of the second team, in how many ways can this score be obtained? Because they are not very good at programming either, they need your help to find out.
In Scundu, the basketball rules are the following: depending on the striking distance, each team can get either 2 or 3 points for introducing the ball in the basket. Because scundenians are superior people, we consider that faults will never occur.
The input contains two integers $$$A$$$ and $$$B$$$ ($$$ 0 \le A, B \le 500$$$ ), where $$$A$$$ is the score of the first team and $$$B$$$ is the score of the second team.
The output contains one integer $$$X$$$, the number of ways that score can be obtained. Because the number of ways can be very big, the number of ways should be printed modulo $$$1.000.000.007$$$
2 5
6
The ways we can obtain the score are the following:
$$$0$$$ to $$$0$$$ -> $$$2$$$ to $$$0$$$ -> $$$2$$$ to $$$3$$$ -> $$$2$$$ to $$$5$$$
$$$0$$$ to $$$0$$$ -> $$$2$$$ to $$$0$$$ -> $$$2$$$ to $$$2$$$ -> $$$2$$$ to $$$5$$$
$$$0$$$ to $$$0$$$ -> $$$0$$$ to $$$3$$$ -> $$$2$$$ to $$$3$$$ -> $$$2$$$ to $$$5$$$
$$$0$$$ to $$$0$$$ -> $$$0$$$ to $$$3$$$ -> $$$0$$$ to $$$5$$$ -> $$$2$$$ to $$$5$$$
$$$0$$$ to $$$0$$$ -> $$$0$$$ to $$$2$$$ -> $$$2$$$ to $$$2$$$ -> $$$2$$$ to $$$5$$$
$$$0$$$ to $$$0$$$ -> $$$0$$$ to $$$2$$$ -> $$$0$$$ to $$$5$$$ -> $$$2$$$ to $$$5$$$
In 10660 B.C., we will assume that, in Scundu, there has been the most epic battle to this day (because we can't prove that it didn't happen). The battle between the scundenians (the name of the people from scundu) and the invading forces was very close, so close that it was perfectly even and both sides decided to call for reinforcements. We say that the scundenians won the battle if, in every moment of the battle (since the reinforcements start to arrive), the number of scundenians engaged in battle was greater or equal to the number of invading forces engaged in battle.
Knowing the number $$$N$$$ of scundenians that come as reinforcements, the same $$$N$$$ number of invading forces that come as reinforcements and that at every second there is exactly one soldier arriving at battle (either scundenian or invader), find the number of ways the reinforcements can come so that the scundenians win The Battle of Scundu
We consider that 2 ways of the reinforcements $$$a_0 a_1 ... a_n$$$ and $$$b_0 b_1 ... b_n$$$ to come are different if at any second $$$1 \le i \le n$$$ we have $$$a_i \neq b_i$$$ (where $$$a_i$$$ and $$$b_i$$$ represent the type of the soldier that comes at the second $$$i$$$ , scundenian or invader).
You receive one integer from the console $$$N$$$ ($$$ 1 \le N \le 1.000.000$$$) , the number of soldiers each side gets as reinforcements.
You have to print one number $$$x$$$ , the number of ways the scundenians win the Battle of Scundu. Because the number can be very big, you have to output the number modulo $$$1.000.000.007$$$
3
5
If we represent the reinforcements as a sequence $$$a_1,a_2...a_{2N} $$$ where $$$a_i = S$$$ means that at the second $$$i$$$ a scundenian arrived at the battle, while $$$a_i = I$$$ means that at the second $$$i$$$ an invader arrived at the battle, we can describe the possible ways the reinforcements can come as:
$$$SSSIII$$$
$$$SSISII$$$
$$$SSIISI$$$
$$$SISSII$$$
$$$SISISI$$$
After a tiring practical test at OOP, Rares is faced with a new challenge. He has to solve the following problem, otherwise he will fail the Programming class.
Let $$$v$$$ be an array of $$$n$$$ non-negative integers. Find the maximum value of ($$$v_i$$$ $$$\oplus$$$ $$$v_j$$$) $$$\times$$$ ($$$v_k$$$ + $$$v_l$$$), where $$$1$$$ $$$\le$$$ $$$i \lt j \lt k \lt l$$$ $$$\le$$$ $$$n$$$. Here $$$\oplus$$$ represents the bitwise xor operation.
Help Rares save his GPA!
The first line of the input contains $$$n$$$ ($$$4$$$ $$$\le$$$ $$$n$$$ $$$\le$$$ $$$200000$$$), the size of the given array.
The next line contains $$$n$$$ non-negative integers $$$v_1$$$, $$$v_2$$$, ..., $$$v_n$$$ ($$$0$$$ $$$\le$$$ $$$v_i$$$ $$$\le$$$ $$$2^{30}-1$$$).
Output a single number, the maximum value of ($$$v_i$$$ $$$\oplus$$$ $$$v_j$$$) $$$\times$$$ ($$$v_k$$$ + $$$v_l$$$), where $$$1$$$ $$$\le$$$ $$$i \lt j \lt k \lt l$$$ $$$\le$$$ $$$n$$$.
6 12 42 2 0 145 7
6384
Rares chooses $$$i=2$$$, $$$j=4$$$, $$$k=5$$$, $$$l=6$$$. The value is ($$$42$$$ $$$\oplus$$$ $$$0$$$) $$$\times$$$ ($$$145$$$ + $$$7$$$) = $$$6384$$$.
As many of you might know, during the golden age of romanian television, one of the most beloved channels was named OTV.
One of the reasons for its popularity were the polls where the spectators voted for one of two options. Maybe the most popular poll was the one asking who would win in a fight between the dacians and the samurai.
After years and years, the OTV founder, DD, is back with his new project: DD Home Cinema. In order to regain his old level of fame he wants to please the nostalgics by bringing back the famous poll, but with a modern twist!
DD gives his spectators two integer sequences $$$A$$$ (the strenghts of the dacians) and $$$B$$$ (the strengths of the samurai) and wants another sequence $$$C$$$ of the same length, where $$$C_i \in \{A_i, B_i\}$$$ (either the $$$i$$$-th dacian or the $$$i$$$-th samurai). Because such a large sequence would not fit well on a tv display, he asks for his spectators only for the smallest difference in strength of such a sequence.
Formally, the spectators are asked for the minimum value of $$$max(C) - min(C)$$$ among all possible sequences $$$C$$$.
The first line will contain a single integer $$$N \leq 10^5$$$ - the length of the arrays $$$A$$$ and $$$B$$$.
The following $$$N$$$ lines will each contain 2 integers, $$$A_i, B_i \leq 10^9$$$, the values that form the sequences $$$A$$$ and $$$B$$$
The only line will contain a single integer - the minimum value of said expression.
5 3 4 1 2 6 7 5 1 8 3
4
The minimum value is 4, and it can be obtain by choosing $$$C_1=A_1, C_2=B_2 , C_3=A_3 , C_4=A_4 , C_5 = B_5$$$.
After getting bored of playing with the Rubik's Cube and submitting Wrong Answers, Ion decided to move on to more interesting activities. He decided to play a game with his good friend Mario on a one dimensional board which can be represented as an array with $$$n$$$ non-negative integers $$$a_1, a_2, a_3, ... , a_n$$$. The game is played by the following rules:
They play this game many times and the board can be modified many times. Ion wants to ask you for some initial states who will win the game.
The first line of input contains $$$2$$$ integers $$$n$$$ and $$$m$$$ $$$(1 \le n,m \le 200000)$$$, denoting the length of the array and the number of operations.
The second line contains $$$n$$$ integers $$$a_1, a_2 , ... , a_n$$$ $$$(0 \le a_i \le 255)$$$, denoting the array $$$a$$$.
The next $$$m$$$ lines each contains $$$2$$$ integers $$$op$$$ $$$(1 \le op \le 2)$$$ and $$$k$$$, denoting each operation:
For each operation with $$$op=2$$$, output one line containing "Ion" if Ion will win, or "Mario" if Mario will win.
4 6 7 6 5 4 2 4 1 5 2 4 1 2 2 3 2 2
Mario Ion Mario Mario
It is the first day of school and you are in Computer Science class. Your best friend Iuli has a new challenge for you.
He hands you a string consisting of lowercase english characters and asks you to find the length of all its periods.
A period of a string is a prefix of it which has the property that the string can be written as a concatenation of that prefix with itself for a finite number of times.
For example, the periods of $$$aaaaaa$$$ are $$$a, aa, aaa, aaaaaa$$$.
Due to the high ammount of input and output data, it is recommended to code in C++, use streams and the following instructions before reading the input for speedup:
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
On the first line there will be an integer $$$t \lt =20$$$, the number of testcases.
On each of the next $$$t$$$ lines there will be a string $$$s$$$ $$$(|s| \lt =10^6)$$$ containing lowercase letters of the english alphabet.
The sum of lengths of all strings in the input will not exceed $$$2\cdot10^7$$$.
The output will consist of $$$t$$$ lines.
On line $$$i$$$ there will be a list of integers signifying the periods of the $$$i^{th}$$$ string in the input. The numbers on each line will be sorted increasingly and will have a single space between them.
1 aaaaaa
1 2 3 6
The periods of $$$aaaaaa$$$ are $$$a, aa, aaa, aaaaaa$$$ which have lengths $$$1, 2, 3, 6$$$
Mathematical Final Boss is getting tired from all his success and decided to start playing with some integer sequences.
After a while, he found a very interesting function which he called $$$SAlt$$$. For a sequence of numbers $$$S = a_1, a_2, \cdots a_k$$$, he takes the non-increasing sorted sequence and stars to alternatively add and substract numbers. Formally if the sorted sequence is $$$a_{i_1},a_{i_2},\cdots a_{i_k}$$$, we have $$$SAlt(S) = \sum_{p=1}^{k}(-1)^{(p-1)}\cdot a_{i_p}$$$.
This is too easy for our Final Boss, so, for a sequence of numbers he now wants to compute the sum of the $$$SAlt$$$ values for all its subsets.
Now every morning he takes an integer sequence $$$A$$$ with $$$N$$$ numbers and $$$Q$$$ queries $$$q_i=(l_i,r_i)$$$ that ask for the $$$SAlt$$$ sum of all subsets of numbers of the substring $$$A[l_i,r_i]$$$.
He can do all these computations in less than a second and he is now curious if you can do it too with the help of a modern computer.
Because the numbers can become very large, you have to compute it modulo $$$10^9 + 7$$$.
First line will contain one integer $$$N$$$ $$$(1 \leq N \leq 10^5)$$$ - the length of the sequence. The second line will contain $$$N$$$ numbers $$$(1 \leq A_i \leq 2\cdot 10^5)$$$ - the elements of the sequence. The third line contains $$$Q$$$ $$$(1 \leq Q \leq 10^5)$$$ - the number of queries. The following $$$Q$$$ lines each have a pair of numbers $$$l_i,r_i$$$ denoting the query interval.
The $$$i$$$-th line will represent the answer to the $$$i$$$-th query given by the Final Boss.
5 5 4 3 2 1 3 2 3 1 5 2 2
8 80 4
For the first query, we have the substring $$$4,3$$$, with the subsets $$$S_1 = \{4\}, S_2 = \{3\}, S_3 = \{3,4\}$$$. We have $$$SAlt(S_1) = 4$$$, $$$SAlt(S_2) = 3$$$ and $$$SAlt(S_3) = 4 - 3 = 1$$$. The answer for this query is $$$4+3+1=8$$$.
As Rares failed his OOP exam mentioned earlier, he tries his luck with this problem hoping to forget his problems. We call an interesting-substring any substring which has at least one minimum value in its second half. $$$[1, 0, 3, 0, 4, 6]$$$ is an interesting substring because its minimum, $$$0$$$ lays in the second half, while $$$[1, 0, 3, 0, 5, 6, 8]$$$ is not an interesting substring as its minimum, $$$0$$$ lays in the first half.
$$$ATTENTION!$$$ If the substring is of odd length, the middle is considered to be a part of the first half
In this problem, we consider that a substring is a contiguous subset of indices $$$[i,i+1,\cdots j-1, j]$$$.
Given an array of $$$N$$$ elements, calculate the number of interesting substrings.
The first line contains a single number $$$N$$$ ($$$1 \le N \le 200000$$$). The second line contains $$$N$$$ positive numbers $$$\le 10^9$$$ separated with spaces.
The only line contains the number of substrings computed.
5 1 3 2 0 5
6
6 0 0 2 3 1 0
8
For the first example the substrings are: $$$[ (1, 3, 2, 0), (1, 3, 2, 0, 5), (3, 2), (3, 2, 0), (3, 2, 0, 5), (2, 0)]$$$
For the second example the substrings are: $$$[(0, 0), (0, 0, 2, 3, 1, 0), (0, 2, 3, 1, 0), (2, 3, 1), (2, 3, 1, 0), (3, 1), (3, 1, 0), (1, 0)]$$$
The scientists at UniBuc have recently discovered an ancient game played by the Dacians called Bitscore. They would write on a piece of paper multiple strictly positive numbers and the players had to choose subsets with the property that the number of digits in the binary form of the numbers create a strictly decreasing sequence. For instance $$$100, 63, 4, 2, 1$$$ is a valid sequence, while $$$100, 64$$$ is not valid.
Given an array of $$$N$$$ numbers compute the number of valid subsets. Because the result can be very big, print the result modulo $$$1000000007$$$.
$$$ATTENTION!$$$ The elements of a subset can be rearranged.
The first line contains a single number $$$N$$$ ($$$1 \le N \le 100000$$$). The second line contains $$$N$$$ numbers $$$\le 10^9$$$ separated with spaces.
The only line contains the number of valid subsets.
6 1 3 2 16 5 9
47
6 1 6 3 4 5 2
23
For the second example the subsets are: $$$[(1), (2), (3), (4), (5), (6), (2, 1), (3, 1), (4, 1), (4, 2), (4, 3), (5, 1), (5, 2), (5, 3), (6, 1), (6, 2), (6, 3), (4, 2, 1), (4, 3, 1), \\(5, 2, 1), (5, 3, 1), (6, 2, 1), (6, 3, 1)]$$$