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:
#-*-coding:utf-8-*-

def main():
    lines=[]
    rows,coloums = map(int,input().split())
    lines=[list(map(int,input().split())) for _ in range(rows)]
    colmus_total=[0]*coloums
    for line in lines:
        row_total=0
        row_output=" ".join(map(str,line))
        for col_index,data in enumerate(line):
            row_total+=data
            colmus_total[col_index]+=data
        print(row_output,row_total)
    col_output=" ".join(map(str,colmus_total))
    print(col_output,sum(colmus_total))

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
r, c = [int(i) for i in input().strip().split()]
table = [[None] * (c + 1) for _ in range(r + 1)]

for i in range(r):
    line = [int(i) for i in input().strip().split()]
    for j in range(c):
        table[i][j] = line[j]

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

for i in range(r+1):
    table[i][c] = sum(table[i][:c])

for line in table:
    print(" ".join([str(i) for i in line]))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
sheet = [list(map(int,input().split())) for j in range(H)]
for i in range(H):
    sheet[i].append(sum(sheet[i]))
sheet.append([0 for i in range(W+1)])
for i in range(W+1):
    tmp = 0
    for j in range(H):
        tmp+=sheet[j][i]
    sheet[H][i] = tmp
for i in range(H+1):
    print(" ".join(map(str,sheet[i])))

Submission status: Accepted

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

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

calc_c_lst = []
for i in range(c):
    calc_c = 0
    for j in range(r):
        calc_c += nums[j][i]
    calc_c_lst.append(calc_c)
sum_c = sum(calc_c_lst)
calc_c_lst.append(sum_c)
ans_lst = nums + [calc_c_lst]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
rows,cols = map(int, input().split())
matrix = [[0 for cols in range(cols+1)] for rows in range(rows+1)]

for row in range(rows):
    vs = list(map(int, input().split()))
    for col in range(cols):
        matrix[row][col] = vs[col]
    matrix[row][cols] = sum(vs)

for col in range(cols + 1):
    total = 0
    for row in range(rows):
        total += matrix[row][col]
    matrix[rows][col] = total

for row in range(rows+1):
    for col in range(cols+1):
        if col == 0:
            print(f"{matrix[row][col]}", end="")
        else:
            print(f" {matrix[row][col]}", end="")
    print("")

Submission status: Accepted

Solution code:

a = []
i = 0
j = 0
sum = 0
sumsum = 0

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

while i < r:
    a.append(list(map(int, input().split())))
    i += 1

for i in range(r + 1):
    sum = 0

    if i < r:
        for j in range(c + 1):
            if j < c:
                print("%s " % a[i][j], end="")
                sum += a[i][j]
            else:
                print("%s" % sum)
    else:
        for j in range(c + 1):
            sum = 0

            if j < c:
                for i in range(r):
                    sum += a[i][j]
                    sumsum += a[i][j]
            
                print("%s " % sum, end="")
            else:
                print("%s" % sumsum)

Submission status: Accepted

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

for j in range(r):
    s = 0
    print(*l[j],end=" ")
    print(sum(l[j]))
    s = sum(l[j])
    a += s
    

for n in range(c):
    c = 0
    for m in range(r):
        c += l[m][n]
    print(c,end=" ")
print(a)

Submission status: Accepted

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

a=[list(map(int,input().split())) for i in range(n)]
b=[[0]*(m+1) for i in range(n+1)]

for i in range(n):
    for j in range(m):
        b[i][j]=a[i][j]

for i in range(n):
    tmp=0
    for j in range(m):
        b[i][m]+=b[i][j]
    print(*b[i])
    
for i in range(m+1):
    tmp=0
    for j in range(n):
        b[n][i]+=b[j][i]
print(*b[n])

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

ans = []
for i in range(r):
    tmp = list(map(int, input().split()))
    tmp.append(sum(tmp))
    ans.append(tmp)
    str_tmp = [str(s) for s in tmp]
    str_tmp = " ".join(str_tmp)
    print(str_tmp)

tmp = []
for i in range(c+1):
    total = 0
    for j in ans:
        total += j[i]
    tmp.append(total)
    
str_tmp = [str(s) for s in tmp]
str_tmp = " ".join(str_tmp)
print(str_tmp)

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])
a=list(zip(*a[::-1]))
for i in range(m):print(sum(a[i]),end=' ')
print(sum(a[m]))

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
r, c = list(map(int, input().split()))
t = [[int(x) for x in input().split()] for _ in range(r)]
for i in t:
    i.append(sum(i))
u = list(map(list, zip(*t)))
for i in u:
    i.append(sum(i))
for i in list(map(list, zip(*u))):
    print(' '.join(map(str, i)))

Submission status: Accepted

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

rc = []
for i in range(r):
  cs=[int(num) for num in input().split()]
  cs.append(sum(cs))
  rc.append(cs)

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

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

Submission status: Accepted

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

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

for i in range(len(box)):
    box[i].append(sum(box[i]))
    count = len(box[i])
    for a in box[i]:
        if count == 1:
            print(a)
        else:
            print(a, end = ' ')
        count -= 1
            

for x in range(c):
    result = 0
    for y in range(r):
        result += box[y][x]
    final += result
    print(result, end = ' ')

print(final)

Submission status: Accepted

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

for i in range(r):
    k=list(map(int, input().split()))
    for j in range(c):
        print(k[j], end=" ")
        s[j]+=k[j]
    print(sum(k))
    s[c]+=sum(k)
    
for i in range(c+1):
    print(s[i], end="")
    if i<c:
        print(" ", end="")
print("")

Submission status: Accepted

Solution code:
a, b = list(map(int, input().split()))
e=[0]*(b+1) 

for x in range(a):
    c=list(map(int, input().split()))
    d=0 
    for y in range(b):
        d+=c[y]
        e[y]+=c[y]
    c.append(d)
    e[b]+=c[b]
    print(*c)
print(*e)

Submission status: Accepted

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

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

sum_cols = []
for col in range(c):
    sum_col = 0
    for row in range(r):
        sum_col += t[row][col]
    sum_cols.append(sum_col)
t.append(sum_cols)

for row in range(r+1):
    t[row].append(sum(t[row]))

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

Submission status: Accepted

Solution code:
def row_sum(list):
    sum = 0
    for i in range(len(list)):
        sum += list[i]
    return sum

def column_sum(list, stop):
    sum = []
    for i in range(stop):
        temp_sum = 0
        for j in range(len(list)):
            temp_sum += list[j][i]
        sum.append(temp_sum)
    return(sum)

def answer(list, stop):
    list.append(column_sum(list, stop))
    for i in list:
        i.append(row_sum(i))
    return list

def print_list_list(list):
    for i in list:
        print(i[0],end="")
        for j in range(1, len(i)):
            print(" ", end="")
            print(i[j],end="")
        print()

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

ans = answer(a, c)
print_list_list(ans)

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
list_gyouretsu = []
list_last_gyou = []
for i in range(r):
  list_gyou = list(map(int, input().split()))
  list_gyouretsu.append(list_gyou)
  list_gyouretsu[-1].append(sum(list_gyou))
for j in range(c+1):
  sum = 0
  for k in range(r):
    sum += list_gyouretsu[k][j]
  list_last_gyou.append(sum)
list_gyouretsu.append(list_last_gyou)
for l in range(r+1):
  print(" ".join(map(str, list_gyouretsu[l])))

Submission status: Accepted

Solution code:
n_row, n_col = map(int, input().split(" "))
list_list_n = []
for i in range(n_row):
    list_list_n.append([int(_) for _ in map(int, input().split())])
    list_list_n[i].append(sum(list_list_n[i]))


list_sum = [0 for _ in range(n_col + 1)]
for list_n in list_list_n:
    for i, num in enumerate(list_n):
        if i == len(list_n) - 1:
            print(num, end="")
        else:
            print(num, end=" ")
        list_sum[i] += num
    print()

for j, sum_n in enumerate(list_sum):
    if j == len(list_sum) - 1:
        print(sum_n, end="")
    else:
        print(sum_n, end=" ")
print()

Submission status: Accepted

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

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

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

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

m = m+[l]


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

Submission status: Accepted

Solution code:
R, C = [int(n) for n in input().split()]
c_sum = [0]*C
for i in range(R):
  r = [int(n) for n in input().split()]
  for j in range(C):
    c_sum[j] += r[j]
  print(*(r + [sum(r)]))
print(*(c_sum + [sum(c_sum)]))

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):
    ai = list(map(int,input().split()))
    for j in range(c):
        a[i] [j] = ai[j]
#rint(a)


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


for a in a:
    print(*a)

Submission status: Accepted

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

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

ll = []
for k in range(c+1):
    s = 0
    for j in range(r):
        s += m[j][k]
    ll.append(s)
print(' '.join(map(str, ll)))

Submission status: Accepted

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

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

for line in arr:
    print(*line)

Submission status: Accepted

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

Submission status: Accepted

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

    print(*l)
print(*under)

Submission status: Accepted

Solution code:
# coding: utf-8
#71

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

A = [list(map(int,input().split())) for i in range(r)]
G=0
for i in range(r):
    a=0
    print(*A[i],end=' ')
    print(sum(A[i]))
    G += sum(A[i])
for j in range(c):
    b=0
    for k in range(r):
        b += A[k][j]
    print(b,end=' ')
print(G)

Submission status: Accepted

Solution code:
r,c = map(int,input().split(" "))
sumall = [0]*(c+1)
for i in range(r):
    x = list(map(int,input().split(" ")))
    sumx = sum(x)
    for j in range(c):
        sumall[j] += x[j]
        # print(sumall)
    sumall[c] += sumx
    newl = " ".join(map(str,x))
    print(newl + " " + str(sumx))
lastl = " ".join(map(str,sumall))
print(lastl)

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
z=[0]*(w+1)
for i in range(h):
    a=list(map(int,input().split()))
    a.append(sum(a))
    for y in range(w+1):
      z[y]+=a[y]
    x=''
    for j in a:
        x+=str(j)
        x+=' '
    x=x[:-1]
    print(x)
t=''
for s in z:
        t+=str(s)
        t+=' '
t=t[:-1]
print(t)

Submission status: Accepted

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

for l in range(line):
    work = list(map(int, input().split()))
    for r in range(row):
        table[l][r] = work[r]

for l in range(line):
    for r in range(row):
        table[l][row] += table[l][r]

for r in range(row + 1):
    for l in range(line):
        table[line][r] += table[l][r]

for l in range(line + 1):
    print('{}'.format(table[l][0]), end='')
    for r in range(1, row + 1):
        print(' {}'.format(table[l][r]), 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] += [sum(a[i])]

for i in range(r):
    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, input().split())
a = []

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

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

s = map(sum, list(zip(*a)))
print(*s)

Submission status: Accepted

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

for i in range(r):
  a.append(list(map(int, input().split())))#配列aに入力値を格納
  a[i].append(sum(a[i]))#その行の最終列にそれまでの和を格納

for i in range(r):
    print(" ".join(list(map(str, a[i]))))#a[i]はsumを経ているので一度文字列に変換し、joinで配列aに格納し、出力

csum =[]#r+1行目
for j in range(c+1):
  s = 0
  for i in range(r):
    s += a[i][j]
  csum.append(s)

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

Submission status: Accepted

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

for i in range(r):
    l = list(map(int, input().split()))
    for j in range(c):
        rc_t[i][j] = l[j]
        rc_t[i][c]+=l[j]
        rc_t[r][j]+=l[j]
        rc_t[r][c]+=l[j]
for i in rc_t:
    for x,j in enumerate(i):
        print(f'{j}', end='')
        if x != c:
            print(' ', end='')
    print()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
r,c=map(int,input().split())
l=[[int(a) for a in input().split()] for _ in range(r)]
for x in l:
  print(*x,sum(x))
print(*list(map(sum,zip(*l))),sum(sum(y) for y in l))

Submission status: Accepted

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

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

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

for i in range(r):
    print(*x[i])
print(*y)

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):
  for j in range(c):
    print(table[i][j], end = ' ')
  print(sum(table[i]))
for j in range(c):
  print(sum([table[i][j] for i in range(r)]), end = ' ')
print(sum([table[i][j] for i in range(r) for j in range(c)]))

Submission status: Accepted

Solution code:

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

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

for i in range(c):
    for j in range(r):
        lst[-1][i] += lst[j][i]
        
for i in range(r+1):
    for j in range(c):
        lst[i][-1] += lst[i][j]
        
for i in lst:
    print(*i)

Submission status: Accepted

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

arr = [input().split() for l in range(r)]

lastans = 0
for a in arr:
    ans = 0
    answord = ""
    for num in a:
        answord += num
        answord += " "
        ans += int(num)
    lastans += ans
    answord += str(ans)
    print(answord)

lastansword = ""
for i in range(c):
    ans = 0
    for j in range(r):
        ans += int(arr[j][i])
    lastansword += str(ans)
    lastansword += " "
lastansword += str(lastans)
print(lastansword)

Submission status: Accepted

Solution code:
rows, cols = (int(x) for x in input().split())

table = []
for r in range(rows):
    line = input().split()
    row = [int(x) for x in line]
    table.append(row)

final_row = [0] * (cols + 1)
for r in range(rows):
    table[r].append(sum(table[r]))
    for c in range(cols + 1):
        final_row[c] += table[r][c]
table.append(final_row)

for r in range(rows+1):
    line = ""
    for c in range(cols+1):
        line += str(table[r][c]) + " "
    print(line.strip())

Submission status: Accepted

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

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

  tmp += 1
print()

Submission status: Accepted

Solution code:
r,c=map(int,input().split())
lst=[]
for i in range(r):
    lst.append(list(map(int,input().split())))
for j in range(r):
    a=0
    for k in range(c):
        a+=lst[j][k]
    lst[j].append(a)
lst2=[]
for l in range(c+1):
    b=0
    for n in range(r):
        b+=lst[n][l]
    lst2.append(b)
lst.append(lst2)

for m in range(r+1):
    for o in range(c+1):
        if o==c:
            print(lst[m][o])
        else:
            print(lst[m][o],end=" ")

Submission status: Accepted

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

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

Submission status: Accepted

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

data.append([])

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

for li_int in data:
  li = [str(a) for a in li_int]
  li = ' '.join(li)
  print(li)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    a,b = map(int, input().split())
    s = []
    for i in range(a):
        temp = list(map(int, input().split()))
        s.append(temp)
    for i in range(a):
        temp_sum = sum(s[i])
        s[i].extend([temp_sum])
        print(*s[i])
    last = []
    temp_sum = 0
    for i in range(b+1):
        temp_sum = 0
        for k in range(a):
            temp_sum += s[k][i]
        last.append(temp_sum)
    print(*last)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
a = []
b = []

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

for i in range(c):
    x=0
    for i2 in range(r):
        x += a[i2][i]
    b.append(x)
a.extend([b])

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

Submission status: Accepted

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

a = [0 for i in range(r)] 

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

b = []

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

print(*b)

Submission status: Accepted

Solution code:
r,c=map(int,input().split())
x=[]
for i in range(r):
    x.append(list(map(int,input().split())))
    x[i].append(sum(x[i]))
    print(" ".join(list(map(str,x[i]))))
y=[]

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

Submission status: Accepted

Solution code:

def run():
    row,col=tuple(map(int,input().split()))
    
    A=[]
    
    for i in range(row):
        row_ls=list(map(int,input().split()))
        
        row_sum=sum(row_ls)
        
        A.append(row_ls+[row_sum])
        
    
    col_sum=[0 for i in range(col+1)]
    
    for j in range(col+1):
        for i in range(row):
            col_sum[j]+=A[i][j]
            
    A.append(col_sum)
    
    for i in range(row+1):
        for j in range(col+1):
            if j!=col:
                print(f"{A[i][j]} ",end="")
            else:
                print(f"{A[i][j]}")
                
run()

Submission status: Accepted

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


for i,x in enumerate(rows):
	_sum_=sum(x)
	rows[i].append(_sum_)



sums=[]
for i in range(len(rows[0])):
	_sum_=0
	for x in rows:
		_sum_+=x[i]
	sums.append(_sum_)

rows.append(sums)

for i in rows:
	for s,j in enumerate(i):
		print(f"{j}",end="")
		if s!=len(i)-1:
			print(" ",end="")

	print()

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

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

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

l = []
x = 0
for j in range(c):
    x = 0
    for k in range(r) :
        x += hyo[k][j]
    l.append(x)
l.append(sum(l))

for i in range(r):
    print(*hyo[i])
print(*l)

Submission status: Accepted

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

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

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

row = []

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

Submission status: Accepted

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

Submission status: Accepted

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

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

for x in range(r):
    print(*table[x],end=" ")
    print(sum(table[x]))

st = 0
for x in range(c):
    s = 0
    for y in range(r):
        s += table[y][x]
    print(s, end = " ")
    st += s
print(st)

Submission status: Accepted

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

table.append([0 for _ in range(c+1)])

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = [[0 for i in range(c+1)] for j in range(r+1)]
for i in range(r):
    for j in range(c):
        ans[i][j] = M[i][j]
        
for j in range(c):
    ans[r][j] = sum([ans[i][j] for i in range(r)])
    
for i in range(r+1):
    ans[i][c] = sum([ans[i][j] for j in range(c)])
    
for i in range(r+1):
    print(*ans[i])

Submission status: Accepted

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

idxr = 0
R = []

while idxr <= r - 1:
    R.append(list(map(int,input().split())))
    idxr += 1

for rr in R:
    print(*rr, sum(rr))

RR = []

for idxc in range(c):
    T = 0
    for rrr in R:
        T += rrr[idxc]
    RR.append(T)

print(*RR,sum(RR))

Submission status: Accepted

Solution code:

r, c = map(int, input().split())
d = [0] * c

for _ in range(r):
    a = input()
    b = list(map(int, a.split()))
    e = sum(b)
    a += ' {}'.format(e)
    print(a)
    d = [d[i] + b[i] for i in range(c)]

d = list(map(int, d))
g = sum(d)
f = ''
for i in d:
    f += str(i) + ' '
f += str(g)
print(f)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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


data.append([])

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


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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a,b = map(int, input().split())
listA = [[0 for i in range(b+1)] for j in range(a+1)]
for i in range(a):
    listA[i] = list(map(int, input().split()))

for i in range(a):
    s = sum(listA[i])
    listA[i].append(s)

for i in range(b):
    s = 0
    for j in range(a):
        s += listA[j][i]
    listA[a][i] = s

listA[a][b] = sum(listA[a])

for i in range(a+1):
    for j in range(b+1):
        if j == b:
            print(str(listA[i][j]))
        else:
            print(str(listA[i][j]) + ' ',end='')