Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L=[int(x) for x in input().split()]
L.sort()
count=0

for i,a in enumerate(L):
    for j,b in enumerate(L[i+1:]):
        for k,c in enumerate(L[i+j+2:]):
            if c>=a+b:
                break
            count+=1
print(count)

Fixed submission:
def main():
    N=int(input())
    L=[int(x) for x in input().split()]
    L.sort()
    count=0

    dic={}

    for i in range(N):
        for j in range(i+1,N):
            if i:
                try:
                    start=dic[j]
                    count+=dic[j]-j-1
                except:
                    count+=N-j-1
                    continue
            else:
                start=j+1
            for k in range(start,N):
                if L[k]>=L[i]+L[j]:
                    dic[j]=k
                    break
                count+=1
                
                
                
    print(count)

main()
Buggy python submission (verdict: Runtime Error):
S=input()
K=int(input())

count=1
L=[]
for i in range(len(S)):
    try:
        if S[i] == S[i+1]:
           count = count + 1
        else:
            L.append(count)
            count = 1
    except:
        # 最後の文字セットがOutOfRangeになるので結果に出力
        L.append(count)

if S[-1]==S[1]:
  flag=0
  if len(L)==1:
    print(len(S)*K//2)
  else:
    if L[-1]%2==1 and L[0]%2==1:
      flag=1
    L[0]=(L[0]+L[-1])//2*2
    L[-1]=0
    print(sum([x//2 for x in L])*K-flag)
else:
  print(sum([x//2 for x in L])*K)


Fixed submission:

def solve():
  S=input()
  K=int(input())
  if len(S)==1:
    return K//2
  count=1
  L=[]
  for i in range(len(S)):
      try:
          if S[i] == S[i+1]:
             count = count + 1
          else:
              L.append(count)
              count = 1
      except:
          # 最後の文字セットがOutOfRangeになるので結果に出力
          L.append(count)

  if S[-1]==S[1]:
    flag=0
    if len(L)==1:
      return len(S)*K//2
    else:
      if L[-1]%2==1 and L[0]%2==1:
        flag=1
      L[0]=(L[0]+L[-1])//2*2
      L[-1]=0
    return sum([x//2 for x in L])*K-flag
  else:
    return sum([x//2 for x in L])*K

print(solve())
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
from collections import defaultdict

S=input()
T=input()

def solve():
    obj=defaultdict(list)
    for i,s in enumerate(S):
        obj[s].append(i)

    result=1
    mx=-1
    for t in T:
        flag=True

        if not obj[t]:
            return -1

        
        pos=(obj[t]+[-1])[bisect.bisect_right(obj[t],mx)]
        if pos==-1:
            mx=obj[t][0]
            result+=1
        else:
            mx=pos

    if pos==-1:
        pos=obj[t][0]
    return len(S)*(result-1)+pos+1
print(solve())


Fixed submission:
import bisect
from collections import defaultdict

S=input()
T=input()

def solve():
    obj=defaultdict(list)
    for i,s in enumerate(S):
        obj[s].append(i)

    result=1
    mx=-1
    for t in T:
        flag=True

        if not obj[t]:
            return -1

        
        bi_pos=bisect.bisect_right(obj[t],mx)
        if bi_pos==len(obj[t]):
            pos=-1
            mx=obj[t][0]
            result+=1
        else:
            pos=obj[t][bi_pos]
            mx=pos

    if pos==-1:
        pos=obj[t][0]
    return len(S)*(result-1)+pos+1
print(solve())
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
        

obj = defaultdict(lambda: 1)

N=int(input())
ANA=[]
L=[]
for i in range(N):
    k="".join(sorted([x for x in input()]))
    if k in L:
        obj[k]+=1
    else:
        L.append(k)

result=0
for i in obj.values():
    if i and i-1:
        result+=i*(i-1)/2
    
print(int(result))


Fixed submission:
from collections import defaultdict
        

obj = defaultdict(lambda: 1)

N=int(input())
ANA=[]
L=set([])
for i in range(N):
    k="".join(sorted([x for x in input()]))
    if k in L:
        obj[k]+=1
    else:
        L.add(k)

result=0
for i in obj.values():
    if i and i-1:
        result+=i*(i-1)/2
    
print(int(result))

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

obj = defaultdict(lambda: 1)

N=int(input())
ANA=[]
L=[]
for i in range(N):
    k=sorted([x for x in input()])
    if k in L:
        obj["".join(k)]+=1
    else:
        L.append(k)

result=0
for i in obj.values():
    if i and i-1:
        result+=i*(i-1)/2
    
print(int(result))


Fixed submission:
from collections import defaultdict
        

obj = defaultdict(lambda: 1)

N=int(input())
ANA=[]
L=set([])
for i in range(N):
    k="".join(sorted([x for x in input()]))
    if k in L:
        obj[k]+=1
    else:
        L.add(k)

result=0
for i in obj.values():
    if i and i-1:
        result+=i*(i-1)/2
    
print(int(result))

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

obj = defaultdict(lambda: 1)

N=int(input())
ANA=[]
L=[]
for i in range(N):
    k=sorted([x for x in input()])
    if k in L:
        obj[L.index(k)]+=1
    else:
        L.append(k)

result=0
for i in obj.values():
    if i and i-1:
        result+=i*(i-1)/2
    
print(int(result))


Fixed submission:
from collections import defaultdict
        

obj = defaultdict(lambda: 1)

N=int(input())
ANA=[]
L=set([])
for i in range(N):
    k="".join(sorted([x for x in input()]))
    if k in L:
        obj[k]+=1
    else:
        L.add(k)

result=0
for i in obj.values():
    if i and i-1:
        result+=i*(i-1)/2
    
print(int(result))
Buggy python submission (verdict: Time Limit Exceeded):
N,M=(int(x) for x in input().split())
L=[]
D=[0]*M

for i in range(N):
    L.append(tuple(int(x) for x in input().split()))

L = sorted(L, key=lambda x:-x[1])
pay=0
mn=-1
for ab in L:
    flag=True
    if ab[0]<=M and mn<M-ab[0]:
        i=0
        while True:
            if M-ab[0]-i<0:
                break
            if mn==M-ab[0]-i:
                break
            if D[M-ab[0]-i]==0:
                D[M-ab[0]-i]+=1
                pay+=ab[1]
                flag=False
                break
            else:
                i+=D[M-ab[0]-i]

        if flag:
            mn=M-ab[0]
            
print(pay)


Fixed submission:
N,M=(int(x) for x in input().split())
L=[]
D=[0]*M

for i in range(N):
    L.append(tuple(int(x) for x in input().split()))

L = sorted(L, key=lambda x:-x[1])
pay=0
mn=-1
for ab in L:
    flag=True
    if ab[0]<=M and mn<M-ab[0]:
        i=0
        while True:
            if M-ab[0]-i<0:
                break
            if mn>M-ab[0]-i:
                break
            D[M-ab[0]-i]+=1
            if D[M-ab[0]-i]==1:
                pay+=ab[1]
                flag=False
                break
            else:
                if i==1:
                    i+=1
                else:
                    i+=D[M-ab[0]-i]-1
            
        if flag:
            mn=M-ab[0]
            
print(pay)

Buggy python submission (verdict: Time Limit Exceeded):
N,M=(int(x) for x in input().split())
L=[]
D=[0]*M

for i in range(N):
    L.append(tuple(int(x) for x in input().split()))

L = sorted(L, key=lambda x:-x[1])
pay=0
for ab in L:
    if ab[0]<=M:
        for i in range(M-ab[0]+1):
            if D[M-ab[0]-i]==0:
                D[M-ab[0]-i]=1
                pay+=ab[1]
                break

print(pay)


Fixed submission:
N,M=(int(x) for x in input().split())
L=[]
D=[0]*M

for i in range(N):
    L.append(tuple(int(x) for x in input().split()))

L = sorted(L, key=lambda x:-x[1])
pay=0
mn=-1
for ab in L:
    flag=True
    if ab[0]<=M and mn<M-ab[0]:
        i=0
        while True:
            if M-ab[0]-i<0:
                break
            if mn>M-ab[0]-i:
                break
            D[M-ab[0]-i]+=1
            if D[M-ab[0]-i]==1:
                pay+=ab[1]
                flag=False
                break
            else:
                if i==1:
                    i+=1
                else:
                    i+=D[M-ab[0]-i]-1
            
        if flag:
            mn=M-ab[0]
            
print(pay)
Buggy python submission (verdict: Time Limit Exceeded):
S=int(input())
X1=0
Y1=0

if S<=10**9:
    X2=0
    Y2=1
    X3=S
    Y3=0
elif S%10**9==0:
    X2=0
    Y2=S//10**9
    X3=10**9
    Y3=0
else:
    t=S%(10**9)
    A=10**9-t#x2 , y3
    v=(S+A)//10**9#x3=10**9 , y2=v
    K=A
    while A%2==0:
        A//=2
        if A<=10**9:
            X2=K//A
            Y3=A
        
    i=3
    while True:
        if A==1:
            X2=1
            Y3=1
            break
        
        if A%i==0:
            A//=i
            if A<=10**9:
                X2=K//A
                Y3=A
                break
            
        else:
            i+=2
        
    X3=10**9
    Y2=v
    
L=[X1,Y1,X2,Y2,X3,Y3]
print(" ".join([str(x) for x in L]))


Fixed submission:
S=int(input())
X1=0
Y1=0
flag=True
if S<=10**9:
    X2=0
    Y2=1
    X3=S
    Y3=0
elif S%10**9==0:
    X2=0
    Y2=S//10**9
    X3=10**9
    Y3=0
else:
    t=S%(10**9)
    A=10**9-t#x2 , y3
    v=(S+A)//10**9#x3=10**9 , y2=v
    
    K=A
    if A<=10**9:
        X2=1
        Y3=A
        flag=False
        
    if flag:
        while A%2==0:
            A//=2
            if A<=10**9:
                X2=K//A
                Y3=A
            
        i=3
        while True:
            if A%i==0:
                A//=i
                if A<=10**9:
                    X2=K//A
                    Y3=A
                    break
                
            else:
                i+=2
    
    X3=10**9
    Y2=v
    
L=[X1,Y1,X2,Y2,X3,Y3]
print(" ".join([str(x) for x in L]))

Buggy python submission (verdict: Time Limit Exceeded):
S=int(input())
X1=0
Y1=0

if S<=10**9:
    X2=0
    Y2=1
    X3=S
    Y3=0
elif S%10**9==0:
    X2=0
    Y2=S//10**9
    X3=10**9
    Y3=0
else:
    t=S%(10**9)
    A=10**9-t#x2 , y3
    v=(S+A)//10**9#x3=10**9 , y2=v

    K=A
    while A%2==0:
        A//=2
        if A<=10**9:
            X2=K//A
            Y3=A
        
    i=3
    while True:
        if A%i==0:
            A//=i
            if A<=10**9:
                X2=K//A
                Y3=A
                break
        else:
            i+=2

    X3=10**9
    Y2=v
    
L=[X1,Y1,X2,Y2,X3,Y3]
print(" ".join([str(x) for x in L]))


Fixed submission:
S=int(input())
X1=0
Y1=0
flag=True
if S<=10**9:
    X2=0
    Y2=1
    X3=S
    Y3=0
elif S%10**9==0:
    X2=0
    Y2=S//10**9
    X3=10**9
    Y3=0
else:
    t=S%(10**9)
    A=10**9-t#x2 , y3
    v=(S+A)//10**9#x3=10**9 , y2=v
    
    K=A
    if A<=10**9:
        X2=1
        Y3=A
        flag=False
        
    if flag:
        while A%2==0:
            A//=2
            if A<=10**9:
                X2=K//A
                Y3=A
            
        i=3
        while True:
            if A%i==0:
                A//=i
                if A<=10**9:
                    X2=K//A
                    Y3=A
                    break
                
            else:
                i+=2
    
    X3=10**9
    Y2=v
    
L=[X1,Y1,X2,Y2,X3,Y3]
print(" ".join([str(x) for x in L]))
Buggy python submission (verdict: Runtime Error):
N,D=[int(x) for x in input().split()]
if( N/D < N- D*2){
 print(int(N/D)) 
}else{
 print(int(N/D)+1)
}


Fixed submission:
import math
def Solve():
    N,D=[int(x) for x in input().split()]
    return math.ceil(N/(D*2+1))
print(Solve())

Buggy python submission (verdict: Runtime Error):
N,D=[int(x) for x in input().split()]
if( N/D < N- D*2){
 console.log(Math.floor(N/D)) 
}else{
 console.log(Math.floor(N/D)+1)
}

Fixed submission:
import math
def Solve():
    N,D=[int(x) for x in input().split()]
    return math.ceil(N/(D*2+1))
print(Solve())
Buggy python submission (verdict: Time Limit Exceeded):
import math
import bisect

import sys
input = sys.stdin.readline

def Solve():
    L=[]
    N=int(input())
    for i in range(N):
        L.append(int(input()))
    

    col=1
    K=[]
    for i,a in enumerate(L):
        if i==0:
            K.append(a)
            continue
        pos=bisect.bisect_left(K,a)
        if pos==0:
            col+=1
            K=[a]+K
        else:
            K[pos-1]=a

    return col



print(Solve())




Fixed submission:
import math
import bisect
from collections import deque
import sys
input = sys.stdin.readline


def Solve():
    L=[]
    N=int(input())
    for i in range(N):
        L.append(int(input()))

    col=1
    K=deque()
    
    
    for i,a in enumerate(L):
        if i==0:
            K.append(a)
            continue
        pos=bisect.bisect_left(K,a)
        if pos==0:
            col+=1
            K.appendleft(a)
        else:
            K[pos-1]=a

    return col



print(Solve())
Buggy python submission (verdict: Runtime Error):
import collections
LX=[]
LY=[]
N=int(input())
for i in range(N):
    x,y=(int(t) for t in input().split())
    LX.append(x)
    LY.append(y)

LLX=[]
LLY=[]
for i,x1 in enumerate(LX):
    for j,x2 in enumerate(LX):
        if i==j:
            continue
        LLX.append(x2-x1)

for i,y1 in enumerate(LY):
    for j,y2 in enumerate(LY):
        if i==j:
            continue
        LLY.append(y2-y1)


LLL=[str(dx)+'&'+str(dy) for dx,dy in zip(LLX,LLY)]

print(N-collections.Counter(LLL).most_common(1)[0][1])


Fixed submission:
import collections
LX=[]
LY=[]
def Solve():
    N=int(input())
    for i in range(N):
        x,y=(int(t) for t in input().split())
        LX.append(x)
        LY.append(y)
        
    if N==1:
        return 1
    
    LLX=[]
    LLY=[]
    for i,x1 in enumerate(LX):
        for j,x2 in enumerate(LX):
            if i==j:
                continue
            LLX.append(x2-x1)

    for i,y1 in enumerate(LY):
        for j,y2 in enumerate(LY):
            if i==j:
                continue
            LLY.append(y2-y1)


    LLL=[str(dx)+'&'+str(dy) for dx,dy in zip(LLX,LLY)]

    return N-collections.Counter(LLL).most_common(1)[0][1]

print(Solve())
Buggy python submission (verdict: Runtime Error):
L=[]
L2=[]
for i in range(5):
    I=int(input())
    L.append(I)
    L2.append(I%10)

result=0
for i in L:
    result+=i
    if result%10==0:
        continue
    for j in range(10):
        result+=1
        if result%10==0:
            break

if min(L2)==0:
    for t in sorted(L2):
        if t==0:
            pass
        else:
            mn=t
            break
else:
    mn=min(L2)

print(result-(10-mn))


Fixed submission:
L=[]
L2=[]
for i in range(5):
    I=int(input())
    L.append(I)
    L2.append(I%10)

result=0
for i in L:
    result+=i
    if result%10==0:
        continue
    for j in range(10):
        result+=1
        if result%10==0:
            break

if max(L2)==0:
    print(sum(L))
else:
    if min(L2)==0:
        for t in sorted(L2):
            if t==0:
                pass
            else:
                mn=t
                break
    else:
        mn=min(L2)

    print(result-(10-mn))
Buggy python submission (verdict: Time Limit Exceeded):
def BFS(Bs,del_idx,result):
    if Bs==[1]:
        return result
    
    if del_idx!=None:
        del Bs[del_idx]

    for i,b in enumerate(Bs):
        if i+1==b:
            DBs=Bs.copy()
            result.append(i+1)
            out=BFS(DBs,i,result)
            if out:
                return out
            else:
                del result[-1]

    return None


def Solve():
    output=[]
    N=int(input())
    Bs=[int(x) for x in input().split()]
    return BFS(Bs,None,[])
        

        
result=Solve()
if result:
    result.reverse()
    for r in result:
        print(r)
else:
    print(-1)


Fixed submission:
def BFS(Bs,del_idx,result):
    if Bs==[1]:
        return result
    
    if del_idx!=None:
        del Bs[del_idx]


    for i,b in enumerate(Bs):
        if b>i+1:
            return None
        
    for i,b in enumerate(Bs):
        if i+1==b:
            DBs=Bs.copy()
            result.append(i+1)
            out=BFS(DBs,i,result)
            if out:
                return out
            else:
                del result[-1]

    return None


def Solve():
    output=[]
    N=int(input())
    Bs=[int(x) for x in input().split()]
    return BFS(Bs,None,[])
        

        
result=Solve()
if result:
    result.reverse()
    for r in result:
        print(r)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
_=input()
S=input()

"""
S=""
import random
AL=["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
for i in range(10):
    t=int(random.random()*20)
    S+=AL[t]
    print(AL[t])
    print(S)
print(S)
"""
obj={}
L=[]
r=1
for i in S:
    if i in L:
        obj[S[i]]+=1
        r=r*(1+1/(2**obj[i]))
    else:
        r*=2
        obj[i]=0
        L.append(i)

    if r>(10**9+7):
        r-=(10**9+7)
        
print(r-1)


Fixed submission:
N=int(input())
S=input()
R=""
L=[]
obj={}
for s in S:
    if s not in L:
        R+=s
        L.append(s)
        obj[s]=1
    else:
        obj[s]+=1

out=1
for a in obj.keys():
    out*=(obj[a]+1)
    if out>10**9+7:
        out=out%(10**9+7)
print(out-1)

Buggy python submission (verdict: Runtime Error):
_=input()
S=input()
L=[]
r=1
for i in range(len(S)):
    if S[i] in L:
        r=int(r*(3/2))
    else:
        r*=2
        L.append(S[i])

print((r-1)%(10**9+7))


Fixed submission:
N=int(input())
S=input()
R=""
L=[]
obj={}
for s in S:
    if s not in L:
        R+=s
        L.append(s)
        obj[s]=1
    else:
        obj[s]+=1

out=1
for a in obj.keys():
    out*=(obj[a]+1)
    if out>10**9+7:
        out=out%(10**9+7)
print(out-1)
Buggy python submission (verdict: Runtime Error):
A,B,C=(int() for x in input().split())
print(min(C,A//B))

Fixed submission:
A,B,C=[int(x) for x in input().split()]
print(min(int(B/A),C))
Buggy python submission (verdict: Runtime Error):
N=int(input())
LA=[0]*N
LD=[0]*N
for i in range(N):
    A,B=input().split()
    LA[i]=int(A)
    LD[i]=int(A)+int(B)

isRunned=True
while(isRunned):
    isRunned=False
    for i in range(N-1):
        if LD[i]<LD[i+1]:    
            LD[i],LD[i+1]=LD[i+1],LD[i]
            LA[i],LA[i+1]=LA[i+1],LA[i]
            isRunned=True
        

print(sum(LA[::2])-(sum(LD[1::2])-sum(LA[1::2])))


Fixed submission:
N,A,B=input().split()
N=int(N)
A=int(A)
B=int(B)
if A+B-N<0:
    print(str(min(A,B))+" 0")
else:
    print(str(min(A,B))+" "+str(A+B-N))

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

PA=0
PB=0

LD=[0]*N
for i in range(N):
    LD[i]=LA[i]+LB[i]

isRunned=True
while(isRunned):
    isRunned=False
    for i in range(N-1):
        if LD[i]<LD[i+1]:
            LD[i],LD[i+1]=LD[i+1],LD[i]
            LA[i],LA[i+1]=LA[i+1],LA[i]
            LB[i],LB[i+1]=LB[i+1],LB[i]
            isRunned=True
        

print(sum(LA[::2])-sum(LB[1::2]))


Fixed submission:
N,A,B=input().split()
N=int(N)
A=int(A)
B=int(B)
if A+B-N<0:
    print(str(min(A,B))+" 0")
else:
    print(str(min(A,B))+" "+str(A+B-N))

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

PA=0
PB=0

LD=[0]*N
for i in range(N):
    LD[i]=LA[i]+LB[i]


SLD=sorted(LD)
SLD.reverse()
if N%2==0:
    for i in range(0,N,2):
        PA+=LA[LD.index(SLD[i])]
        PB+=LB[LD.index(SLD[i+1])]
else:
    for i in range(0,N-1,2):
        PA+=LA[LD.index(SLD[i])]
        PB+=LB[LD.index(SLD[i+1])]

    PA+=LA[LD.index(SLD[N-1])]

print(PA-PB)


Fixed submission:
N,A,B=input().split()
N=int(N)
A=int(A)
B=int(B)
if A+B-N<0:
    print(str(min(A,B))+" 0")
else:
    print(str(min(A,B))+" "+str(A+B-N))
Buggy python submission (verdict: Runtime Error):
import sys
N=int(sys.stdin.readline())
H=list(map(int,sys.stdin.readline().split()))
dp[1]=abs(H[0]-H[1])
for i in range(2,N):
    dp[i]=min(dp[i-1]+abs(H[i-1]-H[i]),dp[i-2]+abs(H[i-2]-H[i]))
print(dp[-1])


Fixed submission:
import sys
N=int(sys.stdin.readline())
H=list(map(int,sys.stdin.readline().split()))

dp=[0]*N

dp[1]=abs(H[0]-H[1])
for i in range(2,N):
    dp[i]=min(dp[i-1]+abs(H[i-1]-H[i]),dp[i-2]+abs(H[i-2]-H[i]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)
N=int(sys.stdin.readline())
H=list(map(int,sys.stdin.readline().split()))

dp=[0]*N
def rec(i):
    if dp[i]:
        return dp[i]
    if i==N-1:
        return 0
    elif i==N-2:
        return abs(H[i]-H[i+1])

    o=min(rec(i+1)+abs(H[i]-H[i+1]),rec(i+2)+abs(H[i]-H[i+2]))
    dp[i]=o
    return o
print(rec(0))


Fixed submission:
import sys
N=int(sys.stdin.readline())
H=list(map(int,sys.stdin.readline().split()))

dp=[0]*N

dp[1]=abs(H[0]-H[1])
for i in range(2,N):
    dp[i]=min(dp[i-1]+abs(H[i-1]-H[i]),dp[i-2]+abs(H[i-2]-H[i]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)
N=int(sys.stdin.readline())
H=list(map(int,sys.stdin.readline().split()))

dp=[0]*N
def rec(i):
    if dp[i]:
        return dp[i]
    if i==N-1:
        return 0
    elif i==N-2:
        return abs(H[i]-H[i+1])

    o=min(rec(i+1)+abs(H[i]-H[i+1]),rec(i+2)+abs(H[i]-H[i+2]))
    dp[i]=o
    return o
print(rec(0))


Fixed submission:
import sys
N=int(sys.stdin.readline())
H=list(map(int,sys.stdin.readline().split()))

dp=[0]*N

dp[1]=abs(H[0]-H[1])
for i in range(2,N):
    dp[i]=min(dp[i-1]+abs(H[i-1]-H[i]),dp[i-2]+abs(H[i-2]-H[i]))
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
import sys
N=int(sys.stdin.readline())
H=list(map(int,sys.stdin.readline().split()))

dp=[0]*N
def rec(i):
    if i==N-1:
        return 0
    elif i==N-2:
        return abs(H[i]-H[i+1])
    return min(rec(i+1)+abs(H[i]-H[i+1]),rec(i+2)+abs(H[i]-H[i+2]))
print(rec(0))

Fixed submission:
import sys
N=int(sys.stdin.readline())
H=list(map(int,sys.stdin.readline().split()))

dp=[0]*N

dp[1]=abs(H[0]-H[1])
for i in range(2,N):
    dp[i]=min(dp[i-1]+abs(H[i-1]-H[i]),dp[i-2]+abs(H[i-2]-H[i]))
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
N,K=list(map(int,sys.stdin.readline().split()))
H=list(map(int,sys.stdin.readline().split()))

dp=[0]*N

for i in range(1,N):
    L=[]
    for j in range(max(0,i-K),i):
        c=abs(H[j]-H[i])
        L.append(dp[j]+c)
    
    dp[i]=min(L)
print(dp[-1])

Fixed submission:
import sys
N,K=list(map(int,sys.stdin.readline().split()))
H=list(map(int,sys.stdin.readline().split()))

dp=[0]*N

for i in range(1,N):
    mn=10**9
    for j in range(max(0,i-K),i):
        mn=min(mn,dp[j]+abs(H[j]-H[i]))

    dp[i]=mn

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)
N,K=list(map(int,sys.stdin.readline().split()))
H=list(map(int,sys.stdin.readline().split()))

dp=[0]*N
def rec(i):
    if dp[i]:
        return dp[i]
    if i==N-1:
        return 0
    L=[]
    for k in range(i+1,min(i+K+1,N)):
        L.append(rec(k)+abs(H[i]-H[k]))

    dp[i]=min(L)
    return min(L)

print(rec(0))

Fixed submission:
import sys
N,K=list(map(int,sys.stdin.readline().split()))
H=list(map(int,sys.stdin.readline().split()))

dp=[0]*N

for i in range(1,N):
    mn=10**9
    for j in range(max(0,i-K),i):
        mn=min(mn,dp[j]+abs(H[j]-H[i]))

    dp[i]=mn

print(dp[-1])
Buggy python submission (verdict: Runtime Error):
import numpy as np
import sys
def solve():
    N=int(sys.stdin.readline())
    dp=np.zeros((3,N)).astype('int64')
    for i in range(N):
        a,b,c=list(map(int,sys.stdin.readline().split()))
        if i:
            dp[0,i]=max(dp[1,i-1]+a,dp[2,i-1]+a)
            dp[1,i]=max(dp[0,i-1]+b,dp[2,i-1]+b)
            dp[2,i]=max(dp[1,i-1]+c,dp[0,i-1]+c)
        else:
            dp[0,i]=a
            dp[1,i]=b
            dp[2,i]=c

    return np.max(dp[:,N-1])
    
if __name__ == '__main__':
    print(solve())

Fixed submission:
import numpy as np
import sys
def solve():
    N=int(sys.stdin.readline())
    dp=np.zeros((3,N)).astype('int64')
    for i in range(N):
        a,b,c=list(map(int,sys.stdin.readline().split()))
        if i:
            dp[0,i]=max(dp[1,i-1]+a,dp[2,i-1]+a)
            dp[1,i]=max(dp[0,i-1]+b,dp[2,i-1]+b)
            dp[2,i]=max(dp[1,i-1]+c,dp[0,i-1]+c)
        else:
            dp[0,i]=a
            dp[1,i]=b
            dp[2,i]=c

    return np.max(dp[:,N-1])
    
if __name__ == '__main__':
    print(solve())