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):
def main():
    m, n = tuple(map(int, input().split()))
    matrix = [[0 for j in range(n+1)] for i in range(m+1)]
    for i in range(m):
        tmp = list(map(int, input().split()))
        for j in range(n):
            matrix[i][j] = tmp[j]
            matrix[i][n] += tmp[j]
    
    for j in range(n+1):
        for i in range(m):
            matrix[m][j] += matrix[i][j]

    for i in range(m+1):
        for j in range(n):
            print(matrix[i][j], end=' ')
        print(matrix[i][n])

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    r, c = map(int, input().split())
    table = []
    for _ in range(r):
        table.append(list(map(int, input().split())))
    table.append([0] * (c+1))
    for index, line in enumerate(table[:-1]):
        table[index].append(sum(line))
        for index1, value in enumerate(table[index]):
            table[-1][index1] += value
    for line in [map(str, line) for line in table]:
        print(' '.join(line))
    return


if __name__ == '__main__':
    main()

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

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

    for _ in range(r):
        nums = [int(x) for x in input().split()]
        total = sum(nums)

        row = nums + [total]
        matrix.append(row)

        for i in range(c+1):
            totals[i] += row[i]

    matrix.append(totals)

    for m in matrix:
        print(" ".join([str(x) for x in m]))

if __name__ == '__main__':
    main()

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

Solution (Python):
all_ele = []
sum_ele = []
h,w = [int(x) for x in input().split()]
for ele in range(h):
    all_ele.append([int(x) for x in input().split()])
    all_ele[ele].append(sum(all_ele[ele]))
    
all_ele.append([int(x) for x in range(w+1)])

for a in range(len(all_ele[0])):
    for b in range(h):
        sum_ele.append(all_ele[b][a])
    all_ele[h][a] = sum(sum_ele)
    sum_ele = []
    
for out1 in all_ele:
    print(' '.join(map(str,out1)))

Solution (Python):
r, c = [int(i) for i in input().split()]
data = [[int(i) for i in input().split()] for j in range(r)]
ans = [data[i] + [sum(data[i])] for i in range(r)]
last_ans = ans + [[sum([ans[i][j] for i in range(r)]) for j in range(c+1)]]
for i in last_ans:
    print(*i)

Solution (Python):
r, c = [int(i) for i in input().split()]
data = [[int(i) for i in input().split()] for j in range(r)]
ans = [data[i] + [sum(data[i])] for i in range(r)]
last_ans = ans + [[sum([ans[i][j] for i in range(r)]) for j in range(c+1)]]
for i in last_ans:
    print(*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))

Solution (Python):
data = []
da = []
a = input().split()
a[0] = int(a[0])
a[1] = int(a[1])
for i in range(a[0]):
    b = input().split()
    for j in range(a[1]):
        b[j] = int(b[j])
    data.append(b)
for i in range(len(data)):
    data[i].append(sum(data[i]))
for i in range(a[1]+1):
    da.append(0)
for i in range(a[0]):
    for j in range(a[1]+1):
        da[j] += data[i][j]
data.append(da)
for i in data:
    for j in range(len(i)):
        i[j] = str(i[j])
for i in data:
    print(" ".join(i))

Solution (Python):


row, col = map(int, input().split())
spreadsheet = []

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

for r in spreadsheet:
    print(' '.join(map(str, r)))

last_row = []
for j in range(len(spreadsheet[0])):
    col_sum = 0
    for i in range(len(spreadsheet)):
        col_sum += spreadsheet[i][j]
    last_row.append(col_sum)

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

Solution (Python):
r, c = map(int, input().split())
x = [];
for i in range(r):
    x.append(list(map(int, input().split())))
rsum = [0 for i in range(r)]
csum = [0 for i in range(c)]
total = 0
for i in range(r):
    for j in range(c):
        rsum[i] += x[i][j]
        csum[j] += x[i][j]
        total += x[i][j]
for i in range(r):
    for j in range(c):
        print(str(x[i][j]) + " ", end="")
    print(rsum[i])
for j in range(c):
    print(str(csum[j]) + " ", end="")
print(total)

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

Solution (Python):
H, W = map(int, raw_input().split())
HW = [[0 for i in range(W+1)] for j in range(H+1)]
for i in range(H):
    tmp = map(int, raw_input().split())
    for j in range(W):
        HW[i][j] = tmp[j]
    HW[i][W] = sum(HW[i])
for i in range(W+1):
    tmp = 0
    for j in range(H):
        tmp+=HW[j][i]
    HW[H][i] = tmp
        
    
for i in range(H+1):
    print " ".join(map(str, HW[i]))

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]))
b = []
for i in range(c+1):
    x = [row[i] for row in a]
    b.append(sum(x))
a.append(b)
for x in a:
    print(*x)

Solution (Python):

r, c = map(int, input().split())
sheet = [[0 for _ in range(c)] for _ in range(r)]
last_culmn = [0 for _ in range(c)]
s = 0
for y in range(r):
    row = list(map(int, input().split()))
    row_s = 0
    for x in range(c):
        sheet[y][x] = row[x]
        row_s += row[x]
        last_culmn[x] += row[x]
        s += sheet[y][x]
    sheet[y].append(row_s)
last_culmn.append(s)
sheet.append(last_culmn)

[print(" ".join(list(map(str, line)))) for line in sheet]

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

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

for i, ai in enumerate(a):
    print(*ai)

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

d = [0] * (r + 1)

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

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

for i in range(r + 1):
    row = ''
    for j in range(c + 1):
        row += str(d[i][j])
        if j <= c - 1:
            row += ' '
    print(row)

Solution (Python):
r, c = map(int, input().split())
a = []
for _ in range(r):
    a.append(list(map(int, input().split())))
for row in a:
    row.append(sum(row))
s = []
for column in range(c + 1):
    tmp = 0
    for row in range(r):
        tmp += a[row][column]
    s.append(tmp)
a.append(s)
for row in a:
    count = 0
    for i in row:
        if count != c:
            print('{} '.format(i), end = '')
        else:
            print('{}'.format(i), end = '')
        count += 1
    print('')

Solution (Python):
r_c_str=input().split()
r_c=list(map(lambda i :int(i),r_c_str))
r=r_c[0]
c=r_c[1]
s_str=[input() for i in range(r)]
s_str=[i.split() for i in s_str]
s=[]
for i in s_str:
    s.append(list(map(lambda j :int(j),i)))
for i in range(r):
    s[i].append(sum(s[i]))
s.append([])
for i in range(c+1):
    s[-1].append(0)
for i in range(c):
    for j in range(r):
        s[r][i]+=s[j][i]
s[-1][-1]+=sum(s[r])
for i in s:
    print(*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):
r,c=map(int, input().split())
total=[0]*(c+1)
for i in range(r):
    a=list(map(int, input().split()))
    a.append(sum(a))
    print(*a)
    for j in range(c+1):
        total[j]+=a[j]
print(*total)

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

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

Solution (Python):
from sys import stdin

r, c = [int(x) for x in stdin.readline().rstrip().split()]
table = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(r)]
for row in range(r):
    table[row] += [sum(table[row])]
    print(*table[row])

col_sum = [sum(x) for x in zip(*table)]
print(*col_sum)

Solution (Python):
table = []


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









for i in range(r):
    print(' '.join(map(str, table[i])))
for j in range(c + 1):
    out = 0
    for i in range(r):
        out += table[i][j]
    if not j == c:
        print(out, end= ' ')
    else:
        print(out)

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

matrix = []

vsum = [0]*(c+1)

for i in range(r):
	row = list(map(int, input().split()))
	row.append(sum(row))
	matrix.append(row)
	for j in range(c+1):
		vsum[j] += row[j]

matrix.append(vsum)

for row in matrix:
	print(' '.join(list(map(str, row))))

Solution (Python):
r,c = map(int,input().split())
data = [[0] * (c+1) for i in range(r)]
for row in range(r):
    data[row] = [int(i) for i in input().split()]
    data[row].append(sum(data[row]))
for row in range(r):
    for column in range(c+1):
        if column == (c):
            print(data[row][column])
        else: 
            print("%d " %data[row][column],end = "")


data_t = []
sumColumn = []
sumSumRow = 0
for column in range(c):
    dataRow = []
    for rowVector in data:
        dataRow.append(rowVector[column])
    data_t.append(dataRow) 

for column in data_t:
    sumColumn.append(sum(column))
for index in range(c):
    print("%d " %sumColumn[index],end = "")
for row in range(r):
    sumSumRow = sumSumRow + sum(data[row][:-1])
print("%d" % sumSumRow)

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

Solution (Python):
n=list(map(int,input().split()))
x=[]
b=[]
s=[]
for i in range(n[0]):
	x.append(list(map(int,input().split())))

for i in range(n[0]):
	a=0
	for j in range(n[1]):
		a+=x[i][j]
	x[i].append(a)
	print(' '.join(list(map(str,x[i]))))
for i in range(n[1]+1):
	l=0
	for j in range(n[0]):
		l+=x[j][i]
	s.append(l)
print(' '.join(list(map(str,s))))

Solution (Python):
m,n=map(int,input().split())
a =[]
for _ in range(m):
    a.append(list(map(int,input().split())))
for index in range(m):
    a[index].append(sum(a[index]))
for a_column in a:
    for num in a_column[:-1]:
        print(num, end=' ')
    print(a_column[-1])
for row_index in range(n):
    sum = 0
    for a_column in a:
        sum += a_column[row_index]
    print(sum, end=' ')
sum = 0
for a_column in a:
    sum += a_column[-1]
print(sum)

Solution (Python):
m,n=map(int,input().split())
a =[]
for _ in range(m):
    a.append(list(map(int,input().split())))
for index in range(m):
    a[index].append(sum(a[index]))
for a_column in a:
    print(' '.join(map(str, a_column)))
a.append([0]*(n+1))
for row_index in range(n+1):
    for a_column in a[:-1]:
        a[-1][row_index] += a_column[row_index]
print(' '.join(map(str, a[-1])))

Solution (Python):

import sys

H, W = map(int, input().split())
table = [[0]*(W+1) for i in range(H+1)]


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

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

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

for row in range(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())
matrix = []
for i in range(r):
    a = list(map(int, input().split()))
    sum = 0
    for j in range(c):
        sum += a[j]
    a.append(sum)
    matrix.append(a)
    for k in range(c+1):
        print(a[k], end = "")
        if k != c:
            print(" ", end = "")
    print()
for l in range(c+1):
    sum2 = 0
    for m in range(r):
        sum2 += matrix[m][l]
    print(sum2, end = "")
    if l != c:
        print(" ", end = "")
print()

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

row_lists = []
column = []

for i in range(r):
    rows = list(map(int, input().split()))
    row_sum = sum(rows)
    rows.append(row_sum)
    row_lists.append(rows)

for j in range(c+1):
    tmp_list = []
    for i in range(r):
        tmp = row_lists[i][j]
        tmp_list.append(tmp)
    sum_tmp_list = sum(tmp_list)
    column.append(sum_tmp_list)


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

print(" ".join(map(str, column)))

Solution (Python):

line,col = map(int,input().split(" "))

list_col = [0 for i in range(col+1)]
for _ in range(line):
	
	data = list(map(int,input().split(" ")))
	data.append(sum(data))

	str_data = list(map(str,data))
	print(" ".join(str_data))

	
	for j in range(col+1):
		list_col[j] += data[j]

str_col = list(map(str,list_col))
print(" ".join(str_col))

Solution (Python):

line,col = map(int,input().split(" "))

list_col = [0 for i in range(col+1)]
for _ in range(line):
	
	data = list(map(int,input().split(" ")))
	data.append(sum(data))
	print(*data)

	
	for j in range(col+1):
		list_col[j] += data[j]

print(*list_col)

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

table = []
i = 0

while i < r:
  table.append(list(int(x) for x in input().split()))
  i += 1

i,j = 0,0
for i in table:
  sum = 0
  for idx,j in enumerate(i):
    if idx != 0:
      print(' ', end='')
    print(j, end='')   
    sum += j
  print(' ' + str(sum))

j,ttl = 0,0
while j < c:
  i = 0
  sum = 0
  while i < r:
    sum += table[i][j]
    i += 1
  print (sum, end=' ')
  ttl += sum
  j += 1
print(ttl)

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(W):
        table[row][W] += table[row][col]

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

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

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

Solution (Python):
a, b = map(int, input().split())
al = []
b_lis = []

for _ in range(a):
    g = list(map(int, input().split()))
    g.append(sum(g))
    al.append(g)
for i in range(b+1):
    p = 0
    for j in range(a):
        p += al[j][i]
    b_lis.append(p)
al.append((b_lis))
for i in al:
    print(' '.join([str(v) for v in i]))

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

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):
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):
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):
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())
tbl = [[] for _ in range(r)]
cSum = [0 for _ in range(c+1)]

for i in range(r):
  tblS = input()
  tbl[i] = list(map(int, tblS.split()))
  print(tblS, end = '')
  print(' ', sum(tbl[i]), sep = '')

  for j in range(c):
    cSum[j] += tbl[i][j]
  cSum[c] += sum(tbl[i])

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

Solution (Python):
l, c = map(int, input().split())
tbl = [[] for _ in range(l)]
li_sum = [0 for _ in range(c+1)]

for i in range(l):
  tblS = input()
  tbl[i] = list(map(int, tblS.split()))
  print(tblS, end = '')
  print(' ', sum(tbl[i]), sep = '')

  for j in range(c):
    li_sum[j] += tbl[i][j]
  li_sum[c] += sum(tbl[i])

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

Solution (Python):
l, c = map(int, input().split())
tbl = [[] for _ in range(l)]
li_sum = [0 for _ in range(c+1)]

for i in range(l):
  a = input()
  tbl[i] = list(map(int, a.split()))
  print(a, end='')
  print(' ', sum(tbl[i]), sep = '')

  for j in range(c):
    li_sum[j] += tbl[i][j]
  li_sum[c] += sum(tbl[i])

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

Solution (Python):
l, c = map(int, input().split())
tbl = [[] for _ in range(l)]
li_sum = [0 for _ in range(c+1)]

for i in range(l):
  a = input()
  tbl[i] = list(map(int, a.split()))
  print(a, end='')
  print(' ', sum(tbl[i]), sep ='')

  for j in range(c):
    li_sum[j] += tbl[i][j]
  li_sum[c] += sum(tbl[i])

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

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

for i in range(c):
    csum = 0 
    for j in range(r):
        csum = csum + array[j][i]
    csum_a.append(csum)
array.append(csum_a)


for i in range((r+1)):
    rsum = 0 
    for j in range(c):
        rsum = rsum + array[i][j]
    array[i].append(rsum)

for i in array:
    print(*i)

Solution (Python):
if __name__ == '__main__':
    from sys import stdin

    r, c = (int(n) for n in stdin.readline().split())

    table = []
    for _ in range(r):
        row = [int(n) for n in stdin.readline().split()]
        row.append(sum(row))

        print(" ".join(map(str, row)))
        table.append(row)
        
    sum_column = (sum(column) for column in zip(*table))
    print(" ".join(map(str, sum_column)))

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

for i in range(r):
    table[i] = list(map(int,input().split()))
    table[i].append(sum(table[i]))
    for j in range(c+1):
        table[r][j] += table[i][j]

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

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

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

b = list(map(sum,zip(*a)))

for i in range(r) :
  print(*a[i])
print(*b)

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

R = list(zip(*C))

C.append([sum(x) for x in R])
for r in C:
  print(*r)

Solution (Python):
r,c=map(int, input().split())
S=[]
for num in range(r):
  A=list(map(int, input().split()))
  S.append(A)
  A.append(sum(A))


C=[]
for t in (zip(*S)):
  C.append(sum(t))
S.append(C)
for i in S:
  print(*i)

Solution (Python):
r,c=map(int,input().split())
N=[list(map(int,input().split())) for i in range(r)]
retu=[[0 for i in range(1)] for j in range(1)] 
for j in range(c):
  ret=0
  for i in range(r):
    ret+=N[i][j]
  if j==0:
    retu[0][0]+=ret
  else:
    retu[0].append(ret)
N.extend(retu)
for i in range(r+1):
  tuika=0
  for j in range(c):
    tuika+=N[i][j]
  N[i].append(tuika)
  
for i in range(r+1):
  for j in range(c+1):
    if j==0:
      print(N[i][j],end="")
    else:
      print("",N[i][j],end="")
  print("")

Solution (Python):
[r,c] = map(int,raw_input().split()) 
D = [[0 for i in range(c+1)] for j in range(r+1)] 
for y in range(r):
    v = map(int,raw_input().split())
    for x in range(c):
        D[y][x] = v[x]
        D[y][c] = D[y][c] + v[x]
        D[r][x] = D[r][x] + v[x]
        D[r][c] = D[r][c] + v[x] 
        
for y in range(r+1):
    s = ''
    for x in range(c+1):
        if x == 0:
            s = str(D[y][x])
        else: s = s + ' ' + str(D[y][x])
    print s

Solution (Python):
r, c = map(int, raw_input().split())
m = []
ans = []
for i in range(r):
    a = map(int, raw_input().split())
    m.append(a)
    sum = 0
    for j in range(c):
        print(a[j]),
        sum += a[j]
    print(sum)
total = 0
for i in range(c):
    sum = 0
    for j in range(r):
        sum += m[j][i]
    print(sum),
    total += sum
print(total)

Solution (Python):
i = list(map(lambda x: int(x), input().split(" ")))
count = 0
h = list()
c = [0 for i in range(0, i[1]+1)]
while count < i[0]:
    l = list(map(lambda x: int(x), input().split(" ")))
    l.append(sum(l))
    h.append(l)
    for j, c_ in enumerate(l):
        c[j] += c_
    count += 1
for r_ in h:
    print("%d" % r_[0], end="")
    for c_ in r_[1:]:
        print(" %d" % c_, end="")
    print("")

print("%d" % c[0], end="")
for c_ in c[1:]:
    print(" %d" % c_, end="")
print("")

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

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

Solution (Python):
y,x = map(int,raw_input().split())
list =[]
last = [ 0 for a in range(x+1)]

for a in range(y):
    tmp = map(int,raw_input().split())
    list.append(tmp + [sum(tmp)])
    for i,b in enumerate(list[a]):
        last[i] = last[i] + b

for c in list:
    print " ".join(map(str,c))
print " ".join(map(str,last))

Solution (Python):

r,c = tuple([int(x) for x in raw_input().split(" ")])

A = []

for i in range(r):
    A.append([int(x) for x in raw_input().split(" ")])

for lst in A:
    lst.append(sum(lst))
    print(" ".join([str(x) for x in lst]))

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

lst2.append(sum(lst2))
print " ".join([str(x) for x in lst2])

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

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

for line in arr:
    print(*line)

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

a = []
for i in range(r):
    a.append([int(i) for i in input().split()])
a.append([0 for i in range(c)])

for i in range(r + 1):
    sum = 0
    count = 0
    for j in a[i]:
        print(j, end=' ')
        sum += j
        if i != r:
            a[r][count] += j
            count += 1
    print(sum)

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

ct = [0 for d in range(c)]
tmp = []
for rc in range(r):
    tmp = [int(i) for i in input().split()]
    total = 0
    for cc in range(c):
        ct[cc] += tmp[cc]
        total += tmp[cc]
        print(tmp[cc], end=' ')
    print(total)
total = sum(ct)
print(' '.join([str(i) for i in ct]), total)

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

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

for i in range(r):
    tmp = [int(x) for x in input().split()]
    for j in range(c + 1):
        if not j == c:
            table[i][j] = tmp[j]
            table[i][c] += table[i][j]
        table[r][j] += table[i][j]

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

Solution (Python):
import sys

r, c = map(int, raw_input().split())
table = {}

for i in range(r):
    a = map(int, raw_input().split())
    for j in range(c):
        table[(i,j)] = a[j]

for i in range(r+1):
    for j in range(c+1):
        if(i != r and j != c):
            sys.stdout.write(str(table[(i,j)]))
            sys.stdout.write(' ')
        elif(i != r and j == c):
            print sum(table[(i,l)] for l in range(c))
        elif(i == r and j != c):
            sys.stdout.write(str(sum(table[(k,j)] for k in range(r))))
            sys.stdout.write(' ')
        elif(i == r and j == c):
            total = 0
            for k in range(r):
                for l in range(c):
                    total += table[(k,l)]
            print total

Solution (Python):
import sys
from operator import add
(r, c) = [int(i) for i in sys.stdin.readline().split()]
s = [0] * (c + 1)
for i in range(r):
    l = [int(i) for i in sys.stdin.readline().split()]
    l.append(sum(l))
    print(" ".join([str(i) for i in l]))
    s = map(add, s, l)

print(" ".join([str(i) for i in s]))

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

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

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

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

Solution (Python):
(r, c) = [int(i) for i in input().split()]
 
ct = [0 for d in range(c)]
tmp = []
for rc in range(r):
    tmp = [int(i) for i in input().split()]
    total = 0
    for cc in range(c):
        ct[cc] += tmp[cc]
        total += tmp[cc]
        print(tmp[cc], end=' ')
    print(total)
total = sum(ct)
print(' '.join([str(i) for i in ct]), total)