#include <string>
#include <vector>
#include <cmath>
using namespace std;
int calc_dist(pair<int,int> a, pair<int,int> b, pair<int,int> l)
{
int a_d = abs(a.first-l.first) + abs(a.second-l.second);
int b_d = abs(b.first-l.first) + abs(b.second-l.second);
if(a_d < b_d) return 1;
if(a_d > b_d) return 2;
return 3;
}
string solution(vector<int> numbers, string hand) {
string answer = "";
int ch;
pair<int,int> left = {3,0};
pair<int,int> right = {3,2};
for(int i=0;i<numbers.size();i++)
{
ch=numbers[i];
if(ch == 1 || ch == 4 || ch == 7)
{
switch(ch)
{
case 1: left = {0,0}; break;
case 4: left = {1,0}; break;
case 7: left = {2,0}; break;
default : break;
}
answer += 'L';
}else if(ch == 3 || ch == 6 || ch == 9)
{
switch(ch)
{
case 3: right = {0,2}; break;
case 6: right = {1,2}; break;
case 9: right = {2,2}; break;
default : break;
}
answer += 'R';
}else{
pair<int,int> l;
switch(ch)
{
case 2: l = {0,1}; break;
case 5: l = {1,1}; break;
case 8: l = {2,1}; break;
case 0: l = {3,1}; break;
default : break;
}
int result = calc_dist(left,right,l);
if(result == 1){
answer += 'L';
left = l;
}else if(result == 2)
{
answer += 'R';
right = l;
}else{
if(hand == "left"){
answer += 'L';
left = l;
}else{
answer += 'R';
right = l;
}
}
}
}
return answer;
}