There was an epidemic in Monstropolis and all monsters became sick. To recover, all monsters lined up in queue for an appointment to the only doctor in the city.

Soon, monsters became hungry and began to eat each other. 

One monster can eat other monster if its weight is strictly greater than the weight of the monster being eaten, and they stand in the queue next to each other. Monsters eat each other instantly. There are no monsters which are being eaten at the same moment. After the monster A eats the monster B, the weight of the monster A increases by the weight of the eaten monster B. In result of such eating the length of the queue decreases by one, all monsters after the eaten one step forward so that there is no empty places in the queue again. A monster can eat several monsters one after another. Initially there were n monsters in the queue, the i-th of which had weight a_{i}.

For example, if weights are [1, 2, 2, 2, 1, 2] (in order of queue, monsters are numbered from 1 to 6 from left to right) then some of the options are:  the first monster can't eat the second monster because a_1 = 1 is not greater than a_2 = 2;  the second monster can't eat the third monster because a_2 = 2 is not greater than a_3 = 2;  the second monster can't eat the fifth monster because they are not neighbors;  the second monster can eat the first monster, the queue will be transformed to [3, 2, 2, 1, 2]. 

After some time, someone said a good joke and all monsters recovered. At that moment there were k (k ≤ n) monsters in the queue, the j-th of which had weight b_{j}. Both sequences (a and b) contain the weights of the monsters in the order from the first to the last.

You are required to provide one of the possible orders of eating monsters which led to the current queue, or to determine that this could not happen. Assume that the doctor didn't make any appointments while monsters were eating each other.


-----Input-----

The first line contains single integer n (1 ≤ n ≤ 500) — the number of monsters in the initial queue.

The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^6) — the initial weights of the monsters.

The third line contains single integer k (1 ≤ k ≤ n) — the number of monsters in the queue after the joke. 

The fourth line contains k integers b_1, b_2, ..., b_{k} (1 ≤ b_{j} ≤ 5·10^8) — the weights of the monsters after the joke. 

Monsters are listed in the order from the beginning of the queue to the end.


-----Output-----

In case if no actions could lead to the final queue, print "NO" (without quotes) in the only line. 

Otherwise print "YES" (without quotes) in the first line. In the next n - k lines print actions in the chronological order. In each line print x — the index number of the monster in the current queue which eats and, separated by space, the symbol 'L' if the monster which stays the x-th in the queue eats the monster in front of him, or 'R' if the monster which stays the x-th in the queue eats the monster behind him. After each eating the queue is enumerated again. 

When one monster eats another the queue decreases. If there are several answers, print any of them.


-----Examples-----
Input
6
1 2 2 2 1 2
2
5 5

Output
YES
2 L
1 R
4 L
3 L

Input
5
1 2 3 4 5
1
15

Output
YES
5 L
4 L
3 L
2 L

Input
5
1 1 1 3 3
3
2 1 6

Output
NO


-----Note-----

In the first example, initially there were n = 6 monsters, their weights are [1, 2, 2, 2, 1, 2] (in order of queue from the first monster to the last monster). The final queue should be [5, 5]. The following sequence of eatings leads to the final queue:  the second monster eats the monster to the left (i.e. the first monster), queue becomes [3, 2, 2, 1, 2];  the first monster (note, it was the second on the previous step) eats the monster to the right (i.e. the second monster), queue becomes [5, 2, 1, 2];  the fourth monster eats the mosnter to the left (i.e. the third monster), queue becomes [5, 2, 3];  the finally, the third monster eats the monster to the left (i.e. the second monster), queue becomes [5, 5]. 

Note that for each step the output contains numbers of the monsters in their current order in the queue.

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Greedy algorithms

Dynamic programming

Amortized analysis

Constructive algorithms


Solutions:
na = int(input())
a = list(map(int, input().split()))
nb = int(input())
b = list(map(int, input().split()))

def judge(na, a, nb, b):
	ans = []
	if sum(a) != sum(b):
		return (False, None)
	cur = 0
	ind = -1
	j = 0
	for (i, x) in enumerate(a):
		cur += x
		if cur < b[j]:
			pass
		elif cur == b[j]:
			begin = ind + 1
			end = i
			interval = a[begin:end + 1]
			if len(interval) > 1 and all((val == a[begin] for val in interval)):
				return (False, None)
			else:
				ans.append(interval)
			ind = i
			cur = 0
			j += 1
		else:
			return (False, None)
		if j >= len(b):
			break
	return (True, ans)

def PrintAns(ans):
	for ii in range(len(ans)):
		num = ans[ii]
		begin = end = 0
		maxn = max(num)
		lenn = len(num)
		for i in range(lenn):
			if num[i] == maxn and (i > 0 and num[i] > num[i - 1] or (i < lenn - 1 and num[i] > num[i + 1])):
				begin = end = i
				break
		while begin > 0 or end < lenn - 1:
			if begin > 0 and num[begin] > num[begin - 1]:
				PrintOne(begin, ii, 'L')
				begin -= 1
				num[begin] += num[begin + 1]
				num[end] = num[begin]
			elif end < len(num) - 1 and num[end] > num[end + 1]:
				PrintOne(begin, ii, 'R')
				end += 1
				num[end] += num[end - 1]
				num[begin] = num[end]

def PrintOne(ind, offset, op):
	print(ind + offset + 1, op)
(ret, ans) = judge(na, a, nb, b)
if ret:
	print('YES')
	PrintAns(ans)
else:
	print('NO')


import sys
a = [0]
b = [0]
ans1 = []
ans2 = []
n = int(input())
s = input()
nums = s.split()
for i in range(0, n):
	a.append(int(nums[i]))
k = int(input())
s = input()
nums = s.split()
for i in range(0, k):
	b.append(int(nums[i]))

def f(x, y, z):
	pos1 = x
	pos2 = x
	if x == y:
		return 1
	for i in range(x, y + 1):
		if a[i] > a[pos1]:
			pos1 = i
		if a[i] >= a[pos2]:
			pos2 = i
	for i in range(x, y):
		if a[i] == a[pos2]:
			if a[i + 1] < a[i]:
				pos2 = i
	for i in range(x + 1, y + 1):
		if a[i] == a[pos1]:
			if a[i - 1] < a[i]:
				pos1 = i
	if pos1 != x or a[pos1] > a[pos1 + 1]:
		for i in range(0, pos1 - x):
			ans1.append(pos1 - x + z - i)
			ans2.append('L')
		for i in range(0, y - pos1):
			ans1.append(z)
			ans2.append('R')
	elif pos2 != y or a[pos2] > a[pos2 - 1]:
		for i in range(0, y - pos2):
			ans1.append(pos2 - x + z)
			ans2.append('R')
		for i in range(0, pos2 - x):
			ans1.append(pos2 - x + z - i)
			ans2.append('L')
	else:
		return 0
	return 1
lasti = 0
j = 1
sum = 0
for i in range(1, n + 1):
	if j > k:
		print('NO')
		sys.exit()
	sum += a[i]
	if sum > b[j]:
		print('NO')
		sys.exit()
	if sum == b[j]:
		if f(lasti + 1, i, j) == 0:
			print('NO')
			sys.exit()
		lasti = i
		j += 1
		sum = 0
if j <= k:
	print('NO')
	sys.exit()
print('YES')
for i in range(0, len(ans1)):
	print(ans1[i], ans2[i])


def main():

	def helper(l, i):
		if len(l) == 2:
			raise TabError
		if l[i] > l[i - 1]:
			res.append('%d L' % (n + i))
			helper([*l[:i - 1], l[i - 1] + l[i], *l[i + 1:]], i - 1)
			del res[-1]
		if l[i] > l[i + 1]:
			res.append('%d R' % (n + i))
			l[i] += l.pop(i + 1)
			helper(l, i)
			del res[-1]
	(inf, res, _) = (10 ** 9, ['YES'], input())
	(aa, _, bb) = ([inf, *map(int, input().split())], input(), list(map(int, input().split())))
	while bb:
		(b, l) = (bb.pop(), [])
		while b > 0:
			a = aa.pop()
			b -= a
			l.append(a)
		if b:
			print('NO')
			return
		(n, m) = (len(aa), max(l))
		l.reverse()
		l.append(inf)
		try:
			for i in range(len(l) - 2, -1, -1):
				if l[i] == m:
					helper(l, i)
		except TabError:
			pass
		else:
			print('NO')
			return
	print('NO' if aa != [inf] else '\n'.join(res))
main()


n = int(input())
scum = list(map(int, input().split()))
k = int(input())
bag = list(map(int, input().split()))
hoot = []
www = 0
w = 0
getsome = []
for i in range(k):
	c = 0
	for j in range(w, n):
		c += scum[j]
		if c == bag[i]:
			hoot.append(j + 1)
			w = j + 1
			break
		if c > bag[i]:
			www = 1
			break
	if www == 1:
		break
	if c < bag[i]:
		www = 1
		break
if www == 1 or j < n - 1:
	print('NO')
else:
	lost = 0
	hell = 0
	for i in range(len(hoot)):
		virginity = max(scum[lost:hoot[i]])
		if virginity == bag[i]:
			lost = hoot[i]
			continue
		hell = 0
		for j in range(lost, hoot[i]):
			if scum[j] == virginity:
				if j != lost and j != hoot[i] - 1:
					if scum[j] > scum[j - 1] or scum[j] > scum[j + 1]:
						hell = 1
						quirks = j
						break
				elif j == lost:
					if scum[j] > scum[j + 1]:
						hell = 1
						quirks = j
						break
				elif scum[j] > scum[j - 1]:
					hell = 1
					quirks = j
					break
		if hell == 1:
			count = quirks - lost
			ghetto = hoot[i] - quirks - 1
			if scum[quirks] > scum[quirks - 1]:
				for v in range(count):
					getsome.append([count - v + i + 1, 'L'])
				for v in range(ghetto):
					getsome.append([i + 1, 'R'])
			else:
				for v in range(ghetto):
					getsome.append([count + i + 1, 'R'])
				for v in range(count):
					getsome.append([count - v + i + 1, 'L'])
		else:
			break
		lost = hoot[i]
	if hell == 0:
		if scum == bag:
			print('YES')
		else:
			print('NO')
	else:
		print('YES')
		for i in getsome:
			print(i[0], i[1])


def solve():
	(i, pre) = (0, 0)
	for (j, v) in enumerate(b):
		while v > 0:
			v -= a[i]
			i += 1
		if v:
			return 0
		(l, pre) = (a[pre:i], i)
		m = max(l)
		l.append(inf)
		for (n, val) in enumerate(l):
			if val == m:
				merge(l, n, j)
			if len(l) == 2:
				continue
		if len(l) > 2:
			return 0
	if a[i] < inf:
		return 0
	else:
		return 1

def merge(l, i, j):
	if l[i] > l[i - 1]:
		ans.append('%d L' % (i + j + 1))
		i -= 1
	elif l[i] > l[i + 1]:
		ans.append('%d R' % (i + j + 1))
	else:
		return
	l[i] += l.pop(i + 1)
	merge(l, i, j)
ans = ['YES']
inf = 1 << 30
(_, a) = (input(), [*map(int, input().split()), inf])
(_, b) = (input(), [int(x) for x in input().split()])
if solve():
	print('\n'.join(ans))
else:
	print('NO\n')


import sys
n = int(input())
ta = input().split()
a = [int(x) for x in ta]
m = int(input())
tb = input().split()
b = [int(x) for x in tb]
(sum1, sum2) = (0, 0)
for i in a:
	sum1 += i
for i in b:
	sum2 += i
if sum1 != sum2:
	print('NO')
	sys.exit(0)
s = []
idx = 0
for i in range(m):
	t = b[i]
	oo = idx
	mm = idx
	while t > 0:
		t -= a[idx]
		if a[mm] < a[idx]:
			mm = idx
		idx += 1
	if t < 0:
		print('NO')
		sys.exit(0)
	if mm == oo:
		while mm + 1 < idx and a[mm] == a[mm + 1]:
			mm = mm + 1
	flag = 0
	if mm - 1 >= oo and a[mm] > a[mm - 1]:
		flag = 1
	elif mm + 1 < idx and a[mm] > a[mm + 1]:
		flag = 2
	elif idx - oo == 1:
		continue
	if flag == 0:
		print('NO')
		sys.exit(0)
	elif flag == 1:
		for x in range(mm, oo, -1):
			s.append([x - oo + i, 'L'])
		for x in range(mm, idx - 1):
			s.append([i, 'R'])
	elif flag == 2:
		for x in range(mm, idx - 1):
			s.append([mm - oo + i, 'R'])
		for x in range(mm, oo, -1):
			s.append([x - oo + i, 'L'])
print('YES')
for x in s:
	print(str(x[0] + 1) + ' ' + str(x[1]))


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
N = int(input())
A = alele()
kk = int(input())
B = alele()
Ans = []
if sum(A) != sum(B):
	Y(0)
else:
	for i in range(kk):
		x = B[i]
		j = i
		tot = 0
		while j < len(A) and tot < x:
			tot += A[j]
			j += 1
		if tot != x:
			Y(0)
			exit(0)
		for k in range(j - i - 1):
			m = max(A[i:j - k])
			for l in range(i, j - k):
				if A[l] == m:
					if l > i and A[l] > A[l - 1]:
						Ans.append((l + 1, 'L'))
						A[l] += A[l - 1]
						A = A[:l - 1] + A[l:]
						break
					elif l < j - k - 1 and A[l] > A[l + 1]:
						Ans.append((l + 1, 'R'))
						A[l] += A[l + 1]
						A = A[:l + 1] + A[l + 2:]
						break
	if len(Ans) == N - kk:
		Y(1)
		for (i, j) in Ans:
			print(i, j)
	else:
		Y(0)


ans = []

def search(j1, j):
	m = max(a[j1:j])
	if a[j1] == m and a[j1] > a[j1 + 1]:
		return j1
	if a[j - 1] == m and a[j - 1] > a[j - 2]:
		return j - 1
	for i in range(j1 + 1, j - 1):
		if a[i] == m and (a[i] > a[i - 1] or a[i] > a[i + 1]):
			return i

def merge(j1, j):
	c = search(j1, j)
	if j1 < c < j - 1:
		if a[c] > a[c + 1]:
			for i in range(c, j - 1):
				ans.append([c - d + 1, 'R'])
			for i in range(c - j1):
				ans.append([c - i - d + 1, 'L'])
		else:
			for i in range(c - j1):
				ans.append([c - i - d + 1, 'L'])
			for i in range(c, j - 1):
				ans.append([j1 - d + 1, 'R'])
	elif c == j1:
		for i in range(j1, j - 1):
			ans.append([c - d + 1, 'R'])
	else:
		for i in range(j - 1 - j1):
			ans.append([j - 1 - i - d + 1, 'L'])
n = int(input())
a = list(map(int, input().split()))
k = int(input())
b = list(map(int, input().split()))
can = 'YES'
j = 0
d = 0
for i in range(k):
	j1 = j
	r = True
	s = 0
	while j < n and s < b[i]:
		if j > j1 and a[j] != a[j - 1]:
			r = False
		s += a[j]
		j += 1
	if r and j - j1 > 1 or s != b[i] or (i < k - 1 and j == n):
		can = 'NO'
		break
	if j - j1 > 1:
		merge(j1, j)
	d += j - j1 - 1
if j < n:
	can = 'NO'
print(can)
if can == 'YES':
	for i in range(len(ans)):
		print(ans[i][0], ans[i][1])


head = 0
result = ''

def maxIndexes(list):
	result = []
	max = -1
	for x in list:
		if x > max:
			max = x
	for i in range(len(list)):
		if list[i] == max:
			result.append(i + 1)
	return result

def neighborsMax(a):
	indexes = maxIndexes(a)
	if len(a) == 1:
		return True
	for j in indexes:
		i = j - 1
		if i == 0:
			if a[0] != a[1]:
				return True
		elif i == len(a) - 1:
			if a[-1] != a[-2]:
				return True
		elif a[i - 1] != a[i] or a[i + 1] != a[i]:
			return True
	return False

def possible(a, b):
	if len(a) < len(b):
		return False
	if len(a) == 1:
		return a == b
	if len(b) == 1:
		return neighborsMax(a) and sum(a) == b[0]
	for i in range(len(a)):
		if sum(a[:i]) == b[0]:
			return neighborsMax(a[:i]) and possible(a[i:], b[1:])

def startIndex(list):
	indexes = maxIndexes(list)
	for index in indexes:
		if index == 1 and list[1] != list[0]:
			return 1
		elif (index == len(list) and list[-1] != list[-2]) and index != 1:
			return index
		elif (index - 1 not in indexes or index + 1 not in indexes) and index != 1 and (index != len(list)):
			return index

def startDirection(list, index):
	if index == 1:
		return 1
	if index == len(list):
		return -1
	if list[index] != list[index - 1]:
		return 1
	return -1

def printTimes(start, direction, times):
	if direction == 1:
		for i in range(times):
			print(start, 'R')
	else:
		for i in range(times):
			print(start - i, 'L')

def output(list, head):
	index = startIndex(list)
	direction = startDirection(list, index)
	if direction == 1:
		printTimes(index + head, 1, len(list) - index)
		printTimes(index + head, -1, index - 1)
	else:
		printTimes(index + head, -1, index - 1)
		printTimes(index + head - index + 1, 1, len(list) - index)

def eat(a, b, head):
	if len(a) == 1:
		return
	if len(b) == 1:
		output(a, head)
		return
	for k in range(len(a)):
		if sum(a[:k]) == b[0]:
			eat(a[:k], [b[0]], head)
			eat(a[k:], b[1:], head + 1)
n = int(input())
a = str(input()).split()
a = [int(x) for x in a]
k = int(input())
b = str(input()).split()
b = [int(x) for x in b]
isPossible = possible(a, b)
if isPossible:
	print('YES')
	eat(a, b, 0)
else:
	print('NO')


from queue import PriorityQueue
fmap = lambda f, l: list(map(f, l))
parse_int = lambda : fmap(int, input().split())
input()
bseq = parse_int()
input()
eseq = parse_int()
ans = []

def eat(l, r):
	part = bseq[l:r + 1]
	if len(part) == 1:
		return
	pmax = max(part)
	if part.count(pmax) == len(part):
		print('NO')
		exit()
	if part[0] == pmax and part[1] < pmax:
		commands = [str(l + 1) + ' R' for _ in range(len(part) - 1)]
		ans.append(commands)
		return
	if part[-1] == pmax and part[-2] < pmax:
		commands = [str(r - _ + 1) + ' L' for _ in range(len(part) - 1)]
		ans.append(commands)
		return
	commands = []
	for idx in range(1, len(part) - 1):
		if part[idx] == pmax:
			if part[idx - 1] < pmax:
				commands.append(str(l + idx + 1) + ' L')
				for _ in range(len(part) - idx - 1):
					commands.append(str(l + idx) + ' R')
				for _ in range(idx - 1):
					commands.append(str(l + idx - _) + ' L')
				ans.append(commands)
				return
			if part[idx + 1] < pmax:
				for _ in range(len(part) - idx - 1):
					commands.append(str(l + idx + 1) + ' R')
				for _ in range(idx):
					commands.append(str(l + idx - _ + 1) + ' L')
				ans.append(commands)
				return
(bidx, eidx, cur) = (0, 0, 0)
(l, r) = (0, -1)
while True:
	cur += bseq[bidx]
	bidx += 1
	r += 1
	if cur > eseq[eidx]:
		print('NO')
		exit()
	if cur == eseq[eidx]:
		eat(l, r)
		(l, r) = (r + 1, r)
		cur = 0
		eidx += 1
	if bidx == len(bseq) and eidx == len(eseq):
		break
	if (bidx == len(bseq)) ^ (eidx == len(eseq)):
		print('NO')
		exit()
print('YES')
for ls in ans[::-1]:
	for com in ls:
		print(com)


def main():
	n = input()
	queue1 = [int(x) for x in input().split()]
	m = input()
	queue2 = [int(x) for x in input().split()]
	(b, steps) = solver(queue1, queue2)
	if b == 'NO':
		print('NO')
	else:
		print('YES')
		for step in steps:
			print(step[0], step[1])

def solver(queue1, queue2):
	if len(queue1) < len(queue2):
		return ('NO', [])
	steps = [None] * (len(queue1) - len(queue2))
	stepIndex = 0
	last = len(queue1)
	for j in range(len(queue2) - 1, -1, -1):
		m2 = queue2[j]
		total = 0
		for i in range(last - 1, -1, -1):
			total += queue1[i]
			if total > m2:
				return ('NO', [])
			elif total == m2:
				curMax = max(queue1[i:last])
				if i == last - 1:
					last = i
					break
				elif m2 == curMax * (last - i):
					return ('NO', [])
				else:
					curSteps = makeSteps(queue1, i, last, curMax)
					steps[stepIndex:len(curSteps) + stepIndex] = curSteps
					stepIndex += len(curSteps)
					last = i
					break
		else:
			return ('NO', [])
	if last != 0:
		return ('NO', [])
	else:
		return ('YES', steps)

def makeSteps(L, left, right, curMax):
	maxIndex = -1
	for i in range(left, right):
		if L[i] == curMax:
			maxIndex = i
			break
	assert maxIndex != -1
	if maxIndex != left:
		lefts = [(x + 1, 'L') for x in range(maxIndex, left, -1)]
		rights = [(left + 1, 'R')] * (right - maxIndex - 1)
		steps = lefts + rights
		return steps
	for i in range(left, right):
		if L[i] != curMax:
			maxIndex = i - 1
			break
	assert maxIndex != -1
	rights = [(maxIndex + 1, 'R')] * (right - maxIndex - 1)
	lefts = [(x + 1, 'L') for x in range(maxIndex, left, -1)]
	steps = rights + lefts
	return steps
main()


def main():

	def helper(i):
		if l[i] > l[i - 1]:
			res.append('%d L' % (i + j))
			i -= 1
		elif l[i] > l[i + 1]:
			res.append('%d R' % (i + j))
		else:
			return
		l[i] += l.pop(i + 1)
		helper(i)
	(inf, res, _) = (1 << 30, ['YES'], input())
	(aa, _) = ([*map(int, input().split()), inf], input())
	lo = hi = 0
	for (j, b) in enumerate(map(int, input().split()), 1):
		while b > 0:
			b -= aa[hi]
			hi += 1
		if b:
			break
		(l, lo) = (aa[lo:hi], hi)
		m = max(l)
		l.append(inf)
		for (i, a) in enumerate(l):
			if a == m:
				helper(i)
		if len(l) > 2:
			b = 1
			break
	print('NO' if b or aa[hi] < inf else '\n'.join(res))
main()


n = int(input())
before = list(map(int, input().split()))
kk = int(input())
after = list(map(int, input().split()))
ans = []
if sum(before) != sum(after):
	print('NO')
	exit()
for i in range(kk):
	need = after[i]
	s = 0
	j = i
	while j < len(before) and s < need:
		s += before[j]
		j += 1
	if s != need:
		print('NO')
		exit()
	for k in range(j - i - 1):
		m = max(before[i:j - k])
		for ind in range(i, j - k):
			if before[ind] == m:
				if ind > i and before[ind] > before[ind - 1]:
					ans.append((ind + 1, 'L'))
					before[ind] += before[ind - 1]
					before = before[:ind - 1] + before[ind:]
					break
				elif ind < j - k - 1 and before[ind] > before[ind + 1]:
					ans.append((ind + 1, 'R'))
					before[ind] += before[ind + 1]
					before = before[:ind + 1] + before[ind + 2:]
					break
		else:
			print('NO')
			exit()
if len(ans) == n - kk:
	print('YES')
	for i in ans:
		print(*i)
else:
	print('NO')


def partition(a, c):
	acc = 0
	a1 = []
	a2 = []
	max_e = 0
	max_idx = 0
	max_idx2 = 0
	update = True
	if len(a) == 0:
		return (None, a2, max_idx, max_idx2)
	first = a[0]
	not_eq = False
	big = False
	for (i, e) in enumerate(a):
		acc += e
		a1.append(e)
		if e != first:
			not_eq = True
		if e > max_e:
			max_e = e
			max_idx = i
			max_idx2 = i
			update = True
		elif e == max_e and update:
			max_idx2 = i
		else:
			update = False
		if acc == c:
			break
	a2 = a[len(a1):]
	if (not_eq or len(a1) == 1) and sum(a1) == c:
		return (a1, a2, max_idx, max_idx2)
	else:
		return (None, a2, max_idx, max_idx2)

def print_steps(a1, max_idx, max_idx2, j):
	res = []
	if max_idx != 0:
		for i in range(max_idx + 1, 1, -1):
			res.append((i + j, 'L'))
		for i in range(1, len(a1) - max_idx):
			res.append((j + 1, 'R'))
		return res
	else:
		for i in range(max_idx2 + 1, len(a1)):
			res.append((j + max_idx2 + 1, 'R'))
		for i in range(max_idx2 + 1, 1, -1):
			res.append((i + j, 'L'))
		return res
n = int(input())
a = [int(j) for j in input().split()]
m = int(input())
b = [int(j) for j in input().split()]
res = []
a2_empty = False
for (i, c) in enumerate(b):
	(a1, a2, max_idx, max_idx2) = partition(a, c)
	if a1:
		res.extend(print_steps(a1, max_idx, max_idx2, i))
		a = a2
	else:
		res = None
		break
	if len(a2) == 0:
		a2_empty = True
if res == None or not a2_empty:
	print('NO')
else:
	print('YES')
	for (i, j) in res:
		print(i, j)


def update(target, threshold):
	global track
	check = [0] * len(a)
	s = 0
	for i in range(len(a)):
		s += a[i]
		if s == target:
			break
	if s != target:
		return False
	if a[i] == target:
		a.pop(0)
		return True
	max = 0
	itrack = 0
	for j in range(i + 1):
		if j == 0 and a[j] > a[j + 1] or (j == i and a[j] > a[j - 1]) or (0 < j < i and (a[j] > a[j - 1] or a[j] > a[j + 1])):
			if a[j] > max:
				max = a[j]
				itrack = j
	iupper = i
	ii = itrack
	while 1:
		if ii > 0:
			if a[ii] > a[ii - 1]:
				track.append((threshold + ii + 1, 'L'))
				a[ii] += a[ii - 1]
				a.pop(ii - 1)
				ii -= 1
				iupper -= 1
			elif ii < iupper:
				if a[ii] > a[ii + 1]:
					track.append((threshold + ii + 1, 'R'))
					a[ii] += a[ii + 1]
					a.pop(ii + 1)
					iupper -= 1
				else:
					break
		else:
			if ii == iupper:
				break
			if a[ii] > a[ii + 1]:
				track.append((threshold + ii + 1, 'R'))
				a[ii] += a[ii + 1]
				a.pop(ii + 1)
				iupper -= 1
			else:
				break
	if a[0] != target:
		return False
	else:
		a.pop(0)
		return True
n = int(input())
a = [int(i) for i in input().split()]
k = int(input())
b = [int(i) for i in input().split()]
i = 0
j = 0
track = []
check = True
while j < k:
	u = update(b[j], j)
	if u == False:
		check = False
		break
	j += 1
if len(a) > 0 or j < k:
	check = False
if not check:
	print('NO')
else:
	print('YES')
	for i in track:
		print(i[0], i[1])


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
s = 0
j = 0
d = [[] for i in range(m)]
for i in range(n):
	s += a[i]
	d[j].append(a[i])
	if s == b[j]:
		s = 0
		j += 1
		if j == m:
			if i != n - 1:
				print('NO')
				exit()
	elif s > b[j]:
		print('NO')
		exit()
if s != 0:
	print('NO')
	exit()
ans = []
for j in range(m):
	if len(d[j]) == 0:
		print('NO')
		exit()
	ma = max(d[j])
	if len(d[j]) == 1:
		continue
	if len(set(d[j])) == 1:
		print('NO')
		exit()
	q = d[j]
	for i in range(len(q)):
		if ma == q[i]:
			if i == 0 and q[i + 1] == ma:
				continue
			elif i == len(q) - 1 and q[i - 1] == ma:
				continue
			elif 0 < i < len(q) - 1 and q[i - 1] == ma and (q[i + 1] == ma):
				continue
			else:
				k = i
				while len(q) > 1:
					if k > 0 and q[k - 1] < ma:
						ans.append(str(j + k + 1) + ' L')
						ma += q[k - 1]
						q.pop(k - 1)
						k -= 1
					elif k + 1 < len(q) and q[k + 1] < ma:
						ans.append(str(j + k + 1) + ' R')
						ma += q[k + 1]
						q.pop(k + 1)
				break
print('YES')
for i in ans:
	print(i)


__author__ = 'Think'

def f(interval, place):
	if len(interval) == 1:
		return []
	m = -1
	n = len(interval)
	for i in range(n):
		if interval[i] > m:
			m = interval[i]
			index = i
	shifted = False
	if index == 0 and n > 1:
		if interval[1] == m:
			shifted = True
			index = 1
			while index < n:
				if interval[index] != m:
					break
				index += 1
			index -= 1
			if index == n - 1:
				return [0]
	if not shifted:
		return [(place + i, 'L') for i in range(index, 0, -1)] + [(place, 'R')] * (n - index - 1)
	else:
		place += index
		return [(place, 'R')] * (n - index - 1) + [(place - i, 'L') for i in range(index)]
n = int(input())
a = [int(i) for i in input().split()]
k = int(input())
b = [int(i) for i in input().split()]
place = 1
point = 0
printer = []
broken = False
for i in b:
	initial = point
	if point >= n:
		broken = True
		break
	total = a[point]
	point += 1
	while total < i:
		if point == n:
			broken = True
			break
		total += a[point]
		point += 1
	if broken:
		break
	if total > i:
		broken = True
		break
	thingy = f(a[initial:point], place)
	place += 1
	if len(thingy) == 1:
		if thingy[0] == 0:
			broken = True
			break
	printer.extend(thingy)
if broken or point != n:
	print('NO')
else:
	print('YES')
	for i in printer:
		print(i[0], i[1])


import timeit

def inp():
	return list(map(int, input().split()))

def a():
	return timeit.default_timer()

def main():
	n = int(input())
	A = inp()
	m = int(input())
	B = inp()
	D = 0
	F = []
	j = 0
	k = 0
	for i in range(n):
		if k > m - 1:
			return [-1]
		D += A[i]
		if D == B[k]:
			C = A[j:i + 1]
			D = 0
			j = i + 1
			k += 1
			if len(C) == 1:
				continue
			while len(C) != 1:
				x = a()
				E = list(C)
				t = E.index(max(E))
				while not (t < len(E) - 1 and C[t] > C[t + 1] or (t > 0 and C[t] > C[t - 1])):
					E[t] = 0
					t = E.index(max(E))
					if max(E) == 0:
						return [-1]
				E = list(C)
				if t < len(E) - 1:
					if C[t] > C[t + 1]:
						C[t:t + 2] = [C[t] + C[t + 1]]
						F.append(str(t + k) + ' R')
						continue
				if t > 0:
					if C[t] > C[t - 1]:
						C[t - 1:t + 1] = [C[t] + C[t - 1]]
						F.append(str(t + k) + ' L')
						continue
		elif D > B[k]:
			return [-1]
	if k != m:
		return [-1]
	else:
		return F
temp = main()
if temp == [-1]:
	print('NO')
else:
	print('YES')
	for i in temp:
		print(i)


import sys

class DeadlockException(Exception):
	pass

def make_actions(array, beg, end, offset):
	if end - beg == 0:
		return []
	mx = max((array[i] for i in range(beg, end + 1)))
	base = None
	for (i1, i2) in zip(range(beg, end), range(beg + 1, end + 1)):
		(m1, m2) = (array[i1], array[i2])
		if max((m1, m2)) == mx and min((m1, m2)) < mx:
			base = i1 if m1 == mx else i2
			dr = 1 if base == i1 else -1
			break
	if base is None:
		raise DeadlockException
	if dr == 1:
		yield from eat_right(beg, end, offset, base)
		yield from eat_left(beg, end, offset, base)
	else:
		yield from eat_left(beg, end, offset, base)
		yield from eat_right(base, end, offset, base)

def eat_right(beg, end, offset, base):
	for _ in range(end - base):
		yield (base - beg + offset, 'R')

def eat_left(beg, end, offset, base):
	for i in range(base, beg, -1):
		yield (i - beg + offset, 'L')

def main():
	n = int(input())
	a1 = [int(x) for x in input().split()]
	k = int(input())
	a2 = [int(x) for x in input().split()]
	cur_sum = 0
	cur_beg = 0
	i2 = 0
	actions = []
	for (i1, e) in enumerate(a1):
		cur_sum += e
		if i2 >= len(a2):
			print('NO')
			sys.exit(0)
		if cur_sum == a2[i2]:
			try:
				actions.extend(make_actions(a1, cur_beg, i1, i2))
			except DeadlockException:
				print('NO')
				sys.exit(0)
			else:
				i2 += 1
				cur_sum = 0
				cur_beg = i1 + 1
		elif cur_sum > a2[i2]:
			print('NO')
			sys.exit(0)
	if i2 != len(a2):
		print('NO')
	else:
		print('YES')
		for (n1, d) in actions:
			print(n1 + 1, d)
main()


def takefirst(a, s):
	curs = 0
	for i in range(len(a)):
		curs += a[i]
		if curs == s:
			return i
		if curs > s:
			return -1
	return -1

def maxid(a):
	if len(a) == 1:
		return 0
	m = max(a)
	if a[0] == m:
		if a[1] < m:
			return 0
	if a[-1] == m:
		if a[-2] < m:
			return len(a) - 1
	for i in range(1, len(a) - 1):
		if a[i] == m:
			if a[i + 1] < m or a[i - 1] < m:
				return i
	return a.index(m)

def maxid1(a):
	m = a[0]
	mid = 0
	for i in range(len(a)):
		if m < a[i]:
			m = a[i]
			mid = i
			continue
		if m == a[i]:
			mid = i
	if mid == len(a) - 1:
		for i in range(len(a)):
			if a[i] == m:
				return i
	return mid
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
step = []
flag = True
o = 0
for i in b:
	take = takefirst(a, i)
	if take == -1:
		flag = False
		break
	else:
		considering = a[:take + 1]
		a = a[take + 1:]
		if len(considering) <= 1:
			o += 1
			continue
		biggest = maxid(considering)
		ii = biggest
		if biggest < take and considering[biggest] > considering[biggest + 1]:
			while ii < take:
				step.append(str(biggest + 1 + o) + ' R')
				ii += 1
			while biggest > 0:
				step.append(str(biggest + 1 + o) + ' L')
				biggest -= 1
		elif biggest > 0 and considering[biggest] > considering[biggest - 1]:
			while biggest > 0:
				step.append(str(biggest + 1 + o) + ' L')
				biggest -= 1
			while ii < take:
				step.append(str(1 + o) + ' R')
				ii += 1
		elif biggest == 0 and considering[biggest] > considering[biggest + 1]:
			while ii < take:
				step.append(str(biggest + 1 + o) + ' R')
				ii += 1
		elif biggest == take and considering[biggest] > considering[biggest - 1]:
			while biggest > 0:
				step.append(str(biggest + 1 + o) + ' L')
				biggest -= 1
		else:
			flag = False
		o += 1
if len(a) > 0:
	flag = False
if not flag:
	print('NO')
else:
	print('YES')
	if len(step) > 0:
		print('\n'.join(step))


import sys

def main():
	n = int(sys.stdin.readline()[:-1])
	a = [int(x) for x in sys.stdin.readline()[:-1].split()]
	k = int(sys.stdin.readline()[:-1])
	b = [int(x) for x in sys.stdin.readline()[:-1].split()]
	last = 0
	menu = []
	largest = []
	if sum(a) != sum(b):
		sys.stdout.write('NO')
		return
	for t in b:
		ate = 0
		bef = last
		large = last
		large1 = last
		for i in range(bef, n):
			if ate < t:
				ate += a[i]
				if a[i] >= a[large] and (i + 1 < n and a[i + 1] < a[i] or (i - 1 >= bef and a[i - 1] < a[i])):
					large1 = large
					large = i
				last = i + 1
			else:
				break
		if ate == t:
			if large == last - 1 and (not (large - 1 >= bef and a[large - 1] < a[large])):
				large = large1
			menu.append(a[bef:last])
			largest.append(large - bef)
		else:
			sys.stdout.write('NO')
			return
	seq = 'YES'
	for (i, l) in enumerate(menu):
		now = largest[i]
		current = l[:]
		while len(current) != 1:
			if now - 1 >= 0 and current[now - 1] < current[now]:
				seq += '\n%d L' % (now + i + 1)
				current[now] += current[now - 1]
				current = current[:now - 1] + current[now:]
				now -= 1
			elif now + 1 < len(current) and current[now + 1] < current[now]:
				seq += '\n%d R' % (now + i + 1)
				current[now] += current[now + 1]
				current = current[:now + 1] + current[now + 2:]
				now = now
			else:
				sys.stdout.write('NO')
				return
	sys.stdout.write(seq)
main()


from array import array
from sys import stdin
input = stdin.readline
n = int(input())
a = array('L', (int(x) for x in input().split()))
k = int(input())
b = array('L', (int(x) for x in input().split()))
valid = True
i = 0
j = 0
cw = 0
p = []
store = []
while valid:
	while cw < b[j] and i < n:
		cw += a[i]
		p.append(a[i])
		i += 1
	if cw == b[j]:
		cw = 0
		j += 1
		store.append(p)
		p = []
	elif cw > b[j]:
		valid = False
		break
	if i == n and j == k:
		break
	elif i == n or j == k:
		valid = False
		break
if valid == False:
	print('NO')
	exit(0)
answer = 'YES\n'
for index in range(len(store)):
	val = max(store[index])
	valid = False
	if len(store[index]) == 1:
		continue
	for c in range(len(store[index])):
		if store[index][c] != val:
			valid = True
			break
	if not valid:
		answer = 'NO'
		break
	else:
		for c in range(len(store[index]) - 1):
			if store[index][c] != val and store[index][c + 1] == val:
				for x in range(c + 1, 0, -1):
					answer += str(index + x + 1) + ' L\n'
				for x in range(len(store[index]) - c - 2):
					answer += str(index + 1) + ' R\n'
				break
			elif store[index][c] == val and store[index][c + 1] != val:
				for x in range(c + 1, len(store[index])):
					answer += str(index + (c + 1)) + ' R\n'
				for x in range(c, 0, -1):
					answer += str(index + x + 1) + ' L\n'
				break
print(answer)


import sys
input = sys.stdin.readline
n = int(input())
a = [int(i) for i in input().split()]
m = int(input())
b = [int(i) for i in input().split()]
j = n - 1
ans = []
for k in range(m - 1, -1, -1):
	sm = 0
	i = j
	while i >= 0:
		sm += a[i]
		if sm == b[k]:
			if i == j:
				pass
			else:
				mx = max(a[i:j + 1])
				ii = -1
				for x in range(i, j + 1):
					if a[x] == mx and (x - 1 >= i and a[x - 1] < a[x] or (x + 1 <= j and a[x] > a[x + 1])):
						ii = x
				if ii == -1:
					print('NO')
					exit()
				(L, R) = (ii - i, j - ii)
				if ii - 1 >= i and a[ii - 1] < a[ii]:
					for _ in range(L):
						ans.append((ii + 1, 'L'))
						ii -= 1
					for _ in range(R):
						ans.append((ii + 1, 'R'))
				else:
					for _ in range(R):
						ans.append((ii + 1, 'R'))
					for _ in range(L):
						ans.append((ii + 1, 'L'))
						ii -= 1
			j = i - 1
			b[k] = 0
			break
		elif sm > b[k]:
			print('NO')
			exit()
		i -= 1
if j >= 0 or max(b) > 0:
	print('NO')
else:
	print('YES')
	for tu in ans:
		print(*tu)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	(sum1, sum2) = (0, 0)
	for i in a:
		sum1 += i
	for i in b:
		sum2 += i
	if sum1 != sum2:
		print('NO')
		return
	instructions = []
	index = 0
	for i in range(m):
		t = b[i]
		p1 = index
		p2 = index
		while t > 0:
			t -= a[index]
			if a[p2] < a[index]:
				p2 = index
			index += 1
		if t < 0:
			print('NO')
			return
		if p2 == p1:
			while p2 + 1 < index and a[p2] == a[p2 + 1]:
				p2 = p2 + 1
		flag = 0
		if p2 - 1 >= p1 and a[p2] > a[p2 - 1]:
			flag = 1
		elif p2 + 1 < index and a[p2] > a[p2 + 1]:
			flag = 2
		elif index - p1 == 1:
			continue
		if flag == 0:
			print('NO')
			return
		elif flag == 1:
			for x in range(p2, p1, -1):
				instructions.append('{0} L'.format(x - p1 + i + 1))
			for x in range(p2, index - 1):
				instructions.append('{0} R'.format(i + 1))
		elif flag == 2:
			for x in range(p2, index - 1):
				instructions.append('{0} R'.format(p2 - p1 + i + 1))
			for x in range(p2, p1, -1):
				instructions.append('{0} L'.format(x - p1 + i + 1))
	print('YES')
	for x in instructions:
		print(x)
main()


n = int(input())
init = list(map(int, input().split()))
k = int(input())
after = list(map(int, input().split()))
(prev, cur, t) = (-1, 0, 0)
ans = []
if sum(init) != sum(after):
	print('NO')
	exit()
for i in range(n):
	t += init[i]
	if t == after[cur] and cur < k:
		cur += 1
		t = 0
		ans.append((prev + 1, i))
		prev = i
if cur != k:
	print('NO')
else:
	res = []
	for i in range(len(ans)):
		(s, f) = (ans[i][0], ans[i][1])
		if s == f:
			continue
		mx = max(init[s:f + 1])
		j = -1
		l = True
		for ii in range(s, f + 1):
			if init[ii] == mx:
				if ii - 1 >= s and init[ii] > init[ii - 1]:
					j = ii
					l = True
					break
				if ii + 1 <= f and init[ii] > init[ii + 1]:
					j = ii
					l = False
					break
		if j == -1:
			print('NO')
			exit()
		if l:
			for ij in reversed(range(2, j - s + 2)):
				res.append((i + ij, 'L'))
			for _ in range(f - j):
				res.append((i + 1, 'R'))
		else:
			for _ in range(f - j):
				res.append((i + j - s + 1, 'R'))
			for ij in reversed(range(2, j - s + 2)):
				res.append((i + ij, 'L'))
	print('YES')
	for _ in range(len(res)):
		print(*res[_])


(n, a) = (int(input()), list(map(int, input().split())))
(k, b) = (int(input()), list(map(int, input().split())))
(j, ss) = (0, 0)
el = []
for i in range(n):
	ss += a[i]
	if j == k:
		print('NO')
		exit()
	if ss == b[j]:
		ss = 0
		j += 1
		el.append(i)
	elif ss > b[j]:
		print('NO')
		exit()
if len(el) < k:
	print('NO')
	exit()
el.append(-1)
iml = []
for i in range(k):
	start = el[i - 1] + 1
	end = el[i]
	iml.append(start)
	maxbsum = 0
	for j in range(start, end):
		if a[j] != a[j + 1]:
			if a[j] + a[j + 1] > maxbsum:
				maxbsum = a[j] + a[j + 1]
				iml[i] = j
	if maxbsum == 0 and start != end:
		print('NO')
		exit()
ans = []
for i in range(k - 1, -1, -1):
	start = el[i - 1] + 1
	end = el[i]
	maxi = iml[i]
	if start == end:
		continue
	if a[maxi] > a[maxi + 1]:
		for j in range(maxi, end):
			ans.append(str(maxi + 1) + ' R')
		for j in range(maxi, start, -1):
			ans.append(str(j + 1) + ' L')
	else:
		ans.append(str(maxi + 2) + ' L')
		for j in range(maxi + 1, el[i]):
			ans.append(str(maxi + 1) + ' R')
		for j in range(maxi, start, -1):
			ans.append(str(j + 1) + ' L')
print('YES')
for l in ans:
	print(l)


n = int(input())
fr = list(map(int, input().split()))
k = int(input())
to = list(map(int, input().split()))

def process(l, off):
	res = []
	m = max(l)
	mi = l.index(m)
	if mi == 0 and all(map(lambda x: x == m, l)):
		return res
	if not mi:
		for i in range(1, len(l)):
			if l[i] < m:
				mi = i - 1
				res.append((off + i - 1, 'R'))
				break
	for i in range(mi, 0, -1):
		res.append((off + i, 'L'))
	for i in range(len(l) - len(res) - 1):
		res.append((off, 'R'))
	return res
st = 0
res = []
good = True
for off in range(k):
	x = to[off]
	if st == n:
		good = False
		break
	elif x == fr[st]:
		st += 1
	else:
		s = 0
		for fn in range(st, n):
			s += fr[fn]
			if s == x:
				t = process(fr[st:fn + 1], off + 1)
				if t:
					st = fn + 1
					res.extend(t)
				else:
					good = False
				break
			elif s > x:
				good = False
				break
		if not good:
			break
if good:
	good = st == n
if good:
	print('YES')
	for (x, y) in res:
		print(x, end=' ')
		print(y)
else:
	print('NO')


def fail():
	print('NO')
	exit()
read = lambda : map(int, input().split())
n = int(input())
a = list(read())
k = int(input())
b = list(read())
if a == b:
	print('YES')
	exit()
if sum(a) != sum(b):
	fail()
ind = []
cur = j = 0
for i in range(n):
	cur += a[i]
	if j > k:
		fail()
	if cur == b[j]:
		ind.append(i)
		cur = 0
		j += 1
if len(ind) != k or ind[-1] != n - 1:
	fail()
ind.append(-1)
seg = []
for i in range(k):
	(l, r) = (ind[i - 1] + 1, ind[i])
	seg.append((l, r))
ans = []
ch = ch2 = 0
c = []
for (l, r) in seg:
	Max = max(a[l:r + 1])
	if r - l == 0:
		c.append(a[l])
		continue
	x = -1
	if a[l] == Max and a[l] > a[l + 1]:
		x = l
	if a[r] == Max and a[r] > a[r - 1]:
		x = r
	for i in range(l + 1, r):
		if a[i] == Max and (a[i] > a[i - 1] or a[i] > a[i + 1]):
			x = i
	if x == -1:
		fail()
	res = a[x]
	ch += ch2
	ch2 = 0
	(L, R) = (x - 1, x + 1)
	for i in range(l, r):
		if L >= l and a[L] < res:
			ans.append((x - ch, 'L'))
			ch += 1
			res += a[L]
			L -= 1
		elif R <= r and a[R] < res:
			ans.append((x - ch, 'R'))
			ch2 += 1
			res += a[R]
			R += 1
		else:
			fail()
	c.append(res)
if c != b:
	fail()
print('YES')
[print(i + 1, j) for (i, j) in ans]


import sys

class Node(object):

	def __init__(self, v, n, p, idx):
		self.next = n
		self.prev = p
		self.value = v
		self.idx = idx

	def remove_next(self):
		if self.next == None:
			return
		if self.next.next == None:
			self.next = None
			return
		self.next = self.next.next
		self.next.prev = self

	def remove_prev(self):
		if self.prev == None:
			return
		if self.prev.prev == None:
			self.prev = None
			return
		self.prev = self.prev.prev
		self.prev.next = self
n = input('')
weights = list(map(int, input('').split(' ')))
k = input('')
weights_after = list(map(int, input('').split(' ')))
groups = []
start = 0
for v in weights_after:
	total = 0
	group = []
	for i in range(start, len(weights)):
		total += weights[i]
		group.append(weights[i])
		if total > v:
			print('NO')
			sys.exit(0)
		elif total == v:
			start = i + 1
			break
	if len(group) == 0 or (len(set(group)) == 1 and group[0] != v):
		print('NO')
		sys.exit(0)
	groups.append(group)
if start != len(weights):
	print('NO')
	sys.exit(0)
print('YES')
start = 0
for g in groups:
	if len(g) == 1:
		start += 1
		continue
	biggest_value = g[max(range(len(g)), key=g.__getitem__)]
	biggest_item = []
	n = Node(g[0], None, None, 0)
	if g[0] == biggest_value:
		biggest_item.append(n)
	for i in range(1, len(g)):
		n.next = Node(g[i], None, n, i)
		n = n.next
		if g[i] == biggest_value:
			biggest_item.append(n)
	starting = None
	for n in biggest_item:
		if n.prev is not None and n.prev.value < n.value:
			starting = n
			break
		if n.next is not None and n.next.value < n.value:
			starting = n
			break
	while True:
		if starting.next is not None and starting.next.value < starting.value:
			print(start + starting.idx + 1, 'R')
			starting.value += starting.next.value
			starting.remove_next()
			continue
		if starting.prev is not None and starting.prev.value < starting.value:
			print(start + starting.idx + 1, 'L')
			starting.idx -= 1
			starting.value += starting.prev.value
			starting.remove_prev()
			continue
		break
	start += 1


import math, sys, re, itertools, pprint, collections
(ri, rai) = (lambda : int(input()), lambda : list(map(int, input().split())))
n = ri()
a = rai()
k = ri()
b = rai()
if sum(a) != sum(b):
	print('NO')
	sys.exit(0)

def f(l, r):
	if r - l == 1:
		return []
	m = max(a[l:r])
	flag = False
	for x in a[l:r]:
		if x != m:
			flag = True
			break
	if not flag:
		return None
	res = []
	mi = l
	md = 'R'
	for (i, x) in enumerate(a[l:r], l):
		if x == m:
			if i == l:
				if a[i + 1] < m:
					break
			elif a[i - 1] < m:
				mi = i
				md = 'L'
				break
			elif a[i + 1] < m:
				mi = i
				break
	if md == 'R':
		for i in range(r - mi - 1):
			res.append([mi, 'R'])
		t = mi - l
		for i in range(t):
			res.append([mi, 'L'])
			mi -= 1
	if md == 'L':
		t = r - mi - 1
		tt = mi - l
		for i in range(tt):
			res.append([mi, 'L'])
			mi -= 1
		for i in range(t):
			res.append([mi, 'R'])
	return res
i = j = s = 0
flag = True
res = []
for (xi, x) in enumerate(b):
	j = i
	s = 0
	while j < len(a) and s < x:
		s += a[j]
		j += 1
	if s > x:
		flag = False
		break
	t = f(i, j)
	if t is None:
		flag = False
		break
	res += t
	a = b[:xi + 1] + a[j:]
	i = xi + 1
if flag:
	print('YES')
	print('\n'.join(map(lambda x: '{} {}'.format(x[0] + 1, x[1]), res)))
else:
	print('NO')


n = int(input())
A = list(map(int, input().split()))
k = int(input())
B = list(map(int, input().split()))

def neighbors(i, l):
	if 0 < i < len(l) - 1:
		return [i - 1, i + 1]
	elif i == 0 == len(l) - 1:
		return []
	elif i == len(l) - 1:
		return [len(l) - 2]
	elif i == 0:
		return [1]

def slice(beg, l, fst):
	s = 0
	for k in range(beg, len(l)):
		if s < fst:
			s += l[k]
		elif s == fst:
			return k
		else:
			return -1
	if s == fst:
		return len(l)
	else:
		return -1

def partial(a, slc, ind):
	if sum(slc) != ind:
		return 'NO  '
	if len(slc) == 1:
		return ''
	else:
		(i, m) = (0, slc[0])
		for j in range(len(slc)):
			if slc[j] > m or (slc[j] == m and min([slc[k] for k in neighbors(j, slc)]) < slc[j]):
				(i, m) = (j, slc[j])
		(j, m) = (neighbors(i, slc)[0], slc[neighbors(i, slc)[0]])
		for k in neighbors(i, slc):
			if slc[i] > slc[k] > m or m == slc[i]:
				(j, m) = (k, slc[k])
		if slc[i] == slc[j]:
			return 'NO  '
		if j < i:
			return str(i + a + 1) + ' L\n' + partial(a, slc[:j] + [slc[i] + slc[j]] + slc[i + 1:], ind)
		else:
			return str(i + a + 1) + ' R\n' + partial(a, slc[:i] + [slc[i] + slc[j]] + slc[j + 1:], ind)

def f(a, b, n, k):
	cuts = [0]
	for j in range(k):
		cut = slice(cuts[-1], a, b[j])
		if cut == -1:
			return 'NO  '
		else:
			cuts.append(cut)
	if cuts[-1] != n:
		return 'NO  '
	rep = 'YES \n'
	for j in range(k):
		part = partial(j, a[cuts[j]:cuts[j + 1]], b[j])
		if part == 'NO  ':
			return part
		else:
			rep += part
	return rep
print(f(A, B, n, k)[:-1])


R = lambda : map(int, input().split())
n = int(input())
a = list(R())
m = int(input())
b = list(R())
st = i = j = 0
res = ''
while i < m:
	psum = 0
	while j < n and psum < b[i]:
		psum += a[j]
		j += 1
	if psum != b[i]:
		print('NO')
		exit(0)
	mi = st if a[st] > a[j - 1] else j - 1
	for k in range(st + 1, j - 1):
		if (a[k] > a[k - 1] or a[k] > a[k + 1]) and a[k] >= a[mi]:
			mi = k
	psum = a[mi]
	(l, r) = (mi - 1, mi + 1)
	while psum != b[i]:
		if l >= st and psum > a[l]:
			res += str(i + l - st + 2) + ' L\n'
			psum += a[l]
			l -= 1
		elif r < j and psum > a[r]:
			res += str(i + l - st + 2) + ' R\n'
			psum += a[r]
			r += 1
		else:
			print('NO')
			exit(0)
	st = j
	i += 1
if i != m or j != n:
	print('NO')
else:
	print('YES')
	print(res)


n = int(input())
a = list(map(int, input().split()))
k = int(input())
b = list(map(int, input().split()))
s = 0
j = 0
ae = []
for i in range(n):
	if j == k:
		print('NO')
		exit()
	s += a[i]
	if s == b[j]:
		ae.append(i)
		j += 1
		s = 0
if len(ae) != k:
	print('NO')
	exit()
start = 0
maxi = []
for i in range(k):
	mm = 0
	if ae[i] != start:
		if min(a[start:ae[i] + 1]) == max(a[start:ae[i] + 1]):
			print('NO')
			exit()
		for j in range(start, ae[i]):
			if a[j] == a[j + 1]:
				continue
			if mm < a[j] + a[j + 1]:
				mm = a[j] + a[j + 1]
				maxi_temp = j
		maxi.append(maxi_temp)
	else:
		maxi.append(start)
	start = ae[i] + 1
ostr = []
for i in range(k - 1, -1, -1):
	if i == 0:
		start = 0
	else:
		start = ae[i - 1] + 1
	if start == ae[i]:
		continue
	else:
		mm = max(a[maxi[i]], a[maxi[i] + 1])
		if mm == a[maxi[i]]:
			for j in range(maxi[i], ae[i]):
				ostr.append(str(maxi[i] + 1) + ' R')
			for j in range(maxi[i], start, -1):
				ostr.append(str(j + 1) + ' L')
		else:
			ostr.append(str(maxi[i] + 2) + ' L')
			for j in range(maxi[i] + 1, ae[i]):
				ostr.append(str(maxi[i] + 1) + ' R')
			for j in range(maxi[i], start, -1):
				ostr.append(str(j + 1) + ' L')
print('YES')
for ss in ostr:
	print(ss)


an = int(input())
a = input().split()
bn = int(input())
b = input().split()
for i in range(an):
	a[i] = int(a[i])
for i in range(bn):
	b[i] = int(b[i])
res = [-1]
t = 0
j = 0
idd = 0
for i in range(an):
	t += a[i]
	if t < b[j]:
		continue
	elif t == b[j]:
		res.append(i)
		t = 0
		if j + 1 == bn and i < an - 1:
			idd = 1
			break
		else:
			j += 1
	else:
		idd = 1
		break
if idd == 0 and len(res) - 1 == bn:
	RES = []
	for i in range(len(res) - 1):
		RES.append(a[res[i] + 1:res[i + 1] + 1])
	res = []
	ll = 0
	for c in RES:
		LL = len(c)
		if LL == 1:
			ll += 1
			continue
		elif c.count(c[0]) != LL:
			for i in range(LL - 1):
				mx = max(c)
				X = c.index(mx)
				if X == 0:
					for i in range(1, LL):
						if c[i] == mx:
							X = i
						else:
							break
					res.append(str(X + 1 + ll) + ' R')
					c[X] += c[X + 1]
					c.pop(X + 1)
				else:
					res.append(str(X + 1 + ll) + ' L')
					c[X] += c[X - 1]
					c.pop(X - 1)
		else:
			print('NO')
			break
		ll += 1
	else:
		print('YES')
		for i in range(len(res)):
			print(res[i])
else:
	print('NO')


n = int(input())
l = list(map(int, input().split()))
m = int(input())
_l = list(map(int, input().split()))
mark = [False for x in range(n)]
i = 0
j = 0
cs = 0
ok = True
while i < n and j < m:
	cs += l[i]
	if cs == _l[j]:
		mark[i] = True
		j += 1
		cs = 0
	elif cs > _l[j]:
		ok = False
		break
	i += 1
if ok == False or cs != 0:
	print('NO')
	exit(0)
a = []
al = []
i = 0
j = 0
while i < n:
	if mark[i] == True:
		a.append(l[j:i + 1])
		al.append(i + 1 - j)
		j = i + 1
	i += 1
if mark[n - 1] == False:
	a.append(l[j:])
	al.append(n - j)
	j = i + 1
ok = True
n = len(a)
if n != m:
	print('NO')
	exit(0)
for i in range(n):
	l = a[i]
	m = al[i]
	j = 0
	sok = False
	if m == 1:
		sok = True
	while j < m - 1:
		if l[j] != l[j + 1]:
			sok = True
			break
		j += 1
	if sok == False:
		ok = False
		break
if ok == False:
	print('NO')
	exit(0)
print('YES')
for i in range(n):
	l = a[i]
	m = al[i]
	for j in range(m - 1):
		mx = 0
		midx = -1
		lenl = m - j
		for k in range(lenl):
			if l[k] > mx:
				if k == 0:
					if l[k + 1] != l[k]:
						mx = l[k]
						midx = k
				elif k == lenl - 1:
					if l[k - 1] != l[k]:
						mx = l[k]
						midx = k
				elif l[k - 1] != l[k] or l[k] != l[k + 1]:
					mx = l[k]
					midx = k
		if midx == 0:
			l[0] += l[1]
			del l[1]
			print(str(i + 1) + ' R')
		elif midx == lenl - 1:
			l[midx] += l[midx - 1]
			del l[midx - 1]
			print(str(i + midx + 1) + ' L')
		elif l[midx - 1] != l[midx]:
			l[midx] += l[midx - 1]
			del l[midx - 1]
			print(str(i + midx + 1) + ' L')
		else:
			l[midx] += l[midx + 1]
			del l[midx + 1]
			print(str(i + midx + 1) + ' R')


def partition(array1, c):
	acc = 0
	a1 = []
	max_num = 0
	max_num_start = 0
	max_num_end = 0
	upd_max_num_end = True
	first = array1[0]
	all_equal = True
	right_value = False
	for (i, num) in enumerate(array1):
		acc += num
		a1.append(num)
		if num != first:
			all_equal = False
		if num > max_num:
			max_num = num
			max_num_start = i
			max_num_end = i
			upd_max_num_end = True
		elif num == max_num and upd_max_num_end:
			max_num_end = i
		else:
			upd_max_num_end = False
		if acc == c:
			right_value = True
			break
	a2 = array1[len(a1):]
	if (not all_equal or len(a1) == 1) and right_value:
		return (a1, a2, max_num_start, max_num_end)
	else:
		return (None, a2, max_num_start, max_num_end)

def get_steps(a1, max_num_start, max_num_end, j):
	steps = []
	if max_num_start != 0:
		for i in range(max_num_start + 1, 1, -1):
			steps.append((i + j, 'L'))
		for i in range(1, len(a1) - max_num_start):
			steps.append((j + 1, 'R'))
	else:
		for i in range(max_num_end + 1, len(a1)):
			steps.append((j + max_num_end + 1, 'R'))
		for i in range(max_num_end + 1, 1, -1):
			steps.append((i + j, 'L'))
	return steps
size_array1 = int(input())
array1 = [int(j) for j in input().split()]
size_array2 = int(input())
array2 = [int(j) for j in input().split()]
a1 = array1
a2 = []
max_idx1 = 0
max_idx2 = 0
steps = []
solved = True
for (i, c) in enumerate(array2):
	(a1, a2, max_num_start, max_num_end) = partition(array1, c)
	if a1:
		steps.extend(get_steps(a1, max_num_start, max_num_end, i))
		array1 = a2
		if len(array1) == 0:
			if i + 1 < len(array2):
				solved = False
			break
	else:
		solved = False
		break
if not solved or len(a2) != 0:
	print('NO')
else:
	print('YES')
	for (i, j) in steps:
		print(i, j)


n = int(input())
a = list(map(int, input().split()))
k = int(input())
b = list(map(int, input().split()))
possible = True
i = 0
j = 0
sub_b = b.copy()
start_index_last_prefix = 0
max_on_prefix = a[start_index_last_prefix]
first_max_on_prefix_index = last_max_on_prefix_index = start_index_last_prefix
actual_finding_max = True
result = []
while possible and i < n and (j < k):
	this = a[i]
	if i == start_index_last_prefix:
		max_on_prefix = a[start_index_last_prefix]
		first_max_on_prefix_index = last_max_on_prefix_index = start_index_last_prefix
		actual_finding_max = True
	if this > max_on_prefix:
		max_on_prefix = this
		first_max_on_prefix_index = last_max_on_prefix_index = i
		actual_finding_max = True
	elif this == max_on_prefix and actual_finding_max:
		last_max_on_prefix_index = i
	else:
		actual_finding_max = False
	sub_b[j] -= this
	if sub_b[j] == 0:
		if first_max_on_prefix_index != start_index_last_prefix:
			number_of_left_eat = first_max_on_prefix_index - start_index_last_prefix
			for x in range(number_of_left_eat):
				pos = number_of_left_eat - x + 1 + j
				step = 'L'
				act = str(pos) + ' ' + step
				result.append(act)
			number_of_right_eat = i - first_max_on_prefix_index
			for x in range(number_of_right_eat):
				pos = 1 + j
				step = 'R'
				act = str(pos) + ' ' + step
				result.append(act)
		elif last_max_on_prefix_index != i:
			number_of_right_eat = i - last_max_on_prefix_index
			for x in range(number_of_right_eat):
				pos = last_max_on_prefix_index - start_index_last_prefix + 1 + j
				step = 'R'
				act = str(pos) + ' ' + step
				result.append(act)
			number_of_left_eat = last_max_on_prefix_index - start_index_last_prefix
			for x in range(number_of_left_eat):
				pos = number_of_left_eat - x + 1 + j
				step = 'L'
				act = str(pos) + ' ' + step
				result.append(act)
		elif start_index_last_prefix != i:
			possible = False
		start_index_last_prefix = i + 1
		j += 1
	elif sub_b[j] < 0:
		possible = False
	i += 1
if i != n or j != k:
	possible = False
if possible:
	print('YES')
	print('\n'.join(result))
else:
	print('NO')


f = lambda : list(map(int, input().split()))

def g(i, j, k):
	z = y = i
	for x in range(i, j):
		if a[x] > a[y]:
			y = x
	if y > i:
		z = y
	else:
		while a[y] == a[i]:
			y += 1
			if y == j:
				return []
		y -= 1
	l = [str(k + y - x) + ' L' for x in range(i, y)]
	r = [str(k + y - z) + ' R' for x in range(y + 1, j)]
	return r + l if z == i else l + r
(n, a, m, b) = (f()[0], f(), f()[0], f())
d = ['YES']
s = i = k = 0
for (j, q) in enumerate(a, 1):
	s += q
	if k < m and s == b[k]:
		d += g(i, j, k + 1)
		(s, i, k) = (0, j, k + 1)
print('\n'.join(d) if len(d) + m > n and k == m else 'NO')


n = int(input())
before = list(map(int, input().split()))
k = int(input())
after = list(map(int, input().split()))
if sum(before) != sum(after):
	print('NO')
	exit()
result = ['YES']
offset = 0
(left, right) = (-1, -1)
for y in after:
	x = 0
	left = right + 1
	while x != y and right + 1 < n:
		right += 1
		x += before[right]
	if x != y:
		print('NO')
		exit()
	if left == right:
		continue
	big = before[left]
	for i in range(left + 1, right + 1):
		big = max(big, before[i])
	found = False
	for i in range(left, right + 1):
		if before[i] != big:
			continue
		if i > left and before[i - 1] < big:
			for j in range(i, left, -1):
				result.append('%d L' % (1 + i - offset))
				offset += 1
			for j in range(i, right):
				result.append('%d R' % (1 + j - offset))
				offset += 1
			found = True
			break
		if i < right and before[i + 1] < big:
			for j in range(i, right):
				result.append('%d R' % (1 + i - offset))
			for j in range(i, left, -1):
				result.append('%d L' % (1 + j - offset))
			offset += right - left
			found = True
			break
	if not found:
		print('NO')
		exit()
print('\n'.join(result))