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: Wrong Answer

Solution code:
r,c = map(int,input().split())
num=[]
r_sum =[]
for i in range(r):
    num.append([int(i) for i in input().split()])
for i in range(r):
    line_sum = 0
    for j in range(c):
        line_sum += num[i][j]
    num[i].append(line_sum)
    print(num[i])
for i in range(c+1):
    row_sum = 0
    for j in range(r):
        row_sum += num[j][i]
    r_sum.append(row_sum)
num.append(r_sum)
for i in range(len(num)):
    print(' '+' '.join(str(i) for i in num[i]))

Submission status: Wrong Answer

Solution code:

Submission status: Wrong Answer

Solution code:
r=int(input().split()[0])
m=[list(map(int,input().split()))for _ in[0]*r]
for s in m:s.append(sum(s))or print(*s)
print(sum(c)for c in zip(*m))

Submission status: Wrong Answer

Solution code:
r, c = map(int, input().split())
lis = [[] for a in range(r+1)]
for x in range(r):
    lis[x] = list(map(int, input().split()))
    lis[x].append(sum(lis[x]))
lis[r] = [0 for a in range(c+1)]
for y in range(c+1):
    for z in range(r):
        lis[r][y] += lis[z][y]
for x in lis:
    for z,y in enumerate(x):
        if z == r+1:
            print(y)
        else:
            print(y, end = " ")

Submission status: Wrong Answer

Solution code:
r, c = map(int, raw_input().split())
sum_c = [0 for x in range(r)]
sum_r = [0 for x in range(c)]
sum = 0

for i in range(r):
    column = map(int, raw_input().split())
    for j in range(c):
        sum_c[i] += column[j]
        sum_r[j] += column[j]
        sum += column[j]

Submission status: Accepted

Solution code:
def main():
    m, n = tuple(map(int, input().split()))
    matrix = [[0 for j in range(n+1)] for i in range(m+1)]
    for i in range(m):
        tmp = list(map(int, input().split()))
        for j in range(n):
            matrix[i][j] = tmp[j]
            matrix[i][n] += tmp[j]
    
    for j in range(n+1):
        for i in range(m):
            matrix[m][j] += matrix[i][j]

    for i in range(m+1):
        for j in range(n):
            print(matrix[i][j], end=' ')
        print(matrix[i][n])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    r, c = map(int, input().split())
    table = []
    for _ in range(r):
        table.append(list(map(int, input().split())))
    table.append([0] * (c+1))
    for index, line in enumerate(table[:-1]):
        table[index].append(sum(line))
        for index1, value in enumerate(table[index]):
            table[-1][index1] += value
    for line in [map(str, line) for line in table]:
        print(' '.join(line))
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

    for _ in range(r):
        nums = [int(x) for x in input().split()]
        total = sum(nums)

        row = nums + [total]
        matrix.append(row)

        for i in range(c+1):
            totals[i] += row[i]

    matrix.append(totals)

    for m in matrix:
        print(" ".join([str(x) for x in m]))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
all_ele = []
sum_ele = []
h,w = [int(x) for x in input().split()]
for ele in range(h):
    all_ele.append([int(x) for x in input().split()])
    all_ele[ele].append(sum(all_ele[ele]))
    
all_ele.append([int(x) for x in range(w+1)])

for a in range(len(all_ele[0])):
    for b in range(h):
        sum_ele.append(all_ele[b][a])
    all_ele[h][a] = sum(sum_ele)
    sum_ele = []
    
for out1 in all_ele:
    print(' '.join(map(str,out1)))

Submission status: Accepted

Solution code:
r, c = [int(i) for i in input().split()]
data = [[int(i) for i in input().split()] for j in range(r)]
ans = [data[i] + [sum(data[i])] for i in range(r)]
last_ans = ans + [[sum([ans[i][j] for i in range(r)]) for j in range(c+1)]]
for i in last_ans:
    print(*i)

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))))
# matrix.append([sum(i) for i in zip(*matrix)])

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

Submission status: Accepted

Solution code:
data = []
da = []
a = input().split()
a[0] = int(a[0])
a[1] = int(a[1])
for i in range(a[0]):
    b = input().split()
    for j in range(a[1]):
        b[j] = int(b[j])
    data.append(b)
for i in range(len(data)):
    data[i].append(sum(data[i]))
for i in range(a[1]+1):
    da.append(0)
for i in range(a[0]):
    for j in range(a[1]+1):
        da[j] += data[i][j]
data.append(da)
for i in data:
    for j in range(len(i)):
        i[j] = str(i[j])
for i in data:
    print(" ".join(i))

Submission status: Accepted

Solution code:
# coding: utf-8

row, col = map(int, input().split())
spreadsheet = []

for i in range(row):
    val = list(map(int, input().split()))
    val.append(sum(val))
    spreadsheet.append(val)

for r in spreadsheet:
    print(' '.join(map(str, r)))

last_row = []
for j in range(len(spreadsheet[0])):
    col_sum = 0
    for i in range(len(spreadsheet)):
        col_sum += spreadsheet[i][j]
    last_row.append(col_sum)

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

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
x = [];
for i in range(r):
    x.append(list(map(int, input().split())))
rsum = [0 for i in range(r)]
csum = [0 for i in range(c)]
total = 0
for i in range(r):
    for j in range(c):
        rsum[i] += x[i][j]
        csum[j] += x[i][j]
        total += x[i][j]
for i in range(r):
    for j in range(c):
        print(str(x[i][j]) + " ", end="")
    print(rsum[i])
for j in range(c):
    print(str(csum[j]) + " ", end="")
print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H, W = map(int, raw_input().split())
HW = [[0 for i in range(W+1)] for j in range(H+1)]
for i in range(H):
    tmp = map(int, raw_input().split())
    for j in range(W):
        HW[i][j] = tmp[j]
    HW[i][W] = sum(HW[i])
for i in range(W+1):
    tmp = 0
    for j in range(H):
        tmp+=HW[j][i]
    HW[H][i] = tmp
        
    
for i in range(H+1):
    print " ".join(map(str, HW[i]))

Submission status: Accepted

Solution code:
r,c = map(int,input().split())
a = []
for i in range(r):
    a.append(list(map(int,input().split())))
    a[i].append(sum(a[i]))
b = []
for i in range(c+1):
    x = [row[i] for row in a]
    b.append(sum(x))
a.append(b)
for x in a:
    print(*x)

Submission status: Accepted

Solution code:
# 一回で回していくバージョン
r, c = map(int, input().split())
sheet = [[0 for _ in range(c)] for _ in range(r)]
last_culmn = [0 for _ in range(c)]
s = 0
for y in range(r):
    row = list(map(int, input().split()))
    row_s = 0
    for x in range(c):
        sheet[y][x] = row[x]
        row_s += row[x]
        last_culmn[x] += row[x]
        s += sheet[y][x]
    sheet[y].append(row_s)
last_culmn.append(s)
sheet.append(last_culmn)

[print(" ".join(list(map(str, line)))) for line in sheet]

Submission status: Accepted

Solution code:
r, c = 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 + 1):
    s = 0
    for i in range(r):
        s += a[i][j]
    a[-1].append(s)

for i, ai in enumerate(a):
    print(*ai)

Submission status: Accepted

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

d = [0] * (r + 1)

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

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

for i in range(r + 1):
    row = ''
    for j in range(c + 1):
        row += str(d[i][j])
        if j <= c - 1:
            row += ' '
    print(row)

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
a = []
for _ in range(r):
    a.append(list(map(int, input().split())))
for row in a:
    row.append(sum(row))
s = []
for column in range(c + 1):
    tmp = 0
    for row in range(r):
        tmp += a[row][column]
    s.append(tmp)
a.append(s)
for row in a:
    count = 0
    for i in row:
        if count != c:
            print('{} '.format(i), end = '')
        else:
            print('{}'.format(i), end = '')
        count += 1
    print('')

Submission status: Accepted

Solution code:
r_c_str=input().split()
r_c=list(map(lambda i :int(i),r_c_str))
r=r_c[0]
c=r_c[1]
s_str=[input() for i in range(r)]
s_str=[i.split() for i in s_str]
s=[]
for i in s_str:
    s.append(list(map(lambda j :int(j),i)))
for i in range(r):
    s[i].append(sum(s[i]))
s.append([])
for i in range(c+1):
    s[-1].append(0)
for i in range(c):
    for j in range(r):
        s[r][i]+=s[j][i]
s[-1][-1]+=sum(s[r])
for i in s:
    print(*i)

Submission status: Accepted

Solution code:
f = open(0)
R, C = map(int, f.readline().split())
ans = [0]*(C+1)
res = []
for line in f.readlines():
    *D, = map(int, line.split())
    for i, v in enumerate(D):
        ans[i] += v
    s = sum(D)
    ans[-1] += s
    res.append(line.strip())
    res.append(" %d\n" % s)
res.append(" ".join(map(str, ans)))
res.append("\n")
open(1, 'w').writelines(res)

Submission status: Accepted

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

Submission status: Accepted

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

A = [list(map(int,input().split())) for i in range(r)]
for i in range(r):
    for j in range(c):
        print(A[i][j],end=" ")
    print(sum(A[i]))
for i in range(c):
    ans = 0
    for j in range(r):
        ans += A[j][i]
    print(ans,end=" ")
print(sum(map(sum,A)))

Submission status: Accepted

Solution code:
from sys import stdin

r, c = [int(x) for x in stdin.readline().rstrip().split()]
table = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(r)]
for row in range(r):
    table[row] += [sum(table[row])]
    print(*table[row])

col_sum = [sum(x) for x in zip(*table)]
print(*col_sum)

Submission status: Accepted

Solution code:
table = []

# 提出用のインプット
r, c = map(int, input().split())
for i in range(r):
    line = [int(i) for i in input().split()]
    line.append(sum(line))
    table.append(line)

# # 動作確認用のインプット
# with open(file='input_itp1_7_c_1.txt', mode='r', encoding='utf8') as input:
#     r, c = map(int, next(input).split())
#     for i in range(r):
#         line = [int(i) for i in next(input).split()]
#         line.append(sum(line))
#         table.append(line)

for i in range(r):
    print(' '.join(map(str, table[i])))
for j in range(c + 1):
    out = 0
    for i in range(r):
        out += table[i][j]
    if not j == c:
        print(out, end= ' ')
    else:
        print(out)

Submission status: Accepted

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

matrix = []

vsum = [0]*(c+1)

for i in range(r):
	row = list(map(int, input().split()))
	row.append(sum(row))
	matrix.append(row)
	for j in range(c+1):
		vsum[j] += row[j]

matrix.append(vsum)

for row in matrix:
	print(' '.join(list(map(str, row))))

Submission status: Accepted

Solution code:
r,c = map(int,input().split())
data = [[0] * (c+1) for i in range(r)]
for row in range(r):
    data[row] = [int(i) for i in input().split()]
    data[row].append(sum(data[row]))
for row in range(r):
    for column in range(c+1):
        if column == (c):
            print(data[row][column])
        else: 
            print("%d " %data[row][column],end = "")
#転置

data_t = []
sumColumn = []
sumSumRow = 0
for column in range(c):
    dataRow = []
    for rowVector in data:
        dataRow.append(rowVector[column])
    data_t.append(dataRow) 

for column in data_t:
    sumColumn.append(sum(column))
for index in range(c):
    print("%d " %sumColumn[index],end = "")
for row in range(r):
    sumSumRow = sumSumRow + sum(data[row][:-1])
print("%d" % sumSumRow)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n[0]):
	a=0
	for j in range(n[1]):
		a+=x[i][j]
	x[i].append(a)
	print(' '.join(list(map(str,x[i]))))
for i in range(n[1]+1):
	l=0
	for j in range(n[0]):
		l+=x[j][i]
	s.append(l)
print(' '.join(list(map(str,s))))

Submission status: Accepted

Solution code:
m,n=map(int,input().split())
a =[]
for _ in range(m):
    a.append(list(map(int,input().split())))
for index in range(m):
    a[index].append(sum(a[index]))
for a_column in a:
    for num in a_column[:-1]:
        print(num, end=' ')
    print(a_column[-1])
for row_index in range(n):
    sum = 0
    for a_column in a:
        sum += a_column[row_index]
    print(sum, end=' ')
sum = 0
for a_column in a:
    sum += a_column[-1]
print(sum)

Submission status: Accepted

Solution code:
m,n=map(int,input().split())
a =[]
for _ in range(m):
    a.append(list(map(int,input().split())))
for index in range(m):
    a[index].append(sum(a[index]))
for a_column in a:
    print(' '.join(map(str, a_column)))
a.append([0]*(n+1))
for row_index in range(n+1):
    for a_column in a[:-1]:
        a[-1][row_index] += a_column[row_index]
print(' '.join(map(str, a[-1])))

Submission status: Accepted

Solution code:
#coding: UTF-8
import sys

H, W = map(int, input().split())
table = [[0]*(W+1) for i in range(H+1)]
# list = [[0 for i in range(W+1)] for j in range(H+1)]

for row in range(H):
    pre_table = list(map(int, input().split()))
    for col in range(W):
        table[row][col] = pre_table[col]

for row in range(H):
    for col in range(W):
        table[row][W] += table[row][col]

for col in range(W+1):
    for row in range(H):
        table[H][col] += table[row][col]

for row in range(H+1):
    print("%d"%(table[row][0]), end="")
    for col in range(1, W+1):
        print(" %d"%(table[row][col]), end = "")
    print()

Submission status: Accepted

Solution code:
r,c = map(int, input().split())
matrix = []
for i in range(r):
    a = list(map(int, input().split()))
    sum = 0
    for j in range(c):
        sum += a[j]
    a.append(sum)
    matrix.append(a)
    for k in range(c+1):
        print(a[k], end = "")
        if k != c:
            print(" ", end = "")
    print()
for l in range(c+1):
    sum2 = 0
    for m in range(r):
        sum2 += matrix[m][l]
    print(sum2, end = "")
    if l != c:
        print(" ", end = "")
print()

Submission status: Accepted

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

row_lists = []
column = []

for i in range(r):
    rows = list(map(int, input().split()))
    row_sum = sum(rows)
    rows.append(row_sum)
    row_lists.append(rows)

for j in range(c+1):
    tmp_list = []
    for i in range(r):
        tmp = row_lists[i][j]
        tmp_list.append(tmp)
    sum_tmp_list = sum(tmp_list)
    column.append(sum_tmp_list)

# output
for i in range(r):
    print(' '.join(map(str, row_lists[i])))

print(" ".join(map(str, column)))

Submission status: Accepted

Solution code:

line,col = map(int,input().split(" "))

list_col = [0 for i in range(col+1)]
for _ in range(line):
	#行ループ
	data = list(map(int,input().split(" ")))
	data.append(sum(data))

	str_data = list(map(str,data))
	print(" ".join(str_data))

	#列ループ
	for j in range(col+1):
		list_col[j] += data[j]

str_col = list(map(str,list_col))
print(" ".join(str_col))

Submission status: Accepted

Solution code:

line,col = map(int,input().split(" "))

list_col = [0 for i in range(col+1)]
for _ in range(line):
	#行ループ
	data = list(map(int,input().split(" ")))
	data.append(sum(data))
	print(*data)

	#列ループ
	for j in range(col+1):
		list_col[j] += data[j]

print(*list_col)

Submission status: Accepted

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

table = []
i = 0

while i < r:
  table.append(list(int(x) for x in input().split()))
  i += 1

i,j = 0,0
for i in table:
  sum = 0
  for idx,j in enumerate(i):
    if idx != 0:
      print(' ', end='')
    print(j, end='')   
    sum += j
  print(' ' + str(sum))

j,ttl = 0,0
while j < c:
  i = 0
  sum = 0
  while i < r:
    sum += table[i][j]
    i += 1
  print (sum, end=' ')
  ttl += sum
  j += 1
print(ttl)

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
table = [[0]*(W+1) for i in range(H+1)]

for row in range(H):
    work = list(map(int,input().split()))
    for col in range(W):
        table[row][col] = work[col]

for row in range(H):
    for col in range(W):
        table[row][W] += table[row][col]

for col in range(W+1):
    for row in range(H):
        table[H][col] += table[row][col]

for row in range(H+1):
    print("%d"%(table[row][0]),end="")
    for col in range(1,W+1):
        print(" %d"%(table[row][col]),end="")
    print()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = []
b = []
for i in range(n):
    a += [list(map(int, input().split()))]
    a[i] += [sum(a[i])]
for i in range(m+1):
    b += [sum(x[i] for x in a)]
a += [b]
for i in range(n+1):
    print(*a[i])

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
al = []
b_lis = []

for _ in range(a):
    g = list(map(int, input().split()))
    g.append(sum(g))
    al.append(g)
for i in range(b+1):
    p = 0
    for j in range(a):
        p += al[j][i]
    b_lis.append(p)
al.append((b_lis))
for i in al:
    print(' '.join([str(v) for v in i]))

Submission status: Accepted

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

a = []

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

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

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))))
# matrix.append([sum(i) for i in zip(*matrix)])

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

Submission status: Accepted

Solution code:
i,j=map(int,input().split())
listA=[]
for n in range(i):
    listA.append(list(map(int,input().split())))
    listA[n].append(sum(listA[n]))
listA.append([])
for n in range(j+1):
    number=0
    for m in range(i):
        number+=listA[m][n]
    listA[i].append(number)
for n in range(i+1):
    print(' '.join(map(str,listA[n])))

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:
l, c = map(int, input().split())
tbl = [[] for _ in range(l)]
li_sum = [0 for _ in range(c+1)]

for i in range(l):
  tblS = input()
  tbl[i] = list(map(int, tblS.split()))
  print(tblS, end = '')
  print(' ', sum(tbl[i]), sep = '')

  for j in range(c):
    li_sum[j] += tbl[i][j]
  li_sum[c] += sum(tbl[i])

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

Submission status: Accepted

Solution code:
l, c = map(int, input().split())
tbl = [[] for _ in range(l)]
li_sum = [0 for _ in range(c+1)]

for i in range(l):
  a = input()
  tbl[i] = list(map(int, a.split()))
  print(a, end='')
  print(' ', sum(tbl[i]), sep = '')

  for j in range(c):
    li_sum[j] += tbl[i][j]
  li_sum[c] += sum(tbl[i])

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

Submission status: Accepted

Solution code:
l, c = map(int, input().split())
tbl = [[] for _ in range(l)]
li_sum = [0 for _ in range(c+1)]

for i in range(l):
  a = input()
  tbl[i] = list(map(int, a.split()))
  print(a, end='')
  print(' ', sum(tbl[i]), sep ='')

  for j in range(c):
    li_sum[j] += tbl[i][j]
  li_sum[c] += sum(tbl[i])

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

Submission status: Accepted

Solution code:
csum_a = []
r, c = list(map(int, input().split()))
array = [[int(j) for j in input().split()] for i in range(r)]

for i in range(c):
    csum = 0 #列ごとに初期化
    for j in range(r):
        csum = csum + array[j][i]
    csum_a.append(csum)
array.append(csum_a)
#ここの時点で(r+1)行×c列の配列になっている

for i in range((r+1)):
    rsum = 0 #行ごとに初期化
    for j in range(c):
        rsum = rsum + array[i][j]
    array[i].append(rsum)

for i in array:
    print(*i)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    from sys import stdin

    r, c = (int(n) for n in stdin.readline().split())

    table = []
    for _ in range(r):
        row = [int(n) for n in stdin.readline().split()]
        row.append(sum(row))

        print(" ".join(map(str, row)))
        table.append(row)
        
    sum_column = (sum(column) for column in zip(*table))
    print(" ".join(map(str, sum_column)))

Submission status: Accepted

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

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

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

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:
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:
r,c = map(int,input().split())
a =[]

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

b = list(map(sum,zip(*a)))

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

Submission status: Accepted

Solution code:
import sys
 
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
 
 
 
H,W = map(int,input().split())
 
table = [[0]*(W+1) for i in range(H+1)]
 
for row in range(H):
    work = list(map(int,input().split())) #★★直にtableに代入すると、列数が変わってしまう!!!★★★
    for col in range(W):
        table[row][col] = work[col]
 
 
for row in range(H):
    for col in range(0,W):
        table[row][W] += table[row][col]
 
 
for col in range(0,W+1):
    for row in range(0,H):
        table[H][col] += table[row][col]
 
 
for row in range(0,H+1):
    print("%d"%(table[row][0]),end="")
    for col in range(1,W+1):
        print(" %d"%(table[row][col]),end = "")
    print()

Submission status: Accepted

Solution code:
r,c=map(int,input().split())
C=[]
for _ in range(r):
  ns = list(map(int, input().split()))
  ns.append(sum(ns))
  C.append(ns)
#print(C)
R = list(zip(*C))
#print(R)
C.append([sum(x) for x in R])
for r in C:
  print(*r)

Submission status: Accepted

Solution code:
r,c=map(int, input().split())
S=[]
for num in range(r):
  A=list(map(int, input().split()))
  S.append(A)
  A.append(sum(A))

#print(list(zip(*S)))
C=[]
for t in (zip(*S)):
  C.append(sum(t))
S.append(C)
for i in S:
  print(*i)

Submission status: Accepted

Solution code:
r,c=map(int,input().split())
N=[list(map(int,input().split())) for i in range(r)]
retu=[[0 for i in range(1)] for j in range(1)] 
for j in range(c):
  ret=0
  for i in range(r):
    ret+=N[i][j]
  if j==0:
    retu[0][0]+=ret
  else:
    retu[0].append(ret)
N.extend(retu)
for i in range(r+1):
  tuika=0
  for j in range(c):
    tuika+=N[i][j]
  N[i].append(tuika)
  
for i in range(r+1):
  for j in range(c+1):
    if j==0:
      print(N[i][j],end="")
    else:
      print("",N[i][j],end="")
  print("")

Submission status: Accepted

Solution code:
[r,c] = map(int,raw_input().split()) 
D = [[0 for i in range(c+1)] for j in range(r+1)] 
for y in range(r):
    v = map(int,raw_input().split())
    for x in range(c):
        D[y][x] = v[x]
        D[y][c] = D[y][c] + v[x]
        D[r][x] = D[r][x] + v[x]
        D[r][c] = D[r][c] + v[x] 
        
for y in range(r+1):
    s = ''
    for x in range(c+1):
        if x == 0:
            s = str(D[y][x])
        else: s = s + ' ' + str(D[y][x])
    print s

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:
i = list(map(lambda x: int(x), input().split(" ")))
count = 0
h = list()
c = [0 for i in range(0, i[1]+1)]
while count < i[0]:
    l = list(map(lambda x: int(x), input().split(" ")))
    l.append(sum(l))
    h.append(l)
    for j, c_ in enumerate(l):
        c[j] += c_
    count += 1
for r_ in h:
    print("%d" % r_[0], end="")
    for c_ in r_[1:]:
        print(" %d" % c_, end="")
    print("")

print("%d" % c[0], end="")
for c_ in c[1:]:
    print(" %d" % c_, end="")
print("")

Submission status: Accepted

Solution code:
r,c=map(int,raw_input().split())
l=[]
for i in range(r):l.append(map(int,raw_input().split()))
l.append([0]*(c+1))
for i in range(c+1):
    for j in range(r):
        if i==0:l[j].append(sum(l[j]))
        l[-1][i]+=l[j][i]
for i in range(r+1):print' '.join(map(str,l[i]))

Submission status: Accepted

Solution code:
r,c = map(int,raw_input().split(' '))
sheet = [[0 for i in range((c+1))]for j in range((r+1))]
for i in range(r):
	s = map(int,raw_input().split(' '))
	for j in range(c):
		sheet[i][j] = s[j]
		sheet[i][c] += s[j]
		sheet[r][j] += s[j]
		print sheet[i][j],
	sheet[r][c] += sheet[i][c]
	print sheet[i][c]
for i in range(c):
	print sheet[r][i],
print sheet[r][c]

Submission status: Accepted

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

for a in range(y):
    tmp = map(int,raw_input().split())
    list.append(tmp + [sum(tmp)])
    for i,b in enumerate(list[a]):
        last[i] = last[i] + b

for c in list:
    print " ".join(map(str,c))
print " ".join(map(str,last))

Submission status: Accepted

Solution code:

r,c = tuple([int(x) for x in raw_input().split(" ")])

A = []

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

for lst in A:
    lst.append(sum(lst))
    print(" ".join([str(x) for x in lst]))

lst2=[0 for x in range(c)]
for i in range(c):
   for j in range(r):
       lst2[i] += A[j][i]

lst2.append(sum(lst2))
print " ".join([str(x) for x in lst2])

Submission status: Accepted

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

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

for line in arr:
    print(*line)

Submission status: Accepted

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

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

for i in range(r + 1):
    sum = 0
    count = 0
    for j in a[i]:
        print(j, end=' ')
        sum += j
        if i != r:
            a[r][count] += j
            count += 1
    print(sum)

Submission status: Accepted

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

ct = [0 for d in range(c)]
tmp = []
for rc in range(r):
    tmp = [int(i) for i in input().split()]
    total = 0
    for cc in range(c):
        ct[cc] += tmp[cc]
        total += tmp[cc]
        print(tmp[cc], end=' ')
    print(total)
total = sum(ct)
print(' '.join([str(i) for i in ct]), total)

Submission status: Accepted

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

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

for i in range(r):
    tmp = [int(x) for x in input().split()]
    for j in range(c + 1):
        if not j == c:
            table[i][j] = tmp[j]
            table[i][c] += table[i][j]
        table[r][j] += table[i][j]

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

Submission status: Accepted

Solution code:
import sys

r, c = map(int, raw_input().split())
table = {}

for i in range(r):
    a = map(int, raw_input().split())
    for j in range(c):
        table[(i,j)] = a[j]

for i in range(r+1):
    for j in range(c+1):
        if(i != r and j != c):
            sys.stdout.write(str(table[(i,j)]))
            sys.stdout.write(' ')
        elif(i != r and j == c):
            print sum(table[(i,l)] for l in range(c))
        elif(i == r and j != c):
            sys.stdout.write(str(sum(table[(k,j)] for k in range(r))))
            sys.stdout.write(' ')
        elif(i == r and j == c):
            total = 0
            for k in range(r):
                for l in range(c):
                    total += table[(k,l)]
            print total

Submission status: Accepted

Solution code:
import sys
from operator import add
(r, c) = [int(i) for i in sys.stdin.readline().split()]
s = [0] * (c + 1)
for i in range(r):
    l = [int(i) for i in sys.stdin.readline().split()]
    l.append(sum(l))
    print(" ".join([str(i) for i in l]))
    s = map(add, s, l)

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