import sys



p = 0

x1 = []

for line in sys.stdin:

    x = [int(i) for i in line.split()]

    if p == 0:

        r,c = x

        p = 1

    else:

        x1.append(x)



for i in range(r):

    x1[i].append(sum(x1[i]))

x=[]

for j in range(c+1):

    s = 0

    for i in range(r):

        s += x1[i][j]

    x.append(s)

x1.append(x)



for i in range(r+1):

    for j in range(c+1):

        print(x1[i][j], end=' ')

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



x = [list(map(int, input().split())) for i in range(r)]



x.append([sum([x[i][j] for i in range(r)]) for j in range(c)])



for e1 in x:

    for e in e1:

        print(e, end=' ')

    print(sum(e1))
import sys

p = 0
x1 = []
for line in sys.stdin:
    x = [int(i) for i in line.split()]
    if p == 0:
        r, c = x
        p = 1
    else:
        x1.append(x)
for i in range(r):
    x1[i].append(sum(x1[i]))
x = []
for j in range(c + 1):
    s = 0
    for i in range(r):
        s += x1[i][j]
    x.append(s)
x1.append(x)
for i in range(r + 1):
    for j in range(c + 1):
        print(x1[i][j], end=" ")
    print()

r, c = list(map(int, input().split()))
x = [list(map(int, input().split())) for i in range(r)]
x.append([sum([x[i][j] for i in range(r)]) for j in range(c)])
for e1 in x:
    for e in e1:
        print(e, end=" ")
    print(sum(e1))

-import sys - -p = 0 -x1 = [] -for line in sys.stdin: -    x = [int(i) for i in line.split()] -    if p == 0: -        r, c = x -        p = 1 -    else: -        x1.append(x) -for i in range(r): -    x1[i].append(sum(x1[i])) -x = [] -for j in range(c + 1): -    s = 0 -    for i in range(r): -        s += x1[i][j] -    x.append(s) -x1.append(x) -for i in range(r + 1): -    for j in range(c + 1): -        print(x1[i][j], end=" ") -    print() +r, c = list(map(int, input().split())) +x = [list(map(int, input().split())) for i in range(r)] +x.append([sum([x[i][j] for i in range(r)]) for j in range(c)]) +for e1 in x: +    for e in e1: +        print(e, end=" ") +    print(sum(e1))