Codeforces Round #475 (Div. 2) C. Alternating Sum

C. Alternating Sum
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given two integers aa and bb. Moreover, you are given a sequence s0,s1,,sns0,s1,…,sn. All values in ss are integers 11 or 1−1. It's known that sequence is kk-periodic and kk divides n+1n+1. In other words, for each kink≤i≤n it's satisfied that si=siksi=si−k.

Find out the non-negative remainder of division of ni=0sianibi∑i=0nsian−ibi by 109+9109+9.

Note that the modulo is unusual!

Input

The first line contains four integers n,a,bn,a,b and kk (1n109,1a,b109,1k105)(1≤n≤109,1≤a,b≤109,1≤k≤105).

The second line contains a sequence of length kk consisting of characters '+' and '-'.

If the ii-th character (0-indexed) is '+', then si=1si=1, otherwise si=1si=−1.

Note that only the first kk members of the sequence are given, the rest can be obtained using the periodicity property.

Output

Output a single integer — value of given expression modulo 109+9109+9.

Examples
input
Copy
2 2 3 3
+-+
output
Copy
7
input
Copy
4 1 5 1
-
output
Copy
999999228
Note

In the first example:

(ni=0sianibi)(∑i=0nsian−ibi) = 22302131+20322230−2131+2032 = 7

In the second example:

(ni=0sianibi)=14501351125211531054=781999999228(mod109+9)(∑i=0nsian−ibi)=−1450−1351−1252−1153−1054=−781≡999999228(mod109+9)


题意:ni=0sianibi



(∑i=0nsian−ibi)=−1450−1351−1252−1153−1054=−781≡999999228(mod109+9)


猜你喜欢

转载自blog.csdn.net/baymax520/article/details/80055588