Example

Input

R?????,2?)


Output

29
#include <bits/stdc++.h>
using namespace std;
string number_max(string S, string T){
  if (S.size() > T.size() || S.size() == T.size() && S > T){
    return S;
  } else {
    return T;
  }
}
int main(){
  string S;
  cin >> S;
  int N = S.size();
  vector<vector<string>> dp(N + 1, vector<string>(N + 1));
  for (int d = 0; d <= N; d++){
    for (int i = 0; i <= N - d; i++){
      int j = i + d;
      bool ok = true;
      string tmp;
      for (int k = i; k < j; k++){
        if ('0' <= S[k] && S[k] <= '9'){
          tmp += S[k];
        } else if (S[k] == '?'){
          tmp += '9';
        } else {
          ok = false;
        }
      }
      if (S[i] == '0' && d > 1){
        ok = false;
      }
      if (ok){
        dp[i][j] = tmp;
      }
      if (d >= 6){
        if (S[i + 1] == '(' || S[i + 1] == '?'){
          if (S[j - 1] == ')' || S[j - 1] == '?'){
            if (S[i] == 'L' || S[i] == '?'){
              for (int k = i + 3; k < j - 2; k++){
                if (S[k] == ',' || S[k] == '?'){
                  if (dp[k + 1][j - 1] != ""){
                    dp[i][j] = number_max(dp[i][j], dp[i + 2][k]);
                  }
                }
              }
            }
            if (S[i] == 'R' || S[i] == '?'){
              for (int k = i + 3; k < j - 2; k++){
                if (S[k] == ',' || S[k] == '?'){
                  if (dp[i + 2][k] != ""){
                    dp[i][j] = number_max(dp[i][j], dp[k + 1][j - 1]);
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  if (dp[0][N] == ""){
    cout << "invalid" << endl;
  } else {
    cout << dp[0][N] << endl;
  }
}
