Example

Input

R?????,2?)


Output

29
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

string max_string(string s, string t){
    if(s.size() > t.size()) return s;
    else if(s.size() < t.size()) return t;
    else{
        rep(i, s.size()){
            if(s[i] > t[i]) return s;
            else if(s[i] < t[i]) return t;
        }
        return s;
    }
}

string s;
string dp[55][55];

string dfs(int l, int r){
    if(dp[l][r] != ".") return dp[l][r];
    if(l == r) return dp[l][r] = "#";

    if(count_if(s.begin() + l, s.begin() + r, [](char c){return c != '?' && !isdigit(c);}) == 0){
        if(r - l != 1 && s[l] == '0') return dp[l][r] = "#";

        string ret = s.substr(l, r - l);
        For(i, l, r) ret[i - l] = (s[i] == '?' ? '9' : s[i]);
        return ret;
    }
    else{
        if(r - l < 6) return dp[l][r] = "#";
        if(s[l] != '?' && s[l] != 'L' && s[l] != 'R') return dp[l][r] = "#";
        if(s[l+1] != '?' && s[l+1] != '(') return dp[l][r] = "#";
        if(s[r-1] != '?' && s[r-1] != ')') return dp[l][r] = "#";

        dp[l][r] = "#";
        For(i, l+3, r-2)if(s[i] == '?' || s[i] == ','){
            string lhs = dfs(l+2, i);
            if(lhs == "#") continue;

            string rhs = dfs(i+1, r-1);
            if(rhs == "#") continue;

            if(s[l] == 'L'){
                if(dp[l][r] == "#") dp[l][r] = lhs;
                else dp[l][r] = max_string(dp[l][r], lhs);
            }
            else if(s[l] == 'R'){
                if(dp[l][r] == "#") dp[l][r] = rhs;
                else dp[l][r] = max_string(dp[l][r], rhs);
            }
            else{
                string tmp = max_string(lhs, rhs);
                if(dp[l][r] == "#") dp[l][r] = tmp;
                else dp[l][r] = max_string(dp[l][r], tmp);
            }
        }
        return dp[l][r];
    }
}

int main(){
    cin >> s;
    rep(i, 55)rep(j, 55) dp[i][j] = '.';
    string ans = dfs(0, s.size());
    cout << (ans == "#" ? "invalid" : ans) << "\n";
}
