r,c = list(map(int,input().split()))

rc = list([int(x) for x in input().split()] for _ in range(r))

[rc[i].append(sum(rc[i])) for i in range(r)]

rc.append([sum(i) for i in zip(*rc)])



for col in rc: print((*col))
r,c = list(map(int,input().split()))

rc=[]

total=[]

for _ in range(r): rc.append(list(map(int,input().split())))

for i in range(r): rc[i].append(sum(rc[i]))

for i in zip(*rc): total.append(sum(i))

rc.append(total)

for col in rc: print((*col))
r, c = list(map(int, input().split()))
rc = list([int(x) for x in input().split()] for _ in range(r))
[rc[i].append(sum(rc[i])) for i in range(r)]
rc.append([sum(i) for i in zip(*rc)])
for col in rc:
    print((*col))

r, c = list(map(int, input().split()))
rc = []
total = []
for _ in range(r):
    rc.append(list(map(int, input().split())))
for i in range(r):
    rc[i].append(sum(rc[i]))
for i in zip(*rc):
    total.append(sum(i))
rc.append(total)
for col in rc:
    print((*col))

-rc = list([int(x) for x in input().split()] for _ in range(r)) -[rc[i].append(sum(rc[i])) for i in range(r)] -rc.append([sum(i) for i in zip(*rc)]) +rc = [] +total = [] +for _ in range(r): +    rc.append(list(map(int, input().split()))) +for i in range(r): +    rc[i].append(sum(rc[i])) +for i in zip(*rc): +    total.append(sum(i)) +rc.append(total)