Example

Input

R?????,2?)


Output

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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

string dp[55][55];

string tonum(string s) {
  if(s[0] == '0') return (s.size() == 1 ? "0" : "");
  string res = "";
  rep(i, s.size()) {
    if(isdigit(s[i])) res += s[i];
    else if(s[i] == '?') res += '9';
    else return "";
  }
  return res;
}

void ch(string &s, string t) {
  if(s.size() < t.size() || s.size() == t.size() && s < t) s = t;
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  string s;
  cin >> s;

  reps(len, 1, s.size()+1) {
    rep(i, s.size()+1-len) {
      int j = i + len;

      dp[i][j] = tonum(s.substr(i, len));

      if(len < 6) continue;

      if(s[i] != 'L' && s[i] != 'R' && s[i] != '?') continue;
      if(s[i+1] != '(' && s[i+1] != '?') continue;
      if(s[j-1] != ')' && s[j-1] != '?') continue;

      //cout<<"!!!!!!!!!!!!!!!"<<s[i]<<" "<<i<<" "<<j<<endl;

      reps(k, i+3, j-2) { //X(Y!...)/X(...!.)
	if(s[k] != ',' && s[k] != '?') continue;
	//string l = tonum(s.substr(i+2, k));
	//string r = tonum(s.substr(k+1, j-1));
	//if(l == "" || r == "") continue;
	if(dp[i+2][k] == "") continue;
	if(dp[k+1][j-1] == "") continue;

	if(s[i] == 'L' || s[i] == '?') ch(dp[i][j], dp[i+2][k]);
	if(s[i] == 'R' || s[i] == '?') ch(dp[i][j], dp[k+1][j-1]);
      }
    }
    /*
    cout << "-----------" << len << "--------" << endl;
    rep(i, s.size()+1)
      reps(j, i+1, s.size()+1)
      cout << i << " " << j << " "<< dp[i][j] << endl;
    */
  }

  cout << (dp[0][s.size()] == "" ? "invalid" : dp[0][s.size()]) << endl;

  return 0;
}