Example

Input

R?????,2?)


Output

29
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};

string s;
vector<vector<string>> dp(100,vector<string> (100, "."));

bool f(string l, string r){
    if(l.length() < r.length()) return true;
    else if(l.length() > r.length()) return false;
    else{
        for (int i = 0; i < l.length(); i++) {
            if(l[i] < r[i]) return true;
            else if(l[i] > r[i]) return false;
        }
    }
    return true;
}


string dfs(int l, int r){
    if(dp[l][r] != ".") return dp[l][r];
    if(s[l] == '0'){
        if(r - l > 1) return dp[l][r] = "-1";
        else return dp[l][r] = "0";
    }
    string ret = "-1";
    bool t = true;
    for (int i = l; i < r; i++) {
        if(s[i] == 'R' || s[i] == 'L' || s[i] == '(' || s[i] == ')' || s[i] == ',') t = false;
    }
    if(t){
        ret = "";
        for (int i = l; i < r; i++) {
            if(s[i] == '?') ret += '9';
            else ret += s[i];
        }
        if(ret == "") ret = "-1";
        return dp[l][r] = ret;
    }
    if(r - l >= 6){
        t = false;
        if(s[l] == 'L' || s[l] == 'R' || s[l] == '?'){
            if(s[l+1] == '(' || s[l+1] == '?'){
                if(s[r-1] == ')' || s[r-1] == '?') t = true;
            }
        }
    }
    if(!t) return ret;
    for (int i = l+3; i < r; i++) {
        if(s[i] == ',' || s[i] == '?'){
            auto p = dfs(l+2,i), q = dfs(i+1,r-1);
            if(p == "-1" || q == "-1") continue;
            string tmp = "-1";
            if(s[l] == 'L') tmp = p;
            else if(s[l] == 'R') tmp = q;
            else if(s[l] == '?') tmp = max(p, q, f);
            if(ret == "-1") ret = tmp;
            else ret = max(ret, tmp, f);
        }
    }
    return dp[l][r] = ret;
}


int main(){
    cin >> s;
    auto r = dfs(0, s.length());
    if(r == "-1") puts("invalid");
    else cout << r << endl;
    return 0;
}

