Example

Input

R?????,2?)


Output

29
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <cctype>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

#define fprintf(...) void(0)

std::string memo[51][51];

std::string better(const std::string &s, const std::string &t) {
  fprintf(stderr, "%s <=> %s\n", s.c_str(), t.c_str());
  if (s == "invalid") return t;
  if (t == "invalid") return s;
  if (s.length() < t.length()) return t;
  if (s.length() > t.length()) return s;
  return std::max(s, t);
}

bool can_be(char ch, char crit) {
  return (ch == crit || ch == '?');
}

std::string best(const std::string &s, size_t first, size_t last) {
  fprintf(stderr, "s[%zu, %zu)\n", first, last);
  if (first == last) return "";

  std::string &res=memo[first][last];
  if (!res.empty()) return res;

  char cl=s[first], cr=s[last-1];
  for (char ch: {cl, cr})
    if (ch == ',' || ch == '(')
      return (res = "invalid");

  if (cl == ')' || cr == 'L' || cr == 'R')
    return (res = "invalid");

  res = "invalid";
  if (can_be(cl, 'L') && can_be(cr, ')')) {
    if (last-first > 4 && can_be(s[first+1], '(')) {
      // "L(" <exprL> "," <exprR> ")"
      // if <exprR> is valid then res = better(res, <exprL>);
      for (size_t i=first+3; i+2<last; ++i) {
        if (!can_be(s[i], ',')) continue;
        if (best(s, i+1, last-1) != "invalid")
          res = better(res, best(s, first+2, i));
      }
    }
  }
  if (can_be(cl, 'R') && can_be(cr, ')')) {
    if (last-first > 4 && can_be(s[first+1], '(')) {
      // "R(" <exprL> "," <exprR> ")"
      // if <exprL> is valid then res = better(res, <exprR>);
      for (size_t i=first+3; i+2<last; ++i) {
        if (!can_be(s[i], ',')) continue;
        if (best(s, first+2, i) != "invalid")
          res = better(res, best(s, i+1, last-1));
      }
    }
  }
  if (isdigit(cl) || cl == '?') {
    // if s[first] == '0' and last-first > 1 then "invalid"
    // if non-digit (excluding '?') in s[first..last-1] then "invalid"
    // otherwise fill with '9'
    std::string cur(s.begin()+first, s.begin()+last);
    if (cur[0] == '0' && cur.length() > 1) {
      cur = "invalid";
    } else {
      for (size_t i=0; i<cur.length(); ++i) {
        if (cur[i] == '?') {
          cur[i] = '9';
        } else if (!isdigit(cur[i])) {
          cur = "invalid";
          break;
        }
      }
    }
    fprintf(stderr, "cur: %s\n", cur.c_str());
    res = better(res, cur);
  }
  fprintf(stderr, "... %s\n", res.c_str());
  return res;
}

int main() {
  char buf[64];
  scanf("%s", buf);
  std::string s=buf;

  printf("%s\n", best(s, 0, s.length()).c_str());
}

