Problem:
PLAY in BASIC
One sunny day, Dick T. Mustang found an ancient personal computer in the closet.
He brought it back to his room and turned it on with a sense of nostalgia, seeing a message coming on the screen:
READY?
Yes. BASIC.
BASIC is a programming language designed for beginners, and was widely used from 1980's to 1990's.
There have been quite a few BASIC dialects.
Some of them provide the PLAY statement, which plays music when called with a string of a musical score written in Music Macro Language (MML).
Dick found this statement is available on his computer and accepts the following commands in MML:
Notes: Cn, C+n, C-n, Dn, D+n, D-n, En,...,... (n = 1,2,4,8,16,32,64,128 + dots)
Each note command consists of a musical note followed by a duration specifier.
Each musical note is one of the seven basic notes: 'C', 'D', 'E', 'F', 'G', 'A', and 'B'.  It can be followed by either '+' (indicating a sharp) or '-' (a flat).  The notes 'C' through 'B' form an octave as depicted in the figure below.  The octave for each command is determined by the current octave, which is set by the octave commands as described later.  It is not possible to play the note 'C-' of the lowest octave (1) nor the note 'B+' of the highest octave (8).
Each duration specifier is basically one of the following numbers: '1', '2', '4', '8', '16', '32', '64', and '128', where '1' denotes a whole note, '2' a half note, '4' a quarter note, '8' an eighth note, and so on.  This specifier is
optional
; when omitted, the duration will be the default one set by the L command (which is described below).  In addition, duration specifiers can contain
dots
next to the numbers.  A dot adds the half duration of the basic note.  For example, '4.' denotes the duration of '4' (a quarter) plus '8' (an eighth, i.e. half of a quarter), or as 1.5 times long as '4'.  It is possible that a single note has more than one dot, where each extra dot extends the duration by half of the previous one.  For example, '4..' denotes the duration of '4' plus '8' plus '16', '4...' denotes the duration of '4' plus '8' plus '16' plus '32', and so on.  The duration extended by dots cannot be shorter than that of '128' due to limitation of Dick's computer; therefore neither '128.' nor '32...' will be accepted.  The dots specified without the numbers extend the default duration.  For example, 'C.' is equivalent to 'C4.' when the default duration is '4'.  Note that 'C4C8' and 'C4.' are
unequivalent
; the former contains two distinct notes, while the latter just one note.
Rest: Rn (n = 1,2,4,8,16,32,64,128 + dots)
The R command rests  for the specified duration.  The duration should be specified in the same way as the note commands, and it can be omitted, too.  Note that 'R4R8' and 'R4.' are
equivalent
, unlike 'C4C8' and 'C4.', since the both rest for the same duration of '4' plus '8'.
Octave: On (n = 1-8), <, >
The O command sets the current octave to the specified number.  '>'  raises one octave up, and '<'  drops one d
...(truncated)

Submitted solutions:

code_snippet: //by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
const int STRLEN=100111;
const int LENCNT=8;
const int NOTEN=12;
int Slen;
char S[STRLEN];
struct note
{
	int id;//-1 for Rest  id=(oct-1)*12+note_id
	int len;
	int vol;
	note(int Id=0,int Len=0,int Vol=0){id=Id;len=Len;vol=Vol;}
}a[STRLEN];
int n;

string nt_tab[NOTEN+2]={"B+","C","C+","D","D+","E","F","F+","G","G+","A","A+","B","C-"};
string Sinf="******************************************************************************************";
int get_note_cost(int oct_diff,int note_id)//oct_diff=cur_oct-note_oct
{
	if(note_id==-1)return 0;
	if(oct_diff==0)return nt_tab[note_id+1].size();
	if(oct_diff==-1&&note_id==0)return nt_tab[0].size();
	if(oct_diff==1&&note_id==NOTEN-1)return nt_tab[NOTEN+1].size();
	return 2333;
}
string get_note_str(int oct_diff,int note_id)
{
	if(note_id==-1)return "";
	if(oct_diff==0)return nt_tab[note_id+1];
	if(oct_diff==-1&&note_id==0)return nt_tab[0];
	if(oct_diff==1&&note_id==NOTEN-1)return nt_tab[NOTEN+1];
	assert(false);
}
string dg_tab[1000];
string len_tab[8][256];
const int T2MX=512;
const int T2MXL=512;
string rest_tab[8][8][T2MX];
pair<string,string> rest_tab2[8][8][T2MX+T2MX];
string get_tab(int i,int j,int k)
{
	string s="";
	if(a[i].id==-1)
	{
		int len=a[i].len;
		string curs="";
		while(len>=T2MXL+T2MXL-1)
		{
			len-=128;
			curs.PB('R');
//			if(j!=LENCNT-1&&k!=LENCNT-1)s2.PB('1');
		}
		s=rest_tab2[j][k][len].FF+curs+rest_tab2[j][k][len].SS;
		while(len>128)
		{
			len-=128;
			curs.PB('R');
			if(rest_tab2[j][k][len].FF.size()+curs.size()+rest_tab2[j][k][len].SS.size()<s.size())
			{
				s=rest_tab2[j][k][len].FF+curs+rest_tab2[j][k][len].SS;
			}
		}
		
		len=a[i].len;
		curs="";
		while(len>=T2MXL)
		{
			len-=128;
			curs.PB('R');
			curs.PB('1');
		}
		curs+=rest_tab[j][k][len];
		if(curs.size()<s.size())s=curs;
	}
	else
	{
		s=len_tab[j][a[i].len]+(j==k?"":"L"+dg_tab[1<<(7-k)]);
	}
	return s;
}
int get_tab_cost(int i,int j,int k)
{
	int ret=0;
	if(a[i].id==-1)
	{
		int len=a[i].len;
		int curs=0;
		while(len>=T2MXL+T2MXL-1)
		{
			len-=128;
			curs++;
		}
		ret=rest_tab2[j][k][len].FF.size()+curs+rest_tab2[j][k][len].SS.size();
		while(len>128)
		{
			len-=128;
			curs++;
			ret=min(ret,int(rest_tab2[j][k][len].FF.size()+curs+rest_tab2[j][k][len].SS.size()));
		}
		len=a[i].len;
		curs=0;
		while(len>=T2MXL)
		{
			len-=128;
			curs+=2;
		}
		curs+=rest_tab[j][k][len].size();
		ret=min(ret,curs);
	}
	else
	{
		ret=len_tab[j][a[i].len].size()+(j==k?0:1+dg_tab[1<<(7-k)].size());
	}
	return ret;
}
void initialize_cost()
{
	for(int i=1;i<1000;i++)
	{
		int x=i;
		dg_tab[i]="";
		while(x)
		{
			dg_tab[i].PB('0'+x%10);
			x/=10;
		}
		reverse(dg_tab[i].begin(),dg_tab[i].end());
	}
	for(int t=0;t<8;t++)for(int i=1;i<=255;i++)len_tab[t][i]=Sinf;
	for(int t=0;t<8;t++)
	{
		for(int i=1;i<=128;i<<=1)
		{
			string cur=(i==(1<<t))?"":dg_tab[128/i];
			int len=i,bs=i;
			while(bs>0)
			{
				len_tab[t][len]=cur;
				cur.PB('.');
				bs>>=1;
				len+=bs;
			}
		}
	}
	for(int i=0;i<T2MX;i++)
	{
		for(int s=0;s<8;s++)
		{
			for(int t=0;t<8;t++)
			{
				string &S=rest_tab[s][t][i];
				S=Sinf;
				for(int j=1;j<=i&&j<256;j++)
				{
					if(rest_tab[s][t][i-j].size()+1+len_tab[t][j].size()<S.size())
					{
						S=rest_tab[s][t][i-j]+"R"+len_tab[t][j];
					}
				}
				if(i==0&&s==t)S="";
			}
			for(int t=0;t<8;t++)
			{
				string &S=rest_tab[s][t][i];
				string tmp="L"+dg_tab[1<<(7-t)];
				for(int pt=0;pt<8;pt++)
				{
					if(rest_tab[s][pt][i].size()+tmp.size()<S.size())
					{
						S=rest_tab[s][pt][i]+tmp;
					}
				}
			}
		}
	}
	for(int i=0;i<T2MXL+T2MXL-1;i++)
	{
		for(int s=0;s<8;s++)
		{ 
			for(int t=0;t<8;t++)
			{
				pair<string,string> &S=rest_tab2[s][t][i];
				S=MP(Sinf,Sinf);
				for(int j=0;j<=i&&j<T2MX;j++)
				{
					if(i-j<T2MX)
					{
						if(rest_tab[s][7][j].size()+rest_tab[7][t][i-j].size()<S.FF.size()+S.SS.size())
						{
							S=MP(rest_tab[s][7][j],rest_tab[7][t][i-j]);
						}
					}
				}
			}
		}
	}
	/*
	for(int i=1;i<T2MX;i++)
	{	
		for(int j=0;j<=i;j++)
		{
			for(int v=0;v<8;v++)
			{	
				for(int s=0;s<8;s++)
				{
					for(int t=0;t<8;t++)
					{
						assert(rest_tab[s][v][j].size()+rest_tab[v][t][i-j].size()>=rest_tab[s][t][i].size());
						if(rest_tab[s][v][j].size()+rest_tab[v][t][i-j].size()<rest_tab[s][t][i].size())
						{
							rest_tab[s][t][i]=rest_tab[s][v][j]+rest_tab[v][t][i-j];
//							cerr<<s<<" "<<t<<" "<<i<<":"<<rest_tab2[s][t][i]<<endl;
//							cerr<<v<<" "<<j<<":"<<rest_tab2[s][v][j]<<" + "<<rest_tab2[v][t][i-j]<<endl;
						}
					}
				}
			}
		}
	}*/
}


int note_chtoid[7]={9,11,0,2,4,5,7};
note make_note(int oct,char note_ch,int dlt,int len,int vol)
{
	return note((oct-1)*NOTEN+note_chtoid[note_ch-'A']+dlt,len,vol);
}
int get_num(char s[],int &it)
{
	int ret=0;
	while(s[it]>='0'&&s[it]<='9')ret=ret*10+s[it]-'0',it++;
	return ret;
}
int get_len(char s[],int &it,int Gdl=0)
{
	int bs=get_num(s,it);
	if(bs==0&&Gdl==0)return 0;
	if(bs==0)bs=Gdl;else bs=128/bs;
	int ret=bs;
	while(s[it]=='.')bs/=2,ret+=bs,it++;
	return ret;
}
void initialize()
{
	int oc=0;
	n=0;
	for(int i=0;i<STRLEN;i++)a[i]=note(0,0,0);
	Slen=strlen(S+1);
	S[Slen+1]='\n';
	int Goct=4,Gvol=100,Gdl=32;
	for(int i=1;i<=Slen;i++)
	{
//		cerr<<"i="<<i<<" Goct="<<Goct<<" Gvol="<<Gvol<<" "<<S[i]<<endl;
		if(S[i]>='A'&&S[i]<='G')
		{
			char note_ch=S[i];
			int dlt=0;
			i++;oc++;
			if(S[i]=='+')dlt=1,i++,oc++;
			if(S[i]=='-')dlt=-1,i++,oc++;
			int len=get_len(S,i,Gdl);
			a[++n]=make_note(Goct,note_ch,dlt,len,Gvol);
			i--;
		}
		if(S[i]=='R')
		{
			i++;
			int len=get_len(S,i,Gdl);
			if(n>0&&a[n].id==-1)a[n].len+=len;
			else a[++n]=note(-1,len,-1);
			i--;
		}
		if(S[i]=='L')
		{
			i++;
			int len=get_len(S,i);
			assert((len&(-len))==len);
			Gdl=len;
			i--;
		}
		if(S[i]=='V')
		{
			i++;
			int len=get_num(S,i);
			Gvol=len;
			i--;
		}
		if(S[i]=='>')Goct++,oc++;
		if(S[i]=='<')Goct--,oc++;
		if(S[i]=='O')
		{
			i++;oc+=2;
			Goct=S[i]-'0';
		}
	}
//	cerr<<"oc="<<oc<<endl;
}
int w[STRLEN][LENCNT][LENCNT];
int dp[STRLEN][LENCNT];
int pre[STRLEN][LENCNT];
void solve_lencost()
{
	memset(w,0,sizeof(w));
//	cerr<<"solve_lencost:"<<endl;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<LENCNT;j++)for(int k=0;k<LENCNT;k++)w[i][j][k]=get_tab_cost(i,j,k);
	}
	memset(dp,31,sizeof(dp));
	memset(pre,0,sizeof(pre));
	for(int i=0;i<LENCNT;i++)dp[0][i]=1+dg_tab[(1<<(7-i))].size();
	dp[0][5]=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<LENCNT;j++)
		{
			for(int t=0;t<LENCNT;t++)
			{
				if(dp[i][j]+w[i+1][j][t]<dp[i+1][t])
				{
					dp[i+1][t]=dp[i][j]+w[i+1][j][t];
					pre[i+1][t]=j;
				}
			}
		}
	}
}
int oct_dp[STRLEN][8];
int oct_pre[STRLEN][8];
void solve_octcost()
{
//	cerr<<"solve_octcost:"<<endl;
	memset(oct_dp,31,sizeof(oct_dp));
	memset(oct_pre,0,sizeof(oct_pre));
	oct_dp[0][3]=0;oct_pre[0][3]=-1;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<8;j++)
		{
			for(int k=0;k<8;k++)
			{
				int cost=2-(abs(j-k)==1);
				if(oct_dp[i][j]>oct_dp[i][k]+cost)
				{
					oct_dp[i][j]=oct_dp[i][k]+cost;
					oct_pre[i][j]=k;
				}
			}
		}
		if(i<n)
		{
			for(int j=0;j<8;j++)
			{
				oct_dp[i+1][j]=oct_dp[i][j]+get_note_cost(j-a[i+1].id/12,a[i+1].id%12);
				oct_pre[i+1][j]=-1;
			}
		}
	}
}
void print_ans()
{
/*	cerr<<"print_ans:"<<endl;
	for(int i=0;i<=n;i++){for(int j=0;j<8;j++)cerr<<dp[i][j]<<","<<pre[i][j]<<" ";cerr<<endl;}cerr<<endl;
	for(int i=0;i<=n;i++){for(int j=0;j<8;j++)cerr<<oct_dp[i][j]<<","<<oct_pre[i][j]<<" ";cerr<<endl;}cerr<<endl;
*/	
	static string ANS[STRLEN];
	for(int i=0;i<=n;i++)ANS[i].clear();
	int COST=0;
	//OctCost
	int x=n,y=0;
	for(int i=0;i<8;i++)if(oct_dp[x][i]<oct_dp[x][y])y=i;
//	cerr<<"OctCost="<<oct_dp[x][y]<<endl;
	COST+=oct_dp[x][y];
	while(x>0||oct_pre[x][y]!=-1)
	{
		if(oct_pre[x][y]==-1)
		{
			ANS[x]+=get_note_str(y-a[x].id/12,a[x].id%12);
			x--;
		}
		else
		{
			y=oct_pre[x][y];
		}
	}
	//LenCost
	x=n,y=0;
	for(int i=0;i<8;i++)if(dp[x][i]<dp[x][y])y=i;
	COST+=dp[x][y];
	while(x>0)
	{
		ANS[x]+=get_tab(x,pre[x][y],y);
		y=pre[x][y];
		x--;
	}
	if(y!=5)ANS[0]+="L"+dg_tab[1<<(7-y)];
	//OctCost2
	x=n,y=0;
	for(int i=0;i<8;i++)if(oct_dp[x][i]<oct_dp[x][y])y=i;
	while(x>0||oct_pre[x][y]!=-1)
	{
		if(oct_pre[x][y]==-1)
		{
			x--;
		}
		else
		{
			if(oct_pre[x][y]==y-1)ANS[x]+=">";
			else if(oct_pre[x][y]==y+1)ANS[x]+="<";
			else ANS[x]+="O"+dg_tab[y+1];
			y=oct_pre[x][y];
		}
	}

	//VolCost
	int Gvol=100;
	for(int i=1;i<=n;i++)
	{
		if(a[i].id!=-1&&a[i].vol!=Gvol)
		{
			ANS[i-1].PB('V');
			ANS[i-1]+=dg_tab[a[i].vol];
			Gvol=a[i].vol;
			COST+=1+dg_tab[a[i].vol].size();
		}
	}
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<ANS[i].size();j++)putchar(ANS[i][j]);
	}
	puts("");
//	cerr<<"COST="<<COST<<endl;
}
void debug()
{
	cerr<<"n="<<n<<endl;
	for(int i=1;i<=n;i++)
	{
		cerr<<a[i].id<<" "<<a[i].len<<" "<<a[i].vol<<endl;
	}
}
void solve()
{
	solve_lencost();
	solve_octcost();
	print_ans();
}
void test_cost()
{
	for(int i=0;i<T2MX;i++)
	{
		a[1]=note(-1,i,-1);
		for(int s=0;s<8;s++)
		{
			for(int t=0;t<8;t++)
			{
				int gt=get_tab_cost(1,s,t);
				int tb=rest_tab[s][t][i].size();
				if(gt!=tb)
				{
					cerr<<i<<" "<<s<<" "<<t<<endl;
					cerr<<"gt="<<gt<<" tb="<<tb<<endl;
					cerr<<get_tab(1,s,t)<<endl;
					cerr<<rest_tab[s][t][i]<<endl;
					exit(0);
				}
			}
		}
	}
}
int main()
{
	initialize_cost();
	test_cost();
//	cerr<<rest_tab[5][7][48]<<" "<<rest_tab[7][1][3]<<endl;
	int tn=0;
	while(true)
	{
		scanf("%s",S+1);
		if(S[1]=='*')break;
		printf("Case %d: ",++tn);
		initialize();
///		cerr<<get_tab(1,5,1)<<endl;
//		debug();
		solve();
	}
	return 0;
}
accuracy: 1
time_ms: 260
memory_kb: 68288
final_rank: 4

code_snippet: #include <bits/stdc++.h>
#define pb push_back
#define sz(a) ((int)a.size())
#define re return
#define all(a) a.begin(),a.end()
#define rept(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,a) rept(i,0,a)
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define debug(x) cout<<#x<<"="<<x<<"\n";
#define int long long
using namespace std;
const int MOD=998244353,INF=1000000000000000000;
template<typename T>inline void Mx(T &a,T b){a=max(a,b);}
template<typename T>inline void Mi(T &a,T b){a=min(a,b);}

struct OP{
	int t,x,y,z;
	OP(int _t,int _x,int _y=0,int _z=0){
		t=_t,x=_x,y=_y,z=_z;
	}
};

int Case;
vector<OP>S;
int cur_oct,cur_vol,cur_def;
int getint(string);
int get_dot_number(string);
string to_str(int);
void ReadStr(string);

string STR;
void pre();
string get_R(int,int,int);
void run1();
void run2();
void run3();
void run4();
void run5();

void run(){
	run1();
	run2();
	run3();
	run4();
	run5();
}
signed main()
{
//	ios::sync_with_stdio(0);
//	cin.tie(0);cout.tie(0);
	pre();
	while(cin>>STR)run();
	re 0;
}

/////////////////////////////////////////

int getint(string s){
	int x=0;
	rep(i,sz(s))if(isdigit(s[i]))x=x*10+s[i]-'0';
	re x;
}
int get_dot_number(string s){
	int x=0;
	rep(i,sz(s))if(s[i]=='.')x++;
	re x;
}
string to_str(int x){
	string s="";
	while(x){
		s+='0'+x%10;
		x/=10;
	}
	reverse(all(s));
	re s;
}
void ReadStr(string s){
	if(s=="")re;
	//octave
	if(s=="<"){
		cur_oct--;
		re;
	}
	if(s==">"){
		cur_oct++;
		re;
	}
	if(s[0]=='O'){
		cur_oct=s[1]-'0'-1;
		re;
	}
	//volume
	if(s[0]=='V'){
		int x=getint(s);
		if(x!=cur_vol){
			cur_vol=x;
			S.pb(OP(2,x));
		}
		re;
	}
	//default
	if(s[0]=='L'){
		cur_def=getint(s);
		re;
	}
	//rest
	if(s[0]=='R'){
		int xx=getint(s);
		if(!xx)xx=cur_def;
		int x=128/xx,y=x,z=get_dot_number(s);
		rep(i,z)y/=2,x+=y;
		S.pb(OP(1,x));
		re;
	}
	//note
	int l=0;
	while(l<sz(s)&&!isdigit(s[l]))l++;
	int h=cur_oct*12;
	if(s[0]=='D')h+=2;
	if(s[0]=='E')h+=4;
	if(s[0]=='F')h+=5;
	if(s[0]=='G')h+=7;
	if(s[0]=='A')h+=9;
	if(s[0]=='B')h+=11;
	if(l>1&&s[1]=='-')h--;
	if(l>1&&s[1]=='+')h++;
	int x=getint(s),y=get_dot_number(s);
	if(x==0)x=cur_def;
	S.pb(OP(0,h,x,y));
}

//////////////////////////////////////////////////

const int BL=4096;
string dp_R[8][8][BL];

void Mi_str(string &ss,string tt){
	if(ss=="~")ss=tt;
	if(sz(ss)>sz(tt))ss=tt;
}
void pre(){
	rep(i,8)rep(j,8)rep(k,BL)dp_R[i][j][k]="~";
	rep(i,8)dp_R[i][i][0]="";
	rep(i,8){
		rep(j,BL){
			rep(k,8){
				if(dp_R[i][k][j]=="~")continue;
				//add L*
				rep(l,8){
					Mi_str(dp_R[i][l][j],dp_R[i][k][j]+"L"+to_str(1<<(l^7)));
				}
			}
			rep(k,8){
				//add R*
				rep(l,8){
					string cur="R";
					if(l!=k)cur+=to_str(1<<(l^7));
					int len=0;
					for(int m=l;m>=0;m--){
						len+=1<<m;
						if(j+len>=BL)break;
						Mi_str(dp_R[i][k][j+len],dp_R[i][k][j]+cur);
						cur+=".";
					}
				}
			}
		}
	}
//	rep(i,BL)rep(x,8)rep(y,8)cout<<x<<" "<<i<<" "<<y<<" "<<dp_R[x][y][i]<<"\n";
}
string get_R(int x,int y,int len){
	if(len<=BL)re dp_R[x][y][len];
	int mid=(len-BL+127)/128;
	pii mi={INF,-1};
	rept(i,BL/2,BL/2+128)Mi(mi,{sz(dp_R[x][7][len-mid*128-i])+sz(dp_R[7][y][i]),i});
	re dp_R[x][7][len-mid*128-mi.S]+string(mid,'R')+dp_R[7][y][mi.S];
}

//////////////////////////////////

//init
void run1(){
	if(STR=="*")exit(0);
	cur_oct=3;
	cur_vol=100;
	cur_def=4;
}
//cut&decode
void run2(){
	S.clear();
	string t="";
	rep(i,sz(STR)){
		if(isupper(STR[i])||STR[i]=='<'||STR[i]=='>'){
			ReadStr(t);
			t="";
		}
		t+=STR[i];
	}
	ReadStr(t);
}
//swap&merge
void run3(){
	vector<OP>S2;
	for(int l=0,r;l<sz(S);l=r){
		r=l;
		if(S[l].t==1){
			int sum=0;
			while(r<sz(S)&&S[r].t==1)sum+=S[r++].x;
			S2.pb(OP(1,sum));
		}
		else if(S[l].t==0){
			r=l+1;
			S2.pb(S[l]);
		}
		else{
			r=l+1;
			bool ok=0;
			while(r<sz(S)){
				if(S[r].t==0){
					ok=1;
					break;
				}
				if(S[r].t==2)break;
				r++;
			}
			r=l+1;
			if(ok)S2.pb(S[l]); 
		}
	}
	S=S2;
	rep(i,sz(S)-1){
		if(S[i].t==2&&S[i+1].t==1)swap(S[i],S[i+1]);
	}
	S2.clear();
	for(int l=0,r;l<sz(S);l=r){
		r=l;
		if(S[l].t==1){
			int sum=0;
			while(r<sz(S)&&S[r].t==1)sum+=S[r++].x;
			S2.pb(OP(1,sum));
		}
		else if(S[l].t==0){
			r=l+1;
			S2.pb(S[l]);
		}
		else{
			r=l+1;
			bool ok=0;
			while(r<sz(S)){
				if(S[r].t==0){
					ok=1;
					break;
				}
				if(S[r].t==2)break;
				r++;
			}
			r=l+1;
			if(ok)S2.pb(S[l]); 
		}
	}
	S=S2;
//	rep(i,sz(S)){
//		if(S[i].t==0){
//			cout<<"Note "<<S[i].x<<" "<<S[i].y<<" "<<S[i].z<<'\n';
//		}
//		else if(S[i].t==1){
//			cout<<"Rest "<<S[i].x<<'\n';
//		}
//		else{
//			cout<<"Volume "<<S[i].x<<"\n";
//		}
//	}
}

//dp
pair<int,pii>DP[100005][8][8];//(pos,def,oct)->(len,trans,from)
vector<string>vecS;
int n;
void run4(){
	n=sz(S);
	rep(i,n+1)rep(j,8)rep(k,8)DP[i][j][k]={INF,{-1,-1}};
	vecS.clear();
	DP[0][5][3]={0,{0,0}};
	int lstV=100;
	rep(i,n){
		if(S[i].t==2){
			string cs="";
			if(lstV!=S[i].x)cs="V"+to_str(lstV=S[i].x);
			rep(j,8)rep(k,8)if(DP[i][j][k].F<INF)Mi(DP[i+1][j][k],{DP[i][j][k].F+sz(cs),{sz(vecS),j<<3|k}});
			vecS.pb(cs);
		}
		if(S[i].t==1){
			rep(j,8)rep(l,8){
				string cs=get_R(j,l,S[i].x);
				bool use=0;
				rep(k,8){
					if(DP[i][j][k].F<INF){
						use=1;
						Mi(DP[i+1][l][k],{DP[i][j][k].F+sz(cs),{sz(vecS),j<<3|k}});
					}
				}
				if(use)vecS.pb(cs);
			}
		}
		if(S[i].t==0){
			string GO[14]={"C-","C","C+","D","D+","E","F","F+","G","G+","A","A+","B","B+"};
			vector<pii>ch_O;
			int h=S[i].x;
			ch_O.pb({h/12,h%12+1});
			if(h%12==0&&h!=0)ch_O.pb({h/12-1,13});
			if(h%12==11&&h!=95)ch_O.pb({h/12+1,0});
			rep(j,8)rep(k,8){
				if(DP[i][j][k].F>=INF)continue;
				for(pii l:ch_O){
					string pf="";
					if(k==l.F+1)pf="<";
					else if(k==l.F-1)pf=">";
					else if(k!=l.F)pf="O"+string(1,'0'+l.F+1);
					if((1<<(j^7))==S[i].y){
						string cs=pf+GO[l.S]+string(S[i].z,'.');
						Mi(DP[i+1][j][l.F],{DP[i][j][k].F+sz(cs),{sz(vecS),j<<3|k}});
						vecS.pb(cs);
					}
					if((1<<(j^7))!=S[i].y){
						//use
						string cs=pf+"L"+to_str(S[i].y)+GO[l.S]+string(S[i].z,'.');
						Mi(DP[i+1][__lg(S[i].y)^7][l.F],{DP[i][j][k].F+sz(cs),{sz(vecS),j<<3|k}});
						vecS.pb(cs);
						cs=pf+GO[l.S]+to_str(S[i].y)+string(S[i].z,'.');
						Mi(DP[i+1][j][l.F],{DP[i][j][k].F+sz(cs),{sz(vecS),j<<3|k}});
						vecS.pb(cs);
					}
				}
			}
		}
	}
//	rep(i,n+1)rep(j,8)rep(k,8)if(DP[i][j][k].F<INF){
//		cout<<DP[i][j][k].F<<" "<<vecS[DP[i][j][k].S.F]<<" "<<(DP[i][j][k].S.S>>3)<<" "<<(DP[i][j][k].S.S&7)<<"\n";
//	}
}
//restore answer&output
void run5(){
	pair<int,pii>p={INF,{-1,-1}};
	rep(i,8)rep(j,8)Mi(p,{DP[n][i][j].F,{i,j}});
	int x=p.S.F,y=p.S.S;
	vi v;
	for(int i=n;i;i--){
		v.pb(DP[i][x][y].S.F);
		int t=DP[i][x][y].S.S;
		x=t>>3;
		y=t&7;
	}
	reverse(all(v));
	assert(sz(v)==n);
	cout<<"Case "<<++Case<<": ";
	for(int i:v)cout<<vecS[i];
	cout<<"\n";
}
accuracy: 1
time_ms: 1030
memory_kb: 69460
final_rank: 6

code_snippet: #include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define F first
#define S second
#define ll int
#define N 100010
using namespace std;
ll num_len(ll x)
{
	if(x==0)
	{
		return 1;
	}
	ll ret=0;
	while(x)
	{
		ret++;
		x/=10;
	}
	return ret;
}
struct Note{
	ll num,cr,vl,len;
};
map<string,ll> ntid;
string ntnm[]={"C","C+","D","D+","E","F","F+","G","G+","A","A+","B"};
string s;
vector<Note> nts;
ll dp[N][9][8],rstval[8][10010][8];
pair<ll,ll> trsrst[8][10010][8];
pair<ll,pair<ll,ll> > trs[N][9][8];
ll calclen(string t,ll curlen)
{
	ll num=0,ret=0,i;
	while((!t.empty())&&isdigit(t[0]))
	{
		num=num*10+t[0]-'0';
		t.erase(t.begin());
	}
	if(num==0)
	{
		num=curlen;
	}
	else
	{
		num=128/num;
	}
	for(i=0;i<=t.size();i++)
	{
		ret+=num;
		num/=2;
	}
	return ret;
}
void printrst(ll l0,ll x,ll l1)
{
	if(x==-1)
	{
		return;
	}
	ll lstx=trsrst[l0][x][l1].F,lstl=trsrst[l0][x][l1].S,j,k;
	printrst(l0,lstx,lstl);
	if(lstx==x)
	{
		printf("L%d",128/(1<<l1));
		return;
	}
	if(lstx==-1)
	{
		return;
	}
	bool ok=false;
	for(j=0;j<8;j++)
	{
		ll cur=num_len(128/(1<<j)),sum=0,curval=1<<j;
		for(k=0;curval;k++,curval>>=1)
		{
			sum+=curval;
			if(sum==x-lstx)
			{
				ll nv=cur*(j!=l1)+k+1;
				if(rstval[l0][x][l1]==rstval[l0][lstx][lstl]+nv)
				{
					putchar('R');
					if(j!=l1)
					{
						printf("%d",128/(1<<j));
					}
					while(k--)
					{
						putchar('.');
					}
					ok=true;
					break;
				}
			}
		}
		if(ok)
		{
			break;
		}
	}
	return;
}
void print(ll x,ll cr,ll len)
{
	if(x==-1)
	{
		return;
	}
	ll lstx=trs[x][cr][len].F,lstcr=trs[x][cr][len].S.F,lstlen=trs[x][cr][len].S.S;
	bool pvol=false;
	if(lstx>=INF)
	{
		lstx-=INF,lstcr-=INF,lstlen-=INF;
		pvol=true;
	}
	print(lstx,lstcr,lstlen);
	if(lstx==-1)
	{
		return;
	}
	if(x==lstx)
	{
		if(cr==lstcr)
		{
			printf("L%d",128/(1<<len));
		}
		else
		{
			if(cr==lstcr+1)
			{
				putchar('>');
			}
			else if(cr==lstcr-1)
			{
				putchar('<');
			}
			else
			{
				printf("O%d",cr);
			}
		}
		return;
	}
	if(nts[x-1].num==INF)
	{
		ll cur=nts[x-1].len,req;
		if(!pvol)
		{
			req=(cur<10000)?0:(cur-10000+(1<<lstlen)+50)/(1<<lstlen);
			cur-=req*(1<<lstlen);
			while(req--)
			{
				putchar('R');
			}
		}
		else
		{
			req=(cur<10000)?0:(cur-10000+(1<<len)+50)/(1<<len);
			cur-=req*(1<<len);
		}
		printrst(lstlen,cur,len);
		if(pvol)
		{
			while(req--)
			{
				putchar('R');
			}
		}
		return;
	}
	ll adsz=0,j,k,curval;
	if(pvol)
	{
		adsz+=num_len(nts[x-1].vl)+1;
		printf("V%d",nts[x-1].vl);
	}
	if(cr==nts[x-1].cr)
	{
		adsz+=ntnm[nts[x-1].num].size();
		printf("%s",ntnm[nts[x-1].num].c_str());
	}
	else if(cr==nts[x-1].cr-1)
	{
		adsz+=2;
		printf("B+");
	}
	else
	{
		adsz+=2;
		printf("C-");
	}
	bool ok=false;
	for(j=0;j<8;j++)
	{
		ll cur=num_len(128/(1<<j)),sum=0,curval=1<<j;
		for(k=0;curval;k++,curval>>=1)
		{
			sum+=curval;
			if(sum==nts[x-1].len)
			{
				ll nv=cur*(j!=len)+k+adsz;
				if(dp[x][cr][len]==dp[lstx][lstcr][len]+nv)
				{
					if(j!=len)
					{
						printf("%d",128/(1<<j));
					}
					while(k--)
					{
						putchar('.');
					}
					ok=true;
					break;
				}
			}
		}
		if(ok)
		{
			break;
		}
	}
	return;
}
int main(){
	ll i,j,k,l,p,TC=1;
	ntid["C-"]=-1;
	ntid["C"]=0;
	ntid["C+"]=ntid["D-"]=1;
	ntid["D"]=2;
	ntid["D+"]=ntid["E-"]=3;
	ntid["E"]=ntid["F-"]=4;
	ntid["E+"]=ntid["F"]=5;
	ntid["F+"]=ntid["G-"]=6;
	ntid["G"]=7;
	ntid["G+"]=ntid["A-"]=8;
	ntid["A"]=9;
	ntid["A+"]=ntid["B-"]=10;
	ntid["B"]=11;
	ntid["B+"]=12;
	for(l=0;l<8;l++)
	{
		memset(rstval[l],63,sizeof(rstval[l]));
		rstval[l][0][l]=0;
		trsrst[l][0][l]=make_pair(-1,-1);
		for(i=0;i<=10000;i++)
		{
			ll mnv=0;
			for(j=0;j<8;j++)
			{
				if(rstval[l][i][j]<rstval[l][i][mnv])
				{
					mnv=j;
				}
			}
			for(j=0;j<8;j++)
			{
				ll nv=num_len(128/(1<<j))+1+rstval[l][i][mnv];
				if(rstval[l][i][j]>nv)
				{
					rstval[l][i][j]=nv;
					trsrst[l][i][j]=make_pair(i,mnv);
				}
			}
			for(j=0;j<8;j++)
			{
				ll cur=num_len(128/(1<<j)),sum=0,curval=1<<j;
				for(k=0;curval;k++,curval>>=1)
				{
					sum+=curval;
					if(i+sum<=10000)
					{
						for(p=0;p<8;p++)
						{
							ll nv=rstval[l][i][p]+cur*(j!=p)+k+1;
							if(rstval[l][i+sum][p]>nv)
							{
								rstval[l][i+sum][p]=nv;
								trsrst[l][i+sum][p]=make_pair(i,p);
							}
						}
					}
				}
			}
		}
	}
	while(true)
	{
		cin>>s;
		if(s=="*")
		{
			break;
		}
		nts.clear();
		ll curvl=100,curcr=4,curlen=32;
		for(i=0;i<s.size();)
		{
			if(s[i]=='>')
			{
				curcr++;
				i++;
			}
			else if(s[i]=='<')
			{
				curcr--;
				i++;
			}
			else if(s[i]=='O')
			{
				curcr=s[i+1]-'0';
				i+=2;
			}
			else if(s[i]=='V')
			{
				ll cnum=0;
				for(j=i+1;isdigit(s[j]);j++)
				{
					cnum=cnum*10+s[j]-'0';
				}
				curvl=cnum;
				i=j;
			}
			else if(s[i]=='L')
			{
				ll cnum=0;
				for(j=i+1;isdigit(s[j]);j++)
				{
					cnum=cnum*10+s[j]-'0';
				}
				curlen=128/cnum;
				i=j;
			}
			else if(s[i]=='R')
			{
				string ts="";
				for(j=i+1;j<s.size()&&(isdigit(s[j])||s[j]=='.');j++)
				{
					ts+=s[j];
				}
				Note nw;
				nw.num=INF,nw.cr=nw.vl=-1,nw.len=calclen(ts,curlen);
				if((!nts.empty())&&nts[nts.size()-1].num==INF)
				{
					nts[nts.size()-1].len+=nw.len;
				}
				else
				{
					nts.push_back(nw);
				}
				i=j;
			}
			else
			{
				ll ntnum,ntcr=curcr;
				if(i+1<s.size()&&(s[i+1]=='+'||s[i+1]=='-'))
				{
					ntnum=ntid[s.substr(i,2)];
					i+=2;
				}
				else
				{
					ntnum=ntid[s.substr(i,1)];
					i++;
				}
				if(ntnum==-1)
				{
					ntnum+=12;
					ntcr--;
				}
				if(ntnum==12)
				{
					ntnum-=12;
					ntcr++;
				}
				string ts="";
				for(j=i;j<s.size()&&(isdigit(s[j])||s[j]=='.');j++)
				{
					ts+=s[j];
				}
				Note nw;
				nw.num=ntnum,nw.cr=ntcr,nw.vl=curvl,nw.len=calclen(ts,curlen);
				nts.push_back(nw);
				i=j;
			}
		}
		for(i=0;i<=nts.size();i++)
		{
			memset(dp[i],63,sizeof(dp[i]));
		}
		dp[0][4][5]=0;
		trs[0][4][5]=make_pair(-1,make_pair(-1,-1));
		curvl=100;
		for(i=0;i<nts.size();i++)
		{
			for(j=1;j<=8;j++)
			{
				ll mnv=0;
				for(k=0;k<8;k++)
				{
					if(dp[i][j][k]<dp[i][j][mnv])
					{
						mnv=k;
					}
				}
				for(k=0;k<8;k++)
				{
					ll nv=dp[i][j][mnv]+1+num_len(128/(1<<k));
					if(dp[i][j][k]>nv)
					{
						dp[i][j][k]=nv;
						trs[i][j][k]=make_pair(i,make_pair(j,mnv));
					}
				}
			}
			for(j=0;j<8;j++)
			{
				for(k=1;k<=8;k++)
				{
					for(l=1;l<=8;l++)
					{
						ll nv=dp[i][k][j]+2-(abs(k-l)<=1);
						if(dp[i][l][j]>nv)
						{
							dp[i][l][j]=nv;
							trs[i][l][j]=make_pair(i,make_pair(k,j));
						}
					}
				}
			}
			if(nts[i].num!=INF)
			{
				ll ad=0;
				if(curvl!=nts[i].vl)
				{
					ad+=num_len(nts[i].vl)+1;
				}
				for(j=0;j<8;j++)
				{
					ll cur=num_len(128/(1<<j)),sum=0,curval=1<<j;
					for(k=0;curval;k++,curval>>=1)
					{
						sum+=curval;
						if(sum==nts[i].len)
						{
							for(p=0;p<8;p++)
							{
								ll nv=dp[i][nts[i].cr][p]+cur*(j!=p)+k+ad+ntnm[nts[i].num].size();
								if(dp[i+1][nts[i].cr][p]>nv)
								{
									dp[i+1][nts[i].cr][p]=nv;
									if(curvl!=nts[i].vl)
									{
										trs[i+1][nts[i].cr][p]=make_pair(i+INF,make_pair(nts[i].cr+INF,p+INF));
									}
									else
									{
										trs[i+1][nts[i].cr][p]=make_pair(i,make_pair(nts[i].cr,p));
									}
								}
								if(nts[i].num==0)
								{
									nv=dp[i][nts[i].cr-1][p]+cur*(j!=p)+k+ad+2;
									if(dp[i+1][nts[i].cr-1][p]>nv)
									{
										dp[i+1][nts[i].cr-1][p]=nv;
										if(curvl!=nts[i].vl)
										{
											trs[i+1][nts[i].cr-1][p]=make_pair(i+INF,make_pair(nts[i].cr-1+INF,p+INF));
										}
										else
										{
											trs[i+1][nts[i].cr-1][p]=make_pair(i,make_pair(nts[i].cr-1,p));
										}
									}
								}
								if(nts[i].num==11)
								{
									nv=dp[i][nts[i].cr+1][p]+cur*(j!=p)+k+ad+2;
									if(dp[i+1][nts[i].cr+1][p]>nv)
									{
										dp[i+1][nts[i].cr+1][p]=nv;
										if(curvl!=nts[i].vl)
										{
											trs[i+1][nts[i].cr+1][p]=make_pair(i+INF,make_pair(nts[i].cr+1+INF,p+INF));
										}
										else
										{
											trs[i+1][nts[i].cr+1][p]=make_pair(i,make_pair(nts[i].cr+1,p));
										}
									}
								}
							}
						}
					}
				}
				curvl=nts[i].vl;
			}
			else
			{
				for(j=0;j<8;j++)
				{
					ll cur=nts[i].len,tot=(cur<10000)?0:(cur-10000+(1<<j)+50)/(1<<j);
					cur-=tot*(1<<j);
					for(l=0;l<8;l++)
					{
						ll nv=tot+rstval[j][cur][l];
						for(k=1;k<=8;k++)
						{
							if(dp[i+1][k][l]>dp[i][k][j]+nv)
							{
								dp[i+1][k][l]=dp[i][k][j]+nv;
								trs[i+1][k][l]=make_pair(i,make_pair(k,j));
							}
						}
						nv=tot+rstval[l][cur][j];
						for(k=1;k<=8;k++)
						{
							if(dp[i+1][k][j]>dp[i][k][l]+nv)
							{
								dp[i+1][k][j]=dp[i][k][l]+nv;
								trs[i+1][k][j]=make_pair(i+INF,make_pair(k+INF,l+INF));
							}
						}
					}
				}
			}
		}
		ll ans=INF,lstx,lsty;
		for(i=1;i<=8;i++)
		{
			for(j=0;j<8;j++)
			{
				if(ans>dp[nts.size()][i][j])
				{
					ans=dp[nts.size()][i][j];
					lstx=i,lsty=j;
				}
			}
		}
		printf("Case %d: ",TC++);
		print(nts.size(),lstx,lsty);
		puts("");
	}
	return 0;
}
accuracy: 1
time_ms: 310
memory_kb: 33528
final_rank: 3

code_snippet: /**
 *    author:  gary
 *    created: 28.04.2022 09:54:53
**/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define rep(a,b) for(int a=0;a<b;++a)
#define LL long long
#define PB push_back
#define POB pop_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define check_min(a,b) a=min(a,b)
#define check_max(a,b) a=max(a,b)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
struct Node{
    int note,x,v,o,d;
    Node(){}
    Node(int _,int __,int ___,int ____,int _____){note=_,x=__,v=___,o=____,d=_____;}
    void Debug(){
        cout<<"{\n";
        cout<<"Note="<<note<<endl;
        cout<<"x="<<x<<endl;
        cout<<"v="<<v<<endl;
        cout<<"o="<<o<<endl;
        cout<<"d="<<d<<endl;
        cout<<"}\n";
    }
};
map<string,int> NOTE={
{"C",1},
{"C+",2},
{"D-",2},
{"D",3},
{"D+",4},
{"E-",4},
{"F-",5},
{"E",5},
{"E+",6},
{"F",6},
{"F+",7},
{"G-",7},
{"G",8},
{"G+",9},
{"A-",9},
{"A",10},
{"A+",11},
{"B-",11},
{"B",12}
};
int NOTE_LEN[13],X_LEN[8]={1,1,1,1,2,2,2,3};
string NOTE2[13];
int getnote(string s){
    return NOTE[s];
}
int getx(int x){
    return floor(log2(x)+0.4);
}
const int MAXN=1e5+10;
int n;
Node dat[MAXN];
int getnum(string &s,int &i){
    int x=0;
    while (i<s.length()&&isdigit(s[i])){
        x*=10;
        x+=s[i]-'0';
        i++;
    }
    return x;
}
void Get(string Note,int x,int V,int O,int d){
    // cout<<Note<<" "<<x<<" "<<V<<" "<<O<<' '<<d<<endl;
    if(Note=="C-") Note="B",O--;
    if(Note=="B+") Note="C",O++;
    if(Note=="R"){
        x=128/x;
        int s=x;
        while (d){
            d--;
            x>>=1;
            s+=x;
        }
        if(n&&dat[n].note==0) dat[n].x+=s;
        else dat[++n]=Node(0,s,0,0,0);
    }
    else{
        dat[++n]=Node(getnote(Note),getx(x),V,O-1,d);
    }
}
void process(string &s){
    int i=0;
    int V=100,O=4,L=4;
    while (i<s.length()){
        if(s[i]=='C'||s[i]=='D'||s[i]=='E'||s[i]=='F'||s[i]=='G'||s[i]=='A'||s[i]=='B'||s[i]=='R'){
            string Note;Note.PB(s[i]);
            if(i+1<s.length()&&(s[i+1]=='+'||s[i+1]=='-')) Note.PB(s[i+1]),i++;
            int x=L;
            i++;
            if(i<s.length()&&isdigit(s[i])) x=getnum(s,i);
            else x=L;
            int d=0;
            while (i<s.length()&&s[i]=='.'){
                i++;
                d++;
            }
            Get(Note,x,V,O,d);
        }
        else if(s[i]=='O'||s[i]=='<'||s[i]=='>'){
            if(s[i]=='O'){
                i++;
                int x=getnum(s,i);
                O=x;
            }
            else if(s[i]=='>'){
                O++;
                i++;
            }
            else O--,i++;
        }
        else if(s[i]=='L'){
            i++;
            int x=getnum(s,i);
            L=x;
        }
        else{
            assert(s[i]=='V');
            i++;
            int x=getnum(s,i);
            V=x;
        }
    }
}
const int B=1024;
int dp[MAXN][8][8];
mp from[MAXN][8][8];// L O
string f[B+1][8][8];
bool upd(string& A,string B){
    if(B.length()<A.length()||A=="EMPTY") {A=B;return 1;}
    return 0;
}
string Num(int x){
    string rest="";
    while (x)
    {
        rest.PB('0'+x%10);
        x/=10;
    }
    reverse(ALL(rest));
    return rest;
}
string Lx(int fx,int tx){
    if(fx==tx) return "";
    return "L"+Num(1<<tx);
}
string Vx(int tx){
    string ans="V";
    ans+=Num(tx);
    return ans;
}
string Ox(int fx,int tx){
    if(fx==tx) return "";
    if(fx==tx-1) return ">";
    else if(fx==tx+1) return "<";
    else{
        string ans="O";
        ans.PB(char('1'+tx));
        return ans;
    }
}
string Query(int i,int j,int k){
    if(i<=B) return f[i][j][k];
    int Cnt=0;
    while (i>B)
    {
        i-=128;
        Cnt++;
    }
    string rest=Query(i,j,k);
    string Ans;
    if(j==0){
        rb(i,1,Cnt) Ans+="R";
        return Ans+rest;
    }
    rep(i,rest.length()){
        if(i>=2&&rest[i-2]=='L'&&rest[i-1]=='1'&&rest[i]!='2'&&rest[i]!='6'){
            rb(i,1,Cnt) Ans+="R";
            Cnt=0;
        }
        Ans.PB(rest[i]);
    }
    // if(Cnt){
    //     cerr<<i<<" "<<rest<<" "<<rest.length()<<j<<" "<<k<<" "<<endl;
    // }
    // assert(!Cnt);
    return Ans;
}
int Querylen(int i,int j,int k){
    if(i<=B) return f[i][j][k].length();
    int Cnt=(i-B)/128;
    i-=Cnt*128;
    while (i>B)
    {
        i-=128;
        Cnt++;
    }
    return Cnt+Querylen(i,j,k);
}
int Work(int o,int k,Node x){
    if(o==x.o){
        return NOTE_LEN[x.note]+(k==x.x? 0:Num((1<<x.x)).length())+x.d;
    }
    if(o==x.o-1&&x.note==1){
        return 2+(k==x.x? 0:Num((1<<x.x)).length())+x.d;
    }
    if(o==x.o+1&&x.note==12){
        return 2+(k==x.x? 0:Num((1<<x.x)).length())+x.d;
    }
    return INF;
}
string Works(int o,int k,Node x){
    if(o==x.o){
        string tmp= NOTE2[x.note]+(k==x.x? "":Num((1<<x.x)));
        rb(i,1,x.d) tmp.PB('.');
        return tmp;
    }
    if(o==x.o-1&&x.note==1){
        string tmp= "B+"+(k==x.x? "":Num((1<<x.x)));
        rb(i,1,x.d) tmp.PB('.');
        return tmp;
    }
    if(o==x.o+1&&x.note==12){
        string tmp= "C-"+(k==x.x? "":Num((1<<x.x)));
        rb(i,1,x.d) tmp.PB('.');
        return tmp;
    }
    return "FUCK";
}
int Recover(int i,int j,int k){
    int fj,fk;
    if(i==0) return 100;
    tie(fj,fk)=from[i][j][k];
    if(dat[i].note==0){
        int tmp=Recover(i-1,fj,fk);
        cout<<Query(dat[i].x,fj,j);
        return tmp;
    }
    int tmp=Recover(i-1,fj,fk);
    if(tmp!=dat[i].v){
        cout<<Vx(dat[i].v);
        tmp=dat[i].v;
    }
    cout<<Lx(fj,j)<<Ox(fk,k)<<Works(k,j,dat[i]);
    return tmp;
}
int main(){
    // freopen("in.txt","r",stdin);
    // freopen("my.txt","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    for(auto it:NOTE) NOTE_LEN[it.second]=it.first.length(),NOTE2[it.second]=it.first;
    for(auto it:NOTE) NOTE_LEN[it.second]=it.first.length(),upd(NOTE2[it.second],it.first);
    rep(i,B+1) rep(j,8) rep(k,8) f[i][j][k]="EMPTY";
    rep(j,8) rep(k,8) f[0][j][k]=Lx(j,k);
    rb(i,1,B) {
        while (true){
            bool ok=0;    
            rep(j,8) rep(k,8){
                rep(l,8) if(f[i][l][k]!="EMPTY") ok|=upd(f[i][j][k],Lx(j,l)+f[i][l][k]);
                rep(g,8){
                    int t=128/((1<<g));
                    int s=0;
                    string Rest="R";
                    if(g!=j) Rest+=Num(1<<g);
                    while (t>=1){
                        if(s!=0) Rest.PB('.');
                        s+=t;
                        t>>=1;
                        if(s<=i&&f[i-s][j][k]!="EMPTY") ok|=upd(f[i][j][k],Rest+f[i-s][j][k]);
                    }
                }
            }
            if(!ok) break;
        }
    }
    // cout<<Query(310,2,0)<<endl;
    // return 0;
    int T=0;
    while (true){
        string s;
        cin>>s;
        if(s=="*") break;
        n=0;
        process(s);
        rb(i,0,n) rep(j,8) rep(k,8) dp[i][j][k]=INF;
        dp[0][2][3]=0;
        rb(i,1,n){
            if(dat[i].note==0){
                rep(j,8){
                    rep(newj,8){
                        int Klen=Querylen(dat[i].x,j,newj);
                        rep(k,8) if(dp[i-1][j][k]+Klen<dp[i][newj][k]){
                            dp[i][newj][k]=dp[i-1][j][k]+Klen;
                            from[i][newj][k]=II(j,k);
                        }
                    }
                }
            }
            else{
                rep(j,8) rep(k,8) if(dp[i-1][j][k]!=INF) 
                rep(nj,8) rep(nk,8){
                    int Klen=Lx(j,nj).length()+Ox(k,nk).length()+Work(nk,nj,dat[i]);
                    if(Klen+dp[i-1][j][k]<dp[i][nj][nk]){
                        dp[i][nj][nk]=dp[i-1][j][k]+Klen;
                        from[i][nj][nk]=II(j,k);
                    }
                }
            }
        }
        // rb(i,1,n){
            // dat[i].Debug();
        // }
        cout<<"Case "<<++T<<": ";
        int ans=INF,j=0,k=0;
        rep(x,8) rep(y,8) if(dp[n][x][y]<ans) ans=dp[n][x][y],j=x,k=y;
        Recover(n,j,k);
        cout<<endl;
    }
    return 0;
}
accuracy: 1
time_ms: 2890
memory_kb: 25476
final_rank: 5

code_snippet: #include<bits/stdc++.h>
#define rep(i,a,n) for (int i=(a);i<=(n);i++)
#define per(i,a,n) for (int i=(n);i>=(a);i--)
#define inf 0x3f3f3f3f
#define pb push_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
using namespace std;
string Ns[] = {"1", "2", "4", "8", "16", "32", "64", "128"};
int DNs[] = {128, 64, 32, 16, 8, 4, 2, 1};
string RS[] = {"C", "D", "E", "F", "G", "A", "B"};
char RC[] = {'C', 'D', 'E', 'F', 'G', 'A', 'B'};
int RK[] = {0, 2, 4, 5, 7, 9, 11};
int LD[] = {2, 2, 2, 2, 3, 3, 3, 4};
const string I = "hyh";
const int N = 100015, M = 1280;

template<class A, class B>
bool upd(A &x, A y, B &xx, B yy) {
	if (x > y) {
		x = y;
		xx = yy;
		return true;
	}

	return false;
}

int NTD(string s) {

	rep(i, 0, 7) if (Ns[i] == s) return DNs[i];

	return 0;
}

int CTRK(char ch) {

	rep(i, 0, 6) if (RC[i] == ch) return RK[i];

	return 0;
}

int STD(string S, int DD) {

	int Num = -1, Dot = count(all(S), '.'), D = 0;

	rep(i, 0, 7) if (DNs[i] == DD) Num = i;

	rep(i, 0, 7) if (S.substr(0, SZ(Ns[i])) == Ns[i]) Num = i;

	rep(i, 0, Dot) D += DNs[Num + i];

	return D;

}

string KTS(int AK, int OT) {
	string _C, n_C;
	auto Do = [&]() {if (SZ(n_C) < SZ(_C) || _C.empty()) _C = n_C;};

	rep(i, 0, 6) {
		if (OT * 12 + RK[i] == AK)
			n_C = RS[i], Do();

		if (OT * 12 + RK[i] + 1 == AK)
			n_C = RS[i] + "+", Do();

		if (OT * 12 + RK[i] - 1 == AK)
			n_C = RS[i] + "-", Do();
	}

	if (_C.empty()) {return I;}

	return _C;
}

string DTS(int D, int DD) {
	vector<int> ms;

	rep(i, 0, 7) if (D & DNs[i]) ms.pb(i);

	if (SZ(ms) != ms.back() - ms[0] + 1) return I;

	string Num, Dot;
	Num = DNs[ms[0]] == DD ? "" : Ns[ms[0]];

	rep(_, 2, SZ(ms)) Dot += ".";

	return Num + Dot;
};

string kts[111][8], dts[256][256];

void Calc(string dp[M + 15][8], int s) {
	static int L[M + 15][8];
	memset(L, 0x3f, sizeof L);
	L[0][s] = 0;

	rep(i, 0, M) {

		rep(j, 0, 7) rep(k, 0, 7) if (j != k) {
			upd(L[i][k], L[i][j] + LD[j], dp[i][k], dp[i][j] + "L" + Ns[k]);
		}

		rep(j, 0, 7) rep(k, 0, 255) {
			if (i + k > M) break;

			string &s = dts[k][DNs[j]];

			if (s == I) continue;

			upd(L[i + k][j], L[i][j] + 1 + SZ(s), dp[i + k][j], dp[i][j] + "R" + s);
		}
	}
}

string dp[8][M + 15][8];

void Prework() {
	rep(i, 0, 7) rep(j, 0, 11) rep(k, 0, 7) kts[i * 12 + j][k] = KTS(i * 12 + j, k);

	rep(i, 1, 255) rep(j, 0, 7) dts[i][DNs[j]] = DTS(i, DNs[j]);

	rep(s, 0, 7) Calc(dp[s], s);
}

int Tr[8][8];

void GTr(int D) {
	int O = D, cnt = 0;

	while (O > M) O -= 128, cnt++;

	rep(p, 0, 7) rep(q, 0, 7) Tr[p][q] = SZ(dp[p][O][q]) + cnt;
}

string GS(int D, int p, int q) {
	int O = D, cnt = 0;

	while (O > M) O -= 128, cnt++;

	string res = dp[p][O][q];

	if (cnt) res.insert(p == 0 ? 0 : (res.find("L1") + 2), cnt, 'R');

	return res;
}

struct Note {
	int AK, Vl, D;
	bool IR;
	string ktos(int OT) {return kts[AK][OT];}
	string dtos(int DD) {return dts[D][DD];}
} A[N];

Note Read(string O, int &OT, int &DD, int &Vl) {
	Note res = (Note) {0, 0, 0, 0};

	if (O[0] == '<') OT--;
	else if (O[0] == '>') OT++;
	else if (O[0] == 'O') OT = O[1] - '1';
	else if (O[0] == 'L') DD = NTD(O.substr(1));
	else if (O[0] == 'V') Vl = stoi(O.substr(1));
	else if (O[0] == 'R') {
		res.IR = 1;
		res.D = STD(O.substr(1), DD);

	} else {
		res.Vl = Vl;
		res.AK = OT * 12 + CTRK(O[0]);
		O.erase(O.begin());

		if (SZ(O) > 0) {
			if (O[0] == '+') {
				O.erase(O.begin());
				res.AK++;

			} else if (O[0] == '-') {
				O.erase(O.begin());
				res.AK--;
			}
		}

		res.D = STD(O, DD);
	}

	return res;
}

int n, f[N][8], fr[N][8];
string se, DA[N], OTA[N], Ex[N];

void SD() {
	rep(i, 0, n) memset(f[i], 0x3f, sizeof f[i]);

	int Vl = 100;
	f[0][2] = 0;

	rep(i, 1, n) {
		if (A[i].IR) {
			GTr(A[i].D);

			rep(p, 0, 7) rep(q, 0, 7) upd(f[i][p], f[i - 1][q] + Tr[q][p], fr[i][p], q);

		} else {
			rep(p, 0, 7) rep(q, 0, 7) upd(f[i][p], f[i - 1][q] + (p != q) * LD[p] + SZ(A[i].dtos(DNs[p])), fr[i][p], q);

			if (Vl != A[i].Vl) {
				Vl = A[i].Vl;
				Ex[i] += "V" + to_string(Vl);
			}
		}
	}

	int Min = inf, p = 0, np = 0;

	rep(i, 0, 7) upd(Min, f[n][i], p, i);

	per(i, 1, n) {
		np = fr[i][p];

		if (A[i].IR) {
			DA[i] = GS(A[i].D, np, p);

		} else {
			if (p != np) Ex[i] += "L" + Ns[p];

			DA[i] = A[i].dtos(DNs[p]);
		}

		p = np;
	}
}

void SOT() {
	rep(i, 0, n) memset(f[i], 0x3f, sizeof f[i]);

	f[0][3] = 0;

	rep(i, 1, n) {
		if (A[i].IR) {
			rep(p, 0, 7) upd(f[i][p], f[i - 1][p], fr[i][p], p);

		} else {
			rep(p, 0, 7) rep(q, 0, 7) {
				string oo = A[i].ktos(p);

				if (oo == I) continue;

				int o = (p == q ? 0 : abs(p - q) == 1 ? 1 : 2);

				upd(f[i][p], f[i - 1][q] + o + SZ(oo), fr[i][p], q);
			}
		}
	}

	int Min = inf, p = 0, np = 0;

	rep(i, 0, 7) upd(Min, f[n][i], p, i);

	per(i, 1, n) {
		np = fr[i][p];

		if (!A[i].IR) {
			if (p != np) {
				if (np + 1 == p) Ex[i] += ">";
				else if (np - 1 == p) Ex[i] += "<";
				else Ex[i] += "O" + to_string(p + 1);
			}

			OTA[i] = A[i].ktos(p);
		}

		p = np;
	}

}

void solve() {
	int OT = 3, DD = NTD("4"), Vl = 100;
	n = 0;

	for (int l = 0, r; r = l, l < SZ(se); l = r + 1) {
		while (r + 1 < SZ(se) && !('A' <= se[r + 1] && se[r + 1] <= 'Z') && se[r + 1] != '<' && se[r + 1] != '>') r++;

		Note Cur = Read(se.substr(l, r - l + 1), OT, DD, Vl);

		if (!Cur.D) continue;

		if (A[n].IR && Cur.IR) A[n].D += Cur.D;
		else A[++n] = Cur;
	}

	rep(i, 1, n) Ex[i] = OTA[i] = DA[i] = "";

	SD();
	SOT();

	rep(i, 1, n) cout << Ex[i] << OTA[i] << DA[i];
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	Prework();
	int test = 0;

	while (cin >> se) {
		if (se == "*") break;

		cout << "Case " << ++test << ": ";
		solve();
		cout << endl;
	}

	return 0;
}
accuracy: 1
time_ms: 390
memory_kb: 26452
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int INF = 0x3f3f3f3f;
inline int get_note(int O, char ch, int f) {
	if (ch == 'C') return (O - 1) * 12 + 1 + f;
	else if (ch == 'D') return (O - 1) * 12 + 3 + f;
	else if (ch == 'E') return (O - 1) * 12 + 5 + f;
	else if (ch == 'F') return (O - 1) * 12 + 6 + f;
	else if (ch == 'G') return (O - 1) * 12 + 8 + f;
	else if (ch == 'A') return (O - 1) * 12 + 10 + f;
	else return (O - 1) * 12 + 12 + f;
}
inline int get_num(char *str, int len, int &i) {
	int x = 0;
	while (i < len && isdigit(str[i + 1])) x = x * 10 + str[++i] - '0';
	return x;
}
inline int get_dot(char *str, int len, int &i) {
	int c = 0;
	while (i < len && str[i + 1] == '.') c++, i++;
	return c;
}
inline int get_len(int x, int L) {
	if (!x) return L;
	else if (x == 1) return 1;
	else if (x == 2) return 2;
	else if (x == 4) return 3;
	else if (x == 8) return 4;
	else if (x == 16) return 5;
	else if (x == 32) return 6;
	else if (x == 64) return 7;
	else return 8;
}
struct Node {
	int nt, x, c, vol;
};
int n;
Node dat[N];
inline void init_all(char *str) {
	int len = strlen(str + 1);
	int O = 4;
	int L = 3;
	int V = 100;
	n = 0;
	for (int i = 1; i <= len; i++) {
		char ch = str[i];
		if (ch >= 'A' && ch <= 'G') {
			int f = 0;
			if (i < len && str[i + 1] == '+') f = 1, i++;
			else if (i < len && str[i + 1] == '-') f = -1, i++;
			int nt = get_note(O, ch, f);
			int x = get_len(get_num(str, len, i), L);
			int c = get_dot(str, len, i);
			dat[++n] = (Node){nt, x, c, V};
		} else if (ch == 'R') {
			int x = get_len(get_num(str, len, i), L);
			int c = get_dot(str, len, i);
			x = (1 << (8 - x));
			int t = x;
			while (c--) {t >>= 1; x += t;}
			if (n && !dat[n].nt) dat[n].x += x;
			else dat[++n] = (Node){0, x, 0, 0};
		} else if (ch == 'O') {
			O = str[++i] - '0';
		} else if (ch == '<') {
			O--;
		} else if (ch == '>') {
			O++;
		} else if (ch == 'L') {
			L = get_len(get_num(str, len, i), L);
		} else if (ch == 'V') {
			V = get_num(str, len, i);
		} else assert(false);
	}
}
char str[N];
int dp_oct[N][9], dp_L[N][9];
int fr_oct[N][9], fr_L[N][9];
const int Len_note[12] = {1, 2, 1, 2, 1, 1, 2, 1, 2, 1, 2, 1};
const int Len_dura[9] = {0, 1, 1, 1, 1, 2, 2, 2, 3};
int dp_r[512][9][9], dp_r2[1024][9][9], fr_r2[1024][9][9];
pair<int, int> fr_r[512][9][9];
pair<int, int> rests[40];
void init_r() {
	int crests = 0;
	for (int i = 1; i <= 8; i++)
		for (int j = i; j <= 8; j++)
			rests[++crests] = {i, j};
	memset(dp_r, 0x3f, sizeof(dp_r));
	for (int j0 = 1; j0 <= 8; j0++) for (int j1 = 1; j1 <= 8; j1++) dp_r[0][j0][j1] = (j0 != j1 ? 1 + Len_dura[j1] : 0);
	for (int i = 1; i < 512; i++) {
		for (int j0 = 1; j0 <= 8; j0++) {
			for (int j1 = 1; j1 <= 8; j1++) {
				for (int k = 1; k <= 36; k++) {
					int l = rests[k].first, r = rests[k].second, len = (1 << (9 - l)) - (1 << (8 - r));
					if (i - len >= 0) {
						for (int j2 = 1; j2 <= 8; j2++) {
							int cur = dp_r[i - len][j0][j2] + (j1 != j2 ? 1 + Len_dura[j1] : 0) + (l != j1 ? Len_dura[l] : 0) + 1 + r - l;
							if (dp_r[i][j0][j1] > cur) {
								dp_r[i][j0][j1] = cur;
								fr_r[i][j0][j1] = {k, j2};
							}
						}
					}
				}
			}
		}
	}
	memset(dp_r2, 0x3f, sizeof(dp_r2));
	for (int i = 0; i < 1024; i++) {
		for (int j0 = 1; j0 <= 8; j0++) {
			for (int j1 = 1; j1 <= 8; j1++) {
				for (int k = max(0, i - 511); k <= i && k < 512; k++) {
					int cur = dp_r[k][j0][1] + dp_r[i - k][1][j1];
					if (dp_r2[i][j0][j1] > cur) {
						dp_r2[i][j0][j1] = cur;
						fr_r2[i][j0][j1] = k;
					}
				}
			}
		}
	}
}
void print_dp_r(int i, int j0, int j1) {
	if (!i) {
		if (j0 != j1) printf("L%d", 1 << (j1 - 1));
		return;
	}
	int k = fr_r[i][j0][j1].first;
	int j2 = fr_r[i][j0][j1].second;
	int l = rests[k].first, r = rests[k].second, len = (1 << (9 - l)) - (1 << (8 - r));
	print_dp_r(i - len, j0, j2);
	if (j1 != j2) printf("L%d", 1 << (j1 - 1));
	printf("R");
	if (l != j1) printf("%d", 1 << (l - 1));
	int cnt = r - l;
	while (cnt--)
		printf(".");
}
int calc_r(int l, int j0, int j1) {
	int c1 = 0, tl = l;
	while (l >= 1024) {
		c1++;
		l -= 128;
	}
	int res = INF;
	res = min(res, dp_r2[l][j0][j1] + c1);
	while (l >= 128) {
		c1++;
		l -= 128;
		res = min(res, dp_r2[l][j0][j1] + c1);
	}
	c1 = 0;
	l = tl;
	while (l >= 512) {
		c1 += 2;
		l -= 128;
	}
	res = min(res, dp_r[l][j0][j1] + c1);
	while (l >= 128) {
		c1 += 2;
		l -= 128;
		res = min(res, dp_r[l][j0][j1] + c1);
	}
	return res;
}
void print_r(int l, int j0, int j1) {
	int c1 = 0, tl = l, a1 = 0, al = 0;
	while (l >= 1024) {
		c1++;
		l -= 128;
	}
	int res = INF;
	if (res > dp_r2[l][j0][j1] + c1) {
		res = dp_r2[l][j0][j1] + c1;
		a1 = 1;
		al = l;
	}
	while (l >= 128) {
		c1++;
		l -= 128;
		if (res > dp_r2[l][j0][j1] + c1) {
			res = dp_r2[l][j0][j1] + c1;
			a1 = 1;
			al = l;
		}
	}
	c1 = 0;
	l = tl;
	while (l >= 512) {
		c1 += 2;
		l -= 128;
	}
	if (res > dp_r[l][j0][j1] + c1) {
		res = dp_r[l][j0][j1] + c1;
		a1 = 0;
		al = l;
	}
	while (l >= 128) {
		c1 += 2;
		l -= 128;
		if (res > dp_r[l][j0][j1] + c1) {
			res = dp_r[l][j0][j1] + c1;
			a1 = 0;
			al = l;
		}
	}
	if (a1) {
		c1 = (tl - al) / 128;
		int k = fr_r2[al][j0][j1];
		print_dp_r(k, j0, 1);
		while (c1--) printf("R");
		print_dp_r(al - k, 1, j1);
	} else {
		c1 = (tl - al) / 128;
		while (c1--) printf("R1");
		print_dp_r(al, j0, j1);
	}
}
int ans_oct[N], ans_L[N];
const char van[14][5] = {"C-", "C", "C+", "D", "D+", "E", "F", "F+", "G", "G+", "A", "A+", "B", "B+"};
int main() {
	int Case = 0;
	init_r();
	while (scanf(" %s", str + 1) == 1 && str[1] != '*') {
		Case++;
		init_all(str);
		for (int i = 0; i <= n; i++)
			for (int j = 1; j <= 8; j++)
				dp_oct[i][j] = dp_L[i][j] = INF;
		dp_oct[0][4] = dp_L[0][3] = 0;
		for (int i = 1; i <= n; i++) {
			if (dat[i].nt) {
				vector<pair<int, int> > vec;
				vec.push_back({(dat[i].nt - 1) / 12 + 1, Len_note[(dat[i].nt - 1) % 12]});
				if (dat[i].nt % 12 == 1 && dat[i].nt != 1) {
					vec.push_back({(dat[i].nt - 1) / 12, 2});
				} else if (dat[i].nt % 12 == 0 && dat[i].nt != 96) {
					vec.push_back({dat[i].nt / 12 + 1, 2});
				}
				for (pair<int, int> P : vec) {
					int j = P.first, cst = P.second;
					for (int k = 1; k <= 8; k++) if (dp_oct[i - 1][k] < INF) {
						int cur = dp_oct[i - 1][k] + min(2, abs(j - k)) + cst;
						if (dp_oct[i][j] > cur) {
							dp_oct[i][j] = cur;
							fr_oct[i][j] = k;
						}
					}
				}
				for (int j = 1; j <= 8; j++) {
					for (int k = 1; k <= 8; k++) if (dp_L[i - 1][k] < INF) {
						int cur = dp_L[i - 1][k] + (j != k ? Len_dura[j] + 1 : 0) + (dat[i].x != j ? Len_dura[dat[i].x] : 0) + dat[i].c;
						if (dp_L[i][j] > cur) {
							dp_L[i][j] = cur;
							fr_L[i][j] = k;
						}
					}
				}
			} else {
				for (int j = 1; j <= 8; j++)
					dp_oct[i][j] = dp_oct[i - 1][j], fr_oct[i][j] = j;
				for (int k = 1; k <= 8; k++) if (dp_L[i - 1][k] < INF) {
					for (int j = 1; j <= 8; j++) {
						int cur = dp_L[i - 1][k] + calc_r(dat[i].x, k, j);
						if (dp_L[i][j] > cur) {
							dp_L[i][j] = cur;
							fr_L[i][j] = k;
						}
					}
				}
			}
		}
		int x1 = 1, x2 = 1;
		for (int i = 2; i <= 8; i++) {
			if (dp_oct[n][i] < dp_oct[n][x1])
				x1 = i;
			if (dp_L[n][i] < dp_L[n][x2])
				x2 = i;
		}
		printf("Case %d: ", Case);
		for (int i = n; i >= 1; i--) {
			ans_oct[i] = x1;
			ans_L[i] = x2;
			x1 = fr_oct[i][x1];
			x2 = fr_L[i][x2];
		}
		int V = 100, O = 4, L = 3;
		for (int i = 1; i <= n; i++) {
			if (dat[i].nt) {
				if (dat[i].vol != V) {
					V = dat[i].vol;
					printf("V%d", V);
				}
				if (ans_L[i] != L) {
					L = ans_L[i];
					printf("L%d", 1 << (L - 1));
				}
				if (ans_oct[i] != O) {
					if (abs(ans_oct[i] - O) > 1)
						printf("O%d", ans_oct[i]);
					else if (ans_oct[i] < O)
						printf("<");
					else
						printf(">");
					O = ans_oct[i];
				}
				printf("%s", van[dat[i].nt - (O - 1) * 12]);
				if (dat[i].x != L)
					printf("%d", 1 << (dat[i].x - 1));
				while (dat[i].c--)
					printf(".");
			} else {
				print_r(dat[i].x, ans_L[i - 1], ans_L[i]);
				L = ans_L[i];
			}
		}
		printf("\n");
	}
	return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 6984
final_rank: 1