Buggy python submission (verdict: Runtime Error):
def t118C():
    N = int(input())
    A = [int(input()) for i in range(N)]
    A.sort()
    AFromMinimum = A
    AFromMaxim = A[::-1]
    ans = 0
    if N % 2 == 0:
        ans = -2 * sum(AFromMinimum[:N // 2]) + 2 * sum(AFromMaxim[:N // 2]) + AFromMinimum[N // 2] - AFromMaxim[n // 2]
    else:
        c = (N - 1) // 2
        tmp1 = -2 * sum(A[:c]) + 2 * sum(A[c + 2:]) + A[c] + A[c + 1]
        tmp2 = -2 * sum(A[:c - 1]) + 2 * sum(A[c + 1:]) - A[c - 1] - A[c]
        ans = max(tmp1, tmp2)
    print(ans)
t118C()

Fixed submission:
def t118C():
    N = int(input())
    A = [int(input()) for i in range(N)]
    A.sort()
    AFromMinimum = A
    AFromMaxim = A[::-1]
    ans = 0
    if N % 2 == 0:
        ans = -2 * sum(AFromMinimum[:N // 2]) + 2 * sum(AFromMaxim[:N // 2]) + AFromMinimum[N // 2 - 1] - AFromMaxim[N // 2 - 1]
    else:
        c = (N - 1) // 2
        tmp1 = -2 * sum(A[:c]) + 2 * sum(A[c + 2:]) + A[c] + A[c + 1]
        tmp2 = -2 * sum(A[:c - 1]) + 2 * sum(A[c + 1:]) - A[c - 1] - A[c]
        ans = max(tmp1, tmp2)
    print(ans)
t118C()

Buggy python submission (verdict: Runtime Error):
def t118C():
    N = int(input())
    A = [int(input()) for i in range(N)]
    A.sort()
    anslist = []
    ans = 0
    tmplist = []
    tmplist2 = []

    up = 0
    down = N - 1
    checklist = [0 for i in range(N)]
    while True:
        if checklist[up] == 1:
            break
        tmplist.append(up)
        checklist[up] = 1
        up += 1

        if checklist[down] == 1:
            break
        tmplist2.append(down)
        checklist[down] = 1
        down -= 1

        if checklist[down] == 1:
            break
        tmplist.append(down)
        checklist[down] = 1
        down -= 1

        if checklist[up] == 1:
            break
        tmplist2.append(up)
        checklist[up] = 1
        up += 1

    for i in range(len(tmplist)):
        tmplist[i] = A[tmplist[i]]

    for i in range(len(tmplist2)):
        tmplist2[i] = A[tmplist2[i]]

    #print(tmplist, tmplist2)
    for i in range(1, len(tmplist)):
        ans += abs(tmplist[i] - tmplist[i - 1])
    for i in range(1, len(tmplist2)):
        ans += abs(tmplist2[i] - tmplist2[i - 1])
    ans += abs(tmplist[0] - tmplist2[0])
    ans2 = ans
    if n >= 2:
        ans2 -= abs(tmplist[-1] - tmplist[-2])
        ans2 -= abs(tmplist2[-1] - tmplist2[-2])
        ans2 += abs(tmplist[-1] - tmplist2[-2])
        ans2 += abs(tmplist[-2] - tmplist2[-1])
    #print(ans2)
    print(max(ans, ans2))
t118C()

Fixed submission:
def t118C():
    N = int(input())
    A = [int(input()) for i in range(N)]
    A.sort()
    AFromMinimum = A
    AFromMaxim = A[::-1]
    ans = 0
    if N % 2 == 0:
        ans = -2 * sum(AFromMinimum[:N // 2]) + 2 * sum(AFromMaxim[:N // 2]) + AFromMinimum[N // 2 - 1] - AFromMaxim[N // 2 - 1]
    else:
        c = (N - 1) // 2
        tmp1 = -2 * sum(A[:c]) + 2 * sum(A[c + 2:]) + A[c] + A[c + 1]
        tmp2 = -2 * sum(A[:c - 1]) + 2 * sum(A[c + 1:]) - A[c - 1] - A[c]
        ans = max(tmp1, tmp2)
    print(ans)
t118C()

Buggy python submission (verdict: Runtime Error):
def t118C():
    N = int(input())
    A = [int(input()) for i in range(N)]
    A.sort()
    anslist = []
    ans = 0
    tmplist = []
    tmplist2 = []

    up = 0
    down = N - 1
    checklist = [0 for i in range(N)]
    while True:
        if checklist[up] == 1:
            break
        tmplist.append(up)
        checklist[up] = 1
        up += 1

        if checklist[down] == 1:
            break
        tmplist2.append(down)
        checklist[down] = 1
        down -= 1

        if checklist[down] == 1:
            break
        tmplist.append(down)
        checklist[down] = 1
        down -= 1

        if checklist[up] == 1:
            break
        tmplist2.append(up)
        checklist[up] = 1
        up += 1

    for i in range(len(tmplist)):
        tmplist[i] = A[tmplist[i]]

    for i in range(len(tmplist2)):
        tmplist2[i] = A[tmplist2[i]]

    #print(tmplist, tmplist2)
    for i in range(1, len(tmplist)):
        ans += abs(tmplist[i] - tmplist[i - 1])
    for i in range(1, len(tmplist2)):
        ans += abs(tmplist2[i] - tmplist2[i - 1])
    ans += abs(tmplist[0] - tmplist2[0])
    ans2 = ans
    ans2 -= abs(tmplist[-1] - tmplist[-2])
    ans2 -= abs(tmplist2[-1] - tmplist2[-2])
    ans2 += abs(tmplist[-1] - tmplist2[-2])
    ans2 += abs(tmplist[-2] - tmplist2[-1])
    #print(ans2)
    print(max(ans, ans2))
t118C()

Fixed submission:
def t118C():
    N = int(input())
    A = [int(input()) for i in range(N)]
    A.sort()
    AFromMinimum = A
    AFromMaxim = A[::-1]
    ans = 0
    if N % 2 == 0:
        ans = -2 * sum(AFromMinimum[:N // 2]) + 2 * sum(AFromMaxim[:N // 2]) + AFromMinimum[N // 2 - 1] - AFromMaxim[N // 2 - 1]
    else:
        c = (N - 1) // 2
        tmp1 = -2 * sum(A[:c]) + 2 * sum(A[c + 2:]) + A[c] + A[c + 1]
        tmp2 = -2 * sum(A[:c - 1]) + 2 * sum(A[c + 1:]) - A[c - 1] - A[c]
        ans = max(tmp1, tmp2)
    print(ans)
t118C()