Vera owns N tops and N pants. The i-th top and i-th pants have colour i, for 1 ≤ i ≤ N, where all N colors are different from each other.
An outfit consists of one top and one pants. Vera likes outfits where the top and pants are not the same colour.
How many different outfits does she like?
Constraints:
1 ≤ N ≤ 2017
N is integer
The input will be in the format:
N
Output one line with the number of different outfits Vera likes.
1
0
2
2
5
20
Vera is learning about the longest common subsequence problem.
A string is a (possibly empty) sequence of lowercase letters. A subsequence of a string S is a string obtained by deleting some letters of S (possibly none or all). For example "vra", "a", "", and "vera" are all subsequences of "vera". The longest common subsequence (LCS) of two strings A, B is a string that is a subsequence of A and B and has the maximum length among all strings that are a subsequence of A and B. There could be multiple LCS for two given strings. For example a LCS of "vera" and "eats" is "ea".
For homework she was given two strings A, B, both of length N and she had to determine the length of the LCS of A and B. She determined the answer to be K but lost B. Given A and K, help her find a possible value of B. It's possible that Vera may have made a mistake and no such B exists, in that case output "WRONGANSWER" (without quotes).
Constraints:
1 ≤ N ≤ 2000
0 ≤ K ≤ 2000
N, K are integers
A consists of N lowercase letters
The input will be in the format:
N K
A
Output one line consisting of the string B of N lowercase letters, or "WRONGANSWER" if no B is valid. If there are multiple correct B output any of them.
4 2
vera
eats
4 5
vera
WRONGANSWER
For the first example, another possible answer is "uber".
The harmonic mean of a sequence of positive integers x1, ..., xN is

Vera thinks that an array of positive integers A = [A1, ..., AN] of length N is K-mean-sorted if M(i) ≥ M(i + 1) for 1 ≤ i ≤ N - K where
A permutation P is an ordered set of integers P1, P2, ..., PN, consisting of N distinct positive integers, each of them doesn't exceed N. We'll call number N the size or the length of permutation.
Permutation P is lexicographically smaller than permutation Q if there is i (1 ≤ i ≤ n), such that Pi < Qi, and for any j (1 ≤ j < i) Pj = Qj.
Given integers N and K, help Vera find the lexicographically smallest permutation P of integers 1 to N such that P is K-mean-sorted but not L-mean-sorted for 1 ≤ L ≤ N - 1, L ≠ K.
If no such permutation exists output 0.
Constraints:
2 ≤ N ≤ 100
1 ≤ K ≤ N - 1
N, K are integers
The input will be in the format:
N K
Output one line with the desired permutation. If such permutation does not exist output one line with 0.
3 2
2 3 1
4 1
0
Vera is very smart and invented a new sorting algorithm. She coded the following python function to count how many steps her algorithm takes.
def steps(array):
if len(array) == 0:
return 0
pivot = array[0]
count = 0
lesser = []
greater = []
for element in array:
count += 1
if element < pivot:
lesser.append(element)
elif element > pivot:
greater.append(element)
return count + steps(lesser) + steps(greater)
A permutation P is an ordered set of integers P1, P2, ..., PN, consisting of N distinct positive integers, each of them doesn't exceed N. We'll call number N the size or the length of permutation.
You are given integers N and K.
Help Vera count the number of permutations P of size N such that steps(P) = K. This number could be large, so output it modulo 109 + 7.
Constraints:
1 ≤ N ≤ 30
1 ≤ K ≤ 900
N, K are integers
The input will be in the format:
N K
Output one integer, the number of possible permutations, modulo 109 + 7.
3 5
2
5 29
0
20 100
262859528
For the first example, the 2 valid permutations are 2, 1, 3 and 2, 3, 1.
Vera has N friends numbered from 0 to N - 1. Being in Software Engineering, all her friends do not have enough spare time to engage in relationships. However, friends have crushes on each other.
Let g(x), where x are non-negative integers, be the number of ones in the binary representation of x.
Let f(i, j) = g((A·B(i·N + j))%M), where A, B, M are integer constants.
It is known that for any 2 friends i < j, if f(i, j) is even then i has a crush on j, otherwise j has a crush on i.
Vera thinks love triangles are very funny. A love triangle is a set of 3 friends i, j, k such that i has a crush on j, j has a crush on k and k has a crush on i.
Given integers N, M, A, B tell Vera how many love triangles exist among her friends. Two love triangles are different if they contain a different set of 3 friends.
Constraints:
3 ≤ N, M ≤ 200, 000
0 < A, B < M
N, M, A, B are integers
M is prime
The input will be in the format:
N M A B
Output one line with the number of love triangles.
3 5 3 4
1
3 3 1 2
0
1337 10007 1337 1337
99141170
Let
denote that friend a has a crush on friend b.
For the first example, f(0, 1) = 1, f(0, 2) = 2, and f(1, 2) = 1. So
,
, and
, so there is one love triangle.
For the second example,
,
, and
, so there are zero love triangles.