Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
b=[0]*64
for i in range(n):
    for j in range(a[i].bit_length()):
        if a[i]>>j & 1: b[j]+=1
c=0
for i in range(64):
    c+=(b[i]*(n-b[i])*2**i) % 1000000007
print(c%1000000007)


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=[0]*64
for i in range(n):
    for j in range(a[i].bit_length()):
        if a[i]>>j & 1: b[j]+=1
c=0
for i in range(64):
    c+=(b[i]*(n-b[i])*2**i) % 1000000007
print(c%1000000007)

Buggy python submission (verdict: Runtime Error):
from math import ceil, log2
n=int(input())
a=list(map(int,input().split()))
b=[0]*64
for i in range(n):
    for j in range(ceil(log2(a[i]))):
        if a[i]>>j & 1: b[j]+=1
c=0
for i in range(64):
    c+=b[i]*(n-b[i])*2**i
print(c%(10**9+7))


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=[0]*64
for i in range(n):
    for j in range(a[i].bit_length()):
        if a[i]>>j & 1: b[j]+=1
c=0
for i in range(64):
    c+=(b[i]*(n-b[i])*2**i) % 1000000007
print(c%1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
b=[0]*64
for i in range(n):
    for j in range(len(bin(a[i]))-2):
        if a[i]>>j & 1: b[j]+=1
c=0
for i in range(64):
    c+=b[i]*(n-b[i])*2**i
print(c%(10**9+7))


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=[0]*64
for i in range(n):
    for j in range(a[i].bit_length()):
        if a[i]>>j & 1: b[j]+=1
c=0
for i in range(64):
    c+=(b[i]*(n-b[i])*2**i) % 1000000007
print(c%1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
N = int(input())
A = [int(i) for i in input().split()]

S = 0
for i, j in combinations(A, 2):
    S += i^j
    S %= 10**9+7

print(S)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=[0]*64
for i in range(n):
    for j in range(a[i].bit_length()):
        if a[i]>>j & 1: b[j]+=1
c=0
for i in range(64):
    c+=(b[i]*(n-b[i])*2**i) % 1000000007
print(c%1000000007)
Buggy python submission (verdict: Runtime Error):
a,b=[i for i in input().split()]
if a<10 and b<10:
    print(a*b)
else:
    print(-1)

Fixed submission:
a,b=[int(i) for i in input().split()]
if 0<a<10 and 0<b<10:
    print(a*b)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
N = int(input())
L = [int(i) for i in input().split()]
c = 0


def check(a, b, c):
    return (a < b+c) and (b < c+a) and (c < a+b)


for i, j, k in combinations(L, 3):
    c += check(i, j, k)

print(c)


Fixed submission:
from bisect import bisect_left
N = int(input())
L = sorted([int(i) for i in input().split()])

res = 0

for i in range(N):
    for j in range(i+1, N):
        r = bisect_left(L, L[i]+L[j])
        res += max(r-(j+1), 0)

print(res)

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

n=int(input())
l=sorted([int(i) for i in input().split()])

v=np.array([l[0], l[1]])
vsum=np.array([l[0]+l[1]])

c=0

for i in range(2, n):
    p=l[i]
    c+=np.sum(vsum>p)
    vsum = np.concatenate([vsum, v+p], 0)
    v=np.append(v, p)

print(c)

Fixed submission:
from bisect import bisect_left
N = int(input())
L = sorted([int(i) for i in input().split()])

res = 0

for i in range(N):
    for j in range(i+1, N):
        r = bisect_left(L, L[i]+L[j])
        res += max(r-(j+1), 0)

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

n=int(input())
l=[int(i) for i in input().split()]

c=0
for i in combinations(l,3):
    p=max(i)
    if p<sum(i)-p:
        c+=1
print(c)

Fixed submission:
from bisect import bisect_left
N = int(input())
L = sorted([int(i) for i in input().split()])

res = 0

for i in range(N):
    for j in range(i+1, N):
        r = bisect_left(L, L[i]+L[j])
        res += max(r-(j+1), 0)

print(res)
Buggy python submission (verdict: Runtime Error):
import numpy as np
n=int(input())
a=np.array([int(i) for i in input().split()])
a = 1/a
print(1/(sum(a))

Fixed submission:
import numpy as np
n=int(input())
a=np.array([int(i) for i in input().split()])
a = 1/a
print(1/sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(2**31-1)

N, Q = [int(i) for i in input().split()]
G = [[] for _ in range(N)]
counter = [0] * N
res = [0] * N
visited = [0] * N

for _ in range(N-1):
    a, b = [int(i)-1 for i in input().split()]
    G[a].append(b)
    G[b].append(a)

for _ in range(Q):
    p, x = [int(i) for i in input().split()]
    p -= 1
    counter[p] += x

def dfs(G, v, p):
    visited[v] = 1
    res[v] = res[p]+counter[v]
    for nv in G[v]:
        if visited[nv]: continue
        dfs(G, nv, v)

dfs(G, 0, 0)
print(*res)

Fixed submission:
N, Q = [int(i) for i in input().split()]
G = [[] for _ in range(N)]
counter = [0] * N
res = [0] * N
visited = [0] * N

for _ in range(N-1):
    a, b = [int(i)-1 for i in input().split()]
    G[a].append(b)
    G[b].append(a)

for _ in range(Q):
    p, x = [int(i) for i in input().split()]
    p -= 1
    counter[p] += x

# def dfs(G, v, p):
#     visited[v] = 1
#     res[v] = res[p]+counter[v]
#     for nv in G[v]:
#         if visited[nv]: continue
#         dfs(G, nv, v)

stack = [0]
parent = [0]
while stack:
    v = stack.pop()
    p = parent.pop()
    visited[v] = 1
    res[v] = res[p]+counter[v]
    for nv in G[v]:
        if visited[nv]: continue
        stack.append(nv)
        parent.append(v)

# dfs(G, 0, 0)
print(*res)

Buggy python submission (verdict: Runtime Error):
N, Q = [int(i) for i in input().split()]
G = [[] for _ in range(N)]
counter = [0] * N
res = [0] * N
visited = [0] * N

for _ in range(N-1):
    a, b = [int(i)-1 for i in input().split()]
    G[a].append(b)
    G[b].append(a)

for _ in range(Q):
    p, x = [int(i) for i in input().split()]
    p -= 1
    counter[p] += x

def dfs(G, v, p):
    visited[v] = 1
    res[v] = res[p]+counter[v]
    for nv in G[v]:
        if visited[nv]: continue
        dfs(G, nv, v)

dfs(G, 0, 0)
print(*res)

Fixed submission:
N, Q = [int(i) for i in input().split()]
G = [[] for _ in range(N)]
counter = [0] * N
res = [0] * N
visited = [0] * N

for _ in range(N-1):
    a, b = [int(i)-1 for i in input().split()]
    G[a].append(b)
    G[b].append(a)

for _ in range(Q):
    p, x = [int(i) for i in input().split()]
    p -= 1
    counter[p] += x

# def dfs(G, v, p):
#     visited[v] = 1
#     res[v] = res[p]+counter[v]
#     for nv in G[v]:
#         if visited[nv]: continue
#         dfs(G, nv, v)

stack = [0]
parent = [0]
while stack:
    v = stack.pop()
    p = parent.pop()
    visited[v] = 1
    res[v] = res[p]+counter[v]
    for nv in G[v]:
        if visited[nv]: continue
        stack.append(nv)
        parent.append(v)

# dfs(G, 0, 0)
print(*res)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[int(input()) for _ in range(n)]
aa=sorted(list(set(a[:])),reverse=True)
maxa=aa[0]
for i in range(n):
    if a[i] == maxa:
        print(aa[1])
    else:
        print(maxa)

Fixed submission:
n=int(input())
a=[int(input()) for _ in range(n)]
aa=sorted(list(set(a[:])),reverse=True)
maxa=aa[0]
f=False if a.count(maxa) != 1 else True
for i in range(n):
    if a[i] == maxa and f:
        print(aa[1] if len(aa) != 1 else maxa)
    else:
        print(maxa)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[int(input()) for _ in range(n)]
aa=sorted(a[:])
for i in range(n):
  k=a[i]
  t=-1
  while True:
    if aa[t] != k:
      print(aa[t])
      break
    else: t -= 1

Fixed submission:
n=int(input())
a=[int(input()) for _ in range(n)]
aa=sorted(list(set(a[:])),reverse=True)
maxa=aa[0]
f=False if a.count(maxa) != 1 else True
for i in range(n):
    if a[i] == maxa and f:
        print(aa[1] if len(aa) != 1 else maxa)
    else:
        print(maxa)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[int(input()) for _ in range(n)]
aa=sorted(a[:])
for i in range(n):
  k=a[i]
  t=-1
  while True:
      if aa[t] != k:
          print(aa[t])
          break
      else: t -= 1

Fixed submission:
n=int(input())
a=[int(input()) for _ in range(n)]
aa=sorted(list(set(a[:])),reverse=True)
maxa=aa[0]
f=False if a.count(maxa) != 1 else True
for i in range(n):
    if a[i] == maxa and f:
        print(aa[1] if len(aa) != 1 else maxa)
    else:
        print(maxa)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(input()) for _ in range(n)]
for i in range(n):
  k=a[:i]+a[i+1:]
  print(max(k))

Fixed submission:
n=int(input())
a=[int(input()) for _ in range(n)]
aa=sorted(list(set(a[:])),reverse=True)
maxa=aa[0]
f=False if a.count(maxa) != 1 else True
for i in range(n):
    if a[i] == maxa and f:
        print(aa[1] if len(aa) != 1 else maxa)
    else:
        print(maxa)
Buggy python submission (verdict: Runtime Error):
def gcd(a,b):
  while b:
    a,b=b,a%b
  return a

def lcm(a,b):
  return a * b // gcd(a,b)

e=lcm(c,d)
a,b,c,d=map(int,input().split())
print((b-a+1)-(b//c-a//c)-(b//d-a//d)+(b//e-a//e))

Fixed submission:
def gcd(a,b):
	while b:
		a,b = b,a % b
	return a

def lcm(a,b):
	return a * b // gcd (a, b)

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

cc=(b//c)-((a-1)//c)
dd=(b//d)-((a-1)//d)
cd=(b//e)-((a-1)//e)
print((b-a+1)-(cc+dd-cd))
Buggy python submission (verdict: Runtime Error):
w,h,x,y=map(int,input().split())

if w/2 == x and h/2 == y:
  way=1
  s=w*h/2

elif (x==0 and y==0) or (x==0 and y==h) or (x==w and y==0) or (x==w and y==h):
  way=0
  s=w*h/2

elif y/x == h/w:
  way=0
  s=w*h/2

else:
  oy,yh,ox,xw=y,h-y,x,w-x
  yoko=min(oy*w,yh*w)
  tate=min(ox*h,xw*h)
  way=0
  s=max(yoko,tate)

print(float(s),way)

Fixed submission:
W,H,x,y=map(int,input().split())
ways=1 if (W/2 == x) and (H/2 == y) else 0
print(W*H/2,ways)
Buggy python submission (verdict: Runtime Error):
N, M = [int(i) for i in input().split()]
A = {int(input()) for _ in range(M)}

dp = [0] * 10100
dp[0] = 1
dp[1] = 0 if 1 in A else 1

for i in range(2, N+1):
    if not i-1 in A:
        dp[i] += dp[i-1]
    if not i-2 in A:
        dp[i] += dp[i-2]
    dp[i] %= 1000000007

print(dp[N])


Fixed submission:
N, M = map(int, input().split())
A = set([int(input()) for _ in range(M)])

dp = [0, 1]
for i in range(N):
    if i+1 in A: dp.append(0)
    else: dp.append(dp[i]+dp[i+1])
print(dp[N+1]%1000000007)

Buggy python submission (verdict: Runtime Error):
N, M = [int(i) for i in input().split()]

dp = [-1] * 10100
dp[0] = 1
dp[1] = 1

for i in range(M):
    a = int(input())
    dp[a] = 0

for i in range(N):
    if dp[i+2] == 0: continue
    dp[i+2] = dp[i]+dp[i+1]

print(dp[N] % 1000000007)

Fixed submission:
N, M = map(int, input().split())
A = set([int(input()) for _ in range(M)])

dp = [0, 1]
for i in range(N):
    if i+1 in A: dp.append(0)
    else: dp.append(dp[i]+dp[i+1])
print(dp[N+1]%1000000007)

Buggy python submission (verdict: Runtime Error):
N, M = [int(i) for i in input().split()]
A = {int(input()) for _ in range(M)}

dp = [0] * 20000
dp[0] = 1
dp[1] = 0 if 1 in A else 1
for i in range(N):
    if i+2 in A:
        continue
    dp[i+2] = dp[i] + dp[i+1]

print(dp[N] % 1000000007)

Fixed submission:
N, M = map(int, input().split())
A = set([int(input()) for _ in range(M)])

dp = [0, 1]
for i in range(N):
    if i+1 in A: dp.append(0)
    else: dp.append(dp[i]+dp[i+1])
print(dp[N+1]%1000000007)

Buggy python submission (verdict: Runtime Error):
N, M = [int(i) for i in input().split()]
A = {int(input()) for _ in range(M)}

dp = [0] * 10010
dp[0] = 1
dp[1] = 0 if 1 in A else 1
for i in range(N):
    if i+2 in A:
        continue
    dp[i+2] = dp[i] + dp[i+1]

print(dp[N] % 1000000007)

Fixed submission:
N, M = map(int, input().split())
A = set([int(input()) for _ in range(M)])

dp = [0, 1]
for i in range(N):
    if i+1 in A: dp.append(0)
    else: dp.append(dp[i]+dp[i+1])
print(dp[N+1]%1000000007)
Buggy python submission (verdict: Runtime Error):
A,B=map(int,input().split())
print(b if A >= 13 else int(b/2) if 12 >= A >= 6 else 0)

Fixed submission:
A,B=map(int,input().split())
print(B if A >= 13 else int(B/2) if 12 >= A >= 6 else 0)

Buggy python submission (verdict: Runtime Error):
A,B=map(int,input().split())
print(b if A >= 13 else int(b/2) if A >= 6 else 0)

Fixed submission:
A,B=map(int,input().split())
print(B if A >= 13 else int(B/2) if 12 >= A >= 6 else 0)
Buggy python submission (verdict: Runtime Error):
n,m=[int(i) for i in input().split()]
a=[]
for i in range(m):
    l,r=[int(i) for i in input().split()]
    a.append(set(range(l,r+1)))
for i in range(m):
  a[0]=a[0] & a[1]
print(len(a))

Fixed submission:
n, m=[int(i) for i in input().split()]

maxL = float("-inf")
minR = float("inf")

for i in range(m):
    l, r = [int(i) for i in input().split()]
    maxL, minR = max(maxL, l), min(minR, r)

print(max(0, minR - maxL + 1))
Buggy python submission (verdict: Runtime Error):
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
D = [X[i] - Y[i] for i in range(N)]
D = filter(lambda x: x > 0, D)
print(sum(D))

Fixed submission:
n=int(input())
v=list(map(int,input().split()))
c=list(map(int,input().split()))
x=0
y=0
l=[v[j]-c[j] for j in range(n)]
l.sort(reverse=True)
l=filter(lambda x:x >0,l)
print(sum(l))
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
k = int(input())
m = s[k-1]

for i in range(n):
  if s[i] != m:
    s[i] = "*"
print(s)

Fixed submission:
n = int(input())
s = input()
k = int(input())
m = s[k-1]

for i in range(n):
  if s[i] != m:
    s = s.replace(s[i], "*")
print(s)

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
k = int(input())
m = s[k-1]

for i in range(n):
  if s[i] != m:
    s[i] = "*"

Fixed submission:
n = int(input())
s = input()
k = int(input())
m = s[k-1]

for i in range(n):
  if s[i] != m:
    s = s.replace(s[i], "*")
print(s)
Buggy python submission (verdict: Runtime Error):
A,B = map(int, input().split())
c=0
if max(A, B) -2 >= min(A,B):
  c = max(A,B) + max(A,B) - 1
else:
  c = sum(A,B)
print(c)

Fixed submission:
A,B = map(int, input().split())
c=0
if max(A, B) -2 >= min(A,B):
  c = max(A,B) + max(A,B) - 1
else:
  c = A+B
print(c)
Buggy python submission (verdict: Runtime Error):
antenna = [int(input()) for _ in range(N)]
k = int(input())

print("Yay!" if max(antenna) - min(antenna) <= k else ":(")

Fixed submission:
b=True
a=[int(input()) for i in range(5)]
k=int(input())
for j in range(5):
  for l in range(5):
    if a[j]-a[l] > k:
      b=False
if b:
  print("Yay!")
else:
  print(":(")
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[int(input()) for i in range(5)]
p=[n, 0, 0, 0, 0, 0]
t=0
if min(s) >= n:
  print(5)
else:
  while p[5] != n:
    for i in range(5):
      if p[4-i] >= s[4-i]:
        p[4-i] -= s[4-i]
        to = s[4-i]
      else:
        to = p[4-i]
        p[4-i] = 0
      p[5-i] += to

    t+=1
  print(t)

Fixed submission:
import math
N = int(input())
t = min([int(input()) for _ in range(5)])
print(math.ceil(N/t)+4)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[int(input()) for i in range(5)]
a=s[0]
b=s[1]
c=s[2]
d=s[3]
e=s[4]
p=[n, 0, 0, 0, 0, 0]
t=0
while p[5] != n:
  for i in range(5):
    if p[4-i] >= s[4-i]:
      p[4-i] -= s[4-i]
      to = s[4-i]
    else:
      to = p[4-i]
      p[4-i] = 0
    p[5-i] += to

  t+=1
print(t)

Fixed submission:
import math
N = int(input())
t = min([int(input()) for _ in range(5)])
print(math.ceil(N/t)+4)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[int(input()) for i in range(5)]
a=s[0]
b=s[1]
c=s[2]
d=s[3]
e=s[4]
p=[n, 0, 0, 0, 0, 0]
t=0
while p[5] != n:
  for i in range(5):
    if p[4-i] >= s[4-i]:
      p[4-i] -= s[4-i]
      to = s[4-i]
    else:
      to = p[4-i]
      p[4-i] = 0
    p[5-i] += to

  t+=1
print(t)

Fixed submission:
import math
N = int(input())
t = min([int(input()) for _ in range(5)])
print(math.ceil(N/t)+4)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[int(input()) for i in range(5)]
a=s[0]
b=s[1]
c=s[2]
d=s[3]
e=s[4]
p=[n, 0, 0, 0, 0, 0]
t=0
while p[5] != n:
  #to6
  if p[4] >= e:
    p[4] -= e
    to6 = e
  else:
    to6 = p[4]
    p[4] = 0
  p[5] += to6
  #to5
  if p[3] >= d:
    p[3] -= d
    to5 = d
  else:
    to5 = p[3]
    p[3] = 0
  p[4] += to5
  #to4
  if p[2] >= c:
    p[2] -= c
    to4 = c
  else:
    to4 = p[2]
    p[2] = 0
  p[3] += to4
  #to3
  if p[1] >= b:
    p[1] -= b
    to3 = b
  else:
    to3 = p[1]
    p[1] = 0
  p[2] += to3
  #to2
  if p[0] >= a:
    p[0] -= a
    to2 = a
  else:
    to2 = p[0]
    p[0] = 0
  p[1] += to2
  t+=1
print(t)

Fixed submission:
import math
N = int(input())
t = min([int(input()) for _ in range(5)])
print(math.ceil(N/t)+4)
Buggy python submission (verdict: Time Limit Exceeded):
n,q=[int(i) for i in input().split()]
s=input()
for i in range(q):
    c=0
    query = (lambda x: [x[0]-1, x[1]])([int(i) for i in input().split()])
    seq = s[query[0]:query[1]]
    for i in range(query[1]-query[0]-1):
        if seq[i:i+2] == "AC":
            c += 1
    print(c)


Fixed submission:
N, Q = [int(i) for i in input().split()]
S = input()

cumsum = [0]
for i in range(1, N):
    if (S[i-1], S[i]) == ("A", "C"):
        cumsum.append(cumsum[i-1]+1)
    else:
        cumsum.append(cumsum[i-1])

for i in range(Q):
    l, r = [int(i)-1 for i in input().split()]
    print(cumsum[r]-cumsum[l])

Buggy python submission (verdict: Time Limit Exceeded):
n,q=[int(i) for i in input().split()]
s=list(input())
for i in range(q):
    c=0
    query = (lambda x: [x[0]-1, x[1]])([int(i) for i in input().split()])
    seq = s[query[0]:query[1]]
    for i in range(query[1]-query[0]-1):
        if seq[i]+seq[i+1] == "AC":
            c += 1
    print(c)


Fixed submission:
N, Q = [int(i) for i in input().split()]
S = input()

cumsum = [0]
for i in range(1, N):
    if (S[i-1], S[i]) == ("A", "C"):
        cumsum.append(cumsum[i-1]+1)
    else:
        cumsum.append(cumsum[i-1])

for i in range(Q):
    l, r = [int(i)-1 for i in input().split()]
    print(cumsum[r]-cumsum[l])
Buggy python submission (verdict: Runtime Error):
# 入力
N, M = [int(i) for i in input().split()]

# カウント用の配列
count = [0] * (M-1)

for i in range(N):  # 入力しながら
    _, *A = [int(i)-1 for i in input().split()]
    for j in A:     # 数える
        count[j] += 1

res = 0
for i in count:
    if i == N: res += 1

print(res)

Fixed submission:
# 入力
N, M = [int(i) for i in input().split()]

# カウント用の配列
count = [0] * M

for i in range(N):  # 入力しながら
    _, *A = [int(i)-1 for i in input().split()]
    for j in A:     # 数える
        count[j] += 1

res = 0
for i in count:
    if i == N: res += 1

print(res)
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=list(map(int, input().split()))
m=pop(max(l))
print("Yes" if m < sum(l) else "No")

Fixed submission:
N = int(input())
L = list(map(int, input().split()))
print("Yes" if max(L) < sum(L)-max(L) else "No")

Buggy python submission (verdict: Runtime Error):
N = int(input())
L = list(map(int, input().split()))
print("Yes" if pop(index(max(L))) < sum(L) else "No")

Fixed submission:
N = int(input())
L = list(map(int, input().split()))
print("Yes" if max(L) < sum(L)-max(L) else "No")
Buggy python submission (verdict: Runtime Error):
S=[i for i in list(input())];N=len(S);k=['k','e','y','e','n','c','e']
for d in range(N-6):
    for i in range(N-d+1):
        s=S[:i]+S[i+d:];if s==k:
            print('YES');quit()
print('NO')

Fixed submission:
S = [i for i in list(input())]
N = len(S)
k = [i for i in list('keyence')]

for d in range(N-6):
    for i in range(N-(d-1)):
        s = S[:i] + S[i+d:]
        if s==k:
            print('YES')
            quit()
print('NO')
Buggy python submission (verdict: Runtime Error):
N = int(input())
h = [int(i) for i in input().split()]
dp = [float("inf")]*N

dp[0] = 0

for i in range(1, N):
    dp[i+1] = min(dp[i+1], dp[i] + abs(h[i] - h[i+1]))
    if i > 1: dp[i+2] = min(dp[i+2], dp[i] + abs(h[i] - h[i+2]))

print(dp[-1])

Fixed submission:
N = int(input())
h = [int(i) for i in input().split()]
dp = [float("inf")]*N

dp[0] = 0

for i in range(1, N):
    dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
    if i > 1: dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]))

print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
INF = 10**9

N, K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()] + [0]*100

dp = [INF] * 100200
dp[0] = 0

for i in range(N):
    for j in range(1, K+1):
        dp[i+j] = min(dp[i+j], dp[i]+abs(h[i+j]-h[i]))

print(dp[N-1])

Fixed submission:
N, K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

INF = 10**9

dp = [INF]*100010

dp[0] = 0

for i in range(N):
    for j in range(1, K+1):
        if i < N-j: dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j] - h[i]))

print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
INF = 10**18

N, K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()] + [0]*100

dp = [INF] * 100200
dp[0] = 0

for i in range(N):
    for j in range(1, K+1):
        dp[i+j] = min(dp[i+j], dp[i]+abs(h[i+j]-h[i]))

print(dp[N-1])

Fixed submission:
N, K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

INF = 10**9

dp = [INF]*100010

dp[0] = 0

for i in range(N):
    for j in range(1, K+1):
        if i < N-j: dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j] - h[i]))

print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

INF = 10**12

dp = [INF]*100010

dp[0] = 0

for i in range(N):
    for j in range(1, K+1):
        if i < N-j: dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j] - h[i]))

print(dp[N-1])


Fixed submission:
N, K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

INF = 10**9

dp = [INF]*100010

dp[0] = 0

for i in range(N):
    for j in range(1, K+1):
        if i < N-j: dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j] - h[i]))

print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = [int(i) for i in input().split()]
h = [0] * (N+K)
for i, j in enumerate([int(i) for i in input().split()]):
    h[i]=j

INF = 10**12

dp = [INF]*200000

dp[0] = 0

for i in range(N):
    for j in range(1, K+1):
        dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j] - h[i]))

print(dp[N-1])


Fixed submission:
N, K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

INF = 10**9

dp = [INF]*100010

dp[0] = 0

for i in range(N):
    for j in range(1, K+1):
        if i < N-j: dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j] - h[i]))

print(dp[N-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
p = [int(input()) for _ in range(n)]
ex = l.pop(l.index(max(l)))
print(int(ex / 1) + sum(l))

Fixed submission:
n = int(input())
p = [int(input()) for _ in range(n)]
ex = p.pop(p.index(max(p)))
print(int(ex / 2) + sum(p))
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
from collections import deque
n,X = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
x.append(X)
x = sorted(x)
k = x[0]
x = deque([i-k for i in x])
x.popleft()

def gcdn():
    if len(x)==1:
        return
    p=x.pop()
    q=x.pop()
    x.append(gcd(p,q))
    gcdn()

gcdn()
print(x[0])

Fixed submission:
import sys
sys.setrecursionlimit((2**31)-1)
from fractions import gcd
from collections import deque
n,X = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
x.append(X)
x = sorted(x)
k = x[0]
x = deque([i-k for i in x])
x.popleft()

def gcdn():
    if len(x)==1:
        return
    p=x.pop()
    q=x.pop()
    x.append(gcd(p,q))
    gcdn()

gcdn()
print(x[0])