FMI No Stress 11
A. String String
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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:

  • Has an even positive length.
  • The first half of the subsequence is equal to the second half.
  • It is the lexicographically largest subsequence.

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$$$.

Input

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

Output a single line, the elements of the scariest subsequence separated by spaces. If no such subsequence exists, print $$$-1$$$.

Scoring
  • $$$1 \le n \le 5$$$ for $$$20$$$ points
  • $$$5 \lt n \le 100$$$ for $$$20$$$ points
  • $$$100 \lt n \le 1000$$$ for $$$20$$$ points
  • $$$1000 \lt n \le 100000$$$ for $$$40$$$ points
Examples
Input
8
3 1 2 3 2 3 3 3
Output
3 3 3 3 
Input
3
1 2 3
Output
-1
Note

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$$$.

B. Nitoiu
time limit per test
0.25 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

The only line contains two integers $$$N$$$ and $$$K$$$ ($$$1 \leq N \leq 10^9$$$, $$$1 \leq K \leq 10^5$$$).

Output

Output a single integer - the minimum number of concatenations needed to obtain a multiple of $$$K$$$ or $$$-1$$$ if this is impossible.

Scoring
  • for 20 points it is guaranteed that $$$N \lt 10$$$, $$$K \leq 18$$$ and the lowest multiple is less than $$$10^{18}$$$
  • for another 20 points it is guaranteed that $$$N \lt 10$$$, $$$K \leq 1000$$$ and the result is less than $$$10^4$$$.
  • for another 20 points it is guaranteed that $$$N \lt 10$$$, $$$K \leq 10^5$$$ and the result is less than $$$10^7$$$.
  • for another 20 points it is guaranteed that $$$N \leq 1000$$$, $$$K \leq 10^5$$$ and the result is less than $$$10^7$$$.
  • the last 20 points are given for tests where $$$N \leq 10^9$$$ and $$$K \leq 10^5$$$.
Example
Input
2 6
Output
2
Note

The minimum number of concatenations needed is $$$2$$$ because $$$222$$$ is divisible by $$$6$$$ and $$$22$$$ is not divisible by $$$6$$$.

C. Prime
time limit per test
0.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

The only line of input contains one integer $$$N$$$ ($$$ 1 \leq N \leq 5\cdot 10^4$$$)

Output

Output a single integer - the number of ways to write $$$N$$$ as sum of 3 prime numbers.

Scoring
  • for 40 points it is guaranteed that $$$N \leq 100$$$
  • for another 30 points it is guaranteed that $$$N \leq 5000$$$
  • for the other 30 points, $$$N \leq 5\cdot 10^4$$$
Example
Input
7
Output
1
Note

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$$$)

D. Gioconda
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

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$$$).

Output

The first line will contain a string that is either "YES" or "NO", that represents the existence of a correct partitioning.

Scoring
  • for 20 point it is guaranteed that $$$N \leq 20$$$
  • for the other 80 points we have $$$N \leq 10^5$$$
Examples
Input
5
1 2 1 2 3
Output
YES
Input
5
1 2 2 2 2
Output
NO
Note

For the first example, a valid partitioning is $$$[1,2], [2,1], [2,3]$$$ corresponding to the indices $$$[1,2], [2,3], [4,5]$$$.

E. CntSeq
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 :(

Input

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$$$.

Output

The only line will contain a single integer - the number of substrings of $$$A$$$ with their maximum value between $$$L$$$ and $$$U$$$.

Scoring
  • for 25 points, it is guaranteed that $$$N \leq 500$$$
  • for another 25 points, it is guaranteed that $$$N \leq 5000$$$
  • for the last 50 points, we have $$$N \leq 10^5$$$
Example
Input
5 3 4
1 5 2 4 3
Output
5
Note

The substrings with their maximum value between 3 and 4 are: $$$[4], [2,4], [4,3], [4,3,2], [3]$$$

F. Basketball
time limit per test
0.5 seconds
memory limit per test
128 megabytes
input
standard input
output
standard output

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.

Input

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.

Output

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$$$

Scoring
  • for 30 points, we have $$$ 0 \le A, B \le 10$$$
  • for another 20 points, we have $$$A = 0$$$ or $$$B = 0$$$
  • for the last 50 points, we have $$$ 0 \le A, B \le 500$$$
Example
Input
2 5
Output
6
Note

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$$$

G. Battle of Scundu
time limit per test
0.5 seconds
memory limit per test
128 megabytes
input
standard input
output
standard output

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).

Input

You receive one integer from the console $$$N$$$ ($$$ 1 \le N \le 1.000.000$$$) , the number of soldiers each side gets as reinforcements.

Output

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$$$

Scoring
  • for 30 points it is guaranteed that $$$N \le 30$$$
  • for another 30 points it is guaranteed that $$$N \le 1000$$$
  • for the last 40 points, we have $$$N \le 1.000.000$$$
Example
Input
3
Output
5
Note

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$$$

H. for-for-for-for
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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!

Input

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

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$$$.

Scoring
  • For $$$20$$$ points, it is guaranteed that $$$n$$$ $$$\le$$$ $$$200$$$
  • For another $$$20$$$ points, it is guaranteed that $$$n$$$ $$$\le$$$ $$$2000$$$
  • For the last $$$60$$$ points, we have $$$n \leq 200000$$$
Example
Input
6
12 42 2 0 145 7
Output
6384
Note

Rares chooses $$$i=2$$$, $$$j=4$$$, $$$k=5$$$, $$$l=6$$$. The value is ($$$42$$$ $$$\oplus$$$ $$$0$$$) $$$\times$$$ ($$$145$$$ + $$$7$$$) = $$$6384$$$.

I. Dacians vs Samurai
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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$$$.

Input

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$$$

Output

The only line will contain a single integer - the minimum value of said expression.

Scoring
  • for 5 points, it is guaranteed that $$$N \leq 2$$$
  • for another 15 points, it is guaranteed that $$$N \leq 20$$$
  • for another 20 points, it is guaranteed that $$$N \leq 5000$$$
  • for the last 60 points, we have $$$N \leq 10^5$$$
Example
Input
5
3 4
1 2
6 7
5 1
8 3
Output
4
Note

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$$$.

J. P-ON
time limit per test
3 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

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 the game by moving a pawn on the board which is initially placed at position $$$k$$$.
  • Ion takes the first move, and they take moves alternatively.
  • In any move with the pawn at position $$$i$$$, the current player must move the pawn to the smallest next position $$$j$$$ such that $$$j \gt i$$$ and $$$a_j$$$ differs from $$$a_i$$$ on at most one bit in binary representation.
  • The player who can't make any legal move loses the game.

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.

Input

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:

  • $$$op=1$$$ means a modification on the board. Ion will append an integer $$$k$$$ $$$(0 \le k \le 255)$$$ at the end of the array so the array becomes $$$a_1 , a_2 , ... , a_{n+1}$$$ where $$$n$$$ is the current length of the array before modification.
  • $$$op=2$$$ means a new game starts with the pawn at position $$$k$$$ $$$(1 \le k \le n)$$$, where $$$n$$$ is the current length of the array. You need to predict the winner of this game.
Output

For each operation with $$$op=2$$$, output one line containing "Ion" if Ion will win, or "Mario" if Mario will win.

Scoring
  • for $$$20$$$ points it is guaranteed that $$$n \le 1000$$$ and $$$m \le 1000$$$
  • for the other $$$80$$$ points, $$$n \le 200000$$$ and $$$m \le 200000$$$
Example
Input
4 6
7 6 5 4
2 4
1 5
2 4
1 2
2 3
2 2
Output
Mario
Ion
Mario
Mario

K. Iuli
time limit per test
0.8 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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);
Input

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$$$.

Output

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.

Scoring
  • for $$$30$$$ points, it is guaranteed that the sum of lengths of all strings in the input will not exceed $$$10^4$$$
  • for another $$$40$$$ points, it is guaranteed that the sum of lengths of all strings in the input will not exceed $$$5\cdot10^6$$$
  • for the last $$$30$$$ points, the sum of lengths of all strings in the input will not exceed $$$2\cdot10^7$$$.
Example
Input
1
aaaaaa
Output
1 2 3 6 
Note

The periods of $$$aaaaaa$$$ are $$$a, aa, aaa, aaaaaa$$$ which have lengths $$$1, 2, 3, 6$$$

L. SAlt
time limit per test
1.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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$$$.

Input

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.

Output

The $$$i$$$-th line will represent the answer to the $$$i$$$-th query given by the Final Boss.

Scoring
  • for $$$20$$$ points, it is guaranteed that $$$N\leq20$$$ and $$$Q\leq 50$$$.
  • for the other $$$80$$$ points, we have $$$N \leq 10^5$$$ and $$$Q \leq 10^5$$$.
Example
Input
5
5 4 3 2 1
3
2 3
1 5
2 2
Output
8
80
4
Note

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$$$.

M. Interesting Minimums
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

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.

Output

The only line contains the number of substrings computed.

Scoring
  • for 30 points $$$N \leq 200$$$
  • for another 30 points, $$$N \leq 5000$$$
  • for the last 40 points, $$$N \leq 200000$$$
Examples
Input
5
1 3 2 0 5
Output
6
Input
6
0 0 2 3 1 0
Output
8
Note

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)]$$$

N. Bitscore
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

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.

Output

The only line contains the number of valid subsets.

Scoring
  • for 35 points, it is guaranteed that $$$N \leq 15$$$
  • for the last 65 points, we have $$$N \leq 100000$$$
Examples
Input
6
1 3 2 16 5 9
Output
47
Input
6
1 6 3 4 5 2
Output
23
Note

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)]$$$