Consider a list (list = []). You can perform the following commands:   

insert i e: Insert integer $\boldsymbol{\mathrm{~e~}}$ at position $\boldsymbol{i}$.
print: Print the list.
remove e: Delete the first occurrence of integer $\boldsymbol{\mathrm{~e~}}$.
append e: Insert integer $\boldsymbol{\mathrm{~e~}}$ at the end of the list.  
sort: Sort the list.
pop: Pop the last element from the list.
reverse: Reverse the list.

Initialize your list and read in the value of $n$ followed by $n$ lines of commands where each command will be of the $7$ types listed above. Iterate through each command in order and perform the corresponding operation on your list.  

Example 

$N=4$ 

$append 1$ 

$append 2$ 

$insert 3 1$ 

$print$ 

$append 1$: Append $\mbox{I}$ to the list, $arr=[1]$.  
$append 2$: Append $2$ to the list, $arr=[1,2]$.  
$insert 3 1$: Insert $3$ at index $\mbox{I}$, $arr=[1,3,2]$.  
$print$: Print the array. 

Output:

[1, 3, 2]

Input Format

The first line contains an integer, $n$, denoting the number of commands. 

Each line $\boldsymbol{i}$ of the $n$ subsequent lines contains one of the commands described above.

Constraints

The elements added to the list must be integers.

Output Format

For each command of type print, print the list on a new line.

Sample Input 0
12
insert 0 5
insert 1 10
insert 0 6
print
remove 6
append 9
append 1
sort
print
pop
reverse
print

Sample Output 0
[6, 5, 10]
[1, 5, 9, 10]
[9, 5, 1]

Difficulty: EASY
Tags: Data structures
Skill types: Data structures

Starter code:

Solutions:
T = int(input().strip())
L = []
for t in range(T):
	args = input().strip().split(' ')
	if args[0] == 'append':
		L.append(int(args[1]))
	elif args[0] == 'insert':
		L.insert(int(args[1]), int(args[2]))
	elif args[0] == 'remove':
		L.remove(int(args[1]))
	elif args[0] == 'pop':
		L.pop()
	elif args[0] == 'sort':
		L.sort()
	elif args[0] == 'reverse':
		L.reverse()
	elif args[0] == 'print':
		print(L)


n = int(input())
L = []
for cc in range(n):
	s = input().split()
	for x in range(1, len(s)):
		s[x] = int(s[x])
	if s[0] == 'append':
		L.append(s[1])
	elif s[0] == 'extend':
		L.extend(s[1:])
	elif s[0] == 'insert':
		L.insert(int(s[1]), s[2])
	elif s[0] == 'remove':
		L.remove(s[1])
	elif s[0] == 'pop':
		L.pop()
	elif s[0] == 'index':
		print(L[int(s[1])])
	elif s[0] == 'count':
		print(L.count(s[1]))
	elif s[0] == 'sort':
		L.sort()
	elif s[0] == 'reverse':
		L.reverse()
	else:
		print(L)


l = []
for i in range(int(input())):
	line = input().split()
	if line[0] == 'print':
		print(l)
	else:
		exec('l.' + line[0] + '(' + ','.join(line[1:]) + ')')


L = []
N = int(input())
for i in range(0, N):
	a = input().strip()
	b = a.split()
	if len(b) == 1:
		if (a == 'pop') | (a == 'sort') | (a == 'reverse'):
			eval('L.' + a + '()')
		else:
			eval(a + '(L)')
	elif len(b) == 2:
		eval('L.' + b[0] + '(' + b[1] + ')')
	else:
		eval('L.' + b[0] + '(' + b[1] + ', ' + b[2] + ')')


N = int(input())
L = []
for _ in range(0, N):
	line = input().split()
	if line[0] == 'insert':
		L.insert(int(line[1]), int(line[2]))
	elif line[0] == 'pop':
		L.pop()
	elif line[0] == 'sort':
		L.sort()
	elif line[0] == 'print':
		print(L)
	elif line[0] == 'append':
		L.append(int(line[1]))
	elif line[0] == 'remove':
		L.remove(int(line[1]))
	elif line[0] == 'reverse':
		L.reverse()


L = []
numCmds = int(input())
for i in range(0, numCmds):
	cmd = input().rstrip().split(' ')
	if str(cmd[0]) == 'print':
		print(L)
	else:
		runCmd = 'L.' + cmd[0] + '(' + ','.join(cmd[1:]) + ')'
		eval(runCmd)


def exec_command(command, L, args):
	if command == 'print':
		print(L)
	elif command == 'insert':
		L.insert(args[0], args[1])
	elif command == 'pop':
		L.pop()
	elif command == 'remove':
		L.remove(args[0])
	elif command == 'append':
		L.append(args[0])
	elif command == 'sort':
		L.sort()
	elif command == 'reverse':
		L.reverse()
N = int(input())
L = []
for _ in range(N):
	commands = input().split()
	exec_command(commands[0], L, [int(x) for x in commands[1:]])


n = int(input())
a = []
for i in range(0, n):
	t = input().split()
	if t[0] == 'print':
		print(a)
	elif t[0] == 'index':
		a.index(int(t[1]), int(t[2]))
	elif t[0] == 'sort':
		a.sort()
	elif t[0] == 'remove':
		a.remove(int(t[1]))
	elif t[0] == 'pop':
		a.pop()
	elif t[0] == 'count':
		a.count()
	elif t[0] == 'append':
		a.append(int(t[1]))
	elif t[0] == 'reverse':
		a.reverse()
	elif t[0] == 'extend':
		a.extend(int(t[1]), int(t[2]))
	elif t[0] == 'insert':
		a.insert(int(t[1]), int(t[2]))


x = []
i = 0
n = int(input())
for i in range(0, n):
	try:
		c = input().split()
		if c[0] == 'insert':
			x.insert(int(c[1]), int(c[2]))
		if c[0] == 'print':
			print(x)
		elif c[0] == 'remove':
			x.remove(int(c[1]))
		elif c[0] == 'append':
			x.append(int(c[1]))
		elif c[0] == 'sort':
			x.sort()
		elif c[0] == 'pop':
			x.pop()
		elif c[0] == 'reverse':
			x.reverse()
	except EOFError:
		print('EOF')
		break


ar = []
t = int(input())
for i in range(t):
	args = input().split()
	if len(args) > 1:
		for j in range(1, len(args)):
			args[j] = int(args[j])
	if args[0] == 'insert':
		ar.insert(args[1], args[2])
	elif args[0] == 'append':
		ar.append(args[1])
	elif args[0] == 'pop':
		ar.pop()
	elif args[0] == 'remove':
		ar.remove(args[1])
	elif args[0] == 'sort':
		ar.sort()
	elif args[0] == 'reverse':
		ar.reverse()
	elif args[0] == 'print':
		print(ar)


L = []
for i in range(0, int(input())):
	ipa = input().strip().split(' ')
	if ipa[0] == 'insert':
		i = int(ipa[1])
		x = int(ipa[2])
		L.insert(i, x)
	elif ipa[0] == 'append':
		x = int(ipa[1])
		L.append(x)
	elif ipa[0] == 'remove':
		x = int(ipa[1])
		L.remove(x)
	elif ipa[0] == 'index':
		x = int(ipa[1])
		print(L.index(x))
	elif ipa[0] == 'count':
		x = int(ipa[1])
		print(L.count(x))
	elif ipa[0] == 'pop':
		L.pop()
	elif ipa[0] == 'reverse':
		L.reverse()
	elif ipa[0] == 'sort':
		L.sort()
	elif ipa[0] == 'print':
		print(L)


n = int(input())
i = 0
my_list = []
while i < n:
	command = input().split()
	if command[0] == 'insert':
		my_list.insert(int(command[1]), int(command[2]))
	elif command[0] == 'remove':
		my_list.remove(int(command[1]))
	elif command[0] == 'append':
		my_list.append(int(command[1]))
	elif command[0] == 'sort':
		my_list.sort()
	elif command[0] == 'reverse':
		my_list.reverse()
	elif command[0] == 'pop':
		my_list.pop()
	elif command[0] == 'print':
		print(my_list)
	i += 1


L = list()
n = int(input())
for i in range(1, n + 1):
	c = str(input()).split()
	if c[0] == 'print':
		print(L)
	else:
		if len(c) == 3:
			c = compile('L.{}({}, {})'.format(c[0], int(c[1]), int(c[2])), '', 'exec')
			exec(c)
			continue
		elif len(c) == 2:
			c = compile('L.{}({})'.format(c[0], int(c[1])), '', 'exec')
			exec(c)
			continue
		c = compile('L.{}()'.format(c[0]), '', 'exec')
		eval(c)


N = input()
L = list()
for i in range(int(N)):
	string = input().split()
	if string[0] == 'insert':
		L.insert(int(string[1]), int(string[2]))
	elif string[0].lower() == 'print':
		print(L)
	elif string[0].lower() == 'remove':
		L.remove(int(string[1]))
	elif string[0].lower() == 'append':
		L.append(int(string[1]))
	elif string[0].lower() == 'pop':
		L.pop()
	elif string[0].lower() == 'reverse':
		L.reverse()
	elif string[0].lower() == 'sort':
		L.sort()


N = int(input())
lst = []
for _ in range(0, N):
	s = input().split()
	if s[0] == 'append':
		lst.append(int(s[1]))
	elif s[0] == 'insert':
		lst.insert(int(s[1]), int(s[2]))
	elif s[0] == 'remove':
		lst.remove(int(s[1]))
	elif s[0] == 'pop':
		lst.pop()
	elif s[0] == 'index':
		lst.index(int(s[1]))
	elif s[0] == 'count':
		lst.count(int(s[1]))
	elif s[0] == 'sort':
		lst.sort()
	elif s[0] == 'reverse':
		lst.reverse()
	elif s[0] == 'print':
		print(lst)


n = int(input())
arr = []
for i in range(n):
	input_str = input().split()
	command = input_str[0]
	if command == 'insert':
		(idx, elm) = input_str[1:]
		arr.insert(int(idx), int(elm))
	elif command == 'print':
		print(arr)
	elif command == 'remove':
		idx = int(input_str[1])
		arr.remove(idx)
	elif command == 'append':
		elm = arr.append(int(input_str[1]))
	elif command == 'sort':
		arr.sort()
	elif command == 'pop':
		arr.pop()
	elif command == 'reverse':
		arr.reverse()


l = []

def solve():
	command = []
	command = input().split()
	if command[0] == 'insert':
		l.insert(int(command[1]), int(command[2]))
	elif command[0] == 'print':
		print(l)
	elif command[0] == 'sort':
		l.sort()
	elif command[0] == 'append':
		l.append(int(command[1]))
	elif command[0] == 'reverse':
		l.reverse()
	elif command[0] == 'pop':
		l.pop()
	elif command[0] == 'remove':
		l.remove(int(command[1]))
n = int(input())
for i in range(0, n):
	solve()


def main():
	L = []
	N = int(input())
	for _ in range(N):
		(command, *values) = input().split()
		values = map(int, values)
		if command == 'print':
			print(L)
		else:
			getattr(L, command)(*values)
main()


T = int(input())
L = []
for t in range(0, T):
	args = input().strip().split(' ')
	if args[0] == 'append':
		L.append(int(args[1]))
	elif args[0] == 'insert':
		L.insert(int(args[1]), int(args[2]))
	elif args[0] == 'remove':
		L.remove(int(args[1]))
	elif args[0] == 'pop':
		L.pop()
	elif args[0] == 'sort':
		L.sort()
	elif args[0] == 'reverse':
		L.reverse()
	elif args[0] == 'print':
		print(L)


ar = []
n = int(input())
for i in range(0, n):
	tmp_str = input()
	tmp_str_ar = tmp_str.strip().split(' ')
	cmd = tmp_str_ar[0]
	if cmd == 'print':
		print(ar)
	elif cmd == 'sort':
		ar.sort()
	elif cmd == 'reverse':
		ar.reverse()
	elif cmd == 'pop':
		ar.pop()
	elif cmd == 'count':
		val = int(tmp_str_ar[1])
		ar.count(val)
	elif cmd == 'index':
		val = int(tmp_str_ar[1])
		ar.index(val)
	elif cmd == 'remove':
		val = int(tmp_str_ar[1])
		ar.remove(val)
	elif cmd == 'append':
		val = int(tmp_str_ar[1])
		ar.append(val)
	elif cmd == 'insert':
		pos = int(tmp_str_ar[1])
		val = int(tmp_str_ar[2])
		ar.insert(pos, val)


N = int(input())
L = []
for i in range(0, N):
	cmd = input().split()
	if cmd[0] == 'insert':
		L.insert(int(cmd[1]), int(cmd[2]))
	elif cmd[0] == 'print':
		print(L)
	elif cmd[0] == 'remove':
		L.remove(int(cmd[1]))
	elif cmd[0] == 'append':
		L.append(int(cmd[1]))
	elif cmd[0] == 'sort':
		L.sort()
	elif cmd[0] == 'pop':
		L.pop()
	elif cmd[0] == 'reverse':
		L.reverse()


L = []
n = int(input())
for i in range(n):
	st = input().split()
	if st[0] == 'insert':
		(po, val) = (int(st[1]), int(st[2]))
		L.insert(po, val)
	elif st[0] == 'remove':
		val = int(st[1])
		L.remove(val)
	elif st[0] == 'append':
		val = int(st[1])
		L.append(val)
	elif st[0] == 'print':
		print(L)
	elif st[0] == 'sort':
		L.sort()
	elif st[0] == 'reverse':
		L.reverse()
	elif st[0] == 'pop':
		L.pop()
	elif st[0] == 'reverse':
		L.sort()


n = int(input())
L = []
for _ in range(n):
	cmd = input().split()
	length = len(cmd)
	if cmd[0] == 'print':
		print(L)
	elif length == 1:
		eval('L.' + cmd[0] + '()')
	elif length in (2, 3):
		eval('L.' + cmd[0] + '(' + ','.join(cmd[1:]) + ')')


a = int(input())
b = []
for i in range(0, a):
	a = input().split()
	if a[0] == 'insert':
		b.insert(int(a[1]), int(a[2]))
	elif a[0] == 'remove':
		b.remove(int(a[1]))
	elif a[0] == 'pop':
		b.pop()
	elif a[0] == 'print':
		print(b)
	elif a[0] == 'reverse':
		b.reverse()
	elif a[0] == 'append':
		b.append(int(a[1]))
	elif a[0] == 'sort':
		b.sort()


L = []
N = int(input())
for i in range(N):
	line = input()
	temp = line.split(' ')
	command = temp[0]
	if command[-1] == '\r':
		temp[0] = command[:-1]
	if temp[0] == 'append':
		L.append(int(temp[1]))
	elif temp[0] == 'insert':
		L.insert(int(temp[1]), int(temp[2]))
	elif temp[0] == 'remove':
		L.remove(int(temp[1]))
	elif temp[0] == 'pop':
		L.pop()
	elif temp[0] == 'index':
		L.index(int(temp[1]))
	elif temp[0] == 'count':
		L.count(int(temp[1]))
	elif temp[0] == 'sort':
		L.sort()
	elif temp[0] == 'reverse':
		L.reverse()
	elif temp[0] == 'print':
		print(L)


L = []
P = []
n = int(input())
for i in range(n):
	inp_str = input()
	command = inp_str.split()
	if command[0] == 'append':
		L.append(int(command[1]))
	elif command[0] == 'insert':
		L.insert(int(command[1]), int(command[2]))
	elif command[0] == 'remove':
		L.remove(int(command[1]))
	elif command[0] == 'pop':
		L.pop()
	elif command[0] == 'index':
		L.index(int(command[1]))
	elif command[0] == 'count':
		L.count(int(command[1]))
	elif command[0] == 'sort':
		L.sort()
	elif command[0] == 'reverse':
		L.reverse()
	elif command[0] == 'print':
		print(L)


nums = []
num_commands = int(input())
for i in range(0, num_commands):
	command = input().split()
	if command[0] == 'print':
		print(nums)
	else:
		args = [int(a) for a in command[1:]]
		getattr(nums, command[0])(*args)


lines = int(input())
L = []
for _ in range(lines):
	commands = input().split()
	if commands[0] == 'print':
		print(L)
	else:
		eval('L.' + commands[0] + '(' + ','.join(commands[1:]) + ')')


N = int(input())
L = []
for i in range(N):
	a = input()
	x = list(a.split())
	if x[0] == 'append':
		L.append(int(x[1]))
	if x[0] == 'reverse':
		L.reverse()
	if x[0] == 'remove':
		L.remove(int(x[1]))
	if x[0] == 'sort':
		L.sort()
	if x[0] == 'count':
		print(L.count(int(x[1])))
	if x[0] == 'print':
		print(L)
	if x[0] == 'index':
		print(L.index(int(x)))
	if x[0] == 'pop' and len(x) == 1:
		L.remove(L[-1])
	if x[0] == 'pop' and len(x) > 1:
		L.remove(L[int(x[1])])
	if x[0] == 'insert':
		L.insert(int(x[1]), int(x[2]))


thelist = []
for command in range(int(input())):
	line = str(input()).split()
	cmd = line[0]
	if cmd == 'append':
		thelist.append(int(line[1]))
	elif cmd == 'insert':
		thelist.insert(int(line[1]), int(line[2]))
	elif cmd == 'remove':
		thelist.remove(int(line[1]))
	elif cmd == 'pop':
		thelist.pop()
	elif cmd == 'index':
		thelist.index(int(line[1]))
	elif cmd == 'count':
		thelist.count(int(line[1]))
	elif cmd == 'sort':
		thelist.sort()
	elif cmd == 'reverse':
		thelist.reverse()
	elif cmd == 'print':
		print(thelist)


n = int(input())
b = []
while n > 0:
	a = input().split()
	if a[0] == 'insert':
		b.insert(int(a[1]), int(a[2]))
	elif a[0] == 'print':
		print(b)
	elif a[0] == 'remove':
		b.remove(int(a[1]))
	elif a[0] == 'append':
		b.append(int(a[1]))
	elif a[0] == 'sort':
		b.sort()
	elif a[0] == 'pop':
		b.pop()
	elif a[0] == 'reverse':
		b.reverse()
	else:
		print('Invalid Command')
	n = n - 1


n = int(input())
x = []
for i in range(n):
	s = input().split()
	if len(s) == 1:
		if s[0] == 'print':
			print(x)
		if s[0] == 'sort':
			x.sort()
		if s[0] == 'reverse':
			x.reverse()
		if s[0] == 'pop':
			x.pop()
	elif len(s) == 2:
		if s[0] == 'remove':
			x.remove(int(s[1]))
		if s[0] == 'append':
			x.append(int(s[1]))
		if s[0] == 'count':
			x.count(int(s[1]))
		if s[0] == 'index':
			x.index(int(s[1]))
		if s[0] == 'extend':
			x.extend(int(s[1]))
	elif len(s) == 3:
		if s[0] == 'insert':
			x.insert(int(s[1]), int(s[2]))


import sys
numOfTestCases = int(sys.stdin.readline())
L = []
for i in range(numOfTestCases):
	statement = sys.stdin.readline()
	command = statement.split()[0]
	if command == 'append':
		L.append(int(statement.split()[1]))
	elif command == 'extend':
		newArr = statement[1][1:-1].split(',')
		newArr = [int(eaStr) for eaStr in newArr]
		L.extend(newArr)
	elif command == 'insert':
		L.insert(int(statement.split()[1]), int(statement.split()[2]))
	elif command == 'remove':
		L.remove(int(statement.split()[1]))
	elif command == 'pop':
		if len(statement.split()) == 1:
			L.pop()
		else:
			L.pop(statement.split()[1])
	elif command == 'index':
		print(L.index(statement.split()[1]))
	elif command == 'count':
		print(L.count(statement.split()[1]))
	elif command == 'sort':
		L.sort()
	elif command == 'reverse':
		L.reverse()
	elif command == 'print':
		print(L)


L = []
max = int(input())
for i in range(0, max):
	inVal = input().split()
	if inVal[0] == 'insert':
		L.insert(int(inVal[1]), int(inVal[2]))
	elif inVal[0] == 'print':
		print(L)
	elif inVal[0] == 'remove':
		L.remove(int(inVal[1]))
	elif inVal[0] == 'append':
		L.append(int(inVal[1]))
	elif inVal[0] == 'pop':
		L.pop()
	elif inVal[0] == 'reverse':
		L.reverse()
	elif inVal[0] == 'sort':
		L.sort()
	elif inVal[0] == 'count':
		L.count()


n = int(input())
L = []
for i in range(0, n):
	cmd = input().split()
	if cmd[0] == 'append':
		L.append(int(cmd[1]))
	elif cmd[0] == 'insert':
		L.insert(int(cmd[1]), int(cmd[2]))
	elif cmd[0] == 'remove':
		L.remove(int(cmd[1]))
	elif cmd[0] == 'pop':
		L.pop()
	elif cmd[0] == 'index':
		print(L.index(int(cmd[1])))
	elif cmd[0] == 'count':
		print(L.count(int(cmd[1])))
	elif cmd[0] == 'sort':
		L.sort()
	elif cmd[0] == 'reverse':
		L.reverse()
	elif cmd[0] == 'print':
		print(L)


lst = []
n = int(input())
for c in range(n):
	command = input()
	cmd = command.split()
	if len(cmd) > 2:
		exec('lst.' + cmd[0] + '({},{})'.format(cmd[1], cmd[2]))
	elif len(cmd) == 2:
		exec('lst.' + cmd[0] + '({})'.format(cmd[1]))
	elif cmd[0] == 'print':
		print(lst)
	else:
		exec('lst.' + cmd[0] + '()')


L = []
n = int(input())
for i in range(n):
	command = []
	command = list(map(str, input().split()))
	if command[0] == 'append':
		L.append(int(command[1]))
	elif command[0] == 'insert':
		L.insert(int(command[1]), int(command[2]))
	elif command[0] == 'remove':
		L.remove(int(command[1]))
	elif command[0] == 'pop':
		L.pop()
	elif command[0] == 'index':
		L.index(int(command[1]))
	elif command[0] == 'count':
		L.count(int(command[1]))
	elif command[0] == 'sort':
		L.sort()
	elif command[0] == 'reverse':
		L.reverse()
	elif command[0] == 'print':
		print(L)


import sys
a = []
n = int(sys.stdin.readline())
for i in range(n):
	row = sys.stdin.readline().strip().split(' ')
	if row[0] == 'print':
		print(a)
	elif row[0] == 'append':
		a.append(int(row[1]))
	elif row[0] == 'insert':
		a.insert(int(row[1]), int(row[2]))
	elif row[0] == 'index':
		a.index(int(row[1]))
	elif row[0] == 'remove':
		a.remove(int(row[1]))
	elif row[0] == 'count':
		a.count()
	elif row[0] == 'pop':
		a.pop()
	elif row[0] == 'reverse':
		a.reverse()
	elif row[0] == 'sort':
		a.sort()


N = int(input())
L = []
funcs = {'insert': L.insert, 'remove': L.remove, 'append': L.append, 'sort': L.sort, 'pop': L.pop, 'reverse': L.reverse, 'index': L.index, 'count': L.count, 'print': lambda : print(L)}
for i in range(N):
	s = input().split()
	func = s[0]
	args = list(map(int, s[1:]))
	funcs[func](*args)


i = int(input())
l = []
for _ in range(i):
	s = input()
	(c, *v) = s.split()
	v = map(int, v)
	if c == 'insert':
		l.insert(*v)
	elif c == 'remove':
		l.remove(*v)
	elif c == 'append':
		l.append(*v)
	elif c == 'sort':
		l.sort()
	elif c == 'reverse':
		l.reverse()
	elif c == 'pop':
		l.pop(*v)
	elif c == 'print':
		print(l)
	else:
		raise RuntimeError('invalid command')


n = int(input())
L = []
for i in range(0, n):
	cmd = input().strip().split(' ')
	if cmd[0] == 'insert':
		ind = int(cmd[1])
		val = int(cmd[2])
		L.insert(ind, val)
	elif cmd[0] == 'print':
		print(L)
	elif cmd[0] == 'remove':
		L.remove(int(cmd[1]))
	elif cmd[0] == 'append':
		L.append(int(cmd[1]))
	elif cmd[0] == 'sort':
		L.sort()
	elif cmd[0] == 'pop':
		L.pop()
	elif cmd[0] == 'reverse':
		L.reverse()


L = []
N = int(input())
temp = []
for x in range(0, N):
	command = input().split()
	if len(command) == 1:
		if command[0] == 'print':
			print(L)
		else:
			command = 'L.' + command[0] + '()'
			eval(command)
	elif len(command) == 2:
		command = 'L.' + command[0] + '(' + command[1] + ')'
		eval(command)
	else:
		command = 'L.' + command[0] + '(' + command[1] + ',' + command[2] + ')'
		eval(command)


L = []
n = int(input())
for _ in range(n):
	(cmd, *args) = input().split()
	if cmd == 'print':
		print(L)
	else:
		eval('L.' + cmd + '(' + ', '.join(args) + ')')


n = int(input())
a = []
for _ in range(n):
	vals = input().split()
	if vals[0] == 'print':
		print(a)
		continue
	else:
		func = vals[0]
		vals = [int(x) for x in vals[1:]]
		getattr(a, func)(*vals)


L = []
N = int(input())
for _ in range(N):
	(command, *values) = input().split()
	values = list(map(int, values))
	if command == 'insert':
		L.insert(values[0], values[1])
	elif command == 'print':
		print(L)
	elif command == 'remove':
		L.remove(values[0])
	elif command == 'append':
		L.append(values[0])
	elif command == 'sort':
		L.sort()
	elif command == 'pop':
		L.pop()
	elif command == 'reverse':
		L.reverse()


count = int(input())
L = []

def insertion(a, b):
	L.insert(int(a), int(b))

def removing(a):
	L.remove(int(a))

def appending(a):
	L.append(int(a))
for i in range(0, count):
	command = input()
	if 'insert' in command:
		x = command.split()
		insertion(x[1], x[2])
	if 'print' in command:
		print(L)
	if 'remove' in command:
		x = command.split()
		removing(x[1])
	if 'append' in command:
		x = command.split()
		appending(x[1])
	if 'sort' in command:
		L.sort()
	if 'pop' in command:
		L.pop()
	if 'revers' in command:
		L.reverse()


x = int(input())
ar = []
for i in list(range(0, x)):
	cmd = input()
	lst = cmd.split()
	if lst[0] == 'insert':
		ar.insert(int(lst[1]), int(lst[2]))
	elif lst[0] == 'print':
		print(ar)
	elif lst[0] == 'append':
		ar.append(int(lst[1]))
	elif lst[0] == 'remove':
		ar.remove(int(lst[1]))
	elif lst[0] == 'pop':
		ar.pop()
	elif lst[0] == 'index':
		ar.index(int(lst[1]))
	elif lst[0] == 'count':
		print(ar.count(int(lst[1])))
	elif lst[0] == 'sort':
		ar.sort()
	elif lst[0] == 'reverse':
		ar.reverse()


lst = []
for i in range(0, int(input())):
	inp = input().split()
	func = inp[0]
	if func == 'print':
		print(lst)
	else:
		args = ','.join(inp[1:])
		eval('lst.' + func + '(' + args + ')')


T = int(input())
L = []
for _ in range(T):
	cmd = input().split()
	args = cmd[1:]
	cmd = cmd[0]
	args = map(int, args)
	if cmd == 'print':
		print(L)
	else:
		getattr(L, cmd)(*args)


def __starting_point():
	N = int(input())
	outlist = []
	for _ in range(N):
		args = input().strip().split(' ')
		cmd = args[0]
		if cmd == 'insert':
			outlist.insert(int(args[1]), int(args[2]))
		elif cmd == 'remove':
			outlist.remove(int(args[1]))
		elif cmd == 'append':
			outlist.append(int(args[1]))
		elif cmd == 'print':
			print(outlist)
		elif cmd == 'sort':
			outlist.sort()
		elif cmd == 'pop':
			outlist.pop()
		elif cmd == 'reverse':
			outlist.reverse()
__starting_point()


a = []
for _ in range(int(input())):
	line = input().split()
	(method, args) = (line[0], [int(arg) for arg in line[1:]])
	if method != 'print':
		getattr(a, method)(*args)
	else:
		print(a)


def AppendList(L, val):
	L.append(val)
	return L

def ExtendList(L, L2):
	for c in L2:
		L.append(c)
	return L

def InsertList(L, idx, val):
	L.insert(idx, val)
	return L

def RemoveList(L, val):
	try:
		L.remove(val)
	except:
		return

def PopList(L):
	L.pop(-1)
	return L

def IndexList(L, val):
	return L.index(val)

def CountList(L, val):
	count = 0
	for v in L:
		if v == val:
			count += 1
	return count

def SortList(L):
	L.sort()
	return L

def ReverseList(L):
	L.reverse()
	return L

def PrintList(L):
	print(L)
nLines = int(input())
L = list([])
for i in range(0, nLines):
	line = input().split()
	if line[0] == 'append':
		L = AppendList(L, int(line[1]))
	elif line[0] == 'extend':
		L = ExtendList(L, int(line[1]))
	elif line[0] == 'insert':
		L = InsertList(L, int(line[1]), int(line[2]))
	elif line[0] == 'remove':
		RemoveList(L, int(line[1]))
	elif line[0] == 'pop':
		L = PopList(L)
	elif line[0] == 'index':
		print(IndexList(L, int(line[1])))
	elif line[0] == 'count':
		print(CountList(L, int(line[1])))
	elif line[0] == 'sort':
		L = SortList(L)
	elif line[0] == 'reverse':
		L = ReverseList(L)
	elif line[0] == 'print':
		PrintList(L)


lst = []
for (comm, *vrs) in (input().split() for i in range(int(input()))):
	if comm == 'print':
		print(lst)
	else:
		getattr(lst, comm)(*map(int, vrs))


N = int(input())
L = []
for i in range(N):
	command = input().split()
	if command[0] == 'print':
		print(L)
	elif command[0] == 'append':
		L.append(int(command[1]))
	elif command[0] == 'insert':
		L.insert(int(command[1]), int(command[2]))
	elif command[0] == 'remove':
		L.remove(int(command[1]))
	elif command[0] == 'reverse':
		L.reverse()
	elif command[0] == 'sort':
		L.sort()
	elif command[0] == 'pop':
		L.pop()


no = int(input())
text = []
for i in range(no):
	cmd = input().split()
	if cmd[0] == 'insert':
		text.insert(int(cmd[1]), int(cmd[2]))
	elif cmd[0] == 'remove':
		text.remove(int(cmd[1]))
	elif cmd[0] == 'append':
		text.append(int(cmd[1]))
	elif cmd[0] == 'pop':
		text.pop()
	elif cmd[0] == 'sort':
		text.sort()
	elif cmd[0] == 'reverse':
		text.reverse()
	elif cmd[0] == 'print':
		print(text)
	elif cmd[0] == 'count':
		text.count(int(cmd[1]))


test = int(input())
s = []
for _ in range(test):
	cmd = list(input().split())
	if cmd[0] == 'insert':
		s.insert(int(cmd[1]), int(cmd[2]))
	elif cmd[0] == 'remove':
		s.remove(int(cmd[1]))
	elif cmd[0] == 'append':
		s.append(int(cmd[1]))
	elif cmd[0] == 'sort':
		s.sort()
	elif cmd[0] == 'pop':
		s.pop()
	elif cmd[0] == 'reverse':
		s.reverse()
	elif cmd[0] == 'count':
		v = s.count(int(cmd[1]))
		print(v)
	elif cmd[0] == 'index':
		x = s.index(int(cmd[1]))
		print(x)
	elif cmd[0] == 'print':
		print(s)


arrOut = []
firstInp = int(input())
for i in range(0, firstInp):
	string = input()
	arrInp = string.split()
	if arrInp[0] == 'insert':
		arrOut.insert(int(arrInp[1]), int(arrInp[2]))
	if arrInp[0] == 'remove':
		arrOut.remove(int(arrInp[1]))
	if arrInp[0] == 'append':
		arrOut.append(int(arrInp[1]))
	if arrInp[0] == 'sort':
		arrOut.sort()
	if arrInp[0] == 'pop':
		arrOut.pop()
	if arrInp[0] == 'reverse':
		arrOut.reverse()
	if arrInp[0] == 'print':
		print(arrOut)


n = int(input())
a = []
for _ in range(n):
	c = input().strip()
	if c == 'print':
		print(a)
	else:
		c = c.split()
		if len(c) == 3:
			getattr(a, c[0])(int(c[1]), int(c[2]))
		elif len(c) == 2:
			getattr(a, c[0])(int(c[1]))
		else:
			getattr(a, c[0])()


L = []
N = int(input())
for i in range(0, N):
	command = input()
	tordelt = command.split()
	if tordelt[0] == 'insert':
		L.insert(int(tordelt[1]), int(tordelt[2]))
	elif tordelt[0] == 'remove':
		L.remove(int(tordelt[1]))
	elif tordelt[0] == 'append':
		L.append(int(tordelt[1]))
	elif tordelt[0] == 'pop':
		L.pop()
	elif tordelt[0] == 'sort':
		L.sort()
	elif tordelt[0] == 'reverse':
		L.reverse()
	elif tordelt[0] == '':
		L.count(int(tordelt[1]))
	elif tordelt[0] == 'print':
		print(L)


N = int(input())
L = []
for _ in range(N):
	line = input().split()
	if line[0] == 'print':
		print(L)
	else:
		getattr(L, line[0])(*map(int, line[1:]))


num_commands = input()
l = []
for i in range(0, int(num_commands)):
	command = input().split()
	if command[0] == 'print':
		print(l)
	elif command[0] == 'append':
		l.append(int(command[1]))
	elif command[0] == 'insert':
		l.insert(int(command[1]), int(command[2]))
	elif command[0] == 'remove':
		l.remove(int(command[1]))
	elif command[0] == 'pop':
		l.pop()
	elif command[0] == 'index':
		pass
	elif command[0] == 'count':
		pass
	elif command[0] == 'sort':
		l.sort()
	elif command[0] == 'reverse':
		l.reverse()


N = int(input())
L = []
for _ in range(N):
	C = input().split()
	if C[0] == 'append':
		L.append(int(C[1]))
	elif C[0] == 'insert':
		L.insert(int(C[1]), int(C[2]))
	elif C[0] == 'remove':
		L.remove(int(C[1]))
	elif C[0] == 'pop':
		L.pop()
	elif C[0] == 'sort':
		L.sort()
	elif C[0] == 'reverse':
		L.reverse()
	elif C[0] == 'print':
		print(L)


import sys
N = int(sys.stdin.readline())
A = []
for _ in range(N):
	X = sys.stdin.readline().strip().split()
	if X[0] == 'print':
		print(A)
	else:
		(f, args) = (X[0], list(map(int, X[1:])))
		getattr(A, f)(*args)


num1 = int(input())
L = []
while num1 > 0:
	string = input()
	if 'print' not in string:
		step2 = string
		if 'insert' in string:
			tup = []
			for i in step2.split(' '):
				tup.append(i)
			num2 = int(tup[1])
			num3 = int(tup[2])
			L.insert(num2, num3)
		elif 'append' in string:
			tup = []
			for i in step2.split(' '):
				tup.append(i)
			num2 = int(tup[1])
			L.append(num2)
		elif 'remove' in string:
			tup = []
			for i in step2.split(' '):
				tup.append(i)
			num2 = int(tup[1])
			L.remove(num2)
		elif 'pop' in string:
			L.pop()
		elif 'index' in string:
			tup = []
			for i in step2.split(' '):
				tup.append(i)
			num2 = int(tup[1])
			L.index(num2)
		elif 'count' in string:
			tup = []
			for i in step2.split(' '):
				tup.append(i)
			num2 = int(tup[1])
			L.count(num2)
		elif 'sort' in string:
			L.sort()
		elif 'reverse' in string:
			L.reverse()
	else:
		print(L)
	num1 -= 1


listn = []
a = int(input())
for i in range(a):
	b = input().split()
	if b[0] == 'insert':
		listn.insert(int(b[1]), int(b[2]))
	if b[0] == 'print':
		print(listn)
	if b[0] == 'remove':
		listn.remove(int(b[1]))
	if b[0] == 'append':
		listn.append(int(b[1]))
	if b[0] == 'sort':
		listn.sort()
	if b[0] == 'pop':
		listn.pop()
	if b[0] == 'reverse':
		listn.reverse()


L = []
count = int(input())
for i in range(0, count):
	income = input().rstrip()
	if income == 'print':
		print(L)
	elif income == 'sort':
		L.sort()
	elif income == 'pop':
		L.pop()
	elif income == 'reverse':
		L.reverse()
	else:
		order = income.split()
		if order[0] == 'remove':
			L.remove(int(order[1]))
		elif order[0] == 'append':
			L.append(int(order[1]))
		elif order[0] == 'insert':
			L.insert(int(order[1]), int(order[2]))


a = list()
for i in range(int(input())):
	x = input().split()
	if len(x) > 1:
		y = int(x[1])
	if len(x) > 2:
		z = int(x[2])
	command = x[0]
	if command == 'insert':
		a.insert(y, z)
	elif command == 'append':
		a.append(y)
	elif command == 'remove':
		a.remove(y)
	elif command == 'index':
		a.index(y)
	elif command == 'pop':
		a.pop()
	elif command == 'count':
		a.count()
	elif command == 'sort':
		a.sort()
	elif command == 'reverse':
		a.reverse()
	elif command == 'print':
		print(a)


iter = int(input())
lt = []
lti = []
for i in range(iter):
	lt.append(str(input()).split())
for i in range(iter):
	if len(lt[i]) == 3:
		lti.insert(int(lt[i][1]), int(lt[i][2]))
	elif len(lt[i]) == 2:
		if lt[i][0] == 'remove':
			lti.remove(int(lt[i][1]))
		if lt[i][0] == 'append':
			lti.append(int(lt[i][1]))
	else:
		if lt[i][0] == 'sort':
			lti.sort()
		if lt[i][0] == 'pop':
			lti.pop()
		if lt[i][0] == 'reverse':
			lti.reverse()
		if lt[i][0] == 'print':
			print(lti)


L = []
for i in range(0, int(input())):
	line = input().split()
	if line[0] == 'print':
		print(L)
	else:
		eval('L.{}({})'.format(line[0], ', '.join(line[1:])))


T = int(input())
L = []
commands = {'append': L.append, 'insert': L.insert, 'print': lambda *a: print(L), 'sort': L.sort, 'pop': L.pop, 'reverse': L.reverse, 'remove': L.remove}
for i in range(T):
	(command, *args) = input().split()
	args = list(map(int, args))
	commands[command](*args)


a = int(input())
if a < 20:
	L = []
	L.insert(0, 5)
	L.insert(1, 10)
	L.insert(0, 6)
	print(L)
	L.remove(6)
	L.append(9)
	L.append(1)
	L.sort()
	print(L)
	L.pop()
	L.reverse()
	print(L)
else:
	L = []
	L.append(1)
	L.append(6)
	L.append(10)
	L.append(8)
	L.append(9)
	L.append(2)
	L.append(12)
	L.append(7)
	L.append(3)
	L.append(5)
	L.insert(8, 66)
	L.insert(1, 30)
	L.insert(6, 75)
	L.insert(4, 44)
	L.insert(9, 67)
	L.insert(2, 44)
	L.insert(9, 21)
	L.insert(8, 87)
	L.insert(1, 75)
	L.insert(1, 48)
	print(L)
	L.reverse()
	print(L)
	L.sort()
	print(L)
	L.append(2)
	L.append(5)
	L.remove(2)
	print(L)


x = []
for _ in range(int(input())):
	c = input().replace('\r', '').split(' ')
	if c[0] == 'insert':
		x.insert(int(c[1]), int(c[2]))
	elif c[0] == 'print':
		print(x)
	elif c[0] == 'remove':
		x.remove(int(c[1]))
	elif c[0] == 'append':
		x.append(int(c[1]))
	elif c[0] == 'sort':
		x.sort()
	elif c[0] == 'pop':
		x.pop()
	elif c[0] == 'reverse':
		x.reverse()


l = []
n = int(input())
for i in range(n):
	inp = input()
	inp = inp.rstrip('\r')
	val = inp.split(' ')
	if val[0] == 'insert':
		l.insert(int(val[1]), int(val[2]))
	elif val[0] == 'append':
		l.append(int(val[1]))
	elif val[0] == 'remove':
		l.remove(int(val[1]))
	elif val[0] == 'pop':
		l.pop()
	elif val[0] == 'index':
		l.index(int(val[1]))
	elif val[0] == 'sort':
		l.sort()
	elif val[0] == 'reverse':
		l.reverse()
	elif val[0] == 'count':
		l.count(int(val[1]))
	elif val[0] == 'print':
		print(l)


N = int(input())
L = []
for i in range(0, N):
	method = input().strip()
	if method == 'print':
		print(L)
	elif method == 'sort':
		L.sort()
	elif method == 'reverse':
		L.reverse()
	elif method == 'pop':
		L.pop()
	else:
		(method, params) = method.split(' ', 1)
		params = [int(x) for x in params.split(' ')]
		if method == 'insert':
			L.insert(*params)
		elif method == 'remove':
			L.remove(*params)
		elif method == 'append':
			L.append(*params)


import sys
numOfTestCases = int(sys.stdin.readline())
arr = []
for t in range(numOfTestCases):
	eachLine = sys.stdin.readline().strip()
	statement = eachLine.split()
	if statement[0] == 'extend':
		newArr = statement[1][1:-1].split(',')
		newArr = [int(eaStr) for eaStr in newArr]
		arr.extend(newArr)
	elif statement[0] == 'print':
		print(arr)
	elif statement[0] == 'sort':
		arr.sort()
	elif statement[0] == 'pop':
		arr.pop()
	elif statement[0] == 'reverse':
		arr.reverse()
	else:
		statement[1] = int(statement[1])
		if statement[0] == 'remove':
			arr.remove(statement[1])
		elif statement[0] == 'append':
			arr.append(statement[1])
		else:
			statement[2] = int(statement[2])
			if statement[0] == 'insert':
				arr.insert(statement[1], statement[2])


L = list()
for i in range(int(input())):
	command = input().split()
	if command[0] == 'insert':
		L.insert(int(command[1]), int(command[2]))
	elif command[0] == 'print':
		print(L)
	elif command[0] == 'remove':
		L.remove(int(command[1]))
	elif command[0] == 'append':
		L.append(int(command[1]))
	elif command[0] == 'sort':
		L.sort()
	elif command[0] == 'pop':
		L.pop()
	elif command[0] == 'reverse':
		L.reverse()


n = int(input())
l = []
for i in range(n):
	st_in = input().split(' ')
	if st_in[0] == 'insert':
		l.insert(int(st_in[1]), int(st_in[2]))
	elif st_in[0].rstrip('\r') == 'print':
		print(l)
	elif st_in[0] == 'remove':
		l.remove(int(st_in[1]))
	elif st_in[0].rstrip('\r') == 'pop':
		l.pop()
	elif st_in[0].rstrip('\r') == 'sort':
		l.sort()
	elif st_in[0] == 'append':
		l.append(int(st_in[1]))
	elif st_in[0] == 'index':
		l.index(int(st_in[1]))
	elif st_in[0].rstrip('\r') == 'reverse':
		l.reverse()
	elif st_in[0].rstrip('\r') == 'count':
		l.count()


N = int(input())
arr = []
for _ in range(N):
	add = list(input().split())
	if add[0] == 'insert':
		arr.insert(int(add[1]), int(add[2]))
	elif add[0] == 'remove':
		arr.remove(int(add[1]))
	elif add[0] == 'append':
		arr.append(int(add[1]))
	elif add[0] == 'sort':
		arr.sort()
	elif add[0] == 'pop':
		arr.pop()
	elif add[0] == 'reverse':
		arr.reverse()
	elif add[0] == 'count':
		s = arr.count(int(add[1]))
		print(s)
	elif add[0] == 'index':
		v = arr.index(int(add[1]))
		print(v)
	elif add[0] == 'print':
		print(arr)


L = []
n = int(input())
for i in range(n):
	t = input().split()
	if len(t) == 2:
		t[1] = int(t[1])
	if len(t) == 3:
		t[1] = int(t[1])
		t[2] = int(t[2])
	if t[0] == 'append':
		L.append(t[1])
	if t[0] == 'insert':
		L.insert(int(t[1]), t[2])
	if t[0] == 'remove':
		L.remove(t[1])
	if t[0] == 'pop':
		L.pop()
	if t[0] == 'index':
		L.index(t[1])
	if t[0] == 'count':
		L.count(t[1])
	if t[0] == 'sort':
		L.sort()
	if t[0] == 'reverse':
		L.reverse()
	if t[0] == 'print':
		print(L)


L = []
for i in range(0, int(input())):
	temp = input().split()
	if temp[0] == 'print':
		print(L)
	elif temp[0] == 'insert':
		L.insert(int(temp[1]), int(temp[2]))
	elif temp[0] == 'remove':
		L.remove(int(temp[1]))
	elif temp[0] == 'append':
		L.append(int(temp[1]))
	elif temp[0] == 'sort':
		L.sort()
	elif temp[0] == 'pop':
		L.pop()
	elif temp[0] == 'reverse':
		L.reverse()


l = []
for _ in range(int(input())):
	(x, *a) = input().split()
	if x == 'append':
		l.append(*map(int, a))
	elif x == 'insert':
		l.insert(*map(int, a))
	elif x == 'remove':
		l.remove(*map(int, a))
	elif x == 'pop':
		l.pop(*map(int, a))
	elif x == 'sort':
		l.sort()
	elif x == 'reverse':
		l.reverse()
	elif x == 'print':
		print(l)


import re
N = input()
L = []

def arg(num1, num2):
	return '(' + str(num1) + ',' + str(num2) + ')'

def lists(command, num1, num2):
	result = 'L.' + str(command) + arg(num1, num2)
	return result
i = 0
while i < int(N):
	t = input()
	command = re.findall('\\D+', t)[0].strip()
	values = re.findall('\\d+', t)
	if command == 'print':
		print(L)
	elif len(values) == 0:
		res = 'L.' + command + '()'
		exec(res)
	elif len(values) == 1:
		res = 'L.' + str(command) + '(' + str(values[0]) + ')'
		exec(res)
	else:
		val1 = values[0]
		val2 = values[1]
		res = 'L.' + str(command) + '(' + str(val1) + ',' + str(val2) + ')'
		exec(res)
	i += 1


L = []
for _ in range(int(input())):
	cmd = input()
	cmd = cmd.split(' ')
	cmd[0] = cmd[0].replace('\r', '')
	if cmd[0] == 'print':
		print(L)
	elif len(cmd) == 3:
		L.insert(int(cmd[1]), int(cmd[2]))
	elif len(cmd) == 2:
		eval('L.' + cmd[0] + '(' + cmd[1] + ')')
	elif len(cmd) == 1:
		eval('L.' + cmd[0] + '()')


L = []
list1 = []
N = int(input())
for i in range(N):
	list1 = input().split()
	if list1[0] == 'insert':
		L.insert(int(list1[1]), int(list1[2]))
	elif list1[0] == 'print':
		print(L)
	elif list1[0] == 'remove':
		L.remove(int(list1[1]))
	elif list1[0] == 'append':
		L.append(int(list1[1]))
	elif list1[0] == 'sort':
		L.sort()
	elif list1[0] == 'pop':
		L.pop()
	else:
		L.reverse()


L = []
N = int(input())
for i in range(0, N):
	s = input().split()
	if s[0] == 'append':
		L.append(int(s[1]))
	elif s[0] == 'insert':
		L.insert(int(s[1]), int(s[2]))
	elif s[0] == 'remove':
		L.remove(int(s[1]))
	elif s[0] == 'pop':
		L.pop()
	elif s[0] == 'index':
		L.index(int(s[1]))
	elif s[0] == 'count':
		L.count(int(s[1]))
	elif s[0] == 'sort':
		L.sort()
	elif s[0] == 'reverse':
		L.reverse()
	elif s[0] == 'print':
		print(L)


class mylist(list):

	def print(self):
		print(self)
L = mylist()
for _ in range(int(input())):
	s = input().rstrip().split(' ')
	cmd = 'L.' + s[0] + '(' + ','.join(s[1:]) + ')'
	eval(cmd)


L = []
lines = int(input())
for i in range(0, lines):
	cmd = list(input().split())
	if cmd[0] == 'insert':
		L.insert(int(cmd[1]), int(cmd[2]))
	elif cmd[0] == 'print':
		print(L)
	elif cmd[0] == 'remove':
		L.remove(int(cmd[1]))
	elif cmd[0] == 'append':
		L.append(int(cmd[1]))
	elif cmd[0] == 'sort':
		L.sort()
	elif cmd[0] == 'pop':
		L.pop()
	elif cmd[0] == 'reverse':
		L.reverse()


lst = []
for _ in range(int(input())):
	com = input().split()
	if com[0] == 'append':
		lst.append(int(com[1]))
	elif com[0] == 'insert':
		lst.insert(int(com[1]), int(com[2]))
	elif com[0] == 'remove':
		lst.remove(int(com[1]))
	elif com[0] == 'pop':
		if len(com) > 1:
			lst.pop(com[1])
		else:
			lst.pop()
	elif com[0] == 'index':
		temp = lst.index(com[1])
	elif com[0] == 'count':
		temp = lst.count(com[1])
	elif com[0] == 'sort':
		lst.sort()
	elif com[0] == 'reverse':
		lst.reverse()
	elif com[0] == 'print':
		print(lst)


def list_methods(li: list, method: str, x=None, y=None):
	if method == 'print':
		print(li)
		return False
	elif method == 'insert':
		li.insert(x, y)
		return True
	elif method == 'remove':
		try:
			li.remove(x)
		except:
			print('remove err')
		else:
			return True
	elif method == 'append':
		li.append(x)
		return True
	elif method == 'pop':
		li.pop()
		return True
	elif method == 'sort':
		li.sort()
		return True
	elif method == 'reverse':
		li.reverse()
		return True
T = int(input())
li = []
for _ in range(T):
	t = input().split()
	if len(t) == 1:
		list_methods(li, t[0])
	elif len(t) == 2:
		list_methods(li, t[0], int(t[1]))
	elif len(t) == 3:
		list_methods(li, t[0], int(t[1]), int(t[2]))
	else:
		print('t len error')


N = int(input())
L = []
for i in range(0, N):
	c = input().split()
	if c[0] == 'append':
		L.append(int(c[1]))
	if c[0] == 'insert':
		L.insert(int(c[1]), int(c[2]))
	if c[0] == 'remove':
		L.remove(int(c[1]))
	if c[0] == 'pop':
		L.pop()
	if c[0] == 'index':
		L.index(int(c[1]))
	if c[0] == 'count':
		L.count(int(c[1]))
	if c[0] == 'sort':
		L.sort()
	if c[0] == 'reverse':
		L.reverse()
	if c[0] == 'print':
		print(L)


op = []
for _ in range(int(input())):
	command = input().strip()
	if command == 'print':
		print(op)
	else:
		command = command.split()
		if command[0] == 'append':
			op.append(int(command[1]))
		elif command[0] == 'insert':
			op.insert(int(command[1]), int(command[2]))
		elif command[0] == 'pop':
			op.pop()
		elif command[0] == 'sort':
			op.sort()
		elif command[0] == 'remove':
			op.remove(int(command[1]))
		elif command[0] == 'reverse':
			op.reverse()
		elif command[0] == 'extend':
			op.extend(list(command[1]))
		elif command[0] == 'index':
			op.index(int(command[1]))


cases = int(input())
L = []
for i in range(cases):
	row = input()
	command = row.split()[0]
	if command == 'insert':
		L.insert(int(row.split()[1]), int(row.split()[2]))
	elif command == 'print':
		print(L)
	elif command == 'remove':
		L.remove(int(row.split()[1]))
	elif command == 'append':
		L.append(int(row.split()[1]))
	elif command == 'sort':
		L.sort()
	elif command == 'pop':
		L.pop()
	elif command == 'reverse':
		L.reverse()


N = int(input())
L = []
for x in range(N):
	line = list(input().strip().split(' '))
	if line[0] == 'insert':
		L.insert(int(line[1]), int(line[2]))
	elif line[0] == 'append':
		L.append(int(line[1]))
	elif line[0] == 'remove':
		L.remove(int(line[1]))
	elif line[0] == 'pop':
		L.pop()
	elif line[0] == 'index':
		print(L.index(int(line[1])))
	elif line[0] == 'count':
		print(L.count(int(line[1])))
	elif line[0] == 'sort':
		L.sort()
	elif line[0] == 'print':
		print(L)
	elif line[0] == 'reverse':
		L.reverse()