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

list_2d = []
for i in range(r):
    list_1d = [int(x) for x in input().split()]
    list_2d.append(list_1d)
    
for i in range(r):
    sum_r = sum(list_2d[i])
    list_2d[i].append(sum_r)

list_2d_last = []
for i in range(c):
    sum_c = 0
    for k in range(r):
        sum_c += list_2d[k][i]
    list_2d_last.append(sum_c)
    
list_2d.append(list_2d_last)
list_2d[r].append(sum(list_2d[r]))

for a in list_2d:
    print(*a)

Submission status: Accepted

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

for i in range(r):
    sc = input().split()
    for j in range(c):
        a[i][j] = int(sc[j])
for i in range(r):
    for j in range(c):
        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 == 0:
            print(a[i][j], end = '')
        else:
            print(' {}'.format(a[i][j]), end = '')
    print('')

Submission status: Accepted

Solution code:
r,c = map(int,input().split())
sheet = [list(map(int,input().split())) for i in range(r)]
for j in range(r):
         sheet[j].append(sum(sheet[j]))
newrow = []
for k in range(c+1):
         tmp = 0
         for l in range(r):
                  tmp  += sheet[l][k]
         newrow.append(tmp)
sheet.append(newrow)
for m in range(r+1):
         print(*sheet[m])

Submission status: Accepted

Solution code:
import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

r, c = map(int, readline().split())
A = []
for _ in range(r):
    x = [int(i) for i in readline().split()]
    x.append(sum(x))
    A.append(x)

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

for i in A:
    print(*i)

Submission status: Accepted

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

Submission status: Accepted

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

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

total = 0
for row in range(r):
    Arow = list(map(int, input().split()))
    for col in range(c):
        total += Arow[col]
        A[row][col] = Arow[col]
        A[r][col] += Arow[col]
        A[row][c] += Arow[col]
A[r][c] = total

for row in range(r + 1):
    for col in range(c + 1):
        if col < c:
            print("{} ".format(A[row][col]), end="")
        else:
            print(A[row][col], end="")
    print()

Submission status: Accepted

Solution code:
d = {}
r, c = [int(i) for i in input().split()]
a = [input() for i in range(r)]
for i in range(r):
    d[i] = [int(j) for j in a[i].split()]

for i in range(r):
    print(" ".join(map(str,d[i]))+" ", end="")
    print(sum(d[i]))

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

Submission status: Accepted

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

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

for i in range(r+1):
  for j in range(c):
    print(cells[i][j], end=" ")
  print(cells[i][c])

Submission status: Accepted

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

col = []
for i in range(c + 1) :
    element = 0
    for j in range(r) :
        element += ans[j][i]
    col.append(element)

ans.append(col)

for col in ans :
    print(" ".join(map(str, col)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
rc = input()
rc = rc.split()
r,c = int(rc[0]),int(rc[1])
rc_list = list()
c_list = [[] for i in range(c)]
for i in range(r):
    rc_set = input()
    rc_set = rc_set.split()
    rc_list.append([])
    r_text = ''
    for j,n in enumerate(rc_set):
        rc_list[-1].append(int(n))
        r_text = r_text + n + ' '
        c_list[j].append(int(n))
    else:
        r_text = r_text + str(sum(rc_list[-1]))
        print(r_text)
else:
    c_text = ''
    t_sum = 0
    for c in c_list:
        s = sum(c)
        t_sum += s
        c_text = c_text + str(s) + ' '
    else:
        c_text = c_text + str(t_sum)
        print(c_text)

Submission status: Accepted

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

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


for i in rc:
    print(*i)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
sheet = [list(map(int,input().split())) for _ in range(r)]
for num, rec in enumerate(sheet):
    sheet[num] += [sum(rec)]
    print(*sheet[num])
print(*map(sum,zip(*sheet)))

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

Submission status: Accepted

Solution code:
r,c = list(map(int,input().split()))
ans = [[0] * (c + 1) for i in range (r + 1)]
for i in range (r):
    s = list(map(int,input().split()))
    for k in range (c):
        ans[i][k] = s[k]
    ans[i][c] = sum(s)
for j in range (c + 1):
    for k in range (r):
        ans[r][j] = ans[r][j] + ans[k][j]
for i in ans:
    k = 0
    for j in i:
        if k == 0:
            k = 1
            print(j,end = "")
        else:
            print(" " + str(j),end = "")
    print()

Submission status: Accepted

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

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

for i in range(b+1):
    aa.append(sum([a[i] for a in bs]))
bs.append(aa)

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

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
l = list(list(map(int, input().split())) for _ in range(r))

col_sum = [0]*(c+1)
for li in l:
    li.append(sum(li))
    for i in range(c+1):
        col_sum[i] += li[i]

for li in l:
    print(*li)
print(*col_sum)

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
t = []
l = [0]*(c+1)
for _ in range(r):
    *_r, = map(int, input().split())
    _r.append(sum(_r))
    t.append(_r)

    l = [_l+__r for _l, __r in zip(l, _r)]

for _t in t:
    print(*_t)
print(*l)

Submission status: Accepted

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

for i in range(r):
    tmp=sum(spl[i])
    spl[i].append(tmp)

cnt=[]
for j in range(c+1):
    tmp=0
    for k in range(r):
        tmp+=spl[k][j]
    cnt.append(tmp)

spl.append(cnt)

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

for i in range(r):
    for j in range(c):
        print(A[i][j],end=" ")
    print(tate[i])
for i in range(c):
    print(yoko[i],end=" ")
print(sum(tate))

Submission status: Accepted

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

s = ([0 for x in range(c)])

for i in range(r):
    cell = ([int(x) for x in input().split()])
    
    cell_sum = 0
    for j in range(c):
        print(cell[j], end=' ')
        
        s[j] += cell[j]
        cell_sum += cell[j]
    print(cell_sum)

total = 0;
for i in s:
    print(i, end=' ')
    
    total += i
    
print(total)

Submission status: Accepted

Solution code:
import sys

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

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

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

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

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

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 = list(map(int, input().split()))
answer = []

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

sumLine = [0] * (c + 1)
for i in range(len(answer)):
    for j in range(c + 1):
        sumLine[j] += answer[i][j]

answer.append(sumLine)

[print(*answer[i]) for i in range(len(answer))]

Submission status: Accepted

Solution code:
r,c=(int(x) for x in input().split())
A=[[0 for i in range(c)] for j in range(r)]
b=[0]*r
d=[0]*(c+1)
for i in range(r):
    A[i]=[int(x) for x in input().split()]
for i in range(r):
    for j in range(c):
        b[i]+=A[i][j]
for i in range(c):
    for j in range(r):
        d[i]+=A[j][i]
for i in range(r):
    d[c]+=b[i]
for i in range(r):
    for j in range(c+1):
        if j!=c:
            print(A[i][j],end=" ")
        else:
            print(b[i])
for i in range(c):
    print(d[i],end=" ")
print(d[c])

Submission status: Accepted

Solution code:
R,C = map(int,input().split(' '))
c_list = [0] * (C + 1)
for r in range(R):
    r_list = list(map(int,input().split(' ')))
    r_list.append(sum(r_list))
    print(*r_list)
    c_list = [r + c for r,c in zip(r_list,c_list)]
print(*c_list)

Submission status: Accepted

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

calc_table = []
res_table = []

for _ in range(r):
	calc_table = list(map(int,input().split()))
	num = 0
	for i in calc_table:
		num += i
	calc_table.append(num)
	print(" ".join(str(a) for a in calc_table))
	res_table.append(calc_table)

last_table = []
for j in range(c + 1):
	last_num = 0
	for k in range(r):
		last_num += res_table[k][j]
	last_table.append(last_num)
print(" ".join(str(a) for a in last_table))

Submission status: Accepted

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

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

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

for i in range(len(table)):
    for j in range(len(table[0])):
        if j != c:
            print(f"{table[i][j]} ", end='')
        else:
            print(table[i][j])

Submission status: Accepted

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

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

ans = 0
for i in range(r):
    for j in range(c):
        print('{} ' .format(table[i][j]), end='')
        ans += table[i][j]
    print(ans)
    ans = 0

total = 0
for i in range(c):
    for j in range(r):
        ans += table[j][i]
    print('{} ' .format(ans), end='')
    total += ans
    ans = 0
print(total)

Submission status: Accepted

Solution code:
#初期値の挿入
list_xy = list(map(int, input().split()))
result_data = [[0 for y in range(list_xy[1]+1)] for x in range(list_xy[0]+1)] 

#表dataの入力と計算
for x in range(list_xy[0]):
    input_data = list()
    input_data = list(map(int, input().split()))
    for y in range(list_xy[1]):
        result_data[x][y] = input_data[y]
        result_data[x][list_xy[1]] += input_data[y]
        result_data[list_xy[0]][y] += input_data[y]
    result_data[list_xy[0]][list_xy[1]] += result_data[x][list_xy[1]]

#計算結果の表示
for a in result_data:
    print(*a)

Submission status: Accepted

Solution code:
r,c = list(map(int, input().split() ))
table = [[0 for i in range(c)] for j in range(r)];
rm = [0 for i in range(r)]
cm = [0 for i in range(c)]
for ri in range(r):
 table[ri] = list(map(int, input().split() ))
 rm[ri] = sum(table[ri])
for ci in range(c):
 for ri in range(r):
  cm[ci] = cm[ci] + table[ri][ci]
for ri in range(r):
 print(" ".join(map(str,table[ri])), end = "" )
 print(f" {rm[ri]}")
print(" ".join(map(str, cm)), end="")
print(f" {sum(cm)}")

Submission status: Accepted

Solution code:
queue=[]
vector=[]
first_num=[int(w) for w in input().split()]

for i in range(first_num[0]):
    queue.append([int(w) for w in input().split()])

for i in range(first_num[0]):
    sum=0
    for w in range(first_num[1]):
        sum+=queue[i][w]
    queue[i].append(sum)

for i in range(first_num[1]+1):
    sum=0
    
    for w in range(first_num[0]):
        sum+=queue[w][i]
        
    vector.append(sum)
    
queue.append(vector)

for i in range(first_num[0]+1):
    print(' '.join(map(str,queue[i])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
l = list(map(int,input().split()))
r = l[0]
c = l[1]

#各列毎の合計
lst = [0 for i in range(c)]

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

    print(*temp,sum(temp))

print(*lst,sum(lst))

Submission status: Accepted

Solution code:
c=[]
d=[]
dd = []
a,b = map(int,input().split())
for i in range(a):
    c.append(list(input().split()))
    d.append([int(s) for s in c[i]])
for i in range(a) :
    f = sum(d[i])
    d[i].append(f)
for i in range(b+1):
    ff=0
    for j in range(a):
        ff = ff + d[j][i]
    dd.append(ff)
d.append(dd)
for i in range(a+1):
        print(*d[i])

Submission status: Accepted

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

Submission status: Accepted

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

result = []
for _ in range(r):
    r_vec = list(map(int, input().split()))
    r_vec.append(sum(r_vec))
    result.append(r_vec)

last_row = [0] * (c + 1)
for i in range(r):
    for j in range(c+1):
        last_row[j] += result[i][j]
result.append(last_row)
        
for i in range(r+1):
    print(" ".join(map(str, result[i])))

Submission status: Accepted

Solution code:
r,c=map(int, input().split())
mat = []
for y in range(r):
	mat.append(list(map(int,input().split())))
	
cols = [0]*c

for row in mat:
	print(" ".join(list(map(str, row))), end=" ")
	print(sum(row))
	for i in range(c):
		cols[i] += row[i]

print(" ".join(list(map(str, cols))), end=" ")
print(sum(cols))

Submission status: Accepted

Solution code:
#7_C
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):
    row = list(map(int, input().split()))
    row_sum = sum(row)
    mat[i][c] = row_sum
    for j in range(c):
        mat[i][j] = row[j]

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

for i in range(r+1):
    row = str(mat[i][0])
    for j in range(c):
        j = j + 1
        row += " " + str(mat[i][j])
    print(row)

Submission status: Accepted

Solution code:
# rとcを受け取る
r, c = map(int, input().split())

# 表を受け取る
rc = [list(map(int, input().split())) for i in range(r)]

# 処理実行
for j in rc:
    sumr = sum(j)
    j.append(sumr)
    print(" ".join(map(str, j)))

last = []
for k in range(c + 1):
    sumc = 0
    for l in range(r):
        sumc += rc[l][k]
    last.append(sumc)
print(" ".join(map(str, last)))

Submission status: Accepted

Solution code:
r,c=list(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):
    mat[i].append(sum(mat[i]))

for i in range(c):
    s=0
    for j in range(r):
        s+=mat[j][i]
    mat[r][i]=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 = [int(i) for i in input().split()]
table = [list(map(int, input().split())) for _ in range(r)]
for row in table:
    row.append(sum(row))
table.append([sum(column) for column in zip(*table)])
for row in table:
    print(*row)

Submission status: Accepted

Solution code:
r,c = map(int, input().split())
L = [[int(l) for l in input().split()] for _ in range(r)]

ans = [[0]*(c+1) for _ in range(r+1)]
for i in range(r):
    cnt = 0
    for j in range(c+1):
        if j != c:
            cnt += L[i][j]
            ans[i][j] = L[i][j]
        else:
            ans[i][j] = cnt
            
for i in range(r):
    for j in range(c+1):
        ans[r][j] += ans[i][j]
        
for i in range(r+1):
    print(*ans[i])

Submission status: Accepted

Solution code:
r,c=map(int,raw_input().split())
a=[map(int,raw_input().split()) for i in range(r)]
b=[0 for i in range(c+1)]
for i in range(r):
    a[i].append(sum(a[i]))
    for j in range(c+1):
        b[j]+=a[i][j]
a.append(b)
l=""
for i in range(r+1):
    for j in range(c+1):
        print (a[i][j]),
    print

Submission status: Accepted

Solution code:
def create_new_table2(table):

    v = list()

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

    table.append(v)

    for i in range(len(table)):
        for j in range(len(table[i])):
            print(str(table[i][j]), end="")
            
            if j != len(table[i]) - 1:
                print(" ", end="")

        print("\n", end="")

if __name__ == "__main__":
    
    param = input().split(" ")
    r = int(param[0])
    c = int(param[1])

    table = list()

    l = r
    
    while(l):

        lines = input().split(" ")

        line = list([ int(n) for n in lines])
        s = sum(line)
        line.append(s)

        table.append(line)

        l -= 1

    create_new_table2(table)

Submission status: Accepted

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

table = []
for _ in range(r):
    temp = [int(x) for x in input().split()]
    temp.append(sum(temp))
    table.append(temp)
    
c_sum = [0 for _ in range(c + 1)]
for i in range(r):
    for j in range(c + 1):
        c_sum[j] += table[i][j]
table.append(c_sum)

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

Submission status: Accepted

Solution code:
#行数ｒ、列数ｃを入力
r,c = map(int,input().split())

#r x c の行列Aの入力
A = [[int(i) for i in input().split()]for j in range(r)]

#各行と各列をそれぞれたして行列に追加
for i in range(r):
    addr = 0 #行の合計
    for j in range(c):
        addr += A[i][j]
    A[i].append(addr) #各行の最後に追加

B = list(map(list,(zip(*A)))) #リストAの行列を転置したBを作成
for i in range(c+1): #行を追加してサイズが1増えたから
    addc = 0 #もとの列の合計(転置後の行の合計)
    for j in range(r):
        addc += B[i][j]
    B[i].append(addc) #リストに追加

A = list(map(list,(zip(*B)))) #Bを転置してもとに戻す

for i in range(r+1):
    for j in range(c+1):
        if j < c:
            print(A[i][j],end=" ")
        elif j == c:
            print(A[i][j])

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[i] = list(map(int, input().split()))
    a[i].append(sum(a[i]))
for j in range(c + 1):
    for i in range(r):
        a[r][j] += a[i][j]
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:
r, c = map(int, input().split())
sheet = [[0 for i in range(c)] for j in range(r+1)]
for i in range(r):
    sheet[i] = list(map(int, input().split()))
    sheet[i].append(0)
    for j in range(c):
        sheet[i][c] += sheet[i][j]
sheet[r].append(0)
for k in range(c+1):
    for l in range(r):
        sheet[r][k] += sheet[l][k]
for m in range(r+1):
    for n in range(c):
        print(sheet[m][n], end=" ")
    print(sheet[m][n+1])

Submission status: Accepted

Solution code:
r,c  = map(int, input().split())
tbl = []
tblS = [0 for i in range(c+1)]
for i in range(r):
    tbl.append(input())
    tmpL = tbl[i].split()
    tmpL = [int(j) for j in tmpL]
    print(tbl[i] ,sum(tmpL))
    
    for j in range(c):
        tblS[j] += int(tbl[i].split()[j])
    
    tblS[c] += sum(tmpL)

print(*tblS)

Submission status: Accepted

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

sr = []

for i in range(r):
  row = [i for i in map(int, input().split())]
  row.append(sum(row))
  print(' '.join(map(str, row)))
  sr = row if i == 0 else [sr[i] + row[i] for i in range(c + 1)]

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

Submission status: Accepted

Solution code:
list = []
r,c=map(int,input().split())
all_ttl = 0
for i in range(r):
    s = input()
    ttl = 0
    cnt = 0
    for a in map(int, s.split()):
        if i==0:
            list.append(a)
        else:
            list[cnt] += a
        ttl += a
        cnt += 1
    s = s + " " + str(ttl)
    all_ttl += ttl
    print(s)
s = ""
for a in list:
    if s == "":
        s = str(a)
    else:
        s = s + " " + str(a)
print(s + " " + str(all_ttl))

Submission status: Accepted

Solution code:
r,c = map(int,input().split())
rowsum = [0 for i in range(c)]
for i in range(r):
    colsum = 0
    nums = [int(e) for e in input().split()]
    for j in range(c):
        print(nums[j],end=" ")
        colsum = colsum + nums[j]
        rowsum[j] = rowsum[j] + nums[j]
    print(colsum)
print(*rowsum,end = " ")
print(sum(rowsum))

Submission status: Accepted

Solution code:
r ,c = map(int,input().split())
l = [[int(x) for x in input().split()] for i in [0]*r]
s = [0]*(c+1)
for j in range(r):
    l[j] += [sum(l[j])]
    for k in range(c+1):
        s[k] += l[j][k]
for m in range(r):
    print(*l[m])
print(*s)

Submission status: Accepted

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

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

for i in range(len(sheet)):
    for j in range(len(sheet[i])):
        print(sheet[i][j],end="")

        if(j<len(sheet[i])-1):
            print(" ",end="")
    print()

Submission status: Accepted

Solution code:
r, c = map(int,input().split())
print_list_sum = lambda l : print(" ".join(map(str,l)) + " " + str(sum(l)))
a = [list(map(int,input().split())) for _ in range(r)]
s = [0] * c
for i in range(r):
    for j in range(c):
        s[j] += a[i][j]
    print_list_sum(a[i])
print_list_sum(s)

Submission status: Accepted

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

for i in range (r): #行の構築
    _line = list(map(int, input().split()))
    _line.append(sum(_line))
    matrix.append(_line)

_col_sum = [] #列の構築
for j in range (c+1):
    num = 0
    for i in range (r):
        num += matrix[i][j]
    _col_sum.append(num)

matrix.append(_col_sum)

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

Submission status: Accepted

Solution code:

r,c=map(int,input().split())
m=[[]for i in range(r)]
for i in range(r):
    m[i]=list(map(int,input().split()))
sc=[0]*c
for i in range(r):
    for j in range(c):
        sc[j]+=m[i][j]
for er in m:
    print(*er,end=' ')
    print(sum(er))
print(*sc,end=' ')
print(sum(sc))

Submission status: Accepted

Solution code:
number_of_rows, number_of_columns = list(map(int, input().split(" ")))
rows = [list(map(int, input().split(" "))) for i in range(number_of_rows)]

for j in range(number_of_rows):
    for k in range(number_of_columns ):
        if k == number_of_columns - 1:
            print(rows[j][k],end=" ")
            print(sum(rows[j]))
            rows[j].append(sum(rows[j]))
        else:
            print(rows[j][k],end=" ")
ans = []

for l in range(number_of_columns + 1):
    plus = 0
    for m in range(number_of_rows):
        plus += rows[m][l]
    ans.append(plus)
for n in range(number_of_columns + 1):
    if n == number_of_columns:
        print(ans[n])
    else:
        print(ans[n],end=" ")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
lst_input_num = list(map(int, input().split()))
r, c = lst_input_num[0], lst_input_num[1]
lst = []
lst_row = []

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

for i in range(c):
    lst_column = []
    for j in range(r):
        lst_column.append(lst[j][i])

    lst_row.append(sum(lst_column))

lst.append(lst_row) 

count = 0
for i in lst:
    for j in i:
        print(j, end=" ")

    print(sum(i))

Submission status: Accepted

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

csum = [0 for _ in range(c+1)]
for i in range(r):
    table[i].append(sum(table[i]))
    print(*table[i])
    for j in range(c+1):
        csum[j] += table[i][j]
print(*csum)

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, *D = map(int, open(0).read().split())
A = [D[i:i+c] for i in range(0, r*c, c)]
A.append([0 for _ in range(c+1)])
for i in range(r):
    A[i].append(sum(A[i]))
    for j in range(c+1):
        A[r][j] += A[i][j]
for i in range(r+1):
    print(' '.join(map(str, A[i])))

Submission status: Accepted

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

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

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

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