A transformation is applied to a sequence a1,a2,…,an of length n. The transformation has two steps. First, build a new sequence b1,b2,…,bn with the formula below.
bi=(minj=1naj)−ai+∑j=1naj(1≤i≤n)
Then replace the sequence a with the sequence b, so ai takes the value bi for every 1≤i≤n.
For a sequence x of length n, define q(x)=maxi=1nxi−mini=1nxi.
The sequence r is the result of applying the transformation k times to some sequence, and you are given the value q(r) together with k. Write a program that counts the sequences c1,c2,…,cn satisfying both conditions below.
- 1≤ci≤m for every 1≤i≤n.
- q(d)=q(r), where d is the sequence obtained by applying the transformation k times to the sequence c.