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:
size = [int(i) for i in input().split()]
sheet =[ [0 for i in range(size[1])] for j in range(size[0])]
for gyou in range(size[0]):
    x = [int(i) for i in input().split()]
    sheet[gyou] = x
    sheet[gyou].append(sum(sheet[gyou]))

for gyou in range(size[0]):
    for retsu in range(size[1]+1):
        print(sheet[gyou][retsu],end="")
        if retsu != size[1]:
            print(" ",end="")
    print("")
for retsu in range(size[1]+1):
    sum2 = 0
    for gyou in range(size[0]):
        sum2 += sheet[gyou][retsu]
    print(sum2, end="")
    if retsu != size[1]:
        print(" ",end="")
print("")

Submission status: Accepted

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

# for yoko
i=0
b=[]
while i<r:
    a=input().split()
    q=0
    su=0
    while q<c:
        b.append(int(a[q]))
        su+=int(a[q])
        q=q+1
    b.append(su)
    i=i+1

# for tate
#x=0
#d=b[0]+b[c+1]+b[2*(c+1)]+b[3*(c+1)]
#x<c+1
x=0
while x<c+1:
    d=0
    z=0
    while z<r:
        d+=b[x+z*(c+1)]
        z+=1
    b.append(d)
    x=x+1
# for output
# C=[]
# y=0 (for gyou)
# z=0 (for yoko)
C=[]
y=0
while y<r+1:
    z=0
    Ans=str(b[y*(c+1)+z])
    while z<c:
        z+=1
        Ans=Ans+" "+str(b[y*(c+1)+z])
    C.append(Ans)
    y+=1

for k in C:
    print(k)

Submission status: Accepted

Solution code:
r,c=map(int,input().split())
w=[0]*c
q=[]
for i in range(r):
    b=input().split()
    e=[int(s) for s in b]
    q.append(e)
for i in range(r):
    for j in range(c):
        w[j]+=q[i][j]
        print(q[i][j],end=' ')
    print(sum(q[i]))
for j in range(c):
    print(w[j],end=' ')
print(sum(w))

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
matrix = [[int(n) for n in input().split()] for row in range(r)]

for i, row in enumerate(matrix):
    matrix[i].append(sum(row))

end = [0 for _ in range(c+1)]
for i in range(c+1):
    for row in matrix:
        end[i] += row[i]

matrix.append(end)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def data_assignment():
    for i in range(r):
        for j, e in enumerate(map(int, input().split())):
            table[i][j] = e

def total_rows():
    for i, line in enumerate(table):
        table[i][c] = sum(line[:c])


def total_columns():
    for i, line in enumerate(table):
        if i == r:
            break
        for j, element in enumerate(line):
            table[r][j] += element


def table_print():
    for line in table:
        for i, element in enumerate(line):
            if i == c:
                print(element)
            else:
                print(element, end=' ')


r, c = map(int, input().split())
table = [[0 for i in range(c+1)] for j in range(r+1)]
data_assignment()
total_rows()
total_columns()
table_print()

Submission status: Accepted

Solution code:
# AOJ ITP1_7_C

def numinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

def main():
    a = numinput()
    r = a[0]; c = a[1]
    M = []
    for i in range(r):
        M.append(numinput())  # あ、そうか。。
        sum = 0
        for j in range(c): sum += M[i][j]
        M[i].append(sum)
    list = []
    for j in range(c + 1):
        sum = 0
        for i in range(r): sum += M[i][j]
        list.append(sum)
    M.append(list)

    for i in range(r + 1):
        _str_ = ""
        for j in range(c):
            _str_ += str(M[i][j]) + " "
        _str_ += str(M[i][c])
        print(_str_)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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):
    for j, x in enumerate(input().split()):
        a[i][j] = int(x)

###### 各行の合計を求める ######
for i, line in enumerate(a):
    a[i][c] = sum(line)

###### 行と列を入れ替える ######
a = list(zip(*a))

###### 各列の合計を求める ######
for i, line in enumerate(a):
    a[i] = list(line)
    a[i][r] = sum(a[i])

###### 行と列を入れ替える ######
a = list(zip(*a))

for line in a:
    for i, x in enumerate(line):
        if i == c:
            print(x)
        else:
            print(x, end=" ")

Submission status: Accepted

Solution code:
import sys

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

matrix = [[0 for x in range(m + 1)] for y in range(n + 1)]

for i in range(n):
	arr = list(map(int, input().split()))
	for j in range(m):
		matrix[i][j] = arr[j]
		
for i in range(n):
	sum = 0
	for j in range(m):
		sum += matrix[i][j]
	matrix[i][m] = sum

for i in range(m + 1):
	sum = 0
	for j in range(n):
		sum += matrix[j][i]
	matrix[n][i] = sum
	
for i in range(n + 1):
	for j in range(m + 1):
		sys.stdout.write(str(matrix[i][j]))
		if j != m:
			sys.stdout.write(' ')
	print()

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
table = []
for _ in range(r):
    table.append(list(map(int, input().split())))
for row in range(r):
    print(' '.join(map(str, table[row])), sum(table[row]), sep=' ')
# print(' '.join(map(str, [sum(table[:][col]) for col in range(c)])), sum(table), sep=' ')
col_sum = [sum([table[row][col] for row in range(r)]) for col in range(c)]
print(' '.join(map(str, col_sum)), sum(col_sum), sep=' ')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Spreadsheet

sheet = [int(i) for i in input().rstrip().split()]
rows = sheet[0]
columns = sheet[1]

spreadSheet = []
for i in range(rows):
    row = [int(j) for j in input().rstrip().split()]
    rowTotal = 0
    for element in row:
        rowTotal += element
    row.append(rowTotal)
    spreadSheet.append(row)
# print(spreadSheet)
spreadColumns = columns + 1

totalRow = []
for column in range(spreadColumns):
    columnTotal = 0
    for i in range(rows):
        columnTotal += spreadSheet[i][column]
    totalRow.append(columnTotal)
spreadSheet.append(totalRow)
# print(spreadSheet)

for spreadRow in spreadSheet:
    row_str = [str(element) for element in spreadRow]
    print(' '.join(row_str))

Submission status: Accepted

Solution code:

import sys

n, m = input().strip().split(" ")
n = int(n) ;m = int(m)

c = n

a = []
for line in sys.stdin :
    a.append(line)
    c -= 1
    if c == 0 :
        break
for i in range(0, len(a)) :
    a[i] = a[i].strip().split(" ")
    for j in range(0, len(a[i])) :
        a[i][j] = int(a[i][j])

for r in range(0, len(a)) :
    a[r].append(sum(a[r]))

arr = []
for c in a[0] :
    arr.append(0)
for r in range(0, len(a)) :
    for c in range(0, len(a[i])) :
        arr[c] += a[r][c]
a.append(arr)

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

    print()

Submission status: Accepted

Solution code:
g,r=map(int,input().split());
num,table=list(),list()
for i in range(g):
    num=list(map(int,input().split()))
    num.append(0)
    table.append(num)
num=[0 for i in range(r+1)]
table.append(num)
for i in range(g):
    for j in range(r):
        table[i][r]+=table[i][j]
        table[g][j]+=table[i][j]
    table[g][r]+=table[i][r]
for i in range(g+1):
    for j in range(r):
        print(table[i][j],end=" ")
    print(table[i][r])

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(0)
    aic = 0
    for k in range(c):
        aic = aic + a[i][k]
    a[i][c] = aic
a.append([0for i in range(c+1)])
for k in range(c):
    ark = 0
    for i in range(r):
        ark = ark + a[i][k]
    a[r][k] = ark
arc = 0
for i in range(r):
    arc = arc +a[i][c]
a[r][c] = arc

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

Submission status: Accepted

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

Submission status: Accepted

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

t.append([sum([t[j][i] for j in range(r)]) for i in range(c+1)])

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

Submission status: Accepted

Solution code:
import sys

p = 0
x1 = []
for line in sys.stdin:
    x = [int(i) for i in line.split()]
    if p == 0:
        r,c = x
        p = 1
    else:
        x1.append(x)

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

for i in range(r+1):
    for j in range(c+1):
        print x1[i][j],
    print

Submission status: Accepted

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

x = [map(int, raw_input().split()) for i in range(r)]

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

for e1 in x:
    for e in e1:
        print e,
    print sum(e1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from __future__ import division, print_function
from sys import stdin
r, c = (int(s) for s in stdin.readline().split())
sheet = [[int(s) for s in stdin.readline().split()] for _ in range(r)]
sheet.append([sum(row[i] for row in sheet) for i in range(c)])
for row in sheet:
    row.append(sum(row))
    print(*row)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import time
import sys
import io
import re
import math
#start = time.time()
start = time.clock()
l=[]
m=[]
s=[]
(r,c)=map(int, raw_input().split())
for i in range(r):
    l.append(map(int, raw_input().split()))
### ???????????則??\?????????
for cc in range(c):
    a=0
    for rr in range(r):
        a+=int(l[rr][cc])
#        print int(l[rr][cc])
    s.append(a)
for j in range(r):
    print ' '.join(map(str,l[j])),str(sum(l[j]))
print ' '.join(map(str,s)),str(sum(s))

Submission status: Accepted

Solution code:
r, c = map(int, raw_input().split())
sum_c = [0] * (c+1)
row_list = []
for i in xrange(r):
	row = map(int, raw_input().split())
	row.append(sum(row))
	row_list.append(row)
	sum_c = map(lambda x, y: x+y, sum_c, row) 
row_list.append(sum_c)
for row in row_list:
	print ' '.join(map(str, row))

Submission status: Accepted

Solution code:
r,c = map(int,raw_input().split())
sheet = []
for i in range(0,r):
    sheet.append(map(int,raw_input().split()))
total = [0] * (c+1)
for line in sheet:
    sum = 0
    for i,tmp in enumerate(line):
        total[i] += tmp 
        sum += tmp
    total[-1] += sum
    print " ".join(map(str,line))+" "+str(sum)
print " ".join(map(str,total))

Submission status: Accepted

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

Submission status: Accepted

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

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

print (" ".join(map(str, sum_r)) + " " + str(sum))

Submission status: Accepted

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

line = [map(int, raw_input().split()) for i in range(r)]
foot = [0 for i in range(c+1)]

for i in range(len(line)):
	line[i].append(sum(line[i]))
	for j in range(len(line[i])):
		foot[j] += line[i][j]

line.append(foot)
for l in line:
	print " ".join(map(str, l))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
lst = [[0 for i in range(m+1)] for j in range(n+1)]
for i in range(n):
    line = list(map(int,input().split()))
    for j in range(m):
        lst[i][j] = line[j]
for i in range(n):
    for j in range(m):
        lst[i][m] += lst[i][j]
for j in range(m+1):
    for i in range(n):
        lst[n][j] += lst[i][j]
for i in range(n+1):
    for j in range(m+1):
        if j>0:
            print(f" {lst[i][j]}", end="")
        else:
            print(lst[i][j], 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())
a=[]
sum1=[]
for i in range(r):
    a.append(list(map(int, input().split())))

for i in range(r):
    sum=0
    for j in range(c):
        print(a[i][j],end=' ')
        sum+=a[i][j]
        if i==0:
            sum1.append(a[i][j])
        else:
            sum1[j]+=a[i][j]
        if j==c-1:
            print(sum)
            if i==0:
                sum1.append(sum)
            else:
                sum1[c]+=sum
for i in range(c+1):
    if i!=c:
        print(sum1[i],end=' ')
    else:
        print(sum1[i])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
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:
ll=[]
p=[]
a,b=map(int,input().split())
for i in range(a):
    l=input().rstrip().split()
    l=list(map(int,l))
    ll+=l
    #print(ll)
#print(ll)
LL=[str(a) for a in ll]
for i in range(0,a*b,b):
    print(' '.join(LL[i:i+b]),sum(ll[i:i+b]))
    
for i in range(0,a):    
    ll.insert(i+b*(i+1),sum(ll[i+b*i:i+b*(i+1)]))
#print(ll)
for j in range(b+1):
    J=[]
    for i in range(j,a*(b+1),b+1):
        J.append(ll[i])
    #print(J)
    p.append(sum(J))
    #print(p)
LL=[str(a) for a in p]
print(' '.join(LL))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
sum_n=[0]*m
sum=0
for i in range(n):
    lst=list(map(int,input().split()))
    sum_m=0
    for j in range(m):
        print(lst[j], end=" ")
        sum_m+=lst[j]
        sum_n[j]+=lst[j]
    print(sum_m)
    sum+=sum_m
for i in range(m):
    print(sum_n[i], end=" ")
print(sum)

Submission status: Accepted

Solution code:
h=0
i=0
j=0
a=[]

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

Submission status: Accepted

Solution code:
n, m= map(int,input().split())
a =[]

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

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

sum = []
for j in range(m+1):
    s = 0
    for i in range(n):
        s += a[i][j]
    sum.append(s)

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

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
table = [cc + [sum(cc)] for cc in (list(map(int, input().split())) for _ in range(r))]
table.append(list(map(sum, zip(*table))))
for line in table:
    print(*line)

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=[int(x) for x in input().split()]
s_row=[0 for x in range(c+1)]
for i in range(r):
	row=[int(x) for x in input().split()]
	row.append(sum(row))
	print(" ".join([str(x) for x in row]))
	s_row=[x+y for x,y in zip(s_row,row)]
print(" ".join([str(x) for x in s_row]))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())

A = []
for line in range(n):
    A.append(list(map(int, input().split())))

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

t = []
for i in range(m+1):
    t.append([A[j][i] for j in range(n)])
    t[i].append(sum(t[i]))

r = []
for i in range(n+1):
    r.append([t[j][i] for j in range(m+1)])
    print(' '.join(map(str, r[i])))

Submission status: Accepted

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

Submission status: Accepted

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

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

B = [];
for j in range(0,r):
    B.append(sum(A[j*c:j*c+(c-1)+1]));

for k in range(0,r): 
    A.insert(c*(k+1)+k, B[k]);

        
C = [];
for m in range(0,c+1):
    b = 0;
    for l in range(0,r):
        b += A[l*(c+1)+m];
    A.append(b);

t =  [str(n) for n in A];

for x in range(0, r+1):
    result = ' '.join(t[x*(c+1):x*(c+1)+(c+1)]);
    print(result);

Submission status: Accepted

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

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())) #★★直にtableに代入すると、列数が変わってしまう!!!★★★
    for col in range(W):
        table[row][col] = work[col]


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


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


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

Submission status: Accepted

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

A = []

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

S = []

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

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

Submission status: Accepted

Solution code:
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())
R=[]
A=[0]*(c+1)
for i in range(r):
    R.append(list(map(int,input().split())))
for i in range(r):    
    s=0
    for j in range(c):
        s+=R[i][j]
        A[j]+=R[i][j]
    print(' '.join(map(str,R[i]))+' '+str(s))
    A[c]+=s
print(' '.join(map(str,A)))

Submission status: Accepted

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


n, m = map(int, input().split())
A = [[0 for j in range(m)] for i in range(n)]

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

S = [0 for j in range(m)]
c = 0
for i in range(n):
   for j in range(m):
      print(A[i][j], end = "")
      print(" ", end = "")
   print(sum(A[i]))
   c += sum(A[i])

for j in range(m):
   sum = 0
   for i in range(n):
      sum += A[i][j]
   print(sum, end = "")
   print(" ", end = "")
print(c)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# 7_C
r,c=map(int,input().split())
table=[[0 for i in range(c+1)]for n in range(r+1)]
for i in range(r):
    var=list(map(int,input().split()))
    for n in range(len(var)+1):
        if(n==c):
            table[i][n]=sum(var)
        else:
            table[i][n]=var[n]

for i in range(r):
    for n in range(c):
        table[r][n]+=table[i][n]
table[r][c]=sum(table[r])
for line in table:
    length=len(line)
    for col in line:
        length-=1
        if length ==0 :
            print(str(col))
        else:
            print(str(col)+" ",end='')

Submission status: Accepted

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

b = [sum(i) for i in zip(*a)]
a.append(b)

for r in a:
    print(" ".join(str(i) for i in r))

Submission status: Accepted

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

for j in range(r):
  b=0
  for k in range(c):
    b+=table[j][k]
    print(table[j][k],end=" ")
  print(b)
a=[]
for k in range(c):
  d=0
  for j in range(r):
    d+=table[j][k]
  a.append(d)
print(' '.join(map(str,a)),end=' ')
print(sum(a))

Submission status: Accepted

Solution code:
r,c = map(int,input().split())
data = []
for i in range(r):
	data.append(list(map(int,input().split())))
for k in range(r):
	su = sum(data[k])
	an = data[k].copy()
	an = list(map(str,an))
	print(" ".join(an),su)
las = []
for kk in range(c):
	ans = 0
	for s in range(r):
		ans += data[s][kk]
	las.append(ans)
total = sum(las)
last = list(map(str,las))
print(" ".join(last),total)

Submission status: Accepted

Solution code:
a=[]
u=[]
x=[]
l=0  
num=input().split(' ')
for i in range(0,int(num[0]),1):
    sum=0
    num2=input().split(' ')
    for j in range(0,int(num[1]),1):
        sum=sum+int(num2[j])
        a.append(int(num2[j]))
    a.append(sum)
for k in range(int(num[1])+1):
    u.append(a[k::int(num[1])+1])
for i in range(0,len(u),1):
    sum2=0
    for j in range(0,len(u[i]),1):
        sum2=sum2+u[i][j]
    x.append(sum2)
for i in range(0,int(num[0]),1):
    for j in range(0,int(num[1])+1,1):
        if j==int(num[1]):
            print(a[l])
            l+=1
        else:    
            print(a[l],end=" ")
            l+=1    
for j in range(len(x)):
    if j==len(x)-1:
       print(x[j])
    else:    
       print(x[j],end=" ")

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

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

Submission status: Accepted

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

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

S = [0 for j in range(m)]
c = 0
for i in range(n):
   for j in range(m):
      print(A[i][j], end = "")
      print(" ", end = "")
   print(sum(A[i]))
   c += sum(A[i])

for j in range(m):
   sum = 0
   for i in range(n):
      sum += A[i][j]
   print(sum, end = "")
   print(" ", end = "")
print(c)

Submission status: Accepted

Solution code:
r,c=(int(x) for x in input().split())
count=0
answer_lst=[]
while count<r:
    line=input().split()
    lst=[]
    total=0
    for i in line:
        lst.append(int(i))
        total+=int(i)
    lst.append(total)
    answer_lst.append(lst)
    count+=1
lst2=[]
for l in range(c+1):
    total2=0
    for m in answer_lst:
        total2+=m[l]
    lst2.append(total2)
answer_lst.append(lst2)
for ans in answer_lst:
    print(*ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in range(c):
  temp = 0
  for j in range(r):
    temp += data[j][i]
  sita.append(temp)
sita.append(ans//2)
data.append(sita)

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

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())
sheet = []
for r in range(R):
    row = list(map(int,input().split()))
    s = sum(row)
    row.append(s)
    sheet.append(row)

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

for r in range(R):
  for c in range(C + 1):
    last_row[c] += sheet[r][c]
sheet.append(last_row)

for row in sheet:
  print(*row, sep = ' ')

Submission status: Accepted

Solution code:
r,c=list(map(int,input().split()))
a=[]
A1=[[0 for col in range(c+1)] for row in range(r+1)]
sum_col=0
sum_row=0
for row in range(r):
    A = list(map(int,input().split()))
    a.append(A)
for row in range(r):
    for col in range(c):
        A1[row][col]=a[row][col]
for row in range(r+1):
    for col in range(c+1):
        sum_col+=A1[row][col]
    A1[row][c]=sum_col
    sum_col=0
for col in range(c+1):
    for row in range(r+1):
        sum_row+=A1[row][col]
    A1[r][col]=sum_row
    sum_row=0
for row in range(r+1):
    print("%d"%(A1[row][0]),end="")
    for col in range(1,c+1):
        print(" %d"%(A1[row][col]),end="")
    print()