Problem p03227 (python)

Fixed submission:
S = input()

if len(S) == 2:
    print(S)
elif len(S) == 3:
    print(S[::-1])

Buggy submission (verdict: Runtime Error):
#coding:utf-8
import copy
N = int(input())
A_list = []
for i in range(N):
    A_list.append(int(input()) )

def calculate_x(list):
    len_list = len(list)
    sum = 0
    for i in range(len_list-1):
        sum = sum + abs(list[i]-list[i+1])
    return sum

A_list = sorted(A_list)

if N % 2 ==0: #even
    answer_list = []
    A_min_list = A_list[:int(N/2)-1]
    A_max_list = A_list[-int(N/2)+1:]
    for max, min in zip(A_max_list, A_min_list):
        answer_list.append(max)
        answer_list.append(min)
    answer_list.append(A_list[int(N/2)]) #min of max_list
    answer_list.insert(0,A_list[int(N/2)-1]) #max of min_list
    tmp = calculate_x(answer_list)
    print(tmp)

else: #odd
    answer_list = []
    A_min_list = A_list[:int((N-1)/2)-1] #0,1
    A_max_list = A_list[-int((N-1)/2)+1:] #5,6
    x1 = A_list[int((N-1)/2)-1] #2
    x2 = A_list[int((N-1)/2)]#3
    x3 = A_list[int((N-1)/2)+1]#4
    for max, min in zip(A_max_list, A_min_list):
        answer_list.append(max)
        answer_list.append(min)

    answer_list2 = copy.deepcopy(answer_list)
    max = 0
    answer_list2.append(x1)
    answer_list2.insert(0,x2)
    answer_list2.insert(0,x3)
    tmp = calculate_x(answer_list2)
    if tmp > max:
        max = tmp

    answer_list2 = copy.deepcopy(answer_list)
    answer_list2.append(x1)
    answer_list2.insert(0,x3)
    answer_list2.insert(0,x2)
    tmp = calculate_x(answer_list2)
    if tmp > max:
        max = tmp

    answer_list2 = copy.deepcopy(answer_list)
    answer_list2.append(x2)
    answer_list2.insert(0,x1)
    answer_list2.insert(0,x3)
    tmp = calculate_x(answer_list2)
    if tmp > max:
        max = tmp

    answer_list2 = copy.deepcopy(answer_list)
    answer_list2.append(x2)
    answer_list2.insert(0,x3)
    answer_list2.insert(0,x1)
    tmp = calculate_x(answer_list2)
    if tmp > max:
        max = tmp

    answer_list2 = copy.deepcopy(answer_list)
    answer_list2.append(x3)
    answer_list2.insert(0,x1)
    answer_list2.insert(0,x2)
    tmp = calculate_x(answer_list2)
    if tmp > max:
        max = tmp

    answer_list2 = copy.deepcopy(answer_list)
    answer_list2.append(x3)
    answer_list2.insert(0,x2)
    answer_list2.insert(0,x1)
    tmp = calculate_x(answer_list2)
    if tmp > max:
        max = tmp



    answer_list3 = []
    A_min_list = A_list[:int((N-1)/2)-1] #0,1
    A_max_list = A_list[-int((N-1)/2)+1:] #5,6
    x1 = A_list[int((N-1)/2)-1] #2
    x2 = A_list[int((N-1)/2)]#3
    x3 = A_list[int((N-1)/2)+1]#4
    for max, min in zip(A_max_list, A_min_list):
        answer_list3.append(min)
        answer_list3.append(max)

    answer_list4 = copy.deepcopy(answer_list3)
    answer_list4.append(x1)
    answer_list4.insert(0,x2)
    answer_list4.insert(0,x3)
    tmp = calculate_x(answer_list4)
    if tmp > max:
        max = tmp

    answer_list4 = copy.deepcopy(answer_list3)
    answer_list4.append(x1)
    answer_list4.insert(0,x3)
    answer_list4.insert(0,x2)
    tmp = calculate_x(answer_list4)
    if tmp > max:
        max = tmp

    answer_list4 = copy.deepcopy(answer_list3)
    answer_list4.append(x2)
    answer_list4.insert(0,x1)
    answer_list4.insert(0,x3)
    tmp = calculate_x(answer_list4)
    if tmp > max:
        max = tmp

    answer_list4 = copy.deepcopy(answer_list3)
    answer_list4.append(x2)
    answer_list4.insert(0,x3)
    answer_list4.insert(0,x1)
    tmp = calculate_x(answer_list4)
    if tmp > max:
        max = tmp

    answer_list4 = copy.deepcopy(answer_list3)
    answer_list4.append(x3)
    answer_list4.insert(0,x1)
    answer_list4.insert(0,x2)
    tmp = calculate_x(answer_list4)
    if tmp > max:
        max = tmp

    answer_list4 = copy.deepcopy(answer_list3)
    answer_list4.append(x3)
    answer_list4.insert(0,x2)
    answer_list4.insert(0,x1)
    tmp = calculate_x(answer_list4)
    if tmp > max:
        max = tmp
    print(max)