Problem:

Vector

 

  For a dynamic array $A = \{a_0, a_1, ...\}$ of integers, perform a sequence of the following operations:

  
pushBack($x$): add element $x$ at the end of $A$

  
randomAccess($p$):print element $a_p$

  
popBack(): delete the last element of $A$

  
$A$ is a 0-origin array and it is empty in the initial state.

Input

  The input is given in the following format.

$q$
$query_1$
$query_2$
:
$query_q$

  Each query $query_i$ is given by

0 $x$

or

1 $p$

or

2

  where the first digits 0, 1 and 2 represent pushBack, randomAccess and popBack operations respectively.

  randomAccess and popBack operations will not be given for an empty array.

Output

  For each randomAccess, print $a_p$ in a line.

Constraints

  
$1 \leq q \leq 200,000$

  
$0 \leq p < $ the size of $A$

  
$-1,000,000,000 \leq x \leq 1,000,000,000$

Sample Input 1

8
0 1
0 2
0 3
2
0 4
1 0
1 1
1 2

Sample Output 1

1
2
4



Sample input:
8
0 1
0 2
0 3
2
0 4
1 0
1 1
1 2


Sample output:
1
2
4

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import deque

num = int(input())

q = deque()

for i in range(num):

	cmd = stdin.readline().strip().split()

	if cmd[0] == "0":
		#末尾に挿入
		q.append(cmd[1])

	elif cmd[0] == "1":
		#要素の出力
		print(q[int(cmd[1])])
	else:
		#末尾の削除
		q.pop()

print(*q,sep='\n')

Submission status: Wrong Answer

Solution code:
# AOJ ITP2_1_A: Vector
# Python3 2018.6.24 bal4u

from collections import deque
Q = deque()
q = int(input())
for i in range(q):
	a = input()
	if   a[0] == '0': Q.append(a[2:])     # pushBack
	elif a[0] == '1': print(Q[int(a[2])]) # randomAccess
	else:             Q.pop()             # popBack

Submission status: Wrong Answer

Solution code:
# AOJ ITP2_1_A: Vector
# Python3 2018.6.24 bal4u

from collections import deque
Q = deque()
q = int(input())
for i in range(q):
	a = input()
	print(a[2:])
	if   a[0] == '0': Q.append(a[2:])      # pushBack
	elif a[0] == '1': print(Q[int(a[2:])]) # randomAccess
	else:             Q.pop()              # popBack

Submission status: Accepted

Solution code:
n = int(input())
commands = [input().split() for i in range(n)]
a = []
for command in commands:
    if len(command) == 2:
        if command[0] == '0':
            a.append(int(command[1]))
        elif command[0] == '1':
            print(int(a[int(command[1])]))
    else:
        a.pop(len(a) - 1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

from collections import deque

n = int(input())
word = deque()

for i in range(n):
    command = list(map(int, input().split()))
    if command[0] == 0:
        word.append(command[1])
    elif command[0] == 1:
        print('{0}'.format(word[command[1]]))
    elif command[0] == 2:
        word.pop()

Submission status: Accepted

Solution code:
line_num = int(input())
array = []
for i in range(line_num):
    line = [int(i) for i in input().split()]
    if line[0] == 0:
        array.append(line[1])
    elif line[0] == 2:
        array.pop()
    else:
        print(array[line[1]])

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n):
    order = input().split()
    if order[0] == '0':
        a.append(int(order[1]))
    elif order[0] == '1':
        print(a[int(order[1])])
    elif order[0] == '2':
        a.pop()

Submission status: Accepted

Solution code:
from sys import stdin
from collections import deque

num = int(input())

q = deque()

for i in range(num):

	cmd = stdin.readline().strip().split()

	if cmd[0] == "0":
		#末尾に挿入
		q.append(cmd[1])

	elif cmd[0] == "1":
		#要素の出力
		print(q[int(cmd[1])],sep='\n')
	else:
		#末尾の削除
		q.pop()

Submission status: Accepted

Solution code:
cnt = int(input())
a = []
for i in range(cnt):
    li = list(map(int,input().split()))
    if li[0] == 0:
        a.append(li[1])
    elif li[0] ==1:
        print(a[li[1]])
    else:
        a.pop(-1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat May 19 14:55:45 2018
AOJ ITP2_1_A  
@author: maezawa
"""

q = int(input())
a = []

for i in range(q):
    ops= list(map(int,input().split()))
    if ops[0] == 0:
        a.append(ops[1])
    elif ops[0] == 1:
        print(a[ops[1]])
    else:
        a.pop(-1)

Submission status: Accepted

Solution code:
stack = []

q = int(input())
for i in range(q):
    op = list(map(int, input().split(' ')))
    if op[0] == 0:
        stack.append(op[1])
    elif op[0] == 1:
        print(stack[op[1]])
    elif op[0] == 2:
        stack.pop()

Submission status: Accepted

Solution code:

from collections import UserList


class Vector(UserList):
    def push_back(self, v):
        self.data.append(v)

    def pop_back(self):
        return self.data.pop()


def run():
    vec = Vector()
    count = int(input())

    for i in range(count):
        com, *val = [int(x) for x in input().split()]
        if com == 0:
            vec.push_back(val[0])
        elif com == 1:
            print(vec[val[0]])
        elif com == 2:
            vec.pop_back()
        else:
            ValueError('invalid command')


if __name__ == '__main__':
    run()

Submission status: Accepted

Solution code:
arr = []
q = int(input())

for _ in range(q):
    cmd = input().split()
    cmdNum = int(cmd[0])
    if cmdNum == 0:
        arr.append(int(cmd[1]))
    elif cmdNum == 1:
        print(arr[int(cmd[1])])
    else:
        arr.pop()

Submission status: Accepted

Solution code:
# Vector 2018/06/02
# job hunting (*_*)

class Vector(object):
    def __init__(self):
        self.A = list()

    def pushBack(self, x):
        self.A.append(x)

    def randomAccess(self, p):
        print self.A[p]

    def popBack(self):
        del self.A[-1]

A = Vector()
q = int(raw_input())
for i in range(q):
    line = [int(i) for i in raw_input().split()]
    if line[0] == 0:
        A.pushBack(line[1])
    elif line[0] == 1:
        A.randomAccess(line[1])
    else:
        A.popBack()

Submission status: Accepted

Solution code:
stack = []
 
q = int(input())
for i in range(q):
    op = list(map(int, input().split(' ')))
    if op[0] == 0:
        stack.append(op[1])
    elif op[0] == 1:
        print(stack[op[1]])
    elif op[0] == 2:
        stack.pop()

Submission status: Accepted

Solution code:
def pushBack(lists, x):
    return lists.insert(len(lists), x)

def randomAccess(lists, p):
    print(lists[p])

def popBack(lists):
    return lists.pop(len(lists) - 1)

if __name__ == '__main__':
    l = list()
    n = int(input())
    for i in range(n):
        j= input().split()

        if int(j[0]) == 0:
            pushBack(l, int(j[1]))
        elif int(j[0]) == 1:
            randomAccess(l, int(j[1]))
        else:
            popBack(l)

Submission status: Accepted

Solution code:
# coding=utf-8

N = int(input())
A = []
for i in range(N):
    query = list(map(int, input().split()))
    if query[0] == 0:
        A.append(query[1])
    elif query[0] == 1:
        print(A[query[1]])
    elif query[0] == 2:
        A.pop()

Submission status: Accepted

Solution code:
import sys

def decodes(x):
	temp = []
	for i in range(len(x)):
		if x[i][0] == 0:
			temp.append(x[i][1])
		elif x[i][0] == 1:
			print(temp[x[i][1]])
		elif x[i][0] == 2:
			temp = temp[:len(temp) - 1]

l = []
for i in sys.stdin:
	l.append(i.split())

for i in range(len(l)):
	for j in range(len(l[i])):
		l[i][j] = int(l[i][j])

decodes(l)

Submission status: Accepted

Solution code:
# AOJ ITP2_1_A: Vector
# Python3 2018.6.24 bal4u

from collections import deque
Q = deque()
q = int(input())
for i in range(q):
	a = input()
	if a[0] == '2': Q.pop()      # popBack
	else:
		id, v = map(int, a.split())
		if id == 0: Q.append(v)  # pushBack
		else: print(Q[v])        # randomAccess

Submission status: Accepted

Solution code:
# AOJ ITP2_1_A: Vector
# Python3 2018.6.24 bal4u

from collections import deque
Q = deque()
q = int(input())
for i in range(q):
	a = input()
	if   a[0] == '0': Q.append(a[2:])      # pushBack
	elif a[0] == '1': print(Q[int(a[2:])]) # randomAccess
	else:             Q.pop()              # popBack

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 24 14:53:50 2018
ITP21A
@author: maezawa
"""

from collections import deque

d = deque()

n = int(input())

for i in range(n):
    c = list(map(int, input().split()))
    if c[0] == 0:
        d.append(c[1])
    elif c[0] == 1:
        print(d[c[1]])
    else:
        d.pop()

Submission status: Accepted

Solution code:
q=int(input())
A=[]
for i in range(q):
    s=input()
    if s[0]=="0":
        a,b=map(int,s.split())
        A.append(b)
    if s[0]=="1":
        a,b=map(int,s.split())
        print(A[b])
    if s[0]=="2":
        A=A[:-1]

Submission status: Accepted

Solution code:
n=int(input())
s=[]
for i in range(n):
    a=list(map(int,input().split()))
    b=len(a)
    if b==2:
        if a[0]==0:
            s.append(a[1])
        else:
            print(s[a[1]])
    else:
        s.pop()

Submission status: Accepted

Solution code:
# AOJ ITP2_1_A: Vector
# Python3 2018.6.24 bal4u

from collections import deque
Q = deque()
q = int(input())
for i in range(q):
    a = input()
    if   a[0] == '0': Q.append(a[2:])      # pushBack
    elif a[0] == '1': print(Q[int(a[2:])]) # randomAccess
    else:             Q.pop()              # popBack

Submission status: Accepted

Solution code:
def pushBack(x):
	A.append(x)


def randomAccess(p):
	print(A[p])


def popBack():
	A.pop()


q = int(input())
A = []
for _ in range(q):
	tmp = input()
	if tmp=='2':
		popBack()
	else:
		a, b = map(int, tmp.split())
		if a==0:
			pushBack(b)
		else:
			randomAccess(b)

Submission status: Accepted

Solution code:
A = []
n = int(input())
for i in range(n):
    tmp = input().split()
    if tmp[0] == "2":
        A.pop()
    else:
        if tmp[0] == "0":
            A.append(tmp[1])
        else:
            print(A[int(tmp[1])])

Submission status: Accepted

Solution code:
q = int(input())
A = []
ans = []
for i in range(q):
    q = str(input())
    if q[0] == "0": #pushBack
        A.append(int(q[2:]))
    elif q[0] == "1": #randamAccess
        # ans.append(A[int(q[2:])])
        print(A[int(q[2:])])
    else: #popBack
        A.pop()

Submission status: Accepted

Solution code:
A = []
ans = []


def pushBack(x):
    A.append(x)


def randomAccess(p):
    if A != []:
        ans.append(A[p])
    else:
        print('RandAccError')


def popBack():
    if A != []:
        del A[-1]
    else:
        print('DelError')


def main():
    q = input()
    for i in range(int(q)):
        try:
            query, number = (int(x) for x in input().split())
        except ValueError:
            popBack()
            continue

        if query == 0:
            pushBack(number)
        elif query == 1:
            randomAccess(number)

    for i in range(len(ans)):
        print(ans[i])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#vector    
def pushBack(a, x):
    a.append(x)
def randomAccess(a, p):
    print(a[p])
def popBack(a):
    a = a[:-1]
    return a
q = int(input())
a = []
for _ in range(q):
    b = list(map(int, input().split()))
    if b[0] == 0:
        pushBack(a, b[1])
    elif b[0] == 1:
        randomAccess(a, b[1])
    else:
        a = popBack(a)

Submission status: Accepted

Solution code:
import sys

A = []

Q = int(sys.stdin.readline().rstrip())
for _ in range(Q):
    s = sys.stdin.readline().rstrip().split()
    if s[0] == "0":  # pushback
        A.append(s[1])
    elif s[0] == "1":  # randomAccess
        print(A[int(s[1])])
    else:
        A.pop()

Submission status: Accepted

Solution code:
class vector:
    data = []

    def pashBack(self, x):
        self.data.append(x)

    def randomAccess(self, p):
        return self.data[p]

    def popBack(self):
        deta_index = len(self.data)-1
        del self.data[deta_index]


q = int(input())
v = vector()

for i in range(q):
    order = input().split()

    if order[0] == "0":
        x = int(order[1])
        v.pashBack(x)

    elif order[0] == "1":
        x = int(order[1])
        data = v.randomAccess(x)
        print(data)

    elif order[0] == "2":
        v.popBack()

Submission status: Accepted

Solution code:
import sys
N = int(input())
a = []
for i in range(N):
  line = sys.stdin.readline().split()
  if int(line[0]) == 0:
    a.append(int(line[1]))
  elif int(line[0]) == 1:
    print(a[int(line[1])])
  elif  int(line[0]) == 2:
    a.pop()

Submission status: Accepted

Solution code:
def resolve():
    from collections import deque
    q = int(input())
    ans = deque()
    for _ in range(q):
        q = [int(i) for i in input().split()]
        if q[0] == 2:
            ans.pop()
        else:
            x = q[1]
            if q[0] == 0:
                ans.append(x)
            else:
                print(ans[x])


resolve()

Submission status: Accepted

Solution code:
N = int(input())
A = []

for _ in range(N):
    order = list(map(int,input().split()))
    if order[0] == 0:
        A.append(order[1])
    elif order[0] == 1:
        print(A[order[1]])
    else:
        del A[-1]

Submission status: Accepted

Solution code:
A = []
n = int(input())
for i in range(n):
    q = input()
    if q[0] == "0":
        A.append(q[2:])
    elif q[0] == "1":
        print(A[int(q[2:])])
    else:
        del A[-1]

Submission status: Accepted

Solution code:
q=int(input())
lis=[]
lq=[]
for i in range(q):
	lq.append([int(x) for x in input().split(' ')])

for i in lq:
	order=i[0]
	if order==0:
		lis.append(i[1])
	elif order==1:
		print(lis[i[1]])
	elif order==2:
		lis.pop(-1)

Submission status: Accepted

Solution code:
from collections import deque
Q = deque()
q = int(input())
for i in range(q):
	a = input()
	if   a[0] == '0': Q.append(a[2:])      # pushBack
	elif a[0] == '1': print(Q[int(a[2:])]) # randomAccess
	else:             Q.pop()              # popBack

Submission status: Accepted

Solution code:
class Vector:
    def __init__(self):
        self.vec = []
    
    def push_back(self,x):
        self.vec.append(x)
    
    def random_access(self,p):
        return self.vec[p]

    def pop_back(self):
        self.vec.pop()

my_vec = Vector()

n = int(input())
for _ in range(n):
    args = input().split(' ')
    ope = args[0]
    if ope == '0':
        my_vec.push_back(int(args[1]))
    elif ope == '1':
        print(my_vec.random_access(int(args[1])))
    elif ope == '2':
        my_vec.pop_back()

Submission status: Accepted

Solution code:
Q = int(input())
stack = []
for _ in range(Q):
    query = list(map(int,input().split()))
    if query[0] == 0:
        stack.append(query[1])
    elif query[0] == 1:
        print(stack[query[1]])
    else:
        stack.pop()

Submission status: Accepted

Solution code:
n = int(input())
s = []
for i in range(n):
    order = list(map(int,input().split()))
    if order[0] == 0:
        s.append(order[1])
    elif order[0] == 1:
        print(s[order[1]])
    elif order[0] == 2:
        s.pop()

Submission status: Accepted

Solution code:
num = int(input())

A=[]

for i in range(num):
    queryi = list(map(int, input().split()))
    if queryi[0] == 0:
        A.append(queryi[1])
    elif queryi[0] == 1:
        print(A[queryi[1]])
    elif queryi[0] == 2:
        A.pop(-1)
    else:
        print("error")

Submission status: Accepted

Solution code:
def pushBack(vec,x):
    vec.append(x)
    return vec

def randomAccess(vec, p):
    return vec[p]

def popBack(vec):
    vec= vec[0:len(vec)-1]    
    return vec

n = int(input())
num_list = []
for i in range(n):
    num_list.append(list(map(int,input().split())))

num_of_operations = num_list[0][0]
vec = []
for i in range(len(num_list)):
    operation = num_list[i][0]
    if(operation == 2):
        vec = popBack(vec)
    else:
        n = num_list[i][1]
        
        if(operation == 0):
            vec = pushBack(vec,n)

        if(operation == 1):
            value = randomAccess(vec,n)
            print(value)

Submission status: Accepted

Solution code:
q = int(input())
A = []
for i in range(q):
    query = input().split()
    if query[0] == '0':
        A.append(query[1])
    elif query[0] == '1':
        print(A[int(query[1])])
    elif query[0] == '2':
        A.pop()

Submission status: Accepted

Solution code:
#空リスト作成
str_list = []

#標準入力繰り返す
for _ in range(int(input())):
    
    #aが0ならリストの最後にbを加え、1ならリストのb番目のを出力
    try:
        a,b = map(int,input().split())
        if a == 0:str_list.append(b)
        elif a == 1:print(str_list[b])
        
    #入力数が1個しかなかったらリストの一番最後を消す
    except ValueError:
        str_list.pop(-1)

Submission status: Accepted

Solution code:
q = int(input())
A = []

for i in range(q):
    Q, *x = (int(x) for x in input().split())
    x = x[0] if x else None
    if Q == 0:
        A.append(x)
    elif Q == 1:
        print(A[x])
    else:
        del A[-1]

Submission status: Accepted

Solution code:

from sys import stdin
from collections import deque

n = int(input())
deq = deque()
for i in range(n):
    q = list(stdin.readline().split())
    if q[0] == '0':
        deq.append(q[1])
    elif q[0] == '1':
        print(deq[int(q[1])])
    else:
        deq.pop()

Submission status: Accepted

Solution code:
A = list()

#0:pushBack
def pushBack(x):
  A.append(x)

#1:randomAccess
def randomAccess(x):
  print(A[x])
  
#2:popBack
def popBack():
  A.pop()


cmdList = [ pushBack, randomAccess, popBack ]
n = int(input())

for i in range(n):
  cmd = input()
  if cmd.startswith("0"):
    c,param = map(int,cmd.split(" "))
    cmdList[0](param)
  if cmd.startswith("1"):
    c,param = map(int,cmd.split(" "))
    cmdList[1](param)
  if cmd.startswith("2"):
    cmdList[2]()

Submission status: Accepted

Solution code:
q = int(input())
querys = [list(map(int, input().split())) for _ in range(q)]

stack = []
for query in querys:
    if query[0] == 0:
        stack.append(query[1])

    if query[0] == 1:
        print(stack[query[1]])

    if query[0] == 2:
        stack.pop()

Submission status: Accepted

Solution code:
def pushBack(A, x):
    A.append(x)
def randomAccess(A, x):
    return A[x]
def popBack(A):
    _=A.pop()


A = []
q = int(input())
for _ in range(q):
    query = input()
    if query == '2':
        popBack(A)
    else:
        query = list(map(int, query.split()))
        if query[0] == 0:
            pushBack(A, query[1])
        elif query[0] == 1:
            print(randomAccess(A, query[1]))

Submission status: Accepted

Solution code:
q = int(input())
A = []
for _ in range(q):
    tmp = [int(i) for i in input().split()]
    if tmp[0] == 0:
        A.append(tmp[1])
    if tmp[0] == 1:
        print(A[tmp[1]])
    if tmp[0] == 2:
        A.pop()

Submission status: Accepted

Solution code:
from collections import deque

q = int(input())

que = deque()
for i in range(q):
    query = input().split()

    if query[0] == "0":
        que.append(query[1])
    elif query[0] == "1":
        print(que[int(query[1])])
    else:##popBack
        que.pop()

Submission status: Accepted

Solution code:
lst=[]
n = int(input())
for i in range(n) :
    ope = list(map(int, input().split()))
    if ope[0] == 0 :
        lst.append(ope[1])
    elif ope[0] == 1 :
        print(lst[ope[1]])
    elif ope[0] == 2 :
        del lst[-1]

Submission status: Accepted

Solution code:
q = int(input())
data_list = list()
for i in range(q):
    data = input()
    data_list.append(data)

a = list()
for data in data_list:
    if data[0] == "0":
        a.append(data.split()[1])
    elif data[0] == "1":
        print(a[int(data.split()[1])])
    else:
        a.pop(-1)

Submission status: Accepted

Solution code:
q = int(input())
l = []
while q > 0:
    q -= 1
    s = input().split()
    if s[0] == '0':
        l.append(s[1])
    elif s[0] == '1':
        print(l[int(s[1])])
    else:
        l.pop()

Submission status: Accepted

Solution code:
l=[]
n=int(input())
for i in range(n):
    q=list(map(int,input().split()))
    if q[0]==0:
        l.append(q[1])
    elif q[0]==1:
        print(l[q[1]])
    else:
        del l[-1]

Submission status: Accepted

Solution code:
from collections import deque
Q = deque()
q = int(input())
for i in range(q):
    a = input().split()
    if a[0] == "0":Q.append(a[1])
    elif a[0] == "1": print(Q[int(a[1])])
    else: Q.pop()

Submission status: Accepted

Solution code:
q = int(input())
A = []
for i in range(q):
    a, *x = (int(x) for x in input().split())
    if a == 0:
        A.append(x[0])
    elif a == 1:
        print(A[int(x[0])])
    else:
        del A[-1]

Submission status: Accepted

Solution code:
q = int(input())
A = []
for i in range(q):
    query = [int(i) for i in input().split()]
    if query[0] == 0:
        A.append(query[1])
    elif query[0] == 1:
        print(A[query[1]])
    elif query[0] == 2:
        A.pop(len(A)-1)

Submission status: Accepted

Solution code:
N = int(input())

num_list = []

def pushback(x):
    num_list.append(x)
    
def randomAccess(p):
    print(num_list[p])
    
def popBack():
    num_list.pop()
    
for i in range(N):
    input_num = input().split()
    if input_num[0] == "0":
        pushback(input_num[1])
    elif input_num[0] == "1":
        randomAccess(int(input_num[1]))
    else:
        popBack()

Submission status: Accepted

Solution code:
d = []
n = int(input())
for _ in range(n):
    q = list(map(int,input().split()))
    if q[0] == 0:
        d.append(int(q[1]))
    if q[0] == 1:
        print (d[int(q[1])])
    if q[0] == 2:
        d.pop()

Submission status: Accepted

Solution code:
a=[]
for _ in range(int(input())):
    ar=list(map(int,input().split()))
    if len(ar)==1: x,=ar
    else: x,y=ar
    if x==0:
        a.append(y)
    if x==1:
        print(a[y])
    if x==2:
        a.pop()

Submission status: Accepted

Solution code:
n = int(input())
ans = []


for i in range(n):
    m = list(map(int,input().split()))
    if m[0] == 0:
        ans.append(m[1])
    elif m[0] == 1:
        print(ans[m[1]])
    
    elif m[0] == 2:
        ans.pop()

Submission status: Accepted

Solution code:
num=int(input())
A=[]
for i in range(num):
    lst=list(map(int,input().split()))
    if lst[0]==0:
        A.append(lst[1])
        
    elif lst[0]==1:
        print(A[lst[1]])
        
    elif lst[0]==2:
        del A[-1]

Submission status: Accepted

Solution code:
import itertools

def spaced_to_ints(spaced_some):
    return [int(a) for a in spaced_some.split(" ")]

def order_sequence_chars(str):
    return list(str)
def count_order(order):
    return(int(order))

def get_dice():
    input_data = input().split(" ")
    items = [int(cont) for cont in input_data]
    keys = ['T', 'S', 'E', 'W', 'N', 'B']
    return dict(zip(keys, items))

def rot_dice(rot, dice):
    if rot == "N":
        keys = ['T', 'S', 'B', 'N']
        items = dice['S'], dice['B'], dice['N'], dice['T']
        new_dice = dict(zip(keys, items))
        dice.update(new_dice)

    if rot == "S":
        keys = ['T', 'S', 'B', 'N']
        items = dice['N'], dice['T'], dice['S'], dice['B']
        new_dice = dict(zip(keys, items))
        dice.update(new_dice)

    if rot == "E":
        keys = ['T', 'E', 'B', 'W']
        items = dice['W'], dice['T'], dice['E'], dice['B']
        new_dice = dict(zip(keys, items))
        dice.update(new_dice)

    if rot == "W":
        keys = ['T', 'E', 'B', 'W']
        items = dice['E'], dice['B'], dice['W'], dice['T']
        new_dice = dict(zip(keys, items))
        dice.update(new_dice)

    if rot == "R":
        keys = ['N', 'W', 'S', 'E']
        items = dice['E'], dice['N'], dice['W'], dice['S']
        new_dice = dict(zip(keys, items))
        dice.update(new_dice)

    if rot == "L":
        keys = ['N', 'W', 'S', 'E']
        items = dice['W'], dice['S'], dice['E'], dice['N']
        new_dice = dict(zip(keys, items))
        dice.update(new_dice)

def search_right_surf(conds, dice):
    a, b = conds
    a_key = [k for k, v in dice.items() if v == a]
    b_key = [k for k, v in dice.items() if v == b]
    key_list = a_key + b_key

    part_st = ''.join(key_list)

    def search(part_st):
        if part_st in "TNBST":
            return "W"

        if part_st in "TSBNT":
            return "E"

        if part_st in "TEBWT":
            return "N"

        if part_st in "TWBET":
            return "S"

        if part_st in "NESWN":
            return "B"

        if part_st in "NWSEN":
            return "T"

    target_key = search(part_st)
    print(dice[target_key])

def search_top_surf(top_surf, dice):

    dice2_surf, *_ = [k for k, v in dice.items() if v == top_surf]

    if dice2_surf == 'N':
        rot_dice("S", dice)

    if dice2_surf == 'B':
        controls = list("SS")
        for i in controls:
            rot_dice(i, dice)
    if dice2_surf == 'S':
        controls = list("N")
        for i in controls:
            rot_dice(i, dice)
    if dice2_surf == 'W':
        controls = list("E")
        for i in controls:
            rot_dice(i, dice)
    if dice2_surf == 'E':
        controls = list("W")
        for i in controls:
            rot_dice(i, dice)

def search_flont_surf(flont_surf, dice):

    dice2_surf, *_ = [k for k, v in dice.items() if v == flont_surf]

    if dice2_surf == 'E':
        controls = list("R")
        for i in controls:
            rot_dice(i, dice)

    if dice2_surf == 'S':
        controls = list("RR")
        for i in controls:
            rot_dice(i, dice)

    if dice2_surf == 'W':
        rot_dice("L", dice)

def rot_compare(dice1, dice2):

    def compare_dice(dice1, dice2):
        if dice1 == dice2:
            return True

    comb = ["N", "S", "E", "W", "R", "L"]
    tups = list()
    for i in range(6):
        tups.append(itertools.combinations(comb, i))

    if compare_dice(dice1, dice2):
        return True

    for commands in itertools.chain.from_iterable(tups):
        for command in commands:
            rot_dice(command, dice2)
            if compare_dice(dice1, dice2):
                return True
    return False

def compare_many_dices(dice_list):
    dice1 = dice_list.pop(0)
    for dice2 in dice_list:
        if rot_compare(dice1, dice2):
            return True
    return False

def q1():

    dice = get_dice()
    controls = list(input())
    for i in controls:
        rot_dice(i, dice)
    print(dice["T"])

def q2():

    dice = get_dice()
    a = input()
    repeater = int(a)

    for neee in range(repeater):
        control_input = input().split(" ")
        conds = [int(i) for i in control_input]
        search_right_surf(conds, dice)

def q3():
    dice1 = get_dice()
    dice2 = get_dice()

    if rot_compare(dice1, dice2):
        print("Yes")
    else:
        print("No")

def q4():
    inp = input()
    dice_num = int(inp)
    dice_list = list()
    for i in range(dice_num):
        dice_list.append(get_dice())

    if compare_many_dices(dice_list):
        print("No")

    else:
        print("Yes")

def alds1():
    n = int(input())
    A = [int(cont) for cont in input().split(" ")]

    print(' '.join(map(str, A)))

    for _i in range(len(A)-1):
        i = _i+1
        v = A[i]
        j = i-1

        while j >= 0:
            if A[j] < v:
                break

            A[j+1] = A[j]
            A[j] = v
            j = j - 1

        print(' '.join(map(str, A)))

def itp2_1_a():
    def pushBack(li, insertion):
        li.append(insertion)

    def randomAccess(li, dist):
        print(li[dist])

    def popBack(li):
        li.pop(-1)

    def func_allocate(mylist, inp):
        # "0 x" or "1 p" or "2" given

        order, *a = spaced_to_ints(inp)
        if a:
            num = a[0]
        if order == 0:
            pushBack(mylist, num)

        if order == 1:
            randomAccess(mylist, num)

        if order == 2:
            popBack(mylist)

    mylist = list()
    count = count_order(input())

    for i in range(count):
        func_allocate(mylist, input())

itp2_1_a()

Submission status: Accepted

Solution code:
_q = int(input())
v = []
for _ in range(_q):
    *q, = map(int, input().split())

    if q[0] == 0:
        v.append(q[1])
    elif q[0] == 1:
        print(v[q[1]])
    elif q[0] == 2:
        v.pop()

Submission status: Accepted

Solution code:
n = int(input())
my_list = []
for _ in range(n):
    t = input().split()
    if t[0] == "0":
        my_list.append(int(t[1]))
    elif t[0] == "1":
        print(my_list[int(t[1])])
    else:
        my_list.pop(-1)

Submission status: Accepted

Solution code:
l = []

n = int(input())
for i in range(n):
    x = input().split()
    if len(x)==2:
        if int(x[0])==0:
            l.append(int(x[1]))
        elif int(x[0])==1:
            print(l[int(x[1])])
    else:
        l.pop()

Submission status: Accepted

Solution code:
def get_input():
  return list(map(lambda s: int(s), input().split(' ')))

n = get_input()[0]
l = []
for _ in range(n):
  c = get_input()
  if c[0] == 0: # pushBack(x)
    l.append(c[1])
  elif c[0] == 1: # randomAccess(p)
    print(l[c[1]])
  elif c[0] == 2: # popBack()
    l = l[0:len(l)-1]

Submission status: Accepted

Solution code:
from collections import deque

q = int(input())
a = deque()

for i in range(q):
    inp = input()
    # pushBack
    if inp[0] == "0":
        operation, x = list(map(int, inp.split()))
        a.append(x)

    # randomAccess
    elif inp[0] == "1":
        operation, p = list(map(int, inp.split()))
        print(a[p])

    # popBack
    else:
        a.pop()

Submission status: Accepted

Solution code:
listA = []
num = int(input())
for i in range(num):
    command = input().split()
    if command[0] == "0":
        listA.append(int(command[1]))
    elif command[0] == "1":
        print(listA[int(command[1])])
    elif command[0] == "2":
        listA.pop(-1)

Submission status: Accepted

Solution code:
import collections
q = int(input())
A = collections.deque()
ans = list()
for i in range(q):
    query = list(map(int, input().split()))
    if query[0] == 0:
        A.append(query[1])
    elif query[0] == 1:
        ans.append(A[query[1]])
    elif query[0] == 2:
        A.pop()
for a in ans:
    print(a)

Submission status: Accepted

Solution code:
a = []
q = int(input())
for _ in range(q):
    k = [int(i) for i in input().split()]
    if not k[0]:
        a.append(k[1])
    elif k[0] == 1:
        print(a[k[1]])
    else:
        del a[-1]

Submission status: Accepted

Solution code:
def main():
	q = int(input())
	a = []
	for _ in range(q):
		query = input()
		qn = query[0]
		if qn != "2":
			x = int(query[2:])
		if qn == "0":
			a += [x]
		elif qn == "1":
			print(a[x])
		else:
			a.pop(-1)

main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

Q = int(input())
A = []
ans = []

for _ in range(Q):
    q = list(map(int,input().split()))
    if q[0] == 0:
        A.append(q[1])
    elif q[0] == 1:
        ans.append(A[q[1]])
    else:
        A.pop()

print(*ans,sep='\n')

Submission status: Accepted

Solution code:
q = int(input())
v = []
for _ in range(q):
	op = list(map(int, input().split()))
	if op[0]==0:
		v.append(op[1])
	elif op[0]==1:
		print(v[op[1]])
	else:
		v.pop(len(v)-1)

Submission status: Accepted

Solution code:
from collections import deque

if __name__ == "__main__":

    n = int(input())
    queue = deque()

    for _ in range(n):
        param = input().split(" ")

        if param[0] == "0":
            queue.append(param[1])
        elif param[0] == "1":
            print(queue[int(param[1])])
        elif param[0] == "2":
            queue.pop()