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(' '))
c_list = [0] * (C + 1)
for r in range(R):
    r_list = list(map(int,input().split(' ')))
    r_list.append(sum(r_list))
    print(*r_list)
    c_list = [r + c for r,c in zip(r_list,c_list)]
print(*c_list)

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

calc_table = []
res_table = []

for _ in range(r):
	calc_table = list(map(int,input().split()))
	num = 0
	for i in calc_table:
		num += i
	calc_table.append(num)
	print(" ".join(str(a) for a in calc_table))
	res_table.append(calc_table)

last_table = []
for j in range(c + 1):
	last_num = 0
	for k in range(r):
		last_num += res_table[k][j]
	last_table.append(last_num)
print(" ".join(str(a) for a in last_table))

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

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

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

for i in range(len(table)):
    for j in range(len(table[0])):
        if j != c:
            print(f"{table[i][j]} ", end='')
        else:
            print(table[i][j])

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

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

ans = 0
for i in range(r):
    for j in range(c):
        print('{} ' .format(table[i][j]), end='')
        ans += table[i][j]
    print(ans)
    ans = 0

total = 0
for i in range(c):
    for j in range(r):
        ans += table[j][i]
    print('{} ' .format(ans), end='')
    total += ans
    ans = 0
print(total)

Solution (Python):

list_xy = list(map(int, input().split()))
result_data = [[0 for y in range(list_xy[1]+1)] for x in range(list_xy[0]+1)] 


for x in range(list_xy[0]):
    input_data = list()
    input_data = list(map(int, input().split()))
    for y in range(list_xy[1]):
        result_data[x][y] = input_data[y]
        result_data[x][list_xy[1]] += input_data[y]
        result_data[list_xy[0]][y] += input_data[y]
    result_data[list_xy[0]][list_xy[1]] += result_data[x][list_xy[1]]


for a in result_data:
    print(*a)

Solution (Python):
r,c = list(map(int, input().split() ))
table = [[0 for i in range(c)] for j in range(r)];
rm = [0 for i in range(r)]
cm = [0 for i in range(c)]
for ri in range(r):
 table[ri] = list(map(int, input().split() ))
 rm[ri] = sum(table[ri])
for ci in range(c):
 for ri in range(r):
  cm[ci] = cm[ci] + table[ri][ci]
for ri in range(r):
 print(" ".join(map(str,table[ri])), end = "" )
 print(f" {rm[ri]}")
print(" ".join(map(str, cm)), end="")
print(f" {sum(cm)}")

Solution (Python):
queue=[]
vector=[]
first_num=[int(w) for w in input().split()]

for i in range(first_num[0]):
    queue.append([int(w) for w in input().split()])

for i in range(first_num[0]):
    sum=0
    for w in range(first_num[1]):
        sum+=queue[i][w]
    queue[i].append(sum)

for i in range(first_num[1]+1):
    sum=0
    
    for w in range(first_num[0]):
        sum+=queue[w][i]
        
    vector.append(sum)
    
queue.append(vector)

for i in range(first_num[0]+1):
    print(' '.join(map(str,queue[i])))

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

Solution (Python):
l = list(map(int,input().split()))
r = l[0]
c = l[1]


lst = [0 for i in range(c)]

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

    print(*temp,sum(temp))

print(*lst,sum(lst))

Solution (Python):
c=[]
d=[]
dd = []
a,b = map(int,input().split())
for i in range(a):
    c.append(list(input().split()))
    d.append([int(s) for s in c[i]])
for i in range(a) :
    f = sum(d[i])
    d[i].append(f)
for i in range(b+1):
    ff=0
    for j in range(a):
        ff = ff + d[j][i]
    dd.append(ff)
d.append(dd)
for i in range(a+1):
        print(*d[i])

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

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

result = []
for _ in range(r):
    r_vec = list(map(int, input().split()))
    r_vec.append(sum(r_vec))
    result.append(r_vec)

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

Solution (Python):
r,c=map(int, input().split())
mat = []
for y in range(r):
	mat.append(list(map(int,input().split())))
	
cols = [0]*c

for row in mat:
	print(" ".join(list(map(str, row))), end=" ")
	print(sum(row))
	for i in range(c):
		cols[i] += row[i]

print(" ".join(list(map(str, cols))), end=" ")
print(sum(cols))

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):
    row = list(map(int, input().split()))
    row_sum = sum(row)
    mat[i][c] = row_sum
    for j in range(c):
        mat[i][j] = row[j]

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

for i in range(r+1):
    row = str(mat[i][0])
    for j in range(c):
        j = j + 1
        row += " " + str(mat[i][j])
    print(row)

Solution (Python):

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


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


for j in rc:
    sumr = sum(j)
    j.append(sumr)
    print(" ".join(map(str, j)))

last = []
for k in range(c + 1):
    sumc = 0
    for l in range(r):
        sumc += rc[l][k]
    last.append(sumc)
print(" ".join(map(str, last)))

Solution (Python):
r,c=list(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):
    mat[i].append(sum(mat[i]))

for i in range(c):
    s=0
    for j in range(r):
        s+=mat[j][i]
    mat[r][i]=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 = [int(i) for i in input().split()]
table = [list(map(int, input().split())) for _ in range(r)]
for row in table:
    row.append(sum(row))
table.append([sum(column) for column in zip(*table)])
for row in table:
    print(*row)

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

ans = [[0]*(c+1) for _ in range(r+1)]
for i in range(r):
    cnt = 0
    for j in range(c+1):
        if j != c:
            cnt += L[i][j]
            ans[i][j] = L[i][j]
        else:
            ans[i][j] = cnt
            
for i in range(r):
    for j in range(c+1):
        ans[r][j] += ans[i][j]
        
for i in range(r+1):
    print(*ans[i])

Solution (Python):
r,c=map(int,raw_input().split())
a=[map(int,raw_input().split()) for i in range(r)]
b=[0 for i in range(c+1)]
for i in range(r):
    a[i].append(sum(a[i]))
    for j in range(c+1):
        b[j]+=a[i][j]
a.append(b)
l=""
for i in range(r+1):
    for j in range(c+1):
        print (a[i][j]),
    print

Solution (Python):
def create_new_table2(table):

    v = list()

    for j in range(len(table[0])) :
        s = 0
        for i in range(len(table)):
            s += table[i][j]
        v.append(s)

    table.append(v)

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

        print("\n", end="")

if __name__ == "__main__":
    
    param = input().split(" ")
    r = int(param[0])
    c = int(param[1])

    table = list()

    l = r
    
    while(l):

        lines = input().split(" ")

        line = list([ int(n) for n in lines])
        s = sum(line)
        line.append(s)

        table.append(line)

        l -= 1

    create_new_table2(table)

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

table = []
for _ in range(r):
    temp = [int(x) for x in input().split()]
    temp.append(sum(temp))
    table.append(temp)
    
c_sum = [0 for _ in range(c + 1)]
for i in range(r):
    for j in range(c + 1):
        c_sum[j] += table[i][j]
table.append(c_sum)

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

Solution (Python):

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


A = [[int(i) for i in input().split()]for j in range(r)]


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

B = list(map(list,(zip(*A)))) 
for i in range(c+1): 
    addc = 0 
    for j in range(r):
        addc += B[i][j]
    B[i].append(addc) 

A = list(map(list,(zip(*B)))) 

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

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

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

Solution (Python):
r,c  = map(int, input().split())
tbl = []
tblS = [0 for i in range(c+1)]
for i in range(r):
    tbl.append(input())
    tmpL = tbl[i].split()
    tmpL = [int(j) for j in tmpL]
    print(tbl[i] ,sum(tmpL))
    
    for j in range(c):
        tblS[j] += int(tbl[i].split()[j])
    
    tblS[c] += sum(tmpL)

print(*tblS)

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

sr = []

for i in range(r):
  row = [i for i in map(int, input().split())]
  row.append(sum(row))
  print(' '.join(map(str, row)))
  sr = row if i == 0 else [sr[i] + row[i] for i in range(c + 1)]

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

Solution (Python):
list = []
r,c=map(int,input().split())
all_ttl = 0
for i in range(r):
    s = input()
    ttl = 0
    cnt = 0
    for a in map(int, s.split()):
        if i==0:
            list.append(a)
        else:
            list[cnt] += a
        ttl += a
        cnt += 1
    s = s + " " + str(ttl)
    all_ttl += ttl
    print(s)
s = ""
for a in list:
    if s == "":
        s = str(a)
    else:
        s = s + " " + str(a)
print(s + " " + str(all_ttl))

Solution (Python):
r,c = map(int,input().split())
rowsum = [0 for i in range(c)]
for i in range(r):
    colsum = 0
    nums = [int(e) for e in input().split()]
    for j in range(c):
        print(nums[j],end=" ")
        colsum = colsum + nums[j]
        rowsum[j] = rowsum[j] + nums[j]
    print(colsum)
print(*rowsum,end = " ")
print(sum(rowsum))

Solution (Python):
r ,c = map(int,input().split())
l = [[int(x) for x in input().split()] for i in [0]*r]
s = [0]*(c+1)
for j in range(r):
    l[j] += [sum(l[j])]
    for k in range(c+1):
        s[k] += l[j][k]
for m in range(r):
    print(*l[m])
print(*s)

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

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

for i in range(len(sheet)):
    for j in range(len(sheet[i])):
        print(sheet[i][j],end="")

        if(j<len(sheet[i])-1):
            print(" ",end="")
    print()

Solution (Python):
r, c = map(int,input().split())
print_list_sum = lambda l : print(" ".join(map(str,l)) + " " + str(sum(l)))
a = [list(map(int,input().split())) for _ in range(r)]
s = [0] * c
for i in range(r):
    for j in range(c):
        s[j] += a[i][j]
    print_list_sum(a[i])
print_list_sum(s)

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

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

_col_sum = [] 
for j in range (c+1):
    num = 0
    for i in range (r):
        num += matrix[i][j]
    _col_sum.append(num)

matrix.append(_col_sum)

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

Solution (Python):

r,c=map(int,input().split())
m=[[]for i in range(r)]
for i in range(r):
    m[i]=list(map(int,input().split()))
sc=[0]*c
for i in range(r):
    for j in range(c):
        sc[j]+=m[i][j]
for er in m:
    print(*er,end=' ')
    print(sum(er))
print(*sc,end=' ')
print(sum(sc))

Solution (Python):
number_of_rows, number_of_columns = list(map(int, input().split(" ")))
rows = [list(map(int, input().split(" "))) for i in range(number_of_rows)]

for j in range(number_of_rows):
    for k in range(number_of_columns ):
        if k == number_of_columns - 1:
            print(rows[j][k],end=" ")
            print(sum(rows[j]))
            rows[j].append(sum(rows[j]))
        else:
            print(rows[j][k],end=" ")
ans = []

for l in range(number_of_columns + 1):
    plus = 0
    for m in range(number_of_rows):
        plus += rows[m][l]
    ans.append(plus)
for n in range(number_of_columns + 1):
    if n == number_of_columns:
        print(ans[n])
    else:
        print(ans[n],end=" ")

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

Solution (Python):
lst_input_num = list(map(int, input().split()))
r, c = lst_input_num[0], lst_input_num[1]
lst = []
lst_row = []

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

for i in range(c):
    lst_column = []
    for j in range(r):
        lst_column.append(lst[j][i])

    lst_row.append(sum(lst_column))

lst.append(lst_row) 

count = 0
for i in lst:
    for j in i:
        print(j, end=" ")

    print(sum(i))

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

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

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, *D = map(int, open(0).read().split())
A = [D[i:i+c] for i in range(0, r*c, c)]
A.append([0 for _ in range(c+1)])
for i in range(r):
    A[i].append(sum(A[i]))
    for j in range(c+1):
        A[r][j] += A[i][j]
for i in range(r+1):
    print(' '.join(map(str, A[i])))

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

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

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

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    h,w = map(int, input().split())
    t=[list(map(int, input().split())) for _ in range(h)]
    sum_row=[0]*h
    sum_column=[0]*w
    for i,row in enumerate(t):
        for j,a in enumerate(row):
            sum_row[i]+=a
            sum_column[j]+=a
    for i,row in enumerate(t):
        print(*t[i],sum_row[i])
    print(*sum_column,sum(sum_column))

main()

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

for i in range(r):
    row = [ int(s) for s in input().split() ]
    sheet[i][:c+1] = row + [sum(row)]
    total_row[:c+1] = [ total_row[j] + sheet[i][j] for j in range(c+1) ]

sheet[r][:c+1] = total_row

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

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())
listA = [[0] * (c+1) for i in range(r+1)]

for i in range(0, r):
    listnum = input().split()
    for j in range (0, c):
        s = 0
        listA[i][j]=listnum[j]
        for elem in listnum:
            s = s + int(elem)
    listA[i][c] = str(s)

for i in range(0,c+1):
    t = 0
    for j in range(0,r):
        t = t + int(listA[j][i])
    listA[r][i] = str(t)

for i in range(0, r+1):
    print(" ".join(listA[i]))

Solution (Python):
r,c = map(int,input().split())
numbers = []
for i in range(r):
    subnumbers = list(map(int,input().split()))
    numbers.append(subnumbers)
for j in range(r):
    for k in range(c):
        print(numbers[j][k],end = " ")
    print(sum(numbers[j]))
allcount = 0
for l in range(c):
    count = 0
    for m in range(r):
        count += numbers[m][l]
    print(count,end = " ")
    allcount += count
print(allcount)

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

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

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

    L[i].append(tmp)

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

        if j != c:
            print(" ", end="")

    print()

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

    print(tmp, end="")

    if i != c:
        print(" ", end="")

print()

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

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

s = []

for r in range(R):
    s.extend([int(i) for i in input().split()])
    
for r in range(R):
    row = s[r*C:r*C+C]
    row.append(sum(row))
    print(*row)

footer = [sum(s[c::C]) for c in range(C)]
footer.append(sum(footer))
print(*footer)

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

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

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

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

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

row = [0] * (c + 1)
for i in range(c+1):
    for j in range(r):
        row[i] += tbl[j][i]
tbl.append(row)

for row in tbl:
    print(" ".join(map(str, row)))

Solution (Python):
r,c=map(int,input().split())
matr= [input().split() for i in range(r)]
for i in range(len(matr)):
    matr[i] = [int(j) for j in matr[i]]
matr_column=[sum(matr[i]) for i in range(len(matr))]
for i in range(len(matr)):
    matr[i].append(matr_column[i])
matr_s=sum(matr,[])
matr_row=[]
for i in range(int((r*c+r)/r)):
    matr_r=matr_s[i:len(matr_s)][::c+1]
    matr_row.append(matr_r)
for i in range(len(matr)):
    print(*matr[i])
print(*[sum(matr_row[i]) for i in range(len(matr_row))])

Solution (Python):
r,c=[int(k) for k in input().split()]
arr=[[]]*r
for i in range(r):
    arr[i]=[int(k) for k in input().split()]
arr+=[[0]*c]
for i in range(r):
    arr[i].append(sum(arr[i]))
    arr[r]=[arr[r][k]+arr[i][k] for k in range(c)]
arr[r].append(0)
for v in arr[r]:
    arr[r][c]+=v
arr[r][c]//=2
for i in range(r+1):
    for j in range(c+1):
        arr[i][j]=str(arr[i][j])
for x in arr:
    print(' '.join(x))

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

b=[]
for j in range(m+1):
    tmp=0
    for l in range(n):
        tmp=tmp+a[l][j]
    b.append(tmp)
    

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

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

for i in range(r):
    for j in range(c):
        sheet[i][c] += sheet[i][j]
        sheet[r][j] += sheet[i][j]
    sheet[r][c] += sheet[i][c]
    l = [str(k) for k in sheet[i]]
    print(' '.join(l))
l = [str(k) for k in sheet[r]]
print(' '.join(l))

Solution (Python):

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

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

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

for k in a:
    t = sum(k)
    k.append(t)

for x in range(c+1):
    z = 0
    for y in a:
        z += y[x]
    else:
        ans.append(z)
else:
    a.append(ans)

for i in a:
    print(*i)

Solution (Python):
r, c = map(int,input().split())
sheet = []
for i in range(0,r):
    row = []
    row[:] = map(int,input().split())
    rsum = 0
    for j in range(0,c):
        rsum+=row[j]
    row.append(rsum)
    sheet.append(row)
    print(' '.join(map(str,row)))

row = []
for j in range(0,c+1):
    csum = 0
    for i in range(0,r):
        csum+=sheet[i][j]
    row.append(csum)
print(' '.join(map(str,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 k in range(r):
        A[r][j] += A[k][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(" "))
table = []
for i in range(r):
    line = list(map(int, input().split(" ")))
    table.append(line)
for i in range(r):
    x = 0
    for j in range(c):
        x += table[i][j]
    table[i].append(x)
add_table = []
for i in range(c+1):
    y = 0
    for j in range(r):
        y += table[j][i]
    add_table.append(y)
table.append(add_table)
for i in range(r+1):
    print(*table[i])

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

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

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


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

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

sum=0
for i in range(c):
    sum+=b[r][i]

b[r][c]=sum

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

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

sum_colum = [0]*c
sum_matrix = 0
for i in range(r):
    sum_row = sum(l[i])
    sum_matrix += sum_row
    l_str = [str(n) for n in l[i]]
    print(" ".join(l_str),end=" ")
    print(sum_row,end="")
    print()

for i in range(c):
    for j in range(r):
        sum_colum[i]+= l[j][i]
    print(sum_colum[i], end=" ")
print(sum_matrix)

Solution (Python):
r, c = map(int, input().split())
sums = [0] * (c + 1)
for x in range(0, r):
    raw = list(map(int, input().split()))
    raw_t = 0
    for x in range(0, c):
        sums[x] += raw[x]
        raw_t += raw[x]
    raw.append(raw_t)
    sums[c] += raw_t
    print(*raw)
print(*sums)

Solution (Python):
R, C = map(int, input().split())
spred_sheet = []
sum_row = [0 for i in range(C+1)]
for i in range(R):
    input_line = list(map(int, input().split()))
    input_line = input_line + [sum(input_line)]
    spred_sheet.append(input_line)
    for j in range(C+1):
        sum_row[j] += input_line[j]
spred_sheet.append(sum_row)
for i in range(R+1):
    for j in range(C+1):
        print("{}".format(spred_sheet[i][j]), end="")
        if j == C:
            print()
        else:
            print(" ", end="")

Solution (Python):
def shownum(list):
    stri = str()
    for s in list:
        stri += str(s) + " "
    print(stri[:-1])
    
r , c = map(int,input().split())
csum =[list() for x in range(c)]
rlist = [list() for x in range(r+1)]




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

sum = 0
for i in rlist[r]:
   sum += i
rlist[r].append(sum)


for i in range(r+1):
    shownum(rlist[i])

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

values=[]

for i in range(r):
    values=list(map(int,input().split(" ")))
    for j in range(c+1):
        if j!=c:
            originalMatrix[i][j]=values[j]
        else:
            originalMatrix[i][j]=sum(values)

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

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

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

Solution (Python):
def get_row_sum(l):
    sums = 0
    for num in l:
        sums += num
    return sums

num_rows, num_columns = map(int, input().split())

result_table = list()
sum_row = [0 for _ in range(num_columns+1)]

for i in range(num_rows):
    row = list(map(int, input().split()))
    row_sum = get_row_sum(row)
    row.append(row_sum)
    result_table.append(row)
    
    for i in range(len(row)):
        sum_row[i] += row[i]

result_table.append(sum_row)

for r in result_table:
    for i, num in enumerate(r):
        print(num, end='')
        if i != num_columns:
            print(end=' ')
    print()

Solution (Python):
r,c = map(int, input().split( ))
M = []
for _ in range(r):
    clm = list(map(int, input().split( )))
    clm.append(sum(clm))
    print(*clm)
    M.append(clm)
for i in range(c):
    sm = 0
    for j in range(r):
        sm += M[j][i]
    print(sm, end = " ")
sm = 0    
for j in range(r):
    sm += M[j][c]
print(sm)

Solution (Python):
r,c = map(int,input().split())
lst = [[0 for i in range(101)] for j in range(101)]
for i in range(r):
    lst[i][0:c] = map(int,input().split())
for i in range(r):
    lst[i][c] = sum(lst[i])
for i in range(c+1):
    for j in range(r):
        lst[r][i] += lst[j][i]
for i in range(r+1):
    for j in range(c+1):
        print(f"{lst[i][j]}",end = "")
        if j != c:
            print(" ",end = "")
        else:
            print()

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

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