CF963A.Alternating Sum

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given two integers aa and bb . Moreover, you are given a sequence s0,s1,,sns_0, s_1, \dots, s_{n} . 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 \leq i \leq n it's satisfied that si=siks_{i} = s_{i - k} .

Find out the non-negative remainder of division of i=0nsianibi\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i} by 109+910^{9} + 9 .

Note that the modulo is unusual!

输入格式

The first line contains four integers n,a,bn, a, b and kk (1n109,1a,b109,1k105)(1 \leq n \leq 10^{9}, 1 \leq a, b \leq 10^{9}, 1 \leq k \leq 10^{5}) .

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

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

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

输出格式

Output a single integer — value of given expression modulo 109+910^{9} + 9 .

输入输出样例

  • 输入#1

    2 2 3 3
    +-+
    

    输出#1

    7
    
  • 输入#2

    4 1 5 1
    -
    

    输出#2

    999999228
    

说明/提示

In the first example:

(i=0nsianibi)(\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i}) = 22302131+20322^{2} 3^{0} - 2^{1} 3^{1} + 2^{0} 3^{2} = 7

In the second example:

(i=0nsianibi)=14501351125211531054=781999999228(mod109+9)(\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i}) = -1^{4} 5^{0} - 1^{3} 5^{1} - 1^{2} 5^{2} - 1^{1} 5^{3} - 1^{0} 5^{4} = -781 \equiv 999999228 \pmod{10^{9} + 9} .

首页