Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

n,m=map(int,input().split())
a=deque(map(int,input().split()))
#a=deque(a)
for i in range(m):
  b,c=map(int,input().split())
  l=[c for _ in range(b)]
  a.extend(l)
a=list(a)
#print(a)
a.sort(reverse=1)
a=a[:n]





print(sum(a))
#print(a)

Fixed submission:
from collections import deque

n,m=map(int,input().split())
a=deque(map(int,input().split()))
bc=[list(map(int,input().split())) for _ in range(m)]
bc.sort(key=lambda x: x[1])
bc=bc[::-1]
l=0
for b,c in bc:
  if l>n:
    break
  else:
    d=[c]*b
    a.extend(d)
    l+=b


a=list(a)
#print(a)
a.sort(reverse=1)
a=a[:n]





print(sum(a))
#print(a)

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

n,m=map(int,input().split())
a=list(map(int,input().split()))
a=deque(a)
for i in range(m):
  b,c=map(int,input().split())
  a.extend([c for _ in range(b)])
a=list(a)
#print(a)
a.sort(reverse=1)
a=a[:n]





print(sum(a))
#print(a)

Fixed submission:
from collections import deque

n,m=map(int,input().split())
a=deque(map(int,input().split()))
bc=[list(map(int,input().split())) for _ in range(m)]
bc.sort(key=lambda x: x[1])
bc=bc[::-1]
l=0
for b,c in bc:
  if l>n:
    break
  else:
    d=[c]*b
    a.extend(d)
    l+=b


a=list(a)
#print(a)
a.sort(reverse=1)
a=a[:n]





print(sum(a))
#print(a)

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

n,m=map(int,input().split())
a=list(map(int,input().split()))
a=deque(a)
for i in range(m):
  b,c=map(int,input().split())
  for j in range(b):
    a.append(c)
a=list(a)
#print(a)
a.sort(reverse=1)
a=a[:n]





print(sum(a))
#print(a)

Fixed submission:
from collections import deque

n,m=map(int,input().split())
a=deque(map(int,input().split()))
bc=[list(map(int,input().split())) for _ in range(m)]
bc.sort(key=lambda x: x[1])
bc=bc[::-1]
l=0
for b,c in bc:
  if l>n:
    break
  else:
    d=[c]*b
    a.extend(d)
    l+=b


a=list(a)
#print(a)
a.sort(reverse=1)
a=a[:n]





print(sum(a))
#print(a)
Buggy python submission (verdict: Runtime Error):
n,q=map(int,input().split())
s=input()
c=[0 for _ in range(n)]
p=''
for i in range(1,n):
  x=s[i]
  if p=='A' and x='C':
    c[i-1]=1
  p=x
for i in range(q):
  ans=0
  l,r=map(int,input().split())
  ans=sum(c[l-1:r-1])
 # if s[]
  print(ans)


Fixed submission:
n,q=map(int,input().split())
s=input()
c=[0 for _ in range(n)]
p=''
d=0
for i in range(n):
  x=s[i]
  if p=='A' and x=='C':
    d+=1
  p=x
  c[i]=d
for i in range(q):
  ans=0
  l,r=map(int,input().split())
  ans=c[r-1]-c[l-1]

  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
s=input()
c=[0 for _ in range(n)]
for i in range(n-1):
  if s[i:i+2]=='AC':
    c[i]=1
for i in range(q):
  ans=0
  l,r=map(int,input().split())
  ans=sum(c[l-1:r-1])
 # if s[]
  print(ans)

Fixed submission:
n,q=map(int,input().split())
s=input()
c=[0 for _ in range(n)]
p=''
d=0
for i in range(n):
  x=s[i]
  if p=='A' and x=='C':
    d+=1
  p=x
  c[i]=d
for i in range(q):
  ans=0
  l,r=map(int,input().split())
  ans=c[r-1]-c[l-1]

  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
s=input()
'''
c=[]
for i in range(n-1):
  if s[i:i+2]=='AC':
    c.append(1)
  else:
    c.append(0)
for i in range(q):
  l,r=map(int,input().split())
  print(sum(c[l-1:r-1]))
'''
for i in range(q):
  l,r=map(int,input().split())
  print(s[l-1:r].count('AC'))

Fixed submission:
n,q=map(int,input().split())
s=input()
c=[0 for _ in range(n)]
p=''
d=0
for i in range(n):
  x=s[i]
  if p=='A' and x=='C':
    d+=1
  p=x
  c[i]=d
for i in range(q):
  ans=0
  l,r=map(int,input().split())
  ans=c[r-1]-c[l-1]

  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
s=input()
c=[]
for i in range(n-1):
  if s[i:i+2]=='AC':
    c.append(1)
  else:
    c.append(0)
for i in range(q):
  l,r=map(int,input().split())
  print(sum(c[l-1:r-1]))

Fixed submission:
n,q=map(int,input().split())
s=input()
c=[0 for _ in range(n)]
p=''
d=0
for i in range(n):
  x=s[i]
  if p=='A' and x=='C':
    d+=1
  p=x
  c[i]=d
for i in range(q):
  ans=0
  l,r=map(int,input().split())
  ans=c[r-1]-c[l-1]

  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
s=input()
for i in range(q):
  l,r=map(int,input().split())
  print(s[l-1:r].count('AC'))

Fixed submission:
n,q=map(int,input().split())
s=input()
c=[0 for _ in range(n)]
p=''
d=0
for i in range(n):
  x=s[i]
  if p=='A' and x=='C':
    d+=1
  p=x
  c[i]=d
for i in range(q):
  ans=0
  l,r=map(int,input().split())
  ans=c[r-1]-c[l-1]

  print(ans)

Buggy python submission (verdict: Runtime Error):
n,q=map(int,input().split())
s=input()
for i in range(n):
  l,r=map(int,input().split())
  print(s[l-1:r].count('AC'))

Fixed submission:
n,q=map(int,input().split())
s=input()
c=[0 for _ in range(n)]
p=''
d=0
for i in range(n):
  x=s[i]
  if p=='A' and x=='C':
    d+=1
  p=x
  c[i]=d
for i in range(q):
  ans=0
  l,r=map(int,input().split())
  ans=c[r-1]-c[l-1]

  print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input())
print(9*max(a,b,c)+a+b+c)

Fixed submission:
a,b,c=map(int,input().split())
print(9*max(a,b,c)+a+b+c)
Buggy python submission (verdict: Time Limit Exceeded):
n,x=map(int,input().split())
r=list(map(int,input().split()))
r.append(x)
r.sort()
d=[]
e=[]
for i in range(n):
  if r[i+1]!=r[i]:
    d.append(r[i+1]-r[i])
d=list(set(d))
#print(d)
while len(d)>1:
  m=min(d)
  for i in range(len(d)-1):
    if d[i+1]!=d[i]:
      e.append(d[i+1]-d[i])
  d=e[:]
  d.append(m)
  d=list(set(d))
  d.sort()
  #print(d)
print(*d)

Fixed submission:
def gcd(a,b):
  if a%b==0:
    return b
  else:
    return gcd(b,a%b)

n,x=map(int,input().split())
r=list(map(int,input().split()))
r.append(x)
r.sort()
d=[]
e=[]
for i in range(n):
  if r[i+1]!=r[i]:
    d.append(r[i+1]-r[i])
d=list(set(d))
ans=gcd(d[0],d[-1])
for y in d:
  if y%ans!=0:
    ans=gcd(ans,y)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,k=map(int,input().split())
for i in range(a,b+1):
  if i-a<k or b-i<k:
    print(i)

Fixed submission:
a,b,k=map(int,input().split())
l=min((a+b+1)//2,a+k)
r=max((a+b+1)//2,b-k+1)
for i in range(a,l):
  print(i)
for i in range(r,b+1):
  print(i)
Buggy python submission (verdict: Runtime Error):
def primes(n):
    ass = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass

q = int(input())
n = 100000
ass = primes(n)
lkn = []
for p in ass:
    l = (p + 1) // 2
    if l in ass:
        lkn.append(p)
cnt = 0
pre = 1
ans = {}
for p in lkn:
    for i in range(pre,p,2):
        ans[i] = cnt
    cnt += 1
    pre = p
for i in range(q):
    l,r = map(int,input().split())
    l = max(l-2,1)
    print(ans[r] - ans[l])
    #print(ans[r],ans[l])
#print(lkn)

Fixed submission:
def primes(n):
    ass = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass

q = int(input())
n = 100000
ass = primes(n)
lkn = []
for p in ass:
    l = (p + 1) // 2
    if l in ass:
        lkn.append(p)
cnt = 0
pre = 1
ans = {}
lkn.append(100001)
for p in lkn:
    for i in range(pre,p,2):
        ans[i] = cnt
    cnt += 1
    pre = p
for i in range(q):
    l,r = map(int,input().split())
    l = max(l-2,1)
    print(ans[r] - ans[l])
    #print(ans[r],ans[l])
#print(lkn)
Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
if a+b>c+d:
  print('Left')
elif a+b=c+d:
  print('Balanced')
else:
  print('Right')

Fixed submission:
a,b,c,d=map(int,input().split())
if a+b>c+d:
  print('Left')
elif a+b==c+d:
  print('Balanced')
else:
  print('Right')
Buggy python submission (verdict: Runtime Error):
a,b=map(int.input().split())
print((a+b+1)//2)

Fixed submission:
a,b=map(int,input().split())
print((a+b+1)//2)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
b=list(set(a))
c,ans=0,0
for x in b:
  c=a.count(x)
  if c>=int(x):
    ans+=c-int(x)
  else:
    ans+=c
print(ans)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
a.sort()
cnt,ans=0,0
p=0
for x in a:
  if p==x:
    cnt+=1
  else:
    if cnt>p:
      ans+=cnt-p
    elif cnt<p:
      ans+=cnt
    p=x
    cnt=1
if cnt>p:
  ans+=cnt-p
elif cnt<p:
  ans+=cnt
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
b=list(set(a))
c=0
for x in b:
  c=a.count(x)
  if c>=int(x):
    for i in range(int(x)):
      a.remove(x)
print(len(a))

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
a.sort()
cnt,ans=0,0
p=0
for x in a:
  if p==x:
    cnt+=1
  else:
    if cnt>p:
      ans+=cnt-p
    elif cnt<p:
      ans+=cnt
    p=x
    cnt=1
if cnt>p:
  ans+=cnt-p
elif cnt<p:
  ans+=cnt
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
b=list(set(a))
c=0
for x in b:
  c=a.count(x)
  if c>=int(x):
    for i in range(int(x)):
      a.remove(x)
print(len(a))

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
a.sort()
cnt,ans=0,0
p=0
for x in a:
  if p==x:
    cnt+=1
  else:
    if cnt>p:
      ans+=cnt-p
    elif cnt<p:
      ans+=cnt
    p=x
    cnt=1
if cnt>p:
  ans+=cnt-p
elif cnt<p:
  ans+=cnt
print(ans)
Buggy python submission (verdict: Runtime Error):
r,g=map(int,input().split())
print(g*2-r)

Fixed submission:
r=int(input())
g=int(input())
print(g*2-r)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
f=[0 for i in range(max(a))]
for x in a:
  f[x-1]+=1
  f[x-1]%=2
print(sum(f))

Fixed submission:
n=int(input())
a=[0 for _ in range(n)]
for i in range(n):
  a[i]=int(input())
a.sort()
ans,cnt=0,0
p=-1
for x in a:
  if p==x:
    cnt+=1
  else:
    p=x
    if cnt%2==1:
      ans+=1
    cnt=1
if cnt%2==1:
  ans+=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
ans=[]
for i in range(n):
  a=input()
  if a in ans:
    ans.remove(a)
  else:
    ans.append(a)
print(len(ans))

Fixed submission:
n=int(input())
a=[0 for _ in range(n)]
for i in range(n):
  a[i]=int(input())
a.sort()
ans,cnt=0,0
p=-1
for x in a:
  if p==x:
    cnt+=1
  else:
    p=x
    if cnt%2==1:
      ans+=1
    cnt=1
if cnt%2==1:
  ans+=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
ans=[]
for i in range(n):
  a=int(input())
  if a in ans:
    ans.remove(a)
  else:
    ans.append(a)
print(len(ans))

Fixed submission:
n=int(input())
a=[0 for _ in range(n)]
for i in range(n):
  a[i]=int(input())
a.sort()
ans,cnt=0,0
p=-1
for x in a:
  if p==x:
    cnt+=1
  else:
    p=x
    if cnt%2==1:
      ans+=1
    cnt=1
if cnt%2==1:
  ans+=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
ans=[]
for i in range(n):
  a=int(input())
  if a in ans:
    ans.remove(a)
  else:
    ans.append(a)
print(len(ans))

Fixed submission:
n=int(input())
a=[0 for _ in range(n)]
for i in range(n):
  a[i]=int(input())
a.sort()
ans,cnt=0,0
p=-1
for x in a:
  if p==x:
    cnt+=1
  else:
    p=x
    if cnt%2==1:
      ans+=1
    cnt=1
if cnt%2==1:
  ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
x,a,b=map(int,input().split())
print(min(abs(x-a)),abs(x-b))

Fixed submission:
x,a,b=map(int,input().split())
c=abs(x-a)
d=abs(x-b)
print('A' if c<d else 'B')
Buggy python submission (verdict: Runtime Error):
n=int(input())
ans=1
a=[]
for i in range(n):
  a.append(int(input()))
x=a[0]
if x=-2:
  print(ans)
  exit()
for i in range(n):
  x=a[x-1]
  if x==2:
    print(ans+1)
    exit()
  else:
    ans+=1
print(-1)

Fixed submission:
n=int(input())
ans=1
a=[]
for i in range(n):
  a.append(int(input()))
x=a[0]
if x==2:
  print(ans)
  exit()
for i in range(n):
  x=a[x-1]
  if x==2:
    print(ans+1)
    exit()
  else:
    ans+=1
print(-1)
Buggy python submission (verdict: Runtime Error):
n=int(input())
abc='abcdefghijklmnopqrstuvwxyz'
ans=''
for x in abc:
  z=100
  v=100
  for i in range(n):
    s=input()
    z=s.count(x)
    v=min(z,v)
  ans+=x*v   
print(ans)

Fixed submission:
n=int(input())
#t=list(input())
#t.sort()
abc='abcdefghijklmnopqrstuvwxyz'
c=0
y=''
a=[0 for i in range(len(abc))]
'''
for i in range(len(abc)):
  a[i]=t.count(abc[i])
print(a,t)
'''
s=['' for i in range(n)]
for i in range(n):
  s[i]=input()

ans=''
for x in abc:
  z=100
  v=100
  for w in s:
    z=w.count(x)
    v=min(z,v)
  ans+=x*v
    
print(ans)
Buggy python submission (verdict: Runtime Error):
_,s_=input().split()
print('A'+s[0]+'C')

Fixed submission:
_,s,_=input().split()
print('A'+s[0]+'C')
Buggy python submission (verdict: Time Limit Exceeded):
_ = int(input())
ns = list(map(int, input().split()))
total = 1
for n in ns:
    total = total*n
if total > 10**18:
    print(-1)
else:
    print(total)

Fixed submission:
import sys
_ = int(input())
ns = list(map(int, input().split()))
total = 1
flg = False
if 0 in ns:
    print(0)
    sys.exit(0)
for n in ns:
    if total > 10**18:
        flg = True
        break 
    total = total*n
if flg or total > 10**18:
    print(-1)
else:
    print(total)
Buggy python submission (verdict: Runtime Error):
n, k = [int(i) for i in input().split()]
towns = [int(i) for i in input().split()]
ind_ = 1
ts = []
roop_s = None
for i in range(k):
    ind_ = towns[ind_-1]
    if ind_ in ts:
        roop_s = ts.index(ind_)
        break
    else:
        ts.append(ind_)
init = len(ts[:roop_s])
roop_l = len(ts) - init
roop = ts[roop_s:]
print(roop[((k-init)%roop_l)-1])


Fixed submission:
n, k = [int(i) for i in input().split()]
towns = [int(i) for i in input().split()]
ind_ = 1
ts = []
visited = [0]*n
loop_s = None
while(True):
    ind_ = towns[ind_-1]
    if visited[ind_-1]:
        loop_s = ts.index(ind_)
        break
    else:
        visited[ind_-1] = 1
        ts.append(ind_)
if k <= len(ts):
    print(ts[k-1])
else:
    init = len(ts[:loop_s])
    loop_l = len(ts) - init
    loop = ts[loop_s:]
    print(loop[((k-init)%loop_l)-1])

Buggy python submission (verdict: Runtime Error):
n, k = [int(i) for i in input().split()]
towns = [int(i) for i in input().split()]
ind_ = 1
ts = []
roop_s = None
for i in range(k):
    ind_ = towns[ind_-1]
    if ind_ in ts:
        roop_s = ts.index(ind_)
        break
    else:
        ts.append(ind_)
init = len(ts[:roop_s])
roop_l = len(ts) - init
roop = ts[roop_s:]
print(roop[((k-init)%roop_l)-1])


Fixed submission:
n, k = [int(i) for i in input().split()]
towns = [int(i) for i in input().split()]
ind_ = 1
ts = []
visited = [0]*n
loop_s = None
while(True):
    ind_ = towns[ind_-1]
    if visited[ind_-1]:
        loop_s = ts.index(ind_)
        break
    else:
        visited[ind_-1] = 1
        ts.append(ind_)
if k <= len(ts):
    print(ts[k-1])
else:
    init = len(ts[:loop_s])
    loop_l = len(ts) - init
    loop = ts[loop_s:]
    print(loop[((k-init)%loop_l)-1])

Buggy python submission (verdict: Runtime Error):
n, k = [int(i) for i in input().split()]
towns = [int(i) for i in input().split()]
ind_ = 1
ts = []
roop_s = None
for i in range(15):
    ind_ = towns[ind_-1]
    if ind_ in ts:
        roop_s = ts.index(ind_)
        break
    else:
        ts.append(ind_)
init = len(ts[:roop_s])
roop_l = len(ts) - init
roop = ts[roop_s:]
print(roop[((k-init)%roop_l)-1])


Fixed submission:
n, k = [int(i) for i in input().split()]
towns = [int(i) for i in input().split()]
ind_ = 1
ts = []
visited = [0]*n
loop_s = None
while(True):
    ind_ = towns[ind_-1]
    if visited[ind_-1]:
        loop_s = ts.index(ind_)
        break
    else:
        visited[ind_-1] = 1
        ts.append(ind_)
if k <= len(ts):
    print(ts[k-1])
else:
    init = len(ts[:loop_s])
    loop_l = len(ts) - init
    loop = ts[loop_s:]
    print(loop[((k-init)%loop_l)-1])
Buggy python submission (verdict: Runtime Error):
import numpy as np
s = input()
cnt = 0
ss = []
nums = np.array([(i+1)*2019 for i in range(200000//2019) if not "0" in str((i+1)*2019)])
for start in range(len(s)):
  end = start + 3
  while(end+1<=len(s)):
    if int(s[start:end+1]) in nums:
      cnt += 1
    end += 1
print(cnt)

Fixed submission:
s, w = [int(i) for i in input().split()]
if s <= w:
  print("unsafe")
else:
  print("safe")
Buggy python submission (verdict: Runtime Error):
N = int(input())
B = [int(i) for i in input().split()]
A = [0]*N

for i in range(N):
    if i == 0:
        A[i] = B[0]
    else:
        if i < N-1:
            if B[i-1] <= B[i]:
                A[i] = B[i-1]
                A[i+1] = B[i]
            else:
                A[i] = B[i]
                A[i+1] = B[i+1]
        else:
            A[i] = B[-1]
print(sum(A))

Fixed submission:
N = int(input())
B = [int(i) for i in input().split()]
A = [0]*N

for i in range(N):
    if i == 0:
        A[i] = B[0]
    else:
        if i < N-1:
            if B[i-1] <= B[i]:
                A[i] = B[i-1]
                A[i+1] = B[i]
            else:
                A[i] = B[i]
                # A[i+1] = B[i+1]
        else:
            A[i] = B[-1]
print(sum(A))

Buggy python submission (verdict: Runtime Error):
N = int(input())
B = [int(i) for i in input().split()]
A = [0]*N

for i in range(N):
    if i < 1:
        A[i] = B[0]
    else:
        if i < N-1:
            if B[i-1] < B[i]:
                A[i] = B[i-1]
                A[i+1] = B[i]
            else:
                A[i] = B[i]
                A[i+1] = B[i+1]
        else:
            A[i] = B[-1]
print(sum(A))

Fixed submission:
N = int(input())
B = [int(i) for i in input().split()]
A = [0]*N

for i in range(N):
    if i == 0:
        A[i] = B[0]
    else:
        if i < N-1:
            if B[i-1] <= B[i]:
                A[i] = B[i-1]
                A[i+1] = B[i]
            else:
                A[i] = B[i]
                # A[i+1] = B[i+1]
        else:
            A[i] = B[-1]
print(sum(A))

Buggy python submission (verdict: Runtime Error):
N = int(input())
foods = [int(i) for i in input().split()]
eff = sum([int(i) for i in input().split()])
plus = [int(i) for i in input().split()]
if foods[-1]-2 in plus:
  print(eff + plus[foods[-1]-2])
else:
  print(eff)

Fixed submission:
N = int(input())
B = [int(i) for i in input().split()]
A = [0]*N

for i in range(N):
    if i == 0:
        A[i] = B[0]
    else:
        if i < N-1:
            if B[i-1] <= B[i]:
                A[i] = B[i-1]
                A[i+1] = B[i]
            else:
                A[i] = B[i]
                # A[i+1] = B[i+1]
        else:
            A[i] = B[-1]
print(sum(A))
Buggy python submission (verdict: Runtime Error):
N = int(input())
steps = [int(i) for i in input().split()]
dp = [float('inf')]*N
for i in range(N):
  if i == 0:
    dp[0] = 0
    dp[1] = abs(steps[1] - steps[0])
    dp[2] = abs(steps[2] - steps[0])
  else:
    # 現在位置までのコスト + 隣に行くコスト　を登録済みのDPテーブルと比較し、小さい方で更新
    if i+1 < N:
    	dp[i+1] = min(abs(steps[i] - steps[i+1]) + dp[i], dp[i+1])
    if i+2 < N:
    	dp[i+2] = min(abs(steps[i] - steps[i+2]) + dp[i], dp[i+2])
print(dp[-1])

Fixed submission:
N = int(input())

hights = [int(h) for h in input().split()]


eval = []

def chmin(a,b):
    if a > b:
        b = a
        return True
    return False

for i in range(N):
    if i == N:
        break
    elif i == 0:
        eval.append(0)
        continue
    elif i == 1:
        eval.append(abs(hights[i] - hights[i-1] ))
        continue

    to_next = abs(hights[i] - hights[i-1]) + eval[i-1]
    prev_to_next = abs(hights[i] - hights[i-2]) + eval[i-2]
    if prev_to_next > to_next:
        eval.append(to_next)
    else:
        eval.append(prev_to_next)
print(eval[N-1])

Buggy python submission (verdict: Runtime Error):
N = input()
input = input()
hights = [int(h) for h in input.split()]

print(hights)

eval = []

def chmin(a,b):
    if a > b:
        b = a
        return True
    return False

for i in range(N):
    if i == N:
        break
    elif i == 0:
        eval.append(0)
        continue
    elif i == 1:
        eval.append(abs(hights[i] - hights[i-1] ))
        continue

    to_next = abs(hights[i] - hights[i-1]) + eval[i-1]
    prev_to_next = abs(hights[i] - hights[i-2]) + eval[i-2]
    if prev_to_next > to_next:
        eval.append(to_next)
    else:
        eval.append(prev_to_next)
print(eval)
print(eval[N-1])

Fixed submission:
N = int(input())

hights = [int(h) for h in input().split()]


eval = []

def chmin(a,b):
    if a > b:
        b = a
        return True
    return False

for i in range(N):
    if i == N:
        break
    elif i == 0:
        eval.append(0)
        continue
    elif i == 1:
        eval.append(abs(hights[i] - hights[i-1] ))
        continue

    to_next = abs(hights[i] - hights[i-1]) + eval[i-1]
    prev_to_next = abs(hights[i] - hights[i-2]) + eval[i-2]
    if prev_to_next > to_next:
        eval.append(to_next)
    else:
        eval.append(prev_to_next)
print(eval[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, K = [int(i) for i in input().split()]
steps = [int(i) for i in input().split()]
dp = [float('inf')]*N

for i in range(N):
  if i == 0:
    dp[0] = 0
    for k in range(1, K+1):
      if N > k:
          dp[k] = abs(steps[k] - steps[0])
  else:
    # 現在位置までのコスト + 隣に行くコスト　を登録済みのDPテーブルと比較し、小さい方で更新
    for k in range(1, K+1):
      if i+k < N:
          dp[i+k] = min(abs(steps[i] - steps[i+k]) + dp[i], dp[i+k])
print(dp[-1])

Fixed submission:
N, K = [int(i) for i in input().split()]
steps = [int(i) for i in input().split()]
dp = [float('inf')]*N

for i in range(N):
  if i == 0:
    dp[0] = 0
    for k in range(1, K+1):
      if N > k:
          dp[k] = abs(steps[k] - steps[0])
  else:
    # 現在位置までのコスト + 隣に行くコスト　を登録済みのDPテーブルと比較し、小さい方で更新
    for k in range(1, K+1):
      if i+k < N:
          dp[i+k] = min(abs(steps[i] - steps[i+k]) + dp[i], dp[i+k])
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
import copy
N, K = [int(i) for i in input().split()]
wvs = [(int(w), int(v)) for w,v in [input().split() for _ in range(N)]]
dp = [0]*(K)
for i, wv in enumerate(wvs):
  w,v = wv
  tmp_dp = copy.deepcopy(dp)
  for j in range(i,K):
    if (j+w) <= K:
      tmp_dp[j+w-1] = max(dp[j+w-1], dp[j-1] + v)
  dp = tmp_dp
print(max(dp))

Fixed submission:
from copy import deepcopy
N, K = [int(i) for i in input().split()]
wvs = [(int(w), int(v)) for w,v in [input().split() for _ in range(N)]]
dp = [0]*(K)
for i, wv in enumerate(wvs):
  w,v = wv
  tmp_dp = deepcopy(dp)
  for j in range(i,K):
    if (j+w) <= K:
      tmp_dp[j+w-1] = max(dp[j+w-1], dp[j-1] + v)
  dp = tmp_dp
print(max(dp))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ns = [int(input()) for _ in range(n)]
i = 0
cnt = 0
pushed = [0]
flg = False
while(True):
    cnt += 1
    i = ns[i] - 1
    if i in pushed:
        break
    pushed.append(i)
    if i == 1:
        flg = True
        break
if flg:
    print(cnt)
else:
    print(-1)

Fixed submission:
import sys
n = int(input())
ns = [int(input()) for _ in range(n)]
if not 2 in ns:
    print(-1)
    sys.exit(0)
i = 0
cnt = 0
pushed = [0]*n
flg = False
while(True):
    cnt += 1
    i = ns[i] - 1
    if pushed[i] == 1:
        break
    pushed[i] = 1
    if i == 1:
        flg = True
        break
if flg:
    print(cnt)
else:
    print(-1)