Problem:
Vector II For $n$ dynamic arrays $A_i$ ($i = 0, 1, ..., n-1$), perform a sequence of the following operations:  pushBack($t$, $x$): Add element $x$ at the end of $A_t$.  dump($t$): Print all elements in $A_t$.  clear($t$): Clear $A_t$. If $A_t$ is empty, do nothing.  $A_i$ is a 0-origin array and it is empty in the initial state. Input The input is given in the following format. $n$ $q$
$query_1$
$query_2$
:
$query_q$ Each query $query_i$ is given by 0 $t$ $x$ or 1 $t$ or 2 $t$ where the first digits 0 , 1 and 2 represent pushBack, dump and clear operations respectively. Output For each dump operation, print elements of $A_t$ a line. Separete adjacency elements by a space character (do not print the space after the last element). Note that, if the array is empty, an empty line should be printed. Constraints  $1 \leq n \leq 1,000$  $1 \leq q \leq 500,000$  $-1,000,000,000 \leq x \leq 1,000,000,000$  The total number of elements printed by dump operations do not exceed 500,000  Sample Input 1 3 13
0 0 1
0 0 2
0 0 3
0 1 -1
0 2 4
0 2 5
1 0
1 1
1 2
2 1
1 0
1 1
1 2 Sample Output 1 1 2 3
-1
4 5
1 2 3

4 5

Solution (Python):
a = [int(i) for i in input().split()]
list = []

for i in range(a[0]):
    list.append([])

for i in range(a[1]):
    cmd = [int(i) for i in input().split()]

    if cmd[0] == 0:
        list[cmd[1]].append(cmd[2])

    elif cmd[0] == 1:
        output = ""
        for x in list[cmd[1]]:
            output += str(x) + " "
        if output != "": output = output[:-1]
        print(output)

    elif cmd[0] == 2:
        list[cmd[1]] = []

Solution (Python):
a = [int(i) for i in input().split()]
list = []

for i in range(a[0]):
    list.append([])

for i in range(a[1]):
    cmd = [int(i) for i in input().split()]

    if cmd[0] == 0:
        list[cmd[1]].append(cmd[2])

    elif cmd[0] == 1:
        maped = map(str, list[cmd[1]])
        output = " ".join(maped)
        print(output)

    elif cmd[0] == 2:
        list[cmd[1]] = []

Solution (Python):
n, q = list(map(int, input().split(' ')))
stacks = [[] for i in range(n)]

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

Solution (Python):
def run():
    n, q = [int(x) for x in input().split()]
    ls = [[] for _ in range(n)]

    for _ in range(q):
        command = input()
        if command.startswith('0'):
            i, j = [int(x) for x in command[2:].split()]
            ls[i].append(j)
        elif command.startswith('1'):
            i = int(command[2:])
            print(" ".join([str(x) for x in ls[i]]))
        elif command.startswith('2'):
            i = int(command[2:])
            ls[i] = []
        else:
            raise ValueError('invalid command')


if __name__ == '__main__':
    run()

Solution (Python):


n, q = map(int, input().split())
A = [[] for i in range(n)]

for j in range(q):
    query = list(map(int, input().split()))
    if query[0] == 0:
        A[query[1]].append(query[2])
    elif query[0] == 1:
        print(' '.join(map(str, A[query[1]])))
    elif query[0] == 2:
        A[query[1]].clear()

Solution (Python):
from collections import deque
if __name__ == '__main__':
    n, q = input().split()
    n, q= int(n), int(q)
    lists = [deque([]) for i in range(n)]

    for i in range(q):
        p = input().split()
        if p[0] == '0':
            lists[int(p[1])].append(p[2])
        elif p[0] == '1':
            frag = False
            for i in lists[int(p[1])]:
                print(' ' + i if frag else i, end = '')
                frag = True
            print()
        else:
            lists[int(p[1])].clear()

Solution (Python):



from collections import deque
n, q = map(int, input().split())
Q = []
for i in range(n): Q.append(deque())
for i in range(q):
	a = input().split()
	t = int(a[1])
	if   a[0] == '0': Q[t].append(a[2])   
	elif a[0] == '1': print(*Q[t])        
	else: Q[t].clear()

Solution (Python):

"""
Created on Sun Jun 24 14:53:50 2018
ITP21D
@author: maezawa
"""

n, q = list(map(int, input().split()))
a = [[] for _ in range(n)]

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

Solution (Python):
from collections import deque

n,q = map(int,input().split())

Q = [deque() for _ in range(n)]

for _ in range(q):
    a = input().split()
    t = int(a[1])
    if a[0] == "0":
        
        Q[t].append(a[2])
    elif a[0] == "1":
        if Q[t]:
            print(*Q[t])
        else:
            print()
    else:
        if Q[t]:
            Q[t].clear()
        else:
            continue

Solution (Python):


from collections import deque
n, q = map(int, input().split())
Q = []

for i in range(n):
    Q.append(deque())
for i in range(q):
    a = input().split()
    t = int(a[1])
    if a[0] == '0':
        Q[t].append(a[2])
    elif a[0] == '1':
        print(*Q[t])
    else:
        Q[t].clear()

Solution (Python):









import os
import sys




def main():
    n, q = map(int, input().split())
    big_list = [[] for _ in range(n)]
    for _ in range(q):
        query = list(map(int, input().split()))
        if len(query) == 3:
            big_list[query[1]].append(query[2])
        else:
            if query[0] == 1:
                if big_list[query[1]]:
                    print(big_list[query[1]][0], end="")
                    for i in range(1, len(big_list[query[1]])):
                        print(" {}".format(big_list[query[1]][i]), end="")
                print()
            else:
                big_list[query[1]].clear()


if __name__ == "__main__":
    main()

Solution (Python):
def resolve():
    from collections import deque
    n, Q = [int(i) for i in input().split()]
    ans = [deque() for _ in range(n)]
    for _ in range(Q):
        q = [int(i) for i in input().split()]
        if q[0] == 0:
            ans[q[1]].append(q[2])
        elif q[0] == 1:
            print(*ans[q[1]])
        else:
            ans[q[1]].clear()


resolve()

Solution (Python):
def pushBack(t,x):
    global A
    A[t].append(str(x))

def dump(t):
    global A
    if A[t] == []:
        print()
    else:
        print(" ".join(A[t]))
def clear(t):
    global A
    A[t] =[]


A =[]
num = list(map(int, input().split()))
for j in range(num[0]):
    A.append([])

for i in range(num[1]):
    queryi = list(map(int, input().split()))
    
    if queryi[0] == 0:
        pushBack(queryi[1], queryi[2])

    elif queryi[0] == 1:
        dump(queryi[1])
    
    else:
        clear(queryi[1])

Solution (Python):

from sys import stdin
from collections import deque

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

for i in range(q):
    l = list(stdin.readline().split())
    l[1] = int(l[1])
    if l[0] == '0':
        q_list[l[1]].append(l[2])
    elif l[0] == '1':
        print(' '.join(q_list[l[1]]))
    else:
        q_list[l[1]].clear()

Solution (Python):

def pushBack(t,x):
  A[t].append(x)
  

def dump(t):
  if len(A[t]) > 0:
    print(A[t][0],end="")
    for i in A[t][1:]:
      print(" {}".format(i), end="")
  print()


def clear(t):
  A[t].clear()
  

cmdList = [ pushBack, dump, clear ]
n,q = map(int,input().split())
A = list()
for i in range(n):
  A.append([])

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

Solution (Python):
n,q = map(int,input().split())
L = [[] for _ in range(n)]

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

    if query[0] == "0":
        L[int(query[1])].append(query[2])
    elif query[0] == "1":
        print(*L[int(query[1])])
    else:
        L[int(query[1])] = []

Solution (Python):
n, q = map(int, input().split())
A = [[] for i in range(n)]
while q:
    q -= 1
    op = input().split()
    if op[0] == '0':
        A[int(op[1])].append(op[2])
    elif op[0] == '1':
        print(*A[int(op[1])])
    else:
        A[int(op[1])].clear()

Solution (Python):
from collections import deque

def main():
    n,m = map(int,input().split())
    dq = [deque() for _ in range(n)]
    for _ in range(m):
        q = list(map(int,input().split()))
        if q[0] == 0:dq[q[1]].append(q[2])
        elif q[0] == 1:print (' '.join(map(str,dq[q[1]])))
        else :dq[q[1]].clear()



if __name__ == '__main__':
    main()

Solution (Python):
from collections import deque
n,q = map(int,input().split())
Q = []
for i in range(n):
    Q.append(deque())
for i in range(q):
    a = input().split()
    t = int(a[1])
    if a[0] == "0":Q[t].append(a[2])
    elif a[0] == "1":print(*Q[t])
    else: Q[t].clear()

Solution (Python):



from collections import deque
n, q = map(int, input().split())
Q = []
for i in range(n): Q.append(deque())
for i in range(q):
	a, *b = map(int, input().split())
	if   a == 0: Q[b[0]].append(b[1])   
	elif a == 1: print(*Q[b[0]])        
	else: Q[b[0]].clear()

Solution (Python):
n,q=map(int,input().split())
l=[[] for i in range(n)]

for i in range(q):
    qry=list(map(int,input().split()))
    if qry[0]==0:
        l[qry[1]].append(qry[2])
    elif qry[0]==1:
        li=map(str,l[qry[1]])
        print(' '.join(map(str,li)))
    else:
        l[qry[1]].clear()

Solution (Python):
def get_input():
  return list(map(int, input().split(' ')))

(n, q) = get_input()

l = [[] for i in range(n)]

for _ in range(q):
  c = get_input()
  if c[0] == 0: 
    l[c[1]].append(c[2])
  elif c[0] == 1: 
    print(' '.join(map(str, l[c[1]])))
  elif c[0] == 2: 
    l[c[1]] = []

Solution (Python):
N, Q = map(int, input().split())

A = [[] for _ in range(N)]

for _ in range(Q):
    query = list(map(int, input().split()))
    if query[0] == 0:
        A[query[1]].append(query[2])
    elif query[0] == 1:
        print(*A[query[1]])
    elif query[0] == 2:
        A[query[1]].clear()

Solution (Python):






from sys import stdin,setrecursionlimit










setrecursionlimit(10**6+1)
input=stdin.readline

n,q=map(int,input().split())
a=[[] for _ in range(n)]
for _ in range(q):
    c,*t=map(int,input().split())
    if c==0:
        a[t[0]].append(t[1])
    elif c==1:
        print(*a[t[0]])
    else:
        a[t[0]].clear()

Solution (Python):
from collections import deque

n, q = list(map(int, input().split()))
A = deque()
[A.append([]) for _ in range(n)]

for i in range(q):
    query = list(map(int, input().split()))
    t = query[1]

    
    if query[0] == 0:
        x = query[2]
        A[t].append(x)

    
    elif query[0] == 1:
        print(*A[t])

    
    else:
        if len(A[t]) != 0:
            A[t].clear()

Solution (Python):
n, q = map(int, input().split())
A = [[] for i in range(n)]
queries = list()
for i in range(q):
    queries.append(list(map(int, input().split())))
for query in queries:
    if query[0] == 0:
        A[query[1]].append(query[2])
    elif query[0] == 1:
        print(' '.join(map(str, A[query[1]])))
    elif query[0] == 2:
        A[query[1]].clear()

Solution (Python):
import sys
input = sys.stdin.readline

N,Q = map(int,input().split())

A = [[] for _ in range(N)]

for _ in range(Q):
    q = list(map(int,input().split()))
    if q[0] == 0:
        A[q[1]].append(q[2])
    elif q[0] == 1:
        if A[q[1]]:
            print(' '.join(map(str,A[q[1]])))
        else:
            print()
    else:
        A[q[1]] = []

Solution (Python):
def main():
    n, q = map(int, input().split())
    At = list()
    for i in range(n):
        At.append(list())

    for _ in range(q):
        param = [int(a) for a in input().split()]

        if   param[0] == 0:
            At[param[1]].append(param[2])

        elif param[0] == 1:
            if len(At[param[1]]) == 0:
                print()
            else:
                print(*At[param[1]])

        elif param[0] == 2:
            if len(At[param[1]]) == 0:
                continue
            else:
                At[param[1]].clear()
main()

Solution (Python):
class Vector():
    def __init__(self, num_vector):
        self.vector = [[] for i in range(0, num_vector)]

    def pushBack(self, t, x):
        self.vector[t].append(x)
        return self

    def dump(self, t):
        print(' '.join(map(str, self.vector[t])))
        return self

    def clear(self, t):
        self.vector[t].clear()
        return self


num_vector, num_queue = tuple(map(int, input().split(' ')))
A = Vector(num_vector)

for i in range(0, num_queue):
    queue = tuple(map(int, input().split(' ')))
    if queue[0] == 0:
        A.pushBack(queue[1], queue[2])
    elif queue[0] == 1:
        A.dump(queue[1])
    elif queue[0] == 2:
        A.clear(queue[1])

Solution (Python):
n,q=[int(i) for i in input().split(" ")]
A=[[] for i in range(n)]

for _ in range(q):
    query=[int(i) for i in input().split(" ")]
    if query[0]==0:
        A[query[1]].append(query[2])
    elif query[0]==1:
        print(" ".join([str(j) for j in A[query[1]]]))
    else:
        A[query[1]]=[]

Solution (Python):
from collections import deque
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n,q=map(int, input().split())
    aa=[[] for _ in range(n)]
    for _ in range(q):
        qq=list(map(int, input().split()))
        if qq[0]==0:
            aa[qq[1]].append(qq[2])
        elif qq[0]==1:
            print(*aa[qq[1]])
        else:
            aa[qq[1]]=[]

main()

Solution (Python):
n, seq = [int(x) for x in input().split()]
L = []
for i in range(n):
    L.append([])

for i in range(seq):
    c, t, x = [ int(x) for  x in (input() + " 0").split()][:3]
    if c == 0:
        L[t].append(x)
    elif c == 1:
        print( " ".join(map(str,L[t])) )
    elif c == 2:
        L[t].clear()
    else:
        pass

Solution (Python):
import sys
n, q = map(int, input().split())

A = [[] for _ in range(n)]
for _ in range(q):
    query = list(map(int,sys.stdin.readline().split()))
    
    if query[0] == 0:
        A[query[1]].append(query[2])
    elif query[0] == 1:
        print(*A[query[1]])
    else:
        del A[query[1]][:]

Solution (Python):
from typing import List


if __name__ == "__main__":
    num_vector, num_query = map(lambda x: int(x), input().split())
    int_vector: List[List[int]] = [[] for _ in range(num_vector)]
    for _ in range(num_query):
        op, *value = map(lambda x: int(x), input().split())
        if (0 == op):
            int_vector[value[0]].append(value[1])
        elif (1 == op):
            print(" ".join([str(elem) for elem in int_vector[value[0]]]))
        elif (2 == op):
            int_vector[value[0]] = []
        else:
            pass

Solution (Python):

n,q=map(int,input().split( ))
A=[[] for i in range(n)]
for i in range(q):
    command=input().split( )
    com=int(command[0])
    if len(command)>2:
        t=int(command[1])
        x=int(command[2])
    else:
        t=int(command[1])
    if com==0:
        A[t].append(x)
    elif com==1:
        print(*A[t])
    elif com==2:
        A[t].clear()

Solution (Python):
def solve():
    import sys
    f_i = sys.stdin
    
    n, q = map(int, f_i.readline().split())
    A = [[] for i in range(n)]
    ans = []
    
    for l in (line.split() for line in f_i):
        op = l[0]
        if op == '0':
            A[int(l[1])].append(l[2])
        elif op == '1':
            ans.append(' '.join(A[int(l[1])]))
        else:
            A[int(l[1])].clear()
    print('\n'.join(ans))

solve()

Solution (Python):

"""
Dynamic Arrays and List - Vector II
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_1_D&lang=jp

"""
n, q = map(int, input().split())
A = [[] for _ in range(n)]
for _ in range(q):
    op, t, x = (input() + ' 1').split()[:3]
    if op == '0':
        A[int(t)].append(x)
    elif op == '1':
        print(*A[int(t)])
    else:
        A[int(t)] = []

Solution (Python):
from sys import stdin
from collections import deque

n, q = map(int,stdin.readline().split())
queries = stdin.readlines()
A = [deque() for _ in range(n)]


for query in queries:
    
    
    query = query.split()
    if query[0] == '0':
        A[int(query[1])].append(query[2])
    elif query[0] == '1':
        print(' '.join(list(A[int(query[1])])))
    else:
        A[int(query[1])].clear()

Solution (Python):
class arrayList():
    def __init__(self):
       self.L = []

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

    def dump(self):
        print(" ".join(map(str, self.L)))

    def clear(self):
        self.L.clear()

n,queries = map(int, input().split())
parentList = {}
for i in range(queries):
    q, t, *x = map(int, input().split())
    if parentList.get(t) == None:
        parentList[t] = arrayList()

    if q == 0:
        parentList[t].pushBack(x[0])
    elif q == 1:
        parentList[t].dump()
    elif q == 2:
        parentList[t].clear()

Solution (Python):
n, q = map(int, input().split())

A = [[] for _ in range(n)]


for _ in range(q):

    command, *list_num = input().split()

    t = int(list_num[0])

    if   command == "0":
        x = int(list_num[1])
        A[t].append(x)
    elif command == "1":
        print(*A[t])
    elif command == "2":
        A[t].clear()
    else:
        raise

Solution (Python):
n, q = map(int, input().split())
aa = [list() for i in range(n)]
for i in range(q):
  order = list(map(int, input().split()))
  if order[0] == 0:
    t = order[1]
    x = order[2]
    aa[t].append(x)
  elif order[0] == 1:
    t = order[1]
    for j in range(len(aa[t])):
      if j == 0:
        print(aa[t][j], end = "")
      else:
        print("", aa[t][j], end = "")
    print()
  elif order[0] == 2:
    t = order[1]
    del aa[t][:]
  else:
    pass

Solution (Python):
def p(b):
    print(*box[b])

n, q = map(int, input().split())
box = [[]for i in range(n)]
for _ in range(q):
    a, b, *c = map(int, input().split())
    if a == 0:
        box[b] += [c[0]]
    elif a == 1:
        p(b)
    else:
        box[b] = []

Solution (Python):
from sys import stdin

n,q = map(int,input().split(" "))

list2 = [[] for _ in range(n)]

for i in range(q):
	cmd = stdin.readline().strip().split()

	if cmd[0] == "0":
		list2[int(cmd[1])].append(cmd[2])
	elif cmd[0] == "1":
		print(*list2[int(cmd[1])])
	else:
		list2[int(cmd[1])].clear()

Solution (Python):
from collections import deque
n,q = map(int, input().split())
A = []

for i in range(n):
    A.append(deque())
for i in range(q):
    a = input().split()
    t = int(a[1])
    
    if a[0] == '0':
        A[t].append(a[2])
    elif a[0] == '1':
        print(*A[t])
    else:
        A[t].clear()

Solution (Python):
def pushback(A,t,x):
    A[t].append(x)
    return A

def dump(A,t):
    count=len(A[t])
    if count==0:
        print()
    else:
        print(str(A[t][0]),end="")
        if count>1:
            for i in range(1,count):
                print(" "+str(A[t][i]),end="")
        print()

def clear(A,t):
    A[t].clear()
    return A

n,q=(int(x) for x in input().split())
A=[[] for i in range(n)]
for i in range(q):
    query=list(map(int,input().split()))
    if query[0]==0:
        A=pushback(A,query[1],query[2])
    elif query[0]==1:
        dump(A,query[1])
    else:
        A=clear(A,query[1])

Solution (Python):
from array import array
n,q = [int(i) for i in input().split()]

count = [0 for i in range(n)]
input_ = [0 for i in range(q)] 
for i in range(q):
	input_[i] = input()
	a = [int(i) for i in input_[i].split()]
	if a[0] == 0:
		count[a[1]] += 1
A = [array('i',[0 for i in range(count[j]+1)]) for j in range(n)]
cursor = [-1 for i in range(n)]

def pushBack(t, x):
	cursor[t] += 1
	A[t][cursor[t]] = x
def dump(t):
	print(*A[t][:cursor[t]+1], sep=' ')
def clear(t):
	cursor[t] = -1

for input__ in input_:
	a = [int(i) for i in input__.split()]
	if a[0] == 0:
		pushBack(a[1],a[2])
	elif a[0] == 1:
		dump(a[1])
	else:
		clear(a[1])

Solution (Python):
q,n = map(int,input().split(" "))

A = [[] for i in range(q)]

for i in range(n):
    a = [int(j) for j in input().split(" ")]
    if a[0] == 0:
        A[a[1]].append(a[2])
    elif a[0] == 1:
        print(" ".join(map(str,A[a[1]])))
    elif a[0] == 2:
        A[a[1]].clear()

Solution (Python):
def main():
    n, q = [int(x) for x in input().split(' ')]
    arys = []
    for i in range(n):
        arys.append([])
    for i in range(q):
        query = input()
        cmd = int(query[0])
        if cmd == 0:
            _, t, x = [int(x) for x in query.split(' ')]
            arys[t].append(x)
        elif cmd == 1:
            _, t = [int(x) for x in query.split(' ')]
            print(' '.join([str(x) for x in arys[t]]))
        elif cmd == 2:
            _, t = [int(x) for x in query.split(' ')]
            arys[t] = []


if __name__ == '__main__':
    main()

Solution (Python):
import sys
from collections import deque
n, q = map(int, input().split())

deq = deque()
arrays = {str(i): deque() for i in range(n)}

lines = sys.stdin.readlines()
for i in range(q):
    query, *arg = lines[i].split()
    if query == '0':    
        arrays[arg[0]].append(arg[1])
    elif query == '1':  
        print(" ".join(arrays[arg[0]]))
    elif query == '2':  
        arrays[arg[0]].clear()
    else:
        raise AssertionError

Solution (Python):



from collections import deque
import sys
input = sys.stdin.readline

def loop_proc():
    (n1,n2) = map(int,input().split())
    wl =[]
    for i in range(n1):
        wl.append(deque())
    for i in range(n2):
        l = list(map(int,input().split()))  
        if (l[0] == 0 ):
            wl[l[1]].append(l[2])
        elif (l[0] == 1 ):
            if ( len(wl[l[1]]) == 0 ):
                print ("")
            else:
                print (" ".join(map(str,wl[l[1]])))
        elif (l[0] == 2 ):
            wl[l[1]] = deque()
 

loop_proc()

Solution (Python):
n, q = map(int, input().split())
mat = [[] for _ in range(n)]

for _ in range(q):
    command = list(map(int, input().split()))
    if command[0] == 0:
        mat[command[1]].append(command[2])
    elif command[0] == 1:
        print(' '.join(str(c) for c in mat[command[1]]))
    elif command[0] == 2:
        mat[command[1]].clear()

Solution (Python):
import sys
from collections import defaultdict
n = int(sys.stdin.readline().split()[0])
A = defaultdict(list)
ans = []
for query in sys.stdin:
    if query[0] == '0':
        t, x = query[2:].split()
        A[t].append(x)
    elif query[0] == '1':
        ans.append(' '.join(A[query[2:-1]]) + '\n')
    else:
        A[query[2:-1]] = []
sys.stdout.writelines(ans)

Solution (Python):
readline = open(0).readline
writelines = open(1, 'w').writelines
N, Q = map(int, readline().split())
ans = []
A = [[] for i in range(N)]
def push(t, x):
    A[t].append(str(x))
def dump(t):
    ans.append(" ".join(A[t]))
    ans.append("\n")
def clear(t):
    A[t] = []


C = [push, dump, clear].__getitem__
for i in range(Q):
    t, *a=map(int, readline().split())
    C(t)(*a)
writelines(ans)

Solution (Python):
from collections import deque

n, q = map(int, input().split())
A = [deque() for _ in range(n)]

for _ in range(q):
    query = list(map(int, input().split()))
    if query[0] == 0:
        A[query[1]].append(query[2])
    elif query[0] == 1:
        print(*A[query[1]])
    elif query[0] == 2:
        A[query[1]] = deque()

Solution (Python):



import sys
from collections import defaultdict

dyna_list = defaultdict(list)   

n,q = map(int, sys.stdin.readline().split())
for i in range(q):
    query = sys.stdin.readline().split()  
    ope = query[0]
    list_id = query[1]

    if ope == '0':      
        dyna_list[list_id].append(query[2])
    elif ope == '1':    
        print(' '.join(dyna_list[list_id]))
    elif ope == '2':    
        dyna_list[list_id].clear()

Solution (Python):
from collections import deque
n, q = list(map(int, input().split()))
A = deque()
for i in range(n):
    A.append(deque())
for i in range(q):
    query = list(map(int, input().split()))
    if query[0] == 0:
        A[query[1]].append(query[2])
    elif query[0] == 1:
        print(*list(map(str,A[query[1]])))
    else:
        A[query[1]].clear()

Solution (Python):
n, q = list(map(int, input().split()))
a = [[] for _ in range(n)]
for _ in range(q):
  q = list(map(int, input().split()))
  if q[0]==0:
    a[q[1]].append(q[2])
  elif q[0]==1:
    print(" ".join(map(str, a[q[1]])))
  elif q[0]==2:
    a[q[1]].clear()