#icpc2014springd. [icpc2014spring_d]LR
[icpc2014spring_d]LR
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; }
We modified the problem statement: ,
is also a usable character. We apologize for any inconvenience. (15:42 UTC+9)
Problem Statement
JAG Kingdom will hold a contest called ICPC (Interesting Contest for Producing Calculation).
At the contest, you are given a string composed of ?
s and usable characters. You should replace all ?
s in the string with the usable characters to make the string valid mathematical expression, before submitting it. The usable characters are L
, R
, (
, )
, ,
, 0
, 1
, 2
, 3
, 4
, 5
, 6
, 7
, 8
, and 9
.
For example, suppose that you are given the string "R(??3,??1?78??1?)?", then you can submit "R(123,L(1678,213))" as an example.
The submitted string will be scored as follows.
-
Let and be functions defined by , , where and are non-negative integers.
-
The submitted string will be regarded as a mathematical expression, whose value will be the score. For example, the score of the string "R(123,L(1678,213))" is .
-
If the string cannot be evaluated as a mathematical expression about the functions and , the string will be rejected. For example, "R", "R(3)", "R(3,2", "R(3,2,4)" and "LR(3,2)" are all invalid.
-
And strings that contain numbers with extra leading zeros, will be rejected. For example, "R(04,18)" is invalid, while "R(0,18)" is valid.
The winner of the contest will be the person getting the highest score. Your friend Jagger, who is going to join the contest, wants to be the winner. You are asked by Jagger to make the program finding the possible highest score for the input string.
Input
The input contains one string in a line, whose length is between and , inclusive.
You can assume that each element in the string is one of L
, R
, (
, )
, ,
, 0
, 1
, 2
, 3
, 4
, 5
, 6
, 7
, 8
, 9
, or ?
.
Output
Display the possible highest score in a line for the given string.
If it's impossible to get valid strings for the input string, print "invalid" in a line.
Sample Input 1
R?????,2?)```
### Output for the Sample Input 1
```plain
29```
* * *
### Sample Input 2
```plain
???3??```
### Output for the Sample Input 2
```plain
999399```
* * *
### Sample Input 3
```plain
????,??,???```
### Output for the Sample Input 3
```plain
invalid```
* * *
### Sample Input 4
```plain
?????,??,???```
### Output for the Sample Input 4
```plain
99```
* * *
### Sample Input 5
```plain
L(1111111111111111111111111111111111111111111,2)```
### Output for the Sample Input 5
```plain
1111111111111111111111111111111111111111111```
* * *
### Sample Input 6
```plain
L?1???????????????????????????????????????????????```
### Output for the Sample Input 6
```plain
199999999999999999999999999999999999999999999```
* * *
### Sample Input 7
```plain
L?0???????????????????????????????????????????????```
### Output for the Sample Input 7
```plain
0```
* * *
### Source Name
[Japan Alumni Group Spring Contest 2014](http://acm-icpc.aitea.net/index.php?2013%2FPractice%2F%BD%D5%A5%B3%A5%F3%A5%C6%A5%B9%A5%C8%2F%B0%C6%C6%E2)
* * *