#icpc2013autumnf. [icpc2013autumn_f]Shipura
[icpc2013autumn_f]Shipura
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
Dr. Suposupo developed a programming language called Shipura. Shipura supports only one binary operator and only one unary function .
is evaluated to (that is, the greatest integer not exceeding ), and is evaluated to (that is, the remainder when is divided by ).
The operator is left-associative. For example, the expression is interpreted as , not as . Note that these parentheses do not appear in actual Shipura expressions.
The syntax of Shipura is given (in BNF; Backus-Naur Form) as follows:
expr ::= term | expr sp ">>" sp term
term ::= number | "S" sp "<" sp expr sp ">"
sp ::= "" | sp " "
number ::= digit | number digit
digit ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"```
The start symbol of this syntax is $\\tt expr$ that represents an expression in Shipura. In addition, $\\tt number$ is an integer between $0$ and $1{,}000{,}000{,}000$ inclusive, written without extra leading zeros.
Write a program to evaluate Shipura expressions.
* * *
### Input
The input is a sequence of datasets. Each dataset is represented by a line which contains a valid expression in Shipura.
A line containing a single ${\\tt \\#}$ indicates the end of the input. You can assume the number of datasets is at most $100$ and the total size of the input file does not exceed $2{,}000{,}000$ bytes.
### Output
For each dataset, output a line containing the evaluated value of the expression.
* * *
### Sample Input
```plain
S< S< 12 >> 2 > >
123 >> 1 >> 1
1000000000 >>129
S<S<S<S<S<2>>>>>
S <S< S<2013 >>> 11 >>> 10 >
#```
### Output for the Sample Input
```plain
81
30
0
294967268
14592400```
* * *
### Source Name
[JAG Practice Contest for ACM-ICPC Asia Regional 2013](http://acm-icpc.aitea.net/index.php?2013%2FPractice%2F%CC%CF%B5%BC%C3%CF%B6%E8%CD%BD%C1%AA)
* * *