#icpc2016autumnj. [icpc2016autumn_j]Compressed Formula
[icpc2016autumn_j]Compressed Formula
MathJax.Hub.Config({ tex2jax: { inlineMath: [[""], ["\\(","\\)"]], processEscapes: true }}); blockquote { font-family: Menlo, Monaco, "Courier New", monospace; color: #333333; display: block; padding: 8.5px; margin: 0 0 9px; font-size: 12px; line-height: 18px; background-color: #f5f5f5; border: 1px solid #ccc; border: 1px solid rgba(0, 0, 0, 0.15); -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; white-space: pre; white-space: pre-wrap; word-break: break-all; word-wrap: break-word; }
Problem Statement
You are given a simple, but long formula in a compressed format. A compressed formula is a sequence of pairs of an integer and a string , which consists only of digits ('0'-'9'), '+', '-', and '*'. To restore the original formula from a compressed formula, first we generate strings obtained by repeating times for all , then we concatenate them in order of the sequence.
You can assume that a restored original formula is well-formed. More precisely, a restored formula satisfies the following BNF:
<expression> := <term> | <expression> '+' <term> | <expression> '-' <term>
<term> := <number> | <term> * <number>
<number> := <digit> | <non-zero-digit> <number>
<digit> := '0' | <non-zero-digit>
<non-zero-digit> := '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' ```
Here, '+' means addition, '\-' means subtraction, and '\*' means multiplication of integers.
Your task is to write a program computing the answer of a given formula modulo $1{,}000{,}000{,}007$, where $x$ modulo $m$ is a non-negative integer $r$ such that there exists an integer $k$ satisfying $x = km + r$ and $0 \\le r \\lt m$; it is guaranteed that such $r$ is uniquely determined for integers $x$ and $m$.
* * *
### Input
The input consists of a single test case.
> $N$
> $r\_1$ $s\_1$
> ...
> $r\_N$ $s\_N$
The first line contains a single integer $N$ ($1 \\le N \\le 10^4$), which is the length of a sequence of a compressed formula. The following $N$ lines represents pieces of a compressed formula. The $i$-th line consists of an integer $r\_i$ ($1 \\le r\_i \\le 10^9$) and a string $s\_i$ ($1 \\le |s\_i| \\le 10$), where $t\_i$ is the number of repetition of $s\_i$, and $s\_i$ is a piece of an original formula. You can assume that an original formula, restored from a given compressed formula by concatenation of repetition of pieces, satisfies the BNF in the problem statement.
### Output
Print the answer of a given compressed formula modulo $1{,}000{,}000{,}007$.
* * *
* * *
### Sample Input 1
```plain
1
5 1```
### Output for the Sample Input 1
```plain
11111```
* * *
### Sample Input 2
```plain
2
19 2*
1 2```
### Output for the Sample Input 2
```plain
1048576```
* * *
### Sample Input 3
```plain
2
1 1-10
10 01*2+1```
### Output for the Sample Input 3
```plain
999999825```
* * *
### Sample Input 4
```plain
4
3 12+45-12
4 12-3*2*1
5 12345678
3 11*23*45```
### Output for the Sample Input 4
```plain
20008570```
* * *