Read problems statements in Mandarin Chinese  and Russian. 

You are given an array A of N integers. You are to fulfill M queries. Each query has one of the following three types:

C d : Rotate the array A clockwise by d units.
A d : Rotate the array A anticlockwise by d units.
R d : Query for the value of the element, currently being the d-th in the array A.

------ Input ------ 

The first line contains two numbers - N and M respectively.

The next line contains N space separated Integers, denoting the array A.
Each of the following M lines contains a query in the one of the forms described above.

------ Output ------ 

For each query of type R output the answer on a separate line.

------ Constraints ------ 

$1 ≤ N ≤ 100000 $
$1 ≤ M ≤ 100000 $
$1 ≤ d ≤ N, in all the queries$
$1 ≤ elements of A ≤ 1000000$
$The array A and the queries of the type R are 1-based.
$ 

----- Sample Input 1 ------ 
5 5
5 4 3 3 9
R 1
C 4
R 5
A 3
R 2
----- Sample Output 1 ------ 
5
3
3
----- explanation 1 ------ 

The initial array : 5 4 3 3 9
The answer for R 1 : 5
The array after C 4 :  9 5 4 3 3
The answer for R 5 : 3
The array after A 3 : 4 3 3 9 5
The answer for R 2 : 3

Difficulty: MEDIUM

Solutions:
(N, M) = map(int, input().split(' '))
arr = list(map(int, input().split(' ')))
query = []
for _ in range(M):
	query.append(list(input().split()))
pointer = 0
for each in query:
	if each[0] == 'C':
		pointer += int(each[1])
	elif each[0] == 'A':
		pointer -= int(each[1])
	else:
		print(arr[(pointer + int(each[1]) - 1) % N])


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
x = 0
for _ in range(m):
	(b, c) = input().split()
	c = int(c)
	if b == 'R':
		print(a[(c - 1 + x) % n])
	elif b == 'C':
		x += c
	elif b == 'A':
		x -= c


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
(x, y) = (0, 0)
for i in range(m):
	s = input().split()
	r = int(s[1])
	if s[0] == 'C':
		x = x + r
	elif s[0] == 'A':
		x -= r
	else:
		print(l[(x + r - 1) % n])


def solution(L, net, d):
	temp = net % len(L)
	d += temp
	if d % len(L) == 0:
		return L[len(L) - 1]
	return L[d % len(L) - 1]
(N, M) = map(int, input().split())
L = list(map(int, input().split()))
net = 0
for m in range(M):
	(move, d) = map(str, input().split())
	if move == 'C':
		net += int(d)
	if move == 'A':
		net -= int(d)
	elif move == 'R':
		print(solution(L, net, int(d)))


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
ref = 0
for i in range(m):
	(q, d) = input().split()
	if q == 'A':
		ref -= int(d)
	elif q == 'C':
		ref += int(d)
	else:
		print(l[(ref + int(d) - 1) % n])


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
i = 0
for _ in range(m):
	(s, k) = input().split()
	c = int(k)
	if s == 'A':
		i -= c
	elif s == 'C':
		i += c
	else:
		pos = (i + c) % n - 1
		print(a[pos])


(n, m) = map(int, input().strip().split(' '))
a = list(map(int, input().strip().split(' ')))
f = 0
for _ in range(m):
	(c, d) = input().strip().split(' ')
	d = int(d)
	if c == 'C':
		f = (f + d) % n
	elif c == 'A':
		f = (f + (n - d)) % n
	else:
		print(a[(f + d - 1) % n])


(N, M) = map(int, input().split())
s = input()
A = list(map(int, s.split()))
list_1 = []
list_2 = []
for i in range(M):
	(a, b) = map(str, input().split(' '))
	b = int(b)
	list_1.append(a)
	list_2.append(b)
from collections import deque
count = 0
A = deque(A)
for X in list_1:
	if X == 'R':
		print(A[list_2[count] - 1])
	if X == 'A':
		A.rotate(list_2[count])
	if X == 'C':
		A.rotate(-1 * list_2[count])
	count += 1


import sys

def main():
	(N, M) = [int(x) for x in sys.stdin.readline().split()]
	A = [int(x) for x in sys.stdin.readline().split()]
	offset = 0
	for _ in range(M):
		(op, d) = [x for x in sys.stdin.readline().split()]
		d = int(d)
		if op == 'C':
			offset = (offset + d) % N
		elif op == 'A':
			offset = (offset - d + N) % N
		else:
			print(A[(d - 1 + offset) % N])
main()


from collections import deque
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a = deque(a)
for _ in range(m):
	(instruction, d) = map(str, input().split())
	d = int(d)
	if instruction == 'C':
		a.rotate(-d)
	elif instruction == 'A':
		a.rotate(d)
	elif instruction == 'R':
		print(a[d - 1])


(n, m) = map(int, input().split())
a = [int(j) for j in input().split()]
strt = 0
for i in range(m):
	s = input().split()
	d = int(s[1])
	if s[0] == 'C':
		strt += d
	elif s[0] == 'A':
		strt -= d
	else:
		print(a[(strt + d - 1) % n])


a = input().split()
n = int(a[0])
m = int(a[1])
a = input().split()
a = [int(j) for j in a]
shift = 0
for j in range(m):
	q = input().split()
	if q[0] == 'R':
		print(a[(shift + int(q[1]) - 1) % n])
	elif q[0] == 'C':
		shift += int(q[1])
	else:
		shift += n - int(q[1])


import collections
(n, m) = map(int, input().split())
arr = [int(i) for i in input().split()]
e = collections.deque(arr)
for j in range(m):
	(s, k) = map(str, input().split())
	k = int(k)
	result = []
	if s == 'R':
		print(e[k - 1])
	elif s == 'C':
		e.rotate(-k)
	elif s == 'A':
		e.rotate(k)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
pointer = 0
for i in range(m):
	(a, b) = map(str, input().split())
	if a == 'R':
		print(l[(pointer + int(b) - 1) % n])
	elif a == 'C':
		pointer = (pointer + int(b) % n) % n
	else:
		pointer = (pointer - int(b) % n) % n


def mod(val, n):
	if val >= 0:
		return val
	while val < 0:
		val += n
	return val
temp = list(map(int, input().split()))
n = temp[0]
m = temp[1]
a = list(map(int, input().split()))
start = 0
end = n - 1
for t in range(m):
	temp = list(input().split())
	d = int(temp[1])
	c = temp[0]
	if c == 'C':
		start = (start + d) % n
		end = (end + d) % n
	elif c == 'A':
		start = mod(start - d, n)
		end = mod(end - d, n)
	else:
		x = (start + d - 1) % n
		print(a[x])


(n, m) = map(int, input().split())
ar = list(map(int, input().split()))
(clock, anti) = (0, 0)
for _ in range(m):
	s = input().split()
	num = int(s[1])
	if s[0] == 'R':
		num -= 1
		res = (anti - clock) % n
		res = -res % n
		print(ar[(res + num) % n])
	elif s[0] == 'C':
		clock = (clock + num) % n
	else:
		anti = (anti + num) % n


(T, Q) = input().split()
T = int(T)
Q = int(Q)
aa = input().split()
rot = 0
for i in range(0, Q):
	(a, b) = input().split()
	b = int(b)
	if a == 'C':
		rot += b
	elif a == 'A':
		rot += T - b
	else:
		print(aa[(b + rot - 1) % T])


from sys import stdin, stdout
(n, m) = map(int, stdin.readline().split())
l = list(map(int, stdin.readline().split()))
c = 0
for i in range(m):
	(a, b) = map(str, stdin.readline().split())
	b = int(b)
	if a == 'C':
		c += b
	elif a == 'A':
		c -= b
	else:
		c1 = c + b
		p = c1 % n
		print(l[p - 1])


import math
import sys
import string
(n, m) = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
i = 0
while m:
	c = sys.stdin.read(1)
	d = int(input())
	if c == 'R':
		print(arr[(d + i - 1) % n])
	elif c == 'C':
		i = (i + d) % n
	else:
		i = (i + n - d) % n
	m -= 1


(n, m) = map(int, input().strip().split())
A = [int(x) for x in input().strip().split()]
pointer = 0
for i in range(m):
	query = input().split()
	(direction, d) = (query[0], int(query[1]))
	if direction == 'R':
		d = (d - 1 + pointer) % n
		print(A[d])
	elif direction == 'C':
		pointer = (d + pointer) % n
	else:
		pointer = (pointer - d) % n


(n, s) = map(int, input().split())
list1 = list(map(int, input().split()))
m = 0
for x in range(s):
	(l, d) = map(str, input().split())
	d = int(d)
	if l == 'R':
		print(list1[((d + m - 1) % n + n) % n])
	elif l == 'C':
		m += d
	elif l == 'A':
		m -= d


(N, Q) = map(int, input().split())
A = list(map(int, input().split()))
rotate = 0
for _ in range(Q):
	(Op, d) = input().split()
	d = int(d)
	if Op == 'C':
		rotate += d
	elif Op == 'A':
		rotate -= d
	else:
		print(A[(d + rotate - 1) % N])


[n, q] = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
s = 0
for _ in range(q):
	b = input().split()
	if b[0] == 'R':
		print(a[(s + int(b[1]) - 1) % n])
	elif b[0] == 'C':
		s += int(b[1])
	else:
		s -= int(b[1])


(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
pos = 0
i = 0
for i in range(m):
	(ch, d) = list(input().split())
	ch = str(ch)
	d = int(d)
	if ch == 'R':
		print(a[(pos + d - 1) % n])
	elif ch == 'A':
		pos = pos - d + n
		pos %= n
	else:
		pos += d
		pos %= n


(N, M) = map(int, input().split())
A = list(map(int, input().split()))
x = 0
for i in range(M):
	(s, n) = input().split()
	n = int(n)
	if s[0] == 'C':
		x += n
	elif s[0] == 'A':
		x -= n
	elif s[0] == 'R':
		print(A[(n - 1 + x) % N])


(n, m) = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
s = 0
for m in range(m):
	(dire, val) = input().split()
	val = int(val)
	if dire == 'C':
		s += val
	elif dire == 'A':
		s -= val
	else:
		print(arr[(s + val - 1) % n])


from sys import stdin, stdout
(n, m) = map(int, stdin.readline().split())
llist = list(map(int, stdin.readline().split()))
c = 0
for _ in range(m):
	(q, d) = map(str, stdin.readline().split())
	d = int(d)
	if q == 'C':
		c += d
	if q == 'A':
		c -= d
	if q == 'R':
		print(llist[(d - 1 + c) % n])


(n, m) = map(int, input().split())
offset = 0
arr = list(map(int, input().split()))
for _ in range(m):
	(q, p) = map(str, input().split())
	p = int(p)
	if q == 'C':
		offset = (offset + p) % n
	elif q == 'A':
		offset = (offset - p) % n
	else:
		print(arr[(offset + p - 1) % n])


from collections import deque
(N, M) = map(int, input().split())
Ai = list(map(int, input().split()))[:N]
Ai = deque(Ai)
for i in range(M):
	(query, d) = input().split()
	d = int(d)
	if query == 'C':
		Ai.rotate(-d)
	elif query == 'A':
		Ai.rotate(d)
	else:
		print(Ai[d - 1])


from collections import deque
(l, m) = map(int, input().split())
a = list(map(int, input().split()))
a = deque(a)
for j in range(m):
	(s, n) = input().split()
	if s == 'C':
		a.rotate(-int(n))
	elif s[0] == 'A':
		a.rotate(int(n))
	else:
		print(a[int(n) - 1])


(N, M) = [int(s) for s in input().split()]
A = [int(s) for s in input().split()]
offset = -1
for _ in range(M):
	I = input()
	if I[0] == 'C':
		offset += int(I[2:])
	elif I[0] == 'A':
		offset -= int(I[2:])
	else:
		print(A[(int(I[2:]) + offset) % N])


(n, m) = map(int, input().split())
a = input().split()
c = 0
for i in range(m):
	d = input().split()
	if d[0] == 'R':
		ind = (int(d[1]) - c) % n
		print(a[ind - 1])
	elif d[0] == 'C':
		c = c + (n - int(d[1]))
	elif d[0] == 'A':
		c = c + int(d[1])


(n, k) = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
head = 0
for i in range(k):
	(opp, pos) = input().strip().split()
	if opp == 'R':
		print(a[(head + int(pos) - 1) % n])
	elif opp == 'C':
		head = (int(pos) + head) % n
	elif opp == 'A':
		head = (head - int(pos) + n) % n


(x, y) = map(int, input().split())
a = list(map(int, input().split()))
count = 0
for i in range(y):
	(p, q) = input().split()
	q = int(q)
	if p == 'C':
		count += q
	elif p == 'A':
		count -= q
	else:
		print(a[(q - 1 + count) % x])


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
start = 0
end = n - 1
for i in range(m):
	tmp = input().split()
	if tmp[0] == 'R':
		idx = (int(tmp[1]) - 1 + start) % n
		print(arr[idx])
	elif tmp[0] == 'C':
		start = (start + int(tmp[1])) % n
		end = (end + int(tmp[1])) % n
	else:
		start = (start - int(tmp[1])) % n
		end = (end - int(tmp[1])) % n


from bisect import bisect_right as br
from bisect import bisect_left as bl
from collections import *
from itertools import *
import functools
import sys
import math
import random
import re
MAX = sys.maxsize
MAXN = 10 ** 5 + 10
MOD = 10 ** 9 + 9

def isprime(n):
	n = abs(int(n))
	if n < 2:
		return False
	if n == 2:
		return True
	if not n & 1:
		return False
	for x in range(3, int(n ** 0.5) + 1, 2):
		if n % x == 0:
			return False
	return True

def mhd(a, b, x, y):
	return abs(a - x) + abs(b - y)

def numIN(x=' '):
	return map(int, sys.stdin.readline().strip().split(x))

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def dis(x, y):
	a = y[0] - x[0]
	b = x[1] - y[1]
	return (a * a + b * b) ** 0.5

def lgcd(a):
	g = a[0]
	for i in range(1, len(a)):
		g = math.gcd(g, a[i])
	return g
(n, m) = numIN()
a = list(numIN())
cnt = 0
for _ in range(m):
	(x, y) = charIN()
	y = int(y)
	if x == 'C':
		cnt -= y
	elif x == 'A':
		cnt += y
	else:
		z = cnt % n
		z = (y - 1 - z) % n
		print(a[z])


(numberOfEleInArr, numberOfQueries) = map(int, input().split())
array = input().split()
arrayLen = len(array)
index = 0
for qn in range(numberOfQueries):
	inputArr = input().split()
	command = inputArr[0]
	number = int(inputArr[1])
	if command == 'R':
		number -= 1
		if index == 0:
			print(array[number])
		else:
			print(array[(index + number) % arrayLen])
	elif command == 'C':
		index = (index + number) % arrayLen
	else:
		index = (index - number + arrayLen) % arrayLen


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
count = 0
for _ in range(m):
	q = input().split()
	c = int(q[1])
	if q[0] == 'C':
		count += c
	elif q[0] == 'A':
		count -= c
	else:
		print(a[(c - 1 + count) % n])


(N, M) = map(int, input().split())
A = list(map(int, input().split()))
k = 0
for _ in range(M):
	li = input().split()
	(a, b) = (li[0], int(li[1]))
	if a == 'C':
		k += b
	elif a == 'A':
		k -= b
	else:
		print(A[((k + b - 1) % N + N) % N])


(n, q) = map(int, input().split())
arr = list(map(int, input().split()))
offset = 0
for i in range(q):
	query = input().split()
	mag = int(query[1])
	if query[0] == 'C':
		offset -= mag
		if offset < 0:
			offset += n
	elif query[0] == 'A':
		offset += mag
	else:
		print(arr[(mag - offset - 1) % n])


(n, m) = list(map(int, input().split()))
l = list(map(int, input().split()))
c = 0
for i in range(m):
	(a, b) = list(map(str, input().split()))
	b = int(b)
	if a == 'C':
		c += b
	elif a == 'A':
		c -= b
	else:
		c1 = c + b
		p = c1 % n
		print(l[p - 1])


(n, m) = list(map(int, input().split()))
arr = list(map(int, input().split()))
index = 0
for i in range(m):
	(op, d) = list(input().split())
	op = str(op)
	d = int(d)
	if op == 'R':
		d -= 1
		if index == 0:
			print(arr[d])
		else:
			print(arr[(index + d) % n])
	elif op == 'C':
		index = (index + d) % n
	elif op == 'A':
		index = (index - d + n) % n


from sys import stdin, stdout
(n, m) = map(int, stdin.readline().split())
a = [0]
a.extend(list(map(int, stdin.readline().split())))
b = {i: i + 1 for i in range(n - 1)}
b[n - 1] = 0
start = 0
end = n - 1
while m:
	m -= 1
	(q, d) = map(str, stdin.readline().split())
	d = int(d)
	if q == 'C':
		start += d
		start %= n
		end = (start - 1) % n
	elif q == 'A':
		start -= d
		start %= n
		end = (start - 1) % n
	else:
		c = (start + d - 1) % n
		print(a[c + 1])


nm = input('')
nm = nm.split()
n = int(nm[0])
m = int(nm[1])
a = input('')
a = a.split()
a = [int(c) for c in a]
d = 0
for query in range(0, m):
	q = input('')
	q = q.split()
	qType = q[0]
	qArg = int(q[1])
	if qType == 'A':
		d -= qArg % len(a)
	elif qType == 'C':
		d += qArg % len(a)
	else:
		qArg -= 1
		qArg += d
		if qArg < 0:
			qArg = abs(qArg) % len(a)
			if qArg != 0:
				qArg = -qArg
		else:
			qArg = abs(qArg) % len(a)
		print(a[qArg])


(N, Q) = map(int, input().split())
A = list(map(int, input().split()))
rotate = 0
for i in range(Q):
	(a, d) = input().split()
	d = int(d)
	if a == 'C':
		rotate += d
	elif a == 'A':
		rotate -= d
	else:
		print(A[(d + rotate - 1) % N])


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
start = 0
for i in range(m):
	s = input().split()
	d = int(s[1])
	if s[0] == 'C':
		start += d
	elif s[0] == 'A':
		start -= d
	else:
		print(a[(start + d - 1) % n])


(n, m) = map(int, input().split())
llist = list(map(int, input().split()))
start = 0
end = n - 1
for _ in range(m):
	(q, d) = map(str, input().split())
	d = int(d)
	if q == 'C':
		start += d
		start %= n
		end = (start - 1) % n
	if q == 'A':
		start -= d
		start %= n
		end = (start - 1) % n
	if q == 'R':
		c = (start + d - 1) % n
		print(llist[c])


from collections import deque
(n, m) = [int(d) for d in input().split()]
a = [int(d) for d in input().split()]
a = deque(a)
for i in range(m):
	(c, d) = [d for d in input().split()]
	c = c
	d = int(d)
	if c == 'R':
		print(a[d - 1])
	elif c == 'C':
		a.rotate(-d)
	else:
		a.rotate(d)


(n, m) = map(int, input().split())
array = list(map(int, input().split()))
sign = 0
for i in range(m):
	(query, angka) = input().split()
	if query == 'A':
		sign = (sign + int(angka)) % len(array)
	elif query == 'C':
		sign = (sign - int(angka)) % len(array)
	elif query == 'R':
		n = len(array)
		indexQuery = (n - sign - 1 + int(angka)) % n
		print(array[indexQuery])


from collections import deque
(n, m) = map(int, input().split())
arr = [int(i) for i in input().split()]
arr = deque(arr)
for i in range(m):
	(tipe, units) = map(str, input().split())
	if tipe == 'C':
		arr.rotate(-int(units))
	elif tipe == 'A':
		arr.rotate(int(units))
	elif tipe == 'R':
		print(arr[int(units) - 1])