Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n,k=map(int,input().split())
    X=list(map(int,input().split()))
    cnt=0
    Xp,Xz,Xm=0,False,0
    for x in X:
        if x<0:
            cnt+=1
        elif x==0:
            Xm=X[:cnt]
            Xz=True
            Xp=X[cnt+1:]
        else:
            Xm=X[:cnt]
            Xp=X[cnt:]
    if Xp==0:
      Xm=X
      Xp=[]
    lp,lm=len(Xp),len(Xm)

    if Xz:
        k-=1
    if k==0:
      print(0)
      exit()
      
    ans=10**9
    if k<=lp:
        ans=min(ans,Xp[k-1])
    if k<=lm:
        ans=min(ans,-Xm[-k])

    for i in range(lp):
        j=k-i-1
        if 0<j<=lm:
            ans=min(ans,Xp[i]*2-Xm[-j])
        else:
            continue
        
    for i in range(lm,0,-1):
        j=k-i-1
        if 0<=j<lp:
            ans=min(ans,Xm[-i]*(-2)+Xp[j])
        else:
            continue
    print(ans)
   
if __name__=='__main__':
    main()

Fixed submission:
def main():
    import numpy as np
    n,k=map(int,input().split())
    X=list(map(int,input().split()))
    X=np.array(X)
    Xp,Xz,Xm=X[X>0],X[X==0],X[X<0]
    lp,lm=len(Xp),len(Xm)

    if 0 in Xz:
        k-=1
    if k==0:
      print(0)
      exit()
      
    ans=10**9
    if k<=lp:
        ans=min(ans,Xp[k-1])
    if k<=lm:
        ans=min(ans,-Xm[-k])

    for i in range(lp):
        j=k-i-1
        if 0<j<=lm:
            ans=min(ans,Xp[i]*2-Xm[-j])
        else:
            continue
        
    for i in range(lm,0,-1):
        j=k-i-1
        if 0<=j<lp:
            ans=min(ans,Xm[-i]*(-2)+Xp[j])
        else:
            continue
    print(ans)
   
if __name__=='__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n,k=map(int,input().split())
    X=list(map(int,input().split()))
    cnt=0
    Xp,Xz,Xm=0,False,0
    for x in X:
        if x<0:
            cnt+=1
        elif x==0:
            Xm=X[:cnt]
            Xz=True
            Xp=X[cnt+1:]
        else:
            Xm=X[:cnt]
            Xp=X[cnt:]
    if Xp==0:
      Xm=X
      Xp=[]
    lp,lm=len(Xp),len(Xm)

    if Xz:
        k-=1
    if k==0:
      print(0)
      exit()
      
    ans=10**9
    if k<=lp:
        ans=min(ans,Xp[k-1])
    if k<=lm:
        ans=min(ans,-Xm[-k])

    for i in range(lp):
        j=k-i-1
        if 0<j<=lm:
            ans=min(ans,Xp[i]*2-Xm[-j])
        else:
            continue
        
    for i in range(lm,0,-1):
        j=k-i-1
        if 0<=j<lp:
            ans=min(ans,Xm[-i]*(-2)+Xp[j])
        else:
            continue
    print(ans)
   
if __name__=='__main__':
    main()

Fixed submission:
def main():
    import numpy as np
    n,k=map(int,input().split())
    X=list(map(int,input().split()))
    X=np.array(X)
    Xp,Xz,Xm=X[X>0],X[X==0],X[X<0]
    lp,lm=len(Xp),len(Xm)

    if 0 in Xz:
        k-=1
    if k==0:
      print(0)
      exit()
      
    ans=10**9
    if k<=lp:
        ans=min(ans,Xp[k-1])
    if k<=lm:
        ans=min(ans,-Xm[-k])

    for i in range(lp):
        j=k-i-1
        if 0<j<=lm:
            ans=min(ans,Xp[i]*2-Xm[-j])
        else:
            continue
        
    for i in range(lm,0,-1):
        j=k-i-1
        if 0<=j<lp:
            ans=min(ans,Xm[-i]*(-2)+Xp[j])
        else:
            continue
    print(ans)
   
if __name__=='__main__':
    main()