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())
i = 1
tb1 = [[0 for i in range(c+1)] for j in range(r+1)]
while i <= r:
    C = list(map(int,input().split()))
    for j in range(c):
        tb1[i-1][j] = C[j] 
    tb1[i-1][c] = sum(C) 
    i+=1
for i in range(c+1):
    tb1[r][i] = sum([row[i] for row in tb1])

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

Solution (Python):
x,y=map(int,input().split())

y_li = []
x_li = []
for _ in range(x):
    li = list(map(int,input().split()))
    li_sum = sum(li)
    li.append(li_sum)
    y_li.append(li)

for i in range(y+1):
    x_li.append((sum(e[i] for e in y_li)))
y_li.append(x_li)

for ans in y_li:
    print(' '.join(map(str,ans)))

Solution (Python):

r,c = input().split()
r = int(r)
c = int(c)

Data = []

while True:
    if r == 0:
        break
    temp = input().split()
    Data.append(list(map(int,temp)))
    r -= 1


for a in Data:
    a.append(sum(a))

temp = [0]*(c+1)
for a in Data:
    temp = [x + y for(x,y) in zip(temp,a)]
Data.append(temp)

for a in Data:
    b = map(str,a)
    print(' '.join(b))

Solution (Python):
table = [[0 for i in range(101)] for j in range(101)]
Row, Col = list(map(int, input().split()))

R_total = 0
C_total = 0

for i in range(Row):
    num = list(map(int, input().split()))
    R_num = 0
    for j in range(Col):
        table[i][j] = num[j]
        R_num += num[j]
    table[i][j+1] = R_num

for c in range(Col+1):
    C_num = 0
    for r in range(Row):
        C_num += table[r][c]
    table[r+1][c] = C_num

for i in range(Row+1):
    for j in range(Col+1):
        if j > 0: print(" ", end="")
        print(f"{table[i][j]}", end="")
    print()

Solution (Python):
from sys import stdin
input = stdin.readline

r,c = map(int, input().split())
sumrow = [0 for _ in range(c+1)]
for rowidx in range(r):
    row = list(map(int, input().split()))
    row.append(sum(row))
    print(*row)
    
    for colmunidx in range(c+1):
        sumrow[colmunidx] += row[colmunidx]
print(*sumrow)

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

Solution (Python):
r,c = map(int,input().split())
cel = []
com = [0] * (c + 1)
for i in range(r + 1):
  if i < r:
    cel.append(list(map(int,input().split())))
    cel[i].append(sum(cel[i]))
    com = [x + y for (x,y) in zip(com, cel[i])]
  if i == r:
    cel.append(com)
  cel[i] = ' '.join(map(str,cel[i]))
[print(result) for result in cel]

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


last_line = []
for j in range(c):
    tmp = 0
    for i in range(r):
        tmp += arr[i][j]

    last_line.append(tmp)


arr.append(last_line)    


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

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

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

Solution (Python):

x,y = map(int,input().split())
num_list = []


for _ in range(x):
    line = list(map(int,input().split()))
    line.append(sum(line))
    num_list.append(line)

    line1 = [str(a) for a in line]
    line1 = " ".join(line1)
    print(line1)
line = []

for num in range(0,y + 1):
    kei = 0
    for num1 in range(0,x):
        kei += num_list[num1][num]
    line.append(kei)

line1 = [str(a) for a in line]
line1 = " ".join(line1)
print(line1)

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

queue.append([])

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

queue[r].append(sum(queue[r]))

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

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


matrics = [[0 for i in range(0, c)] for j in range(0, r)]


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


for i in matrics:
	sum = 0
	for j in i:
		sum = sum + j
	i.append(sum)


vectors = [0 for i in range(0, c + 1)]
for i in range(0, len(matrics)):
	for j in range(0, len(matrics[i])):
		vectors[j] = vectors[j] + matrics[i][j]


matrics.append(vectors)



for i in range(0, len(matrics)):
	for j in range(0, len(matrics[i])):
		if j != len(matrics[i]) - 1:
			print('{0} '.format(matrics[i][j]), end='')
		else:
			print(matrics[i][j])

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

rows = [0]*(r+1)
rows[r] = []
total = 0

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

rows[r].append(total)

for i in range(r+1):
    for j in range(c+1):
        rows[i][j] = str(rows[i][j])
    line = " ".join(rows[i])
    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 = map(int, input().split())
spread = []
for i in range(r):
    spread.append(list(map(int, input().split())))

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

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

sum_c.append(sum(sum_c))
spread.append(sum_c)
for i in spread:
    print(" ".join(map(str, i)))

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

matrix = []

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

sumlist = []

for C in range(c+1):
    SUM = 0
    for R in range(r):
        SUM += matrix[R][C]
    sumlist.append(SUM)
matrix.append(sumlist)

for R in range(r+1):
    for C in range(c+1):
        if C != c:
            print(matrix[R][C],end=' ')
        else:
            print(matrix[R][C],end='')
    print(end='\n')

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

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

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

for line in lines:
    print(*line)

Solution (Python):
r,c = map(int,input().split())
A=[list(map(int,input().split()))for _ in[0]*r]
B=A+[[sum(i)for i in zip(*A)]]
for i in B:
    print(*i,sum(i))

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

for i in range(r):
    for j in range(c+1):
        c_sum[j] += mat[i][j]
    
mat.append(c_sum)
for i in range(len(mat)):
    print(*mat[i])

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

Solution (Python):
def main():
  row_num,col_num=map(int, input().split())  
  table=list()

  for i in range(row_num):
    row = list(map(int, input().split()))
    table.append(row)

    row_sum = 0
    for num in table[i]:
      row_sum += num
    table[i].append(row_sum)

  col_sum = list()
  for i in range(col_num):
    col = 0
    for j in range(row_num):
      col += table[j][i]
    col_sum.append(col)
  
  all_sum = 0
  for i in col_sum:
    all_sum += i
  col_sum.append(all_sum)
  table.append(col_sum)
  
  for row in table:
    print(*row)

if __name__ == '__main__':
  main()

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

for i in range(c+1):
  res = 0
  for j in range(r):
    res += matrix[j][i]
  sum_.append(res)
matrix.append(sum_)
for i in range(r+1):
  print(' '.join(map(str, matrix[i])))

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

a = []
b = []

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

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

a.append(b)

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

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

for j in range (len(rc[0])):
    sum_c = 0
    for i in range(len(rc)):
        sum_c = sum_c + rc[i][j]
    sum_cs.append(sum_c)
rc.append(sum_cs)
for i in range(len(rc)):
    for j in range(len(rc[0])):
        print(rc[i][j],end = "")
        if j != len(rc[0])-1:
            print(" ",end = "")
        else:
            print("")

Solution (Python):
m,n = list(map(int,input().split()))
tbl = [[0 for i in range(n+1)] for j in range(m+1)]
s= [0 for i in range(n+1)]
for i in range(m):
    l=list(map(int,input().split()))
    l.append(sum(l))
    tbl[i]=l
for j in range(n+1):
    for i in range(m):
        s[j] += tbl[i][j]
tbl[m] = s
for i in range(m+1):
    for j in range(n):
        print(tbl[i][j],end=" ")
    print(tbl[i][n],end="\n")

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

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

ss_row = []
for j in range(c+1):
    ss_rows_value = [k[j] for k in ss]
    ss_row.append(sum(ss_rows_value))
    
ss.append(ss_row)

for l in range(r+1):
    print (*ss[l])

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):
rc, cc = map(int, input().split())
i = 0
r = []
c_sum = [0] * cc

while rc > i:
    r.append([int(s) for s in input().split()])
    r[i].append(sum(r[i]))
    j = 0
    while cc > j:
        c_sum[j] += r[i][j]
        j += 1
    i += 1

i, j = 0, 0
while rc > i:
    while cc + 1 > j:
        if cc != j:
            print("{} ".format(r[i][j]), end="")
        elif cc == j:
            print(r[i][j])
        j += 1
    i += 1
    j = 0

c_sum.append(sum(c_sum))
i = 0
while cc + 1 > i:
    if cc != i:
        print("{} ".format(c_sum[i]), end="")
    elif cc == i:
        print(c_sum[i])
    i += 1

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

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

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

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

for i in range(r+1):
    m = 0
    for j in range(c):
        m += sheet[i][j]
        print(sheet[i][j], end=' ')
    print(m)

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

A = [list(map(int,input().split(" "))) for i in range(r)]
B = []
x = 0
y = 0
for i in range(r):
    for j in range(c):
        x += A[i][j]
    A[i].append(x)
    x = 0

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

A.append(B)

for a in A:
    print(*a)

Solution (Python):




r_length,c_length  = map(int, input().split())

spread_sheet = [[0] * (c_length) for i in range(r_length + 1)]
for i in range(r_length):
    spread_sheet[i] = list(map(int, input().split()))

total = 0
for i in range(r_length):
    calc = 0
    for j in range(c_length):
        calc += spread_sheet[i][j]

    spread_sheet[i].append(calc)
    total += calc

for i in range (c_length):
    calc = 0
    for j in range(r_length):
        calc += spread_sheet[j][i]

    spread_sheet[r_length][i] = calc

spread_sheet[r_length].append(total)


for i in range(r_length + 1):
    print(spread_sheet[i][0], end='')
    for j in range(1,c_length + 1):
        print(f' {spread_sheet[i][j]}', end='')

   
    print('')

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

table=[]

for i in range(r):
    table.append(list(map(int, input().split(" "))))


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


table_t=[list(x) for x in zip(*table)]


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


ans=[list(x) for x in zip(*table_t)]


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

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

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

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

for i in range(r):
    print(*num[i])
print(*num2)

Solution (Python):
N,M=map(int,input().split())
l = [list(map(int, input().split())) for i in range(N)]
new=[0 for i in range(M)]
for i in range(N):
    for j in range(M):
        new[j]+=l[i][j]
    for z in l[i]:
        print(z,end=" ")
    print(sum(l[i]))
for c in new:
    print(c,end=" ")
print(sum(new))

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

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

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

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

a = [[int(t)for t in input().split()]for _ in [0]*r]

r_sum = []

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

c_sum = []

for i in range(c):
    s_ = 0
    for j in range(r):
        s_+=a[j][i]
    c_sum.append(s_)

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

for t in range(c):
    print(c_sum[t],end=' ')

print(sum(c_sum))

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

spread = [[0]*(c+1) for _ in range(r+1)]



for k in range(r):
    number = input().split()
    for i in range(c):
        spread[k][i] = int(number[i])
        spread[k][i+1] = sum(spread[k])

for l in range(r):
    for m in range(c+1):
        spread[r][m] += spread[l][m] 

for n in range(r+1):
    print(*spread[n])

Solution (Python):
row, column = map(int,input().split())
lis = [[0]*(column+1) for i in range(row+1)]
for i in range(row):

    inp = list(map(int,input().split()))
    lis[i] = inp + [0]

for i in range(row):
    for j in range(column):
        lis[row][j] += lis[i][j]
        lis[i][column] += lis[i][j]
        lis[row][column] += lis[i][j]

for i in range(row+1):
    print(*lis[i])

Solution (Python):
r,c = map(int, input().split())
f = [0 for i in range(c)]
for i in range(r):
  e = list(map(int,input().split()))
  for j in range(c) :
    print("{} ".format(e[j]),end="")
    f[j] += e[j]
  print(sum(e))

for j in range(c) :
  print("{} ".format(f[j]),end="")
print(sum(f))

Solution (Python):
row , col = map(int,input().split())
row = int(row)
end_num = 0

row_col_list = []
while True:
    base_suit = input()
    row_col_list.append(base_suit)

    end_num += 1
    if row == end_num:
        break

col_sum_list = []
for row in row_col_list:
    term = row.split()
    row_sum = 0
    col_list = []
    for r in term:
        row_sum += int(r)
        col_list.append(int(r))
        print('{} '.format(r),end='')
    
    col_list.append(row_sum)
    print(row_sum)
    col_sum_list.append(col_list)

for i in range(0,col+1):
    col_sum = 0
    for c in col_sum_list:
        col_sum += c[i]

    print('{}'.format(col_sum),end='')
    if i != col:
        print(' ',end='')

print()

Solution (Python):




data_1 = list(map(int,input().split()))
line_i = list()
for i in range(data_1[0]):
    line_i.append(list(map(int,input().split())))
    new = sum(line_i[i])
    line_i[i].append(new)
line_new = list()   
for k in range(data_1[1]+1):
    sammary =0
    for j in range(data_1[0]):
        sammary += line_i[j][k]
    line_new.append(sammary)
line_i.append(line_new)

for l in range(data_1[0]+1):
    print(" ".join(map(str,line_i[l])))

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

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

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

for a in A:
    print(*a)

Solution (Python):
r,c = map(int, input().split())
rows = list()
for i in range(r):
    rows.append(list(map(int, input().split())))
[row.append(sum(row)) for row in rows]
rows.append([sum(t) for t in zip(*rows)])
[print(*row) for row in rows]

Solution (Python):

a, c = map(int, input().split())

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

for col in range(a):
    Col = list(map(int, input().split()))
    for row in range(c):
        table[col][row] = Col[row]

for row in range(c):
    for col in range(a):
        table[a][row] += table[col][row]
        table[col][c] += table[col][row]
        table[a][c] += table[col][row]

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

    print()

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

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

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


for i, row in enumerate(tbl):
    for j, col in enumerate(row):
        print (tbl[i][j],end='')
        if j != c:
            print(' ',end='')
    print()

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]))
    print(*list[i])


sumList =[]
for j in range(c+1):
    sum = 0
    for i in range(r):
        sum += list[i][j]
    sumList.append(sum)
print(*sumList)

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

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

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

list = []
for col in range(c + 1):
  sum = 0
  for row in range(r):
    sum += A[row][col]
  list.append(sum)

A.append(list)
for row in range(r + 1):
  for col in range(c + 1):
    if(col == c): print(A[row][col])
    else: print(A[row][col], "", end = "")

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

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

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

for i in range(r):
    A[i] = list(map(int,input().split()))
    A_str = [[str(x) for x in y] for y in A]
    
    l = A_str[i]
    print(" ".join(l) + " " + str(sum(A[i])))

for i in range(r):
    for j in range(c):
        s[j] += A[i][j]

sum_str = list(map(str,s))
print(" ".join(sum_str) + " " + str(sum(s)))

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

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

while r > 0:
    n =[int(n) for n in input().split()]
    n.append(sum(n))

    for i in range(len(n)):
        last_row[i] += n[i]

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

    r-=1

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

Solution (Python):
import functools

if __name__ == "__main__":
    num_rows, num_cols = list(map(int, input().split()))

    table = []

    for _ in range(num_rows):
        row = list(map(int, input().split()))

        table.append(row)

    table_added_row_sum = list(map(lambda row: row + [sum(row)], table))

    col_sum = functools.reduce(
        lambda acc, elem: acc + [sum(elem)],
        list(zip(*table_added_row_sum)),
        []
    )

    table_added_row_col_sum = table_added_row_sum + [col_sum]

    string_records = list(map(
        lambda row: ' '.join(map(str, row)),
        table_added_row_col_sum
    ))

    for string_record in string_records:
        print(string_record)

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


for i in range(r):
    for j in range(c):
        b[i][j]=a[i][j]
        b[r][j]+=a[i][j]
        b[i][c]+=a[i][j]
        b[r][c]+=a[i][j]

for i in b:
  print(*i)

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())
x = [] * r

for _ in range(r):
    l = list(map(int,input().split()))
    l.append(sum(l))
    x.append (l)

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

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

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

total_row = []
for col in range(c+1):
    column_sum = 0
    for row in range(r):
        column_sum += table[row][col]
    total_row.append(column_sum)
table.append(total_row)

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

Solution (Python):
r,c = map(int,input().split())
tbl = [list(map(int,input().split())) for _ in range(r)]
tbladd = []
for i in range(r):
    tbl[i].insert(c,sum(tbl[i]))
for i in range(c+1):
    sum = 0
    for j in range(r):
        sum += tbl[j][i]
    tbladd.insert(i,sum)
tbl.append(tbladd)
for i in range(r+1):
    for j in range(c+1):
        if j != c:
            print(tbl[i][j], end=' ')
        else:
            print(tbl[i][j], end='')
    if i != r:
        print()
    else:
        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]))))

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())
A = [list(map(int,input().split())) for _ in range(r)]
ans = [0] * c

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

ans.append(sum(ans))

for l in A:
    l = [str(i) for i in l]
    print(' '.join(l))
else:
    l = [str(i) for i in ans]
    print(' '.join(l))

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

EX_list = []

for i in range(r):
    EX_list.append(input().split())
for i in range(r):
    r_sum = 0
    for j in EX_list[i]:
        r_sum += int(j)
    EX_list[i].append(r_sum)
    print(*EX_list[i])

c_sum_list = []
for c_i in range(c):
    c_sum = 0
    for r_i in range(r):
        c_sum += int(EX_list[r_i][c_i])
    c_sum_list.append(c_sum)
c_sum_list_sum = 0
for i in c_sum_list:
    c_sum_list_sum += i
c_sum_list.append(c_sum_list_sum)
print(*c_sum_list)

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

matrix = [(list(map(int, input().split()))) for i in range(r)]
total = [0] * c

for row in matrix:
    for i, elem in enumerate(row):
        print("{} ".format(elem), end="")
        total[i] += elem
    print(sum(row))

for total_col in total:
    print("{} ".format(total_col), end="")
print(sum(total))

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

mat = []
for row in range(r):
    row_index = list(map(int, input().split()))
    mat.append(row_index)


new_r = [0]*c
mat.append(new_r)

for i in range(c):
    for j in range(r):
        mat[r][i] += mat[j][i]

for i in range(r+1):
    m = 0
    for j in range(c):
        m += mat[i][j]
        print((mat[i][j]), end=' ')
    print(m)

Solution (Python):
r,c=input().split()
r,c=[int(r),int(c)]
A=[0]*r
for i in range(r):
    A[i]=list(map(int, input().split()))
for i in range(r):
    sum1=0
    for j in range(c):
        sum1+=A[i][j]
    A[i].append(sum1)
b=[]
for i in range(c+1):
    sum2=0
    for j in range(r):
        sum2+=A[j][i]
    b.append(sum2)
for i in range(r):
    results=" ".join([str(m) for m in A[i]])
    print(results)
results2=" ".join([str(m) for m in b])
print(results2)

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

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

[(s.append(sum(s)) or print(*s)) for s in a]

print(*[sum(c)for c in zip(*a)])

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

tableA = []
resultC = []

for i in range(r):
    tableA.append(list(map(int, input().split())))

for index_column in range(c):
    sumC = 0
    for index_row in range(r):
        sumC = sumC + tableA[index_row][index_column]
    resultC.append(sumC)

tableA.append(resultC)


for j in range(len(tableA)):
    tableA[j].append(sum(tableA[j]))

for i in tableA:
    print(*i, sep=" ")

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

res = [0] * c

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

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

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

for i in range(r):
    for j in range(c):
        rows[i][c] += rows[i][j]

for i in range(c + 1):
    for j in range(r):
        rows[r][i] += rows[j][i]

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

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

Solution (Python):
r, c = map(int, input().split())
nums = []
for i in range(r):
	nums.append(list(map(int, input().split())))
c_nums = [0 for i in range(c)]
for r_nums in nums:
	print(' '.join(list(map(str, r_nums))), sum(r_nums))
	index = 0
	for r_num in r_nums:
		c_nums[index] += r_num
		index += 1
print(' '.join(list(map(str, c_nums))), sum(c_nums))

Solution (Python):
r, c = map(int, input().split())
table = [[int(x) for x in input().split()] for _ in range(r)]
for row in table:
    row.append(sum(row))
ex_lst = []
for col in zip(*table):
    ex_lst.append(sum(col))
table.extend([ex_lst])

for row in table:
    print(*row)

Solution (Python):
def main():
    n,m = map(int,input().split())
    sheet = [[0]*(m+1) for _ in range(n+1)]
    for i in range(n):
        r = list(map(int,input().split()))
        s = 0
        for j in range(m):
            sheet[i][j] = r[j]
            s += r[j]
            sheet[n][j] += r[j]
        sheet[i][m] = s
        sheet[n][m] += s
    for i in range(n+1):
        print (' '.join(map(str,sheet[i])))


if __name__ == '__main__':
    main()

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

for i in range(r):
    xlx[i][-1] = sum(xlx[i])
for i in range(c):
    tmp = 0
    for j in range(r):
        tmp += xlx[j][i]
    xlx[-1][i] = tmp

s = 0
for i in range(r):
    s += sum(xlx[i])-max(xlx[i])
xlx[-1][-1] = s

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

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

temp_row = []
for i in range(m+1):
    temp_row.append(0)
matrixA.append(temp_row)

temp_col = []
cnt = 0
for i, row in enumerate(matrixA):
    if i == n:
        break
    row.append(sum(row))
    cnt += 1
    for j, column in enumerate(row):
        matrixA[n][j] += column
        
for row in matrixA:
    print(" ".join(map(str, row)))

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

A.append(add_l)

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