Example

Input

R?????,2?)


Output

29
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

string g(string s,string t){
	int n=s.size(),m=t.size();
	if(s=="invalid") return t;
	if(t=="invalid") return s;
	if(n>m) return s;
	if(n<m) return t;
	for(int i=0;i<n;i++){
		if(s[i]<t[i]) return t;
		if(s[i]>t[i]) return s;
	}
	return s;
}

int n;
string s;
vector<vs> dp;

string f(int l,int r){
	if(dp[l][r]!="") return dp[l][r];
	bool B=1;
	for(int i=l;i<=r;i++) if(!isdigit(s[i])&&s[i]!='?') B=0;
	if(B){
		if(s[l]=='0'&&l<r) return dp[l][r]="invalid";
		string t;
		for(int i=l;i<=r;i++){
			if(s[i]=='?') t+='9';
			else t+=s[i];
		}
		return dp[l][r]=t;
	}
	if(r-l+1<=5) return dp[l][r]="invalid";
	if(isdigit(s[l])||s[l]==','||s[l]=='('||s[l]==')') return dp[l][r]="invalid";
	if(isdigit(s[l+1])||isalpha(s[l+1])||s[l+1]==','||s[l+1]==')') return dp[l][r]="invalid";
	if(isdigit(s[r])||isalpha(s[r])||s[r]==','||s[r]=='(') return dp[l][r]="invalid";
	dp[l][r]="invalid";
	if(s[l]=='L'||s[l]=='?'){
		for(int i=l+2;i<r-2;i++) if(s[i+1]=='?'||s[i+1]==','){
			auto lt=f(l+2,i),rt=f(i+2,r-1);
			if(lt!="invalid"&&rt!="invalid"){
				dp[l][r]=g(dp[l][r],lt);
			}
		}
	}
	if(s[l]=='R'||s[l]=='?'){
		for(int i=l+2;i<r-2;i++) if(s[i+1]=='?'||s[i+1]==','){
			auto lt=f(l+2,i),rt=f(i+2,r-1);
			if(lt!="invalid"&&rt!="invalid"){
				dp[l][r]=g(dp[l][r],rt);
			}
		}
	}
	return dp[l][r];
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>s;
	n=s.size();
	dp=vector<vs>(n,vs(n,""));
	cout<<f(0,n-1)<<endl;
}
