Krosh Kaliningrad Contest 1
A. Krosh and new sum
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Krosh has an array of $$$n$$$ integers. Help him to calculate the following value: $$$\sum\limits_{i=1}^n \sum\limits_{j=i+1}^n |a_i - a_j| * (a_i + a_j)$$$. Output it modulo $$$10^9+7$$$.

Input

In the first line you are given number $$$2 \le n \le 2 * 10^5$$$. In the second line you are given array of $$$n$$$ non-negative integers $$$1 \le a_i \le 10^8$$$.

Output

Output answer modulo $$$10^9+7$$$.

Examples
Input
5
2 3 4 5 1
Output
120
Input
2
100000000 100000000
Output
0
Input
10
1 100000000 1 100000000 100000000 1 1 100000000 100000000 1
Output
249999989

B. Krosh and xor of sums
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Krosh has an array of $$$n$$$ non-negative integers. He determines the beauty of array in the following way. He picks a number $$$1 \le k \le n$$$ and some sequence $$$b$$$ of $$$k$$$ different integers $$$1 \le b_i \le n$$$. Then he determines the value of this sequence $$$V(b)$$$ as sum of elements of an array $$$a$$$ on the corresponding positions from array $$$b$$$: $$$V(b) = \sum \limits_{i = 1}^k a_{b_i}$$$. Then the beauty of an array $$$a$$$ equals to bitwise xor of all the values $$$V(b)$$$ over all possible sequences $$$b$$$ which can be obtained in the way described above(pick $$$k$$$ and $$$k$$$ different numbers from $$$1$$$ to $$$n$$$). Help Krosh to determine the beauty of an array $$$a$$$.

Input

In first line you are given number $$$1 \le n \le 2 * 10^5$$$ – number of elements in array $$$a$$$. In the next line you are given an array $$$a$$$ of $$$n$$$ non-negative integers $$$0 \le a_i \le 10^7$$$.

Output

Output the beauty of an array $$$a$$$.

Examples
Input
2
1 2
Output
3
Input
1
10
Output
10

C. Find the order
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given an array of $$$n$$$ positive integers. You should determine is it possible to reorder it's elements in such a way that condition $$$a_1 \lt a_2 \gt a_3 \lt a_4 \gt a_5... $$$ is true. In other words, first element should be strictly less than the second, the second element should be strictly greater than the third etc. If such order exists output $$$n$$$ numbers – the resulting array. If no, just output $$$-1$$$. If there are more than one correct order output any of correct arrays.

Input

In first line you are given number $$$n$$$, $$$1 \le n \le 10^5$$$ – number of elements in array. In the second line you are given $$$n$$$ positive integers $$$1 \le a_i \le 10^9$$$ – array itself.

Output

Output correct order if it exists or $$$-1$$$ if no. Output elements not indices.

Examples
Input
5
1 2 3 4 1
Output
1 3 1 4 2
Input
4
1 1 1 1
Output
-1

D. Krosh and series sum
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Krosh has a homework: calculate the sum of the following series: $$$\sum\limits_{n = 1}^{\infty} \frac{n^k}{2^n}$$$, where $$$k$$$ is given. Help him to calculate it. It's guaranteed that the answer is integer. Output it modulo $$$10^9+7$$$.

Input

You are given an integer $$$1 \le k \le 5000$$$.

Output

Output the answer modulo $$$10^9+7$$$.

Examples
Input
1
Output
2
Input
2
Output
6

E. Krosh and expected value problem
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

Krosh has been learning probability theory and came up with the following problem: consider an array of $$$n$$$ natural numbers from $$$1$$$ to $$$x$$$ and natural number $$$k$$$. Then $$$k$$$ steps follow, on each step we take current array and simultaneously insert a random number from $$$1$$$ to $$$x$$$ between every pair of adjacent numbers, these numbers are chosen equiprobably and independently on each step and in each step. Krosh is interested what is expected number of segments consisting of the equal numbers after $$$k$$$ steps of the algorithm? For example, if $$$a = [1, 2, 4, 1, 1, 5, 5, 6]$$$, $$$x = 6$$$, then number of segments is $$$6$$$. After one step we can obtain the array: $$$[1, 5, 2, 2, 4, 3, 1, 1, 1, 1, 5, 6, 5, 2, 6]$$$ with $$$11$$$ segments.

Input

In first line you are given three natural numbers $$$1 \le n \le 10^5$$$, $$$1 \le x \le 10^9$$$, $$$0 \le k \le 10^9$$$. In next line you are given an array of $$$n$$$ natural numbers from $$$1$$$ to $$$x$$$.

Output

Output answer modulo $$$10^9+7$$$. Answer can be represented as $$$P/Q$$$, where $$$P$$$ and $$$Q$$$ are non-negative integers and $$$Q \gt 0$$$. Output $$$P * Q^{-1}$$$ modulo $$$10^9+7$$$.

Example
Input
5 4 2
1 2 3 4 4
Output
13

F. Krosh and arrays
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Krosh has two numbers $$$n$$$ and $$$m$$$. He calls an array consisting of $$$k$$$ elements good, if any two adjacent numbers differ only by one, so for any $$$1 \le i \le k - 1$$$ $$$|a_i - a_{i + 1}| = 1$$$. Array of length $$$1$$$ is always good. Help Krosh to calculate number of arrays of size $$$m$$$ elements consisting of natural numbers from $$$1$$$ to $$$n$$$ such that every number from $$$1$$$ to $$$n$$$ appears at least once in this array. Answer can be large so output it modulo $$$10^9+7$$$. Two arrays are different if there exists a position in which two elements differ.

Input

You are given two natural numbers $$$1 \le m \le 2000$$$, $$$1 \le n \le m$$$.

Output

Output answer modulo $$$10^9+7$$$.

Examples
Input
4 3
Output
4
Input
2 2
Output
2

G. Krosh and count arrays problem 2
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Krosh calls an array of length $$$n$$$ interesting if it consists of numbers from $$$0$$$ to $$$9$$$ and sum of array is divisible by $$$3$$$. Help him to count number of interesting arrays of length $$$n$$$.

Input

You are given number $$$1 \le n \le 300000$$$.

Output

Output amount of interesting arrays of length $$$n$$$.

Example
Input
1
Output
4

H. Krosh and count arrays problem
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Krosh has three integers $$$n$$$, $$$m$$$, $$$k$$$. Help him to calculate number of arrays with following properties:

1. Number of elements in the array is $$$n$$$

2. Every element of the array is integer between $$$1$$$ and $$$m$$$

3. Sum of the array is divisible by $$$k$$$.

Output amount of these arrays modulo $$$10^9+7$$$.

Input

You are given three integers $$$1 \le n \le 40000$$$, $$$1 \le m \le 100$$$, $$$m \lt k \le 10^9$$$.

Output

Output number of arrays which satisfy conditions in the statement modulo $$$10^9+7$$$.

Example
Input
5 3 7
Output
20

I. Krosh and one more problem with xors
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Krosh has the array $$$a$$$ of $$$n$$$ non-negative integers. Help him to calculate the following value:

$$$\sum\limits_{l = 1}^n \sum\limits_{r = l}^n (a(l) $$$ $$$^$$$ $$$a(l + 1) $$$^$$$ $$$... $$$^$$$ $$$a(r)) * max(a(l), a(l + 1), ..., a(r))$$$ (^ - bitwise XOR).

Output the answer modulo $$$10^9+7$$$.

Input

In the first line you are given number $$$1 \le n \le 2 * 10^5$$$ In the next line you are given $$$n$$$ non-negative integers $$$0 \le a_i \le 10^9$$$.

Output

Output the answer modulo $$$10^9+7$$$.

Examples
Input
4
10 8 12 1
Output
941
Input
1
1000000000
Output
49

J. Krosh and order-2
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Krosh has an array of $$$n$$$ integers $$$a_1, a_2, ..., a_n$$$ and some number $$$m$$$. He determines beauty $$$F$$$ of the sequence $$$a_1, a_2, ..., a_n$$$ in the following way: $$$F(A) = a_1 $$$ $$$mod$$$ $$$m$$$ $$$+ a_2 ^ 2$$$ $$$mod$$$ $$$m$$$ $$$+ a_3 ^ 3$$$ $$$mod$$$ $$$m$$$ + ... + $$$a_n ^ n$$$ $$$mod$$$ $$$m$$$(number above is the power) where $$$x$$$ $$$mod$$$ $$$m$$$ is reminder from division of $$$x$$$ to $$$m$$$. Krosh wants to reorder elements in his array in a way that maximizes it's beauty. Help him to determine maximum possible beauty of the array.

Input

In the first line you are given two numbers $$$1 \le n \le 10^5$$$ - amount of elements in the array and $$$2 \le m \le 4$$$ - number for determining the beauty. In the next line you are given $$$n$$$ numbers $$$0 \le a_i \lt m$$$.

Output

Output the answer for the problem.

Examples
Input
4 4
1 0 3 3
Output
7
Input
5 3
1 2 1 0 1
Output
5