qyliang/CodeNanoFix huggingface dataset:
Buggy code:
m,n=map(int,input().split())
a =[]
for _ in range(m):
    a.append(list(map(int,input().split())))
for index in range(m):
    a[index].append(sum(a[index]))
for a_column in a:
    for num in a_column:
        print(num, end=' ')
    print()
for row_index in range(n+1):
    sum = 0
    for a_column in a:
        sum += a_column[row_index]
    print(sum, end=' ')



Fixed code:
m,n=map(int,input().split())
a =[]
for _ in range(m):
    a.append(list(map(int,input().split())))
for index in range(m):
    a[index].append(sum(a[index]))
for a_column in a:
    for num in a_column[:-1]:
        print(num, end=' ')
    print(a_column[-1])
for row_index in range(n):
    sum = 0
    for a_column in a:
        sum += a_column[row_index]
    print(sum, end=' ')
sum = 0
for a_column in a:
    sum += a_column[-1]
print(sum)
Buggy code:
n, m = map(int, input().split())
a = []
b = []
for i in range(n):
    a += [list(map(int, input().split()))]
    print(a)
    a[i] += [sum(a[i])]
for i in range(m+1):
    b += [sum(x[i] for x in a)]
a += [b]
for i in range(n+1):
    print(*a[i])


Fixed code:
n, m = map(int, input().split())
a = []
b = []
for i in range(n):
    a += [list(map(int, input().split()))]
    a[i] += [sum(a[i])]
for i in range(m+1):
    b += [sum(x[i] for x in a)]
a += [b]
for i in range(n+1):
    print(*a[i])
Buggy code:
a, b = map(int, input().split())
al = []
b_lis = []

for _ in range(a):
    g = list(map(int, input().split()))
    g.append(sum(g))
    al.append(g)
for i in range(b+1):
    p = 0
    for j in range(a):
        p += al[j][i]
    b_lis.append(p)
al_1.append((b_lis))
for i in al_1:
    print(' '.join([str(v) for v in i]))


Fixed code:
a, b = map(int, input().split())
al = []
b_lis = []

for _ in range(a):
    g = list(map(int, input().split()))
    g.append(sum(g))
    al.append(g)
for i in range(b+1):
    p = 0
    for j in range(a):
        p += al[j][i]
    b_lis.append(p)
al.append((b_lis))
for i in al:
    print(' '.join([str(v) for v in i]))
Buggy code:
r,c=map(int,input().split())
N=[list(map(int,input().split())) for i in range(r)]
retu=[[0 for i in range(1)] for j in range(1)] 
for j in range(c):
  ret=0
  for i in range(r):
    ret+=N[i][j]
  if j==0:
    retu[0][0]+=ret
  else:
    retu[0].append(ret)
N.extend(retu)
for i in range(r+1):
  tuika=0
  for j in range(c):
    tuika+=N[i][j]
  N[i].append(tuika)
  
for i in range(r+1):
  for j in range(c+1):
    if j!=(c+1):
      print(N[i][j],"",end="")
    else:
      print(N[i][j])
  print("")


Fixed code:
r,c=map(int,input().split())
N=[list(map(int,input().split())) for i in range(r)]
retu=[[0 for i in range(1)] for j in range(1)] 
for j in range(c):
  ret=0
  for i in range(r):
    ret+=N[i][j]
  if j==0:
    retu[0][0]+=ret
  else:
    retu[0].append(ret)
N.extend(retu)
for i in range(r+1):
  tuika=0
  for j in range(c):
    tuika+=N[i][j]
  N[i].append(tuika)
  
for i in range(r+1):
  for j in range(c+1):
    if j==0:
      print(N[i][j],end="")
    else:
      print("",N[i][j],end="")
  print("")
Buggy 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 tmp]), total)

Fixed 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)
Buggy 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[rc][c] += row_total

for row in table:
    for column in row:
        print(column, end=' ')

    print()

Fixed 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]))
Buggy 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])

Fixed 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]))
Buggy 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)]
for rc in range(r):
    for cc in range(c):
        last_row[cc] += src[rc][cc]
src = append(last_row)


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

Fixed 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]]))
Buggy 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)))

Fixed 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)))
Buggy 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+1:
            print(" ",end="")
        if j == c :
            print("")

Fixed 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("")
Buggy code:
N = input().split()
r = int(N[0])
c = int(N[1])
d = [[0 for i in range(c)] for j in range(r)]
for i in range(r):
    data = input().split()
    for j in range(c):
        d[i][j] = int(data[j])
sum2 = [0 for i in range(c)]
for i in range(r):
    line = ''
    for j in range(c):
        line += str(d[i][j])
        line += ' '
        sum2[j] += d[i][j]
    line += str(sum(d[i]))
    print(line)
line2 = ''
for i in range(c):
    line2 += str(sum2[i])
    line2 += ' '
print('{0} {1}'.format(line2, sum(sum2)))

Fixed code:
N = input().split()
r = int(N[0])
c = int(N[1])
d = [[0 for i in range(c)] for j in range(r)]
for i in range(r):
    data = input().split()
    for j in range(c):
        d[i][j] = int(data[j])
sum2 = [0 for i in range(c)]
for i in range(r):
    line = ''
    for j in range(c):
        line += str(d[i][j])
        line += ' '
        sum2[j] += d[i][j]
    line += str(sum(d[i]))
    print(line)
line2 = ''
for i in range(c):
    line2 += str(sum2[i])
    line2 += ' '
print('{0}{1}'.format(line2, sum(sum2)))
Buggy code:
# -*- coding: utf-8 -*-
r,c = [int(a) for a in input().split(' ')]
arr = []
Hsum=0
for x in range(r):
    i =[int(a) for a in input().split(' ')]
    i.append(sum(i))
    arr.append(i)
arr2=[]
for y in range(c+1):
    for z in range(r):
        Hsum += arr[z][y]
    arr2.append(Hsum)
    Hsum=0
arr.append(arr2)

for y in range(r+1):
    for z in range(c+1):
        print(arr[y][z], end =" ")
    else:
        print()

Fixed code:
# -*- coding: utf-8 -*-
r,c = [int(a) for a in input().split(' ')]
arr = []
Hsum=0
for x in range(r):
    i =[int(a) for a in input().split(' ')]
    i.append(sum(i))
    arr.append(i)
arr2=[]
for y in range(c+1):
    for z in range(r):
        Hsum += arr[z][y]
    arr2.append(Hsum)
    Hsum=0
arr.append(arr2)

for y in range(r+1):
    for z in range(c+1):
        if z == c:
            print(arr[y][z])
        else:
            print(arr[y][z],end = " ")
Buggy code:
rc=list(map(int,input().split()))
a=[[0 for x in range(rc[1]+1)]for x in range(rc[0]+1)]
for x in range(rc[0]):
    code=list(map(int,input().split()))
    result=0
    for y in range(rc[1]):
        a[x][y]=code[y]
        result+=code[y]
    a[x][rc[1]]=result

for y in range(rc[1]+1):
    result=0
    for x in range(rc[0]):
        result+=a[x][y]
    a[rc[0]][y]=result

for x in range(rc[0]+1):
    string=""
    for y in range(rc[1]+1):
        string+=str(a[x][y])
        if (y!=rc[1]+1):
            string+=" "
    print(string)

Fixed code:
rc=list(map(int,input().split()))
a=[[0 for x in range(rc[1]+1)]for x in range(rc[0]+1)]
for x in range(rc[0]):
    code=list(map(int,input().split()))
    result=0
    for y in range(rc[1]):
        a[x][y]=code[y]
        result+=code[y]
    a[x][rc[1]]=result

for y in range(rc[1]+1):
    result=0
    for x in range(rc[0]):
        result+=a[x][y]
    a[rc[0]][y]=result

for x in range(rc[0]+1):
    string=""
    for y in range(rc[1]+1):
        string+=str(a[x][y])
        if (y!=rc[1]):
            string+=" "
    print(string)
Buggy code:
r, c = [int(i) for i in input().split()]

data = []
sum_row = [0] * (c + 1)
for ri in range(r):
    data.append([int(i) for i in input().split()])
    data[ri].append(sum(data[ri]))
    print(" ".join(str[d] for d in data[ri]))
    for ci in range(c + 1):
        sum_row[ci] += data[ri][ci]

print(" ".join([str(s) for s in sum_row]))

Fixed code:
r, c =[int(i) for i in input().split()]
 
date =[]
sum_row = [0] * (c + 1)
 
for ri in range(r):
    date.append([int(i) for i in input().split()])
    date[ri].append(sum(date[ri]))
    print(" ".join([str(d) for d in date[ri]]))
    for ci in range(c + 1):
        sum_row[ci] += date[ri][ci]
 
print(" ".join([str(s) for s in sum_row]))
Buggy code:
r, c = map(int, input().split())
mat =[]

for x in range(r):
 mat.append(list(map(int, input().split())))

for x in range(r):
 rsum = 0
 for y in range(c):
  rsum += mat[x][y]
 mat[x].append(rsum)

mat.append([])

for x in range(c):
 csum = 0
 for y in range(r):
  csum += mat[y][x]
 mat[r].append(csum)

for x in range(r):
 for y in range(c):
  print("{0} ".format(mat[x][y]), end = '')
 print(mat[x][c])

for x in range(c-1):
 print("{0} ".format(mat[r][x]), end='')
print(mat[r][c-1])
 

Fixed code:
r, c = map(int, input().split())
mat =[]

for x in range(r):
 mat.append(list(map(int, input().split())))

tsum = 0

for x in range(r):
 rsum = 0
 for y in range(c):
  rsum += mat[x][y]
  tsum == mat[x][y]
 mat[x].append(rsum)

mat.append([])

for x in range(c):
 csum = 0
 for y in range(r):
  csum += mat[y][x]
  tsum += mat[y][x]
 mat[r].append(csum)



for x in range(r):
 for y in range(c):
  print("{0} ".format(mat[x][y]), end = '')
 print(mat[x][c])

for x in range(c):
 print("{0} ".format(mat[r][x]), end='')
print(tsum)
Buggy code:
r,c = map(int,input().split(' '))
arr = [[0 for i in range(c+1)] for i in range(r+1)]

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

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

for i in range(c):
    for j in range(r):
        print(arr[i][j],end = ' ')
    print(arr[i][-1])

Fixed code:
r,c = map(int,input().split(' '))
arr = [[0 for i in range(c+1)] for i in range(r+1)]

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

for i in range(r):
    for j in range(c):
        arr[i][-1] += arr[i][j]
for i in range(c):
    for j in range(r):
        arr[-1][i] += arr[j][i]
        
if c == 1:
    for i in range(r):
        arr[-1][-1] += arr[i][0]
elif r == 1:
    for i in range(c):
        arr[-1][-1] += arr[0][i]
else:
    for i in range(r):
        arr[-1][-1] += arr[i][-1]
    
for i in range(r+1):
    for j in range(c):
        print(arr[i][j],end = ' ')
    print(arr[i][-1])
Buggy code:
r,c = map(int,input().split())
ss = [[int(i) for i in input().split()]for j in range(r)]
sum_ss = [0 for i in range(c + 1)]
for row in ss:
    row.append(sum(row))
    sum_ss = [x+y for (x, y) in zip(sum_ss, row)]
    print(' '.join(map(str, row)))

Fixed code:
r,c = map(int,input().split())
ss = [[int(i) for i in input().split()]for j in range(r)]
sum_ss = [0 for i in range(c + 1)]
for row in ss:
    row.append(sum(row))
    sum_ss = [x+y for (x, y) in zip(sum_ss, row)]
    print(' '.join(map(str, row)))
print(' '.join(map(str, sum_ss)))
Buggy 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)]

Fixed code:
r,c = map(int,input().split())
s_row = [0 for i in range(c+1)]
for i in range(r):
    row = [int(i) for i 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]))
Buggy code:
max_row, max_col = map(int, input().split(" "))
rows = [[0 for i in range(max_col)] for j in range(max_row)]
row = ""

for i in range(max_row):
    row =  input().split(" ")
    total_row = 0
    for j in range(max_col):
        rows[i][j] = int(row[j])
        total_row = total_row + int(row[j])
    rows[i].append(total_row)
    
#get summery of each columns
total = [0 for i in range(max_col+1)]
for m in range(max_col+1):
    for n in range(max_row):
        total[m] = total[m] + rows[n][m]
rows.append(total)


for i in range(max_row+1):
    out_str = ""
    for j in range(max_col+1):    
        out_str = out_str + " " + str(rows[i][j]) 
    
    print(out_str)

Fixed code:
max_row, max_col = map(int, input().split(" "))
rows = [[0 for i in range(max_col)] for j in range(max_row)]
row = ""

for i in range(max_row):
    row =  input().split(" ")
    total_row = 0
    for j in range(max_col):
        rows[i][j] = int(row[j])
        total_row = total_row + int(row[j])
    rows[i].append(total_row)
    
#get summery of each columns
total = [0 for i in range(max_col+1)]
for m in range(max_col+1):
    for n in range(max_row):
        total[m] = total[m] + rows[n][m]
rows.append(total)


for i in range(max_row+1):
    out_str = ""
    for j in range(max_col+1):    
        out_str = out_str + " " + str(rows[i][j]) 
    
    print(out_str.strip())
Buggy 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):
    a_tmp = list(map(int,input().split()))
    for j in range(c):
        a[i][j] = a_tmp[j]
        a[i][c+1] += a_tmp[j]
        a[r+1][j] += a_tmp[j]
        a[r+1][c+1] += a_tmp[j]

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

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

for i in range(r+1):
    print(' '.join(str(x) for x in a[i]))
Buggy code:
r, c = map(int, input().split())
sheet = [[0 for i in range (r)] for j in range(c)]

for i in range(r):
	sheet[i] = input().split()
	k = 0
	for j in range(c):
		k += int(sheet[i][j])
	sheet[i].append(k)

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

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

for i in range(r):
	sheet[i] = input().split()
	k = 0
	for j in range(c):
		k += int(sheet[i][j])
	sheet[i].append(k)
	
l=[0 for i in range (c+1)]
for j in range(c+1):
	for i in range(r):
		l[j] += int(sheet[i][j])
		#print(sheet[i][j])
sheet.append(l)

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('')
Buggy code:
table = []
r, c = map(int, input().strip().split())
[table.append(input().strip().split()) for i in range(r)]

print(table)
for j in range(r + 1):
    for k in range(c + 1):
        if j == r and k != c:
            lastrow = sum(map(int, [table[x][k] for x in range(r)]))
            table[-1].append(lastrow)
        if k == c:
            print(sum(map(int, table[j])))
            break
        print(table[j][k],end=' ')

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

for j in range(r + 1):
    for k in range(c + 1):
        if j == r and k != c:
            lastrow = sum(map(int, [table[x][k] for x in range(r)]))
            table[-1].append(lastrow)
        if k == c:
            print(sum(map(int, table[j])))
            break
        print(table[j][k],end=' ')
Buggy code:
iranai = [int(i) for i in input().split()]
iru = [[int(i) for i in input().split()] for i in range(iranai[0])]
mikitani = []
son = []
num = 0
mikicount = 0

for i in range(iranai[0]):
    for i2 in range(iranai[1]):
        num += iru[i][i2]
    mikitani.append(num)
    num = 0

for i in range(iranai[1]):
    for i2 in range(iranai[0]):
        num += iru[i2][i]
    son.append(num)
    num = 0

for i in range(iranai[0]):
    for i2 in range(iranai[1]):
        print(iru[i][i2],end=" ")
        if i2 = iranai[2]-1:
            print(mikitani[i])
    mikicount += mikitani[i]
son.append(mikicount)

for i in range(len(son)):
    if i == len(son)-1:
        print(son[i])
    else:
        print(son[i],end=" ")

Fixed code:
iranai = [int(i) for i in input().split()]
iru = [[int(i) for i in input().split()] for i in range(iranai[0])]
mikitani = []
son = []
num = 0
mikicount = 0
for i in range(iranai[0]):
    for i2 in range(iranai[1]):
        num += iru[i][i2]
    mikitani.append(num)
    num = 0

for i in range(iranai[1]):
    for i2 in range(iranai[0]):
        num += iru[i2][i]
    son.append(num)
    num = 0

for i in range(iranai[0]):
    for i2 in range(iranai[1]):
        print(iru[i][i2],end=" ")
        if i2 == iranai[1]-1:
            print(mikitani[i])
    mikicount += mikitani[i]
son.append(mikicount)

for i in range(len(son)):
    if i == len(son)-1:
        print(son[i])
    else:
        print(son[i],end=" ")
Buggy code:
r, c = [int(x) for x in input().split()]

matrix = []
for i in range(r):
    matrix.append([int(x) for x in input().split()])
    
for i in range(r):
    for j in range(c):
        print(matrix[i][j], '', end='')
    print(sum(matrix[i]))

for j in range(c):
    csum = 0
    for i in range(r):
        csum += matrix[i][j]
    print(csum, '', end='')
    crsum = 0
    crsum += csum
print(crsum)

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

matrix = []
for i in range(r):
    matrix.append([int(x) for x in input().split()])
    
for i in range(r):
    for j in range(c):
        print(matrix[i][j], '', end='')
    print(sum(matrix[i]))

crsum = 0
for j in range(c):
    csum = 0
    for i in range(r):
        csum += matrix[i][j]
    print(csum, '', end='')
    crsum += csum
print(crsum)
Buggy code:
r,c = [int(i) for i in input().split()]
a = [[0 for i in range(r+2)] for j in range(c)]
for i in range(r):
	a[i] = [int(j) for j in input().split()]
for i in range(r):
	rowSum = 0
	for j in range(c):
		rowSum += a[i][j]
	a[i].append(rowSum)
for i in range(c+1):
	columnSum = 0
	for j in range(r):
		columnSum += a[j][i]
	a[r][i] = columnSum
for i in range(r+1):
	for j in range(c+1):
		print(a[i][j],end=' ')
	print()

Fixed code:
r,c = [int(i) for i in input().split()]
a = [[0 for i in range(c+1)] for j in range(r+1)]
for i in range(r):
	a[i] = [int(j) for j in input().split()]
for i in range(r):
	rowSum = 0
	for j in range(c):
		rowSum += a[i][j]
	a[i].append(rowSum)
for i in range(c+1):
	columnSum = 0
	for j in range(r):
		columnSum += a[j][i]
	a[r][i] = columnSum
for i in range(r+1):
	for j in range(c):
		print(a[i][j],end=' ')
	print(a[i][c])
Buggy code:
# coding: utf-8
# Here your code !
 
import math
 
def func():
    try:
        (rows,columns) = [ int(item) for item in input().rstrip().split(" ") ]
        data = [ [ int(item) for item in input().rstrip().split(" ") ] for i in range(rows) ]
    except:
        return inputError()
        
    [item.append(sum(item)) for item in data]
    data.append( [sum( [ item[i] for item in data ] ) for i in range(columns+1) ])
    
    result=""
    for row in data:
        for item in row:
            result += str(item)+" "
        result.rstrip(" ")
        result += "\n"
    
    print(result.rstrip())

def inputError():
    '''
    print("input Error")
    return -1
    '''
 
    print("input Error")
    return -1
     
func()

Fixed code:
# coding: utf-8
# Here your code !
 
import math
 
def func():
    try:
        (rows,columns) = [ int(item) for item in input().rstrip().split(" ") ]
        data = [ [ int(item) for item in input().rstrip().split(" ") ] for i in range(rows) ]
    except:
        return inputError()
        
    [item.append(sum(item)) for item in data]
    data.append( [sum( [ item[i] for item in data ] ) for i in range(columns+1) ])
    
    result=""
    for row in data:
        for item in row:
            result += str(item)+" "
        result=result.rstrip()
        result += "\n"
    print(result.rstrip())

def inputError():
    '''
    print("input Error")
    return -1
    '''
 
    print("input Error")
    return -1
     
func()
Buggy code:
r,c = map(int, input().split())
L=[]
for i in range(r):
 al = input()
 print(al, end="")
 AL = list(map(int, al.split()))
 S = sum(AL)
 print(" " + str(S))
 AL. append(S)
 L.append(AL)

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

Fixed code:
r,c = map(int, input().split())
L=[]
for i in range(r):
 al = input()
 print(al, end="")
 AL = list(map(int, al.split()))
 S = sum(AL)
 print(" " + str(S))
 AL. append(S)
 L.append(AL)

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

S = 0
for j in range(r):
 S += L[j][-1]
print(str(S))