(r,c) = [int(i) for i in input().split()]

 

table = []

for rc in range(r):

    table.append([int(i) for i in input().split()])

 

table.append([0 for _ in range(c + 1)])

 

for rc in range(r):

    row_total = 0

    for cc in range(c):

        table[r][cc] += table[rc][cc]

        row_total += table[rc][cc]

 

    table[rc].append(row_total)

    table[r][c] += row_total

 

for row in table:

    print((' '.join([str(column) for column in row])))
(r, c) = [int(i) for i in input().split()]

last_row = [0 for _ in range(c+1)]

 

for _ in range(r):

    row = [int(i) for i in input().split()]

    for cc in range(c):

        last_row[cc] += int(row[cc])

        print(row[cc], end=' ')

 

    print(sum(row))

 

last_row[-1] = sum(last_row)

print(' '.join([str(a) for a in last_row]))

(r, c) = [int(i) for i in input().split()]
table = []
for rc in range(r):
    table.append([int(i) for i in input().split()])
table.append([0 for _ in range(c + 1)])
for rc in range(r):
    row_total = 0
    for cc in range(c):
        table[r][cc] += table[rc][cc]
        row_total += table[rc][cc]
    table[rc].append(row_total)
    table[r][c] += row_total
for row in table:
    print((" ".join([str(column) for column in row])))

(r, c) = [int(i) for i in input().split()]
last_row = [0 for _ in range(c + 1)]
for _ in range(r):
    row = [int(i) for i in input().split()]
    for cc in range(c):
        last_row[cc] += int(row[cc])
        print(row[cc], end=" ")
    print(sum(row))
last_row[-1] = sum(last_row)
print(" ".join([str(a) for a in last_row]))

-table = [] -for rc in range(r): -    table.append([int(i) for i in input().split()]) -table.append([0 for _ in range(c + 1)]) -for rc in range(r): -    row_total = 0 +last_row = [0 for _ in range(c + 1)] +for _ in range(r): +    row = [int(i) for i in input().split()] -        table[r][cc] += table[rc][cc] -        row_total += table[rc][cc] -    table[rc].append(row_total) -    table[r][c] += row_total -for row in table: -    print((" ".join([str(column) for column in row]))) +        last_row[cc] += int(row[cc]) +        print(row[cc], end=" ") +    print(sum(row)) +last_row[-1] = sum(last_row) +print(" ".join([str(a) for a in last_row]))