Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())
    A=[int(input()) for x in range(N)]

    A.sort()
    s = 0
    e = N - 1
    L = A[0]
    R = A[e]
    ret1 = R - L
    while True:
        ss = s + 1
        ee = e + 1

        b = max(abs(L - A[ss]), abs(R - A[ss])) > max(abs(L - A[ee]), abs(R - A[ee]))

        if b:
            s += 1
            if abs(L - A[s]) < abs(R - A[s]):
                ret1 += abs(R - A[s])
                R = A[s]
            else:
                ret1 += abs(L - A[s])
                L = A[s]
        else:
            e -= 1
            if s == e: break
            if abs(L - A[e]) < abs(R - A[e]):
                ret1 += abs(R - A[e])
                R = A[e]
            else:
                ret1 += abs(L - A[e])
                L = A[e]
        if s == e: break

    # 出力
    print("{}".format(ret1))


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    N = int(input())
    A=[int(input()) for x in range(N)]

    A.sort()
    s = 0
    e = N - 1
    L = A[0]
    R = A[e]
    ret1 = R - L
    while True:
        ss = s + 1
        ee = e - 1

        b = max(abs(L - A[ss]), abs(R - A[ss])) > max(abs(L - A[ee]), abs(R - A[ee]))

        if b:
            s += 1
            if abs(L - A[s]) < abs(R - A[s]):
                ret1 += abs(R - A[s])
                R = A[s]
            else:
                ret1 += abs(L - A[s])
                L = A[s]
        else:
            e -= 1
            if s == e: break
            if abs(L - A[e]) < abs(R - A[e]):
                ret1 += abs(R - A[e])
                R = A[e]
            else:
                ret1 += abs(L - A[e])
                L = A[e]
        if s == e: break

    # 出力
    print("{}".format(ret1))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():

    N = int(input())

    A.sort()
    s=0
    e=N-1
    L=A[0]
    R=A[e]
    ret1 = R-L
    while True:
        ss=s+1
        ee=e+1

        b=max(abs(L-A[s]),abs(R-A[s])) > max(abs(L-A[e]),abs(R-A[e]))

        if b:
            s+=1
            if abs(L-A[s]) < abs(R-A[s]):
                ret1 += abs(R-A[s])
                R=A[s]
            else:
                ret1 += abs(L-A[s])
                L=A[s]
        else:
            e-=1
            if s == e: break
            if abs(L-A[e]) < abs(R-A[e]):
                ret1 += abs(R-A[e])
                R=A[e]
            else:
                ret1 += abs(L-A[e])
                L=A[e]
        if s==e: break



    # 出力
    print("{}".format(ret1))

if __name__ == '__main__':
    main()


Fixed submission:
def main():
    N = int(input())
    A=[int(input()) for x in range(N)]

    A.sort()
    s = 0
    e = N - 1
    L = A[0]
    R = A[e]
    ret1 = R - L
    while True:
        ss = s + 1
        ee = e - 1

        b = max(abs(L - A[ss]), abs(R - A[ss])) > max(abs(L - A[ee]), abs(R - A[ee]))

        if b:
            s += 1
            if abs(L - A[s]) < abs(R - A[s]):
                ret1 += abs(R - A[s])
                R = A[s]
            else:
                ret1 += abs(L - A[s])
                L = A[s]
        else:
            e -= 1
            if s == e: break
            if abs(L - A[e]) < abs(R - A[e]):
                ret1 += abs(R - A[e])
                R = A[e]
            else:
                ret1 += abs(L - A[e])
                L = A[e]
        if s == e: break

    # 出力
    print("{}".format(ret1))


if __name__ == '__main__':
    main()