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:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    h,w = map(int, input().split())
    t=[list(map(int, input().split())) for _ in range(h)]
    sum_row=[0]*h
    sum_column=[0]*w
    for i,row in enumerate(t):
        for j,a in enumerate(row):
            sum_row[i]+=a
            sum_column[j]+=a
    for i,row in enumerate(t):
        print(*t[i],sum_row[i])
    print(*sum_column,sum(sum_column))

main()

Submission status: Accepted

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

for i in range(r):
    row = [ int(s) for s in input().split() ]
    sheet[i][:c+1] = row + [sum(row)]
    total_row[:c+1] = [ total_row[j] + sheet[i][j] for j in range(c+1) ]

sheet[r][:c+1] = total_row

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

Submission status: Accepted

Solution code:
import sys

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001



H,W = map(int,input().split())

table = [[0]*(W+1) for i in range(H+1)]

for row in range(H):
    work = list(map(int,input().split())) #★★直にtableに代入すると、列数が変わってしまう!!!★★★
    for col in range(W):
        table[row][col] = work[col]


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


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


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

Submission status: Accepted

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

for i in range(0, r):
    listnum = input().split()
    for j in range (0, c):
        s = 0
        listA[i][j]=listnum[j]
        for elem in listnum:
            s = s + int(elem)
    listA[i][c] = str(s)

for i in range(0,c+1):
    t = 0
    for j in range(0,r):
        t = t + int(listA[j][i])
    listA[r][i] = str(t)

for i in range(0, r+1):
    print(" ".join(listA[i]))

Submission status: Accepted

Solution code:
r,c = map(int,input().split())
numbers = []
for i in range(r):
    subnumbers = list(map(int,input().split()))
    numbers.append(subnumbers)
for j in range(r):
    for k in range(c):
        print(numbers[j][k],end = " ")
    print(sum(numbers[j]))
allcount = 0
for l in range(c):
    count = 0
    for m in range(r):
        count += numbers[m][l]
    print(count,end = " ")
    allcount += count
print(allcount)

Submission status: Accepted

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

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

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

    L[i].append(tmp)

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

        if j != c:
            print(" ", end="")

    print()

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

    print(tmp, end="")

    if i != c:
        print(" ", end="")

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 i in range(r):
    print(*table[i], sum(table[i]))
C = [0] * c
for j in range(c):
    for k in range(r):       
        C[j] += table[k][j]
        
print(*C, sum(C))

Submission status: Accepted

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

s = []

for r in range(R):
    s.extend([int(i) for i in input().split()])
    
for r in range(R):
    row = s[r*C:r*C+C]
    row.append(sum(row))
    print(*row)

footer = [sum(s[c::C]) for c in range(C)]
footer.append(sum(footer))
print(*footer)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

row = [0] * (c + 1)
for i in range(c+1):
    for j in range(r):
        row[i] += tbl[j][i]
tbl.append(row)

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

Submission status: Accepted

Solution code:
r,c=map(int,input().split())
matr= [input().split() for i in range(r)]
for i in range(len(matr)):
    matr[i] = [int(j) for j in matr[i]]
matr_column=[sum(matr[i]) for i in range(len(matr))]
for i in range(len(matr)):
    matr[i].append(matr_column[i])
matr_s=sum(matr,[])
matr_row=[]
for i in range(int((r*c+r)/r)):
    matr_r=matr_s[i:len(matr_s)][::c+1]
    matr_row.append(matr_r)
for i in range(len(matr)):
    print(*matr[i])
print(*[sum(matr_row[i]) for i in range(len(matr_row))])

Submission status: Accepted

Solution code:
r,c=[int(k) for k in input().split()]
arr=[[]]*r
for i in range(r):
    arr[i]=[int(k) for k in input().split()]
arr+=[[0]*c]
for i in range(r):
    arr[i].append(sum(arr[i]))
    arr[r]=[arr[r][k]+arr[i][k] for k in range(c)]
arr[r].append(0)
for v in arr[r]:
    arr[r][c]+=v
arr[r][c]//=2
for i in range(r+1):
    for j in range(c+1):
        arr[i][j]=str(arr[i][j])
for x in arr:
    print(' '.join(x))

Submission status: Accepted

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

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

b=[]
for j in range(m+1):
    tmp=0
    for l in range(n):
        tmp=tmp+a[l][j]
    b.append(tmp)
    

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

Submission status: Accepted

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

for i in range(r):
    for j in range(c):
        sheet[i][c] += sheet[i][j]
        sheet[r][j] += sheet[i][j]
    sheet[r][c] += sheet[i][c]
    l = [str(k) for k in sheet[i]]
    print(' '.join(l))
l = [str(k) for k in sheet[r]]
print(' '.join(l))

Submission status: Accepted

Solution code:

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

for i in range(1,r+2):
    for j in range(1,c+2):
        if j == c+1:
            print(f"{z[i-1][j-1]}",end="")
        else:
            print(f"{z[i-1][j-1]}",end=" ")
    print()

Submission status: Accepted

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

for k in a:
    t = sum(k)
    k.append(t)

for x in range(c+1):
    z = 0
    for y in a:
        z += y[x]
    else:
        ans.append(z)
else:
    a.append(ans)

for i in a:
    print(*i)

Submission status: Accepted

Solution code:
r, c = map(int,input().split())
sheet = []
for i in range(0,r):
    row = []
    row[:] = map(int,input().split())
    rsum = 0
    for j in range(0,c):
        rsum+=row[j]
    row.append(rsum)
    sheet.append(row)
    print(' '.join(map(str,row)))

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

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 k in range(r):
        A[r][j] += A[k][j]

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

Submission status: Accepted

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

Submission status: Accepted

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

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

b=[[0]*(c+1) for i in range(r+1)]


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

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

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

b[r][c]=sum

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

Submission status: Accepted

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

sum_colum = [0]*c
sum_matrix = 0
for i in range(r):
    sum_row = sum(l[i])
    sum_matrix += sum_row
    l_str = [str(n) for n in l[i]]
    print(" ".join(l_str),end=" ")
    print(sum_row,end="")
    print()

for i in range(c):
    for j in range(r):
        sum_colum[i]+= l[j][i]
    print(sum_colum[i], end=" ")
print(sum_matrix)

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
sums = [0] * (c + 1)
for x in range(0, r):
    raw = list(map(int, input().split()))
    raw_t = 0
    for x in range(0, c):
        sums[x] += raw[x]
        raw_t += raw[x]
    raw.append(raw_t)
    sums[c] += raw_t
    print(*raw)
print(*sums)

Submission status: Accepted

Solution code:
R, C = map(int, input().split())
spred_sheet = []
sum_row = [0 for i in range(C+1)]
for i in range(R):
    input_line = list(map(int, input().split()))
    input_line = input_line + [sum(input_line)]
    spred_sheet.append(input_line)
    for j in range(C+1):
        sum_row[j] += input_line[j]
spred_sheet.append(sum_row)
for i in range(R+1):
    for j in range(C+1):
        print("{}".format(spred_sheet[i][j]), end="")
        if j == C:
            print()
        else:
            print(" ", end="")

Submission status: Accepted

Solution code:
def shownum(list):
    stri = str()
    for s in list:
        stri += str(s) + " "
    print(stri[:-1])
    
r , c = map(int,input().split())
csum =[list() for x in range(c)]
rlist = [list() for x in range(r+1)]




for i in range(r):
    sum = 0
    rlist[i] = list(map(int,input().split()))
    for j in range(c):
        csum[j].append(rlist[i][j])
    for j in rlist[i]:
        sum += j
    rlist[i].append(sum)
    
    
for s in csum:
    sum = 0
    for l in s:
        sum += l
    rlist[r].append(sum)

sum = 0
for i in rlist[r]:
   sum += i
rlist[r].append(sum)


for i in range(r+1):
    shownum(rlist[i])

Submission status: Accepted

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

values=[]

for i in range(r):
    values=list(map(int,input().split(" ")))
    for j in range(c+1):
        if j!=c:
            originalMatrix[i][j]=values[j]
        else:
            originalMatrix[i][j]=sum(values)

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def get_row_sum(l):
    sums = 0
    for num in l:
        sums += num
    return sums

num_rows, num_columns = map(int, input().split())

result_table = list()
sum_row = [0 for _ in range(num_columns+1)]

for i in range(num_rows):
    row = list(map(int, input().split()))
    row_sum = get_row_sum(row)
    row.append(row_sum)
    result_table.append(row)
    
    for i in range(len(row)):
        sum_row[i] += row[i]

result_table.append(sum_row)

for r in result_table:
    for i, num in enumerate(r):
        print(num, end='')
        if i != num_columns:
            print(end=' ')
    print()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
r,c = map(int,input().split())
lst = [[0 for i in range(101)] for j in range(101)]
for i in range(r):
    lst[i][0:c] = map(int,input().split())
for i in range(r):
    lst[i][c] = sum(lst[i])
for i in range(c+1):
    for j in range(r):
        lst[r][i] += lst[j][i]
for i in range(r+1):
    for j in range(c+1):
        print(f"{lst[i][j]}",end = "")
        if j != c:
            print(" ",end = "")
        else:
            print()

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))))
for row in matrix:
    print(' '.join(str(e) for e in row))

Submission status: Accepted

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

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

Submission status: Accepted

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

# row sum
for a in range(r):
    ori_t[a].append(sum(ori_t[a]))

# column sum
ori_t.append([0 for x in range(c+1)])

for b in range(c):
    c_sum = 0
    for a in range(r):
        c_sum += ori_t[a][b]
    ori_t[r][b] = c_sum

# cross sum
ori_t[r][c] = sum(ori_t[r])

# output
for num in ori_t:
    print(*num)

Submission status: Accepted

Solution code:
y, x = [int(i) for i in input().split()]
allsum = [0] * (x + 1)

for _ in range(y):
    temp = [int(i) for i in input().split()]
    sumrow = sum(temp)
    print('{} {}'.format(' '.join(map(str, temp)), str(sumrow)))
    for i in range(len(allsum) - 1):
        allsum[i] += temp[i]
    allsum[-1] += sumrow

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

Submission status: Accepted

Solution code:
a = 0
r, c = [int(i) for i in input().split()]
li = [[int(i) for i in input().split()] for _ in range(r)]
for row in li:
    print(*row, sum(row))
for i in range(c):
    t = sum([row[i] for row in li])
    a += t
    print(t, end=" ")
print(a)

Submission status: Accepted

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

for i in range(r):
    row_list = list(map(int, input().split()))
    sum_row = 0
    for j in range(c):
        sum_row += row_list[j]
        print('{} '.format(row_list[j]), end='')
        sum_list.append(row_list[j])
    print(sum_row)
    sum_list.append(sum_row)

for k in range(c+1):
    sum_col = 0
    for l in range(r):
        m = l*(c+1)+k
        sum_col += sum_list[m]
    if k != c:
        print('{} '.format(sum_col), end='')
    else:
        print(sum_col)

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
s = []
for _ in range(H):
    a = [int(i) for i in input().split()]
    a += [sum(a)]
    s.append(a)

s.append([sum([x[i] for x in s]) for i in range(W + 1)])

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

Submission status: Accepted

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

B = []
for j in range(m + 1):
    B.append(0)

for k in A:
    for l,o in enumerate(k):
        B[l] += o

A.append(B)
for i in A:
    for j,k in enumerate(i):
        if j == 0:
            print(k,end="")
        else:
            print("",k,end="")
    print()

Submission status: Accepted

Solution code:
r,c=map(int,input().split())
l=[]
for i in range(r):
    l.append(list(map(int,input().split())))
csum=[0 for j in range(c)]
gsum=0
for i in range(r):
    rsum=0
    for j in range(c):
        print(l[i][j],end=' ')
        rsum+=l[i][j]
        csum[j]+=l[i][j]
    print(rsum)
    gsum+=rsum
for elem in csum:
    print(elem,end=' ')
print(gsum)

Submission status: Accepted

Solution code:
r = 0
c = 0


def input_size():
    global r, c
    r, c = map(int, input().split(' '))


def input_table(table):
    for i in range(0, r):
        vs = list(map(int, input().split(' ')))
        row = []
        for v in vs:
            row.append(v)
        table.append(row)


def calc_total(table):
    total = []
    for i in range(0, c + 1):
        total.append(0)

    for i in range(0, r + 1):
        if i < r:
            t = 0
            for j in range(0, c):
                t += table[i][j]
                total[j] += table[i][j]
            table[i].append(t)
            total[c] += t

        if i == r - 1:
            table.append(total)


def output(vs):
    for row in vs:
        first = True
        for v in row:
            if not first:
                print(end=' ')
            print(v, end='')
            first = False
        print()


input_size()
vs = []
input_table(vs)
calc_total(vs)
output(vs)

Submission status: Accepted

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

for _ in range(r):
    a = [int(x) for x in input().split()]
    for i,j in enumerate(a):
        A[_][i] = j
        A[-1][i] += j
    A[_][i+1] = sum(a)

A[-1][-1] = sum(A[-1])

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

Submission status: Accepted

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

for i in range(r+1):
    if i == r:
        array.append(add)
        break
    for j in range(c+1):
        if j == c:
            array[i].append(sum(array[i]))
            add[j] += array[i][j]
        else:
            add[j] += array[i][j]

for i in range(r+1):
    print(*array[i], sep=' ')

Submission status: Accepted

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

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):
    l = [int(x) for x in input().split()]
    for j in range(c):
        s[j] += l[j]
        print(l[j],end="")
        print(" ",end="")
    print(sum(l))

for j in s:
    print(j,end="")
    print(" ",end="")
print(sum(s))

Submission status: Accepted

Solution code:
s = input().split()

r = int(s[0])
c = int(s[1])

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

row=[]
for i in range(r):
    row = list(map(int,input().split()))
    
    for j in range(c):
        A[i][j]=row[j]
        A[i][c]+=row[j] # sum of row
        A[r][j]+=row[j] # sum of column
    
    A[r][c]+=A[i][c]
        
for i in range(r+1):
    for j in range(c):
        print(A[i][j]," ",end="",sep="")
    print(A[i][c])

Submission status: Accepted

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

print(*[sum(e[i] for e in a) for i in range(c)], sum(map(sum, a)))

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
a = [[0 for i in range(W+1)] for j in range(H+1)]
for y in range(H):
	tmp = list(map(int,input().split()))
	for x in range(W):
		a[y][x] = tmp[x]
		a[y][W]=a[y][x]+a[y][W]
		a[H][x]=a[H][x]+a[y][x]
		a[H][W]=a[H][W]+a[y][x]
for u in range(H+1):
	for i in range(W+1):
		print(a[u][i],end='')
		if	i<W:
			print(" ",end='')
	print()

Submission status: Accepted

Solution code:
#coding: utf-8

r, c = map(int, input().split())
mtx = list()
sor = [0 for i in range(c + 1)]
for i in range(r):
    temp = list(map(int, input().split()))
    temp.append(sum(temp))
    for j in range(c + 1):
        sor[j] += temp[j]
    mtx.append(temp)
mtx.append(sor)
for i in range(r + 1):
    for j in range(c + 1):
        mtx[i][j] = str(mtx[i][j])
    print(' '.join(mtx[i]))

Submission status: Accepted

Solution code:
def test():

	inputs = list(map(int,input().split()))

	r = inputs[0]
	c = inputs[1]

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

	for i in range(r):

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


	for i in range(r+1):
		for j in range(c+1):
			print(f"{sheet[i][j]}",end='')
			if j != c:
				print(" ",end='')

		print("")

if __name__ == "__main__":
	test()

Submission status: Accepted

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

table = [[0]*(W+1) for i in range(H+1)]

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


for row in range(H):
    for col in range(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())
input_list = [[0 for i in range(c)] for j in range(r)]

for i in range(r):
    input_list[i] = list(map(int, input().split()))
    
for i in range(r):
    for j in range(c):
        if j == 0:
            print(input_list[i][j], sep="", end="")
        else:
            print(" ", input_list[i][j], sep="", end="")
    print(" ", sum(input_list[i]), sep="")

all_sum = 0
for j in range(c):
    tmp_sum = 0
    for i in range(r):
        tmp_sum += input_list[i][j]
    
    if j == 0:
        print(tmp_sum, sep="", end="")
    else:
        print(" ", tmp_sum, sep="", end="")
    
    all_sum += tmp_sum
print(" ", all_sum, sep="")

Submission status: Accepted

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

ss = []

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

sum_row = []

for i in range(c+1):
    temp = 0
    for j in ss:
        temp += j[i]
    
    sum_row.append(temp)

ss.append(sum_row)

for s in ss:
    print(*s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

C = [0 for _ in range(c)]
for X in A:
    for j, a in enumerate(X):
        C[j] += a

for X in A + [C]:
    print(" ".join([str(a) for a in X] + [str(sum(X))]))

Submission status: Accepted

Solution code:
n,m=map(int,raw_input().split())
x=[[0 for i in range(m)]for i in range(n)]
a=[[0 for i in range(m+1)] for i in range(n+1)]

for i in range(n):
	x[i] = map(int,raw_input().split())
	for j in range(m):
		a[i][j] = x[i][j]
		a[n][j] += x[i][j]
		a[i][m] += x[i][j]
	print " ".join(map(str,a[i]))
a[n][m]=sum(a[n])
print " ".join(map(str,a[n]))

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
a=[[0 for i in range(W+1)] for j in range(H+1)]
for y in range(H):
	l=list(map(int,input().split()))
	for x in range(W):
		a[y][x]=l[x]
		a[y][W]=a[y][x]+a[y][W]
		a[H][x]=a[H][x]+a[y][x]
		a[H][W]=a[H][W]+a[y][x]
for u in range(H+1):
	for i in range(W+1):
		print(a[u][i],end='')
		if	i<W:
				print(" ",end='')		
	print()

Submission status: Accepted

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

# 入力する全体
ans = []

# 最後の列
last_raw = []

tmpmax = 0
# 横のやつ appendする
sum = 0
for i in range(r):
    ans.append(list(map(int,input().split())))

# 横
for i in range(r):
    sum = 0
    for j in range(c):
        sum += ans[i][j]
    ans[i].append(sum)
    tmpmax+=sum

lastsum=0
for j in range(c):
    lastsum=0
    for i in range(r):
        lastsum+=ans[i][j]
    last_raw.append(lastsum)
    tmpmax+=lastsum 

last_raw.append(int(tmpmax/2))
# 表示
for i in range(r):
    print(' '.join(map(str,ans[i])))
print(' '.join(map(str,last_raw)))

Submission status: Accepted

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

r_sum = [0] * (r+1)
c_sum = [0] * c


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

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

Submission status: Accepted

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

sum0 = 0

for j in range(m):
    for i in range(n):
        sum0 += a[i][j]
    a[n][j] = sum0
    sum0 = 0

for k in range(n+1):

    a[k].append(sum(a[k]))
    print(' '.join([str(p) for p in a[k]]))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())

v=[[0 for j in range(w+1) ] for i in range(h+1)]

for i in range(h):
	row = list(map(int,input().split()))
	for j in range(w):
		v[i][j] = row[j]
		v[i][w] += v[i][j]
		v[h][j] += v[i][j]
		v[h][w] += v[i][j]

for i in range(h+1):
	for j in range(w):
		print(v[i][j],end=" ")
	print(v[i][w])

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):
    m = 0
    for j in range(c):
        m += a[i][j]
        print(a[i][j], end=" ")
    print(m)

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):
   m = 0
   for j in range(c):
       m += a[i][j]
       print(a[i][j], end=" ")
   print(m)

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())) 
    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=[[int(i) for i in input().split()]for _ in range(r)]
y=[sum(i) for i in zip(*a)]
for i in range(r):
    print(*a[i],sum(a[i]))
print(*y,sum(y))

Submission status: Accepted

Solution code:
r,c = map(int, input().split())
fields = []
colsum = [0]*(c+1)
for i in range(r):
    A = list(map(int, input().split()))
    row = A + [sum(A)]
    fields.append(row)
    for i,e in enumerate(row):
        colsum[i] += e
fields.append(colsum)

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

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:
lw = []
lc = []
r, c = map(int, input().split())
for i in range(r):
    ls = list(map(int, input().split()))
    lw.append(ls)
for i in range(r):
    print(" ".join(map(str, (lw[i] + [sum(lw[i])]))))
for i in range(c):
    k = 0
    for j in range(r):
        k =  k + lw[j][i]
    lc.append(k)
print(" ".join(map(str, (lc + [sum(lc)]))))