Codeforces Round 397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
G
Math, math everywhere
Codeforces
3200
原题
← F→
翻译中…

If you have gone that far, you'll probably skip unnecessary legends anyway...

翻译中…

You are given a binary string image and an integer image. Find the number of integers $*k*$, $0 ≤ *k* < *N*$, such that for all $*i* = 0$, $1$, ..., $*m* - 1$

翻译中…

image

翻译中…

Print the answer modulo

翻译中…

109 + 7

翻译中…

.

翻译中…

Input

翻译中…

In the first line of input there is a string $*s*$ consisting of $0$'s and $1$'s ($1 ≤ |*s*| ≤ 40$).

翻译中…

In the next line of input there is an integer $*n*$ ($1 ≤ *n* ≤ 5·10^{5}$).

翻译中…

Each of the next $*n*$ lines contains two space-separated integers $*p*_{*i*}$, $α_{*i*}$ ($1 ≤ *p*_{*i*}, α_{*i*} ≤ 10^{9}$, $*p*_{*i*}$ is prime). All $*p*_{*i*}$ are distinct.

翻译中…

Output

翻译中…

A single integer — the answer to the problem.

翻译中…

样例

Input #1
1
2
2 1
3 1
Output #1
2
InputCopy OutputCopy
Input #2
01
2
3 2
5 1
Output #2
15
InputCopy OutputCopy
Input #3
1011
1
3 1000000000
Output #3
411979884
InputCopy OutputCopy
题目信息
标签
暴力
动态规划
数学
折半搜索
数论

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