Codeforces Round #475 (Div. 2) C. Alternating Sum (geometric series + inverse)

Source: Internet
Author: User
Tags time limit

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

You are given the integers AA and BB. Moreover, given a sequence s0,s1,..., sns0,s1,..., sn. All values in SS is integers one or−1−1. It ' s known that sequence is kk-periodic and KK divides n+1n+1. In the other words, for each k≤i≤nk≤i≤n it's satisfied that si=si−ksi=si−k.

Find out the non-negative remainder of division of N∑i=0sian−ibi∑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 (1≤n≤109,1≤a,b≤109,1≤k≤105) (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 ' + ' and then s

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.