AT_past18_f インタプリタをつくろう
Description
You are given an expression $ S $ consisting of one-letter variables, one-digit integers, and $ + $ and $ - $ signs.
For example, `1+2+3`, `3-a+2+c+0`, and `1` can be given,
but `12+3`, `4-ab`, and `a/2+5` cannot, because $ 12 $ is not a one-digit integer, $ ab $ is not a one-letter variable (nor is it interpreted as $ a\times b $ ), and it contains $ / $ , respectively.
You are given the values of the variables as $ N $ pairs, $ (c _ 1,v _ 1),(c _ 2,v _ 2),\ldots $ , and $ (c _ N,v _ N) $ . The $ i $ -th pair $ (c _ i,v _ i) $ means that the variable $ c _ i $ should evaluate to the value $ v _ i $ .
Evaluate the expression $ S $ .
Input Format
The input is given from Standard Input in the following format:
> $ S $ $ N $ $ c _ 1 $ $ v _ 1 $ $ c _ 2 $ $ v _ 2 $ $ \vdots $ $ c _ N $ $ v _ N $
Output Format
Print the answer.
Explanation/Hint
### Sample Explanation 1
When $ a=18 $ , we have $ 2+a-7=2+18-7=13 $ . Thus, $ 13 $ should be printed.
### Sample Explanation 2
$ S $ may not contain a variable. Also, a value may be given for a variable that is not contained in $ S $ .
### Constraints
- $ S $ is a string of length between $ 1 $ and $ 99 $ , inclusive.
- $ S $ has an odd length.
- Each character at an odd-numbered position of $ S $ is a lowercase English letter or a digit.
- Each character at an even-numbered position of $ S $ is `+` or `-`.
- $ 1\leq N\leq 26 $
- $ c_i $ is a lowercase English letter $ (1\leq i\leq N) $ .
- $ i\neq j\implies c _ i\neq c _ j\ (1\leq i,j\leq N) $
- If a lowercase English letter $ c $ occurs in $ S $ , then there exists $ i\ (1\leq i\leq N) $ such that $ c=c _ i $ .
- $ -100\leq v _ i\leq100\ (1\leq i\leq N) $
- $ N $ , $ v _ 1,v _ 2,\ldots $ , and $ v _ N $ are all integers.