Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math

a,b,c,d = map(int,input().split())

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

gcd_cd = lcm(c,d)

a_c_numbers = a//c
if a % c == 0:
    a_c_numbers -= 1
a_d_numbers = a//d
if a % d == 0:
    a_d_numbers -= 1

a_numbers = a_c_numbers + a_d_numbers

b_c_numbers = b//c
b_d_numbers = b//d
b_numbers = b_c_numbers + b_d_numbers

gcd_cd_numbers = b//gcd_cd - a//gcd_cd

# print(a_c_numbers,a_d_numbers)
# print(b_c_numbers,b_d_numbers)
# print(gcd_cd_numbers)
# print(b_numbers - a_numbers - gcd_cd_numbers)
ans = b - a + 1 - (b_numbers - a_numbers - gcd_cd_numbers)

if ans > 0:
    print(ans)
else:
    print(0)

Fixed submission:
import fractions

a,b,c,d = map(int,input().split())

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

gcd_cd = lcm(c,d)

a_c_numbers = a//c
if a % c == 0:
    a_c_numbers -= 1
a_d_numbers = a//d
if a % d == 0:
    a_d_numbers -= 1

a_numbers = a_c_numbers + a_d_numbers

b_c_numbers = b//c
b_d_numbers = b//d
b_numbers = b_c_numbers + b_d_numbers

if a % gcd_cd == 0:
    gcd_cd_numbers = b//gcd_cd - a//gcd_cd + 1
else:
    gcd_cd_numbers = b//gcd_cd - a//gcd_cd

# print(a_c_numbers,a_d_numbers)
# print(b_c_numbers,b_d_numbers)
# print(gcd_cd_numbers)
# print(b_numbers - a_numbers - gcd_cd_numbers)
ans = b - a + 1 - (b_numbers - a_numbers - gcd_cd_numbers)

if ans > 0:
    print(ans)
else:
    print(0)

Buggy python submission (verdict: Runtime Error):
import math

a,b,c,d = map(int,input().split())

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

gcd_cd = lcm(c,d)

a_c_numbers = a//c
if a % c == 0:
    a_c_numbers -= 1
a_d_numbers = a//d
if a % d == 0:
    a_d_numbers -= 1

a_numbers = a_c_numbers + a_d_numbers

b_c_numbers = b//c
b_d_numbers = b//d
b_numbers = b_c_numbers + b_d_numbers

gcd_cd_numbers = b//gcd_cd - a//gcd_cd

# print(a_c_numbers,a_d_numbers)
# print(b_c_numbers,b_d_numbers)
# print(gcd_cd_numbers)
# print(b_numbers - a_numbers - gcd_cd_numbers)
print(b - a + 1 - (b_numbers - a_numbers - gcd_cd_numbers))

Fixed submission:
import fractions

a,b,c,d = map(int,input().split())

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

gcd_cd = lcm(c,d)

a_c_numbers = a//c
if a % c == 0:
    a_c_numbers -= 1
a_d_numbers = a//d
if a % d == 0:
    a_d_numbers -= 1

a_numbers = a_c_numbers + a_d_numbers

b_c_numbers = b//c
b_d_numbers = b//d
b_numbers = b_c_numbers + b_d_numbers

if a % gcd_cd == 0:
    gcd_cd_numbers = b//gcd_cd - a//gcd_cd + 1
else:
    gcd_cd_numbers = b//gcd_cd - a//gcd_cd

# print(a_c_numbers,a_d_numbers)
# print(b_c_numbers,b_d_numbers)
# print(gcd_cd_numbers)
# print(b_numbers - a_numbers - gcd_cd_numbers)
ans = b - a + 1 - (b_numbers - a_numbers - gcd_cd_numbers)

if ans > 0:
    print(ans)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
W,H,x,y = map(int,input().split())

if W/x == 2 and H/y == 2:
    print(W*H/2, 1)
else:
    print(W*H/2, 0)

Fixed submission:
W,H,x,y = map(int,input().split())

if x * 2 == W and y * 2 == H:
    print(W*H/2, 1)
else:
    print(W*H/2, 0)

Buggy python submission (verdict: Runtime Error):
W,H,x,y = map(int,input().split())

if W/x == 2 and Y/2 == 2:
    print(W*H/2, 1)
else:
    print(W*H/2, 0)

Fixed submission:
W,H,x,y = map(int,input().split())

if x * 2 == W and y * 2 == H:
    print(W*H/2, 1)
else:
    print(W*H/2, 0)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
A = list(map(int,input().split()))

A.sort()

#変えられるカードを格納
change_card = []
for _ in range(M):
    B,C = map(int,input().split())
    for _ in range(B):
        change_card.append(C)

change_card.sort()

for i in range(N):
    if max(change_card) > A[i]:
        A[i] = max(change_card)
        change_card[change_card.index(max(change_card))] = -1

print(sum(A))

Fixed submission:
N,M = map(int,input().split())
A = list(map(int,input().split()))

A.sort()

BC = [list(map(int,input().split())) for _ in range(M)]
#変えられるカードを格納
BC_sort = sorted(BC,key=lambda x: x[1])

BC_sort_index = M-1

for i in range(N):
    if BC_sort[BC_sort_index][1] > A[i]:
        A[i] = BC_sort[BC_sort_index][1]
        BC_sort[BC_sort_index][0] -= 1
        if BC_sort[BC_sort_index][0] == 0:
            BC_sort_index -= 1
            if BC_sort_index < 0:
                break

print(sum(A))
Buggy python submission (verdict: Runtime Error):
import math

N = int(input())
A = list(map(int,input().split()))

# ユークリッドの互除法
# 全体の最小公約数 = 最小値
min_life = math.gcd(A[0],A[1])

for i in range(1,N):
    min_life = math.gcd(min_life,A[i])

print(min_life)

Fixed submission:
import fractions

N = int(input())
A = list(map(int,input().split()))

# ユークリッドの互除法
# 全体の最小公約数 = 最小値
min_life = fractions.gcd(A[0],A[1])

for i in range(1,N):
    min_life = fractions.gcd(min_life,A[i])

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

ans_str = "keyence"

if S[0:7] == ans_str:
    print("YES")
    exit()

if S[len(S)-7:len(S)] == ans_str:
    print("YES")
    exit()

count_check_str = 0
count_insert = 0
count_ans_str = 0
for i in range(len(S)):
    if S[i] == ans_str[count_ans_str]:
        count_check_str += 1
        count_ans_str += 1
        if count_insert == 1:
            count_insert = 2
    else:
        if count_insert == 2:
            print("NO")
            exit()
        count_insert = 1

if count_check_str < 6:
    print("NO")
    exit()
print("YES")

Fixed submission:
S = input()

for i in range(8):
    if S[0:i] + S[i+(len(S)-7):len(S)] == "keyence":
        print("YES")
        exit()
print("NO")
Buggy python submission (verdict: Runtime Error):
n = int(input())
v = list(map(int,input().split()))
dic_odd = {}
dic_even = {}

#奇数桁の中で一番多く存在する数字の数
for i in range(0,n,2):
    if v[i] in dic_odd:
        dic_odd[v[i]] += 1
    else:
        dic_odd[v[i]] = 1

#偶数桁の中で一番多く存在する数字の数
for i in range(1,n,2):
    if v[i] in dic_even:
        dic_even[v[i]] += 1
    else:
        dic_even[v[i]] = 1

odd_sorted = sorted(dic_odd.items(), key=lambda x:x[1])
even_sorted = sorted(dic_even.items(), key=lambda x:x[1])

if odd_sorted[len(odd_sorted)-1][0] == even_sorted[len(even_sorted)-1][0]:
    if len(odd_sorted) == 1 and len(even_sorted) == 1:
        print(n//2)
    elif len(odd_sorted) == 1:
        print(n//2-even_sorted[len(even_sorted)-2][1])
    elif len(even_sorted) == 1:
        print(n//2-odd_sorted[len(odd_sorted)-2][1])
    else:
        if odd_sorted[len(odd_sorted)-1][1] < even_sorted[len(even_sorted)-1][1]:
            print(n - (odd_sorted[len(odd_sorted)-1][2] + even_sorted[len(even_sorted)-1][1]))
        else:
            print(n - (odd_sorted[len(odd_sorted)-1][1] + even_sorted[len(even_sorted)-1][2]))
else:
    print(n-(odd_sorted[len(odd_sorted)-1][1]+even_sorted[len(even_sorted)-1][1]))

Fixed submission:
n = int(input())
v = list(map(int,input().split()))
dic_odd = {}
dic_even = {}

for i in range(0,n,2):
    if v[i] in dic_odd:
        dic_odd[v[i]] += 1
    else:
        dic_odd[v[i]] = 1

for i in range(1,n,2):
    if v[i] in dic_even:
        dic_even[v[i]] += 1
    else:
        dic_even[v[i]] = 1

odd_sorted = sorted(dic_odd.items(), key=lambda x:x[1])
even_sorted = sorted(dic_even.items(), key=lambda x:x[1])

if odd_sorted[len(odd_sorted)-1][0] == even_sorted[len(even_sorted)-1][0]:
    if len(odd_sorted) == 1 and len(even_sorted) == 1:
        print(n//2)
    elif len(odd_sorted) == 1:
        print(n//2-even_sorted[len(even_sorted)-2][1])
    elif len(even_sorted) == 1:
        print(n//2-odd_sorted[len(odd_sorted)-2][1])
    else:
        if odd_sorted[len(odd_sorted)-1][1] < even_sorted[len(even_sorted)-1][1]:
            print(n - (odd_sorted[len(odd_sorted)-2][1] + even_sorted[len(even_sorted)-1][1]))
        elif  odd_sorted[len(odd_sorted)-1][1] > even_sorted[len(even_sorted)-1][1]:
            print(n - (odd_sorted[len(odd_sorted)-1][1] + even_sorted[len(even_sorted)-2][1]))
        else:
            if odd_sorted[len(odd_sorted)-2][1] < even_sorted[len(even_sorted)-2][1]:
                print(n - (odd_sorted[len(odd_sorted)-1][1] + even_sorted[len(even_sorted)-2][1]))
            else:
                print(n - (odd_sorted[len(odd_sorted)-2][1] + even_sorted[len(even_sorted)-1][1]))
else:
    print(n-(odd_sorted[len(odd_sorted)-1][1]+even_sorted[len(even_sorted)-1][1]))
Buggy python submission (verdict: Runtime Error):
n = int(input())
v = list(map(int,input().split()))

v1 = [0] * (10**5)
v2 = [0] * (10**5)

for i in range(0,n,2):
	v1[v[i]] += 1

for i in range(1,n,2):
	v2[v[i]] += 1

ans = n - ( max(v1) + max(v2) )
if ans == 0:
	if v[0] == v[1]:
		print(n//2)
		exit()

print(ans)

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

v1 = [0] * (10**5)
v2 = [0] * (10**5)
v1_max_1 = 0
v1_max_2 = 0
v2_max_1 = 0
v2_max_2 = 0

for i in range(0,n,2):
	v1[v[i]-1] += 1

for i in range(1,n,2):
	v2[v[i]-1] += 1

v1_max_index = v1.index(max(v1))
v2_max_index = v2.index(max(v2))

v1.sort(reverse=True)
v2.sort(reverse=True)
v1_max_1 = v1[0]
v2_max_1 = v2[0]
v1_max_2 = v1[1]
v2_max_2 = v2[1]

ans = n - ( v1_max_1 + v2_max_1 )

if ans == 0:
	if v[0] == v[1]:
		print(n//2)
		exit()

if v1_max_index == v2_max_index:
	print(min( n - ( v1_max_2 + v2_max_1 ),n  - ( v1_max_1 + v2_max_2 ) ))
else:
	print(ans)
Buggy python submission (verdict: Runtime Error):
H, W = map(int,input().split())
S = []
for _ in range(H):
    S.append(input())

ans = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            ans[i][j] = "#"
            if j-1 >= 0 and ans[i][j-1] != "#":
                ans[i][j-1] += 1
            if j-1 >= 0 and i-1 >= 0 and ans[i-1][j-1] != "#":
                ans[i-1][j-1] += 1
            if j-1 >= 0 and i+1 <= H-1 and ans[i+1][j-1] != "#":
                ans[i+1][j-1] += 1

            if i-1 >= 0 and ans[i-1][j] != "#":
                ans[i-1][j] += 1
            if i+1 <= H-1 and ans[i+1][j] != "#":
                ans[i+1][j] += 1
            
            if j+1 <= W-1 and ans[i][j+1] != "#":
                ans[i][j+1] += 1
            if j+1 <= W-1 and i-1 >= 0 and ans[i-1][j+1] != "#":
                ans[i-1][j+1] += 1
            if j+1 <= W-1 and i+1 <= H-1 and ans[i+1][j+1] != "#":
                ans[i+1][j+1] += 1                        

for i in range(H):
    print(''.join(ans[i]))

Fixed submission:
H, W = map(int,input().split())
S = []
for _ in range(H):
    S.append(input())

ans = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            ans[i][j] = "#"
            if j-1 >= 0 and ans[i][j-1] != "#":
                ans[i][j-1] += 1
            if j-1 >= 0 and i-1 >= 0 and ans[i-1][j-1] != "#":
                ans[i-1][j-1] += 1
            if j-1 >= 0 and i+1 <= H-1 and ans[i+1][j-1] != "#":
                ans[i+1][j-1] += 1

            if i-1 >= 0 and ans[i-1][j] != "#":
                ans[i-1][j] += 1
            if i+1 <= H-1 and ans[i+1][j] != "#":
                ans[i+1][j] += 1
            
            if j+1 <= W-1 and ans[i][j+1] != "#":
                ans[i][j+1] += 1
            if j+1 <= W-1 and i-1 >= 0 and ans[i-1][j+1] != "#":
                ans[i-1][j+1] += 1
            if j+1 <= W-1 and i+1 <= H-1 and ans[i+1][j+1] != "#":
                ans[i+1][j+1] += 1                        

for i in range(H):
    print(''.join(map(str,ans[i])))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))

ans = [0] * max(A)
count = 0
for i in range(N):
    if ans[A[i]-1] == 0:
        ans[A[i]-1] = 1
        count += 1
    else:
        ans[A[i]-1] = 0
        count -= 1

print(count)

Fixed submission:
N = int(input())

A = []
for _ in range(N):
    A.append(int(input()))

if N == 1:
    print(1)
    exit()

A.sort()

current_number = A[0]
current_count = 1
ans = 0

for i in range(1,N-1):
    if current_number == A[i]:
        current_count += 1
    else:
        current_number = A[i]
        if current_count % 2 != 0:
            ans += 1
        current_count = 1

if current_number == A[N-1]:
    current_count += 1
    if current_count % 2 != 0:
            ans += 1
else:
    if current_count % 2 != 0:
            ans += 1
    ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))

ans = [0] * (10**9)
for i in range(N):
    if ans[i] == 0:
        ans[i] = 1
    if ans[i] == 1:
        ans[i] = 0

print(sum(ans[i]))

Fixed submission:
N = int(input())

A = []
for _ in range(N):
    A.append(int(input()))

if N == 1:
    print(1)
    exit()

A.sort()

current_number = A[0]
current_count = 1
ans = 0

for i in range(1,N-1):
    if current_number == A[i]:
        current_count += 1
    else:
        current_number = A[i]
        if current_count % 2 != 0:
            ans += 1
        current_count = 1

if current_number == A[N-1]:
    current_count += 1
    if current_count % 2 != 0:
            ans += 1
else:
    if current_count % 2 != 0:
            ans += 1
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import math

N,P = map(int,input().split())
A = list(map(int,input().split()))
pascal_triangle = []

memo = [[0 for _ in range(50)] for _ in range(50)]

def c(n,k):
  if memo[n][k] != 0:
      return memo[n][k]
  if(k<=0 or n<=k):
      memo[n][k] = 1
      return 1
  else:
      ans = c(n-1, k-1) + c(n-1, k)
      memo[n][k] = ans
      return ans

for i in range(50):
  pascal_triangle.append([c(i,j) for j in range(i+1)])

Numbers_1 = 0
for i in range(N):
    Numbers_1 += A[i] % 2

Select_0_count = sum(pascal_triangle[N - Numbers_1])

ans = 0

for i in range(Numbers_1+1):
    if i % 2 == P:
        ans += pascal_triangle[Numbers_1][i] * Select_0_count

print(ans)

Fixed submission:
import math

N,P = map(int,input().split())
A = list(map(int,input().split()))
pascal_triangle = []

memo = [[0 for _ in range(51)] for _ in range(51)]

def c(n,k):
  if memo[n][k] != 0:
      return memo[n][k]
  if(k<=0 or n<=k):
      memo[n][k] = 1
      return 1
  else:
      ans = c(n-1, k-1) + c(n-1, k)
      memo[n][k] = ans
      return ans

for i in range(51):
  pascal_triangle.append([c(i,j) for j in range(i+1)])

Numbers_1 = 0
for i in range(N):
    Numbers_1 += A[i] % 2

Select_0_count = sum(pascal_triangle[N - Numbers_1])

ans = 0

for i in range(Numbers_1+1):
    if i % 2 == P:
        ans += pascal_triangle[Numbers_1][i] * Select_0_count

print(ans)
Buggy python submission (verdict: Runtime Error):
import math
a, b, x = map(int,input().split())
def fnc(n,x):
    if n == -1:
        return 0
    return n//x
print(fnc(b,x) - func((a-1),x))

Fixed submission:
import math
a, b, x = map(int,input().split())
print(b//x - (a-1)//x)

Buggy python submission (verdict: Runtime Error):
import math
a, b, x = map(int,input().split())
if a % x != 0:
    print(b//x - a//x + 2)
else
    print(b//x - a/x + 1)

Fixed submission:
import math
a, b, x = map(int,input().split())
print(b//x - (a-1)//x)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
pdt = 1
for i in range(n):
  pdt *= a[i]
if pdt>10**18:
  print(-1)
else:
  print(pdt)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
pdt = 1
a.sort()
for i in range(n):
  pdt *= a[i]
  if pdt==0:
    print(pdt)
    break
  elif pdt>10**18:
    print(-1)
    break
else:
  print(pdt)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
if abs(k-n)>n:
  print(n)
elif k==1:
  print(0)
else:
  print(n%abs(k-n))

Fixed submission:
n,k = map(int,input().split())
if abs(k-n)>n:
  print(n)
elif k==1 or k==n or n==0:
  print(0)
elif n<k:
  print(k%n)
else:
  n = k+ n%k
  n1 = n%k
  while n1<n:
    n=n1
    n1 = abs(k-n1)
  print(n)
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
cor = set()
pens = {}
for i in range(m):
  p,s = input().split()
  if s=="AC":
    cor.add(p)
  else:
    if not p in cor:
      if p in pens:
        pens[p] += 1
      else:
        pens[p] = 1
pen = 0
for x in cor:
  if x in pens:  
    pen += pens(x)
print(str(len(cor))+" "+str(pen))

Fixed submission:
n,m = map(int,input().split())
cor = set()
pens = {}
for i in range(m):
  p,s = input().split()
  if s=="AC":
    cor.add(p)
  else:
    if not p in cor:
      if p in pens:
        pens[p] += 1
      else:
        pens[p] = 1
pen = 0
for x in cor:
  if x in pens:  
    pen += pens[x]
print(str(len(cor))+" "+str(pen))
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
lr = [[0]*2]*m
for i in range(m):
  lr[i] = list(map(int,input().split()))
valid = set(range(1,n+1))
for i in range(m):
  subleft = set(range(1,lr[i][0]))
  subright = set(range(lr[i][1]+1,n+1))
  valid.difference_update(subleft)
  valid.difference_update(subright)
print(len(valid))

Fixed submission:
n,m = map(int,input().split())
lr = [[0]*2]*m
for i in range(m):
  lr[i] = list(map(int,input().split()))
maxl = 0
minr = 10**5
for i in range(m):
  maxl = max(maxl,lr[i][0])
  minr = min(minr,lr[i][1])
if maxl>minr:
  print(0)
else:
  print(minr-maxl+1)
Buggy python submission (verdict: Time Limit Exceeded):
a,b = input().split()
ab = int(a+b)
ans = "No"
i=3
while i*i<=ab:
  if i*i == ab:
    ans="Yes"
print(ans)

Fixed submission:
a,b = input().split()
ab = int(a+b)
ans = "No"
i=3
while i*i<=ab:
  if i*i == ab:
    ans="Yes"
  i+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
pwr = 1
for i in range(1,n+1):
  pwr *= i
print(pwr%(10**9+7))

Fixed submission:
n = int(input())
pwr = 1
for i in range(1,n+1):
  pwr *= i
  if pwr>10**9+7:
    pwr = pwr%(10**9+7)
print(pwr%(10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))

ans = 0

for i in range(0, 1<<n):
    x = 0
    y = 0
    for j in range(n):
        if(i>>j&1):
            x = x + v[j]
            y = y + c[j]
    
    if(ans < x-y):
        ans = x - y

print(ans)

Fixed submission:
import numpy as np

n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))

ans = 0

for i in range(n):
    if(v[i]-c[i]>0):
        ans += v[i] - c[i]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
input = sys.stdin.readline

N,K = map(int,input().split())

arr=list(map(int,input().split()))

ans=[0]*N

ans[N-2]=abs(arr[-2]-arr[-1])

for i in range(N-3,-1,-1):
	minn=100000000000000
	for j in range(min(K,N-i-1)):
		minn = min(minn,abs(arr[i]-arr[i+j+1])+ans[i+j+1])
	ans[i]=minn

print(ans[0])

Fixed submission:
import sys
import math
input = sys.stdin.readline

N,K = map(int,input().split())

arr=list(map(int,input().split()))

ans=[0]*N

ans[N-2]=abs(arr[-2]-arr[-1])

for i in range(N-3,-1,-1):
	minn=100000000000000
	for j in range(min(K,N-i-1)):
		minn = min(minn,abs(arr[i]-arr[i+j+1])+ans[i+j+1])
	ans[i]=minn

print(ans[0])

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

arr=list(map(int,input().split()))

ans=[0]*N

ans[N-2]=abs(arr[-2]-arr[-1])

for i in range(N-3,-1,-1):
	minn=100000000000000
	for j in range(min(K,N-i-1)):
		minn = min(minn,abs(arr[i]-arr[i+j+1])+ans[i+j+1])
	ans[i]=minn

print(ans[0])

Fixed submission:
import sys
import math
input = sys.stdin.readline

N,K = map(int,input().split())

arr=list(map(int,input().split()))

ans=[0]*N

ans[N-2]=abs(arr[-2]-arr[-1])

for i in range(N-3,-1,-1):
	minn=100000000000000
	for j in range(min(K,N-i-1)):
		minn = min(minn,abs(arr[i]-arr[i+j+1])+ans[i+j+1])
	ans[i]=minn

print(ans[0])

Buggy python submission (verdict: Runtime Error):
import sys
import math
input = sys.stdin.readline

N,K = map(int,input().split())

arr=list(map(int,input().split()))

ans=[0]*N

ans[N-2]=abs(arr[-2]-arr[-1])

for i in range(N-3,-1,-1):
	minn=math.inf
	for j in range(min(K,N-i-1)):
		minn = min(minn,abs(arr[i]-arr[i+j+1])+ans[i+j+1])
	ans[i]=minn

print(ans[0])

Fixed submission:
import sys
import math
input = sys.stdin.readline

N,K = map(int,input().split())

arr=list(map(int,input().split()))

ans=[0]*N

ans[N-2]=abs(arr[-2]-arr[-1])

for i in range(N-3,-1,-1):
	minn=100000000000000
	for j in range(min(K,N-i-1)):
		minn = min(minn,abs(arr[i]-arr[i+j+1])+ans[i+j+1])
	ans[i]=minn

print(ans[0])

Buggy python submission (verdict: Runtime Error):
import sys
import math
input = sys.stdin.readline

N,K = map(int,input().split())

arr=list(map(int,input().split()))

ans=[0]*N

ans[N-2]=abs(arr[-2]-arr[-1])

for i in range(N-3,-1,-1):
	minn=math.inf
	for j in range(min(K,N-i-1)):
		minn = min(minn,abs(arr[i]-arr[i+j+1])+ans[i+j+1])
	ans[i]=minn

print(ans[0])

Fixed submission:
import sys
import math
input = sys.stdin.readline

N,K = map(int,input().split())

arr=list(map(int,input().split()))

ans=[0]*N

ans[N-2]=abs(arr[-2]-arr[-1])

for i in range(N-3,-1,-1):
	minn=100000000000000
	for j in range(min(K,N-i-1)):
		minn = min(minn,abs(arr[i]-arr[i+j+1])+ans[i+j+1])
	ans[i]=minn

print(ans[0])
Buggy python submission (verdict: Runtime Error):
n=int(input())

l=list(map(int,input().split()))
l1=[]
l2=[]

for i in range(n):
	if i%2==0:
		l1.append(l[i])
	else:
		l2.append(l[i])

count1=[]
count2=[]

for i in range(100000):
	count1.append(0)
	count2.append(0)

for i in range(n//2):
	count1[l1[i]-1]+=1
	count2[l2[i]-1]+=1

max1=0
max2=0

maxc1=[]
maxc2=[]

for i in range(100000):
	if count1[i]>=max1:
		max1=count1[i]
		maxc1.append(i)

	if count2[i]>=max2:
		max2=count2[i]
		maxc2.append(i)

# print('maxc1',maxc1)
# print('maxc2',maxc2)
# print('max1',max1)
# print('max2',max2)

# if len(maxc2)+len(maxc1)>2 or (len(maxc2)+len(maxc1)==2 and maxc1[0]!=maxc2[0]):
# 	final=max1+max2

# else :
max3=0
max4=0
for i in range(100000):
	if i!=maxc1[0]:
		if count1[i]>=max3:
			max3=count1[i]
			maxc1.append(i)

	if i!=maxc2[0]:
		if count2[i]>=max4:
			max4=count2[i]
			maxc2.append(i)

final=max(max1+max4,max2+max3)

print(n-final)


Fixed submission:
n=input()
l=[]

for i in n:
	if i=='9':
		l.append('1')
	elif i=='1':
		l.append('9')
	else:
		l.append(i)

print(''.join(l))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

bs = 10**9 + 7
sm = 0

for i, ai in enumerate(a):
    sm += (ai * sum(a[(i+1):])) % bs
    sm = sm % bs

print(sm)

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

bs = 10**9 + 7
s = sum(a)
sm = 0

for i, ai in enumerate(a):
    s -= ai
    sm += (ai * s) % bs
    sm = sm % bs

print(sm)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys

n, k = map(int, input().split())
a = list(map(lambda x: int(x)-1, input().split()))

visited = deque()
i = 0
cnt = 0
while True:
    if cnt == k:
        print(i+1)
        sys.exit()
    if i in visited:
        break
    visited.append(i)
    i = a[i]
    cnt += 1

si = visited.index(i)
loop = list(visited)[si:]
n_loop = len(loop)
left_k = k - cnt
print(loop[left_k % n_loop] + 1)

Fixed submission:
import sys

n, k = map(int, input().split())
a = list(map(lambda x: int(x)-1, input().split()))

is_visited = [0] * n
visited = list()
i = 0
cnt = 0
while True:
    if cnt == k:
        print(i+1)
        sys.exit()
    if is_visited[i]:
        break
    is_visited[i] = 1
    visited.append(i)
    i = a[i]
    cnt += 1

si = visited.index(i)
loop = visited[si:]
n_loop = len(loop)
left_k = k - cnt
print(loop[left_k % n_loop] + 1)