Example

Input

R?????,2?)


Output

29
#include <bits/stdc++.h>

using namespace std;

using int64 = long long;

string s;
string dp[50][50];

bool cmp(const string &x, const string &y) {
  return (x.size() < y.size() || (x.size() == y.size() && x < y));
}

string rec(int x, int y) {
  if(dp[x][y] != "~") return dp[x][y];
  string ret = "";

  bool valid = true;
  for(int i = x; i <= y; i++) {
    if(isdigit(s[i]) || s[i] == '?') {}
    else valid = false;
  }
  if(s[x] == '0' && x < y) valid = false;
  if(valid) {
    for(int i = x; i <= y; i++) {
      if(s[i] == '?') ret += "9";
      else ret += s[i];
    }
  }
  if(y - x + 1 >= 6) {
    if(s[x] == 'L' || s[x] == '?') {
      if(s[y] == ')' || s[y] == '?') {
        if(s[x + 1] == '(' || s[x + 1] == '?') {
          for(int m = x + 3; m < y - 1; m++) {
            if(s[m] == ',' || s[m] == '?') {
              string latte = rec(x + 2, m - 1);
              string malta = rec(m + 1, y - 1);
              if(latte.empty() || malta.empty()) continue;
              ret = max(ret, latte, cmp);
            }
          }
        }
      }
    }
    if(s[x] == 'R' || s[x] == '?') {
      if(s[y] == ')' || s[y] == '?') {
        if(s[x + 1] == '(' || s[x + 1] == '?') {
          for(int m = x + 3; m < y - 1; m++) {
            if(s[m] == ',' || s[m] == '?') {
              string latte = rec(x + 2, m - 1);
              string malta = rec(m + 1, y - 1);
              if(latte.empty() || malta.empty()) continue;
              ret = max(ret, malta, cmp);
            }
          }
        }
      }
    }
  }
  return dp[x][y] = ret;
}

int main() {
  cin >> s;
  fill_n(*dp, 50 * 50, "~");
  auto ret = rec(0, s.size() - 1);
  if(ret.empty()) cout << "invalid\n";
  else cout << ret << endl;
}

