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 &times; 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) &times; (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



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

Submission status: Accepted

Solution code:
r,c=map(int,raw_input().split())
m=[]
ans=[]

for i in range(r):
	a=map(int,raw_input().split())
	m.append(a)
	sum=0
	for j in range(c):
		print(a[j]),
		sum+=a[j]
	print(sum)
total=0
for i in range(c):
	sum=0
	for j in range(r):
		sum+=m[j][i]
	print(sum),
	total+=sum
print(total)

Submission status: Accepted

Solution code:
import sys
import math

r, c = map(int, raw_input().split())
b = [0 for i in xrange(c+1)]

for i in xrange(r):
    a = map(int, raw_input().split())

    for j in xrange(c):
        b[j] += a[j]
        sys.stdout.write(str(a[j]) + " ")
    print sum(a)

    b[c] += sum(a)

for j in xrange(c+1):
    sys.stdout.write(str(b[j]))
    if j < c:
        sys.stdout.write(" ")
print

Submission status: Accepted

Solution code:
N = input().split()
r = int(N[0])
c = int(N[1])
d = [[0 for i in range(c)] for j in range(r)]
for i in range(r):
    data = input().split()
    for j in range(c):
        d[i][j] = int(data[j])
sum2 = [0 for i in range(c)]
for i in range(r):
    line = ''
    for j in range(c):
        line += str(d[i][j])
        line += ' '
        sum2[j] += d[i][j]
    line += str(sum(d[i]))
    print(line)
line2 = ''
for i in range(c):
    line2 += str(sum2[i])
    line2 += ' '
print('{0}{1}'.format(line2, sum(sum2)))

Submission status: Accepted

Solution code:
r,c = list(map(int,input().split()))
matrix = []
for i in range(r):
	matrix.append(list(map(int,input().split())))
	matrix[i].append(sum(matrix[i]))
add_list = []
for j in range(c+1):
	num = 0
	for k in range(r):
		num += matrix[k][j]
	add_list.append(num)
matrix.append(add_list)

for i in range(r+1):
	out = ''
	for m in matrix[i]:
		out += str(m) + ' '
	print(out[:-1])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
r,c = [int(a) for a in input().split(' ')]
arr = []
Hsum=0
for x in range(r):
    i =[int(a) for a in input().split(' ')]
    i.append(sum(i))
    arr.append(i)
arr2=[]
for y in range(c+1):
    for z in range(r):
        Hsum += arr[z][y]
    arr2.append(Hsum)
    Hsum=0
arr.append(arr2)

for y in range(r+1):
    for z in range(c+1):
        if z == c:
            print(arr[y][z])
        else:
            print(arr[y][z],end = " ")

Submission status: Accepted

Solution code:
k=map(int,raw_input().split(" "))
vec=k[0]
col=k[1]

omatrix=[]
for i in range(vec+1):
	omatrix+=[[0]*(col+1)]

for i in range(vec):
	ipt=map(int,raw_input().split(" "))
	for j in range(col):
		omatrix[i][j]+=ipt[j]

for i in range(vec):
	omatrix[i][col]+=sum(omatrix[i])


for j in range(col+1):
	vsum=0
	for i in range(vec):
		vsum+=omatrix[i][j]
	omatrix[vec][j]+=vsum


for i in range(vec+1):
	for j in range(col+1):
		if j==col:
			print omatrix[i][j]
		else:
			print omatrix[i][j],

Submission status: Accepted

Solution code:
rc=list(map(int,input().split()))
a=[[0 for x in range(rc[1]+1)]for x in range(rc[0]+1)]
for x in range(rc[0]):
    code=list(map(int,input().split()))
    result=0
    for y in range(rc[1]):
        a[x][y]=code[y]
        result+=code[y]
    a[x][rc[1]]=result

for y in range(rc[1]+1):
    result=0
    for x in range(rc[0]):
        result+=a[x][y]
    a[rc[0]][y]=result

for x in range(rc[0]+1):
    string=""
    for y in range(rc[1]+1):
        string+=str(a[x][y])
        if (y!=rc[1]):
            string+=" "
    print(string)

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
last_list = [0] * (c + 1)
for _ in range(r):
    n = 0
    x = input()
    sum_list = list(map(int, x.split()))
    for i in range(c):
        last_list[i] += sum_list[i]
        n += sum_list[i]
    print(x, n)

last_list[-1] = sum(last_list)
print(*last_list)

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
c = []
d = [0 for i in range(m+1)]
for i in range(n):
    arr = input().split()
    sum = 0
    for j in range(m):
        sum += int(arr[j])
        d[j] += int(arr[j])
    arr.append(sum)
    d[m] += sum
    c.append(arr)
c.append(d)
for i in range(n+1):
    print(" ".join(map(str,c[i])))

Submission status: Accepted

Solution code:
r, c = map(int, input().split()) # r = 4, c = 5
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)] # ?????????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])))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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('')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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="")

Submission status: Accepted

Solution code:
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],

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
[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]))

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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()])))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
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)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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])))

Submission status: Accepted

Solution code:
# coding: utf-8

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
[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))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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]]))

Submission status: Accepted

Solution code:
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])))

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
'''
ITP-1_7-C
 ??¨?¨????
??¨?¨??????????????°???????????????°???????????????????????????
??¨????????°r??¨?????°c???r ?? c ???????´????????????¨?????????????????§???????????¨??????????¨?????????\????????°????????¨???????????????
????????°?????????????????????????????????
???Input
???????????????r??¨c????????????????????§??????????????????????¶????r??????????????????c????????´??°????????????????????§?????????????????????
???Output
(r+1) ?? (c+1) ?????°????????¨??????????????????????????????????????£???????????´??°????????????????????§????????£???????????????
???????????????????????¨??????????????????????¨?????????????????????????????????¨??????????????????????¨??????????
???????????????????????¨??¨??????????¨????????????\??????????????????
'''
# inputData
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)

# zip ????´?????????????????????????????????¨?????§????????????????????§??????
columnSum = [sum(Column) for Column in zip(*data)]
print(*columnSum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

#fin = open("test.txt", "r")
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])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3

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

Submission status: Accepted

Solution code:
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)]