PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000258. Bảng phân ca (Shift Table)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Bảng phân ca (Shift Table)

Shift Table

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Takahashi and Aoki will work part-time for the next NN days. Takahashi's schedule is represented by a string SS of length NN. On day ii, the character SiS_i is # if Takahashi works and . if he is absent.

Aoki constructs his own schedule as follows:

  1. Choose a positive divisor MM of NN with M≠NM\ne N.
  2. Independently decide Aoki's attendance on the first MM days.
  3. For i=1,2,…,N−Mi=1,2,\ldots,N-M in increasing order, set the attendance on day M+iM+i to be the same as on day ii.

Consequently, Aoki's schedule is periodic with period MM. Different choices of MM can produce the same final schedule. Count each distinct schedule only once.

Determine the number of distinct schedules Aoki can create such that on every day from 11 to NN, at least one of the two people works. Print the number modulo 998244353998244353.

Input

  • The first line contains an integer NN, the number of days.
  • The second line contains a string SS of exactly NN characters from {#, .}, describing Takahashi's attendance on days 11 through NN, in order.

Output

Print one integer: the number of distinct valid schedules for Aoki, modulo 998244353998244353.

Subtasks

  • Subtask 1 (20 points): 2≤N≤122\le N\le12; ∣S∣=N|S|=N; every character of SS is # or ..
  • Subtask 2 (30 points): 2≤N≤20002\le N\le2000; ∣S∣=N|S|=N; every character of SS is # or ..
  • Subtask 3 (50 points): 2≤N≤1052\le N\le10^5; ∣S∣=N|S|=N; every character of SS is # or ..

Examples

Example 1

Input

6
##.#.#

Output

3

Explanation

Takahashi works on days 1,2,4,61,2,4,6 and is absent on days 3,53,5, so Aoki must work on days 33 and 55. The permitted divisors of 66 are 1,2,31,2,3. Period 11 permits ######. Period 22 also permits #.#.#.. Period 33 also permits .##.##. After removing duplicates, there are exactly three schedules: ######, #.#.#., and .##.##.

Example 2

Input

7
...####

Output

1

Explanation

Since 77 is prime, the only permitted divisor is M=1M=1. Aoki's attendance must be identical on all days. Because Takahashi is absent on the first three days, Aoki must work on every day, giving the sole schedule #######.

Example 3

Input

12
####.####.##

Output

19

Explanation

Takahashi is absent on days 55 and 1010, requiring Aoki to work on both. The permitted periods are 1,2,3,4,61,2,3,4,6. Count schedules with each period, then subtract schedules already counted using a smaller divisor. The counts of newly introduced schedules for M=1,2,3,4,6M=1,2,3,4,6 are respectively 1,0,1,3,141, 0, 1, 3, 14. Their sum is 1919.