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


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

    for j in range(c):
        table[i][j] = a[j]
        sumr += a[j]
    table[i][c] = sumr

for j in range(c+1):
    sumc = 0

    for i in range(r):
        sumc += table[i][j]
    table[r][j] = sumc

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

Submission status: Accepted

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

matrix.append([])
for i in range(col):
  col_sum = 0
  for j in range(row):
    col_sum += matrix[j][i]
  matrix[row].append(col_sum)
matrix[row].append(sum(matrix[row]))

for i in range(row+1):
  strings = ''
  for j in range(col+1):
    strings += str(matrix[i][j]) + ' '
  print(strings[:-1])

Submission status: Accepted

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

for i in range(r):
    sum = 0
    for j in range(c):
        sum += sheet[i][j]
        print(sheet[i][j], end=' ')
    print(sum)
total = 0
for j in range(c):
    sum = 0
    for i in range(r):
        sum += sheet[i][j]
    total += sum
    print(sum, end=' ')
print(total)

Submission status: Accepted

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

LIST = []
for i in range(r):
    List = [int(x) for x in input().split()]
    LIST.append(List)

for i in range(r):
    Lsum = sum(LIST[i])
    LIST[i].append(Lsum)

Listbo = []
for i in range(c+1):
    SUM = 0
    for j in range(r):
        L = LIST[j]
        SUM += L[i]
    Listbo.append(SUM)
LIST.append(Listbo)

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

Submission status: Accepted

Solution code:
C, R = map(int, input().split())
T = [[0]*(R+1) for i in range(C+1)]

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

for row in range(C):
    for col in range(0, R):
        T[row][R] += T[row][col]

for row in range(C):
    for col in range(0, R):
        T[C][col] += T[row][col]

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

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

Submission status: Accepted

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

for i in range(r):
    total = 0
    b = input().split()
    for j in b:
        total += int(j)
    b.append(total)
    a.append(b)
C = []
for i in range(c + 1):
    t = 0
    for j in range(r):
        t += int(a[j][i])
    C.append(t)
a.append(C)
for i in a:
    for j in range(len(i)):
        if j != len(i)-1:
            print(i[j], end =" ")
        else:
            print(i[j])

Submission status: Accepted

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

Submission status: Accepted

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

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

list.append([])

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


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

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
tbl = [[] for _ in range(r)]
cSum = [0 for _ in range(c+1)]

for i in range(r):
  tblS = input()
  tbl[i] = list(map(int, tblS.split()))
  print(tblS, end = '')
  print(' ', sum(tbl[i]), sep = '')

  for j in range(c):
    cSum[j] += tbl[i][j]
  cSum[c] += sum(tbl[i])

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

Submission status: Accepted

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

num_list = []
for i in range(n):
    num_list.append(list(map(int,input().split())))
    
allpoint = 0
retu_point = []

for i in range(n):
    print(*num_list[i], end="")
    print(" ", end ="")
    print(sum(num_list[i]))
    

for i in range(m):
    tmp = 0
    for j in range(n):
        tmp += num_list[j][i]
        
    retu_point.append(tmp)
    
print(*retu_point, end ="")
print(" ", end ="")
print(sum(retu_point))

Submission status: Accepted

Solution code:
def main_v2():
    row, column = list(map(int, input().split()))
    lst = [[0 for _ in range(column + 1)] for _ in range(row + 1)]

    for i in range(row):
        tmp = list(map(int, input().split()))
        for j in range(column):
            lst[i][j] = tmp[j]
        lst[i][column] = sum(lst[i])

    for j in range(column + 1):
        for i in range(row):
            lst[row][j] += lst[i][j]

    for i in range(row + 1):
        print(lst[i][0], end="")
        for j in range(1, column + 1):
            print(f" {lst[i][j]}", end="")
        print()

    return 0


if __name__ == "__main__":
    main_v2()

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:
r, c = (int(x) for x in input().split())

table = []

for i in range(r):
    table.append([int(x) for x in input().split()])

for row in table:
    row.append(sum(row))

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

for row in table:
    ans_row = " ".join(list(map(str,row)))
    print(ans_row)

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

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

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

sheet.append(sum_list)

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

Submission status: Accepted

Solution code:
n , k = map(int,input().split(' '))
s = [list(map(int,input().split(' '))) for i in range(n)]
x = [i*0 for i in range(k+1)]
s.append(x)
temp = 0
for i in range(n):
    ans = 0
    for v in range(k):
        ans += s[i][v]
        s[n][v] += s[i][v]
    s[i].append(ans)
    temp += ans
s[n][k] = temp
for i in s:
    print(*i)

Submission status: Accepted

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

col_sum = [0]*(c+1)
for col in range(c+1):
    for row in range(r):
        col_sum[col] += mat[row][col]
for row in range(r):
    print(' '.join(map(str,mat[row])))
print(' '.join(map(str,col_sum)))

Submission status: Accepted

Solution code:
r, c = [int(arg) for arg in input().split()]
table = [[int(arg) for arg in input().split()] for _ in range(r)]
new_row = [0] * (c+1)
for row in table:
    row.append(sum(row))
    for j, v in enumerate(row):
        new_row[j] += v
table.append(new_row)
for row in table:
    print(' '.join([str(i) for i in row]))

Submission status: Accepted

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

for i in range(r):
    row = list(map(int, input().split()))
    sheet.append(row)
    sheet[i].append(sum(sheet[i]))
    
sheet.append([sum(col) for col in zip(*tuple(sheet))])


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

Submission status: Accepted

Solution code:
r, c=(int(x) for x in input().split())
graph=[[int(x) for x in input().split()] for i in range(r)]
for i in range(r):
    sum=0
    for j in range(c):
        sum+=graph[i][j]
    graph[i].append(sum)
new=[]
for i in range(c+1):
    sum=0
    for j in range(r):
        sum+=graph[j][i]
    new.append(sum)
graph.append(new)
for i in range(r+1):
    for j in range(c+1):
        if j!=c:
            print(graph[i][j], end=" ")
        else:
            print(graph[i][j])

Submission status: Accepted

Solution code:
r,c = map(int,input().split())
i = 1
tb1 = [[0 for i in range(c+1)] for j in range(r+1)]
while i <= r:
    C = list(map(int,input().split()))
    for j in range(c):
        tb1[i-1][j] = C[j] 
    tb1[i-1][c] = sum(C) 
    i+=1
for i in range(c+1):
    tb1[r][i] = sum([row[i] for row in tb1])

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

Submission status: Accepted

Solution code:
x,y=map(int,input().split())

y_li = []
x_li = []
for _ in range(x):
    li = list(map(int,input().split()))
    li_sum = sum(li)
    li.append(li_sum)
    y_li.append(li)

for i in range(y+1):
    x_li.append((sum(e[i] for e in y_li)))
y_li.append(x_li)

for ans in y_li:
    print(' '.join(map(str,ans)))

Submission status: Accepted

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

Data = []

while True:
    if r == 0:
        break
    temp = input().split()
    Data.append(list(map(int,temp)))
    r -= 1

# output
for a in Data:
    a.append(sum(a))

temp = [0]*(c+1)
for a in Data:
    temp = [x + y for(x,y) in zip(temp,a)]
Data.append(temp)

for a in Data:
    b = map(str,a)
    print(' '.join(b))

Submission status: Accepted

Solution code:
table = [[0 for i in range(101)] for j in range(101)]
Row, Col = list(map(int, input().split()))

R_total = 0
C_total = 0

for i in range(Row):
    num = list(map(int, input().split()))
    R_num = 0
    for j in range(Col):
        table[i][j] = num[j]
        R_num += num[j]
    table[i][j+1] = R_num

for c in range(Col+1):
    C_num = 0
    for r in range(Row):
        C_num += table[r][c]
    table[r+1][c] = C_num

for i in range(Row+1):
    for j in range(Col+1):
        if j > 0: print(" ", end="")
        print(f"{table[i][j]}", end="")
    print()

Submission status: Accepted

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

r,c = map(int, input().split())
sumrow = [0 for _ in range(c+1)]
for rowidx in range(r):
    row = list(map(int, input().split()))
    row.append(sum(row))
    print(*row)
    
    for colmunidx in range(c+1):
        sumrow[colmunidx] += row[colmunidx]
print(*sumrow)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
r,c = map(int,input().split())
cel = []
com = [0] * (c + 1)
for i in range(r + 1):
  if i < r:
    cel.append(list(map(int,input().split())))
    cel[i].append(sum(cel[i]))
    com = [x + y for (x,y) in zip(com, cel[i])]
  if i == r:
    cel.append(com)
  cel[i] = ' '.join(map(str,cel[i]))
[print(result) for result in cel]

Submission status: Accepted

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

last_line = []
for j in range(c):
    tmp = 0
    for i in range(r):
        tmp += arr[i][j]
#        print(i,j,arr[i][j],tmp)
    last_line.append(tmp)

#print(last_line)
arr.append(last_line)    


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

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

Submission status: Accepted

Solution code:
r,c=map(int,input().split())
table=list()
for i in range(r):
    table.append(list(map(int,input().split())))
for i in range(r):
    for j in range(c):
        print(table[i][j],"",end="")
    print(sum(table[i]),sep="")
bottom=list()
for i in range(c):
    tmp=0
    for j in range(r):
        tmp+=table[j][i]
    bottom.append(tmp)
for i in bottom:
    print(i,"",end="")
print(sum(bottom))

Submission status: Accepted

Solution code:
#標準入力
x,y = map(int,input().split())
num_list = []

#数値を入力して2次元リストに、
for _ in range(x):
    line = list(map(int,input().split()))
    line.append(sum(line))
    num_list.append(line)
#出力
    line1 = [str(a) for a in line]
    line1 = " ".join(line1)
    print(line1)
line = []
#縦の合計を計算
for num in range(0,y + 1):
    kei = 0
    for num1 in range(0,x):
        kei += num_list[num1][num]
    line.append(kei)
#出力
line1 = [str(a) for a in line]
line1 = " ".join(line1)
print(line1)

Submission status: Accepted

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

queue.append([])

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

queue[r].append(sum(queue[r]))

[print(queue[i][j]) if j == c else print(queue[i][j], end=' ') for i in range(r + 1) for j in range(c + 1)]

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
# r:行数, c:列数
# matrics = [[0 for i in range(0, c+1)] for j in range(0, r+1)]
matrics = [[0 for i in range(0, c)] for j in range(0, r)]
# print(matrics)

for i in range(0, r):
	matrics[i] = list(map(int, input().split()))
# print(matrics)

for i in matrics:
	sum = 0
	for j in i:
		sum = sum + j
	i.append(sum)
# print(matrics)

vectors = [0 for i in range(0, c + 1)]
for i in range(0, len(matrics)):
	for j in range(0, len(matrics[i])):
		vectors[j] = vectors[j] + matrics[i][j]

# print(vectors)
matrics.append(vectors)

# print(matrics)

for i in range(0, len(matrics)):
	for j in range(0, len(matrics[i])):
		if j != len(matrics[i]) - 1:
			print('{0} '.format(matrics[i][j]), end='')
		else:
			print(matrics[i][j])

Submission status: Accepted

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

rows = [0]*(r+1)
rows[r] = []
total = 0

for i in range(r):
    rows[i] = list(map(int, input().split()))
    total += sum(rows[i])
    rows[i].append(sum(rows[i]))
    
for j in range(c):
    col_sum = 0
    for i in range(r):
        col_sum += rows[i][j]
    rows[r].append(col_sum)

rows[r].append(total)

for i in range(r+1):
    for j in range(c+1):
        rows[i][j] = str(rows[i][j])
    line = " ".join(rows[i])
    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 = map(int, input().split())
spread = []
for i in range(r):
    spread.append(list(map(int, input().split())))

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

sum_c = [0] * c
for i in range(r):
    for j in range(c):
        sum_c[j] = sum_c[j] + spread[i][j]

sum_c.append(sum(sum_c))
spread.append(sum_c)
for i in spread:
    print(" ".join(map(str, i)))

Submission status: Accepted

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

matrix = []

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

sumlist = []

for C in range(c+1):
    SUM = 0
    for R in range(r):
        SUM += matrix[R][C]
    sumlist.append(SUM)
matrix.append(sumlist)

for R in range(r+1):
    for C in range(c+1):
        if C != c:
            print(matrix[R][C],end=' ')
        else:
            print(matrix[R][C],end='')
    print(end='\n')

Submission status: Accepted

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

for line in lines:
    line.append(sum(line))

lines.append([sum([line[i] for line in lines]) for i in range(c  + 1)])

for line in lines:
    print(*line)

Submission status: Accepted

Solution code:
r,c = map(int,input().split())
A=[list(map(int,input().split()))for _ in[0]*r]
B=A+[[sum(i)for i in zip(*A)]]
for i in B:
    print(*i,sum(i))

Submission status: Accepted

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

for i in range(r):
    for j in range(c+1):
        c_sum[j] += mat[i][j]
    
mat.append(c_sum)
for i in range(len(mat)):
    print(*mat[i])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
  row_num,col_num=map(int, input().split())  
  table=list()

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

    row_sum = 0
    for num in table[i]:
      row_sum += num
    table[i].append(row_sum)

  col_sum = list()
  for i in range(col_num):
    col = 0
    for j in range(row_num):
      col += table[j][i]
    col_sum.append(col)
  
  all_sum = 0
  for i in col_sum:
    all_sum += i
  col_sum.append(all_sum)
  table.append(col_sum)
  
  for row in table:
    print(*row)

if __name__ == '__main__':
  main()

Submission status: Accepted

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

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

Submission status: Accepted

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

a = []
b = []

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

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

a.append(b)

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

Submission status: Accepted

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

for j in range (len(rc[0])):
    sum_c = 0
    for i in range(len(rc)):
        sum_c = sum_c + rc[i][j]
    sum_cs.append(sum_c)
rc.append(sum_cs)
for i in range(len(rc)):
    for j in range(len(rc[0])):
        print(rc[i][j],end = "")
        if j != len(rc[0])-1:
            print(" ",end = "")
        else:
            print("")

Submission status: Accepted

Solution code:
m,n = list(map(int,input().split()))
tbl = [[0 for i in range(n+1)] for j in range(m+1)]
s= [0 for i in range(n+1)]
for i in range(m):
    l=list(map(int,input().split()))
    l.append(sum(l))
    tbl[i]=l
for j in range(n+1):
    for i in range(m):
        s[j] += tbl[i][j]
tbl[m] = s
for i in range(m+1):
    for j in range(n):
        print(tbl[i][j],end=" ")
    print(tbl[i][n],end="\n")

Submission status: Accepted

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

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

ss_row = []
for j in range(c+1):
    ss_rows_value = [k[j] for k in ss]
    ss_row.append(sum(ss_rows_value))
    
ss.append(ss_row)

for l in range(r+1):
    print (*ss[l])

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:
rc, cc = map(int, input().split())
i = 0
r = []
c_sum = [0] * cc

while rc > i:
    r.append([int(s) for s in input().split()])
    r[i].append(sum(r[i]))
    j = 0
    while cc > j:
        c_sum[j] += r[i][j]
        j += 1
    i += 1

i, j = 0, 0
while rc > i:
    while cc + 1 > j:
        if cc != j:
            print("{} ".format(r[i][j]), end="")
        elif cc == j:
            print(r[i][j])
        j += 1
    i += 1
    j = 0

c_sum.append(sum(c_sum))
i = 0
while cc + 1 > i:
    if cc != i:
        print("{} ".format(c_sum[i]), end="")
    elif cc == i:
        print(c_sum[i])
    i += 1

Submission status: Accepted

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

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

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

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

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

Submission status: Accepted

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

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

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

A.append(B)

for a in A:
    print(*a)

Submission status: Accepted

Solution code:


#出力の仕様うざすぎる

r_length,c_length  = map(int, input().split())

spread_sheet = [[0] * (c_length) for i in range(r_length + 1)]
for i in range(r_length):
    spread_sheet[i] = list(map(int, input().split()))

total = 0
for i in range(r_length):
    calc = 0
    for j in range(c_length):
        calc += spread_sheet[i][j]

    spread_sheet[i].append(calc)
    total += calc

for i in range (c_length):
    calc = 0
    for j in range(r_length):
        calc += spread_sheet[j][i]

    spread_sheet[r_length][i] = calc

spread_sheet[r_length].append(total)


for i in range(r_length + 1):
    print(spread_sheet[i][0], end='')
    for j in range(1,c_length + 1):
        print(f' {spread_sheet[i][j]}', end='')

   # if i != r_length:
    print('')

Submission status: Accepted

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

table=[]

for i in range(r):
    table.append(list(map(int, input().split(" "))))
#print(table)

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

table_t=[list(x) for x in zip(*table)]
#print(table_t)

for i in range(c+1):
    table_t[i].append(sum(table_t[i]))
#print(table_t)

ans=[list(x) for x in zip(*table_t)]
#print(ans)

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

Submission status: Accepted

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

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

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

for i in range(r):
    print(*num[i])
print(*num2)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
l = [list(map(int, input().split())) for i in range(N)]
new=[0 for i in range(M)]
for i in range(N):
    for j in range(M):
        new[j]+=l[i][j]
    for z in l[i]:
        print(z,end=" ")
    print(sum(l[i]))
for c in new:
    print(c,end=" ")
print(sum(new))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

a = [[int(t)for t in input().split()]for _ in [0]*r]

r_sum = []

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

c_sum = []

for i in range(c):
    s_ = 0
    for j in range(r):
        s_+=a[j][i]
    c_sum.append(s_)

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

for t in range(c):
    print(c_sum[t],end=' ')

print(sum(c_sum))

Submission status: Accepted

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

spread = [[0]*(c+1) for _ in range(r+1)]

#number = input().split()

for k in range(r):
    number = input().split()
    for i in range(c):
        spread[k][i] = int(number[i])
        spread[k][i+1] = sum(spread[k])

for l in range(r):
    for m in range(c+1):
        spread[r][m] += spread[l][m] 

for n in range(r+1):
    print(*spread[n])

Submission status: Accepted

Solution code:
row, column = map(int,input().split())
lis = [[0]*(column+1) for i in range(row+1)]
for i in range(row):

    inp = list(map(int,input().split()))
    lis[i] = inp + [0]

for i in range(row):
    for j in range(column):
        lis[row][j] += lis[i][j]
        lis[i][column] += lis[i][j]
        lis[row][column] += lis[i][j]

for i in range(row+1):
    print(*lis[i])

Submission status: Accepted

Solution code:
r,c = map(int, input().split())
f = [0 for i in range(c)]
for i in range(r):
  e = list(map(int,input().split()))
  for j in range(c) :
    print("{} ".format(e[j]),end="")
    f[j] += e[j]
  print(sum(e))

for j in range(c) :
  print("{} ".format(f[j]),end="")
print(sum(f))

Submission status: Accepted

Solution code:
row , col = map(int,input().split())
row = int(row)
end_num = 0

row_col_list = []
while True:
    base_suit = input()
    row_col_list.append(base_suit)

    end_num += 1
    if row == end_num:
        break

col_sum_list = []
for row in row_col_list:
    term = row.split()
    row_sum = 0
    col_list = []
    for r in term:
        row_sum += int(r)
        col_list.append(int(r))
        print('{} '.format(r),end='')
    
    col_list.append(row_sum)
    print(row_sum)
    col_sum_list.append(col_list)

for i in range(0,col+1):
    col_sum = 0
    for c in col_sum_list:
        col_sum += c[i]

    print('{}'.format(col_sum),end='')
    if i != col:
        print(' ',end='')

print()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!
data_1 = list(map(int,input().split()))
line_i = list()
for i in range(data_1[0]):
    line_i.append(list(map(int,input().split())))
    new = sum(line_i[i])
    line_i[i].append(new)
line_new = list()   
for k in range(data_1[1]+1):
    sammary =0
    for j in range(data_1[0]):
        sammary += line_i[j][k]
    line_new.append(sammary)
line_i.append(line_new)

for l in range(data_1[0]+1):
    print(" ".join(map(str,line_i[l])))

Submission status: Accepted

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

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

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

for a in A:
    print(*a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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

for col in range(a):
    Col = list(map(int, input().split()))
    for row in range(c):
        table[col][row] = Col[row]

for row in range(c):
    for col in range(a):
        table[a][row] += table[col][row]
        table[col][c] += table[col][row]
        table[a][c] += table[col][row]

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

    print()

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):
    ls = list(map(int, input().split()))
    for j in range(c):
        tbl[i][j] = ls[j]
        tbl[r][j] += ls[j]
        tbl[i][c] += ls[j]
    tbl[r][c] += tbl[i][c]


for i, row in enumerate(tbl):
    for j, col in enumerate(row):
        print (tbl[i][j],end='')
        if j != c:
            print(' ',end='')
    print()

Submission status: Accepted

Solution code:
# Inputを格納
r, c = map(int, input().split())
list = [list(map(int, input().split())) for i in range(r)]

# # テスト用インプット
# r, c = 2, 3
# list = [[1, 2, 3],[4, 5, 6]]

# 各行の合計値を出力
for i in range(r):
    list[i].append(sum(list[i]))
    print(*list[i])

# 各列の合計値を出力
sumList =[]
for j in range(c+1):
    sum = 0
    for i in range(r):
        sum += list[i][j]
    sumList.append(sum)
print(*sumList)

Submission status: Accepted

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

Submission status: Accepted

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

for row in range(r):
  A[row].append(sum(A[row]))

list = []
for col in range(c + 1):
  sum = 0
  for row in range(r):
    sum += A[row][col]
  list.append(sum)

A.append(list)
for row in range(r + 1):
  for col in range(c + 1):
    if(col == c): print(A[row][col])
    else: print(A[row][col], "", end = "")

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(a)]
for i in range(a):
    A[i].append(sum(A[i]))
bottom = [0]*(b+1)
for j in range(b+1):
    for i in range(a):
        bottom[j] += A[i][j]
for i in range(a):
    print(*A[i])
print(*bottom)