Example

Input

R?????,2?)


Output

29
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int length;
string line;
string dp[51][51];


string calc_max(string A,string B){

	if(B == "invalid")return A;
	if(A == "invalid")return B;

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

	int index = 0;

	while(A[index] == B[index]){
		index++;
	}

	if(A[index] > B[index])return A;
	else{
		return B;
	}
}

string make_number(int left,int right) {

	if(left < right && line[left] == '0'){
		return "invalid";
	}

	string ret;

    for(int i = left; i <= right; i++) {
        if(line[i] == 'L' || line[i] == 'R' || line[i] == '(' || line[i] == ')' || line[i] == ',') {
            return "invalid";
        }

        if(line[i] == '?'){
        	ret += '9';
        }else{
        	ret += line[i];
        }
    }
    return ret;
}


string recursive(int left,int right){

	if(left > right)return "invalid";

	if(dp[left][right] != "")return dp[left][right];


	string number = make_number(left,right);
	if(number != "invalid"){
		return dp[left][right] = number;
	}

	if((line[left+1] != '?' && line[left+1] != '(') || (line[right] != '?' && line[right] != ')')) {
		return "invalid";
	}


	vector<int> DIV_POS;

	for(int i = left; i <= right; i++){
		if(line[i] == ',')DIV_POS.push_back(i);
	}

	string ans = "invalid",left_str,right_str;

	for(int div_pos = left+3; div_pos <= right-2; div_pos++){

		if(line[div_pos] != '?' && line[div_pos] != ',')continue;
		if(line[left+1] != '?' && line[left+1] != '(')continue;
		if(line[right] != '?' && line[right] != ')')continue;

		left_str = recursive(left+2,div_pos-1); // LorR(  ,  )
		right_str = recursive(div_pos+1,right-1);

		if(left_str == "invalid" || right_str == "invalid")continue;

		if(line[left] == 'L' || line[left] == '?'){
			ans = calc_max(ans,left_str);
		}

		if(line[left] == 'R' || line[left] == '?'){
			ans = calc_max(ans,right_str);
		}
	}
	return dp[left][right] = ans;
}


int main(){

	getline(cin,line);

	length = line.length();

	for(int left = 0; left < length; left++){
		for(int right = left; right < length; right++)dp[left][right] = "";
	}

	printf("%s\n",recursive(0,length-1).c_str());

	return 0;
}

