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

sum_line = [0 for i in range(c + 1)] 
for line in ss:
	for i in range(c + 1):
		sum_line[i] += line[i]
ss.append(sum_line)

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

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

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

col_sum = [0] * (c+1)
for i in range(r):
    row = map(int, raw_input().split())
    row.append(sum(row))
    col_sum = [a + b for a, b in zip(row, col_sum)]
    
    print " ".join(map(str, row))
    
print " ".join(map(str, col_sum))

Solution (Python):
r,c = [int(x) for x in input().split()]
sheet =[[int(x) for x in input().split()] for y in range(r)]
col_sum = [0]*c
for i in sheet:
    print(" ".join(map(str,i))+" "+str(sum(i)))
    for j in range(c):
        col_sum[j] += i[j]

print(" ".join(map(str,col_sum))+" "+str(sum(col_sum)))

Solution (Python):
h, w = [int(i) for i in input().split()]
date = [[int(q) for q in input().split()] for e in range(h)]
date2=[]
date3=[]
for r in range(0, h):
    for t in range(0, w):
        print(date[r][t], end=' ')
    print(sum(date[r]))

for k in range(0,w):
   for j in range(0,h):
      date2.append(date[j][k])

for n in range(0,w*h,h):
   print(sum(date2[n:(n+h)]),end=' ')

for m in range(h):
   date3.append(sum(date[m]))
print(sum(date3))

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

data = []
sum_row = [0] * (c + 1)

for ri in range(r):
    data.append([int(i) for i in input().split()])
    data[ri].append(sum(data[ri]))
    print(" ".join([str(d) for d in data[ri]]))
    for ci in range(c + 1):
        sum_row[ci] += data[ri][ci]

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

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

data = []
sum_row = [0] * (c + 1)

for ri in range(r):
    data.append([int(i) for i in input().split()])
    data[ri].append(sum(data[ri]))
    print(" ".join([str(d) for d in data[ri]]))
    for ci in range(c + 1):
        sum_row[ci] += data[ri][ci]

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

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

data=[]
sum_row =[0]*(c+1)

for ri in range(r):
    data.append([int(i) for i in input().split()])
    data[ri].append(sum(data[ri]))
    print(" ".join([str(d) for d in data[ri]]))
    for ci in range(c+1):
        sum_row[ci] += data[ri][ci]

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

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

data = []
sum_row = [0] * (c + 1)

for ri in range(r):
    data.append([int(i) for i in input().split()])
    data[ri].append(sum(data[ri]))
    print(" ".join([str(d) for d in data[ri]]))
    for ci in range(c + 1):
        sum_row[ci] += data[ri][ci]

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

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

data = []
sum_row = [0] * (c + 1)

for ri in range(r):
    data.append([int(i) for i in input().split()])
    data[ri].append(sum(data[ri]))
    print(" ".join([str(d) for d in data[ri]]))
    for ci in range(c + 1):
        sum_row[ci] += data[ri][ci]

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

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

date =[]
sum_row = [0] * (c + 1)

for ri in range(r):
    date.append([int(i) for i in input().split()])
    date[ri].append(sum(date[ri]))
    print(" ".join([str(d) for d in date[ri]]))
    for ci in range(c + 1):
        sum_row[ci] += date[ri][ci]

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

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

data = []
sum_row = [0] * (c + 1)

for ri in range(r):
    data.append([int(i) for i in input().split()])
    data[ri].append(sum(data[ri]))
    print(" ".join([str(d) for d in data[ri]]))
    for ci in range(c + 1):
        sum_row[ci] += data[ri][ci]

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

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

data = []
sum_row = [0] * (c + 1)

for ri in range(r):
    data.append([int(i) for i in input().split()])
    data[ri].append(sum(data[ri]))
    print(" ".join([str(d) for d in data[ri]]))
    for ci in range(c + 1):
        sum_row[ci] += data[ri][ci]

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

Solution (Python):
r, c =[int(i) for i in input().split()]
 
date =[]
sum_row = [0] * (c + 1)
 
for ri in range(r):
    date.append([int(i) for i in input().split()])
    date[ri].append(sum(date[ri]))
    print(" ".join([str(d) for d in date[ri]]))
    for ci in range(c + 1):
        sum_row[ci] += date[ri][ci]
 
print(" ".join([str(s) for s in sum_row]))

Solution (Python):
r, c = [int(i) for i in input().split()]
 
data = []
sum_row = [0] * (c + 1)
 
for ri in range(r):
    data.append([int(i) for i in input().split()])
    data[ri].append(sum(data[ri]))
    print(" ".join([str(d) for d in data[ri]]))
    for ci in range(c + 1):
        sum_row[ci] += data[ri][ci]
 
print(" ".join([str(s) for s in sum_row]))

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

data = []
sum_row = [0] * (c + 1)

for ri in range(r):
    data.append([int(i) for i in input().split()])
    data[ri].append(sum(data[ri]))
    print(" ".join([str(d) for d in data[ri]]))
    for ci in range(c + 1):
        sum_row[ci] += data[ri][ci]
        
print(" ".join([str(s) for s in sum_row]))

Solution (Python):
(r, c) = [int(i) for i in input().split()]
src = []
for _ in range(r):
    row = [int(i) for i in input().split()]
    row.append(sum(row))
    src.append(row)
 
last_row = [0 for _ in range(c + 1)]
for rc in range(r):
    for cc in range(c+1):
        last_row[cc] += src[rc][cc]
 
src.append(last_row)
 
 
for rc in range(r + 1):
    print(' '.join([str(a) for a in src[rc]]))

Solution (Python):
r, c = [int(i) for i in input().split()]
 
data = []
sum_row = [0] * (c + 1)
 
for ri in range(r):
    data.append([int(i) for i in input().split()])
    data[ri].append(sum(data[ri]))
    print(" ".join([str(d) for d in data[ri]]))
    for ci in range(c + 1):
        sum_row[ci] += data[ri][ci]
 
print(" ".join([str(s) for s in sum_row]))

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

data = []
sum_row = [0] * (c + 1)

for ri in range(r):
    data.append([int(i) for i in input().split()])
    data[ri].append(sum(data[ri]))
    print(" ".join([str(d) for d in data[ri]]))
    for ci in range(c + 1):
        sum_row[ci] += data[ri][ci]
print(" ".join([str(s) for s in sum_row]))

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

data = []
sum_row = [0] * (c + 1)

for ri in range(r):
    data.append([int(i) for i in input().split()])
    data[ri].append(sum(data[ri]))
    print(" ".join([str(d) for d in data[ri]]))
    for ci in range(c + 1):
        sum_row[ci] += data[ri][ci]

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

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

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

erow = [0 for i in range(c + 1)]
for row1 in rows:
    print(" ".join(str(s) for s in row1))
    for i in range(c + 1):
        erow[i] += row1[i]

print(" ".join(str(s) for s in erow))

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

for i in range(n):
	li[i].append(sum(li[i]))

for j in range(m+1):
	t = 0
	for i in range(n):
		t += li[i][j]
	c.append(t)
li.append(c)

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

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

for i in range(r):
    row = [int(i) for i in input().split()]
    row.append(sum(row))
    array.append(row)
    print(*row)

last_array = []
for i in range(c+1):
    total = 0
    for a in array:
        total += a[i]
    last_array.append(total)
print(*last_array)

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

data = []
sum_row = [0]*(c+1)

for ri in range(r):
    data.append([int(i) for i in input().split()])
    data[ri].append(sum(data[ri]))
    print(" ".join([str(d) for d in data[ri]]))
    for ci in range(c+1):
        sum_row[ci] += data[ri][ci]
print(" ".join([str(s) for s in sum_row]))

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 = [int(x) for x in input().split()]
a = [[int(x) for x in input().split()] for y in range(r)]
b = []

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

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

b.append(sum(b))
a.append(b)

for i in a:
    i = [str(x) for x in i]
    print(' '.join(i))

Solution (Python):
r, c = map(int, input().split())
data = [list(map(int, input().split())) for i in range(r)]
for i in range(r):
    data[i].append(sum(data[i]))
data.append([sum(data[j][i] for j in range(r)) for i in range(c + 1)])
for i in range(r + 1):
    for j in range(c + 1):
        print(data[i][j], end='')
        if j != c:
            print(' ', end='')
    print('')

Solution (Python):
RC = input().split()
r = int(RC[0])
c = int(RC[1])
A_c_sum =[]
final_sum = 0
for j in range(c):
    A_c_sum.append(0)
for i in range(r):
    A_r = input().split()
    A_r_sum = 0
    for j in range(c):
        A_c_sum[j] += int(A_r[j])
        print(A_r[j]+" ", end="")
        A_r_sum += int(A_r[j])
    print(A_r_sum)
    final_sum += A_r_sum
print(" ".join(map(str,A_c_sum))+" ",end="")
print(final_sum)

Solution (Python):

r, c = map(int, raw_input().split())
cl= [0] * c
for i in xrange(r):
	t = map(int, raw_input().split())
	for i, a in enumerate(t):
		print a,
		cl[i] += a
	print sum(t)

for a in cl: print a,
print sum(cl)

Solution (Python):

r, c = map(int, raw_input().split())
cl= [0] * c
for i in xrange(r):
	t = map(int, raw_input().split())
	for i, a in enumerate(t): cl[i] += a
	print ' '.join(map(str, t)), sum(t)
print ' '.join(map(str, cl)), sum(cl)

Solution (Python):
import sys

def main():
    row, col = sys.stdin.readline().strip().split(' ')
    row = int(row)
    col = int(col)

    row_sums = []
    for _ in range(row):
        row_sums.append(0)

    col_sums = []
    for i in range(col):
        col_sums.append(0)
        
    for i in range(row):
        line = sys.stdin.readline().strip()
        data = [int(i) for i in line.split(' ')]

        for j in range(col):
            row_sums[i] += data[j]
            col_sums[j] += data[j]
            
        print(line, row_sums[i])

    sum = 0
    for i in range(col):
        print('{} '.format(col_sums[i]), end='')
        sum += col_sums[i]
        
    print(sum)
    
if __name__ == '__main__':
    main()

Solution (Python):
r, c = list(map(int,input().split()))
S = [map(int,input().split()) for i in range(r)]
col_sum = [0 for i in range(c)];
for row in S:
    row = list(row)
    print(' '.join(map(str,row)) + ' {}'.format(sum(row)))
    col_sum = [x + y for (x,y) in zip(col_sum,row)]
print(' '.join(map(str,col_sum)) + ' {}'.format(sum(col_sum)))

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

data = [0 for i in range(r)]
temp = [0 for i in range(c)]

for i in range(r):
    data[i] = map(int, raw_input().split())
    
for i in range(r):
    data[i].append(0)
    data[i][c] = sum(data[i])
for i in range(c):
    for j in range(r):
        temp[i] += data[j][i]
temp.append(sum(temp))
data.append(temp)

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

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

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

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

for i in range(r+1):
    print(" ".join(str(t) for t in a[i]))

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

for x in range(r):
 mat.append(list(map(int, input().split())))

tsum = 0

for x in range(r):
 rsum = 0
 for y in range(c):
  rsum += mat[x][y]
  tsum == mat[x][y]
 mat[x].append(rsum)

mat.append([])

for x in range(c):
 csum = 0
 for y in range(r):
  csum += mat[y][x]
  tsum += mat[y][x]
 mat[r].append(csum)



for x in range(r):
 for y in range(c):
  print("{0} ".format(mat[x][y]), end = '')
 print(mat[x][c])

for x in range(c):
 print("{0} ".format(mat[r][x]), end='')
print(tsum)

Solution (Python):
size = list(map(int, input().split()))
sheet = []

for i in range(size[0]):
    value = list(map(int, input().split()))
    sheet.extend(value)
    sheet.append(sum(value))

for i in range(size[1]+1):
    
    point = i
    vsum = 0
    
    for j in range(size[0]):
        vsum += sheet[point]
        point += size[1] +1
    sheet.append(vsum)
    
for i in range(len(sheet)):
    if (i+1) % (size[1]+1)  == 0:
        print(sheet[i])
    else:
        print(str(sheet[i])+" ", end="")

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

a = [0 for j in range(c)]

matrix.append(a)

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

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

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

for i in range(r):
    for j in range(c):
        print matrix[i][j],
    print matrix[i][c]

for j in range(c + 1):
    print matrix[r][j],

Solution (Python):
import sys

a = []

n, m = map(int, input().split())
for i in range(n):
    ai = list(map(int, input().split()))
    ai.append(sum(ai))
    a.append(ai)

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

ai = []
for j in range(m + 1):
    s = 0
    for i in range(n):
        s += a[i][j]
    ai.append(s)

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

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

Solution (Python):
r, c = map(int, input().split())
a = [0]*(c+1)
for _ in range(r):
    v = list(map(int, input().split()))
    s = 0
    for i, e in enumerate(v):
        s+=e
        a[i]+=e
    v.append(s)
    print(*v)
    a[-1]+=s
print(*a)

Solution (Python):
r, c = map(int, input().split())
hyou = []
tate_sum = [0] * (c + 1)
for i in range(r):
    line = list(map(int, input().split()))
    line.append(sum(line))
    tate_sum = [tate_sum[j] + line[j] for j in range(len(line))]
    line = map(str, line)
    hyou.append(" ".join(line))
    
tate_sum = map(str, tate_sum)
hyou.append(" ".join(tate_sum))
print("\n".join(hyou))

Solution (Python):
r, c = map(int, input().split())
hyou = []
tate_sum = [0] * (c + 1)
for i in range(r):
    line = list(map(int, input().split()))
    line.append(sum(line))
    tate_sum = [tate_sum[j] + line[j] for j in range(len(line))]
    hyou.append(" ".join(map(str, line)))
    
hyou.append(" ".join(map(str, tate_sum)))
print("\n".join(hyou))

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

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

A = []

counter = 0
while counter < r:
    raw = [int(x) for x in raw_input().split()]
    A.append(raw + [sum(raw)])
    counter += 1

A.append([sum([A[raw][col] for raw in range(r)]) for col in range(c + 1)])
for data in A:
    print(" ".join([str(x) for x in data]))

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

for tr in range(0,r):
    total = 0
    for v in a[tr]:
        total += v
    a[tr].append(total)

total = [0 for i in range(c+1)]
for tr in range(0,r):
    for tc in range(0,c+1):
        total[tc] += a[tr][tc]
a.append(total)

for i in range(r+1):
    a[i] = [str(a[i][j]) for j in range(c+1)]
    print(' '.join(a[i]))

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

ll = []

for _ in range(r):
  l =  [int(n) for n in input().split()]
  l.append(sum(l))
  ll.append(l)

l = [sum(_) for _ in zip(*ll)]
ll.append(l)

for l in ll:
  print(" ".join([str(_) for _ in l]))

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

"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_C

??¨?¨????
??¨?¨??????????????°???????????????°???????????????????????????
??¨????????°r??¨?????°c???r ?? c ???????´????????????¨?????????????????§???????????¨??????????¨?????????\????????°????????¨???????????????????????°?????????????????????????????????
"""

if __name__ == '__main__':
    
    size = [int(x) for x in input().split(' ')]
    row = size[0]
    column = size[1]
    data = []
    for r in range(row):
        current_row = [int(x) for x in input().split(' ')]
        assert(len(current_row) == column)
        data.append(current_row)

    
    for d in data:
        d.append(sum(d))
    
    totals = [0] * len(data[0])
    for line in data:
        for i, d in enumerate(line):
            totals[i] += d
    data.append(totals)

    
    for line in data:
        print(' '.join(map(str, line)))

Solution (Python):
def calcTotalOfRowAndCol(matrix, r, c):
    for l in matrix:
        total = 0
        for val in l:
            total += val
        l.append(total)
    matrix.append([])
    for i in range(c + 1):
        total = 0
        j = 0
        while j < r:
            total += matrix[j][i]
            j += 1
        matrix[r].insert(i, total)

    return matrix


if __name__ == '__main__':
    matrix = []
    row, col = [int(x) for x in input().split()]
    i = row
    while i > 0:
        matrix.append([int(y) for y in input().split()])
        i -= 1
    matrix2 = calcTotalOfRowAndCol(matrix, row, col)
    for l in matrix:
        print(' '.join(str(x) for x in l))

Solution (Python):
def calcTotalOfRowAndCol(matrix, r, c):
    for l in matrix:
        total = 0
        for val in l:
            total += val
        l.append(total)
    matrix.append([])
    for i in range(c + 1):
        total = 0
        j = 0
        while j < r:
            total += matrix[j][i]
            j += 1
        matrix[r].insert(i, total)

if __name__ == '__main__':
    matrix = []
    row, col = [int(x) for x in input().split()]
    i = row
    while i > 0:
        matrix.append([int(y) for y in input().split()])
        i -= 1
    calcTotalOfRowAndCol(matrix, row, col)
    for l in matrix:
        print(' '.join(str(x) for x in l))

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

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

for i in l:
	print(" ".join(list(map(str,i))))

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

Solution (Python):


n, m = map(int, input().split())
total = [0] * m

for i in range(n+1):
    if i < n:
        line = [int(j) for j in input().split()]
        print(" ".join([str(k) for k in line]),sum(line))
        total = [total[i] + line[i] for i in range(m)]
    else:
        print(" ".join([str(k) for k in total]),sum(total))

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

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

for i in range(n):
    s = 0
    for j in range(m):
        s += a[i][j]
        print(str(a[i][j]) + " ",end='')
    print(s)

t = []
for j in range(m):
    u = 0
    for i in range(n):
        u += a[i][j]
    t.append(u)

for j in range(m):
    print(str(t[j]) + " ",end='')
print(sum(t))

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

a = [0]*r

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

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

table = list()

for i in range(r):

    table.append(list())
    table[i] = list(map(int, input().split(" ")))

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

table.append(list())

for i in range(r):
    print(" ".join([str(x) for x in table[i]]))

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

print(" ".join([str(x) for x in table[r]]))

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

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

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

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

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):
n,m=map(int,input().split())
a = []
for i in range(n):
    a+=[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):
'''
ITP-1_7-C
 ??¨?¨????
??¨?¨??????????????°???????????????°???????????????????????????
??¨????????°r??¨?????°c???r ?? c ???????´????????????¨?????????????????§???????????¨??????????¨?????????\????????°????????¨???????????????
????????°?????????????????????????????????
???Input
???????????????r??¨c????????????????????§??????????????????????¶????r??????????????????c????????´??°????????????????????§?????????????????????
???Output
(r+1) ?? (c+1) ?????°????????¨??????????????????????????????????????£???????????´??°????????????????????§????????£???????????????
???????????????????????¨??????????????????????¨?????????????????????????????????¨??????????????????????¨??????????
???????????????????????¨??¨??????????¨????????????\??????????????????
'''

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

for row in data:
    row.append(sum(row))
    print(*row)


columnSum = [sum(Column) for Column in zip(*data)]
print(*columnSum)

Solution (Python):
import sys

lines = [list(map(int,line.split())) for line in sys.stdin]
r,c = lines[0]

lines = lines[1:]
for i,row in enumerate(lines):
    lines[i].append(sum(row))

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

for l in lines:
    print(" ".join(map(str,l)))

Solution (Python):
import sys


fin = sys.stdin

[r, c] = list(map(int, fin.readline().split()))

sum_col = [0 for i in range(c + 1)]

for i in range(r):
	input_list = list(map(int, fin.readline().split()))
	for j in range(c):
		sum_col[j] += input_list[j]
		print(input_list[j], end = " ")


	s = sum(input_list)

	sum_col[c] += s
	print(s)

for i in range(c):
	print(sum_col[i], end = " ")

print(sum_col[c])

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

Solution (Python):
import sys
r,c = map(int,raw_input().split())
col_sum=[0]*c
for  i in range(r):
    row=map(int,raw_input().split())
    row.append(sum(row))
    for j in range (c):
        col_sum[j] += row[j]
    print ' '.join(map(str,row))
for i in range(c):
    print col_sum[i],
print sum(col_sum)

Solution (Python):


import sys


def main():
    r, c = [int(row_col) for row_col in sys.stdin.readline().split()]
    sheet = [
                [int(row_num) for row_num in sys.stdin.readline().split()]
                for row in range(r)
            ]

    sheet.append([0 for col in range(c)])

    for row in range(len(sheet)-1):
        for col in range(len(sheet[0])):
            sheet[-1][col] += sheet[row][col]

    for row in sheet:
        row.append(sum(row))
        print(*row)


if __name__ == '__main__':
    main()

Solution (Python):


import sys


def generate_default_spreadsheet():
    r, c = [int(row_col) for row_col in sys.stdin.readline().split()]
    sheet = [
                [int(row_num) for row_num in sys.stdin.readline().split()]
                for row in range(r)
            ]
    return c, sheet


def generate_spreadsheet_with_sums():
    orig_total_col, sheet_with_sums = generate_default_spreadsheet()

    sheet_with_sums.append([0 for col in range(orig_total_col)])

    for row in range(len(sheet_with_sums)-1):
        for col in range(len(sheet_with_sums[0])):
            sheet_with_sums[-1][col] += sheet_with_sums[row][col]

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

    return sheet_with_sums


def print_summed_spreadsheet():
    sheet_with_sums = generate_spreadsheet_with_sums()
    [print(*row) for row in sheet_with_sums]


def main():
    print_summed_spreadsheet()


if __name__ == '__main__':
    main()

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

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

for j in range(r):
	rS = sum(Tbl[j])
	Tbl[j].append(rS)

cS =[]
for k in range(c+1):
	s = 0
	for l in range(r):
		s += Tbl[l][k]
	cS.append(s)

Tbl.append(cS)

Tblp = [print(" ".join(map(str, Tbl[m]))) for m in range(r+1)]

Solution (Python):
r,c = map(int,input().split())
s_row = [0 for i in range(c+1)]
for i in range(r):
    row = [int(i) for i 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())
A = []
for i in range(r):
    a = [int(j) for j in input().split()]
    A.append(a)

for i in range(r):
    s = 0
    for k in A[i]:
        s += k
    A[i].append(s)

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

for i in range(r+1):
    print(" ".join(str(a) for a in A[i]))

Solution (Python):
max_row, max_col = map(int, input().split(" "))
rows = [[0 for i in range(max_col)] for j in range(max_row)]
row = ""

for i in range(max_row):
    row =  input().split(" ")
    total_row = 0
    for j in range(max_col):
        rows[i][j] = int(row[j])
        total_row = total_row + int(row[j])
    rows[i].append(total_row)
    

total = [0 for i in range(max_col+1)]
for m in range(max_col+1):
    for n in range(max_row):
        total[m] = total[m] + rows[n][m]
rows.append(total)


for i in range(max_row+1):
    out_str = ""
    for j in range(max_col+1):    
        out_str = out_str + " " + str(rows[i][j]) 
    
    print(out_str.strip())

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

for i in range(r+1):
    print(' '.join(str(x) for x in a[i]))

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

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

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

for i in I:
    i = map(str, i)
    print(" ".join(i))

Solution (Python):
row_c, col_c = [int(x) for x in input().split(" ")]

nums =[]
col_sums = []
for i in range(row_c):
    nums.append([int(x) for x in input().split(" ")])


for i in range(col_c):
    s = 0
    for n in nums:
        s += n[i]
    col_sums.append(s)
col_sums.append(sum(col_sums))


for i, num in enumerate(nums):
    nums[i].append(sum(num))


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

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

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

for i in range(r):
	sheet[i] = input().split()
	k = 0
	for j in range(c):
		k += int(sheet[i][j])
	sheet[i].append(k)
	
l=[0 for i in range (c+1)]
for j in range(c+1):
	for i in range(r):
		l[j] += int(sheet[i][j])
		
sheet.append(l)

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