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())
l = []
sum = [0]*c
for i in range(r):
    l.append(list(map(int, input().split())))
for i in range(r):
    count = 0
    for ii in range(c):
        sum[ii] += l[i][ii]
        count += l[i][ii]
    l[i].append(count)
    print(" ".join(map(str, l[i])))
count = 0
for i in range(c):
    count += sum[i]
sum.append(count)
print(" ".join(map(str, sum)))

Submission status: Accepted

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

for i in range(r):
    A[i] = list(map(int,input().split()))
    A_str = [[str(x) for x in y] for y in A]
    
    l = A_str[i]
    print(" ".join(l) + " " + str(sum(A[i])))

for i in range(r):
    for j in range(c):
        s[j] += A[i][j]

sum_str = list(map(str,s))
print(" ".join(sum_str) + " " + str(sum(s)))

Submission status: Accepted

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

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

while r > 0:
    n =[int(n) for n in input().split()]
    n.append(sum(n))

    for i in range(len(n)):
        last_row[i] += n[i]

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

    r-=1

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

Submission status: Accepted

Solution code:
import functools

if __name__ == "__main__":
    num_rows, num_cols = list(map(int, input().split()))

    table = []

    for _ in range(num_rows):
        row = list(map(int, input().split()))

        table.append(row)

    table_added_row_sum = list(map(lambda row: row + [sum(row)], table))

    col_sum = functools.reduce(
        lambda acc, elem: acc + [sum(elem)],
        list(zip(*table_added_row_sum)),
        []
    )

    table_added_row_col_sum = table_added_row_sum + [col_sum]

    string_records = list(map(
        lambda row: ' '.join(map(str, row)),
        table_added_row_col_sum
    ))

    for string_record in string_records:
        print(string_record)

Submission status: Accepted

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


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

for i in b:
  print(*i)

Submission status: Accepted

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

for _ in range(r):
    l = list(map(int,input().split()))
    l.append(sum(l))
    x.append (l)

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

for l in x:
    print(' '.join(map(str, l)))

Submission status: Accepted

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

total_row = []
for col in range(c+1):
    column_sum = 0
    for row in range(r):
        column_sum += table[row][col]
    total_row.append(column_sum)
table.append(total_row)

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

Submission status: Accepted

Solution code:
r,c = map(int,input().split())
tbl = [list(map(int,input().split())) for _ in range(r)]
tbladd = []
for i in range(r):
    tbl[i].insert(c,sum(tbl[i]))
for i in range(c+1):
    sum = 0
    for j in range(r):
        sum += tbl[j][i]
    tbladd.insert(i,sum)
tbl.append(tbladd)
for i in range(r+1):
    for j in range(c+1):
        if j != c:
            print(tbl[i][j], end=' ')
        else:
            print(tbl[i][j], end='')
    if i != r:
        print()
    else:
        print()

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

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

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

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

Submission status: Accepted

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

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

ans.append(sum(ans))

for l in A:
    l = [str(i) for i in l]
    print(' '.join(l))
else:
    l = [str(i) for i in ans]
    print(' '.join(l))

Submission status: Accepted

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

EX_list = []

for i in range(r):
    EX_list.append(input().split())
for i in range(r):
    r_sum = 0
    for j in EX_list[i]:
        r_sum += int(j)
    EX_list[i].append(r_sum)
    print(*EX_list[i])

c_sum_list = []
for c_i in range(c):
    c_sum = 0
    for r_i in range(r):
        c_sum += int(EX_list[r_i][c_i])
    c_sum_list.append(c_sum)
c_sum_list_sum = 0
for i in c_sum_list:
    c_sum_list_sum += i
c_sum_list.append(c_sum_list_sum)
print(*c_sum_list)

Submission status: Accepted

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

matrix = [(list(map(int, input().split()))) for i in range(r)]
total = [0] * c

for row in matrix:
    for i, elem in enumerate(row):
        print("{} ".format(elem), end="")
        total[i] += elem
    print(sum(row))

for total_col in total:
    print("{} ".format(total_col), end="")
print(sum(total))

Submission status: Accepted

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

mat = []
for row in range(r):
    row_index = list(map(int, input().split()))
    mat.append(row_index)


new_r = [0]*c
mat.append(new_r)

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

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

Submission status: Accepted

Solution code:
r,c=input().split()
r,c=[int(r),int(c)]
A=[0]*r
for i in range(r):
    A[i]=list(map(int, input().split()))
for i in range(r):
    sum1=0
    for j in range(c):
        sum1+=A[i][j]
    A[i].append(sum1)
b=[]
for i in range(c+1):
    sum2=0
    for j in range(r):
        sum2+=A[j][i]
    b.append(sum2)
for i in range(r):
    results=" ".join([str(m) for m in A[i]])
    print(results)
results2=" ".join([str(m) for m in b])
print(results2)

Submission status: Accepted

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

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

[(s.append(sum(s)) or print(*s)) for s in a]

print(*[sum(c)for c in zip(*a)])

Submission status: Accepted

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

tableA = []
resultC = []

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

for index_column in range(c):
    sumC = 0
    for index_row in range(r):
        sumC = sumC + tableA[index_row][index_column]
    resultC.append(sumC)

tableA.append(resultC)


for j in range(len(tableA)):
    tableA[j].append(sum(tableA[j]))

for i in tableA:
    print(*i, sep=" ")

Submission status: Accepted

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

res = [0] * c

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

Submission status: Accepted

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

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
nums = []
for i in range(r):
	nums.append(list(map(int, input().split())))
c_nums = [0 for i in range(c)]
for r_nums in nums:
	print(' '.join(list(map(str, r_nums))), sum(r_nums))
	index = 0
	for r_num in r_nums:
		c_nums[index] += r_num
		index += 1
print(' '.join(list(map(str, c_nums))), sum(c_nums))

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
table = [[int(x) for x in input().split()] for _ in range(r)]
for row in table:
    row.append(sum(row))
ex_lst = []
for col in zip(*table):
    ex_lst.append(sum(col))
table.extend([ex_lst])

for row in table:
    print(*row)

Submission status: Accepted

Solution code:
def main():
    n,m = map(int,input().split())
    sheet = [[0]*(m+1) for _ in range(n+1)]
    for i in range(n):
        r = list(map(int,input().split()))
        s = 0
        for j in range(m):
            sheet[i][j] = r[j]
            s += r[j]
            sheet[n][j] += r[j]
        sheet[i][m] = s
        sheet[n][m] += s
    for i in range(n+1):
        print (' '.join(map(str,sheet[i])))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(r):
    xlx[i][-1] = sum(xlx[i])
for i in range(c):
    tmp = 0
    for j in range(r):
        tmp += xlx[j][i]
    xlx[-1][i] = tmp

s = 0
for i in range(r):
    s += sum(xlx[i])-max(xlx[i])
xlx[-1][-1] = s

for i in range(r+1):
    print(*xlx[i])

Submission status: Accepted

Solution code:
n, m = tuple(map(int, input().split(" ")))
matrixA = [list(map(int, input().split(" "))) for i in range(n)]

temp_row = []
for i in range(m+1):
    temp_row.append(0)
matrixA.append(temp_row)

temp_col = []
cnt = 0
for i, row in enumerate(matrixA):
    if i == n:
        break
    row.append(sum(row))
    cnt += 1
    for j, column in enumerate(row):
        matrixA[n][j] += column
        
for row in matrixA:
    print(" ".join(map(str, row)))

Submission status: Accepted

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

A.append(add_l)

for i in range(r+1):
    print(*A[i])

Submission status: Accepted

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

for i in range(r):
    num = list(map(int, input().split()))
    sheet.append(num)
    
for i in sheet:
    last = sum(i)
    i.append(last)
    
inner = []
x = 0

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

for i in sheet:
    print(" ".join(map(str, 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())))
for i in range(r+1):
    if i != r:
        for j in range(c+1):
            if j != c:
                print(f'{a[i][j]} ', end='')
            else:
                print(sum(a[i]))
    else:
        for j in range(c+1):
            if j != c:
                print(f'{sum([b[j] for b in a])} ', end='')
            else:
                print(sum(map(sum, a)))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

[print(*data[i], sum(data[i])) for i in range(r)]
[print(sum([row[j] for row in data]), end = ' ') for j in range(c)]

s = 0
for k in range(r):
    s += sum(data[k])
print(s)

Submission status: Accepted

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

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

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

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

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

Submission status: Accepted

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

li = [list(map(int,input().split())) + [0] for _ in range(r)]
li = li+[[0]*(c+1)]

for i in range(c):
    tmp = 0
    for j in range(r+1):
        if j == r:
            li[j][i] = tmp
        tmp += li[j][i]

for i in range(r+1):
    li[i][c] = sum(li[i][:c])

for i in range(len(li)):
    print(*li[i])

Submission status: Accepted

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

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

for i in range(r):
    j = -1
    for strval in input().split():
        j += 1
        val = int(strval)
        data[i][j] = val
        sumr[i] += val
        sumc[j] += val

for i in range(r):
    for j in range(c):
        print(str(data[i][j]) + " ", end="")
    print(str(sumr[i]))

sumtotal = 0

for i in range(c):
    print(str(sumc[i]) + " ", end="")
    sumtotal += sumc[i]

print(sumtotal)

Submission status: Accepted

Solution code:
r,c=map(int,input().split())
l=[]
for i in range(r):
    l.append([int(x) for x in input().split()])
    l[i].append(sum(l[i]))
l.append([0 for x in range(c+1)])
for m in range(r):
    for n in range(c+1):
        l[-1][n]+=l[m][n]
for u in l:
    print(" ".join(map(str,u)))

Submission status: Accepted

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

table = []

for i in range(r):
    row = [int(item)for item in input().split()]
    row.append(sum(row))
    table.append(row)

lastrow=[0 for _ in range(c+1)]
for row in table:
    for i,cell in enumerate(row):
        lastrow[i]+=cell

table.append(lastrow)

for row in table:
    print(*row)

Submission status: Accepted

Solution code:
s = input().rstrip().split(' ')
h = int(s[0])
w = int(s[1])
lst = [[0] * w for i in range(h)]
for i in range(h):
  t = input().rstrip().split(' ')
  for j in range(w):
    lst[i][j] = int(t[j])
anssum = [0] * (w+1)
for k in range(h):
  ans = ""
  for l in range(w):
    ans += str(lst[k][l]) + " "
    anssum[l] += int(lst[k][l])
  ans += str(sum(lst[k]))
  anssum[w] += int(sum(lst[k]))
  print(ans)
ansbottom = ""
for m in range(w):
  ansbottom += str(anssum[m]) + " "
ansbottom += str(anssum[w])
print(ansbottom)

Submission status: Accepted

Solution code:
import math
import copy
from copy import deepcopy
import sys
import fractions
# import numpy as np
from functools import reduce
# import statistics
import decimal
import heapq
import collections
import itertools
sys.setrecursionlimit(100001)

# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


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

d = getSomeInputListInt(r)
d.append([])

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

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

d[r][c] = sum(d[r][0:c])

for tmp_d in d:
    print(*tmp_d, sep=" ")

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

a.append(b)

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

Submission status: Accepted

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

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

for data in dataset:
    data.append(sum(data))

total_data = []
for row in range(c+1):
    total_data.append(sum([data[row] for data in dataset]))
dataset.append(total_data)

for data in dataset:
    print(" ".join(map(str, data)))

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
A = []
B = []
C = []
for i in range(r):
    A.append(list(map(int, input().split())))
for i in range(r):
    b = [str(j) for j in A[i]]
    B.append(b)
    B[i].append(sum(A[i]))
for i in range(r):
    print(*B[i])

for i in range(c):
    S = 0
    for j in range(r):
        S += A[j][i]
    C.append(S)
C.append(sum(C))
print(*C)

Submission status: Accepted

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

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

t.append(s)

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

Submission status: Accepted

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

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

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

for j in range(c):
    s = 0
    for i in range(r):
        s += mat[i][j]
    mat[r][j] = s

mat[r][c] = (sum(mat[r]))

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

Submission status: Accepted

Solution code:
R,C = map(int,input().split())

table =[[0]*(C+1) for i in range(R+1)]

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

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

for col in range(C+1):
    for row in range(R):
        table[R][col] += table[row][col]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
R, C = map(int, input().split())
grid = [list(map(int, input().split())) for _ in range(R)]
for i in range(R):
    grid[i].append(sum(grid[i]))

total_RC = []
for c in range(C):
    sum_C = 0
    for r in range(R):
        sum_C += grid[r][c]
    total_RC.append(sum_C)
total_RC.append(sum(total_RC))
grid.append(total_RC)
[print(*g) for g in grid]

Submission status: Accepted

Solution code:
r, c = [int(i) for i in input().split()]
ss = []
for _ in range(r):
    s = [int(i) for i in input().split()]
    ss.append(s + [sum(s)])

ans = [[i[j] for i in ss] for j in range(c+1)]
ss.append([sum(i) for i in ans])
print("\n".join(" ".join(map(str, i)) for i in ss))

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(0,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())
lst=[list(map(int,input().split()))for i in range(r)]
all_lst=[0 for i in range(c+1)]
for mini_lst in lst:
    for i in range(c):
        all_lst[i]+=mini_lst[i]
    mini_sum=sum(mini_lst)
    all_lst[-1]+=mini_sum
    mini_lst.append(mini_sum)
    print(' '.join(map(str,mini_lst)))
print(' '.join(map(str,all_lst)))

Submission status: Accepted

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

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

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

for i in t:
    print(*i)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
r,c = map(int,input().split())
table = list()
last_t = list()
for i in range(r):
    a = list(map(int,input().split()))
    table.append(a)

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

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

for i in range(r+1):
    for j in range(c+1):
        if j >=1 and j<c:
            print(" "+str(table[i][j]),end="")
        elif j == c:
            print(" "+str(table[i][j]))
        else:
            print(table[i][j],end="")

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
row = []
for i in range(r):
  row.append(input().split())
  row[i] = [int(n) for n in row[i]]
  rowsum = 0
  for j in range(c):
    rowsum += row[i][j]
    # print(row[i][j], end=" ")
  row[i].append(rowsum)
  # print(row[i][c])

# for i in range(r):
#   for j in range(c+1):
#     print(row[i][j], end=' ')
#   print()

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

# for i in range(c+1):
#   if i==c:
#     print(calsum[i])
#   else:
#     print(calsum[i],end=' ')

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

Submission status: Accepted

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

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

col_sum_list = [0 for i in range(len(table[0]))]
for line in table:
    line_sum = 0
    for i in range(len(line)):
        line_sum += line[i]
        col_sum_list[i] += line[i]
    line.append(line_sum)
col_sum_list.append(sum(col_sum_list))

for line in table:
    line = [str(i) for i in line]
    print(' '.join(line))

col_sum_list = [str(i) for i in col_sum_list]
print(' '.join(col_sum_list))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
data = [list(map(int, input().split())) for i in range(n)]
count = 0
side = [0] * (m+1)
for i in data:
  total = 0
  for j in i:
    total += j
  data[count].append(total)
  count += 1
for k in data:
  side = [x + y for (x, y) in zip(side, k)]
data.append(side)

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

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):
    a[i].append(sum(a[i]))

na = []
for i in range(c + 1):
    na.append(sum([j[i] for j in a]))
a.append(na)

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

Submission status: Accepted

Solution code:

def outputTable (table):
  r = len(table)
  c = len(table[0])
  for i in range(r):
    for j in range(c-1):
      print(str(table[i][j])+' ',end='')
    print(str(table[i][j+1]))


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

ans_r = r+1
ans_c = c+1

table = [[0 for i in range(ans_c)] for j in range(ans_r)]
for i in range(r):
  inputRow = list(map(int,input().split()))
  for j in range(c):
    table[i][j] = inputRow[j]
  table[i][c] = sum(inputRow)

for i in range(ans_c):
  table[r][i] = sum([row[i] for row in table[:][:r]])
outputTable(table)

Submission status: Accepted

Solution code:
spreadsheet = []
total = 0
r, c = list(map(int, input().split()))
for i in range(r):
    listTmp = []
    listTmp = list(map(int, input().split()))
    spreadsheet.append(listTmp)
for j in range(r):
    for k in range(c):
        print(spreadsheet[j][k], end=" ")
    print(sum(spreadsheet[j]))
for m in range(c):
    cTotal = 0
    for n in range(r):
        cTotal += spreadsheet[n][m]
    print(cTotal, end=" ")
    total += cTotal
print(total)

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[r][j] += l[j]
    A[i][c] = sum(l)
    A[r][c] += sum(l)

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

y=list(map(int,input().split()))
y.append(sum(y))
print(" ".join(list(map(str,y))))
for i in range(b):
  bottom_list.append(y[i])

for h in range (a-1):
  y=list(map(int,input().split()))
  y.append(sum(y))
  print(" ".join(list(map(str,y))))
  for i in range(b):
    bottom_list[i]+=y[i]
  
bottom_list.append(sum(bottom_list))
print(" ".join(list(map(str,bottom_list))))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def main():
    r, c = map(int, input().split())
    tab = [list(map(int, input().split())) for i in range(r)]

    col_sums = [0] * c
    
    for i in range(r):
        tmp = 0
        for j in range(c):
            tmp += tab[i][j]
            col_sums[j] += tab[i][j]
            print(tab[i][j], end=" ")
        print(tmp)
    
    tmp = 0
    for i in range(c):
        tmp += col_sums[i]
        print(col_sums[i], end=" ")
    print(tmp)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

def sa(Type= int):
  return [Type(x) for x in input().split()]

def solve():
  r, c = sa()

  mat = []

  for _ in range(r):
    arr = sa()
    arr.append(sum(arr))

    mat.append(arr)

  arr = []
  for i in range(c+1):
    arr.append(sum([mat[x][i] for x in range(r)]))

  mat.append(arr)

  print('\n'.join([' '.join([str(s) for s in x]) for x in mat]))

if __name__ == '__main__':
  # sys.stdin = open('input.txt', 'r')
  solve()

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
H,W = map(int,input().split())

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

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

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

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
table = [[0 for i in range(c+1)]for j in range(r+1)]
for i in range(r):
    a = list(map(int, input().split()))
    for j in range(c):
        table[i][j] = a[j]
for i in range(r):
    for j in range(c):
        table[i][-1] += table[i][j]
        table[-1][j] += table[i][j]
    table[-1][-1] += table[i][-1]
for i in range(r+1):
    for j in range(c+1):
        if j > 0:
            print(" ", end="")
        print(table[i][j], end="")
    print()

Submission status: Accepted

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

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

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

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

for i in range(r+1):
    print(*co[i])

Submission status: Accepted

Solution code:
a,b=map(int,input().split())

table=[[0]*b for i in range(a)]

for j in range(a):
    l=list(map(int,input().split()))
    for k in range(b):
        table[j][k]=l[k]

for j in range(a):
    sum1=0
    for k in range(b):
        print("%d " %(table[j][k]), end="")
        sum1+=table[j][k]
    print("%d" %(sum1))

sum3=0
for k in range(b):
    sum2=0
    for j in range(a):
        sum2+=table[j][k]
    sum3+=sum2
    print("%d " %(sum2), end="")
print(sum3)

Submission status: Accepted

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

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

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

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

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

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

Submission status: Accepted

Solution code:
def main(r, c, inputs):
    csum = [0]*(c+1)
    for input in inputs:
        input.append(sum(input))
        for i in range(len(input)):
            csum[i] += input[i]
    inputs.append(csum)
    row = [" ".join(map(str, i)) for i in inputs]
    return '\n'.join(map(str, row))


if __name__ == "__main__":
    r, c = map(int, input().split())
    inputs = [list(map(int, input().split())) for i in range(r)]
    print(main(r, c, inputs))