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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

tmpc=[0 for _ in range(c+1)]
for i in range(r):
    tmpr=0
    for j in range(c):
        tmpr+=s[i][j]
        tmpc[j]+=s[i][j]
    s[i].append(tmpr)
    tmpc[-1]+=tmpr
s.append(tmpc)
for i in range(r+1):
    for j in range(c):
        print(s[i][j],end=" ")
    print(s[i][-1])

Submission status: Accepted

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

for i in range(n):
    print(*a[i],sum(a[i]))

c=[0]*m
for i in range(m):
    for j in range(n):
        c[i]=a[j][i]+c[i]
print(*c,sum(c))

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
nums = []
for i in range(r):
    i = list(map(int, input().split()))
    i_add = sum(i)
    i.append(i_add)
    nums.append(i)
last = []
for j in range(c):
    add_num = 0
    for k in range(r):
        add_num += nums[k][j]
    last.append(add_num)
last_sum = sum(last)
last.append(last_sum)
nums.append(last)
for i in nums:
    L = [str(m) for m in i]
    print(' '.join(L))

Submission status: Accepted

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

for i in range(0, r):
  s = sum(l[i])
  l[i].append(s)
  print(' '.join(map(str,l[i])))

ele = []
for i in range(0, c + 1):
  e = 0
  for j in range(0, r):
    e += l[j][i]
  ele.append(e)

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

Submission status: Accepted

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

for i in range(r):
    rTotal = 0
    for j in range(c):
        rTotal += int(T[i][j])
    
    T[i].append(rTotal)

newT = []

for i in range(c):
    cTotal = 0
    for j in range(r):
        cTotal += int(T[j][i])
    
    newT.append(cTotal)

total = 0
for i in range(len(newT)):
    total += newT[i]

newT.append(total)
T.append(newT)

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

Submission status: Accepted

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

spread_list=[ [0]*c ] * (r+1) 

for i in range( r ):# スプレッドシート入力
    spread_list[i] = list ( map( int,input().split()) )
    spread_list[i].append( sum (spread_list[i]) )

spread_list[r].append( 0 )

for ci in range( c+1 ):
    sumer = 0
    for ri in range(r):
        sumer += spread_list[ri][ci]
    spread_list[r][ci] = sumer

for a in spread_list:
    print(*a, sep=' ')

Submission status: Accepted

Solution code:
table = [[0 for i in range(101)]for j in range(101)]

row,column = map(int,input().split())

for r in range(row):
    lst = list(map(int,input().split()))
    for c in range(column):
        table[r][c] += lst[c]
        
for c in range(column):#行の合計値
    total = 0
    for r in range(row):
        total += table[r][c]
    table[row][c] = total
    
for r in range(row+1):#列の合計値
    table[r][column] = sum(table[r])#1～100列目まで合計してるけどまあ良いでしょ


for r in range(row+1):
    lst = []
    for c in range(column+1):
        lst.append(table[r][c])
    lst = [str(i) for i in lst]
    print(" ".join(lst))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    try:
        n,m = map(int, input().split())
        b = []
        for j in range(n):
            a = list(map(int,input().split()))
            b.append(a)    
            S = sum(a)
            c = list(zip(*b))
            D = [sum(x)for x in c]
            X = sum(D)
            print(*a,S)
        print(*D,X)
    except:
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
L, tl = [], []
for i in range(r):
    L.append(list(map(int, input().split())))
    L[i].append(sum(L[i]))
for i in range(c+1):
    tl.append(sum(l[i] for l in L))
L.append(tl)
for i in range(r+1):
    print(' '.join(str(x) for x in L[i]))

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 k in range(r):
    b = input().split()
    b_int = [int(s) for s in b ]
    for s in range(len(b_int)):
        a[k][s] = b_int[s]
i = 0
j = 0
for i in range(r):
    for j in range(c):
        a[i][c]+=a[i][j]
i = 0
j = 0
for i in range(c+1):
    for j in range(r):
        a[r][i]+=a[j][i]
i = 0
for i in range(r+1):
    print(' '.join(map(str,a[i])))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
c = []
for i in range(n):
    x= list(map(int, input().split()))
    x.append(sum(x))
    c.append(x)
    print(*x)
#print(c)
d = [0 for i in range(m+1)]
for i in range(n):
    for j in range(m+1):
        d[j]+=c[i][j]
print(*d)

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):
    print(*a[i],sum(a[i]))
y=0
for i in range(c):
    x=0
    for j in range(r):
        x+=a[j][i]
    y+=x
    print(x,end=' ')
print(y)

Submission status: Accepted

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

print(" ".join(map(str,an[r])))

Submission status: Accepted

Solution code:
def mapt(fn, *args):
    return list(map(fn, *args))

def Array(listseq):
    return mapt(Vector, listseq)

def Vector(lines):
    return mapt(str, lines)
    
    
r, c = mapt(int, input().split(" "))
arrays = [mapt(int, input().split(" ")) for i in range(r)]

def calc(arrays, r):
    y_axis = [sum(i) for i in zip(*arrays)]
    arrays.append(y_axis)
    x_axis = [sum(i) for i in arrays]
    for i in range(r+1):
        arrays[i].append(x_axis[i])
    for row in Array(arrays):
        print(" ".join(row))

calc(arrays, r)

Submission status: Accepted

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

Submission status: Accepted

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

matrix = []
column_sum = [0]*(c+1)

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

for row in matrix:
    row_sum = 0
    for i in range(len(row)):
        row_sum += row[i]
        column_sum[i] += row[i]
    row.append(row_sum)
    column_sum[c] += row_sum
matrix.append(column_sum)

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
W=[list(map(int,input().split())) for i in range(N)]
E=[0]*(M+1)
for h in range(N):
  a=sum(W[h])
  W[h].append(a)
for l in range(N):
  for g in range(M+1):
    E[g]+=W[l][g]
W.append(E)
for e in range(N+1):
  for b in range(M+1):
    if b!=M:
      print(W[e][b],end=" ")
    else:
      print(W[e][b])

Submission status: Accepted

Solution code:
#
# 7c
#

def main():
    r, c = map(int, input().split())
    T = []
    S = [0 for _ in range(c+1)]
    for i in range(r):
        C = list(map(int, input().split()))
        C.append(sum(C))
        T.append(C)
    for i in range(r):
        for j in range(c+1):
            S[j] += T[i][j]
    T.append(S)
    for i in range(r+1):
        print(*T[i])


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
table = [list(map(int, input().split())) for _ in range(r)]
c_sum = [0]*c
for i in range(r):
    for j in range(c):
        c_sum[j] += table[i][j]
for i in table:
    print(*i, end=' ')
    print(sum(i))
print(*c_sum, end=' ')
print(sum(c_sum))

Submission status: Accepted

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


A = [[int(x) for x in input().split()] for l in range(r)]
newA = [[0]*(c+1) for i in range(r+1)]

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

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

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
input_sheet = [[0]*m]*n
add_migi = [0]*n
add_shita = [0]*(m+1)
output_sheet = [[0 for i in range(m+1)] for j in range(n+1)]
for i in range(n):
  input_sheet[i] = list(map(int, input().split()))
  output_sheet[i][m] = sum(input_sheet[i])
  for j in range(m):
    output_sheet[i][j] = input_sheet[i][j]
for j in range(m):
  for i in range(n):
    output_sheet[n][j] += input_sheet[i][j]
output_sheet[n][m] = sum(map(sum, input_sheet))

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

Submission status: Accepted

Solution code:
r,c = map(int,input().split())
result = [0 for i in range(c+1)]
for _ in range(r):
    add = [int(x)for x in input().split()]
    add.append(sum(add))
    print(" ".join([str(x) for x in add]))
    result = [i + j for i,j in zip(result,add)]
print(" ".join([str(x) for x in result]))

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

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

  print("")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
r,c=map(int,input().split())
tbl=[[0 for i in range(c+1)] for j in range(r+1)]
for i in range(r):
    a = list(map(int,input().split()))
    a_1 = len(a)
    b = 0
    for j in range(a_1):
        tbl[i][j] = a[j]
        b += a[j]
    tbl[i][c] = b
for k in range(c+1):
    d = 0
    for l in range(r):
        d += tbl[l][k]
    tbl[r][k] = d
for m in tbl:
    print(*m)

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)]
lst=[[int(a) for a in input().split()] for x in range(r)]

for k in range(r):
    for l in range(c):
        a[k][l]=lst[k][l]
        
for n in range(r+1):
    for m in range(c,c+1):
        a[n][m]=sum(a[n])
        
for n in range(c):
    s=0
    for m in range(r):
        s+=a[m][n]
    a[r][n]=s
a[r][c]=sum(a[r])
for n in range(r+1):
    print(*a[n])

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

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

Submission status: Accepted

Solution code:
#71 表計算

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]))
    
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:
row, col = map(int, input().split())
table = [list(map(int, input().split())) for _ in range(row)]
ans   = [[0 for c in range(col+1)] for r in range(row+1)]

for r in range(row):
    for c in range(col+1):
        if c == col:
            ans[r][c] = sum(table[r][:])
        else:
            ans[r][c] = table[r][c]
        ans[row][c] += ans[r][c]
        
    print(*ans[r][:])
print(*ans[row][:])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
num=list(map(int,input().split(" ")))
matrix=[list(map(int,input().split(" "))) for i in range(num[0])]
tmp=list(map(lambda x:x.append(sum(x)),matrix))
a=[sum([i[j] for i in matrix])for j in range(num[1]+1)]
matrix.append(a)
for i in matrix:
    print(" ".join(map(str,i)))

Submission status: Accepted

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

Submission status: Accepted

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

def num_get(r):
    nums = []
    for i in range(r):
        num = list(map(int, input().split()))
        nums.append(num)
    return nums

def hori_sum(num, r):
    nums = []
    for i in range(r):
        sum_i = sum(num[i])
        num[i].append(sum_i)
        print(" ".join([str(j) for j in num[i]]))
        nums.append(num[i])
    #print(nums)
    return nums

def verti_sum(nums, r, c):
    sums = []
    sum_v = 0
    c = c + 1
    for i in range(c):
        #print(i)
        for j in range(r):
            #print("{} {} {}" .format(i, j, num[j][i]))
            sum_v = sum_v + nums[j][i]
        sums.append(sum_v)
        sum_v = 0
    print(" ".join([str(i) for i in sums]))
    return sums

nums = num_get(r)
hori = hori_sum(nums, r)
#print(hori)
verti_sum(hori, r, c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
r,c=map(int,input().split())
M=[]
N=[]
S=0
e=0

for i in range(r):
    L=list(input().split())
    for j in range(c):
        S+=int(L[j])
    L.append(S)
    M.append(L)
    S=0
    
for k in range(r):
    d=M[k]
    
    for l in range(c+1):
        if l<c:
            print(d[l],end=' ')
        else:
            print(d[l])
            
for m in range(c+1):
    for n in range(r):
        a=M[n]
        e+=int(a[m])
    if m<c:
        print(e,end=' ')
        e=0
    else:
        print(e)
        e=0

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
r,c=map(int,input().split())
s=[[]for R in range(r)]
t=[0 for C in range(c)]
for i in range(r):
    s[i]=list(map(int,input().split()))
    for j in range(c):
        print(s[i][j],end=' ')
        t[j]+=s[i][j]
    print(sum(s[i]))
for k in range(c):
    print(t[k],end=' ')
print(sum(t))

Submission status: Accepted

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

for i in range(r):
    sx = 0 
    for j in range(c):
        sx +=l[i][j]
    l[i][c] = sx
   
for j in range(c):
    sy = 0
    for i in range(r):
        sy +=l[i][j]
    l[r][j] =sy
    SY +=sy
l[r][c] = SY

for k in l:
    print(*k)

Submission status: Accepted

Solution code:

r,c=map(int,input().split())
cc=[]
for l in range(c+1):
    cc.append(0)
    
for i in range(r):
    rr=list(map(int,input().split()))

    x=0
    for j in rr:
        x+=j
    rr.append(x)
    print(*rr)
    
    for k in range(c+1):
#        print(rr[k])
        cc[k]+=rr[k]
    
print(*cc)

Submission status: Accepted

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

Submission status: Accepted

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

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

n=0
o=[]
for i in range(b):
    for j in range(a):
        n+=m[j][i]
    o.append(n)
    n=0
o.append(sum(o))
print(' '.join(map(str,o)))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

r, c = map(int, input().split())
# r, c = map(int, '4 5'.split())
arr = []
col_t = [0]*(c)

for _ in range(r):
    arr.append(list(map(int, input().split())))

for row in range(r):
    row_t = 0
    for col in range(c):
        row_t += arr[row][col]
        col_t[col] += arr[row][col]
    arr[row].append(row_t)

total = 0
for v in col_t:
    total += v
col_t.append(total)
arr.append(col_t)

for v in arr:
    print(' '.join(map(str, v)))

Submission status: Accepted

Solution code:
# 演習1-10 Spreadsheet
r, c = map(int, input().split())

Sum = 0

c_sum = [0 for i in range(c)]

for i in range(r):
    temp = list(map(int, input().split()))
    Sum += sum(temp)
    r_sum = 0
    for j in range(c):
        print(temp[j], end=' ')
        r_sum += temp[j]
        c_sum[j] += temp[j]
    print(r_sum)
    
for i in range(c):
    print(c_sum[i], end=' ')
    
print(Sum)

Submission status: Accepted

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

for i in range(r+1):
    for j in range(c+1):
        print(A[i][j],end="")
        if j < c:
            print(" ",end="")
    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]))))

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

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

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
matrix = []
for _ in range(r):
    data_row = list(map(int, input().split()))
    sum_row = 0
    for num_row in data_row:
        sum_row += num_row
    data_row.append(sum_row)
    matrix.append(data_row)

data_col = []
for i in range(c + 1):
    sum_col = 0
    for j in range(r):
        sum_col += matrix[j][i]
    data_col.append(sum_col)
matrix.append(data_col)
    
for row in matrix:
    for i, num in enumerate(row):
        if i > 0:
            print(" ", end="")
        print(num, end="")    
    print()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
R,C,*T = list(map(int, open(0).read().split()))
r = [0] * C
for i in range(0, len(T), C):
    for j in range(C):
        print(T[i+j], end="")
        print(" ", end="")
        r[j] += T[i+j]
    print(sum(T[i:i+C]))
r.append(sum(r))
print(" ".join(map(str, r)))

Submission status: Accepted

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

lst.append([sum([x[j] for x in lst]) for j in range(c)])

for i in range(r+1):
    lst[i].append(sum(lst[i]))
    print(" ".join([str(x) for x in lst[i]]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
TBL = [list(map(int, input().split())) for _ in range(r)]
for i in TBL:
    i.append(sum(i))
TTL = [0 for i in range(c + 1)]
for i in TBL:
    for j in range(c + 1):
        TTL[j] += i[j]
TBL.append(TTL)
for i in TBL:
    ROW = ' '.join(map(str, i))
    print(ROW)

Submission status: Accepted

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

numbers_list = []

for _ in range(rows):
  numbers = [int(y) for y in input().split()]
  numbers.append(sum(numbers))

  numbers_list.append(numbers)

column_sums = [sum(x) for x in zip(*numbers_list)]

numbers_list.append(column_sums)

string_list = []

for number_list in numbers_list:
  string_list.append([str(x) for x in number_list])

for number_list in string_list:
  print(" ".join(number_list))

Submission status: Accepted

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

for i in range(r):
    h[i].append(sum(h[i]))
    
for i in range(c+1):
    t = 0
    for j in range(r):
        t += h[j][i]
    total.append(t)
    
for i in range(r):
    print(*h[i])

print(*total)

Submission status: Accepted

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

res = [0 for i in range(c)]
for i in range(r):
    li = [int(x) for x in list(input().split())]
    for j, k in enumerate(li):
        print("{} ".format(k), end="")
        res[j] += k
    print(sum(li), end="")
    print("")

for rr in res:
    print("{} ".format(rr), end="")
print(sum(res))

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
c = []
for i in range(a):
    c.append(list(map(int,list(input().split()))))
    c[i].append(sum(c[i]))
e=[]
for i in range(b):
    total=0
    for j in range(a):
        total+=c[j][i]
    e.append(total)
e.append(sum(e))
c.append(e)
"""
for i in range(a+1):
    for j in range(b+1):
        print(c[i][j],end=" ")
    print()
"""
for row in range(0,a+1):
    print("%d"%(c[row][0]),end="")
    for col in range(1,b+1):
        print(" %d"%(c[row][col]),end ="")
    print()

Submission status: Accepted

Solution code:
#もっといい方法全然あると思われ
import copy
r, c = map(int, input().split())
a = [input().split() for i in range(r)]

M=copy.copy(a)
tmp = []
all = 0

for i in range(r):
    s_r = 0
    s_c = 0
    for j in range(c):
        s_r += int(a[i][j])

    M[i].append(s_r)

for i in range(c):
    s_c = 0
    for j in range(r):
        s_c += int(a[j][i])
    tmp.append(s_c)
    all += s_c
tmp.append(all)
M.append(tmp)

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

Submission status: Accepted

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

for i in range(r):
    l[i] = list(map(int, input().split()))
    l[i].append(sum(l[i]))
    print(*l[i], sep=" ")

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

print(*cl, sep=" ")

Submission status: Accepted

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

for line in table:
    print(" ".join(map(str, line)))

Submission status: Accepted

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

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

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

for j in range(c) :
	print(c_sum[j],end=" ")
	all += c_sum[j]
print(all)

Submission status: Accepted

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

    sum_c = [0 for _ in range(c)]
    for i in range(r):
        row = list(map(int, input().split()))
        for j, x in enumerate(row):
            print("{} ".format(x), end='')
            sum_c[j] += row[j]
        print(sum(row))

    [print("{} ".format(x), end="") for x in sum_c]
    print(sum(sum_c))


resolve()

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
mat = [list(map(int, input().split())) for _ in range(r)]
for i in range(r):
    mat[i].append(sum(mat[i]))
new_row = []
for i in range(c):
    total_c = 0
    for j in range(r):
        total_c += mat[j][i]
    new_row.append(total_c)
new_row.append(sum(new_row))
mat.append(new_row)
for i in range(r+1):
    for j in range(c):
        print(f'{mat[i][j]} ', end='')
    print(mat[i][c])

Submission status: Accepted

Solution code:
dataset = input().split(" ")
r = int(dataset[0])
c = int(dataset[1])

table = []
for i in range(r):
    table.append([])
    dataset = input().split(" ")
    for j in range(c):
        table[i].append(int(dataset[j]))

# 最終列の計算
for i in range(r):
    sum = 0
    for j in range(c):
        sum += table[i][j]
    table[i].append(sum)

# 最終行の計算
table.append([])
for x in range(c+1):
    sum = 0
    for y in range(r):
        sum += table[y][x]
    table[r].append(sum)

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

for i in range(r):
    print(' '.join(map(str, l[i])))
print(*m)

Submission status: Accepted

Solution code:
r, c = list(map(int, input().split(' ')))
l = []
for i in range(r):
    l.append(list(map(int, input().split(' '))))
yl = []
xl = []
for y in range(r):
    xl.append(0)
    for x in range(c):
        xl[y] += l[y][x]
    l[y].append(xl[y])
t = [0] * len(l[0])
for y in range(r):
    for x in range(len(t)):
        t[x] += l[y][x]
l.append(t)
for a in l:
    print(*a)

Submission status: Accepted

Solution code:
n,m=map(int,input().split(' '))
a=[]
for i in range(n):
  tmp=list(map(int,input().split(' ')))
  tmp.append(sum(tmp))
  a.append(tmp)
al=[]
for i in range(m+1):
  tmp=0
  for j in range(n):
    tmp+=a[j][i]
  al.append(tmp)
a.append(al)

for i in a:
  s=''
  for j in range(len(i)):
    if j==len(i)-1:
      s+=str(i[j])
    else:
      s+=str(i[j])+' '
  print(s)