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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)
    
#get summery of each columns
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())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

#calc each col
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))

#calc each row
for i, num in enumerate(nums):
    nums[i].append(sum(num))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for j in range(r + 1):
    for k in range(c + 1):
        if j == r and k != c:
            lastrow = sum(map(int, [table[x][k] for x in range(r)]))
            table[-1].append(lastrow)
        if k == c:
            print(sum(map(int, table[j])))
            break
        print(table[j][k],end=' ')

Submission status: Accepted

Solution code:
iranai = [int(i) for i in input().split()]
iru = [[int(i) for i in input().split()] for i in range(iranai[0])]
mikitani = []
son = []
num = 0
mikicount = 0
for i in range(iranai[0]):
    for i2 in range(iranai[1]):
        num += iru[i][i2]
    mikitani.append(num)
    num = 0

for i in range(iranai[1]):
    for i2 in range(iranai[0]):
        num += iru[i2][i]
    son.append(num)
    num = 0

for i in range(iranai[0]):
    for i2 in range(iranai[1]):
        print(iru[i][i2],end=" ")
        if i2 == iranai[1]-1:
            print(mikitani[i])
    mikicount += mikitani[i]
son.append(mikicount)

for i in range(len(son)):
    if i == len(son)-1:
        print(son[i])
    else:
        print(son[i],end=" ")

Submission status: Accepted

Solution code:
res1  = []
r, c = [int(temp) for temp in input().split()]

for temp in range(c + 1) : res1.append(0)

for tem in range(r) :
    tem1 = [temp for temp in input().split()]
    tem2 = list(map(int, tem1))
    print(' '.join(tem1) + ' ' + str(sum(tem2)))
    for mak in range(c) :
        res1[mak] = res1[mak] + tem2[mak]
    res1[c] += sum(tem2)

res2 = list(map(str, res1))
print(' '.join(res2))

Submission status: Accepted

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

matrix = []
for i in range(r):
    matrix.append([int(x) for x in input().split()])
    
for i in range(r):
    for j in range(c):
        print(matrix[i][j], '', end='')
    print(sum(matrix[i]))

crsum = 0
for j in range(c):
    csum = 0
    for i in range(r):
        csum += matrix[i][j]
    print(csum, '', end='')
    crsum += csum
print(crsum)

Submission status: Accepted

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

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

for rows in matrix:
    rows.append(sum(rows))

column_sum = []
for j in range(c+1):
    element_sum = 0
    for k in range(r):
        element_sum += matrix[k][j]
    column_sum.append(element_sum)

for p in matrix:
    print(" ".join(map(str,p)))
    
print(" ".join(map(str,column_sum)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import os


def input_to_list():
    return list(map(int, input().split()))

H, W = input_to_list()
M = []
for i in range(H):
    lis = input_to_list()
    s = sum(lis)
    lis.append(s)
    M.append(lis)

# vertical sum
last = []
for i in range(W + 1):
    s = 0
    for j in range(H):
        s += M[j][i]
    last.append(s)
M.append(last)

# print
for i in range(H + 1):
    print(*M[i])

Submission status: Accepted

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

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

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

for i in range(r):
    for j in range(c):
        print(a[i][j], end = " ")
    print(rsum[i])
for i in range(c):
    print(csum[i], end = " ")
print(allsum)

Submission status: Accepted

Solution code:
r,c = [int(i) for i in input().split()]
a = [[0 for i in range(c+1)] for j in range(r+1)]
for i in range(r):
	a[i] = [int(j) for j in input().split()]
for i in range(r):
	rowSum = 0
	for j in range(c):
		rowSum += a[i][j]
	a[i].append(rowSum)
for i in range(c+1):
	columnSum = 0
	for j in range(r):
		columnSum += a[j][i]
	a[r][i] = columnSum
for i in range(r+1):
	for j in range(c):
		print(a[i][j],end=' ')
	print(a[i][c])

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !
 
import math
 
def func():
    try:
        (rows,columns) = [ int(item) for item in input().rstrip().split(" ") ]
        data = [ [ int(item) for item in input().rstrip().split(" ") ] for i in range(rows) ]
    except:
        return inputError()
        
    [item.append(sum(item)) for item in data]
    data.append( [sum( [ item[i] for item in data ] ) for i in range(columns+1) ])
    
    result=""
    for row in data:
        for item in row:
            result += str(item)+" "
        result=result.rstrip()
        result += "\n"
    print(result.rstrip())

def inputError():
    '''
    print("input Error")
    return -1
    '''
 
    print("input Error")
    return -1
     
func()

Submission status: Accepted

Solution code:
#!/usr/bin/env python

ss = []
sumf = []

n, m = input().split()
n = int(n)
m = int(m)

for i in range(n):
    r = input()
    rSplit = r.split()
    for j in range(m):
        rSplit[j] = int(rSplit[j])
    ss.append(rSplit)

for i in range(m):
    summ = 0
    for j in range(n):
        summ += ss[j][i]
    sumf.append(summ)

ss.append(sumf)

for x in ss:
    summ = sum(x)
    x.append(summ)

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

for x in ss:
    print(" ".join(x))

Submission status: Accepted

Solution code:
r, c = [int(i) for i in input().split(" ")]
s_row = [0 for x in range(c + 1)]

for i in range(r):
    row = [int(n) for n in input().split(" ")]
    row.append(sum(row))
    print(" ".join( [ str(s) for s in row ] ) )
    s_row = [ x + y for x, y in zip(s_row, row)]
print(" ".join( [str(s1) for s1 in s_row] ))

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
li = []
last_r =[0 for _ in range(c + 1)]
for i in range(r):
    li.append([int(x) for x in input().split()])
    li[i].append(sum(li[i]))
    for j in range(c+1):
        last_r[j] +=li[i][j]
li.append(last_r)
for i in li:
    print(*i)

Submission status: Accepted

Solution code:
r,c = map(int, input().split())
L=[]
for i in range(r):
 al = input()
 print(al, end="")
 AL = list(map(int, al.split()))
 S = sum(AL)
 print(" " + str(S))
 AL. append(S)
 L.append(AL)

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

S = 0
for j in range(r):
 S += L[j][-1]
print(str(S))

Submission status: Accepted

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

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

for i in range(r):
    rows  = list(map(int, input().split(' ')));

    total = sum(rows)
    rows.append(total)

    total_cols = [ total_cols[i] + x for i, x in enumerate(rows) ]

    matrix.append(rows)

matrix.append(total_cols)

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

Submission status: Accepted

Solution code:
num = [[0 for i in range(101)] for j in range(101)]
r, c = map(int, input().split())
for i in range(r):
    num[i][:c] = list(map(int, input().split()))
    for j in range(c):
        num[i][c] += num[i][j]
for j in range(c+1):
    for i in range(r):
        num[r][j] += num[i][j]
for i in range(r+1):
    for j in range(c):
        print(num[i][j], end=' ')
    print(num[i][c])

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
#coding:utf-8

r , c = [int(i) for i in input().rstrip().split()]
hyou =[]
r1=[]

#r????????§
for i in range(r):
    a = [int(i) for i in input().rstrip().split()]
    gou = sum(a)
    a.append(gou)
    print(" ".join(list(map(str ,a))))
    hyou.append(a)
    gou =0

#r+1
for i in range(c+1):
    for j in range(r):
       gou += hyou[j][i]


    r1.append(gou)
    gou = 0

#print(hyou)

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

Submission status: Accepted

Solution code:
s = input().split(" ")
r = int(s[0])
c = int(s[1])
a = [[0 for i in range(c)] for j in range(r+1)]
for i in range(r):
    s = input().split(" ")
    for j in range(c):
        a[i][j] = int(s[j])
for i in range(c):
    sk = 0
    for j in range(r):
        sk += a[j][i]
    a[r][i] = sk
for i in range(r+1):
    sk = 0
    for j in range(c):
        print(a[i][j],end=" ")
        sk += a[i][j]
    print(sk)

Submission status: Accepted

Solution code:
#!/usr/bin/python

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

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

lastrow = [sum(i) for i in zip(*row_lists)]

row_lists.append(lastrow)

for r in row_lists:
    print(" ".join(map(str, r)))

Submission status: Accepted

Solution code:
r, c = map(int, raw_input().split())
matrix = []
sum_line = [0] * c
for i in range(r):
    line = map(int, raw_input().split())
    sum = 0
    for j in range(c):
        sum += line[j]
        sum_line[j] += line[j]
    line.append(sum)
    matrix.append(line)
    #print " ".join(map(str, line))

sum = 0
for i in range(r):
    print " ".join(map(str, matrix[i]))
    sum += matrix[i][c]
sum_line.append(sum)
print " ".join(map(str, sum_line))

Submission status: Accepted

Solution code:
r, c = map(int,input().split())
ans = [0 for i in range(c+1)]
for i in range(r):
    l = list(map(int, input().split()))
    l.append(sum(l))
    ans = [x + y for (x, y) in zip(ans, l)]
    print(" ".join(map(str,l)))
print(" ".join(map(str,ans)))

Submission status: Accepted

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

for i in range(r+1):
    for j in range(c+1):
        if j == c:
            print(b[i][j])
        else:
            print("{0} ".format(b[i][j]), end = "")

Submission status: Accepted

Solution code:
# coding: utf-8
height, width = list(map(int, input().split(" ")))
answer = [[0 for _ in range(width + 1)] for _ in range(height + 1)]

for row in range(height):
    column = 0
    sumOfColumn = 0
    for value in list(map(int, input().split(" "))):
        answer[row][column] = value
        sumOfColumn += value
        column += 1
    answer[row][column] = sumOfColumn
    
for columnIndex in range(width + 1):
    sumOfRow = 0
    for rowIndex in range(height):
        value = answer[rowIndex][columnIndex]
        sumOfRow += value
    answer[height][columnIndex] = sumOfRow

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

Submission status: Accepted

Solution code:
r, c = map(int,input().split())
b=[]
for i in range(r):    
        a=list(map(int,input().split()))
        a.append(sum(a))
        b.append(a)
        a=map(str,a)
        print(" ".join(a))
d=[]
for i in range(c+1):
    cs=[]
    for j in range(r):
        cs.append(b[j][i])
    d.append(sum(cs))
d=map(str,d)
print(" ".join(d))

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
last = [0] * (c + 1)

for _ in range(r):
    row = list(map(int, input().split()))
    row += [sum(row)]

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

    for x in range(c + 1):
        last[x] += row[x]

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

Submission status: Accepted

Solution code:
r, c = list(map(int, input().split(" ")))
A = [[0 for _ in range(c)] for _ in range(r)]

A_sum = 0
for i in range(r):
    a_line = list(map(int, input().split(" ")))
    for j, a in enumerate(a_line):
        print("%d "%a, end="")
        A[i][j] = a
        A_sum += a
    print("%d"%sum(a_line))

A_T = list(map(list, zip(*A)))
for a_t in A_T:
    print ("%d "%(sum(a_t)), end="")

print (A_sum)

Submission status: Accepted

Solution code:
y,x=[int(i) for i in input().split()]
s=[[int(0)for i in range(x+1)]for j in range(y+1)]
for i in range(y):
    k=input().split()
    for j in range(x):
        s[i][j]=int(k[j])
for i in range(y):
    for j in range(x):
        s[i][x]=s[i][x]+s[i][j]
        s[y][j]=s[y][j]+s[i][j]
for i in range(y):
    s[y][x]=s[y][x]+s[i][x]
for i in range(y+1):
    for j in range(x):
        print(s[i][j],"",end="")
    print(s[i][x])

Submission status: Accepted

Solution code:
r,c = [int(s) for s in input().split(' ')]
data = [[int(s) for s in input().split(' ')] for i in range(r)]
[row.append(sum(row)) for row in data]
T = [[row[i] for row in data] for i in range(c+1)]
bottom = [sum(t) for t in T]
data += [bottom]
data_s = [' '.join([str(i) for i in row]) for row in data]
[print(row) for row in data_s]

Submission status: Accepted

Solution code:
r, c = (int(i) for i in input().split())
table = tuple([int(x) for x in input().split()] for _ in range(r))
for cols in table:
  cols.append(sum(cols))
  print(*cols)
sums = tuple(sum(table[y][x] for y in range(r)) for x in range(c + 1))
print(*sums)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
??´?????????
"""
inp = input().strip().split(" ")
row = int(inp[0])
col = int(inp[1])

cells = [[0 for r in range(col+1)] for c in range(row+1)]
for r in range(row):
    inp = input().strip().split(" ")
    for c in range(col):
        cells[r][c] = int(inp[c])
        cells[row][c] += cells[r][c]
        cells[r][col] += cells[r][c]
    cells[row][col] += cells[r][col]

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

Submission status: Accepted

Solution code:
r,c = [eval(x) for x in input().split()]
table = [[eval(x) for x in input().split()] for _ in range(r)]
[table[i].append(sum(table[i])) for i in range(r)]
table.append([sum([table[i][j] for i in range(r)]) for j in range(c+1)])
[print(''.join([str(table[i][j]) + (' ' if j != c else '') for j in range(c+1)])) for i in range(r+1)]

Submission status: Accepted

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

for i in range(n):
    k = [int(i) for i in input().split()]
    k.append(sum(k))
    a.append(k)
    for j in range(m):
        s[j] += k[j]

s.append(sum(s))
a.append(s)

for j in a:
    print(' '.join(map(str, j)))

Submission status: Accepted

Solution code:
rc=list(map(int,input().split()))
sheet=[list(map(int,input().split()))+[0] for i in range(rc[0])]
sheet.append([0 for i in range(rc[1]+1)])
for s in sheet:
    s[-1]=sum(s[0:-1])
for i in range(rc[1]+1):
    r=sum([n[i] for n in sheet[0:-1]])
    sheet[-1][i]=r
for sh in sheet:
    print(*sh)

Submission status: Accepted

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

Submission status: Accepted

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

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


for s in range(r):
    a[s] = [int(x) for x in input().split()]

for t in range(r):
    a_sum = sum(a[t])
    a[t].append(a_sum)

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

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

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:
ls = []
ls2=[]
r,c = map(int,input().split())
for i in range(0, r):
    ls.append(list(map(int,input().split())))

for j in range(0, r):
    ls[j].append(sum(ls[j]))

for j in range(0, c+1):
    num = 0
    for k in range(0, r):
        num += ls[k][j]
    ls2.append(num)
ls.append(ls2)
for z in range(0, r+1):
    print(*ls[z])

Submission status: Accepted

Solution code:
ls = []
r,c = map(int,input().split())
for i in range(0, r):
    ls.append(list(map(int,input().split())))
ls.append([])
for j in range(0, r):
    ls[j].append(sum(ls[j]))

for j in range(0, c+1):
    num = 0
    for k in range(0, r):
        num += ls[k][j]
    ls[r].append(num)
for z in range(0, r+1):
    print(*ls[z])

Submission status: Accepted

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

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

array.append(coltotal)

for a in range(r + 1):
	print(*array[a])

Submission status: Accepted

Solution code:
sheet = []
r, c = (int(x) for x in input().split())

for row in range(r):
    bufarr = [int(x) for x in input().split()]
    bufarr.append(sum(bufarr))
    sheet.append(bufarr)

bufarr = []
for col in range(c + 1):
    bufarr.append(sum(sheet[row][col] for row in range(r)))
sheet.append(bufarr)

for row in range(r + 1):
    print(" ".join(str(sheet[row][col]) for col in range(c + 1)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
r, c = map(int, raw_input().split())
sheet = list()
for i in range(r):
    sheet.append(map(int, raw_input().split()))
for i in range(r):
    sheet[i].append(sum(sheet[i]))
for i in sheet:
    print(" ".join(str(j) for j in i))
temp = list()
for i in range(c):
    result = 0
    for j in range(r):
        result += sheet[j][i]
    temp.append(result)
temp.append(sum(temp))
print(" ".join(str(i) for i in temp))

Submission status: Accepted

Solution code:
r,c = map(int,input().split())
rc = list([int(x) for x in input().split()] for _ in range(r))
[rc[i].append(sum(rc[i])) for i in range(r)]
rc.append([sum(i) for i in zip(*rc)])

for col in rc: print(*col)

Submission status: Accepted

Solution code:
r,c = map(int,input().split())
rc=[]
total=[]
for _ in range(r): rc.append(list(map(int,input().split())))
for i in range(r): rc[i].append(sum(rc[i]))
for i in zip(*rc): total.append(sum(i))
rc.append(total)
for col in rc: print(*col)

Submission status: Accepted

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

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

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

matrix.append([sum(i) for i in zip(*matrix)])

for m in matrix:
    print(' '.join(str(e) for e in m))

Submission status: Accepted

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

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

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

matrix.append(list(map(sum, zip(*matrix))))

for m in matrix:
    print(' '.join(str(e) for e in m))

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
sheet = [[int(n) for n in input().split()] for i in range(r)]
sheet_sum = [[0 for i in range(c + 1)] for j in range(r + 1)]
for i in range(r):
    for j in range(c):
        sheet_sum[i][j] = sheet[i][j]
    sheet_sum[i][c] = sum(sheet[i])
for i in range(c + 1):
    for j in range(r):
        sheet_sum[r][i] += sheet_sum[j][i]
for i in range(r + 1):
    for j in range(c + 1):
        if j == c:
            print(sheet_sum[i][j])
        else:
            print(sheet_sum[i][j], end = " ")

Submission status: Accepted

Solution code:
row, col = map(int, raw_input().split())

ret = []
for _ in range(row):
    _row = map(int, raw_input().split())
    _row += [sum(_row)]
    ret.append(_row)

for i in ret: 
    print ' '.join(map(str, i))

ret_sum = []
for i in range(col+1):
    work = 0
    for j in ret: 
        work += j[i] 
    ret_sum.append(work)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Aizu Problem ITP_1_7_C: Spreadsheet
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


n, m = [int(_) for _ in input().split()]
A = [[int(_) for _ in input().split()] for __ in range(n)]

for row in range(n):
    A[row].append(sum(A[row]))

for row in A:
    print(' '.join([str(r) for r in row]))

last = []
for col in range(m):
    last.append(sum([A[row][col] for row in range(n)]))
last.append(sum(last))
print(' '.join([str(l) for l in last]))

Submission status: Accepted

Solution code:
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):
    j = 0
    for line in input().split():
        a[i][j] = int(line)
        a[i][c] += a[i][j]
        j += 1
for i in range(c+1):
    for j in range(r):
        a[r][i] += a[j][i]
for i in range(r+1):
    for j in range(c+1):
        if j == c:
            print(a[i][j])
        else:
            print(a[i][j], end=" ")

Submission status: Accepted

Solution code:
m,n=map(int,input().split())
hozon=[]
for i in range(n):
    hozon.append(0)
for _ in range(m):
    x = input()
    gyou = list(map(int,x.split()))
    print(x+" {0}".format(sum(gyou)))
    for num in range(n):
        hozon[num] += gyou[num]

print(" ".join(map(str,hozon))+" {0}".format(sum(hozon)))

Submission status: Accepted

Solution code:
r,c = [int(i) for i in input().split()]
a = [[int(i) for i in input().split()] for j in range(r)]
b = [sum(a[i]) for i in range(r)]
[a[i].append(b[i]) for i in range(r)]
d = [0 for i in range(c + 1)]
for i in range(r):
    for j in range(c + 1):
        d[j] += a[i][j]
a.append(d)
for i in range(r + 1):
    print(' '.join(map(str,a[i])))

Submission status: Accepted

Solution code:
y, x = map(int, input().split())
box = []
y_sum = [[]]

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

box_replace = list(map(list, zip(*box)))
[y_sum[0].append(sum(box_replace[i])) for i in range(x+1)]
box += y_sum

[print( " ".join(map(str, box[i])) ) for i in range(y+1)]

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
sheet = []

for j in range(h):
	lista = list(map(int, input().split()))
	lista.append(sum(lista))
	sheet.append(lista)

lista = []

for i in range(w+1):
	sum = 0
	for j in range(h):
		sum += sheet[j][i]
	lista.append(sum)
	
sheet.append(lista)

for i in range(h+1):
	text = ""
	for j in range(w+1):
		text += str(sheet[i][j]) + " "
	print(text[:-1])

Submission status: Accepted

Solution code:
list = [input().split()]
r = int(list[0][0])
c = int(list[0][1])
i = 0
k = 0
sum2 = 0
list3 = [0] * c
while i < r:
    sum = 0
    list2 = [input().split()]
    for j in list2[0]:
        print(j, end=' '),
        sum += int(j)
    for k in range(c):
        list3[k] += int(list2[0][k])
    print(sum)
    sum2 += sum
    i += 1
for l in list3:
    print(l, end=' ')
print(sum2)

Submission status: Accepted

Solution code:
I = input().split()
r = int(I[0])
c = int(I[1])
Rsum = 0
Csum = (c + 1) * [0]

o = [[0 for i2 in range(c + 1)] for i1 in range(r + 1)]

for i in range(r + 1):
    if i < r:
        Irc = input().split()
    for j in range(c):
        if i < r:
            o[i][j] = int(Irc[j])
            Rsum += o[i][j]
            Csum[j] += o[i][j]
        else:
            o[i][j] += Csum[j]
            Rsum += o[i][j]
    o[i][c] = Rsum
    Csum[c] = o[i][c]
    Rsum = 0

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

Submission status: Accepted

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

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

for l in data:
    print(*l)
print(*list1)

Submission status: Accepted

Solution code:
m, n = map(int, input().split())
sheet = [ list(map(int, input().split())) for i in range(m)]
for i in range(m):
    sheet[i].append(sum(sheet[i]))
    if i == 0:
        sheet.append(list(sheet[i]))
    else :
        for j in range(n):
            sheet[-1][j] += sheet[i][j]
sheet[-1][-1] = sum(sheet[-1]) - sheet[0][-1]
for tmp_list in sheet:
    print(" ".join(str(x) for x in tmp_list))

Submission status: Accepted

Solution code:
class Reader:
    def __init__(self, r, c):
        self.r = r
        self.c = c
        self.buf = [0 for _ in range(c+1)]

    def __call__(self, s):
        total = 0
        for i, v in enumerate(map(int, s.split())):
            self.buf[i] += v
            total += v
        self.buf[-1] += total
        return " ".join((s, str(total)))

    def __str__(self):
        return " ".join(map(str, self.buf))

r, c = list(map(int, input().split()))
reader = Reader(r, c)

for _ in range(r):
    print(reader(input()))
print(reader)