CodeCraft-19 and Codeforces Round 537 (Div. 2)
D
Destroy the Colony
Codeforces
2600
原题
← CE →
翻译中…

There is a colony of villains with several holes aligned in a row, where each hole contains exactly one villain.

翻译中…

Each colony arrangement can be expressed as a string of even length, where the $i$-th character of the string represents the type of villain in the $i$-th hole.

翻译中…

Iron Man can destroy a colony only if the colony arrangement is such that all villains of a certain type either live in the first half of the colony or in the second half of the colony.

翻译中…

His assistant Jarvis has a special power. It can swap villains of any two holes, i.e. swap any two characters in the string; he can do this operation any number of times.

翻译中…

Now Iron Man asks Jarvis $q$ questions. In each question, he gives Jarvis two numbers $x$ and $y$. Jarvis has to tell Iron Man the number of distinct colony arrangements he can create from the original one using his powers such that all villains having the same type as those originally living in $x$-th hole or $y$-th hole live in the same half and the Iron Man can destroy that colony arrangement.

翻译中…

Two colony arrangements are considered to be different if there exists a hole such that different types of villains are present in that hole in the arrangements.

翻译中…

Input

翻译中…

The first line contains a string $s$ ($2 \le |s| \le 10^{5}$), representing the initial colony arrangement. String $s$ can have both lowercase and uppercase English letters and its length is even.

翻译中…

The second line contains a single integer $q$ ($1 \le q \le 10^{5}$) — the number of questions.

翻译中…

The $i$-th of the next $q$ lines contains two integers $x_i$ and $y_i$ ($1 \le x_i, y_i \le |s|$, $x_i \ne y_i$) — the two numbers given to the Jarvis for the $i$-th question.

翻译中…

Output

翻译中…

For each question output the number of arrangements possible modulo $10^9+7$.

翻译中…

Note

翻译中…

Consider the first example. For the first question, the possible arrangements are "aabb" and "bbaa", and for the second question, index $1$ contains 'a' and index $2$ contains 'b' and there is no valid arrangement in which all 'a' and 'b' are in the same half.

翻译中…

样例

Input #1
abba
2
1 4
1 2
Output #1
2
0
InputCopy OutputCopy
Input #2
AAaa
2
1 2
1 3
Output #2
2
0
InputCopy OutputCopy
Input #3
abcd
1
1 3
Output #3
8
InputCopy OutputCopy
题目信息
题号
1111D
时间限制
2 s
内存限制
512 MB
标签
组合数学
动态规划
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。