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: WA: Presentation Error

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):
    a = list(map(int, input().split()))
    for j in range(c):
        matrix[i][j] = a[j]
    matrix[i][c] = sum(a)
for l in range(c+1):
    for m in range(r):
        matrix[r][l] += matrix[m][l]

for cv in range(r+1):
    for fv in range(c+1):
        print("%s " % matrix[cv][fv], end='')
    print()

Submission status: WA: Presentation Error

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):
    a = list(map(int, input().split()))
    for j in range(c):
        matrix[i][j] = a[j]
    matrix[i][c] = sum(a)
for l in range(c+1):
    for m in range(r):
        matrix[r][l] += matrix[m][l]

for cv in range(r+1):
    for fv in range(c+1):
        print("%d " % matrix[cv][fv], end='')
    print()

Submission status: WA: Presentation Error

Solution code:
import sys

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

c = n

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

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

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

for i in a :
    for j in i :
        print(str(j), end=" ")
    print()

Submission status: WA: Presentation Error

Solution code:
r, c = map(int,input().split())
a=[]
for i in range(r):
    a.append(list(map(int,input().split())))
    a[i].append(0)
    aic = 0
    for k in range(c):
        aic = aic + a[i][k]
    a[i][c] = aic
a.append([0for i in range(c+1)])
for k in range(c):
    ark = 0
    for i in range(r):
        ark = ark + a[i][k]
    a[r][k] = ark
arc = 0
for i in range(r):
    arc = arc +a[i][c]
a[r][c] = arc

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

Submission status: WA: Presentation Error

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