Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03606 (python)

Fixed submission:
value = int(input())
people = 0
while True:
	try:
		seat = input()
		if seat:
			string_seat = seat.split()
			seat_list = []
			seat_list = [int(x) for x in (string_seat)]
			people += seat_list[len(seat_list)-1] - seat_list[0]+1
	except EOFError:
		break
# while True:
# 	seat = input()
# 	if seat:
# 		string_seat = seat.split()
# 		seat_list = []
# 		seat_list = [int(x) for x in (string_seat)]
# 		people += aaa(seat_list)
# 	else:
# 		break
print(people)

Buggy submission (verdict: Runtime Error):

def aaa(seat_list):
	return seat_list[len(seat_list)-1] - seat_list[0]+1

value = int(input())
people = 0
# while True:
# 	try:
# 		seat = input()
# 		if seat:
# 			string_seat = seat.split()
# 			seat_list = []
# 			seat_list = [int(x) for x in (string_seat)]
# 			people += aaa(seat_list)
# 	except EOFError:
# 		break
while True:
	seat = input()
	if seat:
		string_seat = seat.split()
		seat_list = []
		seat_list = [int(x) for x in (string_seat)]
		people += aaa(seat_list)
		print(people)
	else:
		break
print(people)

Buggy submission (verdict: Runtime Error):


def aaa(seat_list):
	return seat_list[len(seat_list)-1] - seat_list[0]

value = int(input())

people = 0
while True:
	try:
		seat = input()
		if seat:
			string_seat = seat.split()
			seat_list = []
			seat_list = [int(x) for x in (string_seat)]
			people += aaa(seat_list)
		except EOFError:
		break
print(people)

Buggy submission (verdict: Runtime Error):


def aaa(seat_list):
	return seat_list[len(seat_list)-1] - seat_list[0]

value = int(input())

people = 0
# while True:
# 	try:
# 		seat = input()
# 		seat_list.append(int(seat.split(" "))
# 	except EOFError:
# 		break
while True:
	seat = input()
	if seat:
		string_seat = seat.split()
		seat_list = []
		seat_list = [int(x) for x in (string_seat)]
		people += aaa(seat_list)
	else:
		break

print(people)
Problem p03607 (python)

Fixed submission:
import collections

cnt = int(input())
array = []
for i in range(cnt):
    array.append(int(input()))
cnt_dict = collections.Counter(array)

res = 0
for j in cnt_dict.values():
    if j % 2 != 0:
        res += 1
print(res)

Buggy submission (verdict: Runtime Error):

def duplicate_check(value, value_list):
	if value_list.count(value) == 2:
		while value in value_list: value_list.remove(value)
	return ()value_list
value_list = []
result_list = []
while True:
	try:
		number_of_test = int(input())
		value = int(input()
		value_list.append(value)
		result_list = duplicate_check(value, value_list)
	except EOFError:
		break

print(len(result_list))
Problem p03651 (python)

Fixed submission:
import fractions
import sys

n, k = map(int, input().split())
array = [int(x) for x in input().split()]

if n == 1:
    print("POSSIBLE" if max(array) == k else "IMPOSSIBLE")
    sys.exit()

res = fractions.gcd(array[0], array[1])

for i in array[2:]:
    res = fractions.gcd(res, i)
print("POSSIBLE" if k%res==0 and max(array) >= k else "IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
import fractions

n, k = map(int, input().split())
array = [int(x) for x in input().split()]

res = fractions.gcd(array[0], array[1])


for i in array[2:]:
    res = fractions.gcd(res, i)
print("POSSIBLE" if k%res==0 and max(array) >= k else "IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
import fractions

n, k = map(int, input().split())
array = [int(x) for x in input().split()]

res = fractions.gcd(array[0], array[1])


for i in array[2:]:
    res = math.gcd(res, i)
print("POSSIBLE" if k%res==0 and max(array) >= k else "IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
import math

n, k = map(int, input().split())
array = [int(x) for x in input().split()]

res = math.gcd(array[0], array[1])


for i in array[2:]:
    res = math.gcd(res, i)
print("POSSIBLE" if k%res==0 and max(array) >= k else "IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())

array = [int(x) for x in input().split()]
res = sorted(array)
judge = False
tmp = res.pop(0)
for i in res:
  if i%tmp != 0:
    judge = True
    break
if (len(res) == 0 and tmp != m) or res[-1] < m:
  judge = False
print("POSSIBLE" if judge else "IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):

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

array = [int(x) for x in input().split()]
res = sorted(array)
judge = False
tmp = res.pop(0)
for i in res:
  if i%tmp != 0:
    judge = True
    break
if res[-1] < m:
  judge = False
print("POSSIBLE" if judge else "IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())

array = [int(x) for x in range(n)]
res = sorted(array)
judge = False
tmp = res.pop(0)
for i in res:
  if i%tmp != 0:
    judge = True
    break
print("POSSIBLE" if judge else "IMPOSSIBLE")
Problem p03657 (python)

Fixed submission:
num = [int(x) for x in input().split()]
if num[0] %3 == 0 or num[1] % 3 == 0 or (num[0]+num[1]) %3 == 0:
    print("Possible")
else:
    print("Impossible")

Buggy submission (verdict: Runtime Error):
import math

num = int(input())

cards = [int(x) for x in input().split()]

res = sum(cards)
res2 = 0

judge = math.inf
if num == 2:
    judge = abs(cards[0]-cards[1])
else:
    for i in cards:
        res -= i
        res2 += i
        div = abs(res - res2)
        judge = div if div < judge else judge

print(judge)
Problem p03659 (python)

Fixed submission:

num = int(input())

cards = [int(x) for x in input().split()]

res = sum(cards)
res2 = 0

judge = float("inf")

if num == 2:
    judge = abs(cards[0]-cards[1])
else:
    for i in range(0, len(cards)):
        res -= cards[i]
        res2 += cards[i]
        div = abs(res - res2)
        judge = div if div < judge and i != len(cards)-1 else judge

print(judge)

Buggy submission (verdict: Runtime Error):
import math

num = int(input())

cards = [int(x) for x in input().split()]

res = sum(cards)
res2 = 0

judge = math.inf
if num == 2:
    judge = abs(cards[0]-cards[1])
else:
    for i in cards:
        res -= i
        res2 += i
        div = abs(res - res2)
        judge = div if div < judge else judge

print(judge)

Buggy submission (verdict: Runtime Error):
import math

num = int(input())

cards = [int(x) for x in input().split()]

res = sum(cards)
res2 = 0

judge = math.inf
if num == 2:
    judge = abs(cards[0]-cards[1])
else:
    for i in cards:
        res -= i
        res2 += i
        div = abs(res - res2)
        judge = div if div < judge else judge

print(judge)
Problem p03680 (python)

Fixed submission:


num = int(input())

array = []
for i in range(num):
    array.append(int(input()))

res = -1
if 2 in array:
    judge = array[0]
    roop = 1
    while judge != 2 and roop != 100001:
        roop += 1
        judge = array[judge-1]
        if judge == 2:
            break
else:
    judge = 10000000

if judge == 2:
    res = roop

print(res)

Buggy submission (verdict: Runtime Error):


num = int(input())

array = []
for i in range(num):
    array.append(int(input()))

res = -1
if 2 in array:
    judge = array[0]
    roop = 1
    while judge != 2 and roop != 100001:
        roop += 1
        judge = array[judge-1]
        if judge == 2:
            break
if judge == 2:
    res = roop

print(res)
Problem p03697 (python)

Fixed submission:
num = [int(x) for x in input().split()]
print(sum(num) if sum(num) < 10 else "error")

Buggy submission (verdict: Runtime Error):
num = int(input())

array = []
for i in range(num):
    array.append(int(input()))

point_max = sum(array)
tmp_max = point_max

array_sort = sorted(array)

if point_max % 10 != 0:
    print(point_max)
else:
    for i in array_sort:
        point_max -= i
        if point_max % 10 != 0:
            res = point_max
            break
        else:
            point_max += i
    print(0 if point_max == tmp_max else point_max)
Problem p03738 (python)

Fixed submission:
val =[]
val.append(int(input()))
val.append(int(input()))

if val[1] == val[0]:
    print("EQUAL")
elif val[0] > val[1]:
    print("GREATER")
else:
    print("LESS")

Buggy submission (verdict: Runtime Error):
/Users/miyauchitoru/Python_Competitive-programming/bin/python "/Users/miyauchitoru/PycharmProjects/Competitive_Programming/AtCorder/AtCoder Beginner Contest 077/compe.py"
123456789012345678901234567890
234567890123456789012345678901
LESS

Process finished with exit code 0
Problem p03838 (python)

Fixed submission:
x, y = map(int, input().split())
tmp = abs(abs(x) - abs(y))
if (y == 0 and 0 < x) or (x == 0 and y < 0):
    print(tmp + 1)
elif 0 <= x * y and x <= y:
    print(tmp)
elif 0 <= x * y and y < x:
    print(tmp + 2)
else:
    print(tmp + 1)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().spllit())
tmp = abs(n)-abs(m)
print(tmp if (n <= 0 and m <= 0) or  (n >= 0 and m >= 0) else tmp+1)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().spllit())
tmp = abs(n)-abs(m)
print(tmp if (n <= 0 and m <= 0) or  (n >= 0 and m >= 0) else tmp+1
Problem p03844 (python)

Fixed submission:
val = input().split()
if val[1] == "+":
    print(int(val[0])+int(val[2]))
else:
    print(int(val[0]) - int(val[2]))

Buggy submission (verdict: Runtime Error):
val = input().split()
if val[1] == "+":
    print(int(val[0]+int(val[2])))
else:
    print(int(val[0] - int(val[2])))
Problem p03846 (python)

Fixed submission:
num =int(input())

val = [int(x) for x in input().split()]

_len = len(val)
sort_val = sorted(val)
res = False

if len(sort_val) %2 == 0:
    tmp = sort_val[1::2]
    tmp2 = sort_val[::2]
    if sorted(tmp) == sorted(tmp2):
        res = True
else:
    if sort_val.count(0) != 1:
        pass
    else:
        del sort_val[0]
        tmp = sort_val[::2]
        tmp2 = sort_val[1::2]
        if sorted(tmp) == sorted(tmp2):
            res = True

cnt = 1
if res:
    for i in range(0, _len//2):
        cnt = cnt*2 % 1000000007

print(0 if not res else cnt)

Buggy submission (verdict: Runtime Error):
num =int(input())

val = [int(x) for x in input().split()]

_len = len(val)
sort_val = sorted(val)
set_val = set(sort_val)

res = True

if len(sort_val) %2 != 0 and sort_val[1] == 0:
    res = False
elif len(sort_val) %2 != 0 and sort_val[1] != 0:
    sort_val = sort_val[1:]
    set_val.remove(0)

if res:
    for i in set_val:
        if len(sort_val) == 2 and sort_val[0] == sort_val[1]:
            break
        if sort_val[2] == i:
            res = False
            break
        else:
            sort_val = sort_val[2:]


cnt = 1
if res:
    for i in range(0, _len//2):
        cnt = cnt*2 % 1000000007

print(0 if not res else cnt)
Problem p04031 (python)

Fixed submission:
num = int(input())

val = [int(x) for x in input().split()]

val2 = [int(x) for x in range(min(val), max(val))]


array = []
for i in val2:
    res = 0
    for j in val:
        res += pow(abs(i - j), 2)
    array.append(res)
print(min(array) if len(array) != 0 else 0)

Buggy submission (verdict: Runtime Error):
n = int(input())
a_array = [int(x) for x in input().split()]
sum_a = sum(a_array)
if sum_a % 2 == 0:
    sum_a = int(sum_a/len(a_array))
    ans = 0
    for a in a_array:
        ans += abs(sum_a-a)**2
    print(sum_a)
    print(int(ans))
else:
    sum_a1 = int(sum_a/len(a_array))
    sum_a2 = int(sum_a/len(a_array))+1
    ans1 = 0
    ans2 = 0
    for a in a_array:
        ans1 += abs(sum_a1-a)**2
        ans2 += abs(sum_a2-a)**2
    print(int(min(ans1, ans2)))

n = int(input())
a_array = [int(x) for x in input().split()]
ans = float("inf")
for i in range(-100, 101):
    tmp = 0
    for a in a_array:
        tmp += abs(a-i)**2
    ans = min(ans, tmp)
print(ans)
Problem p04043 (python)

Fixed submission:
a,b,c = map(int, input().split())
sum = [a, b, c]
if sum.count(5) == 2 and sum.count(7) == 1:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
import itertools

n, k = map(int, input().split())
array = {x for x in input().split()}
num_array = {str(x) for x in range(10)}
like_num = array^num_array

res = float("inf")
for i in range(1, 100000):
    tmp = set(list(str(i)))
    if tmp.issubset(like_num):
        if n <= i < res:
            res = i
print(res)
Problem p04044 (python)

Fixed submission:
n, l = map(int, input().split())

array = []
for i in range(n):
    array.append(input())
sort_array = sorted(array)
print("".join(sort_array))

Buggy submission (verdict: Runtime Error):
n, l = map(int, input().split())
array = sorted([input() for x in range(l)])

res = ""
for i in array:
    res += i

print(res)
Problem p04045 (python)

Fixed submission:
import itertools, math

n, k = input().split()
nums = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"} - {x for x in input().split()}
length = len(n)
coms = itertools.product(nums, repeat=length)
n = int(n)
ans = float("inf")
for com in coms:
    tmp = "".join(com)
    if n <= int(tmp) < ans:
        ans = int(tmp)

coms = itertools.product(nums, repeat=length+1)
for com in coms:
    tmp = "".join(com)
    if n <= int(tmp) < ans:
        ans = int(tmp)
print(ans)

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n, k;

    cin >> n >> k;
    vector<int>d_vec(k, 0);
    for (int i = 0; i < k; ++i) {
        cin >> d_vec[i];
    }

    int price = n;
    while (true){
        bool isValid = true;
        int digit_cnt = floor(log10(price));
        int now = price;
        for (int digit = 0; digit < digit_cnt+1; ++digit) {
            int tmp = now % 10;
            auto iter = find(d_vec.begin(), d_vec.end(), tmp);
            if (iter != d_vec.end()){
                isValid = false;
                break;
            }
            now /= 10;
        }

        if (isValid){
            cout << price << endl;
            break;
        }


        price++;
    }
    return 0;
Problem p02618 (python)

Fixed submission:
# coding: utf-8
# Your code here!

D = int(input())
# with open("sample1.in") as f:

#c = [0 for i in range(26)]
s = [[0 for j in range(27)] for i in range(D)]
c = list(map(int, input().split(" ")))
result=[]
# for i in range(26):
#    c[i] = int(input())
for i in range(D):
    a = list(map(int, input().split(" ")))
    for j, k in enumerate(a):
        #print(i, j, k)
        s[i][j] = int(k)
    result.append(a.index(max(a))+1)
    #print(a.index(max(a)))

for i in range(D):
    # print(s.index(max(s[i])))
    print(result[i])

Buggy submission (verdict: Runtime Error):

D = int(input())
# with open("sample1.in") as f:

last = [0 for i in range(26)]
s = [[0 for j in range(26)] for i in range(D)]
c = list(map(int, input().split(" ")))
result = []
total = 0
# opened = []  #開催したやつを保存
for i in range(D):
    a = list(map(int, input().split(" ")))
    for j, k in enumerate(a):
        #print(i, j, k)
        s[i][j] = int(k)
        # スコア計算
    score_max = 0
    score_index = 0
    for j in range(26):

        if j == 0:
            score_max = s[i][j]+(i + 1 - last[j]) * \
                c[j]  # - (i - last[j]) * c[j]
            for k in range(26):
                score_max -= (i + 1 - last[k]) * c[k]
            score_index = 0
        else:
            score = s[i][j]+(i+1 - last[j]) * c[j]
            for k in range(26):
                score -= (i + 1 - last[k]) * c[k]

            if score_max < score:
                score_max = score
                score_index = j
            #print(i, j, score)
    result.append(score_index)
    #print(score_index, score)
    last[score_index] = i + 1
    toral += score
    # print(a.index(max(a)))
# print(total)
for i in range(D):
    # print(s.index(max(s[i])))
    print(result[i]+1)

Buggy submission (verdict: Runtime Error):
D = int(input())
# with open("sample1.in") as f:

last = [0 for i in range(26)]
s = [[0 for j in range(26)] for i in range(D)]
c = list(map(int, input().split(" ")))
# for i in range(26):
#    c[i] = int(input())
result=[]
# opened = []  #開催したやつを保存
for i in range(D):
    a = list(map(int, input().split(" ")))
    for j, k in enumerate(a):
        #print(i, j, k)
        s[i][j] = int(k)
        # スコア計算
    score = 0
    score_index = 0
    for j in range(26):
        if j == 0:
            score_max = s[i][j] - (i + 1 - last[j]) * c[j]
            score_index = 0
        else:
            score = s[i][j] - (i + 1 - last[j]) * c[j]
            if score_max < score:
                score_max = score
                score_index = j
    result.appned(score_index)
    #print(score_index, score)
    last[score_index] = i
    # print(a.index(max(a)))

for i in range(D):
    # print(s.index(max(s[i])))
    print(result[i])
Problem p02714 (python)

Fixed submission:
def combi_three(n):
    if n < 3:
        return 0
    else:
        return int((n * (n - 1) * (n - 2)) / 6)

def quest_d():
    N = int(input())
    S = input()

    index_dict = {'R':0, 'G':0, 'B':0 }
    for index in range(N):
        index_dict[S[index]] = index_dict[S[index]] + 1

    if index_dict['R'] * index_dict['G'] * index_dict['B'] == 0:
        print(0)
        return

    rrr = combi_three(index_dict['R'])
    ggg = combi_three(index_dict['G'])
    bbb = combi_three(index_dict['B'])
    rrg = combi_three(index_dict['R'] + index_dict['G'])
    ggb = combi_three(index_dict['G'] + index_dict['B'])
    bbr = combi_three(index_dict['B'] + index_dict['R'])

    i = 0
    sum = 0
    while i < N:
        a = S[i]
        j = i
        while j < N - 1:
            j += 1
            if S[j] == a:
                continue

            k = 2 * j - i
            if k < N:
                b = S[j]
                if S[k] != a and S[k] != b:
                    sum += 1
        i += 1
    print(combi_three(N) - sum - rrg - bbr - ggb + rrr + ggg + bbb)

if __name__ == '__main__':
    quest_d()

Buggy submission (verdict: Runtime Error):
def quest_d():
    N = int(input())
    S = input()

    index_dict = {
        'R':0,
        'G':0,
        'B':0
    }
    for index in range(len(S)):
        index_dict[S[index]] = index_dict[S[index]] + 1

    if index_dict['R'] * index_dict['G'] * index_dict['B'] == 0:
        print(0)
        return

    rrr = combi_three(index_dict['R'])
    ggg = combi_three(index_dict['G'])
    bbb = combi_three(index_dict['B'])
    rrg = combi_three(index_dict['R'] + index_dict['G'])
    ggb = combi_three(index_dict['G'] + index_dict['B'])
    bbr = combi_three(index_dict['B'] + index_dict['R'])

    i = 0
    sum = 0
    while i < len(S):
        a = S[i]
        j = i
        while j < len(S) - 1:
            j += 1
            if S[j] == a:
                continue

            k = 2 * j - i
            if k < len(S):
                b = S[j]
                if S[k] != a and S[k] != b:
                    sum += 1
        i += 1
    print(combi_three(N) - sum - rrg - bbr - ggb + rrr + ggg + bbb)

if __name__ == '__main__':
    quest_d()
Problem p02718 (python)

Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))

MAX_VOTE_NUM = 1000

x = [-1] * MAX_VOTE_NUM
total_vote_num = 0
for i in range(n):
  x[a[i] - 1] = i
  total_vote_num += a[i]

popular_num = 0
for i in range(MAX_VOTE_NUM):
  index = MAX_VOTE_NUM - i
  if x[index - 1] != -1 and (index * 4 * m) >= total_vote_num:
    popular_num += 1

if popular_num >= m:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))

MAX_VOTE_NUM = 1000

x = [-1] * MAX_VOTE_NUM
total_vote_num = 0
for i in range(n):
  x[a[i] - 1] = i
  total_vote_num += a[i]

popular_num = 0
for i in range(MAX_VOTE_NUM):
  index = MAX_VOTE_NUM - 
  if x[index - 1] != -1 and (index * 4 * m) >= total_vote_num:
    popular_num += 1

if popular_num >= m:
  print('Yes')
else:
  print('No')
Problem p02719 (python)

Fixed submission:
n, k = map(int, input().split())

if n != k:
  x1 = n % k
  x2 = k - x1
  print(min(x1, x2))
else:
  print(0)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())

if n != k:
  x1 = n % k
  x2 = k - x1
  print(min(x1, x2))
else n == k:
  print(0)
Problem p02830 (python)

Fixed submission:
def f03():
    n=int(input())
    s, t=map(str, input().split())
    print(''.join([s[i]+t[i] for i in range(n)]))
f03()

Buggy submission (verdict: Runtime Error):
def f03():
    n=int(input())
    s, t=map(str, input().split())
    print(*[s[i]+t[i] for i in range(n)], seq='')
f03()
Problem p03068 (python)

Fixed submission:
def f06():
    n=int(input())
    S=input()
    k=int(input())
    for s in S:
        print(s if s==S[k-1] else '*', end='')
f06()

Buggy submission (verdict: Runtime Error):
def f06():
    n=int(input())
    s=input()
    k=int(input())
    x=s[k-1]
    for i in range(n):
        if s[i]!=x:
            s[i]='*'
    print(s)
f06()

Buggy submission (verdict: Runtime Error):
def f06():
    n=int(input())
    s=input()
    k=int(input())
    x=s[k-1]
    for i in range(n):
        if s[i]!=x:
            s[i]='*'
    print(''.join(s))
f06()
Problem p03378 (python)

Fixed submission:
def f10():
    N, M, X=map(int, input().split())
    A=[int(i)-1 for i in input().split()]
    X = X-1
    s=sum(A[i]<X for i in range(len(A)))
    print(min(s, M-s))

def main():
    f10()

main()

Buggy submission (verdict: Runtime Error):
def f10():
    N, M, X=map(int, input().split())
    A=[int(i)-1 for i in input().split()]
    X = X-1
    s=sum(A[i]<X for i in A)
    print(min(s, M-s))

def main():
    f10()

main()
Problem p03760 (python)

Fixed submission:
O=input()
E=input() + ' '
print(''.join([O[i]+E[i] for i in range(len(O))]))

Buggy submission (verdict: Runtime Error):
O=input()
E=input() + ''
print(''.join([O[i]+E[i] for i in range(len(O))]))

Buggy submission (verdict: Runtime Error):
def f07():
    O=input()
    E=input()
    print(''.join([O[i]+E[i] for i in range(len(O))]))
f07()
Problem p03860 (python)

Fixed submission:
s=input()
print('A' + s[8] + 'C')

Buggy submission (verdict: Runtime Error):
s=input()
ptint('A'+s[8]+'C')

Buggy submission (verdict: Runtime Error):
s=input()
print('A{}C'.format(s[8])

Buggy submission (verdict: Runtime Error):
s = input()
print('A{}C'.format(s[8])
Problem p03328 (python)

Fixed submission:
a, b = map(int, input().split())
tower = [i*(2+(i-1))/2 for i in range(1, 1000)]

for i in range(999):
    if a - tower[i] == b - tower[i+1]:
        print(int(abs(tower[i]-a)))
        break

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
tower = [n*(2+(i-1))/2 for i in range(1, 1000)]

for i in range(999):
  if b - a == tower[i+1] - tower[i]:
    print(a-tower[i])
    break
Problem p03436 (python)

Fixed submission:
h, w = map(int, input().split())
cell = []
for _ in range(h):
    cell.append(input())

dist = [[float('inf') for _ in range(w)] for _ in range(h)]
dist[0][0] = 0
next_move = [[0, 0]]
x = [1, 0, -1, 0]
y = [0, 1, 0, -1]

while len(next_move):
    if next_move[0] == [h-1, w-1]:
        break
    
    for i in range(4):
        nx = next_move[0][1] + x[i]
        ny = next_move[0][0] + y[i]
        if (nx >= 0 and nx < w and ny >= 0 and ny < h and 
            cell[ny][nx] != '#' and dist[ny][nx] == float('inf')):
            dist[ny][nx] = dist[next_move[0][0]][next_move[0][1]] + 1
            next_move.append([ny, nx])
    next_move.pop(0)

cnt = 0
for i in range(h):
    for t in range(w):
        
        if cell[i][t] == '#':
            cnt += 1
            
if dist[h-1][w-1] == float('inf'):
    print(-1)
else:
    print((h*w) - (dist[h-1][w-1] + 1) - cnt)

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
cell = []
for _ in range(h):
    temp = input()
    cell.append(temp[:-1])

dist = [[float('inf') for _ in range(w)] for _ in range(h)]
dist[0][0] = 0
next_move = [[0, 0]]
x = [1, 0, -1, 0]
y = [0, 1, 0, -1]

while len(next_move):
    if next_move[0] == [h-1, w-1]:
        break
    
    for i in range(4):
        nx = next_move[0][1] + x[i]
        ny = next_move[0][0] + y[i]
        if (nx >= 0 and nx < w and ny >= 0 and ny < h and 
            cell[ny][nx] != '#' and dist[ny][nx] == float('inf')):
            dist[ny][nx] = dist[next_move[0][0]][next_move[0][1]] + 1
            next_move.append([ny, nx])
    next_move.pop(0)

cnt = 0
for i in range(h):
    for t in range(w):
        
        if cell[i][t] == '#':
            cnt += 1
            
if dist[h-1][w-1] == float('inf'):
    print(-1)
else:
    print((h*w) - (dist[h-1][w-1] + 1) - cnt)