Problem:
Spreadsheet Your task is to perform a simple table calculation. Write a program which reads the number of rows r , columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column. Input In the first line, two integers r and c are given. Next, the table is given by r lines, each of which consists of c integers separated by space characters. Output Print the new table of ( r +1) × ( c +1) elements. Put a single space character between adjacent elements. For each row, print the sum of it's elements in the last column. For each column, print the sum of it's elements in the last row. Print the total sum of the elements at the bottom right corner of the table. Constraints  1 ≤ r , c ≤ 100  0 ≤ an element of the table ≤ 100  Sample Input 4 5
1 1 3 4 5
2 2 2 4 5
3 3 0 1 1
2 3 4 4 6 Sample Output 1 1 3 4 5 14
2 2 2 4 5 15
3 3 0 1 1 8
2 3 4 4 6 19
8 9 9 13 17 56

Solution (Python):
r, c = map(int, input().split())
lis = [[] for a in range(r+1)]
for x in range(r):
    lis[x] = list(map(int, input().split()))
    lis[x].append(sum(lis[x]))
lis[r] = [0 for a in range(c+1)]
for y in range(c+1):
    for z in range(r):
        lis[r][y] += lis[z][y]
for x in lis:
    for z,y in enumerate(x):
        if z == c:
            print(y)
        else:
            print(y, end = " ")

Solution (Python):


sheet = [int(i) for i in input().rstrip().split()]
rows = sheet[0]
columns = sheet[1]

spreadSheet = []
for i in range(rows):
    row = [int(j) for j in input().rstrip().split()]
    rowTotal = 0
    for element in row:
        rowTotal += element
    row.append(rowTotal)
    spreadSheet.append(row)

spreadColumns = columns + 1

totalRow = []
for column in range(spreadColumns):
    columnTotal = 0
    for i in range(rows):
        columnTotal += spreadSheet[i][column]
    totalRow.append(columnTotal)
spreadSheet.append(totalRow)


for spreadRow in spreadSheet:
    row_str = [str(element) for element in spreadRow]
    print(' '.join(row_str))

Solution (Python):

import sys

n, m = input().strip().split(" ")
n = int(n) ;m = int(m)

c = n

a = []
for line in sys.stdin :
    a.append(line)
    c -= 1
    if c == 0 :
        break
for i in range(0, len(a)) :
    a[i] = a[i].strip().split(" ")
    for j in range(0, len(a[i])) :
        a[i][j] = int(a[i][j])

for r in range(0, len(a)) :
    a[r].append(sum(a[r]))

arr = []
for c in a[0] :
    arr.append(0)
for r in range(0, len(a)) :
    for c in range(0, len(a[i])) :
        arr[c] += a[r][c]
a.append(arr)

for i in a :
    for j in range(0, len(i)) :
        if j != len(i)-1 :
            print(str(i[j]), end=" ")
        else :
            print(str(i[j]), end="")

    print()

Solution (Python):
g,r=map(int,input().split());
num,table=list(),list()
for i in range(g):
    num=list(map(int,input().split()))
    num.append(0)
    table.append(num)
num=[0 for i in range(r+1)]
table.append(num)
for i in range(g):
    for j in range(r):
        table[i][r]+=table[i][j]
        table[g][j]+=table[i][j]
    table[g][r]+=table[i][r]
for i in range(g+1):
    for j in range(r):
        print(table[i][j],end=" ")
    print(table[i][r])

Solution (Python):
r, c = map(int,input().split())
a=[]
for i in range(r):
    a.append(list(map(int,input().split())))
    a[i].append(0)
    aic = 0
    for k in range(c):
        aic = aic + a[i][k]
    a[i][c] = aic
a.append([0for i in range(c+1)])
for k in range(c):
    ark = 0
    for i in range(r):
        ark = ark + a[i][k]
    a[r][k] = ark
arc = 0
for i in range(r):
    arc = arc +a[i][c]
a[r][c] = arc

for i in range(r+1):
    for k in range(c+1):
        if k == c:
            print('{}'.format(a[i][k]), end = "")
        else:
            print('{} '.format(a[i][k]), end = "")
    print()

Solution (Python):
r, c = list(map(int, input().split()))
a = []
for i in range(r):
	a.append(list(map(int, input().split())))
	a[i] += [sum(a[i])]
	print(*a[i])
a = list(zip(*a))
for i in range(c):
	print(sum(a[i]), end=" ")
print(sum(a[c]))

Solution (Python):
r, c = map(int, raw_input().split())
t = []
for i in range(r):
    t.append(map(int, raw_input().split()))
    t[i].append(sum(t[i]))

t.append([sum([t[j][i] for j in range(r)]) for i in range(c+1)])

for i in range(r+1):
    print(" ".join(map(str, t[i])))

Solution (Python):
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],
    print

Solution (Python):
r, c = map(int, raw_input().split())

x = [map(int, raw_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,
    print sum(e1)

Solution (Python):
r,c=map(int,raw_input().split())
mx=[map(int,raw_input().split())+[0] for _ in range(r)]
mx.append([0]*(c+1))
for i in range(c):
    tmp=0
    for j in range(r):
        tmp+=mx[j][i]
    mx[r][i]=tmp
for x in mx:
    x[c]=sum(x)
for x in mx:
    print " ".join(map(str,x))

Solution (Python):
m=map(int,raw_input().split())
c=[0 for i in range(m[1])]
for j in range(m[0]):
        e=map(int,raw_input().split())
        r=0
        for i in range(m[1]):
                r+=e[i]
                c[i]+=e[i]
                print e[i],
        print r
s=0
for i in range(m[1]):
        s+=c[i]
        print c[i],
print s

Solution (Python):
from __future__ import division, print_function
from sys import stdin
r, c = (int(s) for s in stdin.readline().split())
sheet = [[int(s) for s in stdin.readline().split()] for _ in range(r)]
sheet.append([sum(row[i] for row in sheet) for i in range(c)])
for row in sheet:
    row.append(sum(row))
    print(*row)

Solution (Python):


import time
import sys
import io
import re
import math

start = time.clock()
l=[]
m=[]
s=[]
(r,c)=map(int, raw_input().split())
for i in range(r):
    l.append(map(int, raw_input().split()))

for cc in range(c):
    a=0
    for rr in range(r):
        a+=int(l[rr][cc])

    s.append(a)
for j in range(r):
    print ' '.join(map(str,l[j])),str(sum(l[j]))
print ' '.join(map(str,s)),str(sum(s))

Solution (Python):
r, c = map(int, raw_input().split())
sum_c = [0] * (c+1)
row_list = []
for i in xrange(r):
	row = map(int, raw_input().split())
	row.append(sum(row))
	row_list.append(row)
	sum_c = map(lambda x, y: x+y, sum_c, row) 
row_list.append(sum_c)
for row in row_list:
	print ' '.join(map(str, row))

Solution (Python):
r,c = map(int,raw_input().split())
sheet = []
for i in range(0,r):
    sheet.append(map(int,raw_input().split()))
total = [0] * (c+1)
for line in sheet:
    sum = 0
    for i,tmp in enumerate(line):
        total[i] += tmp 
        sum += tmp
    total[-1] += sum
    print " ".join(map(str,line))+" "+str(sum)
print " ".join(map(str,total))

Solution (Python):
r, c = map(int, raw_input().split())
ss = []
for i in range(r):
    ss.append(map(int, raw_input().split()))
    ss[i].append(sum(ss[i]))
    print ' '.join(map(str, ss[i]))
ss.append([])
for j in range(c+1):
    csum = 0
    for i in range(r):
        csum += ss[i][j]
    ss[r].append(csum)
print ' '.join(map(str, ss[r]))

Solution (Python):
r, c = map(int, raw_input().split())
sum_c = [0 for x in range(r)]
sum_r = [0 for x in range(c)]
sum = 0

for i in range(r):
    column = map(int, raw_input().split())
    for j in range(c):
        sum_c[i] += column[j]
        sum_r[j] += column[j]
        sum += column[j]
    print(" ".join(map(str, column)) + " " + str(sum_c[i]))

print (" ".join(map(str, sum_r)) + " " + str(sum))

Solution (Python):
r, c = map(int, raw_input().split())

line = [map(int, raw_input().split()) for i in range(r)]
foot = [0 for i in range(c+1)]

for i in range(len(line)):
	line[i].append(sum(line[i]))
	for j in range(len(line[i])):
		foot[j] += line[i][j]

line.append(foot)
for l in line:
	print " ".join(map(str, l))

Solution (Python):
raws, columns = map(int, input().strip().split())
a = []
for i in range(raws):
    a.append(list(map(int, input().strip().split())))
for i in range(raws):
    a[i].append(sum(a[i]))
a.append([sum(i) for i in zip(*a)])
for r in a:
    print(' '.join(str(x) for x in r))

Solution (Python):
n,m = map(int,input().split())
lst = [[0 for i in range(m+1)] for j in range(n+1)]
for i in range(n):
    line = list(map(int,input().split()))
    for j in range(m):
        lst[i][j] = line[j]
for i in range(n):
    for j in range(m):
        lst[i][m] += lst[i][j]
for j in range(m+1):
    for i in range(n):
        lst[n][j] += lst[i][j]
for i in range(n+1):
    for j in range(m+1):
        if j>0:
            print(f" {lst[i][j]}", end="")
        else:
            print(lst[i][j], end="")
    print()

Solution (Python):
r, c = map(int, input().split())
a = []

for i in range(r):
    a.append(list(map(int, input().split())))
    a[i].append(sum(a[i]))

for i in range(r):
    print(" ".join(list(map(str, a[i]))))

col_sum = []
for j in range(c+1):
    su = 0
    for i in range(r):
        su += a[i][j]
    col_sum.append(su)

print(" ".join(list(map(str, col_sum))))

Solution (Python):
r,c = map(int, input().split())
a=[]
sum1=[]
for i in range(r):
    a.append(list(map(int, input().split())))

for i in range(r):
    sum=0
    for j in range(c):
        print(a[i][j],end=' ')
        sum+=a[i][j]
        if i==0:
            sum1.append(a[i][j])
        else:
            sum1[j]+=a[i][j]
        if j==c-1:
            print(sum)
            if i==0:
                sum1.append(sum)
            else:
                sum1[c]+=sum
for i in range(c+1):
    if i!=c:
        print(sum1[i],end=' ')
    else:
        print(sum1[i])

Solution (Python):
r,c=map(int,input().split())
A=list()

for i in range(r):
    A.append(list(map(int,input().split())))
    A[i]+=[sum(A[i])]
    print(*A[i])
A=list(zip(*A[::-1]))
for i in range(c):
    print(sum(A[i]),end=' ')
print(sum(A[c]))

Solution (Python):
r, c = map(int, input().split())
a = []

for i in range(r):
    a.append(list(map(int, input().split())))
    a[i].append(sum(a[i]))

for i in range(r):
    print(" ".join(list(map(str, a[i]))))

col_sum = []
for j in range(c+1):
    su = 0
    for i in range(r):
        su += a[i][j]
    col_sum.append(su)

print(" ".join(list(map(str, col_sum))))

Solution (Python):
ll=[]
p=[]
a,b=map(int,input().split())
for i in range(a):
    l=input().rstrip().split()
    l=list(map(int,l))
    ll+=l
    

LL=[str(a) for a in ll]
for i in range(0,a*b,b):
    print(' '.join(LL[i:i+b]),sum(ll[i:i+b]))
    
for i in range(0,a):    
    ll.insert(i+b*(i+1),sum(ll[i+b*i:i+b*(i+1)]))

for j in range(b+1):
    J=[]
    for i in range(j,a*(b+1),b+1):
        J.append(ll[i])
    
    p.append(sum(J))
    
LL=[str(a) for a in p]
print(' '.join(LL))

Solution (Python):
i,j=map(int,input().split())
listA=[]
for n in range(i):
    listA.append(list(map(int,input().split())))
    listA[n].append(sum(listA[n]))
listA.append([])
for n in range(j+1):
    number=0
    for m in range(i):
        number+=listA[m][n]
    listA[i].append(number)
for n in range(i+1):
    print(' '.join(map(str,listA[n])))

Solution (Python):
r,c=map(int,input().split())
a = []
for i in range(r):
    a.append(list(map(int, input().split())))
    a[i]+=[sum(a[i])]
    print(*a[i])
a=list(zip(*a[::-1]))
for i in range(c):
    print(sum(a[i]),end=' ')
print(sum(a[c]))

Solution (Python):
n,m=map(int,input().split())
sum_n=[0]*m
sum=0
for i in range(n):
    lst=list(map(int,input().split()))
    sum_m=0
    for j in range(m):
        print(lst[j], end=" ")
        sum_m+=lst[j]
        sum_n[j]+=lst[j]
    print(sum_m)
    sum+=sum_m
for i in range(m):
    print(sum_n[i], end=" ")
print(sum)

Solution (Python):
h=0
i=0
j=0
a=[]

r,c = list(map(int,input().split()))
for h in range(c+1):
    a.append(0)
    h+=1
for i in range(r):
    I= list(map(int,input().split()))
    I.append(sum(I))
    print(*I)
    for j in range(c+1):
        
        a[j]=a[j]+I[j]
        
        j+=1
    i+=1
    j=0
    
    
        
print(*a)

Solution (Python):
n, m= map(int,input().split())
a =[]

for i in range(n):
    a.append(list(map(int, input().split())))
    a[i].append(sum(a[i]))

for i in range(n):
    print(" ".join(list(map(str,a[i]))))

sum = []
for j in range(m+1):
    s = 0
    for i in range(n):
        s += a[i][j]
    sum.append(s)

print(" ".join(list(map(str,sum))))

Solution (Python):
r, c = map(int, input().split())
table = [cc + [sum(cc)] for cc in (list(map(int, input().split())) for _ in range(r))]
table.append(list(map(sum, zip(*table))))
for line in table:
    print(*line)

Solution (Python):
r,c=map(int,input().split())
sheet=[list(map(int,input().split())) for i in range(r)]
for i in range(r):
    sheet[i].append(sum(sheet[i]))
Column_sum=[0]*(c+1)
for j in range(c+1):
    for i in range(r):
        Column_sum[j]+=sheet[i][j]
        
for i in range(r):
    print(*sheet[i])
print(*Column_sum)

Solution (Python):
r,c=[int(x) for x in input().split()]
s_row=[0 for x in range(c+1)]
for i in range(r):
	row=[int(x) for x in input().split()]
	row.append(sum(row))
	print(" ".join([str(x) for x in row]))
	s_row=[x+y for x,y in zip(s_row,row)]
print(" ".join([str(x) for x in s_row]))

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

A = []
for line in range(n):
    A.append(list(map(int, input().split())))

[A[i].append(sum(A[i])) for i in range(n)]

t = []
for i in range(m+1):
    t.append([A[j][i] for j in range(n)])
    t[i].append(sum(t[i]))

r = []
for i in range(n+1):
    r.append([t[j][i] for j in range(m+1)])
    print(' '.join(map(str, r[i])))

Solution (Python):
i,j=map(int,input().split())
lst=[]
for n in range(i):
    lst.append(list(map(int,input().split())))
    lst[n].append(sum(lst[n]))
lst.append([])
for n in range(j+1):
    number=0
    for m in range(i):
        number+=lst[m][n]
    lst[i].append(number)
for n in range(i+1):
    print(' '.join(map(str,lst[n])))

Solution (Python):
r,c = map(int,input().split());

A = [];
for i in range(0,r):
    a = list(map(int, input().split()));
    A.extend(a);

B = [];
for j in range(0,r):
    B.append(sum(A[j*c:j*c+(c-1)+1]));

for k in range(0,r): 
    A.insert(c*(k+1)+k, B[k]);

        
C = [];
for m in range(0,c+1):
    b = 0;
    for l in range(0,r):
        b += A[l*(c+1)+m];
    A.append(b);

t =  [str(n) for n in A];

for x in range(0, r+1):
    result = ' '.join(t[x*(c+1):x*(c+1)+(c+1)]);
    print(result);

Solution (Python):
r, c = map(int, input().split())
a = []

for i in range(r):
    a.append(list(map(int, input().split())))
    a[i].append(sum(a[i]))

for i in range(r):
    print(" ".join(list(map(str, a[i]))))

col_sum = []
for j in range(c+1):
    su = 0
    for i in range(r):
        su += a[i][j]
    col_sum.append(su)

print(" ".join(list(map(str, col_sum))))

Solution (Python):
r,c = map(int,input().split())
a = [[0]*c for i in range(r+1)]
for i in range(r):
    a[i] = list(map(int,input().split()))
for j in range(c):
    for i in range(r):
        a[r][j] += a[i][j]
for i in range(r+1):
        ans = 0
        for j in range(c):
            ans += a[i][j]
            print(a[i][j],end=' ')
        print(ans)

Solution (Python):
H,W = map(int,input().split())

table = [[0]*(W+1) for i in range(H+1)]

for row in range(H):
    work = list(map(int,input().split())) 
    for col in range(W):
        table[row][col] = work[col]


for row in range(H):
    for col in range(0,W):
        table[row][W] += table[row][col]


for col in range(0,W+1):
    for row in range(0,H):
        table[H][col] += table[row][col]


for row in range(0,H+1):
    print("%d"%(table[row][0]),end="")
    for col in range(1,W+1):
        print(" %d"%(table[row][col]),end = "")
    print()

Solution (Python):
r, c = map(int, input().split())

A = []

for i in range(r) :
    A.append([int(a) for a in input().split()])
    A[i].append(sum(A[i]))

S = []

for i in range(c + 1) :
    s = 0
    
    for j in range(r) :
        s += A[j][i]
        
    S.append(s)
        
A.append(S)

for i in range(r + 1) :
    for j in range(c + 1) :
        if j == c :
            print(A[i][j])
        else :
            print(A[i][j], end = " ")

Solution (Python):
n,m=map(int,input().split())
a=[list(map(int,input().split(" "))) for i in range(n)]

for i in range(n):
    print(*a[i],sum(a[i]))

c=[0]*m
for i in range(m):
    for j in range(n):
        c[i]=a[j][i]+c[i]
print(*c,sum(c))

Solution (Python):
r,c=map(int,input().split())
R=[]
A=[0]*(c+1)
for i in range(r):
    R.append(list(map(int,input().split())))
for i in range(r):    
    s=0
    for j in range(c):
        s+=R[i][j]
        A[j]+=R[i][j]
    print(' '.join(map(str,R[i]))+' '+str(s))
    A[c]+=s
print(' '.join(map(str,A)))

Solution (Python):




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

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

S = [0 for j in range(m)]
c = 0
for i in range(n):
   for j in range(m):
      print(A[i][j], end = "")
      print(" ", end = "")
   print(sum(A[i]))
   c += sum(A[i])

for j in range(m):
   sum = 0
   for i in range(n):
      sum += A[i][j]
   print(sum, end = "")
   print(" ", end = "")
print(c)

Solution (Python):
r,c=map(int,input().split())
a=[0]*(c+1)

for i in range(r):
    li=list(map(int,input().split()))
    for j in range(c):
        a[j]+=li[j]
    a[c]+=sum(li)
    li.append(sum(li))
    l=[str(a) for a in li]
    l=" ".join(l)
    print(l)
a=[str(b) for b in a]
a=" ".join(a)
print(a)

Solution (Python):

r,c=map(int,input().split())
table=[[0 for i in range(c+1)]for n in range(r+1)]
for i in range(r):
    var=list(map(int,input().split()))
    for n in range(len(var)+1):
        if(n==c):
            table[i][n]=sum(var)
        else:
            table[i][n]=var[n]

for i in range(r):
    for n in range(c):
        table[r][n]+=table[i][n]
table[r][c]=sum(table[r])
for line in table:
    length=len(line)
    for col in line:
        length-=1
        if length ==0 :
            print(str(col))
        else:
            print(str(col)+" ",end='')

Solution (Python):
rows, columns = map(int, input().split())
a = []
for i in range(rows):
    a.append(list(map(int, input().split())))
for i in range(rows):
    a[i].append(sum(a[i]))

b = [sum(i) for i in zip(*a)]
a.append(b)

for r in a:
    print(" ".join(str(i) for i in r))

Solution (Python):
r,c= map(int,input().split())
table= [list(map(int,input().split())) for i in range(r)]

for j in range(r):
  b=0
  for k in range(c):
    b+=table[j][k]
    print(table[j][k],end=" ")
  print(b)
a=[]
for k in range(c):
  d=0
  for j in range(r):
    d+=table[j][k]
  a.append(d)
print(' '.join(map(str,a)),end=' ')
print(sum(a))

Solution (Python):
r,c = map(int,input().split())
data = []
for i in range(r):
	data.append(list(map(int,input().split())))
for k in range(r):
	su = sum(data[k])
	an = data[k].copy()
	an = list(map(str,an))
	print(" ".join(an),su)
las = []
for kk in range(c):
	ans = 0
	for s in range(r):
		ans += data[s][kk]
	las.append(ans)
total = sum(las)
last = list(map(str,las))
print(" ".join(last),total)

Solution (Python):
a=[]
u=[]
x=[]
l=0  
num=input().split(' ')
for i in range(0,int(num[0]),1):
    sum=0
    num2=input().split(' ')
    for j in range(0,int(num[1]),1):
        sum=sum+int(num2[j])
        a.append(int(num2[j]))
    a.append(sum)
for k in range(int(num[1])+1):
    u.append(a[k::int(num[1])+1])
for i in range(0,len(u),1):
    sum2=0
    for j in range(0,len(u[i]),1):
        sum2=sum2+u[i][j]
    x.append(sum2)
for i in range(0,int(num[0]),1):
    for j in range(0,int(num[1])+1,1):
        if j==int(num[1]):
            print(a[l])
            l+=1
        else:    
            print(a[l],end=" ")
            l+=1    
for j in range(len(x)):
    if j==len(x)-1:
       print(x[j])
    else:    
       print(x[j],end=" ")

Solution (Python):
r,c=map(int,input().split())
a=[]

for i in range(r):
    a.append(list(map(int,input().split())))
    a[i].append(sum(a[i]))

for i in range(r):
    print(" ".join(list(map(str,a[i]))))
    
b=[]
for j in range(c+1):
    s=0
    for i in range(r):
        s+=a[i][j]
    b.append(s)

print(" ".join(list(map(str,b))))

Solution (Python):
n, m = map(int, input().split())
A = [[0 for j in range(m)] for i in range(n)]

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

S = [0 for j in range(m)]
c = 0
for i in range(n):
   for j in range(m):
      print(A[i][j], end = "")
      print(" ", end = "")
   print(sum(A[i]))
   c += sum(A[i])

for j in range(m):
   sum = 0
   for i in range(n):
      sum += A[i][j]
   print(sum, end = "")
   print(" ", end = "")
print(c)

Solution (Python):
r,c=(int(x) for x in input().split())
count=0
answer_lst=[]
while count<r:
    line=input().split()
    lst=[]
    total=0
    for i in line:
        lst.append(int(i))
        total+=int(i)
    lst.append(total)
    answer_lst.append(lst)
    count+=1
lst2=[]
for l in range(c+1):
    total2=0
    for m in answer_lst:
        total2+=m[l]
    lst2.append(total2)
answer_lst.append(lst2)
for ans in answer_lst:
    print(*ans)

Solution (Python):
r,c = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(r)]

for ai in a:
  print(*ai,end=' ')
  print(sum(ai))
for j in range(c):
  print(sum([a[i][j] for i in range(r)]),end=' ')
print(sum([sum(ai)for ai in a]))

Solution (Python):
r, c = map(int, input().split())
sheet = []

for i in range(r):
    sheet.append(list(map(int, input().split())))
    sheet[i].append(sum(sheet[i]))

for i in range(r):
    print(" ".join(list(map(str, sheet[i]))))

c_sum = []
for j in range(c+1):
    sum = 0
    for i in range(r):
        sum += sheet[i][j]
    c_sum.append(sum)

print(" ".join(list(map(str, c_sum))))

Solution (Python):
height, width = map(int, input().split())
table = []
for i in range(height):
    table.append(list(map(int, input().split())))
    table[i].append(sum(table[i]))
table.append([0 for i in range(width + 1)])
for i in range(height):
    for j in range(width + 1):
        table[-1][j] += table[i][j]
    print(*table[i])
print(*table[-1])

Solution (Python):
r,c = map(int, input().split())
data = [list(map(int, input().split())) for i in range(r)]
ans = 0
sita = []

for i in range(r):
  data[i].append(sum(data[i]))
  ans += sum(data[i])

for i in range(c):
  temp = 0
  for j in range(r):
    temp += data[j][i]
  sita.append(temp)
sita.append(ans//2)
data.append(sita)

for i in range(r+1):
  text = " ".join(map(str, data[i]))
  print(text)

Solution (Python):
r,c=map(int,input().split())
sheet=[list(map(int,input().split())) for i in range(r)]
for i in range(r):
    sheet[i].append(sum(sheet[i]))
Column_sum=[0]*(c+1)
for j in range(c+1):
    for i in range(r):
        Column_sum[j]+=sheet[i][j]

for i in range(r):
    print(*sheet[i])
print(*Column_sum)

Solution (Python):
R, C = map(int, input().split())
sheet = []
for r in range(R):
    row = list(map(int,input().split()))
    s = sum(row)
    row.append(s)
    sheet.append(row)

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

for r in range(R):
  for c in range(C + 1):
    last_row[c] += sheet[r][c]
sheet.append(last_row)

for row in sheet:
  print(*row, sep = ' ')

Solution (Python):
r,c=list(map(int,input().split()))
a=[]
A1=[[0 for col in range(c+1)] for row in range(r+1)]
sum_col=0
sum_row=0
for row in range(r):
    A = list(map(int,input().split()))
    a.append(A)
for row in range(r):
    for col in range(c):
        A1[row][col]=a[row][col]
for row in range(r+1):
    for col in range(c+1):
        sum_col+=A1[row][col]
    A1[row][c]=sum_col
    sum_col=0
for col in range(c+1):
    for row in range(r+1):
        sum_row+=A1[row][col]
    A1[r][col]=sum_row
    sum_row=0
for row in range(r+1):
    print("%d"%(A1[row][0]),end="")
    for col in range(1,c+1):
        print(" %d"%(A1[row][col]),end="")
    print()

Solution (Python):
r, c = map(int, input().split())
a = []

for i in range(r):
    a.append(list(map(int, input().split())))
    a[i].append(sum(a[i]))

for i in range(r):
    print(" ".join(list(map(str, a[i]))))

col_sum = []
for j in range(c+1):
    su = 0
    for i in range(r):
        su += a[i][j]
    col_sum.append(su)

print(" ".join(list(map(str, col_sum))))

Solution (Python):
c,r=map(int,input().split())
a=[]
for i in range (c):
    a.append(list(map(int,input().split())))
    a[i]+=[sum(a[i])]
    print(*a[i])
    
a=list(zip(*a[::-1]))
for i in range(r):print(sum(a[i]),end=' ')
print(sum(a[r]))

Solution (Python):
r,c=map(int,input().split())
s=[]
for _ in range(r):
    s.append(list(map(int,input().split())))

tmpc=[0 for _ in range(c+1)]
for i in range(r):
    tmpr=0
    for j in range(c):
        tmpr+=s[i][j]
        tmpc[j]+=s[i][j]
    s[i].append(tmpr)
    tmpc[-1]+=tmpr
s.append(tmpc)
for i in range(r+1):
    for j in range(c):
        print(s[i][j],end=" ")
    print(s[i][-1])

Solution (Python):
n,m=map(int,input().split())
a=[list(map(int,input().split(" "))) for i in range(n)]

for i in range(n):
    print(*a[i],sum(a[i]))

c=[0]*m
for i in range(m):
    for j in range(n):
        c[i]=a[j][i]+c[i]
print(*c,sum(c))

Solution (Python):
r, c = map(int, input().split())
nums = []
for i in range(r):
    i = list(map(int, input().split()))
    i_add = sum(i)
    i.append(i_add)
    nums.append(i)
last = []
for j in range(c):
    add_num = 0
    for k in range(r):
        add_num += nums[k][j]
    last.append(add_num)
last_sum = sum(last)
last.append(last_sum)
nums.append(last)
for i in nums:
    L = [str(m) for m in i]
    print(' '.join(L))

Solution (Python):
r,c = map(int, input().split())
l = []
for i in range(0, r):
  e = list(map(int, input().split()))
  l.append(e)

for i in range(0, r):
  s = sum(l[i])
  l[i].append(s)
  print(' '.join(map(str,l[i])))

ele = []
for i in range(0, c + 1):
  e = 0
  for j in range(0, r):
    e += l[j][i]
  ele.append(e)

print(' '.join(map(str,ele)))

Solution (Python):
r,c = (int(x) for x in input().split())
T = [input().split() for i in range(r)]

for i in range(r):
    rTotal = 0
    for j in range(c):
        rTotal += int(T[i][j])
    
    T[i].append(rTotal)

newT = []

for i in range(c):
    cTotal = 0
    for j in range(r):
        cTotal += int(T[j][i])
    
    newT.append(cTotal)

total = 0
for i in range(len(newT)):
    total += newT[i]

newT.append(total)
T.append(newT)

for i in range(r + 1):
    print(*T[i])

Solution (Python):
r , c = map( int,input().split())

spread_list=[ [0]*c ] * (r+1) 

for i in range( r ):
    spread_list[i] = list ( map( int,input().split()) )
    spread_list[i].append( sum (spread_list[i]) )

spread_list[r].append( 0 )

for ci in range( c+1 ):
    sumer = 0
    for ri in range(r):
        sumer += spread_list[ri][ci]
    spread_list[r][ci] = sumer

for a in spread_list:
    print(*a, sep=' ')

Solution (Python):
table = [[0 for i in range(101)]for j in range(101)]

row,column = map(int,input().split())

for r in range(row):
    lst = list(map(int,input().split()))
    for c in range(column):
        table[r][c] += lst[c]
        
for c in range(column):
    total = 0
    for r in range(row):
        total += table[r][c]
    table[row][c] = total
    
for r in range(row+1):
    table[r][column] = sum(table[r])


for r in range(row+1):
    lst = []
    for c in range(column+1):
        lst.append(table[r][c])
    lst = [str(i) for i in lst]
    print(" ".join(lst))

Solution (Python):
r,c=map(int,input().split())
sheet=[list(map(int,input().split())) for i in range(r)]
for i in range(r):
    sheet[i].append(sum(sheet[i]))
Column_sum=[0]*(c+1)
for j in range(c+1):
    for i in range(r):
        Column_sum[j]+=sheet[i][j]

for i in range(r):
    print(*sheet[i])
print(*Column_sum)

Solution (Python):
r,c=map(int,input().split())
d=c
f=0
a=[];
h=0
for i in range(r):
    a.append(list(map(int,input().split())))
for i in range(r):
    for j in range(c):
        f=a[i][j]+f
        print(a[i][j],end=" ")
    print(f)
    f=0
for i in range(c):
    for j in range(r):
        f=a[j][i]+f
    print(f,end=" ")
    h=f+h
    f=0
    if (i==c-1):
        if (j==r-1):
            f=h
            print(f,end="")
print()

Solution (Python):
c,r=map(int,input().split())
a=[]
for i in range (c):
    a.append(list(map(int,input().split())))
    a[i]+=[sum(a[i])]
    print(*a[i])
    
a=list(zip(*a[::-1]))
for i in range(r):print(sum(a[i]),end=' ')
print(sum(a[r]))

Solution (Python):
while True:
    try:
        n,m = map(int, input().split())
        b = []
        for j in range(n):
            a = list(map(int,input().split()))
            b.append(a)    
            S = sum(a)
            c = list(zip(*b))
            D = [sum(x)for x in c]
            X = sum(D)
            print(*a,S)
        print(*D,X)
    except:
        break

Solution (Python):
r , c = [int(x) for x in input().split()]
s_row = [0 for x in range(c+1)]
for i in range(r):
    row = [int(x) for x in input().split()]
    row.append(sum(row))
    print(" ".join([str(x) for x in row]))
    s_row = [x+y for x,y in zip(s_row,row)]
print(" ".join([str(x) for x in s_row]))

Solution (Python):
r, c = map(int, input().split())
a = []

for i in range(r):
    a.append(list(map(int, input().split())))
    a[i].append(sum(a[i]))

for i in range(r):
    print(" ".join(list(map(str, a[i]))))

col_sum = []
for j in range(c+1):
    su = 0
    for i in range(r):
        su += a[i][j]
    col_sum.append(su)

print(" ".join(list(map(str, col_sum))))

Solution (Python):
r, c = map(int, input().split())
table = [cc + [sum(cc)] for cc in (list(map(int, input().split())) for _ in range(r))]
table.append(list(map(sum, zip(*table))))
for line in table:
    print(*line)

Solution (Python):
r, c = map(int, input().split())
L, tl = [], []
for i in range(r):
    L.append(list(map(int, input().split())))
    L[i].append(sum(L[i]))
for i in range(c+1):
    tl.append(sum(l[i] for l in L))
L.append(tl)
for i in range(r+1):
    print(' '.join(str(x) for x in L[i]))

Solution (Python):
r,c= map(int,input().split())
a=[[0 for i in range(c+1)] for j in range(r+1)]

for k in range(r):
    b = input().split()
    b_int = [int(s) for s in b ]
    for s in range(len(b_int)):
        a[k][s] = b_int[s]
i = 0
j = 0
for i in range(r):
    for j in range(c):
        a[i][c]+=a[i][j]
i = 0
j = 0
for i in range(c+1):
    for j in range(r):
        a[r][i]+=a[j][i]
i = 0
for i in range(r+1):
    print(' '.join(map(str,a[i])))

Solution (Python):
n,m=map(int,input().split())
c = []
for i in range(n):
    x= list(map(int, input().split()))
    x.append(sum(x))
    c.append(x)
    print(*x)

d = [0 for i in range(m+1)]
for i in range(n):
    for j in range(m+1):
        d[j]+=c[i][j]
print(*d)

Solution (Python):
r,c=map(int,input().split())

a=[]
for i in range(r):
    a.append(list(map(int,input().split())))
for i in range(r):
    print(*a[i],sum(a[i]))
y=0
for i in range(c):
    x=0
    for j in range(r):
        x+=a[j][i]
    y+=x
    print(x,end=' ')
print(y)

Solution (Python):
r,c=map(int,input().split())
an = [list(map(int,input().split())) for _ in range(r)]
an.append([0]*(c+1))
for i in range(r):
    an[i].append(sum(an[i]))
    print(" ".join(map(str,an[i])))
    for j in range(c+1):
        an[r][j] += an[i][j] 

print(" ".join(map(str,an[r])))