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())
A=[[0 for i in range(c)]for j in range(r)]
for i in range(r):
  D=list(map(int,input().split()))
  for j in range(c):
    A[i][j]=D[j]
B=[[0 for i in range(c+1)]for j in range(r+1)]
for i in range(r):
  for j in range(c):
    B[i][j]=A[i][j]
for i in range(r):
  a=int(0)
  for j in range(c):
    a=a+A[i][j]
  B[i][j+1]=a
for i in range(c):
  b=int(0)
  for j in range(r):
    b=b+A[j][i]
  B[j+1][i]=b
  
f=int(0)
for j in range(c):
  f=f+B[r][j]
B[r][c]=f
for i in range(r+1):
  for j in range(c+1):
    print(B[i][j],end="")
    if j != c:
      print(" ",end="")
  print("")

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

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

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

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

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

table = list()


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

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

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

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

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

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

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

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

a =[]

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

for i in range(m):print(sum(a[i]),end=' ')

print(sum(a[m]))

Solution (Python):






import sys
import math
import array


class mymath:
    
    pi = 3.14159265358979323846264338

    
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()


class output:
    
    def list(self, l):
        l = list(l)
        
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()
















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

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

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

    A.append(a)

    for i in A:
        output.list(i)

if __name__ == '__main__':
    main()

Solution (Python):

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

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

for j in range(r):

    for cnt, element in enumerate(list(map(int, input().split()))):
        matrix[j][cnt] = element



for i in range(c):
    
    sum_cow = 0
    
    for j in range(r):

        sum_cow += matrix[j][i]

    matrix[r][i] = sum_cow


for j in range(r + 1):

    matrix[j][c] = sum(matrix[j])



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

    print()

Solution (Python):
r, c = map(int, input().split())
data = [list(map(int, input().split())) for i in range(r)]
for x in data:
    x.append(sum(x))
    print(' '.join(map(str, x)))
else:
    subdata = [sum(data[i][j] for i in range(r)) for j in range(c)]
    subdata.append(sum(subdata))
    print(' '.join(
        map(str, subdata)
    ))

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

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

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

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

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

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

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

for i in range(r) :
 s = sum(l[i])   
 l[i].append(s)   

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

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

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

Solution (Python):
RC = []
r, c = [int(e)for e in input().split()]
sum_col = [0]*(c+1)

for i in range(r):
    R = [int(e)for e in input().split()]
    R.append(sum(R))
    RC.append(R)
    for j in range(c+1):
        sum_col[j] += RC[i][j]

RC.append(sum_col)

for x in range(len(RC)):
    print(" ".join(map(str, RC[x])))

Solution (Python):

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


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


for i in range(r):
    s = sum(columns[i])
    columns[i].append(s)


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


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


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

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

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

for i in range(r):
    row = [int(c) for c in input().split()]
    for j in range(c):
        matrix[i][j] = row[j]
    matrix[i][-1] = sum(row)

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

for row in matrix:
    print(' '.join([str(i) for i in row]))

Solution (Python):
r,c=map(int,input().split())
R=list()
L=list()
M=list()
sum=0
for i in range(r):
    R=list(map(int,input().split()))
    L.append(R)
for j in range(r):
    for k in range(c):
        sum+=L[j][k]
    L[j].append(sum)
    sum=0
for l in range(c):
    for m in range(r):
        sum+=L[m][l]
    M.append(sum)
    sum=0
for n in range(c):
    sum+=M[n]
M.append(sum)
L.append(M)
for o in range(r+1):
    print(" ".join(map(str,L[o])))

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):
    for col in range(W+1):
        if(col == W):
            print("{}".format(table[row][col]),end="\n")
        else:
            print("{}".format(table[row][col]),end=" ")

Solution (Python):
if __name__ == "__main__":
    
    res = []
    r, c = map(int, input().split())
    for _ in range(r):
        res.append(list(map(int, input().split())))

    last_row = []

    
    for i in range(c):
        sum_of_i = 0
        for e in res:
            sum_of_i += e[i]
        last_row.append(sum_of_i)
    res.append(last_row)

    
    for e in res:
        e.append(sum(e))

    
    for r in res:
        print(*r)

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


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

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

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

Solution (Python):
if __name__ == '__main__':
	n,m = map(int,input().split())
	d = []
	for i in range(n):
		d.append([int(s) for s in input().split()])
		sum = 0
		for k in range(m):
			sum += d[i][k]
		d[i].append(sum)
	
	for i in range(n):
		for k in range(m+1):
			if k == m:
				print("%d" % d[i][k])
			else:
				print("%d" % d[i][k], end=" ")
	for i in range(m+1):
		sum = 0
		for k in range(n):
			sum += d[k][i]
		if i == m:
			print("%d" % sum)
		else:
			print("%d" % sum, end=" ")

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


matrixA = []


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


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


matrixA.append(col_sum)


for k in range(r+1):
    for l in range(c+1):
        print(matrixA[k][l], end='')
        if l < c:
            print(' ', end='')
    print('')

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

Solution (Python):
numbers = list(map(int, input().split(" ")))

arr_a = []
arr_b = []
matrix = []

for i in range(numbers[0]):
    arr_a = list(map(int, input().split(" ")))
    arr_a.append(sum(arr_a))
    matrix.append(arr_a)
    
for i in range(numbers[1]):
    total = 0
    for j in range(numbers[0]):
        total += matrix[j][i]
    arr_b.append(total)

arr_b.append(sum(arr_b))
matrix.append(arr_b)

for i in range(numbers[0] + 1):
    for j in range(numbers[1] + 1):
        if j == numbers[1]:
            print(matrix[i][j])
            
        else:
            print(matrix[i][j], end="")
            print(" ", end="")

Solution (Python):
import sys
s = [0] * (int(next(sys.stdin).split()[1]) + 1)
for l in sys.stdin:
	a = list(map(int,l.split()))
	a.append(sum(a))
	print(*a)
	for i,v in enumerate(a):
		s[i] += v
print(*s)

Solution (Python):
a = []
gyou = []
retu = []
s = 0

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

for i in range(r):
    gyou.append(0)

for i in range(c):
    a.append(list(map(int, input().split())))

for i in range(c):
        retu.append(sum(a[i]))

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

s = sum(gyou)

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

    if i == c - 1:
        print(" ".join(map(str, gyou)), s)

Solution (Python):
x = input()
list1 = x.split()
[r, c] = list1
r = int(r)
c = int(c)
list3 = []
list4 = []
for i in range(0, r):
    y = input()
    list2 = y.split()
    list2_i = [int(s) for s in list2]
    list3.append(list2_i)

for i in range(0, r):
    s = sum(list3[i])
    list3[i].append(s)

for p in range(0, c):
    z = 0
    
    for q in range (0, r):
        z = z + list3[q][p]
     
    list4.append(z)

s = sum(list4)
list4.append(s)

list3.append(list4)

for i in range(0, r + 1):
    list3[i] = [str(s) for s in list3[i]]

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

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

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

for i in range(r):
	Tbls = input()
	table[i] = list(map(int,Tbls.split()))
	
	
	print(Tbls,sum(table[i]),sep=' ')
	
	for j in range(c):
		Csum[j] += table[i][j]
		
	Csum[c] += sum(table[i])
	
print(' '.join(map(str,Csum)))

Solution (Python):
nums = list(map(int, input().split()))
table = []
for i in range(nums[0]):
    table.append(list(map(int, input().split())))
    table[i].append(sum(table[i][:]))
table.append([])
for i in range(nums[1]+1):
    t = 0
    for j in range(nums[0]):
        t += table[j][i]
    table[nums[0]].append(t)
for i in range(nums[0]+1):
    for j in range(nums[1]+1):
        if j < nums[1]:
            print(table[i][j], end = ' ')
        else:
            print(table[i][j])

Solution (Python):
N, M = map(int, input().split());
A = [[] for i in range(N+1)];
B = [0] * M;
SUM = 0;
for i in range(N):
    sum = 0;
    A[i] = list(map(int, input().split()));
    for j in range(M):
        sum = sum + A[i][j];
        B[j] = B[j] + A[i][j];
        print(A[i][j], end=" ");
    print(sum);
    SUM = SUM + sum;
for k in range(M):
    print(B[k], end=" ");
print(SUM);

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

for k in l:
    print(*k)

Solution (Python):
sheet_size = [int(i) for i in input().split()]
rows = sheet_size[0]
columns = sheet_size[1]

spread_sheet = []

for j in range(rows):
    row =  [int(i) for i in input().split()]
    row.append(sum(row))
    spread_sheet.append(row)

additional_row = []
for c in range(columns+1):
    column_value = 0
    for row in spread_sheet:
        column_value += row[c]
    additional_row.append(column_value)

spread_sheet.append(additional_row)


for row in spread_sheet:
    str_row = list(map(str, row))
    print(' '.join(str_row))

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

for a in range(r):
    S = input().strip().split()
    S = [int(s) for s in S]
    sum_c = sum(S)
    for b in range(c):
        A[a][b] = S[b]
        print(S[b],end=' ')
    A[a][c] = sum_c
    print(sum_c)
    
for i in range(c+1):
    for j in range(r):
        I[i] += A[j][i]
        if i == c and j == r-1:
            print(I[i])
        elif j == r-1:
            print(I[i],end=' ')

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):
n, m = map(int, input().split())

A = [[0]*(m+1) for i in range(n+1)]

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

for j in range(m+1):
    for i in range(n):
        A[n][j] += A[i][j]
        
for i in range(n+1):
    print(A[i][0], end='')
    for j in range(1, m+1):
        print(' %d'%A[i][j], end='')
    print()

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

for row in matrix:
    c_sum = 0
    for col in row:
        c_sum += col
    row.append(c_sum)

r_sum_list =[]
for col in range(c+1):
    r_sum = 0
    for row in range(r):
        r_sum += matrix[row][col]
    r_sum_list.append(r_sum)
matrix.append(r_sum_list)

for i in matrix:
    map_result = map(str,i)
    result = " ".join(map_result)
    print(result)

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

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

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

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

for i in range(m):
    for j in range(n):
        b[i] += A[j][i]

b.append(sum(b))

for i in range(n):
    print(' '.join(map(str, A[i])))
print(' '.join(map(str, b)))

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

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

for i in range(r):
    buff = input()
    lst = [int(x) for x in buff.split()]
    for j in range(c):
        ss[i][j] = lst[j]
    ss[i][c] = sum(lst)
    ss[r][c] += ss[i][c]

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

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

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

A = [[0 for i in range(m+1)] for j in range(n+1)]

for i in range(n):
  data = input().split()

  for j in range(m):
    A[i][j] = int(data[j])

for i in range(n):
  for j in range(m):
    A[i][m] += A[i][j]

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

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

Solution (Python):





















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

for i in range(r + 1):
    for j in range(c + 1):
        if i == r and j == c:
            print(total)
        elif j == c:
            total += sum(elements[i])
            print(sum(elements[i]))
        elif i == r:
            total2 = 0
            for k in range(r):
                total2 += elements[k][j]
            print(total2, end=" ")
        else:
            print(elements[i][j], end=" ")

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

for i in range(init[0]):
    row=list(map(int,input().split()))
    sum=0
    for j in range(init[1]):
        a[i][j]=row[j]
        sum+=row[j]
    a[i][init[1]]=sum


for i in range(init[1]+1):
    sum=0
    for j in range(init[0]):
        sum+=a[j][i]
    a[init[0]][i]=sum

for i in range(init[0]+1):
    for j in range(init[1]):
        print(a[i][j],end=' ')
    print(a[i][init[1]])

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

rc=[]
for i in range(r):
    rc1=[]
    rc1=input().split()
    rc1=[int(s) for s in rc1]
    rc.append(rc1)


for i in range(r):
    s=sum(rc[i])
    rc[i].append(s)


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

for i in range(r+1):
    print(*rc[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(' '))
sheet = [[0 for col in range(c+1)] for row in range(r+1)]
for row in range(r):
    l = list(map(int, input().split(' ')))
    for col in range(c):
        sheet[row][col] = l[col]
    
for row in range(r):
    for col in range(c):
        sheet[row][c] += sheet[row][col]
        
for col in range(c):
    for row in range(r):
        sheet[r][col] += sheet[row][col]
    
for row in range(r):
    for col in range(c):
        sheet[r][c] += sheet[row][col]

for l in sheet:
    l = list(map(str, l))
    print(' '.join(l))

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

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

Solution (Python):
x, y =(int(a) for a in input().split())
w = [[] for j in range(x+1)]
for i in range(x):
    num = 0
    k = [int(a) for a in input().split()]
    for j in  range(len(k)):
        w[i].append(k[j])
        num += k[j]
    else:
        w[i].append(num)
for i in range(y + 1):
    e = 0
    for j in range(x):
        e += w[j][i]
    else:
        w[x].append(e)
for i in range(x+1):
    for j in range(y):
        print(w[i][j],end = " ")
    else:
        print(w[i][j+1])

Solution (Python):
a, b = map(int,input().split())
lst = []
for i in range(a):
  c = 0
  tmp = list(map(int, input().split()))
  for j in tmp:
    c += j
  tmp.append(c)
  lst.append(tmp)

last = []
for i in range(len(lst[0])):
  c = 0
  for ls in lst:
    c += ls[i]
  last.append(c)

lst.append(last)
for line in lst:
  print(' '.join(map(str, line)))

Solution (Python):
rc = input()
rc_list = rc.split(" ")
r = int(rc_list[0])
c = int(rc_list[1])
all_sum = 0
list = [[0 for l in range(c)] for m in range(r)]

for i in range(r):

    row = input()
    row_list = row.split(" ")
    tmp = 0
    row_ans = ""
    for j in range(c):
        list[i][j] = int(row_list[j])
    for k in list[i]:
        tmp += k
        row_ans += str(k) + " "
    row_ans += str(tmp)
    print(row_ans)
    all_sum += tmp

column_list = ""
for m in range(c):
    column = 0
    for n in range(r):
        column += list[n][m]
    column_list += str(column) + " "
print(column_list + str(all_sum))

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

line = input().split()
r = int(line[0])
c = int(line[1])
val = [[0 for i in range(c+1)] for j in range(r+1)]
for i in range(r):
    line = input().split()
    for j in range(c):
        val[i][j] = int(line[j])

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

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

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

all_total = 0
col_total = [0]*w

for _ in range(h):
    nums = list(map(int, input().split()))
    row_total = sum(nums)
    col_total = list(map(sum, zip(nums, col_total)))
    all_total += row_total
    print(' '.join(map(str, nums+[row_total])))

print(' '.join(map(str, col_total+[all_total])))

Solution (Python):
r, c = map(int, input().split())
out = [[]] * (r + 1)
sumrow = [0 for i in range(c + 1)]
for line in range(0, r):
    vals = list(map(int, input().split()))
    vals.append(sum(vals))
    for itm in vals[:-1]:
        print(itm, end = ' ')
    print(vals[-1])
    for ids in range(c + 1):
        sumrow[ids] += vals[ids]
for itm in sumrow[:-1]:
    print(itm,end = ' ')
print(sumrow[-1])

Solution (Python):
a=list(map(int,input().split()))

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


for i in range(a[0]):
    values = list(map(int,input().split()))
    for j in range(a[1]):
        table[i][j] = values[j]


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

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

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

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

for i in range(r):
        sum = 0
        list = input().split()
        for j in range(c):
                a[i][j] = int(list[j])
                sum += a[i][j]
        a[i][c] = sum

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

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

Solution (Python):
r, c = map(int, input().split())
table = []
for x in range(r):
    tmplist = list(map(int, input().split()))
    sum = 0
    for y in tmplist:
        sum += y
    tmplist.append(sum)
    table.append(tmplist)

sumlist = []
for y in range(c + 1):
    sum = 0
    for x in range(r):
        sum += table[x][y]
    sumlist.append(sum)
table.append(sumlist)

for x in table:
    string = ""
    flag = False
    for y in x:
        if flag:
            string += " "
        else:
            flag = True
        string += str(y)
    print(string)

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 = map(int, input().split())
a = [[0] * c for i in range(r + 1)]
for i in range(r):
	a[i] = list(map(int, input().split()))
for j in range(c):
	for i in range(r):
		a[r][j] += a[i][j]
for i in range(r + 1):
	m = 0
	for j in range(c):
		m += a[i][j]
		print(a[i][j], end=" ")
	print(m)

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

spreadSheet = [list(map(int, input().split())) for x in range(r)]
for row in range(r):
    spreadSheet[row].append(sum(spreadSheet[row]))

finalRow = []

for col in range(c + 1):
    sumCol = 0
    for row in range(r):
        sumCol += spreadSheet[row][col]
    finalRow.append(sumCol)

spreadSheet.append(finalRow)

for row in range(r + 1):
    print(*spreadSheet[row])

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

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):
    a = list(map(int,input().split()))
    for col in range(W):
        table[row][col]= a[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())
mtx = [[int(i) for i in input().split()] for j in range(r)]
for m in mtx:
    m.append(sum(m))
    print(' '.join(list(map(str, m))))
print(' '.join(list(map(str, [sum([j[i] for j in mtx]) for i in range(c + 1)]))))

Solution (Python):
r,c=map(int,input().split())
a=[];s=[0]*(c+1)
for _ in [0]*r:a+=[list(map(int,input().split()))];a[-1]+=[sum(a[-1])];s=[x+y for x,y in zip(s,a[-1])]
for b in a+[s]:print(*b)

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