别直接按字典序排序.

from sys import stdin
from random import randint
input = lambda: stdin.readline().strip()
# read1 = stdin.read().split()
# idx = 1
l = []
for _ in range(int(input())):
    x = [int(i) for i in input().split()]
    if x[0] == 1:
        l.append(x[1])
    elif x[0] == 2:
        l.pop()
    elif x[0] == 3:
        print(l[x[1]])
    elif x[0] == 4:
        l.insert(x[1]+1,x[2])
    elif x[0] == 5:
        l.sort()
    elif x[0] == 6:
        l.sort(reverse=True)
    elif x[0] == 7:
        print(len(l))
    else:
        print(" ".join(map(str,l)))