Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N = input()
A = [int(input()) for i in range(N)]

A = sorted(A)
res = []
begin = 0
end = len(A) - 1
res = deque()
res.append(A[begin])
res.append(A[end])
begin += 1
end -= 1
for i in range(N - 2):
	l = [abs(res[0] - A[begin]), abs(res[0] - A[end]), abs(res[-1] - A[begin]), abs(res[-1] - A[end])]
	cand = l.index(max(l))
	if cand == 0:
		res.appendleft(A[begin])
		begin += 1
	elif cand == 1:
		res.appendleft(A[end])
		end -= 1
	elif cand == 2:
		res.append(A[begin])
		begin += 1
	elif cand == 3:
		res.append(A[end])
		end -= 1
sum_diff = 0
for i in range(N - 1):
	 sum_diff += abs(res[i] - res[i + 1])
print sum_diff


Fixed submission:
from collections import deque
N = input()
A = [int(input()) for i in range(N)]
coef = [2] * N
coef[0] = 1
coef[-1] = 1
coef1 = [coef[i] if i % 2 == 0 else coef[i] * -1 for i in range(N)]
coef2 = [coef[i] if i % 2 != 0 else coef[i] * -1 for i in range(N)]

A = sorted(A)
coef1 = sorted(coef1)
coef2 = sorted(coef2)
res1 = 0
for i in range(N):
	res1 += A[i] * coef1[i]
res2 = 0
for i in range(N):
	res2 += A[i] * coef2[i]
print max(res1, res2)

Buggy python submission (verdict: Runtime Error):
from collections import deque
N = input()
A = []


res = []
begin = 0
end = len(A) - 1
res = deque()
res.append(A[begin])
res.append(A[end])
begin += 1
end -= 1


Fixed submission:
from collections import deque
N = input()
A = [int(input()) for i in range(N)]
coef = [2] * N
coef[0] = 1
coef[-1] = 1
coef1 = [coef[i] if i % 2 == 0 else coef[i] * -1 for i in range(N)]
coef2 = [coef[i] if i % 2 != 0 else coef[i] * -1 for i in range(N)]

A = sorted(A)
coef1 = sorted(coef1)
coef2 = sorted(coef2)
res1 = 0
for i in range(N):
	res1 += A[i] * coef1[i]
res2 = 0
for i in range(N):
	res2 += A[i] * coef2[i]
print max(res1, res2)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N = input()
A = []
for i in range(N):
	a = input()
	A.append(a)

A = sorted(A)
res = []
begin = 0
end = len(A) - 1
res = deque()
res.append(A[begin])
res.append(A[end])
begin += 1
end -= 1
for i in range(N - 2):
	l = [abs(res[0] - A[begin]), abs(res[0] - A[end]), abs(res[-1] - A[begin]), abs(res[-1] - A[end])]
	cand = l.index(max(l))
	if cand == 0:
		res.appendleft(A[begin])
		begin += 1
	elif cand == 1:
		res.appendleft(A[end])
		end -= 1
	elif cand == 2:
		res.append(A[begin])
		begin += 1
	elif cand == 3:
		res.append(A[end])
		end -= 1
sum_diff = 0
for i in range(N - 1):
	 sum_diff += abs(res[i] - res[i + 1])
print sum_diff


Fixed submission:
from collections import deque
N = input()
A = [int(input()) for i in range(N)]
coef = [2] * N
coef[0] = 1
coef[-1] = 1
coef1 = [coef[i] if i % 2 == 0 else coef[i] * -1 for i in range(N)]
coef2 = [coef[i] if i % 2 != 0 else coef[i] * -1 for i in range(N)]

A = sorted(A)
coef1 = sorted(coef1)
coef2 = sorted(coef2)
res1 = 0
for i in range(N):
	res1 += A[i] * coef1[i]
res2 = 0
for i in range(N):
	res2 += A[i] * coef2[i]
print max(res1, res2)

Buggy python submission (verdict: Runtime Error):
from collections import deque
N = input()
A = []
for i in range(N):
	a = input()
	A.append(a)

A = sorted(A)
res = []
begin = 0
end = len(A) - 1
res = deque()
res.append(A[begin])
res.append(A[end])
begin+= 1
end -= 1
for i in range(N - 2):
	l = [abs(res[0] - A[begin]), abs(res[0] - A[end]), abs(res[-1] - A[begin]), abs(res[-1] - A[end])]
	cand = l.list(max(l))
	if cand == 0:
		res.appendleft(A[begin])
		begin += 1
	elif cand == 1:
		res.appendleft(A[end])
		end -= 1
	elif cand == 2:
		res.append(A[begin])
		begin += 1
	elif cand == 3:
		res.append(A[end])
		end -= 1
sum_diff = 0
for i in range(N - 1):
	 sum_diff += abs(res[i] - res[i + 1])
print sum_diff


Fixed submission:
from collections import deque
N = input()
A = [int(input()) for i in range(N)]
coef = [2] * N
coef[0] = 1
coef[-1] = 1
coef1 = [coef[i] if i % 2 == 0 else coef[i] * -1 for i in range(N)]
coef2 = [coef[i] if i % 2 != 0 else coef[i] * -1 for i in range(N)]

A = sorted(A)
coef1 = sorted(coef1)
coef2 = sorted(coef2)
res1 = 0
for i in range(N):
	res1 += A[i] * coef1[i]
res2 = 0
for i in range(N):
	res2 += A[i] * coef2[i]
print max(res1, res2)

Buggy python submission (verdict: Runtime Error):
import numpy as np
N = input()
A = []
for i in range(N):
	a = input()
	A.append(a)

A = sorted(A)
res = []
begin = 0
end = len(A) - 1
res = deque()
res.append(A[begin])
res.append(A[end])
begin+= 1
end -= 1
for i in range(N - 2):
	cand = np.argmax([abs(res[0] - A[begin]), abs(res[0] - A[end]), abs(res[-1] - A[begin]), abs(res[-1] - A[end])])
	if cand == 0:
		res.appendleft(A[begin])
		begin += 1
	elif cand == 1:
		res.appendleft(A[end])
		end -= 1
	elif cand == 2:
		res.append(A[begin])
		begin += 1
	elif cand == 3:
		res.append(A[end])
		end -= 1
sum_diff = 0
for i in range(N - 1):
	 sum_diff += abs(res[i] - res[i + 1])
print sum_diff


Fixed submission:
from collections import deque
N = input()
A = [int(input()) for i in range(N)]
coef = [2] * N
coef[0] = 1
coef[-1] = 1
coef1 = [coef[i] if i % 2 == 0 else coef[i] * -1 for i in range(N)]
coef2 = [coef[i] if i % 2 != 0 else coef[i] * -1 for i in range(N)]

A = sorted(A)
coef1 = sorted(coef1)
coef2 = sorted(coef2)
res1 = 0
for i in range(N):
	res1 += A[i] * coef1[i]
res2 = 0
for i in range(N):
	res2 += A[i] * coef2[i]
print max(res1, res2)

Buggy python submission (verdict: Runtime Error):
import numpy as np
from collections import deque
N = input()
A = []
for i in range(N):
	a = input()
	A.append(a)

A = sorted(A)
res = []
begin = 0
end = len(A) - 1
res = deque()
res.append(A[begin])
res.append(A[end])
begin+= 1
end -= 1
for i in range(N - 2):
	cand = np.argmax([abs(res[0] - A[begin]), abs(res[0] - A[end]), abs(res[-1] - A[begin]), abs(res[-1] - A[end])])
	if cand == 0:
		res.appendleft(A[begin])
		begin += 1
	elif cand == 1:
		res.appendleft(A[end])
		end -= 1
	elif cand == 2:
		res.append(A[begin])
		begin += 1
	elif cand == 3:
		res.append(A[end])
		end -= 1
sum_diff = 0
for i in range(N - 1):
	 sum_diff += abs(res[i] - res[i + 1])
print sum_diff


Fixed submission:
from collections import deque
N = input()
A = [int(input()) for i in range(N)]
coef = [2] * N
coef[0] = 1
coef[-1] = 1
coef1 = [coef[i] if i % 2 == 0 else coef[i] * -1 for i in range(N)]
coef2 = [coef[i] if i % 2 != 0 else coef[i] * -1 for i in range(N)]

A = sorted(A)
coef1 = sorted(coef1)
coef2 = sorted(coef2)
res1 = 0
for i in range(N):
	res1 += A[i] * coef1[i]
res2 = 0
for i in range(N):
	res2 += A[i] * coef2[i]
print max(res1, res2)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
from collections import deque
N = input()
A = []
for i in range(N):
	a = input()
	A.append(a)

A = sorted(A)
res = []
begin = 0
end = len(A) - 1
res = deque()
res.append(A[begin])
res.append(A[end])
begin+= 1
end -= 1
for i in range(N - 2):
	cand = np.argmax([abs(res[0] - A[begin]), abs(res[0] - A[end]), abs(res[-1] - A[begin]), abs(res[-1] - A[end])])
	if cand == 0:
		res.appendleft(A[begin])
		begin += 1
	elif cand == 1:
		res.appendleft(A[end])
		end -= 1
	elif cand == 2:
		res.append(A[begin])
		begin += 1
	elif cand == 3:
		res.append(A[end])
		end -= 1
sum_diff = 0
for i in range(N - 1):
	 sum_diff += abs(res[i] - res[i + 1])
print sum_diff


Fixed submission:
from collections import deque
N = input()
A = [int(input()) for i in range(N)]
coef = [2] * N
coef[0] = 1
coef[-1] = 1
coef1 = [coef[i] if i % 2 == 0 else coef[i] * -1 for i in range(N)]
coef2 = [coef[i] if i % 2 != 0 else coef[i] * -1 for i in range(N)]

A = sorted(A)
coef1 = sorted(coef1)
coef2 = sorted(coef2)
res1 = 0
for i in range(N):
	res1 += A[i] * coef1[i]
res2 = 0
for i in range(N):
	res2 += A[i] * coef2[i]
print max(res1, res2)