Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. 

Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the note to one of his neighbours in the row. In other words, if this spy's number is x, he can pass the note to another spy, either x - 1 or x + 1 (if x = 1 or x = n, then the spy has only one neighbour). Also during a step the spy can keep a note and not pass it to anyone.

But nothing is that easy. During m steps Xenia watches some spies attentively. Specifically, during step t_{i} (steps are numbered from 1) Xenia watches spies numbers l_{i}, l_{i} + 1, l_{i} + 2, ..., r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n). Of course, if during some step a spy is watched, he can't do anything: neither give the note nor take it from some other spy. Otherwise, Xenia reveals the spies' cunning plot. Nevertheless, if the spy at the current step keeps the note, Xenia sees nothing suspicious even if she watches him.

You've got s and f. Also, you have the steps during which Xenia watches spies and which spies she is going to watch during each step. Find the best way the spies should act in order to pass the note from spy s to spy f as quickly as possible (in the minimum number of steps).


-----Input-----

The first line contains four integers n, m, s and f (1 ≤ n, m ≤ 10^5; 1 ≤ s, f ≤ n; s ≠ f; n ≥ 2). Each of the following m lines contains three integers t_{i}, l_{i}, r_{i} (1 ≤ t_{i} ≤ 10^9, 1 ≤ l_{i} ≤ r_{i} ≤ n). It is guaranteed that t_1 < t_2 < t_3 < ... < t_{m}.


-----Output-----

Print k characters in a line: the i-th character in the line must represent the spies' actions on step i. If on step i the spy with the note must pass the note to the spy with a lesser number, the i-th character should equal "L". If on step i the spy with the note must pass it to the spy with a larger number, the i-th character must equal "R". If the spy must keep the note at the i-th step, the i-th character must equal "X".

As a result of applying the printed sequence of actions spy s must pass the note to spy f. The number of printed characters k must be as small as possible. Xenia must not catch the spies passing the note.

If there are miltiple optimal solutions, you can print any of them. It is guaranteed that the answer exists.


-----Examples-----
Input
3 5 1 3
1 1 2
2 2 3
3 3 3
4 1 1
10 1 3

Output
XXRR

Difficulty: MEDIUM
Tags: Complete search

Implementation

Greedy algorithms
Skill types: Complete search

Greedy algorithms

Starter code:

Solutions:
import sys
(n, m, s, f) = list(map(int, sys.stdin.readline().split()))
L = []
R = []
T = []
for i in range(m):
	(t, l, r) = list(map(int, sys.stdin.readline().split()))
	T.append(t)
	L.append(l)
	R.append(r)
if f > s:
	i = s
	step = 1
	ind = 0
	Ans = ''
	while i != f:
		if ind >= m or T[ind] != step:
			Ans += 'R'
			i += 1
		else:
			if i >= L[ind] and i <= R[ind] or (i + 1 >= L[ind] and i + 1 <= R[ind]):
				Ans += 'X'
			else:
				Ans += 'R'
				i += 1
			ind += 1
		step += 1
else:
	i = s
	step = 1
	ind = 0
	Ans = ''
	while i != f:
		if ind >= m or T[ind] != step:
			Ans += 'L'
			i -= 1
		else:
			if i >= L[ind] and i <= R[ind] or (i - 1 >= L[ind] and i - 1 <= R[ind]):
				Ans += 'X'
			else:
				Ans += 'L'
				i -= 1
			ind += 1
		step += 1
sys.stdout.write(Ans + '\n')


(n, m, s, f) = map(int, input().split())
(ans, p) = ('', 1)
if s < f:
	for i in range(m):
		(t, l, r) = map(int, input().split())
		if t > p:
			if t - p < f - s:
				ans += 'R' * (t - p)
				s += t - p
			else:
				ans += 'R' * (f - s)
				s = f
				break
		p = t + 1
		if s + 1 < l or s > r:
			ans += 'R'
			s += 1
			if s == f:
				break
		else:
			ans += 'X'
else:
	for i in range(m):
		(t, l, r) = map(int, input().split())
		if t > p:
			if t - p < s - f:
				ans += 'L' * (t - p)
				s -= t - p
			else:
				ans += 'L' * (s - f)
				s = f
				break
		p = t + 1
		if s < l or s - 1 > r:
			ans += 'L'
			s -= 1
			if s == f:
				break
		else:
			ans += 'X'
print(ans + ('R' * (f - s) if f > s else 'L' * (s - f)))


import sys
(spies, turns, note, final) = map(int, input().split())
if note < final:
	next = 1
else:
	next = -1
answer = []

def pass_note(current_turn, next_watch, left, right, note):
	if current_turn == next_watch:
		if note in range(left, right + 1) or note + next in range(left, right + 1):
			return (note, 'X')
	if note < final:
		note += next
		return (note, 'R')
	else:
		note += next
		return (note, 'L')
current_turn = 0
for turn in range(turns):
	(next_watch, left, right) = map(int, input().split())
	while current_turn < next_watch:
		current_turn += 1
		(note, ans) = pass_note(current_turn, next_watch, left, right, note)
		answer.append(ans)
		if note == final:
			print(''.join(answer))
			sys.exit()
while note != final:
	current_turn += 1
	(note, ans) = pass_note(current_turn, 0, -1, -1, note)
	answer.append(ans)
print(''.join(answer))


def geto(a, b):
	return max(0, min(a[1], b[1]) - max(a[0], b[0]) + 1)
(n, m, s, f) = map(int, input().split())
di = {}
for _ in range(m):
	(t, l, r) = map(int, input().split())
	di[t] = [l, r]
t = 1
ans = []
while s != f:
	if f > s:
		inte = [s, s + 1]
		if t in di and geto(inte, di[t]):
			ans += ['X']
		else:
			ans += ['R']
			s += 1
	else:
		inte = [s - 1, s]
		if t in di and geto(inte, di[t]):
			ans += ['X']
		else:
			ans += ['L']
			s -= 1
	t += 1
print(''.join(ans))


(n, m, s, f) = map(int, input().split())
q = dict()
for i in range(m):
	(t, l, r) = map(int, input().split())
	q[t] = (l, r)
k = 1
pos = s
while pos != f:
	if k in q:
		if q[k][0] <= pos <= q[k][1]:
			print('X', end='')
		elif 1 < pos < n:
			if pos > f:
				if q[k][0] <= pos - 1 <= q[k][1]:
					print('X', end='')
				else:
					print('L', end='')
					pos -= 1
			elif q[k][0] <= pos + 1 <= q[k][1]:
				print('X', end='')
			else:
				print('R', end='')
				pos += 1
		elif pos == 1:
			if q[k][0] <= 2 <= q[k][1]:
				print('X', end='')
			else:
				print('R', end='')
				pos = 2
		elif pos == n:
			if q[k][0] <= pos - 1 <= q[k][1]:
				print('X', end='')
			else:
				print('L', end='')
				pos -= 1
	elif pos > f:
		print('L', end='')
		pos -= 1
	else:
		print('R', end='')
		pos += 1
	k += 1


def checkKey(dict, key):
	if key in dict:
		return True
	return False
(n, m, s, f) = map(int, input().split())
d = {}
for i__ in range(m):
	(t, l, r) = map(int, input().split())
	d[t] = (l, r)
if f > s:
	ans = ''
	cp = s
	time = 1
	while cp != f:
		if time in d:
			start = d[time][0]
			end = d[time][1]
			if cp >= start and cp <= end or (cp + 1 >= start and cp + 1 <= end):
				ans += 'X'
				time += 1
			else:
				ans += 'R'
				time += 1
				cp += 1
		else:
			ans += 'R'
			time += 1
			cp += 1
	print(ans)
elif f < s:
	ans = ''
	cp = s
	time = 1
	while cp != f:
		if time in d:
			start = d[time][0]
			end = d[time][1]
			if cp >= start and cp <= end or (cp - 1 >= start and cp - 1 <= end):
				ans += 'X'
				time += +1
			else:
				ans += 'L'
				time += 1
				cp -= 1
		else:
			ans += 'L'
			time += 1
			cp -= 1
	print(ans)


(n, m, s, f) = list(map(int, input().split()))
d = {}
for i in range(m):
	(t, l, r) = list(map(int, input().split()))
	d[t] = [l, r]
ans = ''
for i in range(1, n + m):
	if s == f:
		print(ans)
		return
	t = -1
	if f < s:
		t = s - 1
	else:
		t = s + 1
	if i in d:
		if d[i][0] <= s and s <= d[i][1] or (d[i][0] <= t and t <= d[i][1]):
			t = -1
	if t == -1:
		ans += 'X'
	else:
		if f < s:
			ans += 'L'
		else:
			ans += 'R'
		s = t
print(ans)


(n, m, s, f) = list(map(int, input().split()))
t = {}
step = 1
ans = ''
if s < f:
	sig = 'R'
else:
	sig = 'L'
for i in range(m):
	(t0, l0, r0) = list(map(int, input().split()))
	t[t0] = [l0, r0]
for i in range(1, n + m + 1):
	if s < f:
		u = s + 1
	else:
		u = s - 1
	if i in t:
		if t[i][0] <= s <= t[i][1] or t[i][0] <= u <= t[i][1]:
			ans += 'X'
		else:
			ans += sig
			s = u
	else:
		ans += sig
		s = u
	if s == f:
		break
print(ans)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as c
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def outln(var):
	sys.stdout.write(str(var) + '\n')

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
(n, m, s, f) = sp()
answer = []
last = 0
for _ in range(m):
	(ti, li, ri) = sp()
	diff = ti - last - 1
	if f < s:
		while f < s and diff:
			s -= 1
			diff -= 1
			answer.append('L')
	else:
		while f > s and diff:
			s += 1
			answer.append('R')
			diff -= 1
	if f < s:
		if li <= s <= ri or li <= s - 1 <= ri:
			answer.append('X')
		else:
			answer.append('L')
			s -= 1
	elif f > s:
		if li <= s <= ri or li <= s + 1 <= ri:
			answer.append('X')
		else:
			answer.append('R')
			s += 1
	else:
		break
	last = ti
if f > s:
	for i in range(f - s):
		answer.append('R')
elif f < s:
	for i in range(s - f):
		answer.append('L')
outln(''.join(answer))


(n, m, s, f) = map(int, input().split())
if s < f:
	step = 'R'
	step_i = 1
else:
	step = 'L'
	step_i = -1
ans = []
tp = 0
for i in range(m):
	(t, l, r) = map(int, input().split())
	k = min(t - tp - 1, abs(f - s))
	for j in range(k):
		ans.append(step)
	s += step_i * k
	if s == f:
		print(''.join(ans))
		break
	if not l <= s + step_i <= r and (not l <= s <= r):
		s += step_i
		ans.append(step)
	else:
		ans.append('X')
	tp = t
else:
	if s != f:
		ans.extend([step] * abs(f - s))
	print(''.join(ans))


import sys
from itertools import *
from math import *

def solve():
	(n, m, s, f) = map(int, input().split())
	s -= 1
	f -= 1
	d = {}
	for _ in range(m):
		(t, l, r) = map(int, input().split())
		d[t - 1] = (l - 1, r - 1)
	step = 0
	res = ''
	while s != f:
		wantnext = s + 1 if s < f else s - 1
		canmove = True
		if step in d:
			(l, r) = d[step]
			if s >= l and s <= r or (wantnext >= l and wantnext <= r):
				canmove = False
		if canmove:
			res += 'R' if wantnext > s else 'L'
			s = wantnext
		else:
			res += 'X'
		step += 1
	print(res)
if sys.hexversion == 50594544:
	sys.stdin = open('test.txt')
solve()


def __starting_point():
	inp = input()
	arr = inp.split(' ')
	n = int(arr[0])
	m = int(arr[1])
	s = int(arr[2])
	f = int(arr[3])
	ans = ''
	ch = 'L'
	inc = -1
	if s < f:
		ch = 'R'
		inc = 1
	tm = 1
	done = False
	for i in range(m):
		inp = input()
		if done:
			continue
		arr = inp.split(' ')
		ct = int(arr[0])
		l = int(arr[1])
		r = int(arr[2])
		while ct != tm:
			ans += ch
			tm += 1
			s += inc
			if s == f:
				break
		if s != f and (s + inc >= l and s + inc <= r or (s >= l and s <= r)):
			ans += 'X'
		elif s != f:
			ans += ch
			s += inc
		tm += 1
		if s == f:
			done = True
	while s != f:
		s += inc
		ans += ch
	print(ans)
__starting_point()


(n, m, s, f) = map(int, input().split())
p = s
d = -1
c = 'L'
if s < f:
	d = 1
	c = 'R'
t = 1
ts = {}
ans = ''
for _ in range(m):
	(x, y, z) = map(int, input().split())
	ts[x] = (y, z)
while p != f:
	if t in ts:
		(l, r) = ts[t]
		if l <= p <= r or l <= p + d <= r:
			ans += 'X'
		else:
			p += d
			ans += c
	else:
		p += d
		ans += c
	t += 1
print(ans)


def mi():
	return map(int, input().split())
(n, m, s, f) = mi()
t = [0] * m
l = [0] * m
r = [0] * m
for i in range(m):
	(t[i], l[i], r[i]) = mi()
curp = s
curt = 1
i = 0
a = ''
if f > s:
	a = (f - s) * 'R'
else:
	a = (s - f) * 'L'
while i < m and curp != f:
	if t[i] == curt:
		if a[0] == 'R' and curp + 1 >= l[i] and (curp + 1 <= r[i]):
			print('X', end='')
		elif a[0] == 'L' and curp - 1 >= l[i] and (curp - 1 <= r[i]):
			print('X', end='')
		elif curp >= l[i] and curp <= r[i]:
			print('X', end='')
		elif a[0] == 'R':
			curp += 1
			print(a[0], end='')
		else:
			curp -= 1
			print(a[0], end='')
		i += 1
	elif a[0] == 'R':
		curp += 1
		print(a[0], end='')
	else:
		curp -= 1
		print(a[0], end='')
	curt += 1
if f > curp:
	print((f - curp) * 'R')
elif curp > f:
	print((curp - f) * 'L')


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz/'
M = 998244353
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
(n, m, s, d) = value()
move = 1
if d < s:
	move = 0
last = 0
cur = s
ans = []
given = []
for i in range(m):
	given.append(value())
for (t, l, r) in given:
	if t - 1 != last:
		have = t - last - 1
		need = abs(d - cur)
		if move:
			ans.extend(['R' for i in range(min(need, have))])
			cur += min(need, have)
		else:
			ans.extend(['L' for i in range(min(need, have))])
			cur -= min(need, have)
	if cur == d:
		break
	if move:
		if cur + 1 < l or cur > r:
			ans.append('R')
			cur += 1
		else:
			ans.append('X')
	elif cur < l or cur - 1 > r:
		ans.append('L')
		cur -= 1
	else:
		ans.append('X')
	last = t
if cur != d:
	need = abs(d - cur)
	have = inf
	if move:
		ans.extend(['R' for i in range(min(need, have))])
	else:
		ans.extend(['L' for i in range(min(need, have))])
print(*ans, sep='')


def solve(s, f, t):
	res = ''
	step = 1 if s < f else -1
	i = current = 0
	while s != f:
		current += 1
		(ti, l, r) = t[i] if i < len(t) else (-1, -1, -1)
		if ti == current:
			i += 1
			if l <= s <= r or l <= s + step <= r:
				res += 'X'
				continue
		s += step
		res += 'R' if step > 0 else 'L'
	return res

def __starting_point():
	parse = lambda : list(map(int, input().split()))
	(n, m, s, f) = parse()
	l = [parse() for _ in range(m)]
	print(solve(s, f, l))
__starting_point()


R = lambda : list(map(int, input().split()))
(n, m, s, f) = R()
if s < f:
	d = 1
	c = 'R'
else:
	d = -1
	c = 'L'
res = ''
i = 1
j = s
(t, l, r) = R()
k = 1
while j != f:
	if i > t and k < m:
		(t, l, r) = R()
		k += 1
	if i == t and (l <= j <= r or l <= j + d <= r):
		res += 'X'
	else:
		res += c
		j += d
	i += 1
print(res)


(n, m, s, f) = map(int, input().split())
(c, t1) = (1, 0)
ans = ''
t = 1
while s != f and t1 < m:
	(t, l, r) = map(int, input().split())
	while t != c:
		if s < f:
			ans += 'R'
			s += 1
		else:
			ans += 'L'
			s -= 1
		if s == f:
			break
		c += 1
	if s < f:
		if s >= l - 1 and s <= r:
			ans += 'X'
		else:
			ans += 'R'
			s += 1
	elif s > f:
		if s <= r + 1 and s >= l:
			ans += 'X'
		else:
			ans += 'L'
			s -= 1
	c += 1
	t1 += 1
if s < f:
	ans += 'R' * (f - s)
elif s > f:
	ans += 'L' * (s - f)
print(ans)


(n, m, s, f) = map(int, input().split())
l = []
for i in range(m):
	k = list(map(int, input().split()))
	l.append(k)
count = 1
ans = ''
i = 0
while i < m:
	if count < l[i][0]:
		if f > s:
			ans += 'R' * min(l[i][0] - count, f - s)
			s += min(l[i][0] - count, f - s)
			count = l[i][0]
		if f < s:
			ans += 'L' * min(l[i][0] - count, s - f)
			s -= min(l[i][0] - count, s - f)
			count = l[i][0]
	else:
		if l[i][1] <= s <= l[i][2]:
			ans += 'X'
		else:
			if f > s:
				if l[i][1] <= s + 1 <= l[i][2]:
					ans += 'X'
				else:
					ans += 'R'
					s += 1
			if f < s:
				if l[i][1] <= s - 1 <= l[i][2]:
					ans += 'X'
				else:
					ans += 'L'
					s -= 1
		i += 1
		count += 1
	if s == f:
		break
if s != f:
	if s < f:
		ans += 'R' * (f - s)
	else:
		ans += 'L' * (s - f)
print(ans)


(n, m, s, f) = map(int, input().split())
d = {}
final = 0
for i in range(m):
	a = list(map(int, input().split()))
	d[a[0]] = [a[1], a[2]]
	final = a[0]
z = ''
if s < f:
	i = 0
	while s != f:
		i += 1
		if i not in d:
			s += 1
			z += 'R'
		elif s not in range(d[i][0], d[i][1] + 1) and s + 1 not in range(d[i][0], d[i][1] + 1):
			s += 1
			z += 'R'
		else:
			z += 'X'
		if s == f:
			break
else:
	i = 0
	while s != f:
		i += 1
		if i not in d:
			s -= 1
			z += 'L'
		elif s not in range(d[i][0], d[i][1] + 1) and s - 1 not in range(d[i][0], d[i][1] + 1):
			s -= 1
			z += 'L'
		else:
			z += 'X'
		if s == f:
			break
print(z)


(n, m, s, f) = [int(x) for x in input().split()]
now = 1
d = 1 if f > s else -1
step = 'R' if d == 1 else 'L'
ret = ''
for _ in range(m):
	(t, l, r) = [int(x) for x in input().split()]
	if t > now:
		flag = False
		while t > now:
			s += d
			ret += step
			now += 1
			if s == f:
				flag = True
				break
		if flag:
			break
	if l <= s <= r or l <= s + d <= r:
		ret += 'X'
	else:
		ret += step
		s += d
	if s == f:
		break
	now += 1
while s != f:
	s += d
	ret += step
print(ret)


def checkKey(dict, key):
	if key in dict:
		return True
	return False
(n, m, s, f) = map(int, input().split())
p = s
d = -1
c = 'L'
if s < f:
	d = 1
	c = 'R'
t = 1
ts = {}
ans = ''
for _ in range(m):
	(x, y, z) = map(int, input().split())
	ts[x] = (y, z)
while p != f:
	if t in ts:
		(l, r) = ts[t]
		if l <= p <= r or l <= p + d <= r:
			ans += 'X'
		else:
			p += d
			ans += c
	else:
		p += d
		ans += c
	t += 1
print(ans)


while True:
	try:

		def soln(n, m, s, t, stp):
			stp.sort()
			flg = True
			if s > t:
				flg = False
			i = 1
			j = 0
			ans = []
			while True:
				fund = False
				while j < m:
					if stp[j][0] == i:
						j += 1
						fund = True
					break
				if fund and (not flg):
					a = max(stp[j - 1][1], stp[j - 1][2])
					b = min(stp[j - 1][1], stp[j - 1][2])
					if s <= a and s >= b:
						ans.append('X')
					elif s - 1 <= a and s - 1 >= b:
						ans.append('X')
					else:
						ans.append('L')
						s -= 1
				elif fund and flg:
					a = min(stp[j - 1][1], stp[j - 1][2])
					b = max(stp[j - 1][1], stp[j - 1][2])
					if s >= a and s <= b:
						ans.append('X')
					elif s + 1 >= a and s + 1 <= b:
						ans.append('X')
					else:
						ans.append('R')
						s += 1
				elif flg:
					ans.append('R')
					s += 1
				else:
					ans.append('L')
					s -= 1
				if s == t:
					break
				i += 1
			print(''.join(ans))

		def read():
			(n, m, s, t) = map(int, input().split())
			stp = []
			for i in range(m):
				(a, b, c) = map(int, input().split())
				stp.append([a, b, c])
			soln(n, m, s, t, stp)
		if __name__ == '__main__':
			read()
	except EOFError:
		break


(n, m, s, f) = map(int, input().split())
l = []
for i in range(m):
	(t, c, r) = map(int, input().split())
	l.append([t, c, r])
if s > f:
	st = ''
	t = 1
	i = 0
	while i < m:
		if t == l[i][0]:
			if (s < l[i][1] or s > l[i][2]) and (s - 1 < l[i][1] or s - 1 > l[i][2]):
				s -= 1
				st += 'L'
			else:
				st += 'X'
			i += 1
			if s == f:
				break
		else:
			st += 'L'
			s -= 1
			if s == f:
				break
		t += 1
	while s > f:
		s -= 1
		st += 'L'
	print(st)
if s < f:
	st = ''
	t = 1
	i = 0
	while i < m:
		if t == l[i][0]:
			if (s < l[i][1] or s > l[i][2]) and (s + 1 < l[i][1] or s + 1 > l[i][2]):
				s += 1
				st += 'R'
			else:
				st += 'X'
			i += 1
			if s == f:
				break
		else:
			st += 'R'
			s += 1
			if s == f:
				break
		t += 1
	while s < f:
		s += 1
		st += 'R'
	print(st)


(n, m, s, f) = map(int, input().split())
watch = {}
for i in range(m):
	(t, l, r) = map(int, input().split())
	watch[t] = (l, r)
cur = s
(move, symbol) = (1, 'R') if s < f else (-1, 'L')
step = 1
while cur != f:
	if step in watch:
		(l, r) = watch[step]
		if l <= cur <= r or l <= cur + move <= r:
			print('X', end='')
		else:
			cur += move
			print(symbol, end='')
	else:
		cur += move
		print(symbol, end='')
	step += 1


(n, m, s, f) = map(int, input().split())
t = dict()
for i in range(m):
	(t1, l1, r1) = map(int, input().split())
	t[t1] = (l1, r1)
pos = s
i = 1
while 1:
	if pos == f:
		break
	if i in t:
		if t[i][0] <= pos <= t[i][1]:
			print('X', end='')
			i += 1
			continue
		elif f - pos > 0 and t[i][0] <= pos + 1 <= t[i][1]:
			print('X', end='')
			i += 1
			continue
		elif f - pos < 0 and t[i][0] <= pos - 1 <= t[i][1]:
			print('X', end='')
			i += 1
			continue
	if f - pos > 0:
		print('R', end='')
		pos += 1
	elif pos - f > 0:
		print('L', end='')
		pos -= 1
	i += 1


(n, m, s, f) = list(map(int, input().split()))
if s > f:
	a = 'L'
	c = -1
elif s == f:
	a = 'X'
	c = 0
else:
	a = 'R'
	c = 1
l = []
for i in range(m):
	l.append(list(map(int, input().split())))
ans = ''
if l[0][0] != 1:
	d = l[0][0] - 1
	while s != f and d > 0:
		s = s + c
		ans = ans + a
		d = d - 1
for i in range(m):
	if s == f:
		break
	if i == 0:
		if s >= l[i][1] and s <= l[i][2] or (s + c >= l[i][1] and s + c <= l[i][2]):
			ans = ans + 'X'
		else:
			ans = ans + a
			s = s + c
	elif l[i][0] - l[i - 1][0] == 1:
		if s >= l[i][1] and s <= l[i][2] or (s + c >= l[i][1] and s + c <= l[i][2]):
			ans = ans + 'X'
		else:
			ans = ans + a
			s = s + c
	else:
		d = l[i][0] - l[i - 1][0] - 1
		while s != f and d > 0:
			s = s + c
			ans = ans + a
			d = d - 1
		if s == f:
			break
		if s >= l[i][1] and s <= l[i][2] or (s + c >= l[i][1] and s + c <= l[i][2]):
			ans = ans + 'X'
		else:
			ans = ans + a
			s = s + c
	if s == f:
		break
if s != f:
	while s != f:
		ans = ans + a
		s = s + c
print(ans)


import sys
input = sys.stdin.readline

def print(val):
	sys.stdout.write(str(val) + '\n')

def prog():
	(n, m, s, f) = map(int, input().split())
	curr = s
	step = 1
	steps = {}
	output = []
	for i in range(m):
		(t, l, r) = map(int, input().split())
		steps[t] = [l, r]
	if f > s:
		while curr != f:
			if step not in steps:
				output.append('R')
				step += 1
				curr += 1
			elif curr + 1 < steps[step][0] or curr > steps[step][1]:
				output.append('R')
				step += 1
				curr += 1
			else:
				output.append('X')
				step += 1
	else:
		while curr != f:
			if step not in steps:
				output.append('L')
				step += 1
				curr -= 1
			elif curr - 1 > steps[step][1] or curr < steps[step][0]:
				output.append('L')
				step += 1
				curr -= 1
			else:
				output.append('X')
				step += 1
	print(''.join(output))
prog()


(n, m, s, f) = map(int, input().split())
data = {}
for _ in range(m):
	(t, l, r) = map(int, input().split())
	data[t] = (l, r)
k = 1
curr = s
while curr != f:
	if k in data:
		if data[k][0] <= curr <= data[k][1]:
			print('X', end='')
		elif 1 < curr < n:
			if curr > f:
				if data[k][0] <= curr - 1 <= data[k][1]:
					print('X', end='')
				else:
					print('L', end='')
					curr -= 1
			elif data[k][0] <= curr + 1 <= data[k][1]:
				print('X', end='')
			else:
				print('R', end='')
				curr += 1
		elif curr == 1:
			if data[k][0] <= 2 <= data[k][1]:
				print('X', end='')
			else:
				print('R', end='')
				curr = 2
		elif curr == n:
			if data[k][0] <= curr - 1 <= data[k][1]:
				print('X', end='')
			else:
				print('L', end='')
				curr -= 1
	elif curr > f:
		print('L', end='')
		curr -= 1
	else:
		print('R', end='')
		curr += 1
	k += 1