Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
a = list()
for elem in input().split(' '):
    a.append(int(elem)) 

step = a[1] - a[0]
next =  a[1] + step

while True:
    if next >= a[2]:
        print(next)
        break
    else:
        next +=  step

Fixed submission:
N = int(input())
a = list()
for elem in input().split(' '):
    a.append(int(elem))

sum = 0;
for number in a:
    sum+=1/number

print(1/sum)
Buggy python submission (verdict: Runtime Error):
s = ''
count = 0
while S:
    if s == S[-1]:
        if len(S) >= 2:
            S.pop()
            S.pop()
            s = ''
            count+=1
        else:
            break        
    else:
        s = S.pop()
        count+=1
        
print(count)

Fixed submission:
S = list(input())

s = ''
count = 0
while S:
    if s == S[-1]:
        if len(S) >= 2:
            S.pop()
            S.pop()
            s = ''
            count+=1
        else:
            break        
    else:
        s = S.pop()
        count+=1
        
print(count)

Buggy python submission (verdict: Runtime Error):
S = list(input())

s = ''
count = 0
while S:
    if s == S[-1]:
        if len(S) >= 2:
            S.pop()
            S.pop()
            s = S.pop()
            count+=2
        else:
            break        
    else:
        s = S.pop()
        count+=1
        
print(count)

Fixed submission:
S = list(input())

s = ''
count = 0
while S:
    if s == S[-1]:
        if len(S) >= 2:
            S.pop()
            S.pop()
            s = ''
            count+=1
        else:
            break        
    else:
        s = S.pop()
        count+=1
        
print(count)
Buggy python submission (verdict: Runtime Error):
X = int(input())
A = int(input())

if X<A:
	print(0)
else:
	print(10)


Fixed submission:
X,A = map(int,input().split())

if X<A:
	print(0)
else:
	print(10)

Buggy python submission (verdict: Runtime Error):
X = int(input())
A = int(input())

if X<A:
	print(0)
else:
	print(10)


Fixed submission:
X,A = map(int,input().split())

if X<A:
	print(0)
else:
	print(10)

Buggy python submission (verdict: Runtime Error):
X = int(input())
A = int(input())

if X<A:
  print(0)
else:
  print(10)


Fixed submission:
X,A = map(int,input().split())

if X<A:
	print(0)
else:
	print(10)
Buggy python submission (verdict: Runtime Error):
import numpy as np

N,K = map(int,input().split(' '))
a = np.array(list(map(int,input().split(' '))))

cost = np.full(N,10**9)
cost[0] = 0
for i in range(1 , N):
    
    size =  min(i,K)
    cost[i] = (np.abs(a[i] - a[i-size:i]) + cost[i-size:i])

print(int(cost[-1]))

Fixed submission:
import numpy as np

N,K = map(int,input().split(' '))
a = np.array(list(map(int,input().split(' '))))

cost = np.full(N,10**9)
cost[0] = 0
for i in range(1 , N):
    
    size =  min(i,K)
    cost[i] = (np.abs(a[i] - a[i-size:i]) + cost[i-size:i]).min()

print(int(cost[-1]))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N,K = map(int,input().split(' '))
a = np.array(list(map(int,input().split(' '))))

cost = np.full(N,10**9)
cost[0] = 0
for i in range(1 , N):
    
    size =  min(i,K)
    cost[i] = (abs(a[i] - a[i-size:i]) + cost[i-size:i]).min()

print(int(cost[-1]))

Fixed submission:
import numpy as np

N,K = map(int,input().split(' '))
a = np.array(list(map(int,input().split(' '))))

cost = np.full(N,10**9)
cost[0] = 0
for i in range(1 , N):
    
    size =  min(i,K)
    cost[i] = (np.abs(a[i] - a[i-size:i]) + cost[i-size:i]).min()

print(int(cost[-1]))

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split(' '))
a = list(map(int,input().split(' ')))

cost = list()
cost.append(0)
for i in range(1,N):
    step_min = 10**9
    for j in range(1,min(i+1,K+1)):
        step_cost = abs(a[i] - a[i-j]) + cost[i-j]
        step_min = step_cost if step_cost < step_min else step_min
    cost.append(step_min)

print(cost[-1])

Fixed submission:
import numpy as np

N,K = map(int,input().split(' '))
a = np.array(list(map(int,input().split(' '))))

cost = np.full(N,10**9)
cost[0] = 0
for i in range(1 , N):
    
    size =  min(i,K)
    cost[i] = (np.abs(a[i] - a[i-size:i]) + cost[i-size:i]).min()

print(int(cost[-1]))

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split(' '))
a = list(map(int,input().split(' ')))

cost = list()
for i in range(N):
    if i == 0:
        cost.append(0)
        continue
    step_min = 10**9
    for j in range(1,min(i+1,K+1)):
        step_cost = abs(a[i] - a[i-j]) + cost[i-j]
        step_min = step_cost if step_cost < step_min else step_min
    cost.append(step_min)

print(cost[-1])

Fixed submission:
import numpy as np

N,K = map(int,input().split(' '))
a = np.array(list(map(int,input().split(' '))))

cost = np.full(N,10**9)
cost[0] = 0
for i in range(1 , N):
    
    size =  min(i,K)
    cost[i] = (np.abs(a[i] - a[i-size:i]) + cost[i-size:i]).min()

print(int(cost[-1]))
Buggy python submission (verdict: Runtime Error):
s = input()
K = int(input())

s_sub = list()
s_len = len(s)
for i in range(s_len):
    s_sub.append(s[i:])
    
s_sub.sort()
s_sub.append('')

pre_sum = 0
sum = len(s_sub[0])
for j in range(1,s_len+1):
    
    current = s_sub[j]
    before = s_sub[j-1]

    if sum >= K:
        print(before[:K-pre_sum+z])
        break

    z = 0
    for k in range(min(len(current),len(before))):
        if current[k] == before[k]:
            z+=1
        else:
            break  
    pre_sum =  sum 
    sum += len(current) - z

Fixed submission:
s = input()
K = int(input())

s_sub = list()
s_len = len(s)
for i in range(s_len):
    s_sub.append(s[i:])
    
s_sub.sort()
s_sub.append('')

pre_sum = 0
sum = len(s_sub[0])
z=0
for j in range(1,s_len+1):
    
    current = s_sub[j]
    before = s_sub[j-1]

    
    if sum >= K:
        print(before[:K-pre_sum+z])
        break

    z = 0
    for k in range(min(len(current),len(before))):
        if current[k] == before[k]:
            z+=1
        else:
            break  
    pre_sum =  sum 
    sum += len(current) - z
Buggy python submission (verdict: Runtime Error):
N = int(input())
As = map(int,input().split())
Bs = map(int,input().split())
Cs = map(int,input().split())

score = 0
for i in range(N):
  score += Bs[As[i]]
  if i >= 1 and As[i]==As[i-1]+1:
    score += Cs[As[i]]
print(score)

Fixed submission:
N = int(input())
As = list(map(int,input().split()))
Bs = list(map(int,input().split()))
Cs = [0] + list(map(int,input().split()))

score = 0
for i in range(N):
  score += Bs[As[i]-1]
  if i >= 1 and As[i]-1==As[i-1]:
    score += Cs[As[i]-1]
print(score)
Buggy python submission (verdict: Runtime Error):
    A, B = map(int, input().split())
    capacity = 1
    ans = 0
     
    while True:
      if capacity>=B:
        print(ans)
        break
      capacity += A-1
      ans +=1

Fixed submission:
A, B = map(int, input().split())
capacity = 1
ans = 0

while True:
  if capacity>=B:
    print(ans)
    break
  capacity += A-1
  ans +=1

Buggy python submission (verdict: Time Limit Exceeded):
A, B = map(int, input().split())
capacity = 1
ans = 0

while True:
  if capacity>=B:
    print(ans)
    break
    capacity += A-1
    ans +=1

Fixed submission:
A, B = map(int, input().split())
capacity = 1
ans = 0

while True:
  if capacity>=B:
    print(ans)
    break
  capacity += A-1
  ans +=1
Buggy python submission (verdict: Runtime Error):
N = int(input())
hs = map(int, input().split())
costs = [0] * N
costs[0] = 0
costs[1] = abs(hs[1]-hs[0])
for i in range(2, N):
    costs[i] = min(costs[i-1]+abs(hs[i]-hs[i-1]),
                   costs[i-2]+abs(hs[i]-hs[i-2]))
print(costs[N-1])

Fixed submission:
N = int(input())
hs = list(map(int, input().split()))
costs = [0] * N
costs[0] = 0
costs[1] = abs(hs[1]-hs[0])
for i in range(2, N):
  costs[i] = min(costs[i-1]+abs(hs[i]-hs[i-1]),
                 costs[i-2]+abs(hs[i]-hs[i-2]))
print(costs[N-1])
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
hs = list(map(int, input().split()))



INF = 999999999999999999

costs = [INF] * N
costs[0] = 0

def get_cost(i):
    if costs[i]<INF:
        return costs[i]
    if i == 0:
        return 0
    start_index = max(0, i-K)
    costs[i] = min([get_cost(j)+abs(hs[i]-hs[j]) for j in range(start_index, i)])
    return costs[i]

print(get_cost(N-1))

Fixed submission:
N, K = map(int, input().split())
hs = list(map(int, input().split()))

costs = [999999999999999999] * N
costs[0] = 0
for i in range(N-1):
    for j in range(i, min(N, i+K+1)):
        costs[j] = min(costs[j],
                       costs[i]+abs(hs[j]-hs[i]))
print(costs[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
hs = list(map(int, input().split()))

costs = [999999999999999999] * N
costs[0] = 0
for i in range(N-1):
    for j in range(i, min(N, i+K+1)):
        costs[j] = min(costs[j],
                       costs[i]+abs(hs[j]-hs[i]))
print(costs[-1])

Fixed submission:
N, K = map(int, input().split())
hs = list(map(int, input().split()))

costs = [999999999999999999] * N
costs[0] = 0
for i in range(N-1):
    for j in range(i, min(N, i+K+1)):
        costs[j] = min(costs[j],
                       costs[i]+abs(hs[j]-hs[i]))
print(costs[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())

weights = [0]*(N+10)
values = [0]*(N+10)

dp = [[0]*(W+10) for i in range(N+10)]

for i in range(N):
    weights[i], values[i] = map(int, input().split())
    for sum_w in range(W+1):
        if sum_w >= weights[i]:
            dp[i+1][sum_w] = max(dp[i][sum_w-weights[i]]+values[i],
                                 dp[i+1][sum_w])
        else:
            dp[i+1][sum_w] = max(dp[i][sum_w],
                                 dp[i+1][sum_w])

print(max([max(row) for row in dp]))

Fixed submission:
N, W = map(int, input().split())

weights = [0]*(N+5)
values = [0]*(N+5)

dp = [[0]*(W+5) for i in range(N+5)]

for i in range(N):
    weights[i], values[i] = map(int, input().split())
    for sum_w in range(W+1):
        if sum_w >= weights[i]:
            if dp[i+1][sum_w] < dp[i][sum_w-weights[i]]+values[i]:
                dp[i+1][sum_w] = dp[i][sum_w-weights[i]]+values[i]
        if dp[i+1][sum_w] < dp[i][sum_w]:
            dp[i+1][sum_w] = dp[i][sum_w]


print(max([max(row) for row in dp]))
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
# from math import gcd

N, X = [int(x) for x in input().split()]
P = [int(x) for x in input().split()]

def main():
    ds = list(map(lambda n: abs(X - n), P))
    # ans = reduce(lambda a, b: gcd(a, b), ds)
    d = min(ds)
    while d > 0:
        if all(map(lambda distance: distance % d == 0, ds)) == True:
            break
        d = d - 1
    ans = d
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
from functools import reduce
from fractions import gcd

N, X = [int(x) for x in input().split()]
P = [int(x) for x in input().split()]

def main():
    ds = list(map(lambda n: abs(X - n), P))
    ans = reduce(lambda a, b: gcd(a, b), ds)
    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
from functools import reduce
from math import gcd

N, X = [int(x) for x in input().split()]
P = [int(x) for x in input().split()]

def main():
    ds = list(map(lambda n: abs(X - n), P))
    # ans = reduce(lambda a, b: gcd(a, b), ds)
    d = min(ds)
    while d > 0:
        if all(map(lambda distance: distance % d == 0, ds)) == True:
            break
        d = d - 1
    ans = d
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
from functools import reduce
from fractions import gcd

N, X = [int(x) for x in input().split()]
P = [int(x) for x in input().split()]

def main():
    ds = list(map(lambda n: abs(X - n), P))
    ans = reduce(lambda a, b: gcd(a, b), ds)
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
N = int(input())

def main():
    l = [x + y for x in range(N + 1) if x % 4 == 0
               for y in range(N + 1) if y % 7 == 0]
    l = list(set(l))
    ans = "Yes" if l.count(N) else "No"
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
N, K = [int(x) for x in input().split()]
ans = 0 if N % K == 0 else 1
print(ans)
Buggy python submission (verdict: Runtime Error):
from itertools import groupby

N = int(input())
S = [input() for _ in range(N)]
M = int(input())
T = [input() for _ in range(M)]

def main():
    for t in T:
        if t in S:
            S.remove(t)
    ans = [len(list(group)) for key, group in groupby(S)]
    print(max([0] + ans))

if __name__ == "__main__":
    main()

Fixed submission:
A, B, C = [int(x) for x in input().split()]
ans = 'Yes' if A + B >= C else 'No'
print(ans)
Buggy python submission (verdict: Runtime Error):
GRID = []
for _ in range(3):
    GRID.append([int(c) for c in input().split()])

def diff(row):
    min_num = min(row)
    return list(map(lambda c: c - min_num, row))

def main():
    ans = None
    prev = None
    while GRID:
        row = GRID.pop()
        curr = diff(row)
        if prev is None:
            prev = curr[:] # deep copy
        if curr != prev:
            ans = "No"
            break
    if ans is None:
        ans = "Yes"
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
N = int(input())
A = int(input())

def main():
    remnant = N % 500
    ans = "Yes" if A >= remnant else "No"
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
N = int(input())
HIGH = [int(x) for x in input().split()]
LOW = [int(x) for x in input().split()]

def get_sum(diff_list):
    max_abs_value = max(diff_list, key=abs)
    max_abs_index = diff_list.index(max_abs_value)
    
    down_index = max_abs_index if max_abs_value >= 0 else max_abs_index - 1
    corrects = [HIGH[i] if i <= down_index else LOW[i] for i, _ in enumerate(diff_list)]
    return sum(corrects)

def main():
    first = HIGH.pop(0)
    last = LOW.pop()
    diff_list = []
    high = low = 0
    for i in range(N - 1):
        high = high + HIGH[i]
        low = low + LOW[i]
        diff_list.append(high - low)

    sum = get_sum(diff_list) if len(diff_list) != 0 else 0
    result = first + sum + last
    print(result)

if __name__ == "__main__":
    main()

Fixed submission:
X = int(input())
A = int(input())
B = int(input())

def main():
    m = X - A
    while m - B >= 0:
        m = m - B
    print(m)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
A, B, C, D = [int(x) for x in input().split()]

def main();
    ans = A + B - C - D
    if ans > 0:
        print('Left')
    elif ans < 0:
        print('Right')
    else:
        print('Balanced')

if __name == '__main__':
    main()

Fixed submission:
A, B, C, D = [int(x) for x in input().split()]

def main():
    ans = A + B - C - D
    if ans > 0:
        print('Left')
    elif ans < 0:
        print('Right')
    else:
        print('Balanced')

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(x) for x in input().split()]

def count(num, counter_list):
    isFound = False
    for item in counter_list:
        if item[0] == num:
            item[1] += 1
            isFound = True
            break
    if not isFound:
        counter_list.append([num, 1])

def calc(list):
    result = 0
    for item in list:
        cmp_count = item[1] - item[0]
        result += cmp_count if cmp_count >= 0 else item[1]
    return result

def main():
    counter_list = []
    for i in range(N):
        count(A[i], counter_list)
    ans = calc(counter_list)
    print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]

def count(num, counter_list):
    if len(counter_list) == 0:
        counter_list.append([num, 0])
    current = counter_list[-1]     
    if current[0] == num:
        current[1] += 1
    else:
        counter_list.append([num, 1])

def calc(list):
    result = 0
    for item in list:
        cmp_count = item[1] - item[0]
        result += cmp_count if cmp_count >= 0 else item[1]
    return result

def main():
    A.sort()
    counter_list = []
    for i in range(N):
        count(A[i], counter_list)
    ans = calc(counter_list)
    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
""" small multiple """

K = int(input())

def get_sum_each_digits(number):
    """
    get sum.
    """
    chars = list(str(number))
    int_map = map(int, chars)
    result = sum(int_map)
    # print("number:{0}, result:{1}".format(number, result))
    return result

def main():
    """
    main function.
    """

    min = K
    multiple = 0
    while multiple < 100000:
        multiple += 1
        temp = get_sum_each_digits(K * multiple)
        if temp < min:
            min = temp
        if min == 1:
            break

    # print("ans ---")
    print(min)

main()

Fixed submission:
c11, c12, c13 = list(input())
c21, c22, c23 = list(input())
result = c11 == c23 and \
    c12 == c22 and \
    c13 == c21

ans = "YES" if result else "NO"
print(ans)

Buggy python submission (verdict: Runtime Error):
"""
snuke festival
"""

def input_list():
    """
    returns list from stdin
    """
    input_map = map(int, input().split())
    return list(input_map)

def get_bigger_index(base_num, sub_list):
    """
    returns first index that is bigger than base number
    """
    bigger_index = -1
    for index, item in enumerate(sub_list):
        if base_num < item:
            bigger_index = index
            break
    return bigger_index

def main():
    """
    main function.
    """
    base_len = int(input())
    top = input_list()
    mid = input_list()
    btm = input_list()

    top.sort()
    mid.sort()
    btm.sort()

    result = 0

    for i in range(base_len):
        mid_index = get_bigger_index(top[i], mid)
        if mid_index < 0:
            break
        else:
            btm_index = get_bigger_index(mid[mid_index], btm)
            if btm_index >= 0:
                result += (base_len - mid_index) * (base_len + btm_index)

    print(result)

main()


Fixed submission:
c11, c12, c13 = list(input())
c21, c22, c23 = list(input())
result = c11 == c23 and \
    c12 == c22 and \
    c13 == c21

ans = "YES" if result else "NO"
print(ans)

Buggy python submission (verdict: Runtime Error):
c11, c12, c13 = list(raw_input())
c21, c22, c23 = list(raw_input())
result = c11 == c23 and \
    c12 == c22 and \
    c13 == c21

ans = "YES" if result else "NO"
print ans

Fixed submission:
c11, c12, c13 = list(input())
c21, c22, c23 = list(input())
result = c11 == c23 and \
    c12 == c22 and \
    c13 == c21

ans = "YES" if result else "NO"
print(ans)
Buggy python submission (verdict: Runtime Error):
N = input()

i = 1
sq = i * i
while sq <= N:
    i += 1
    temp = i * i
    if temp > N 
        break
    sq = temp

print(sq)

Fixed submission:
N = int(input())

i = 1
sq = i * i
while sq <= N:
    i += 1
    temp = i * i
    if temp > N:
        break
    sq = temp

print(sq)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(s) for s in input().split()]

def main():
    ans = float('inf')
    for i in range(N - 1):
        A[i] *= -1
        ans = min(ans, abs(sum(A)))
    print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
N = int(input())
A = [int(s) for s in input().split()]

def main():
    sum_n = sum(A)
    mid = sum_n / 2
    a = 0
    abs_list = []
    for i in range(N - 1):
        a += A[i]
        abs_list.append((abs(mid - a), i))    
    abs_list.sort()
    idx = abs_list[0][1]

    left = sum(A[:idx + 1])
    right = sum(A[idx + 1:])
    print(abs(left - right))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(s) for s in input().split()]

def main():
    ans = float('inf')
    for i in range(1, N):
        ans = min(ans, abs(sum(A[:i]) - sum(A[i:])))
    print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
N = int(input())
A = [int(s) for s in input().split()]

def main():
    sum_n = sum(A)
    mid = sum_n / 2
    a = 0
    abs_list = []
    for i in range(N - 1):
        a += A[i]
        abs_list.append((abs(mid - a), i))    
    abs_list.sort()
    idx = abs_list[0][1]

    left = sum(A[:idx + 1])
    right = sum(A[idx + 1:])
    print(abs(left - right))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

def main():
    a = [int(input()) for _ in range(N)]
    visited = []
    idx = 0
    ans = 0
    while True:
        n = a[idx] - 1
        ans += 1
        if n == 1:
            break
        if visited.count(n):
            ans = -1
            break
        visited.append(n)
        idx = n 
    print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
N = int(input())

def main():
    a = [[int(input()), False] for _ in range(N)]
    idx = 0
    ans = 0
    while True:
        idx = a[idx][0] - 1
        ans += 1
        if idx == 1:
            break
        if a[idx][1]:
            ans = -1
            break
        a[idx][1] = True
    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
N, M = [int(s) for s in input().split()]

def main():
    n = N
    m = M
    d = 1_000_000_007
    if abs(n - m) > 1:
        print(0)
        return
    n, m = (m, n) if n > m else (n, m)
    ans = 1
    for i in range(1, n + 1):
        ans *= i ** 2
        ans = ans % d
    last_n = 2 if n == m else m
    ans = ans * last_n % d
    print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
N, M = [int(s) for s in input().split()]

def main():
    n = N
    m = M
    d = 1000000007
    if abs(n - m) > 1:
        print(0)
        return
    n, m = (m, n) if n > m else (n, m)
    ans = 1
    for i in range(1, n + 1):
        ans *= i ** 2
        ans = ans % d
    last_n = 2 if n == m else m
    ans = ans * last_n % d
    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N, T = [int(n) for n in input().split()]
A = [int(n) for n in input().split()]

def main():
    ans = 0
    a = A
    while a:
        curr = a.pop(0)
        next = a[0] if a else float('inf')
        ans += min(T, next - curr)
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
from collections import deque

N, T = [int(n) for n in input().split()]
Q = deque([int(n) for n in input().split()])

def main():
    ans = 0
    while Q:
        curr = Q.popleft()
        next = Q[0] if Q else float('inf')
        ans += min(T, next - curr)
    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N, T = [int(s) for s in input().split()]
PS = [int(s) for s in input().split()]

def main():
    t = T
    ps = PS
    ans = 0
    while ps:
        p = ps.pop(0)
        ans += min(ps[0] - p, t) if ps else t
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
from collections import deque

N, T = [int(n) for n in input().split()]
Q = deque([int(n) for n in input().split()])

def main():
    ans = 0
    while Q:
        curr = Q.popleft()
        next = Q[0] if Q else float('inf')
        ans += min(T, next - curr)
    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
X = int(input())

def jump(s, t):
    ns = set()
    for n in s:
        ns.add(n - t)
        ns.add(n)
        ns.add(n + t)
    return ns

def main():
    t = 0
    curr = set([0])
    while X not in curr:
        t += 1
        curr = jump(curr, t)
    print(t)

if __name__ == '__main__':
    main()

Fixed submission:
X = int(input())

def main():
    t = 0
    curr = 0
    while curr < X:
        t += 1
        curr += t
    print(t)

if __name__ == '__main__':
    main()