A permutation is a sequence of integers from $1$ to $n$ of length $n$ containing each number exactly once. For example, $[1]$, $[4, 3, 5, 1, 2]$, $[3, 2, 1]$ — are permutations, and $[1, 1]$, $[4, 3, 1]$, $[2, 3, 4]$ — no.

Permutation $a$ is lexicographically smaller than permutation $b$ (they have the same length $n$), if in the first index $i$ in which they differ, $a[i] < b[i]$. For example, the permutation $[1, 3, 2, 4]$ is lexicographically smaller than the permutation $[1, 3, 4, 2]$, because the first two elements are equal, and the third element in the first permutation is smaller than in the second.

The next permutation for a permutation $a$ of length $n$ — is the lexicographically smallest permutation $b$ of length $n$ that lexicographically larger than $a$. For example:   for permutation $[2, 1, 4, 3]$ the next permutation is $[2, 3, 1, 4]$;  for permutation $[1, 2, 3]$ the next permutation is $[1, 3, 2]$;  for permutation $[2, 1]$ next permutation does not exist. 

You are given the number $n$ — the length of the initial permutation. The initial permutation has the form $a = [1, 2, \ldots, n]$. In other words, $a[i] = i$ ($1 \le i \le n$).

You need to process $q$ queries of two types:   $1$ $l$ $r$: query for the sum of all elements on the segment $[l, r]$. More formally, you need to find $a[l] + a[l + 1] + \ldots + a[r]$.  $2$ $x$: $x$ times replace the current permutation with the next permutation. For example, if $x=2$ and the current permutation has the form $[1, 3, 4, 2]$, then we should perform such a chain of replacements $[1, 3, 4, 2] \rightarrow [1, 4, 2, 3] \rightarrow [1, 4, 3, 2]$. 

For each query of the $1$-st type output the required sum.


-----Input-----

The first line contains two integers $n$ ($2 \le n \le 2 \cdot 10^5$) and $q$ ($1 \le q \le 2 \cdot 10^5$), where $n$ — the length of the initial permutation, and $q$ — the number of queries.

The next $q$ lines contain a single query of the $1$-st or $2$-nd type. The $1$-st type query consists of three integers $1$, $l$ and $r$ $(1 \le l \le r \le n)$, the $2$-nd type query consists of two integers $2$ and $x$ $(1 \le x \le 10^5)$.

It is guaranteed that all requests of the $2$-nd type are possible to process.


-----Output-----

For each query of the $1$-st type, output on a separate line one integer — the required sum.


-----Example-----
Input
4 4
1 2 4
2 3
1 1 2
1 3 4

Output
9
4
6



-----Note-----

Initially, the permutation has the form $[1, 2, 3, 4]$. Queries processing is as follows:   $2 + 3 + 4 = 9$;  $[1, 2, 3, 4] \rightarrow [1, 2, 4, 3] \rightarrow [1, 3, 2, 4] \rightarrow [1, 3, 4, 2]$;  $1 + 3 = 4$;  $4 + 2 = 6$

Source: codeforces | Difficulty: MEDIUM


Solutions:
from math import *
(n, q) = list(map(int, input().split()))
after = min(15, n)
before = n - after

def calc(left, right):
	return right * (right + 1) // 2 - left * (left - 1) // 2

def perm(i):
	unused = [i + 1 for i in range(after)]
	arr = []
	for j in reversed(range(after)):
		cur = i // factorial(j)
		arr.append(unused[cur])
		del unused[cur]
		i -= cur * factorial(j)
	return arr
p = perm(0)
x = 0
for _ in range(q):
	line = list(map(int, input().split()))
	if len(line) == 3:
		l = line[1]
		r = line[2]
		res = 0
		if l <= before:
			if r <= before:
				res += r * (r + 1) // 2
			else:
				res += before * (before + 1) // 2
			res -= l * (l - 1) // 2
			l = before + 1
		if r > before:
			res += sum(p[l - 1 - before:r - before]) + (r - l + 1) * before
		print(res)
	else:
		x += line[1]
		p = perm(x)


import bisect
factor = [1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 87178291200]
(n, q) = map(int, input().split())

def getpermute(x, n):
	m = bisect.bisect(factor, x) + 1
	output = [0] * m
	have = [i for i in range(m)]
	for i in range(m - 1):
		add = x // factor[m - i - 2]
		x -= add * factor[m - i - 2]
		output[i] = have[add] + (n - m + 1)
		have.pop(add)
	output[-1] = have[0] + (n - m + 1)
	return output
t = 1
x = 0
arr = [n]
while t <= q:
	inp = list(map(int, input().split()))
	if inp[0] == 2:
		x += inp[1]
		arr = getpermute(x, n)
		t += 1
		continue
	(l, r) = (inp[1], inp[2])
	base = n - len(arr)
	if r <= base:
		ans = (l + r) * (r - l + 1) // 2
		print(ans)
	elif l <= base:
		ans = (l + base) * (base - l + 1) // 2
		ans += sum(arr[:r - base])
		print(ans)
	else:
		ans = sum(arr[l - base - 1:r - base])
		print(ans)
	t += 1


import sys
input = sys.stdin.readline
fact = [1]
for i in range(1, 15 + 1):
	fact.append(fact[-1] * i)

def generate_perm(n, m):
	ret = []
	if n <= 15:
		cand = [i + 1 for i in range(n)]
	else:
		cand = [i + 1 for i in range(n - 15, n)]
	for i in range(1, min(15 + 1, n + 1)):
		pos = m // fact[min(15, n) - i]
		m %= fact[min(15, n) - i]
		ret.append(cand[pos])
		del cand[pos]
	return ret
(n, q) = map(int, input().split())
ids = 0
if n <= 15:
	perm = [i + 1 for i in range(n)]
else:
	perm = [i + 1 for i in range(n - 15, n)]
for _ in range(q):
	query = list(map(int, input().split()))
	if query[0] == 1:
		(l, r) = (query[1], query[2])
		if n <= 15:
			print(sum(perm[l - 1:r]))
		elif l <= n - 15:
			if r <= n - 15:
				print(r * (r + 1) // 2 - l * (l - 1) // 2)
			else:
				print((n - 15) * (n - 14) // 2 - l * (l - 1) // 2 + sum(perm[0:r - (n - 15)]))
		else:
			print(sum(perm[l - 1 - (n - 15):r - (n - 15)]))
	elif query[0] == 2:
		ids += query[1]
		perm = generate_perm(n, ids)


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
import os
import sys
from io import BytesIO, IOBase
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')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())
farr = [1]
ifa = []

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	ifa.append(pow(farr[-1], mod - 2, mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa = ifa[::-1]

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def linc(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t > f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rinc(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t < f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def ldec(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t < f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rdec(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t > f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def binfun(x):
	c = 0
	for w in arr:
		c += ceil(w / x)
	return c

def lowbit(n):
	return n & -n

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class smt:

	def __init__(self, l, r, arr):
		self.l = l
		self.r = r
		self.value = (1 << 31) - 1 if l < r else arr[l]
		mid = (l + r) // 2
		if l < r:
			self.left = smt(l, mid, arr)
			self.right = smt(mid + 1, r, arr)
			self.value &= self.left.value & self.right.value

	def setvalue(self, x, val):
		if self.l == self.r:
			self.value = val
			return
		mid = (self.l + self.r) // 2
		if x <= mid:
			self.left.setvalue(x, val)
		else:
			self.right.setvalue(x, val)
		self.value = self.left.value & self.right.value

	def ask(self, l, r):
		if l <= self.l and r >= self.r:
			return self.value
		val = (1 << 31) - 1
		mid = (self.l + self.r) // 2
		if l <= mid:
			val &= self.left.ask(l, r)
		if r > mid:
			val &= self.right.ask(l, r)
		return val

class DSU:

	def __init__(self, n):
		self.c = [-1] * n

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def find(self, x):
		if self.c[x] < 0:
			return x
		self.c[x] = self.find(self.c[x])
		return self.c[x]

	def union(self, u, v):
		(u, v) = (self.find(u), self.find(v))
		if u == v:
			return False
		if self.c[u] < self.c[v]:
			(u, v) = (v, u)
		self.c[u] += self.c[v]
		self.c[v] = u
		return True

	def size(self, x):
		return -self.c[self.find(x)]

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return prime

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		for v in graph[u]:
			if v not in d or d[v] > d[u] + graph[u][v]:
				d[v] = d[u] + graph[u][v]
				heappush(heap, (d[v], v))
	return d

def GP(it):
	res = []
	for (ch, g) in groupby(it):
		res.append((ch, len(list(g))))
	return res

class DLN:

	def __init__(self, val):
		self.val = val
		self.pre = None
		self.next = None

def cal(x, k):
	ans = []
	used = (1 << k) - 1
	for i in range(k - 1, -1, -1):
		(cur, x) = divmod(x, fact(i))
		c = 0
		for j in range(k):
			if used & 1 << j:
				c += 1
			if c == cur + 1:
				ans.append(j + 1)
				used ^= 1 << j
				break
	return ans
t = 1
for i in range(t):
	(n, q) = RL()
	cur = 0
	k = min(n, 14)
	for i in range(q):
		res = RLL()
		if len(res) == 2:
			cur += res[1]
		else:
			(l, r) = res[1:]
			if r <= n - k:
				ans = (l + r) * (r - l + 1) // 2
			else:
				ans = 0
				if l <= n - k:
					ans = (l + n - k) * (n - k - l + 1) // 2
					l = n - k + 1
				res = cal(cur, k)
				ans += sum(res[l - n + k - 1:r - n + k]) + (r - l + 1) * (n - k)
			print(ans)


import io, os
from math import *
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
manual = 20
(n, Q) = map(int, input().split())
after = min(manual, n)
before = n - after
ind = 0

def unrankperm(i):
	unused = [i + 1 for i in range(after)]
	r = []
	for j in range(after)[::-1]:
		use = i // factorial(j)
		r.append(unused[use])
		del unused[use]
		i -= use * factorial(j)
	return r
p = unrankperm(ind)
for _ in range(Q):
	q = list(map(int, input().split()))
	if q[0] == 1:
		(l, r) = q[1:]
		amt = 0
		if l <= before:
			if r <= before:
				amt += r * (r + 1) // 2
			else:
				amt += before * (before + 1) // 2
			amt -= l * (l - 1) // 2
			l = before + 1
		if r > before:
			amt += sum(p[l - 1 - before:r - before]) + (r - l + 1) * before
		print(amt)
	else:
		ind += q[1]
		p = unrankperm(ind)


(n, Q) = list(map(int, input().split()))
cnt = 1
F = [1]
for i in range(1, 17):
	F.append(F[-1] * i)
st = max(0, n - 15)
a = [0] * (n + 1)
vs = [0] * (n + 1)
for i in range(1, n + 1):
	a[i] = a[i - 1] + i
for _ in range(Q):
	q = list(map(int, input().split()))
	if q[0] == 1:
		(l, r) = (q[1], q[2])
		print(a[r] - a[l - 1])
		continue
	x = q[1]
	cnt += x
	hav = cnt
	for i in range(st, n + 1):
		vs[i] = 0
	for i in range(st, n):
		tmp = 0
		for j in range(st, n + 1):
			if not vs[j]:
				tmp += F[n - i]
				if tmp >= hav:
					hav -= tmp - F[n - i]
					a[i] = a[i - 1] + j
					vs[j] = 1
					break
	for i in range(st, n + 1):
		if not vs[i]:
			a[n] = a[n - 1] + i


from math import factorial

def short_perm_to_num(perm, n):
	result = 0
	is_used = {}
	for i in range(n):
		for j in range(perm[i]):
			if not j in is_used:
				result += factorial(n - 1 - i)
		is_used[perm[i]] = True
	return result

def perm_to_num(perm, n):
	max_len = 15
	if n <= max_len:
		return short_perm_to_num(perm, n)
	else:
		last_part = [x - (n - max_len) for x in perm[n - max_len:]]
		return short_perm_to_num(last_part, max_len)

def short_num_to_perm(num, n):
	is_used = {}
	perm = []
	for i in range(n):
		deg = num // factorial(n - 1 - i)
		num %= factorial(n - 1 - i)
		j = 0
		while j in is_used:
			j += 1
		deg_of_j = 0
		while deg_of_j < deg or j in is_used:
			if not j in is_used:
				deg_of_j += 1
			j += 1
		perm.append(j)
		is_used[j] = True
	return perm

def num_to_perm(num, n):
	max_len = 15
	if n <= max_len:
		return short_num_to_perm(num, n)
	else:
		last_part_low = short_num_to_perm(num, max_len)
		last_part = [x + (n - max_len) for x in last_part_low]
		return last_part
[n, q] = [int(x) for x in input().split()]
full_perm = [i for i in range(0, n)]
num_of_perm = 0
for quarry_num in range(q):
	quarry = [int(x) for x in input().split()]
	if quarry[0] == 1:
		perm = num_to_perm(num_of_perm, n)
		l = quarry[1]
		r = quarry[2]
		if n <= 15:
			print(sum(perm[l - 1:r]) + r - l + 1)
		elif l - 1 >= n - 15:
			print(sum(perm[l - 1 - n + 15:r - n + 15]) + r - l + 1)
		elif r < n - 15:
			s = (l - 1 + r - 1) * (r - 1 - l + 1 + 1) // 2
			print(s + r - l + 1)
		else:
			s = (l - 1 + n - 16) * (n - 16 - l + 2) // 2
			rest = sum(perm[:r - n + 15])
			print(s + rest + r - l + 1)
	if quarry[0] == 2:
		num_of_perm += quarry[1]


fact = [1, 1]
for i in range(2, 15):
	fact.append(fact[-1] * i)

def per(n, x):
	arr = list(range(1, n + 1))
	p = [0] * n
	for i in range(n):
		j = x // fact[n - 1 - i]
		p[i] = arr[j]
		arr.pop(j)
		x %= fact[n - 1 - i]
	return p

def solve():
	(n, qq) = map(int, input().split())
	x = 0
	if n <= 14:
		for i in range(qq):
			q = list(map(int, input().split()))
			if q[0] == 2:
				x += q[1]
			else:
				print(sum(per(n, x)[q[1] - 1:q[2]]))
	else:
		for i in range(qq):
			q = list(map(int, input().split()))
			if q[0] == 2:
				x += q[1]
			else:
				(l, r) = (q[1], q[2])
				if r + 14 <= n:
					print((l + r) * (r - l + 1) // 2)
				elif l + 14 <= n:
					print((l + n - 14) * (n - 13 - l) // 2 + sum(per(14, x)[:r + 14 - n]) + (n - 14) * (r + 14 - n))
				else:
					print(sum(per(14, x)[l + 13 - n:r + 14 - n]) + (n - 14) * (r - l + 1))
import sys
input = lambda : sys.stdin.readline().rstrip()
solve()


(n, q) = map(int, input().split())
A = [i for i in range(1, n + 1)]
prefix = [0] * (n + 1)
prefix[0] = A[0]
for i in range(1, n):
	prefix[i] = prefix[i - 1] + A[i]
used0 = A[max(0, n - 15):]
used0.sort()
used_d = {}
for i in used0:
	used_d[i] = 0
fact = [0] * n
fact[-1] = 1
for i in range(n - 2, max(-1, n - 16), -1):
	fact[i] = fact[i + 1] * (n - 1 - i)
number = 1

def permutation_by_number(number):
	for i in range(max(0, n - 15), n):
		position = max(0, (number - 1) // fact[i])
		counter = 0
		for j in used_d:
			if position == counter and (not used_d[j]):
				A[i] = j
				used_d[j] = 1
				break
			if not used_d[j]:
				counter += 1
		number -= position * fact[i]
	for i in range(max(0, n - 15), n):
		prefix[i] = prefix[i - 1] + A[i]
for i in range(q):
	t = list(map(int, input().split()))
	if t[0] == 1:
		(l, r) = (t[1], t[2])
		print(prefix[r - 1] - prefix[l - 2])
	else:
		for j in used_d:
			used_d[j] = 0
		x = t[1]
		number += x
		permutation_by_number(number)


def modify(rest):
	for i in range(len(rest)):
		prefix[-len(rest) + i] = prefix[-len(rest) + (i - 1)] + rest[i]

def next_perm_direct(permc):
	rest = [x for x in range(max(1, n - 14), n + 1)]
	temp = 1
	for i in range(1, len(rest)):
		temp = temp * i
	for i in range(len(rest) - 1):
		if permc >= temp:
			change = permc // temp
			(rest[i], rest[i + change]) = (rest[i + change], rest[i])
			rest = rest[:i + 1] + list(sorted(rest[i + 1:]))
			permc = permc % temp
		temp = temp // (len(rest) - 1 - i)
	modify(rest)
(n, q) = list(map(int, input().split()))
prefix = [0 for i in range(n + 1)]
for i in range(1, n + 1):
	prefix[i] = prefix[i - 1] + i
permc = 0
for _ in range(q):
	quer = list(map(int, input().split()))
	if len(quer) == 2:
		permc += quer[1]
		next_perm_direct(permc)
	else:
		(l, r) = (quer[1], quer[2])
		print(prefix[r] - prefix[l - 1])


import io, os
from math import *
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(n, q) = list(map(int, input().split()))
after = min(15, n)
before = n - after

def perm(i):
	unused = [i + 1 for i in range(after)]
	arr = []
	for j in reversed(range(after)):
		cur = i // factorial(j)
		arr.append(unused[cur])
		del unused[cur]
		i -= cur * factorial(j)
	return arr
p = perm(0)
x = 0
for _ in range(q):
	line = list(map(int, input().split()))
	if len(line) == 3:
		l = line[1]
		r = line[2]
		res = 0
		if l <= before:
			if r <= before:
				res += r * (r + 1) // 2
			else:
				res += before * (before + 1) // 2
			res -= l * (l - 1) // 2
			l = before + 1
		if r > before:
			res += sum(p[l - 1 - before:r - before]) + (r - l + 1) * before
		print(res)
	else:
		x += line[1]
		p = perm(x)


import sys
input = sys.stdin.readline
(n, q) = list(map(int, input().split()))
X = list(range(1, n + 1))
S = [0]
for x in X:
	S.append(S[-1] + x)
FACT = [1, 1]
for i in range(2, 16):
	FACT.append(FACT[-1] * i)
A = X[-15:]
LEN = len(A)

def calc(x):
	AA = [a for a in A]
	ANS = []
	for i in range(LEN, 0, -1):
		q = x // FACT[i - 1]
		x -= q * FACT[i - 1]
		ANS.append(AA.pop(q))
	return ANS
NOW = 0
for queries in range(q):
	Q = list(map(int, input().split()))
	if Q[0] == 2:
		NOW += Q[1]
		continue
	(l, r) = (Q[1], Q[2])
	if r <= n - LEN:
		print(S[r] - S[l - 1])
		continue
	elif l <= n - LEN:
		ANS = S[-LEN - 1] - S[l - 1]
		l = 0
		r -= n - LEN + 1
	else:
		ANS = 0
		l -= n - LEN + 1
		r -= n - LEN + 1
	NOWA = calc(NOW)
	print(ANS + sum(NOWA[l:r + 1]))


import sys
import itertools as it
import math as mt
import bisect as bi
import collections as cc
import itertools as it
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(n, q) = I()
ar = list(range(1, n + 1))
pref = [0]
for i in range(n):
	pref.append(pref[-1] + ar[i])
arr = ar[-15:]
clen = len(arr)
nxt = 0
fact = [1, 1]
for i in range(2, 20):
	fact.append(fact[-1] * i)

def ch(n):
	temp = [i for i in arr]
	re = []
	for i in range(clen, 0, -1):
		cur = n // fact[i - 1]
		n -= cur * fact[i - 1]
		re.append(temp.pop(cur))
	return re
for tc in range(q):
	now = I()
	if now[0] == 2:
		nxt += now[1]
		continue
	(left, right) = (now[1], now[2])
	if right <= n - clen:
		print(pref[right] - pref[left - 1])
		continue
	elif left <= n - clen:
		ans = pref[-clen - 1] - pref[left - 1]
		left = 0
		right -= n - clen + 1
	else:
		ans = 0
		left -= n - clen + 1
		right -= n - clen + 1
	cur = ch(nxt)
	print(ans + sum(cur[left:right + 1]))