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) = [int(i) for i in input().split()]

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

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

for rc in range(r):
    row_total = 0
    for cc in range(c):
        table[r][cc] += table[rc][cc]
        row_total += table[rc][cc]

    table[rc].append(row_total)
    table[r][c] += row_total

for row in table:
    print(' '.join([str(column) for column in row]))

Submission status: Accepted

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

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

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

for rc in range(r):
    row_total = 0
    for cc in range(c):
        table[r][cc] += table[rc][cc]
        row_total += table[rc][cc]

    table[rc].append(row_total)
    table[r][c] += row_total

for row in table:
   print(' '.join([str(column) for column in row]))

Submission status: Accepted

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

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

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

for rc in range(r):
    row_total = 0
    for cc in range(c):
        table[r][cc] += table[rc][cc]
        row_total += table[rc][cc]

    table[rc].append(row_total)
    table[r][c] += row_total

for row in table:
    print(' '.join([str(column) for column in row]))

Submission status: Accepted

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

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

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


for rc in range(r):
    row_total = 0
    for cc in range(c):
        table[r][cc] += table[rc][cc]
        row_total += table[rc][cc]

    table[rc].append(row_total)
    table[r][c] += row_total

for row in table:
   print(' '.join([str(column) for column in row]))

Submission status: Accepted

Solution code:
(r, c) = [int(i) for i in input().split()]
 
ct = [0 for d in range(c)]
tmp = []
for rc in range(r):
    tmp = [int(i) for i in input().split()]
    total = 0
    for cc in range(c):
        ct[cc] += tmp[cc]
        total += tmp[cc]
        print(tmp[cc], end=' ')
    print(total)
total = sum(ct)
print(' '.join([str(i) for i in ct]), total)

Submission status: Accepted

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

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

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

for rc in range(r):
    row_total = 0
    for cc in range(c):
        table[r][cc] += table[rc][cc]
        row_total += table[rc][cc]

    table[rc].append(row_total)
    table[r][c] += row_total

for row in table:
    print(' '.join([str(column) for column in row]))

Submission status: Accepted

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

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

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

for rc in range(r):
    row_total = 0
    for cc in range(c):
        table[r][cc] += table[rc][cc]
        row_total += table[rc][cc]

    table[rc].append(row_total)
    table[r][c] += row_total

for row in table:
        print(' '.join([str(column) for column in row]))

Submission status: Accepted

Solution code:
while True:
    try:
        r,c = map(int,raw_input().split())
        if r == c == 0:
            break
    except EOFError:
        break
    
    array = []
    for i in range(r):
        array.append(map(int,raw_input().split()))
    
    # column sum
    # add a new sum-row 
    c_sum_row = [0 for ii in range(c)]
    for k in range(c):
        for j in range(r):
            c_sum_row[k] += array[j][k]
    array.append(c_sum_row)
    
    # row sum
    # append sum item to end of each row
    for k in range(r+1):
        array[k].append(sum(array[k]))
    
    for k in range(r+1):
        print ' '.join(map(str,array[k]))

Submission status: Accepted

Solution code:
def trans(A):
    """????¬??????????????????¢???"""
    return list(map(list, zip(*A)))

if __name__ == '__main__':
    r, c = [int(i) for i in input().split()]
    sheet = [[int(i) for i in input().split()] for y in range(r)]
    [sheet[y].append(sum(sheet[y])) for y in range(r)]
    sheet = trans(sheet)
    [sheet[y].append(sum(sheet[y])) for y in range(c+1)]
    sheet = trans(sheet)
    [print(' '.join([str(i) for i in sheet[y]])) for y in range(r+1)]

Submission status: Accepted

Solution code:
#coding:utf-8
#1_7_C 2015.4.6
r,c = map(int,input().split())
sheet = [list(map(int,input().split())) for i in range(r)]

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

s = [sum(list(row[i] for row in sheet)) for i in range(c + 1)]
sheet.append(s)

for row in sheet:
    print(*row)

Submission status: Accepted

Solution code:
import sys

r, c = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
csums = [0]*c
rsum = 0
output = []
for k in range( r ):
	matrix = [ int( val ) for val in sys.stdin.readline().split( " " ) ]

	rsum = 0
	for i in range( c ):
		rsum += matrix[i]
		output.append( "{:d} ".format( matrix[i] ) )	
		csums[i] += matrix[i]
		
	output.append( "{:d}\n".format( rsum ) )

rsum = 0
for val in csums:
	rsum += val
	output.append( "{:d} ".format( val ) )	
	
output.append( "{:d}".format( rsum ) )
print( "".join( output ) )

Submission status: Accepted

Solution code:
x,y=map(int,raw_input().split())
a=[map(int,raw_input().split()) for i in range(x)]
for i in range(x):
	a[i].append(sum(a[i]))
	for j in range(y+1):
		print a[i][j],
	print
for i in range(y+1):
	print sum([row[i] for row in a]),

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
matrix = []
for i in range(r):
    l = list(map(int, input().split()))
    l.append(sum(l))
    matrix.append(l)
matrix.append([sum(i) for i in zip(*matrix)])
for l in matrix:
    print(" ".join(str(n) for n in l))

Submission status: Accepted

Solution code:
if __name__ == "__main__":

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

    s = [0] * n * m

    for c in xrange(n):
        s[c*m:c*m+m] = map( int, raw_input().split())

    csum = [0] * n
    rsum = [0] * m
    for c in xrange(n):
        for r in xrange(m):
            csum[c] += s[m*c + r]
            rsum[r] += s[m*c + r]
            print s[m*c + r],
        print csum[c]
    asum = 0
    for i in xrange(m):
        asum += rsum[i]
        print rsum[i],
    print asum

Submission status: Accepted

Solution code:
# coding=utf-8


def main():
    r, c = map(int, raw_input().split())
    rSum = [0] * (c + 1)
    for _ in xrange(r):
        row = map(int, raw_input().split() + ['0'])
        row[-1] = sum(row)
        print ' '.join(map(str, row))
        for i in xrange(c + 1):
            rSum[i] += row[i]
    print ' '.join(map(str, rSum))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
matrix = []
for _ in range(r):
    L = list(map(int, input().split()))
    matrix.append(L + [sum(L)])
matrix.append([sum(column) for column in zip(*matrix)])
for row in matrix:
    print(' '.join(map(str, row)))

Submission status: Accepted

Solution code:
(r,c) = [int(i) for i in input().split()]
 
table = []
for rc in range(r):
    table.append([int(i) for i in input().split()])
 
table.append([0 for _ in range(c + 1)])
 
for rc in range(r):
    row_total = 0
    for cc in range(c):
        table[r][cc] += table[rc][cc]
        row_total += table[rc][cc]
 
    table[rc].append(row_total)
    table[r][c] += row_total
 
for row in table:
    print(' '.join([str(column) for column in row]))

Submission status: Accepted

Solution code:
raws, columns = map(int, input().strip().split())
a = []
for i in range(raws):
    a.append(list(map(int, input().strip().split())))
for i in range(raws):
    a[i].append(sum(a[i]))
a.append([sum(i) for i in zip(*a)])
for r in a:
    print(' '.join(str(x) for x in r))

Submission status: Accepted

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

# sum c
last_row = [ 0 for _ in range( c+1)]
for rc in range(r):
    for cc in range( c+1):
        last_row[cc] += num[rc][cc]
num.append( last_row)
'''
for i in range(r):
     print( sum( [ num[js] for js in range(c)])
    #last_row[i] = sum( [ num[js] for js in range(c)])
'''

for rc in range( r+1):
    print( ' '.join( [ str(a) for a in num[rc]]))

Submission status: Accepted

Solution code:
(r, c) = [int(i) for i in input().split()]
src = []
for _ in range(r):
    row = [int(i) for i in input().split()]
    row.append(sum(row))
    src.append(row)
last_row = [0 for _ in range(c + 1)]
for rc in range(r):
    for cc in range(c+1):
        last_row[cc] += src[rc][cc]
src.append(last_row)

for rc in range(r+1):
    print(' '.join([str(a) for a in src[rc]]))

Submission status: Accepted

Solution code:
(r, c) = [int(i) for i in input().split()]
src = []
for _ in range(r):
    row = [int(i) for i in input().split()]
    row.append(sum(row))
    src.append(row)
last_row = [0 for _ in range(c + 1)]
for rc in range(r):
    for cc in range(c+1):
        last_row[cc] += src[rc][cc]
src.append(last_row)
 
for rc in range(r+1):
    print(' '.join([str(a) for a in src[rc]]))

Submission status: Accepted

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

last_row = [0 for _ in range(c+1)]
for rc in range(r):
    for cc in range(c+1):
        last_row[cc] += src[rc][cc]
src.append(last_row)


for rc in range(r+1):
    print(' '.join([str(a) for a in src[rc]]))

Submission status: Accepted

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

last_row = [0 for _ in range(c+1)]
for rc in range(r):
    for cc in range(c+1):
        last_row[cc] += src[rc][cc]
src.append(last_row)
for rc in range(r+1):
    print(' '.join([str(a) for a in src[rc]]))

Submission status: Accepted

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

last_row = [0 for _ in range(c + 1)]
for rc in range(r):
    for cc in range(c+1):
        last_row[cc] += src[rc][cc]

src.append(last_row)


for rc in range(r + 1):
    print(' '.join([str(a) for a in src[rc]]))

Submission status: Accepted

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

for _ in range(r):
    row = [int(i) for i in input().split()]
    for cc in range(c):
        last_row[cc] += int(row[cc])
        print(row[cc], end=' ')

    print(sum(row))

last_row[-1] = sum(last_row)
print(' '.join([str(a) for a in last_row]))

Submission status: Accepted

Solution code:
(r, c) = [int(i) for i in input().split()]
last_row = [0 for _ in range(c+1)]
 
for _ in range(r):
    row = [int(i) for i in input().split()]
    for cc in range(c):
        last_row[cc] += int(row[cc])
        print(row[cc], end=' ')
 
    print(sum(row))
 
last_row[-1] = sum(last_row)
print(' '.join([str(a) for a in last_row]))

Submission status: Accepted

Solution code:
rc = [int(i) for i in input().split()]
data = []

for i in range(rc[0]):
    sum_c = [int(i) for i in input().split()]
    sum_c.append(sum(sum_c))
    data += [sum_c]
    print(" ".join(map(str,sum_c)))

hoge = [[row[i] for row in data] for i in range(rc[1])]

sum_r = [sum(hoge[i]) for i in range(rc[1])]
sum_r.append(sum(sum_r))
print(" ".join(map(str,sum_r)))

Submission status: Accepted

Solution code:
input_list = raw_input().split(" ")
r = int(input_list[0])
c = int(input_list[1])

i = 0
array = []
while i < r:
  input_line = raw_input().split(" ")
  array.append(map(int, input_line))
  i += 1

# print array

for i in xrange(len(array)):
  sum = 0
  for j in xrange(len(array[i])):
    sum += array[i][j]
  array[i].append(sum)

# print array

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

for i in xrange(r + 1):
  output = ""
  for j in xrange(c + 1):
    output += " " + str(array[i][j])
  print output.strip()

Submission status: Accepted

Solution code:
rc = [int(i) for i in input().split()]
data = []
 
for i in range(rc[0]):
    sum_c = [int(i) for i in input().split()]
    sum_c.append(sum(sum_c))
    data += [sum_c]
    print(" ".join(map(str,sum_c)))
 
hoge = [[row[i] for row in data] for i in range(rc[1])]
 
sum_r = [sum(hoge[i]) for i in range(rc[1])]
sum_r.append(sum(sum_r))
print(" ".join(map(str,sum_r)))

Submission status: Accepted

Solution code:
(r, c) = [int(i) for i in input().split()]
src = []
for _ in range(r):
    row = [int(i) for i in input().split()]
    row.append(sum(row))
    src.append(row)
 
last_row = [0 for _ in range(c + 1)]
for rc in range(r):
    for cc in range(c+1):
        last_row[cc] += src[rc][cc]
 
src.append(last_row)
 
 
for rc in range(r + 1):
    print(' '.join([str(a) for a in src[rc]]))

Submission status: Accepted

Solution code:
(r, c) = [int(i) for i in input().split()]
src = []
for i in range(r):
    row = [int(i) for i in input().split()]
    row.append(sum(row))
    src.append(row)
 
last_row = [0 for _ in range(c+1)]
for rc in range(r):
    for cc in range(c+1):
        last_row[cc] += src[rc][cc]
src.append(last_row)
for rc in range(r+1):
    print(' '.join([str(a) for a in src[rc]]))

Submission status: Accepted

Solution code:
r,c=map(int,raw_input().split())
a=[map(int,raw_input().split()) for _ in xrange(r)]
sums,l=0,[]
for i in xrange(r):
	a[i].append(sum(a[i]))
for i in xrange(c+1):
	for j in xrange(r):
		sums+=a[j][i]
	l.append(sums)
	sums=0
a.append(l)
for i in a:
	for j in xrange(c+1):
		if j==c: print i[j]
		else: print i[j],

Submission status: Accepted

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

Submission status: Accepted

Solution code:
R, C = map(int, raw_input().split())
chart = []
for r in range(R):
    row = map(int, raw_input().split())
    chart.append(row)
col = [0] * C
for r in range(R):
    row = chart[r]
    row.append(sum(row))
    print ' '.join(map(str, row))
    for c in range(C):
        col[c] += row[c]
for c in range(C):
    print col[c],
print sum(col)

Submission status: Accepted

Solution code:
R, C = map(int, raw_input().split())
chart = [map(int, raw_input().split()) for r in range(R)]
col = [0] * C
for r in range(R):
    row = chart[r]
    row.append(sum(row))
    print ' '.join(map(str, row))
    for c in range(C):
        col[c] += row[c]
for c in range(C):
    print col[c],
print sum(col)

Submission status: Accepted

Solution code:
(r, c) = [int(i) for i in input().split()]
src = []
for _ in range(r):
    row = [int(i) for i in input().split()]
    row.append(sum(row))
    src.append(row)
last_row = [0 for _ in range(c + 1)]
for rc in range(r):
    for cc in range(c+1):
        last_row[cc] += src[rc][cc]
src.append(last_row)
  
for rc in range(r+1):
    print(' '.join([str(a) for a in src[rc]]))

Submission status: Accepted

Solution code:
import sys

r,c = map(int,raw_input().split())
table_list = [[0 for i in range(c)]for j in range(r)]
for k in range(r):
	Sum = 0
	table_list[k] = map(int,raw_input().split())
	for l in table_list[k]:
		Sum += l
	table_list[k].append(Sum)
end_list = []
for m in range(c):
	Sum = 0
	for n in range(r):
		Sum += table_list[n][m]
	end_list.append(Sum)
Sum = 0
for o in end_list:
	Sum += o
end_list.append(Sum)
table_list.append(end_list)
for p in range(r+1):
	for q in range(c+1):
			if q==c:
				print '%d' %table_list[p][q]
			else :
				sys.stdout.write(str(table_list[p][q]))
				sys.stdout.write(' ')

Submission status: Accepted

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

sum_row = []

for i in range(c + 1):
    sum_row.append(0)

for i in range(r):
    tmp_row = tuple(map(int, input().split()))
    tmp_row_sum = sum(tmp_row)
    tmp_row += tmp_row_sum,
    print(" ".join(map(str, tmp_row)))
    for j in range(c + 1):
        sum_row[j] += tmp_row[j]

print(" ".join(map(str, sum_row)))

Submission status: Accepted

Solution code:
in_line = raw_input().split()
r = int(in_line[0])
c = int(in_line[1])
data = []
for i in range(0,r):
    in_line = raw_input().split()
    data.append([])
    for j in range(0,c):
        data[i].append(int(in_line[j]))
for data_r in data:
    sum_r = 0
    for data_c in data_r:
        sum_r += data_c
        print data_c,
    data_r.append(sum_r)
    print sum_r
for j in range(0,c+1):
    sum_c = 0
    for i in range(0,r):
        sum_c += data[i][j]
    print sum_c,

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(' '.join(map(str, table[i])), end='')
    print(' {}'.format(sum(table[i])))

total = 0
for j in range(c):
    column_sum = 0
    column_sum = sum([row[j] for row in table])
    print('{} '.format(column_sum), end='')
    total += column_sum
print(total)

Submission status: Accepted

Solution code:
r, c = map(int, raw_input().split(" "))
table1 = [[0 for j in range(c)] for i in range(r)]
for i in range(r):
    table1[i] = map(int, raw_input().split(" "))

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

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

ans = ""
for i in range(r+1):
    for j in range(c+1):
        ans += str(table2[i][j])
        if j!=c:
            ans += " "
    if i!=r:
        ans += "\n"

print ans

Submission status: Accepted

Solution code:
r, c = map(int, raw_input().split(" "))
table1 = [[0 for j in range(c)] for i in range(r)]
for i in range(r):
    table1[i] = map(int, raw_input().split(" "))

table2 = [0 for j in range(c+1)]
ans = ""
for i in range(r):
    tmp = 0
    for j in range(c):
        ans += str(table1[i][j]) + " "
        tmp += table1[i][j] 
        table2[j] += table1[i][j]
    ans += str(tmp) + "\n"
for j in range(c+1):
    ans += str(table2[j])
    table2[c] += table2[j]
    if j!=c:
        ans += " "

print ans

Submission status: Accepted

Solution code:
def show2dlist(nlist,r,c):
    for x in xrange(0,r):
        nlist[x] = map(str,nlist[x])
        ans = " ".join(nlist[x])
        print ans
def showlist(nlist,nlistlen):
    for x in xrange(nlistlen):
        print nlist[x],

r,c = map(int,raw_input().split())
table = [[0 for x in xrange(c)] for y in xrange(r)]
i = 0
for x in xrange(r):
    table[i] = map(int,raw_input().split())
    i+=1
# calc table
csumlist =[0 for x in xrange(0,c+1)]
for x in xrange(0,r):
    table[x].append(sum(table[x]))
    for y in xrange(0,c+1):
        csumlist[y] += table[x][y]
show2dlist(table,r,c+1)
showlist(csumlist,c+1)

Submission status: Accepted

Solution code:
# coding: utf-8

row,col = map(int, input().split())

cells = []

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

cells.append([0] * (col + 1))
for c in range(col + 1):
    for r in range(row):
        cells[row][c] += cells[r][c]

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

Submission status: Accepted

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

ss= [[int(i) for i in input().split()] for j in range(r)]
colsum = [0 for i in range(c+1)]

for row in ss:
    row.append(sum(row))
    colsum = [x+y for (x, y) in zip(colsum, row)]
    print(' '.join(map(str, row)))

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

Submission status: Accepted

Solution code:
data = []
r, c = [int(n) for n in input().split()]
result = [0 for n in range(c)]

for i in range(r):
    data.append([int(n) for n in input().split()])
    for j in range(c):
        result[j] += data[i][j]
data.append(result)
for i in range(r + 1):
    data[i].append(sum(data[i]))
    print(' '.join([str(n) for n in data[i]]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

printf = sys.stdout.write


mat = []
new_map = []

r,c = map(int, raw_input().split())
for i in range(r):
    mat = map(int, raw_input().split())
    new_map.append(mat)


for i in range(r):
    new_map[i].append(sum(new_map[i][:]))
    for j in range(c):
        print new_map[i][j],
    printf(" " + str(new_map[i][j + 1]) + "\n")


for j in range(c + 1):
    a = 0
    for i in range(r):
        a += new_map[i][j]
    if j == c:
        printf(" " + str(a) + "\n")
        break
    else:
        print a,

Submission status: Accepted

Solution code:
height,width=map(int,input().split())
A=[]
for i in range(height):
	A.append([int(j) for j in input().split()])


for i in range(height):
	print(' '.join(map(str,A[i])),str(sum(A[i])))

B=[]
C=[0 for _ in range(width)]
for i in range(width):
	for j in range(height):
		s=0
		s+=A[j][i]
		B.append(s)
	C[i]=sum(B)
	B=[]
print(' '.join(map(str,C)),str(sum(C)))

Submission status: Accepted

Solution code:
r, c = (int(i) for i in input().split())
table = tuple([int(x) for x in input().split()] for _ in range(r))
for cols in table:
  cols.append(sum(cols))
  print(*cols)
else:
  sums = tuple(sum(table[y][x] for y in range(r)) for x in range(c + 1))
  print(*sums)

Submission status: Accepted

Solution code:
r,c = map(int,raw_input().split())
cels = []
for i in xrange(r):
    cols = map(int, raw_input().split())
    cels.append(cols)

for i in xrange(r):
    cels[i].append(sum([ j for j in cels[i]]))

sum_c=[]
for i in xrange(c):
    sum_c.append(sum([cels[n][i] for n in xrange(r)]))

cels.append(sum_c)
cels[r].append(sum(cels[r]))

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

r, c = map(int, raw_input().split())
mat = {}
for i in range(1, r+1):
    col = map(int, raw_input().split())
    for j in range(1, c+1):
        mat[(i, j)] = col[j-1]

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

for j in range(1, c+2):
    mat[(r+1, j)] = 0
    for i in range(1, r+1):
        mat[(r+1, j)] += mat[(i, j)]

for i in range(1, r+2):
    buf = ""
    for j in range(1, c+1):
        buf += str(mat[(i, j)]) +" "
    buf += str(mat[(i, c+1)])
    print buf

Submission status: Accepted

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

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

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

ret = []
for i in range(r+1):
    ret.append([trans[j][i] for j in range(c+1)])
    print(' '.join(map(str, ret[i])))

Submission status: Accepted

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

for i in range(r) :
    s = 0
    for j in range(c) :
        s = s + a[i][j]
        b[j] = b[j] + a[i][j]
    a[i].append(s)
    print ' '.join(map(str,a[i]))
b.append(sum(b))
print ' '.join(map(str,b))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

for i in range(r+1):
    print(' '.join(str(x) for x in sheet[i]))

Submission status: Accepted

Solution code:
import sys

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

c_sum = 0
sum_vector = [0 for i in xrange(c+1)]

for i in xrange(r):
	temp = map(int, raw_input().split())
	temp.append(sum(temp))
	for j in xrange(c):
		sum_vector[j] += temp[j]
		sys.stdout.write(str(temp[j])+" ")
	else:
		sum_vector[c] += temp[c]
		print temp[c]

for i in xrange(c):
	sys.stdout.write(str(sum_vector[i])+" ")
print sum_vector[c]

Submission status: Accepted

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

data = []

for y in range(r):
    row = list(map(int, input().split()))
    data.append(row)

colsum = [0 for i in range(c + 1)]
for y in range(r):
    data[y].append(sum(data[y]))
    for x in range(c + 1):
        colsum[x] += data[y][x]

data.append(colsum)

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

Submission status: Accepted

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

data = []

for y in range(r):
    row = list(map(int, input().split()))
    data.append(row)
    
colsum = [0 for i in range(c + 1)]
for y in range(r):
    data[y].append(sum(data[y]))
    for x in range(c + 1):
        colsum[x] += data[y][x]
    
data.append(colsum)

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

Submission status: Accepted

Solution code:
#   ??¨????????°r??¨?????°c???r ?? c ???????´????????????¨?????????????????§???????????¨??????????¨?????????\????????°????????¨???????????????????????°??????
r, c = map(int, input().split())
spreadSheet = [[0 for i in range(c + 1)] for j in range(r + 1)]
#   ??¨??\????????????
for i in range(0, r):
    spreadSheet[i][:c] = map(int, input().split())
    #   print(spreadSheet)
#   ?????????????¨??????????
for i in range(0, r):
    for j in range(0, c):
        spreadSheet[i][c] += spreadSheet[i][j]
#   ?????????????¨??????????
for i in range(0, c + 1):
    for j in range(0, r):
        spreadSheet[r][i] += spreadSheet[j][i]
#   print(spreadSheet)
for i in range(0, r + 1):
    for j in range(0, c + 1):
        print("{0}".format(spreadSheet[i][j]), end="")
        if j != c:
            print(" ",end="")
        else:
            print("")

Submission status: Accepted

Solution code:
#?????¨????????\???
row, cow = (int(i) for i in input().split())
#??????????????????(??\?????????????????????????´??????????????????????)
array = []
#??\?????????????????????????´?
for i in range(row):
    swap_list = input().split()
    array.append(swap_list)
#?????????????¨????????´?????????????????????????
row_sum = [0 for i in range(row)]
cow_sum = [0 for i in range(cow)]

#?????????????¨?????¨????
for i in range(row):
    for j in range(cow):
        row_sum[i] += int(array[i][j])
        cow_sum[j] += int(array[i][j])
#??¨??????????¨?
all_sum = sum(row_sum)

#?¨???????????????¨???
for i in range(row):
    #?????¨??????????¨??????¨???
    print(" ".join(map(str,array[i][:])),end = "")
    print(" {0}".format(row_sum[i]))
#??????????¨???¨?????°?????¨???
print(" ".join(map(str,cow_sum)),end = "")
print(" {0}".format(all_sum))

Submission status: Accepted

Solution code:
# 13-Structured_Program_II-Spreadsheet.py

# ??¨?¨????
# ??¨?¨??????????????°???????????????°???????????????????????????
# ??¨????????°r??¨?????°c???r ?? c ???????´????????????¨?????????????????§???
# ????????¨??????????¨?????????\????????°????????¨???????????????????????°?????????????????????????????????

# Input
# ???????????????r??¨c????????????????????§?????????????????????
# ?¶????r??????????????????c????????´??°????????????????????§?????????????????????

# Output
# (r+1) ?? (c+1) ?????°????????¨???????????????????????????
# ???????????£???????????´??°????????????????????§????????£??????????????????????????????????????¨??????????????????????¨?????????????????????????????????¨??????????????????????¨?????????????????????????????????¨??¨??????????¨????????????\??????????????????

# Constraints
# 1 ??? r, c ??? 100
# 0 ??? ????´? ??? 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

# ??? Aizu??§numpy ??????????????£??????
#---------------------------------------------------------------
# import numpy as np

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

# data = np.zeros((r,c))

# for i in range(r):
# 	data[i] = np.array( input().split() )

# data=data.astype("int")
# print("data",data)

# for i in range( r ):
# 	for j in range(c):
# 		print("{0} ".format(data[i][j]), end="")
# 	print( np.sum(data[i]) )

# for j in range(c):
# 	print("{0} ".format( np.sum(data, axis=0)[j] ), end="" )

# print( np.sum(data) )
#---------------------------------------------------------------


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

data = []
csum = [0]*c

for i in range(r):
	data.append(  list(map( int,input().split() ))  )

for i in range( r ):
	for j in range(c):
		print("{0} ".format(data[i][j]), end="")
		csum[j] +=data[i][j]
	print( sum(data[i]) )

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

print( sum(csum) )

Submission status: Accepted

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

row = []

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

matrix.append(row)
for i in range(r+1):
    for j in range(c+1):
        print(matrix[i][j],end="")
        if j != c:
            print(" ",end="")
        if j == c :
            print("")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
r,c = [int(x) for x in input().split()]
s_row = [0 for x in range(c+1)]
for i in range(r):
    row = [int(x) for x in input().split()]
    row.append(sum(row))
    print(" ".join([str(x) for x in row]))
    s_row = [x+y for x,y in zip(s_row,row)]
print(" ".join([str(x) for x in s_row]))