Placeholder

#8186
서브태스크

Interstellar Intervals 1초 1024MB

문제

It's the year 3000, and Bessie became the first cow in space! During her journey between the stars, she found a number line with N (2≤N≤5⋅10^5) points, numbered from 1 to N. All points are initially colored white. She can perform the following operation any number of times.

Choose a position i within the number line and a positive integer x. Then, color all the points in the interval [i,i+x−1] red and all points in [i+x,i+2x−1] blue. All chosen intervals must be disjoint (i.e. no points in [i,i+2x−1] can be already colored red or blue). The entire interval must also fall within the number line (i.e. 1≤i≤i+2x−1≤N).

Farmer John gives Bessie a string s of length N consisting of characters R, B, and X. The string represents Farmer John's color preferences for each point: s_i=R means the i'th point must be colored red, s_i=B means the i'th point must be colored blue, and s_i=X means there is no constraint on the color for the i'th point.

Help Bessie count the number of distinct ways for the number line to be colored while satisfying Farmer John's preferences. Two colorings are different if there is at least one corresponding point with a different color. Because the answer may be large, output it modulo 10^9+7.


입력

The first line contains an integer NN.

The following line contains string ss.


출력

Output the number of distinct ways for the number line to be colored while satisfying Farmer John's preferences modulo 109+710^9+7.


부분문제

번호 점수 조건
#110점

N500N \le 500

#220점

N104N \le 10^4

#330점

All but at most 100100 characters in ss are XX.

#440점

No additional constraints


예제1

입력
6
RXXXXB
출력
5

Bessie can choose i=1,x=1i=1,x=1 (i.e. color point 11 red and point 22 blue) and i=3,x=2i=3,x=2 (i.e. color points 3,43,4 red and points 5,65,6 blue) to produce the coloring RBRRBBRBRRBB.

The other colorings are RRBBRBRRBBRB, RBWWRBRBWWRB, RRRBBBRRRBBB, and RBRBRBRBRBRB.


예제2

입력
6
XXRBXX
출력
6

The six colorings are WWRBWWWWRBWW, WWRBRBWWRBRB, WRRBBWWRRBBW, RBRBWWRBRBWW, RBRBRBRBRBRB, and RRRBBBRRRBBB.


예제3

입력
12
XBXXXXRXRBXX
출력
18

출처

USACO 2024 December Gold


역링크 공식 문제집만

로그인해야 코드를 작성할 수 있어요.