Example

Input

R?????,2?)


Output

29
#include<bits/stdc++.h>
#define N 50
using namespace std;

string maxNum(string A,string B){

  if(A.size()>B.size()) return A;
  if(A.size()<B.size()) return B;

  for(int i=0;i<A.size();i++){
    if(A[i]>B[i]) return A;
    if(A[i]<B[i]) return B;
  }

  return A;
}

int main(){

  string s;
  cin>>s;

  //  s="L("+s+",0)";
  
  int slen=s.size();
  string dp[N][N];

  for(int i=0;i<slen;i++){

    string num;
    
    for(int j=i;j<slen;j++){
      
      if(('0'<=s[j]&&s[j]<='9')||s[j]=='?'){
	
	if(s[j]!='?') num+=s[j];
	else num+='9';

	if(num.size()>=2&&num[0]=='0') break;
	
	dp[i][j]=num;
	
      }else break;
      
    }
    
  }
  
  for(int w=6;w<=slen;w++){
    
    for(int i=0;i<=slen-w;i++){
      
      if(s[i]!='?'&&(s[i]!='L'&&s[i]!='R')) continue;

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

      if(s[i+w-1]!='?'&&s[i+w-1]!=')') continue;
      
      for(int j=i+3;j<=i+w-3;j++){
	
	if(s[j]!='?'&&s[j]!=',') continue;
	if(dp[i+2][j-1]==""||dp[j+1][i+w-2]=="") continue;
	
	if(s[i]=='?'||s[i]=='L') dp[i][i+w-1]=maxNum(dp[i][i+w-1],dp[i+2][j-1]);
	
	if(s[i]=='?'||s[i]=='R') dp[i][i+w-1]=maxNum(dp[i][i+w-1],dp[j+1][i+w-2]);
	
      }
    
    }
    
  }
  
  if(dp[0][slen-1]!="") cout<<dp[0][slen-1]<<endl;
  else cout<<"invalid"<<endl;
  
  return 0;
}