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$$$.
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 answer modulo $$$10^9+7$$$.
5 2 3 4 5 1
120
2 100000000 100000000
0
10 1 100000000 1 100000000 100000000 1 1 100000000 100000000 1
249999989
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$$$.
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 the beauty of an array $$$a$$$.
2 1 2
3
1 10
10
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.
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 correct order if it exists or $$$-1$$$ if no. Output elements not indices.
5 1 2 3 4 1
1 3 1 4 2
4 1 1 1 1
-1
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$$$.
You are given an integer $$$1 \le k \le 5000$$$.
Output the answer modulo $$$10^9+7$$$.
1
2
2
6
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.
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 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$$$.
5 4 2 1 2 3 4 4
13
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.
You are given two natural numbers $$$1 \le m \le 2000$$$, $$$1 \le n \le m$$$.
Output answer modulo $$$10^9+7$$$.
4 3
4
2 2
2
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$$$.
You are given number $$$1 \le n \le 300000$$$.
Output amount of interesting arrays of length $$$n$$$.
1
4
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$$$.
You are given three integers $$$1 \le n \le 40000$$$, $$$1 \le m \le 100$$$, $$$m \lt k \le 10^9$$$.
Output number of arrays which satisfy conditions in the statement modulo $$$10^9+7$$$.
5 3 7
20
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$$$.
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 the answer modulo $$$10^9+7$$$.
4 10 8 12 1
941
1 1000000000
49
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.
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 the answer for the problem.
4 4 1 0 3 3
7
5 3 1 2 1 0 1
5