luogu#P5084. 轮换式

轮换式

Problem Description

Xiao Ben found that, for any nn letters, the “rotational form” they form can always be expressed as a linear combination of the nn basic rotational forms of degrees 1n1 \sim n.

Unary basic rotational form: aa.

Binary: a+b,aba+b,ab.

Ternary: a+b+c,ab+ac+bc,abca+b+c,ab+ac+bc,abc.

Quaternary: a+b+c+d,ab+ac+bc+ad+bd+cd,abc+abd+acd+bcd,abcda+b+c+d,ab+ac+bc+ad+bd+cd,abc+abd+acd+bcd,abcd.

And so on.

Similarly, for any nn letters, if you are given several of their basic rotational forms, you can determine the values of these letters.

However, Xiao Ben suddenly showed mercy: he only asks you to compute the sum of the mm-th powers of these letters modulo 107+2910^7+29.

Input Format

The first line contains the number of letters nn and the exponent mm.

The next line contains nn positive integers. The ii-th number is aia_i (0<ai10000)(0<a_i\le 10000), which from left to right are the values of the nn-variable basic rotational forms of degrees 1n1 \sim n.

Output Format

Output one number, the required answer.

2 2
9 18
45

Hint

This problem has 33 subtasks.

Subtask 1 (12 pts): n2n\le 2.

Subtask 2 (28 pts): n=3n=3.

Subtask 3 (60 pts): n=4n=4.

For all data, 0m1000000\le m\le 100000.

Translated by ChatGPT 5