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 = list(map(int, input().split()))
ori_t = []
for i in range(r):
    ori_t.append(list(map(int, input().split())))


for a in range(r):
    ori_t[a].append(sum(ori_t[a]))


ori_t.append([0 for x in range(c+1)])

for b in range(c):
    c_sum = 0
    for a in range(r):
        c_sum += ori_t[a][b]
    ori_t[r][b] = c_sum


ori_t[r][c] = sum(ori_t[r])


for num in ori_t:
    print(*num)

Solution (Python):
y, x = [int(i) for i in input().split()]
allsum = [0] * (x + 1)

for _ in range(y):
    temp = [int(i) for i in input().split()]
    sumrow = sum(temp)
    print('{} {}'.format(' '.join(map(str, temp)), str(sumrow)))
    for i in range(len(allsum) - 1):
        allsum[i] += temp[i]
    allsum[-1] += sumrow

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

Solution (Python):
a = 0
r, c = [int(i) for i in input().split()]
li = [[int(i) for i in input().split()] for _ in range(r)]
for row in li:
    print(*row, sum(row))
for i in range(c):
    t = sum([row[i] for row in li])
    a += t
    print(t, end=" ")
print(a)

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

for i in range(r):
    row_list = list(map(int, input().split()))
    sum_row = 0
    for j in range(c):
        sum_row += row_list[j]
        print('{} '.format(row_list[j]), end='')
        sum_list.append(row_list[j])
    print(sum_row)
    sum_list.append(sum_row)

for k in range(c+1):
    sum_col = 0
    for l in range(r):
        m = l*(c+1)+k
        sum_col += sum_list[m]
    if k != c:
        print('{} '.format(sum_col), end='')
    else:
        print(sum_col)

Solution (Python):
H, W = map(int, input().split())
s = []
for _ in range(H):
    a = [int(i) for i in input().split()]
    a += [sum(a)]
    s.append(a)

s.append([sum([x[i] for x in s]) for i in range(W + 1)])

for l in s:
    print(' '.join(map(str, l)))

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

B = []
for j in range(m + 1):
    B.append(0)

for k in A:
    for l,o in enumerate(k):
        B[l] += o

A.append(B)
for i in A:
    for j,k in enumerate(i):
        if j == 0:
            print(k,end="")
        else:
            print("",k,end="")
    print()

Solution (Python):
r,c=map(int,input().split())
l=[]
for i in range(r):
    l.append(list(map(int,input().split())))
csum=[0 for j in range(c)]
gsum=0
for i in range(r):
    rsum=0
    for j in range(c):
        print(l[i][j],end=' ')
        rsum+=l[i][j]
        csum[j]+=l[i][j]
    print(rsum)
    gsum+=rsum
for elem in csum:
    print(elem,end=' ')
print(gsum)

Solution (Python):
r = 0
c = 0


def input_size():
    global r, c
    r, c = map(int, input().split(' '))


def input_table(table):
    for i in range(0, r):
        vs = list(map(int, input().split(' ')))
        row = []
        for v in vs:
            row.append(v)
        table.append(row)


def calc_total(table):
    total = []
    for i in range(0, c + 1):
        total.append(0)

    for i in range(0, r + 1):
        if i < r:
            t = 0
            for j in range(0, c):
                t += table[i][j]
                total[j] += table[i][j]
            table[i].append(t)
            total[c] += t

        if i == r - 1:
            table.append(total)


def output(vs):
    for row in vs:
        first = True
        for v in row:
            if not first:
                print(end=' ')
            print(v, end='')
            first = False
        print()


input_size()
vs = []
input_table(vs)
calc_total(vs)
output(vs)

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

for _ in range(r):
    a = [int(x) for x in input().split()]
    for i,j in enumerate(a):
        A[_][i] = j
        A[-1][i] += j
    A[_][i+1] = sum(a)

A[-1][-1] = sum(A[-1])

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

Solution (Python):
r, c = map(int, input().split())
array = [list(map(int, input().split())) for _ in range(r)]
add = [0] * (c+1)

for i in range(r+1):
    if i == r:
        array.append(add)
        break
    for j in range(c+1):
        if j == c:
            array[i].append(sum(array[i]))
            add[j] += array[i][j]
        else:
            add[j] += array[i][j]

for i in range(r+1):
    print(*array[i], sep=' ')

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

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

s = [0 for x in range(c)]

for i in range(r):
    l = [int(x) for x in input().split()]
    for j in range(c):
        s[j] += l[j]
        print(l[j],end="")
        print(" ",end="")
    print(sum(l))

for j in s:
    print(j,end="")
    print(" ",end="")
print(sum(s))

Solution (Python):
s = input().split()

r = int(s[0])
c = int(s[1])

A = [[0 for i in range(c+1)] for j in range(r+1)]

row=[]
for i in range(r):
    row = list(map(int,input().split()))
    
    for j in range(c):
        A[i][j]=row[j]
        A[i][c]+=row[j] 
        A[r][j]+=row[j] 
    
    A[r][c]+=A[i][c]
        
for i in range(r+1):
    for j in range(c):
        print(A[i][j]," ",end="",sep="")
    print(A[i][c])

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

print(*[sum(e[i] for e in a) for i in range(c)], sum(map(sum, a)))

Solution (Python):
H,W = map(int,input().split())
a = [[0 for i in range(W+1)] for j in range(H+1)]
for y in range(H):
	tmp = list(map(int,input().split()))
	for x in range(W):
		a[y][x] = tmp[x]
		a[y][W]=a[y][x]+a[y][W]
		a[H][x]=a[H][x]+a[y][x]
		a[H][W]=a[H][W]+a[y][x]
for u in range(H+1):
	for i in range(W+1):
		print(a[u][i],end='')
		if	i<W:
			print(" ",end='')
	print()

Solution (Python):


r, c = map(int, input().split())
mtx = list()
sor = [0 for i in range(c + 1)]
for i in range(r):
    temp = list(map(int, input().split()))
    temp.append(sum(temp))
    for j in range(c + 1):
        sor[j] += temp[j]
    mtx.append(temp)
mtx.append(sor)
for i in range(r + 1):
    for j in range(c + 1):
        mtx[i][j] = str(mtx[i][j])
    print(' '.join(mtx[i]))

Solution (Python):
f = open(0)
R, C = map(int, f.readline().split())
ans = [0]*(C+1)
res = []
for line in f.readlines():
    *D, = map(int, line.split())
    for i, v in enumerate(D):
        ans[i] += v
    s = sum(D)
    ans[-1] += s
    res.append(line.strip())
    res.append(" %d\n" % s)
res.append(" ".join(map(str, ans)))
res.append("\n")
open(1, 'w').writelines(res)

Solution (Python):
def test():

	inputs = list(map(int,input().split()))

	r = inputs[0]
	c = inputs[1]

	sheet = [[0 for i in range(c+1)] for j in range(r+1)]

	for i in range(r):

		inputs = list(map(int,input().split()))
		
		for j in range(c):
			sheet[i][j] = inputs[j]
			sheet[i][c] += sheet[i][j]
			sheet[r][j] += sheet[i][j]
			sheet[r][c] += sheet[i][j]


	for i in range(r+1):
		for j in range(c+1):
			print(f"{sheet[i][j]}",end='')
			if j != c:
				print(" ",end='')

		print("")

if __name__ == "__main__":
	test()

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())
input_list = [[0 for i in range(c)] for j in range(r)]

for i in range(r):
    input_list[i] = list(map(int, input().split()))
    
for i in range(r):
    for j in range(c):
        if j == 0:
            print(input_list[i][j], sep="", end="")
        else:
            print(" ", input_list[i][j], sep="", end="")
    print(" ", sum(input_list[i]), sep="")

all_sum = 0
for j in range(c):
    tmp_sum = 0
    for i in range(r):
        tmp_sum += input_list[i][j]
    
    if j == 0:
        print(tmp_sum, sep="", end="")
    else:
        print(" ", tmp_sum, sep="", end="")
    
    all_sum += tmp_sum
print(" ", all_sum, sep="")

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

ss = []

for i in range(r):
    row = list(map(int, input().split()))
    row.append(sum(row))
    ss.append(row)

sum_row = []

for i in range(c+1):
    temp = 0
    for j in ss:
        temp += j[i]
    
    sum_row.append(temp)

ss.append(sum_row)

for s in ss:
    print(*s)

Solution (Python):
r,c=map(int,input().split())
l=[]
for i in range(r):
    ll=list(map(int,input().split()))
    lsum=sum(ll)
    ll.append(lsum)
    l.append(ll)
sumcl=[]
for i in range(c+1):
    sumc=0
    for j in range(r):
        sumc=sumc+l[j][i]
    sumcl.append(sumc)
l.append(sumcl)
for i in range(r+1):
    print(' '.join(str(l[i][j]) for j in range(c+1)))

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

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

C = [0 for _ in range(c)]
for X in A:
    for j, a in enumerate(X):
        C[j] += a

for X in A + [C]:
    print(" ".join([str(a) for a in X] + [str(sum(X))]))

Solution (Python):
n,m=map(int,raw_input().split())
x=[[0 for i in range(m)]for i in range(n)]
a=[[0 for i in range(m+1)] for i in range(n+1)]

for i in range(n):
	x[i] = map(int,raw_input().split())
	for j in range(m):
		a[i][j] = x[i][j]
		a[n][j] += x[i][j]
		a[i][m] += x[i][j]
	print " ".join(map(str,a[i]))
a[n][m]=sum(a[n])
print " ".join(map(str,a[n]))

Solution (Python):
H,W=map(int,input().split())
a=[[0 for i in range(W+1)] for j in range(H+1)]
for y in range(H):
	l=list(map(int,input().split()))
	for x in range(W):
		a[y][x]=l[x]
		a[y][W]=a[y][x]+a[y][W]
		a[H][x]=a[H][x]+a[y][x]
		a[H][W]=a[H][W]+a[y][x]
for u in range(H+1):
	for i in range(W+1):
		print(a[u][i],end='')
		if	i<W:
				print(" ",end='')		
	print()

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())


ans = []


last_raw = []

tmpmax = 0

sum = 0
for i in range(r):
    ans.append(list(map(int,input().split())))


for i in range(r):
    sum = 0
    for j in range(c):
        sum += ans[i][j]
    ans[i].append(sum)
    tmpmax+=sum

lastsum=0
for j in range(c):
    lastsum=0
    for i in range(r):
        lastsum+=ans[i][j]
    last_raw.append(lastsum)
    tmpmax+=lastsum 

last_raw.append(int(tmpmax/2))

for i in range(r):
    print(' '.join(map(str,ans[i])))
print(' '.join(map(str,last_raw)))

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

r_sum = [0] * (r+1)
c_sum = [0] * c


for i in range(r):
    for j in range(c):
        r_sum[i] += rc[i][j]
        c_sum[j] += rc[i][j]
        r_sum[r] += rc[i][j]

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

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

sum0 = 0

for j in range(m):
    for i in range(n):
        sum0 += a[i][j]
    a[n][j] = sum0
    sum0 = 0

for k in range(n+1):

    a[k].append(sum(a[k]))
    print(' '.join([str(p) for p in a[k]]))

Solution (Python):
h,w=map(int,input().split())

v=[[0 for j in range(w+1) ] for i in range(h+1)]

for i in range(h):
	row = list(map(int,input().split()))
	for j in range(w):
		v[i][j] = row[j]
		v[i][w] += v[i][j]
		v[h][j] += v[i][j]
		v[h][w] += v[i][j]

for i in range(h+1):
	for j in range(w):
		print(v[i][j],end=" ")
	print(v[i][w])

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

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):
    m = 0
    for j in range(c):
        m += a[i][j]
        print(a[i][j], end=" ")
    print(m)

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):
   m = 0
   for j in range(c):
       m += a[i][j]
       print(a[i][j], end=" ")
   print(m)

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

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

Solution (Python):
import sys
 
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
 
 
 
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):
f = open(0)
R, C = map(int, f.readline().split())
ans = [0]*(C+1)
res = []
for line in f.readlines():
    *D, = map(int, line.split())
    for i, v in enumerate(D):
        ans[i] += v
    s = sum(D)
    ans[-1] += s
    res.append(line.strip())
    res.append(" %d\n" % s)
res.append(" ".join(map(str, ans)))
res.append("\n")
open(1, 'w').writelines(res)

Solution (Python):
r,c=map(int,input().split())
a=[[int(i) for i in input().split()]for _ in range(r)]
y=[sum(i) for i in zip(*a)]
for i in range(r):
    print(*a[i],sum(a[i]))
print(*y,sum(y))

Solution (Python):
r,c = map(int, input().split())
fields = []
colsum = [0]*(c+1)
for i in range(r):
    A = list(map(int, input().split()))
    row = A + [sum(A)]
    fields.append(row)
    for i,e in enumerate(row):
        colsum[i] += e
fields.append(colsum)

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

Solution (Python):


BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001



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):
lw = []
lc = []
r, c = map(int, input().split())
for i in range(r):
    ls = list(map(int, input().split()))
    lw.append(ls)
for i in range(r):
    print(" ".join(map(str, (lw[i] + [sum(lw[i])]))))
for i in range(c):
    k = 0
    for j in range(r):
        k =  k + lw[j][i]
    lc.append(k)
print(" ".join(map(str, (lc + [sum(lc)]))))

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

for i in range(r):
    tmp = 0
    for j in range(c):
        tmp += l[i][j]
        
    l[i].append(tmp)

tmpl = []

for i in range(c+1):
    tmp = 0
    for j in range(r):
        tmp+=l[j][i]
    tmpl.append(tmp)
l.append(tmpl)

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

Solution (Python):
r, c = map(int, input().split())
table = []
sum_column = [0 for i in range(c)]
for row in range(r):
    table.append(list(map(int, input().split())))
    table[row].append(sum(table[row]))
    for i in range(c):
        sum_column[i] += table[row][i]
sum_column.append(sum(sum_column))
table.append(sum_column)
for row in table:
    print(" ".join(map(str, row)))

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

Solution (Python):
r, c = map(int, input().split())
a = [0 for i in range(r)]
for i in range(r):
  a[i] = list(map(int, input().split()))
sumA = 0
sumB = 0
sumC = 0

for i in range(r):
  for j in range(c):
    print(a[i][j], "", end="")
    sumA = sumA + a[i][j]
    if j == (c-1):
      print(sumA)
      sumA = 0

for i in range(c):
  for j in range(r):
    sumB = sumB + a[j][i]
    if j == (r-1):
      print(sumB, "", end="")
      sumC = sumC + sumB
      sumB = 0
  if i == (c-1):
    print(sumC)

Solution (Python):
import sys

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001



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())
lit=[[0 for jjj in range(c)]for lll in range(r)]
for a in range(r):
	tet=list(map(int,input().split()))
	for b in range(c):
		lit[a][b]=tet[b]
for p in range (r):
	for q in range(c):
			print(str(lit[p][q])+' ',end='')
	print(sum(lit[p]))
ddd=0

for qq in range(c):
	unko=0
	for pp in range(r):
		unko+=lit[pp][qq]
	ddd+=unko
	print(str(unko)+' ',end='')
print(ddd)

Solution (Python):
def main():
    r, c = map(int, input().split())
    cs = [0] * (c + 1)
    t = []
    for _ in range(r):
        s = list(map(int, input().split()))
        s.append(sum(s))
        t.append(s)
        for i in range(c):
            cs[i] += s[i]
    cs[-1] = sum(cs)
    t.append(cs)
    for a in t:
        print(' '.join(map(str, a)))


main()

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

Solution (Python):
lmap = lambda f, s: list(map(f, s))
n, m = map(int, input().split())
a = [lmap(int, input().split()) for i in range(n)]
a = lmap(lambda xs: xs + [sum(xs)], a)
a.append(lmap(sum, zip(*a)))
for xs in a: print(*xs)

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 = []
rsum = []

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]))))
  
csum = []
for j in range(c+1):
  su = 0
  for i in range(r):
    su += a[i][j]
  csum.append(su)
  
print(" ".join(list(map(str, csum))))

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





listA.append(temp)

for line in listA:
    print(*line)

Solution (Python):
r,c=map(int,input().split())
L = [[0 for j in range(c)] for i in range(r)]
for j in range(r):
    L[j]=list(map(int,input().split()))
    L[j].append(sum(L[j]))
S = [0 for j in range(c+1)]
for j in range(c+1):
    for i in range(r):
        S[j]+=L[i][j]
L.append(S)
for i in range(r+1):
    for j in range(c+1):
        if j<c:
            print("{} ".format(L[i][j]),end="")
        else:
            print("{}".format(L[i][j]))

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

m = []

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

for _ in range(r):
    row = list(map(int, input().split()))
    l = row+[sum(row)]

    m.append(l)
    for i in range(len(l)):
        t[i] += l[i]

m.append(t)

for l in m:
    sep = ''
    for e in l:
        print(sep+str(e), end='')
        sep = ' '
    print()

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

for line in table:
    line.append(sum(line))

table.append([sum([line[i] for line in table]) for i in range(c + 1)])

for line in table:
    print(*line)

Solution (Python):
if __name__ == "__main__":
    row_num, col_num = map(lambda x: int(x), input().split())
    table = [[0] * col_num] * row_num
    total_sum = 0

    for r in range(row_num):
        table[r] = list(map(lambda x: int(x), input().split()))

    for r in range(row_num):
        print(" ".join([str(elem) for elem in table[r] + [sum(table[r])]]))

    for c in range(col_num):
        col_sum = sum(map(lambda x: x[c], table))
        total_sum += col_sum
        print(f"{col_sum} ", end="")
    print(f"{total_sum}")

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

for i in range(c+1):
    x.append(0)

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


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


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

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 = [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())
l = []
for i in range(r):
  l.append(list(map(int, input().split())))
  l[i] += [sum(l[i])]
  print(*l[i])
l = list(zip(*l))
for i in range(c): print(sum(l[i]), end = " ")
print(sum(l[c]))

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):
	m = 0
	for j in range(c):
		m += a[i][j]
		print(a[i][j], end=" ")
	print(m)

Solution (Python):
[r,c]=map(int,input().split())
matrix=[[]for i in range(r)]
r_total=[0 for i in range(r)]
c_total=[0 for i in range(c)]
total=0

for i in range(r):
    matrix[i]=list(map(int,input().split()))
    for j in range(c):
        r_total[i]+=matrix[i][j]
        c_total[j]+=matrix[i][j]
        total+=matrix[i][j]
for i in range(r):
    for j in range(c):
        print(matrix[i][j],end = " ")
    print(r_total[i])
for i in range(c):
    print(c_total[i],end=" ")
print(total)

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


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

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())

total = 0
c_sum = [0 for i in range(c)]
for i in range(r):
    e = list(map(int, input().split()))
    total += sum(e)
    r_sum = 0
    for j in range(c):
        print(e[j], end=' ')
        r_sum += e[j]
        c_sum[j] += e[j]
    print(r_sum)
for i in range(c):
    print(c_sum[i], end=' ')
print(total)

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

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

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

Solution (Python):
lmap = lambda f, s: list(map(f, s))
n, m = map(int, input().split())
a = [lmap(int, input().split()) for i in range(n)]
a = lmap(lambda xs: xs + [sum(xs)], a)
a.append(lmap(sum, zip(*a)))
for xs in a: print(*xs)

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

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 = [[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):
    m = 0
    for j in range(c):
        m += a[i][j]
        print(a[i][j], end=" ")
    print(m)

Solution (Python):



def main():
    r,c=map(int,input().split())
    a=[list(map(int,input().split())) for _ in range(r)]
    c1=[0 for _ in range(c)]
    s=0

    for i in range(r):
        print(*a[i],sum(a[i]))
        s+=sum(a[i])
        for j in range(c):
            c1[j]+=a[i][j]
    print(*c1,s)

main()

Solution (Python):
R,C = map(int,input().split())
table = [[0]*(C+1) for i in range(R+1)]


for row in range(R):
  data = list(map(int,input().split()))
  for col in range(C):
    table[row][col]=data[col]


for row in range(R):
  for col in range(C):
    table[row][C] += table[row][col]
    table[R][col] += table[row][col]
    table[R][C] += table[row][col]

for row in range(0,R+1):
  for col in range(0,C+1):
    if col==C:
      print("{:d}".format(table[row][col]))
    else:
      print("{:d}".format(table[row][col]),end=" ")

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

tmp = [0] * c
for i in range(r):
    print(' '.join(map(str, l[i])) + f' {sum(l[i])}')
    tmp = [a + b for a, b in zip(tmp, l[i])]

print(' '.join(map(str, tmp)) + f' {sum(tmp)}')

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

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

row.append([])


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

Solution (Python):
row, col = list(map(int, input().split()))
rc = []

for i in range(row):
    tmp_r = list(map(int, input().split()))
    tmp_sum = sum(tmp_r)
    rc.append(tmp_r)
    rc[i].append(tmp_sum)

new_row = []
for c in range(col+1):
    tmp = 0
    for r in range(row):
        tmp += rc[r][c]
    new_row.append(tmp)

rc.append(new_row)

for row_list in rc:
    for i, e in enumerate(row_list):
        if i == len(row_list)-1:
            print(e)
        else:
            print(e, end=" ")

Solution (Python):
r, c = map(int, input().split())
 
mat = [[0 for i in range(c+1)] for j in range(r+1)]
for i in range(r):
    mat[i] = list(map(int, input().split()))
 
for i in range(r):
    s = sum(mat[i])
    mat[i].append(s)
 
for j in range(c):
    s = 0
    for i in range(r):
        s += mat[i][j]
    mat[r][j] = s
 
mat[r][c] = (sum(mat[r]))
 
for i in range(r+1):
    for j in range(c+1):
        if j == c:
            print(str(mat[i][j]))
        else:
            print(str(mat[i][j]) + " ", end="")

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

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

B = [[0 for i in range(c+1)] for j in range(r+1)]

for i in range(0, r):
  for j in range(0, c):
    B[i][j] = A[i][j]

for i in range(0,r):
  for j in range(0, c):
    B[i][c] += A[i][j] 

for i in range(0, c+1):
  for j in range(0, r):
    B[r][i] += B[j][i]
    
for i in range(0, r+1):
  print(*B[i])

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

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

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

matrix.append(list(map(sum, zip(*matrix))))


for row in matrix:
    print(' '.join(str(e) for e in row))