Example

Input

R?????,2?)


Output

29
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007LL;
const int INF = LLONG_MAX;

string mymax(string &a, string &b){
    if(a.size() > b.size()){
        return a;
    }else if(a.size() < b.size()){
        return b;
    }else{
        return (a < b ? b : a);
    }
}

string f(int l, int r, string &s, vector<vector<string> > &dp){
    //cout << l << " " << r << endl;
    string res = "";
    if(dp[l][r] != "monkukui") return dp[l][r];
    if(l >= r){
        res = "invalid";
        dp[l][r] = res;
        return "invalid";
    }

    if(r - l == 1){
        if('0' <= s[l] && s[l] <= '9'){
            res += s[l];
            dp[l][r] = res;
            return res;
        }else if(s[l] == '?'){
            res = "9";
            dp[l][r] = res;
            return res;
        }else{
            res = "invalid";
            dp[l][r] = res;
            return res;
        }
    }

    if(s[l] == '0'){
        res = "invalid";
        dp[l][r] = res;
        return "invalid";
    }

    //全部数字にできるなら
    bool ok = true;
    for(int i = l; i < r; i++){
        if('0' <= s[i] && s[i] <= '9') res += s[i];
        else if(s[i] == '?') res += '9';
        else ok = false;
    }


    if(ok){
        dp[l][r] = res;
        return res;
    }else{

        res = "";
        for(int i = l; i < r; i++){   

            if(s[i] != '?' && s[i] != ',') continue;
            if(s[l] != '?' && s[l] != 'L' && s[l] != 'R') continue;
            if(s[l + 1] != '?' && s[l + 1] != '(') continue;
            if(s[r - 1] != '?' && s[r - 1] != ')') continue;
            
            string L = f(l + 2, i, s, dp);
            string R = f(i + 1, r - 1, s, dp);
            if(L == "invalid" || R == "invalid") continue;
            //cout << i << " " << L << " " << R << endl;
            
            if(s[l] == 'L' || s[l] == '?'){
                res = mymax(res, L);
            }
            if(s[l] == 'R' || s[l] == '?'){
                res = mymax(res, R);
            }
        }
    }

    if(res == ""){
        res = "invalid";
        dp[l][r] = res;
        return "invalid";
    }
        
    dp[l][r] = res;
    return res;
}

signed main(){
    
    string s; cin >> s;
    int n = (int)s.size();
    vector<vector<string> > dp(n + 1, vector<string> (n + 1, "monkukui"));
    string ans = f(0, n, s, dp);
    cout << ans << endl;
    return 0;
}
