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())
s=[0]*(c+1)

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

Solution (Python):
a, b = list(map(int, input().split()))
e=[0]*(b+1) 

for x in range(a):
    c=list(map(int, input().split()))
    d=0 
    for y in range(b):
        d+=c[y]
        e[y]+=c[y]
    c.append(d)
    e[b]+=c[b]
    print(*c)
print(*e)

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

for _ in range(r):
    t.append(list(map(int, input().split())))

sum_cols = []
for col in range(c):
    sum_col = 0
    for row in range(r):
        sum_col += t[row][col]
    sum_cols.append(sum_col)
t.append(sum_cols)

for row in range(r+1):
    t[row].append(sum(t[row]))

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

Solution (Python):
def row_sum(list):
    sum = 0
    for i in range(len(list)):
        sum += list[i]
    return sum

def column_sum(list, stop):
    sum = []
    for i in range(stop):
        temp_sum = 0
        for j in range(len(list)):
            temp_sum += list[j][i]
        sum.append(temp_sum)
    return(sum)

def answer(list, stop):
    list.append(column_sum(list, stop))
    for i in list:
        i.append(row_sum(i))
    return list

def print_list_list(list):
    for i in list:
        print(i[0],end="")
        for j in range(1, len(i)):
            print(" ", end="")
            print(i[j],end="")
        print()

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

ans = answer(a, c)
print_list_list(ans)

Solution (Python):
r, c = map(int, input().split())
list_gyouretsu = []
list_last_gyou = []
for i in range(r):
  list_gyou = list(map(int, input().split()))
  list_gyouretsu.append(list_gyou)
  list_gyouretsu[-1].append(sum(list_gyou))
for j in range(c+1):
  sum = 0
  for k in range(r):
    sum += list_gyouretsu[k][j]
  list_last_gyou.append(sum)
list_gyouretsu.append(list_last_gyou)
for l in range(r+1):
  print(" ".join(map(str, list_gyouretsu[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):
n_row, n_col = map(int, input().split(" "))
list_list_n = []
for i in range(n_row):
    list_list_n.append([int(_) for _ in map(int, input().split())])
    list_list_n[i].append(sum(list_list_n[i]))


list_sum = [0 for _ in range(n_col + 1)]
for list_n in list_list_n:
    for i, num in enumerate(list_n):
        if i == len(list_n) - 1:
            print(num, end="")
        else:
            print(num, end=" ")
        list_sum[i] += num
    print()

for j, sum_n in enumerate(list_sum):
    if j == len(list_sum) - 1:
        print(sum_n, end="")
    else:
        print(sum_n, end=" ")
print()

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

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

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

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

m = m+[l]


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

Solution (Python):
R, C = [int(n) for n in input().split()]
c_sum = [0]*C
for i in range(R):
  r = [int(n) for n in input().split()]
  for j in range(C):
    c_sum[j] += r[j]
  print(*(r + [sum(r)]))
print(*(c_sum + [sum(c_sum)]))

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



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


for a in a:
    print(*a)

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

for i in range(r):
    l = m[i]
    l.append(sum(l))
    print(' '.join(map(str, l)))

ll = []
for k in range(c+1):
    s = 0
    for j in range(r):
        s += m[j][k]
    ll.append(s)
print(' '.join(map(str, ll)))

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):
a,b = map(int, input().split(' '))
c = []
for i in range(a):
    d = list(map(int, input().split(' ')))
    ty = 0
    for j in d:
        ty = ty + j
    d.append(ty)
    c.append(d)
tt = 0
e = []
for i in range(b + 1):
    for j in range(a):
        tt = tt + c[j][i]
    e.append(tt)
    tt = 0
c.append(e)
for i in range(a + 1):
    print(' ' .join(map(str,c[i])))

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

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

    print(*l)
print(*under)

Solution (Python):



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

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

Solution (Python):
r,c = map(int,input().split(" "))
sumall = [0]*(c+1)
for i in range(r):
    x = list(map(int,input().split(" ")))
    sumx = sum(x)
    for j in range(c):
        sumall[j] += x[j]
        
    sumall[c] += sumx
    newl = " ".join(map(str,x))
    print(newl + " " + str(sumx))
lastl = " ".join(map(str,sumall))
print(lastl)

Solution (Python):
h,w=map(int,input().split())
z=[0]*(w+1)
for i in range(h):
    a=list(map(int,input().split()))
    a.append(sum(a))
    for y in range(w+1):
      z[y]+=a[y]
    x=''
    for j in a:
        x+=str(j)
        x+=' '
    x=x[:-1]
    print(x)
t=''
for s in z:
        t+=str(s)
        t+=' '
t=t[:-1]
print(t)

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

for l in range(line):
    work = list(map(int, input().split()))
    for r in range(row):
        table[l][r] = work[r]

for l in range(line):
    for r in range(row):
        table[l][row] += table[l][r]

for r in range(row + 1):
    for l in range(line):
        table[line][r] += table[l][r]

for l in range(line + 1):
    print('{}'.format(table[l][0]), end='')
    for r in range(1, row + 1):
        print(' {}'.format(table[l][r]), end='')
    print()

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

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

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

a = list(zip(*a))

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

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

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

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

s = map(sum, list(zip(*a)))
print(*s)

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

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

for line in arr:
    print(*line)

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

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

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

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

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

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

for i in range(r):
    l = list(map(int, input().split()))
    for j in range(c):
        rc_t[i][j] = l[j]
        rc_t[i][c]+=l[j]
        rc_t[r][j]+=l[j]
        rc_t[r][c]+=l[j]
for i in rc_t:
    for x,j in enumerate(i):
        print(f'{j}', end='')
        if x != c:
            print(' ', end='')
    print()

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

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

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

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

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

for i in range(r):
    print(*x[i])
print(*y)

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):
  for j in range(c):
    print(table[i][j], end = ' ')
  print(sum(table[i]))
for j in range(c):
  print(sum([table[i][j] for i in range(r)]), end = ' ')
print(sum([table[i][j] for i in range(r) for j in range(c)]))

Solution (Python):

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

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

for i in range(c):
    for j in range(r):
        lst[-1][i] += lst[j][i]
        
for i in range(r+1):
    for j in range(c):
        lst[i][-1] += lst[i][j]
        
for i in lst:
    print(*i)

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

arr = [input().split() for l in range(r)]

lastans = 0
for a in arr:
    ans = 0
    answord = ""
    for num in a:
        answord += num
        answord += " "
        ans += int(num)
    lastans += ans
    answord += str(ans)
    print(answord)

lastansword = ""
for i in range(c):
    ans = 0
    for j in range(r):
        ans += int(arr[j][i])
    lastansword += str(ans)
    lastansword += " "
lastansword += str(lastans)
print(lastansword)

Solution (Python):
rows, cols = (int(x) for x in input().split())

table = []
for r in range(rows):
    line = input().split()
    row = [int(x) for x in line]
    table.append(row)

final_row = [0] * (cols + 1)
for r in range(rows):
    table[r].append(sum(table[r]))
    for c in range(cols + 1):
        final_row[c] += table[r][c]
table.append(final_row)

for r in range(rows+1):
    line = ""
    for c in range(cols+1):
        line += str(table[r][c]) + " "
    print(line.strip())

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

tmp = 0
sum = 0
while(tmp < c+1):
  for i in range(r):
    sum += table[i][tmp]
  if tmp == c:
    print(sum,end ="")
  else:
    print(sum,end =" ")
  sum = 0

  tmp += 1
print()

Solution (Python):
r,c=map(int,input().split())
lst=[]
for i in range(r):
    lst.append(list(map(int,input().split())))
for j in range(r):
    a=0
    for k in range(c):
        a+=lst[j][k]
    lst[j].append(a)
lst2=[]
for l in range(c+1):
    b=0
    for n in range(r):
        b+=lst[n][l]
    lst2.append(b)
lst.append(lst2)

for m in range(r+1):
    for o in range(c+1):
        if o==c:
            print(lst[m][o])
        else:
            print(lst[m][o],end=" ")

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

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

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

data.append([])

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

for li_int in data:
  li = [str(a) for a in li_int]
  li = ' '.join(li)
  print(li)

Solution (Python):
import sys

input = sys.stdin.readline

def main():
    a,b = map(int, input().split())
    s = []
    for i in range(a):
        temp = list(map(int, input().split()))
        s.append(temp)
    for i in range(a):
        temp_sum = sum(s[i])
        s[i].extend([temp_sum])
        print(*s[i])
    last = []
    temp_sum = 0
    for i in range(b+1):
        temp_sum = 0
        for k in range(a):
            temp_sum += s[k][i]
        last.append(temp_sum)
    print(*last)
    
if __name__ == "__main__":
    main()

Solution (Python):
a = []
b = []

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

for i in range(c):
    x=0
    for i2 in range(r):
        x += a[i2][i]
    b.append(x)
a.extend([b])

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

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

a = [0 for i in range(r)] 

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

b = []

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

print(*b)

Solution (Python):
r,c=map(int,input().split())
x=[]
for i in range(r):
    x.append(list(map(int,input().split())))
    x[i].append(sum(x[i]))
    print(" ".join(list(map(str,x[i]))))
y=[]

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

Solution (Python):

def run():
    row,col=tuple(map(int,input().split()))
    
    A=[]
    
    for i in range(row):
        row_ls=list(map(int,input().split()))
        
        row_sum=sum(row_ls)
        
        A.append(row_ls+[row_sum])
        
    
    col_sum=[0 for i in range(col+1)]
    
    for j in range(col+1):
        for i in range(row):
            col_sum[j]+=A[i][j]
            
    A.append(col_sum)
    
    for i in range(row+1):
        for j in range(col+1):
            if j!=col:
                print(f"{A[i][j]} ",end="")
            else:
                print(f"{A[i][j]}")
                
run()

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


for i,x in enumerate(rows):
	_sum_=sum(x)
	rows[i].append(_sum_)



sums=[]
for i in range(len(rows[0])):
	_sum_=0
	for x in rows:
		_sum_+=x[i]
	sums.append(_sum_)

rows.append(sums)

for i in rows:
	for s,j in enumerate(i):
		print(f"{j}",end="")
		if s!=len(i)-1:
			print(" ",end="")

	print()

Solution (Python):
n, m = map(int, input().split())
sum_n = [0] * m
sum = 0
for i in range(n) :
    lst = list(map(int, input().split()))
    sum_m = 0
    for j in range(m) :
        print(lst[j], end=" ")
        sum_m += lst[j]
        sum_n[j] += lst[j]
    print(sum_m)
    sum += sum_m
for i in range(m) :
    print(sum_n[i], end=" ")
print(sum)

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

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

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

l = []
x = 0
for j in range(c):
    x = 0
    for k in range(r) :
        x += hyo[k][j]
    l.append(x)
l.append(sum(l))

for i in range(r):
    print(*hyo[i])
print(*l)

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

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

row = []

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

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

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

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

for x in range(r):
    print(*table[x],end=" ")
    print(sum(table[x]))

st = 0
for x in range(c):
    s = 0
    for y in range(r):
        s += table[y][x]
    print(s, end = " ")
    st += s
print(st)

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

table.append([0 for _ in range(c+1)])

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

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

Solution (Python):




n, m = map(int, input().split())
A = [[0 for j in range(m)] for i in range(n)]

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

S = [0 for j in range(m)]
c = 0
for i in range(n):
   for j in range(m):
      print(A[i][j], end = "")
      print(" ", end = "")
   print(sum(A[i]))
   c += sum(A[i])

for j in range(m):
   sum = 0
   for i in range(n):
      sum += A[i][j]
   print(sum, end = "")
   print(" ", end = "")
print(c)

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

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

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

ans = [[0 for i in range(c+1)] for j in range(r+1)]
for i in range(r):
    for j in range(c):
        ans[i][j] = M[i][j]
        
for j in range(c):
    ans[r][j] = sum([ans[i][j] for i in range(r)])
    
for i in range(r+1):
    ans[i][c] = sum([ans[i][j] for j in range(c)])
    
for i in range(r+1):
    print(*ans[i])

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

idxr = 0
R = []

while idxr <= r - 1:
    R.append(list(map(int,input().split())))
    idxr += 1

for rr in R:
    print(*rr, sum(rr))

RR = []

for idxc in range(c):
    T = 0
    for rrr in R:
        T += rrr[idxc]
    RR.append(T)

print(*RR,sum(RR))

Solution (Python):

r, c = map(int, input().split())
d = [0] * c

for _ in range(r):
    a = input()
    b = list(map(int, a.split()))
    e = sum(b)
    a += ' {}'.format(e)
    print(a)
    d = [d[i] + b[i] for i in range(c)]

d = list(map(int, d))
g = sum(d)
f = ''
for i in d:
    f += str(i) + ' '
f += str(g)
print(f)

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())
arr = []
for _ in range(r):
    arr.append(list(map(int,input().split())))
for i in range(r):
    for j in range(c):
            print(arr[i][j],"",end="")
    print(sum(arr[i]),sep="")
bottom = []
for i in range(c):
    tmp = 0
    for j in range(r):
        tmp += arr[j][i]
    bottom.append(tmp)
for i in bottom:
    print(i,"",end = "")
print(sum(bottom))

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

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

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


data.append([])

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


for i in range(r+1):
    print(*data[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]))
last_row = []
for i in range(c + 1):
    tmp = 0
    for j in range(r):
        tmp += table[j][i]
    last_row.append(tmp)
table.append(last_row)

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

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

for i in range(a):
    s = sum(listA[i])
    listA[i].append(s)

for i in range(b):
    s = 0
    for j in range(a):
        s += listA[j][i]
    listA[a][i] = s

listA[a][b] = sum(listA[a])

for i in range(a+1):
    for j in range(b+1):
        if j == b:
            print(str(listA[i][j]))
        else:
            print(str(listA[i][j]) + ' ',end='')

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

matrix.append([])
for i in range(col):
  col_sum = 0
  for j in range(row):
    col_sum += matrix[j][i]
  matrix[row].append(col_sum)
matrix[row].append(sum(matrix[row]))

for i in range(row+1):
  strings = ''
  for j in range(col+1):
    strings += str(matrix[i][j]) + ' '
  print(strings[:-1])

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

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

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

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

for i in range(r):
    Lsum = sum(LIST[i])
    LIST[i].append(Lsum)

Listbo = []
for i in range(c+1):
    SUM = 0
    for j in range(r):
        L = LIST[j]
        SUM += L[i]
    Listbo.append(SUM)
LIST.append(Listbo)

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

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

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

for row in range(C):
    for col in range(0, R):
        T[row][R] += T[row][col]

for row in range(C):
    for col in range(0, R):
        T[C][col] += T[row][col]

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

for row in range(0, C+1):
    print("%d" % (T[row][0]), end="")
    for col in range(1, R+1):
        print(" %d" % (T[row][col]), end="")
    print()

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

for i in range(r):
    total = 0
    b = input().split()
    for j in b:
        total += int(j)
    b.append(total)
    a.append(b)
C = []
for i in range(c + 1):
    t = 0
    for j in range(r):
        t += int(a[j][i])
    C.append(t)
a.append(C)
for i in a:
    for j in range(len(i)):
        if j != len(i)-1:
            print(i[j], end =" ")
        else:
            print(i[j])

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

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

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

list.append([])

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


for a in list:
    for i in range(c+1):
        if i == c:
            print("{}".format(a[i]),end = "")
        else:
            print("{}".format(a[i]),end = " ")
    print()

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

num_list = []
for i in range(n):
    num_list.append(list(map(int,input().split())))
    
allpoint = 0
retu_point = []

for i in range(n):
    print(*num_list[i], end="")
    print(" ", end ="")
    print(sum(num_list[i]))
    

for i in range(m):
    tmp = 0
    for j in range(n):
        tmp += num_list[j][i]
        
    retu_point.append(tmp)
    
print(*retu_point, end ="")
print(" ", end ="")
print(sum(retu_point))

Solution (Python):
def main_v2():
    row, column = list(map(int, input().split()))
    lst = [[0 for _ in range(column + 1)] for _ in range(row + 1)]

    for i in range(row):
        tmp = list(map(int, input().split()))
        for j in range(column):
            lst[i][j] = tmp[j]
        lst[i][column] = sum(lst[i])

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

    for i in range(row + 1):
        print(lst[i][0], end="")
        for j in range(1, column + 1):
            print(f" {lst[i][j]}", end="")
        print()

    return 0


if __name__ == "__main__":
    main_v2()

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

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

table = []

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

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

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

for row in table:
    ans_row = " ".join(list(map(str,row)))
    print(ans_row)

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




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

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

sheet.append(sum_list)

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

Solution (Python):
n , k = map(int,input().split(' '))
s = [list(map(int,input().split(' '))) for i in range(n)]
x = [i*0 for i in range(k+1)]
s.append(x)
temp = 0
for i in range(n):
    ans = 0
    for v in range(k):
        ans += s[i][v]
        s[n][v] += s[i][v]
    s[i].append(ans)
    temp += ans
s[n][k] = temp
for i in s:
    print(*i)

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

col_sum = [0]*(c+1)
for col in range(c+1):
    for row in range(r):
        col_sum[col] += mat[row][col]
for row in range(r):
    print(' '.join(map(str,mat[row])))
print(' '.join(map(str,col_sum)))

Solution (Python):
r, c = [int(arg) for arg in input().split()]
table = [[int(arg) for arg in input().split()] for _ in range(r)]
new_row = [0] * (c+1)
for row in table:
    row.append(sum(row))
    for j, v in enumerate(row):
        new_row[j] += v
table.append(new_row)
for row in table:
    print(' '.join([str(i) for i in row]))

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

for i in range(r):
    row = list(map(int, input().split()))
    sheet.append(row)
    sheet[i].append(sum(sheet[i]))
    
sheet.append([sum(col) for col in zip(*tuple(sheet))])


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

Solution (Python):
r, c=(int(x) for x in input().split())
graph=[[int(x) for x in input().split()] for i in range(r)]
for i in range(r):
    sum=0
    for j in range(c):
        sum+=graph[i][j]
    graph[i].append(sum)
new=[]
for i in range(c+1):
    sum=0
    for j in range(r):
        sum+=graph[j][i]
    new.append(sum)
graph.append(new)
for i in range(r+1):
    for j in range(c+1):
        if j!=c:
            print(graph[i][j], end=" ")
        else:
            print(graph[i][j])