#P5337. [TJOI2019] 甲苯先生的字符串

    ID: 6080 远端评测题 1000ms 125MiB 尝试: 19 已通过: 4 难度: 7 上传者: 标签>动态规划 DP2019各省省选矩阵加速天津

[TJOI2019] 甲苯先生的字符串

Background

TJOI2019 D1T1.

Source file name: str.*.

Time limit: 1 s. Memory limit: 128 M.

Problem Description

One day, Xiao Toluene received a divine message. He wants to write it down, but cannot reveal the secret, so he decides to record it in a special way.

The divine message is a string, denoted as s1s_1. s1s_1 contains only 2626 lowercase letters. Now Xiao Toluene wants to write down the message as another string, denoted as s2s_2. s2s_2 also contains only 2626 lowercase letters. The requirement is: any two adjacent letters in s1s_1 must not appear adjacent in s2s_2.

Given the length of s2s_2, Xiao Toluene wants to know how many different strings s2s_2 he can write. Output the number of valid strings modulo 109+710^9+7.

Input Format

The first line contains a single positive integer nn, representing the length of string s2s_2.

The second line contains a string, representing string s1s_1.

Output Format

Output one integer, representing the total number of strings that Xiao Toluene can write. Take the result modulo 109+710^9+7.

2
ab

675

Hint

For 30%30\% of the testdata, n100000n \le 100000.

For 100%100\% of the testdata, 1n10151 \le n \le 10^{15}, s1105|s_1| \le 10^5.

Note: The adjacency restriction requires the same order. For example, in the sample, s2s_2 must not contain ab\text{ab}, and only ab\text{ab} is forbidden, but ba\text{ba} is allowed.

Translated by ChatGPT 5