Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
a,b,c,d,e,f = map(int, input().split())

per = 0
ans = []

for i in range(f//(100*a) + 1):
    for j in range(f//(100*b) + 1):
        w = i * a * 100 + j * b * 100
        if w > f or w == 0:
            break
        for k in range((e * w//100)//c + 1):
            for l in range((e * w//100)//d + 1):
                if e * w//100 < c * k + d * l or w + c * k + d * l > f:
                    break
                now = 100 * (c*k+d*l) / (w+c*k+d*l)
                if per < now:
                    per = now
                    ans = [w+c*k+d*l, c*k+d*l]
if ans = []:
    print(100*a, 0)
else:
    print(ans[0], ans[1])



Fixed submission:
a,b,c,d,e,f = map(int, input().split())

per = 0
ans = []

for i in range(f//(100*a) + 1):
    for j in range(f//(100*b) + 1):
        w = i * a * 100 + j * b * 100
        if w > f or w == 0:
            break
        for k in range((e * w//100)//c + 1):
            for l in range((e * w//100)//d + 1):
                if e * w//100 < c * k + d * l or w + c * k + d * l > f:
                    break
                now = 100 * (c*k+d*l) / (w+c*k+d*l)
                if per < now:
                    per = now
                    ans = [w+c*k+d*l, c*k+d*l]
if ans == []:
    print(100*a, 0)
else:
    print(ans[0], ans[1])

Buggy python submission (verdict: Runtime Error):
a,b,c,d,e,f = map(int, input().split())

per = 0
ans = []

for i in range(f//(100*a) + 1):
    for j in range(f//(100*b) + 1):
        w = i * a * 100 + j * b * 100
        if w > f or w == 0:
            break
        for k in range((e * w//100)//c + 1):
            for l in range((e * w//100)//d + 1):
                if e * w//100 < c * k + d * l or w + c * k + d * l > f:
                    break
                now = 100 * (c*k+d*l) / (w+c*k+d*l)
                if per < now:
                    per = now
                    ans = [w+c*k+d*l, c*k+d*l]

print(ans[0], ans[1])



Fixed submission:
a,b,c,d,e,f = map(int, input().split())

per = 0
ans = []

for i in range(f//(100*a) + 1):
    for j in range(f//(100*b) + 1):
        w = i * a * 100 + j * b * 100
        if w > f or w == 0:
            break
        for k in range((e * w//100)//c + 1):
            for l in range((e * w//100)//d + 1):
                if e * w//100 < c * k + d * l or w + c * k + d * l > f:
                    break
                now = 100 * (c*k+d*l) / (w+c*k+d*l)
                if per < now:
                    per = now
                    ans = [w+c*k+d*l, c*k+d*l]
if ans == []:
    print(100*a, 0)
else:
    print(ans[0], ans[1])
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = [int(i) for i in input().split())

c = [0] * (10**5 + 1)

for i in a:
    c[i] += 1
    if i != 0 and i != 10 ** 5:
        c[i-1] += 1
        c[i+1] += 1
    elif i == 0:
        c[i+1] += 1
    else:
        c[i-1] += 1

print(max(c))

Fixed submission:
N = int(input())
a = [int(i) for i in input().split()]

c = [0] * (10**5 + 1)

for i in a:
    c[i] += 1
    if i != 0 and i != 10 ** 5:
        c[i-1] += 1
        c[i+1] += 1
    elif i == 0:
        c[i+1] += 1
    else:
        c[i-1] += 1

print(max(c))
Buggy python submission (verdict: Runtime Error):
N = str(input())
if N == N[::-1]
	print('Yes')
else
	print('No')

Fixed submission:
N = str(input())
if N == N[::-1]:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
N = int(input())
T = [int(input()) for i in range(N)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


if N == 1:
    print(T[0])
    exit()

now = lcm(T[0], T[1])
for i in range(1, N):
    now = lcm(now, T[i])

print(now)


Fixed submission:
N = str(input())
if N == N[::-1]:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
N = int(input())
T = [int(input()) for i in range(N)]

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b / gcd(a, b)

now = lcm(T[0], T[1])
for i in range(1, N):
    now = lcm(now, T[i])

print(now)


Fixed submission:
N = int(input())
T = [int(input()) for i in range(N)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


if N == 1:
    print(T[0])
    exit()

now = lcm(T[0], T[1])
for i in range(1, N):
    now = lcm(now, T[i])

print(now)

Buggy python submission (verdict: Runtime Error):
N = int(input())
T = [int(input()) for i in range(N)]

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

now = lcm(T[0], T[1])
for i in range(1, N):
    now = lcm(now, T[i])

print(now)


Fixed submission:
N = int(input())
T = [int(input()) for i in range(N)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


if N == 1:
    print(T[0])
    exit()

now = lcm(T[0], T[1])
for i in range(1, N):
    now = lcm(now, T[i])

print(now)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [int(input()) for i in range(N)]

num = 0
now = 0
been = set()
been.add(0)

while now != 1:
    now = a[now] - 1
    if now in been:
        num = -1
        break
    else:
        num += 1

print(num)

Fixed submission:
N = int(input())
a = [int(input()) for i in range(N)]

num = 0
now = 0
been = set()
been.add(0)

while now != 1:
    now = a[now] - 1
    if now in been:
        num = -1
        break
    else:
        been.add(now)
        num += 1

print(num)
Buggy python submission (verdict: Time Limit Exceeded):
N, Ma, Mb = map(int, input().split())

INF = 10 ** 18
dp = [[[INF] * (10*N+1) for _ in range(10*N+1)] for _ in range(N+1)]

dp[0][0][0] = 0
for i in range(N):
    a, b, c = map(int, input().split())
    for j in range(10*N+1-a):
        for k in range(10*N+1-b):
            dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k])
            dp[i+1][j+a][k+b] = min(dp[i+1][j+a][k+b], dp[i][j][k]+c)

ans = INF
for j in range(1, 10*N+1):
    if j * Ma > 10 * N  or j * Mb > 10 * N:
        break

    ans = min(ans, dp[N][j*Ma][j*Mb])

if ans == INF:
    ans = -1

print(ans)

Fixed submission:
N, Ma, Mb = map(int, input().split())

INF = 10 ** 18
dp = [[[INF] * (10*N+1) for _ in range(10*N+1)] for _ in range(N+1)]

dp[0][0][0] = 0
for i in range(N):
    a, b, c = map(int, input().split())
    for j in range(10*N+1-a):
        for k in range(10*N+1-b):
            if dp[i][j][k] == INF:
                continue
            dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k])
            dp[i+1][j+a][k+b] = min(dp[i+1][j+a][k+b], dp[i][j][k]+c)

ans = INF
for j in range(1, 10*N+1):
    if j * Ma > 10 * N  or j * Mb > 10 * N:
        break

    ans = min(ans, dp[N][j*Ma][j*Mb])

if ans == INF:
    ans = -1

print(ans)
Buggy python submission (verdict: Runtime Error):
a, x, b = input()

if x == '+':
    ans = int(a)+int(b)
else:
    ans = int(a)-int(b)

print(ans)


Fixed submission:
a, x, b = input().split()

if x == '+':
    ans = int(a)+int(b)
else:
    ans = int(a)-int(b)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K, L = map(int, input().split())

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    def root(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def unite(self, u, v):
        ru = self.root(u)
        rv = self.root(v)
        if self.rank[ru] < self.rank[rv]:
            self.par[ru] = rv
        else:
            self.par[rv] = ru
            if self.rank[ru] == self.rank[rv]:
                self.rank[ru] += 1

    def same(self, u, v):
        return self.root(u) == self.root(v)


u_road = UnionFind(N)
u_train = UnionFind(N)

for i in range(K):
    p, q = map(int, input().split())
    u_road.unite(p, q)
for i in range(L):
    r, s = map(int, input().split())
    u_train.unite(r, s)

ans = [1] * N

for i in range(1, N):
    for j in range(i+1, N+1):
        if u_road.same(i, j) and u_train.same(i, j):
            ans[i-1] += 1
            ans[j-1] += 1

print(*ans)

Fixed submission:
N, K, L = map(int, input().split())

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    def root(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def unite(self, u, v):
        ru = self.root(u)
        rv = self.root(v)
        if self.rank[ru] < self.rank[rv]:
            self.par[ru] = rv
        else:
            self.par[rv] = ru
            if self.rank[ru] == self.rank[rv]:
                self.rank[ru] += 1

    def same(self, u, v):
        return self.root(u) == self.root(v)


u_road = UnionFind(N)
u_train = UnionFind(N)

for i in range(K):
    p, q = map(int, input().split())
    u_road.unite(p, q)
for i in range(L):
    r, s = map(int, input().split())
    u_train.unite(r, s)

mem = [set() for _ in range(N)]
mem_dict = dict()
for i in range(N):
    a = (u_road.root(i+1), u_train.root(i+1))
    mem[i] = a
    if a in mem_dict:
        mem_dict[a] += 1
    else:
        mem_dict[a] = 1

for i in range(N):
    print(mem_dict[mem[i]], end=' ')

print()
Buggy python submission (verdict: Time Limit Exceeded):
import math
H, W, A, B = map(int, input().split())
MOD = 10 ** 9 + 7


def f(h, w):

    return math.factorial(h+w-2) // (math.factorial(h-1) * math.factorial(w-1))

answer = 0
for i in range(B+1, W+1):
    answer += f(H-A, i) * f(A, W-i+1)
    answer %= MOD

print(int(answer))

Fixed submission:
import math
H, W, A, B = map(int, input().split())
MOD = 10 ** 9 + 7

factorial = [1]
inv_factorial = [1]


for i in range(1, H+W+1):
    factorial.append(factorial[-1] * i % MOD)
    inv_factorial.append(pow(factorial[-1], MOD-2, MOD))


def f(h, w):
    return (factorial[h+w-2] * inv_factorial[h-1] * inv_factorial[w-1]) % MOD


answer = 0
for i in range(B+1, W+1):
    answer += f(H-A, i) * f(A, W-i+1)
    answer %= MOD

print(int(answer))
Buggy python submission (verdict: Runtime Error):
A, B, C, K = map(int, input().split())  # a 1 b 0 c -1

if K <= A:
    print(K)

else:
    maxvalue = A
    K -= A
    if B >= 0:
        if K > 0:
            K = K - B
            if K <= 0:
                print(maxvalue)
    maxvalue -= K * -1
    print(maxvalue)



Fixed submission:
s = input()
t = input()

if t[0:len(s)] == s and len(t) == len(s)+1:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
A, B, C, K = map(int, input().split())  # a 1 b 0 c -1

max_value = 0
m = 0
while(A>0):
    if m < K:
        max_value+=1
        m += 1
        A = A - 1
    else:
        break
        
while(B>0):
    if m < K:
        m += 1
        B = B - 1
    else:
        break
while(C>0):
    if m < k:
        max_value -= 1
        m += 1
        C = C - 1
    else:
        break
        

print(max_value)

Fixed submission:
s = input()
t = input()

if t[0:len(s)] == s and len(t) == len(s)+1:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
A, B, C, K = map(int, input().split())  # a 1 b 0 c -1

max_value = 0
m = 0
while(A>0):
    if m < K:
        max_value+=1
        m += 1
        A = A - 1
    else:
        break
        
while(B>0):
    if m < K:
        m += 1
        B = B - 1
    else:
        break
while(C>0):
    if m < k:
        max_value -= 1
        m += 1
        C = C - 1
    else:
        break
        



Fixed submission:
s = input()
t = input()

if t[0:len(s)] == s and len(t) == len(s)+1:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
a=int(input())
b=int(input())
c=int(input())
if a+b+c >=22:
	print('bust')
else:
	print('win')

Fixed submission:
a,b,c = map(int,input().split())
if a+b+c >=22:
	print('bust')
else:
	print('win')

Buggy python submission (verdict: Runtime Error):
a1=int(input())
a2=int(input())
a3=int(input())
if a1+a2+a3 >=22:
	print('bust')
else:
	print('win')

Fixed submission:
a,b,c = map(int,input().split())
if a+b+c >=22:
	print('bust')
else:
	print('win')
Buggy python submission (verdict: Time Limit Exceeded):
n, b, r = map(int, input().split())
ans = 0

while n > 0:
    ans += min(n, b)
    n -= b + r

print(ans)


Fixed submission:
n, b, r = map(int, input().split())

ans = n // (b + r) * b
n = n % (b + r)

ans += min(n, b)

print(ans)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())

buf = a - b

if buf % 2 = 0:
	print(buf // 2)
else:
	print("IMPOSSIBLE")

Fixed submission:
a, b = map(int, input().split())

buf = a + b

if buf % 2 == 0:
	print(buf // 2)
else:
	print("IMPOSSIBLE")
Buggy python submission (verdict: Runtime Error):
n, m, c = map(int, input().split())
B = [*map(int, input().split())]
ans = 0

for i in range(n):
    cnt = c
    A = [*map(int, input().split())]
    for j in range(m):
        cnt += A[j] * B[j]
    if cnt > 0:
        ans += 1

print(ans)

Fixed submission:
n, m, c = map(int, input().split())
B = list(map(int, input().split()))
ans = 0

for i in range(n):
    cnt = c
    A = list(map(int, input().split()))
    for j in range(m):
        cnt += A[j] * B[j]
    if cnt > 0:
        ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
def main() -> None:
    ab, bc, ca = map(int, input())
    print(ab * bc // 2)


if __name__ == "__main__":
    main()


Fixed submission:
def main() -> None:
    ab, bc, ca = map(int, input().split())
    print(ab * bc // 2)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(sys.maxsize)

n = int(input())
h = [int(x) for x in input().split()]
dp = [-1 for _ in range(n)]


def rec_dp(i: int) -> int:
    global h, dp
    if i == 0:
        return 0
    if dp[i] != -1:
        return dp[i]
    res = rec_dp(i - 1) + abs(h[i] - h[i - 1])
    if i - 2 >= 0:
        res = min(rec_dp(i - 2) + abs(h[i] - h[i - 2]), res)
    dp[i] = res
    return res


print(rec_dp(n - 1))


Fixed submission:
INF = 10 ** 9
N = int(input())
h = [int(x) for x in input().split()]

dp = [INF] * N
dp[0] = 0

for i in range(N - 1):
    for j in range(1, 3):
        if i + j < N:
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))

print(dp[N - 1])

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 4)

n = int(input())
h = [int(x) for x in input().split()]
dp = [-1 for _ in range(n)]


def rec_dp(i: int) -> int:
    global h, dp
    if i == 0:
        return 0
    if dp[i] != -1:
        return dp[i]
    res = rec_dp(i - 1) + abs(h[i] - h[i - 1])
    if i - 2 >= 0:
        res = min(rec_dp(i - 2) + abs(h[i] - h[i - 2]), res)
    dp[i] = res
    return res


print(rec_dp(n - 1))


Fixed submission:
INF = 10 ** 9
N = int(input())
h = [int(x) for x in input().split()]

dp = [INF] * N
dp[0] = 0

for i in range(N - 1):
    for j in range(1, 3):
        if i + j < N:
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))

print(dp[N - 1])

Buggy python submission (verdict: Runtime Error):
n = int(input())
h = [int(x) for x in input().split()]
dp = [-1 for _ in range(n)]


def rec_dp(i: int) -> int:
    global h, dp
    if i == 0:
        return 0
    if dp[i] != -1:
        return dp[i]
    res = rec_dp(i - 1) + abs(h[i] - h[i - 1])
    if i - 2 >= 0:
        res = min(rec_dp(i - 2) + abs(h[i] - h[i - 2]), res)
    dp[i] = res
    return res


print(rec_dp(n - 1))


Fixed submission:
INF = 10 ** 9
N = int(input())
h = [int(x) for x in input().split()]

dp = [INF] * N
dp[0] = 0

for i in range(N - 1):
    for j in range(1, 3):
        if i + j < N:
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))

print(dp[N - 1])
Buggy python submission (verdict: Time Limit Exceeded):
INF = 10 ** 9
N, K = map(int, input().split())
h = [int(x) for x in input().split()]

dp = [INF] * N
dp[0] = 0

for i in range(N - 1):
    for j in range(1, K + 1):
        if i + j < N:
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))

print(dp[N - 1])


Fixed submission:
INF = 10 ** 9
N, K = map(int, input().split())
h = [int(x) for x in input().split()]

dp = [INF] * N
dp[0] = 0

for i in range(N - 1):
    for j in range(1, K + 1):
        if i + j < N:
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))

print(dp[N - 1])
Buggy python submission (verdict: Runtime Error):
x =int(input())
for n in range(x, 0, -1):
    for b in range(1, n + 1):
        for p in range(2, n + 1):
            if b ** p == n:
                print(n)
                exit()
            elif b ** p > n:
                break
print(1)


Fixed submission:
a, b, c, d = map(int,input().split())
if abs(a - c) <= d:
    print('Yes')
elif abs(a - b) <= d and abs(b - c) <= d:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input())

ans = a - 1 + (a == b)

Fixed submission:
a, b = map(int, input().split())

print(a - (a > b))
Buggy python submission (verdict: Runtime Error):
def mySort(S):
    if 'a' not in S:
        return 'No'
    elif 'b' not in S:
        return 'No'
    elif 'c' not in S:
        return 'No'
    else:
        return 'Yes'
    
mySort(S)

Fixed submission:
S = input()

def mySort(S):
    if 'a' not in S:
        return 'No'
    elif 'b' not in S:
        return 'No'
    elif 'c' not in S:
        return 'No'
    else:
        return 'Yes'
    
print(mySort(S))

Buggy python submission (verdict: Runtime Error):
def mySort(arg1):
    if 'a' not in S:
        return 'No'
    elif 'b' not in S:
        return 'No'
    elif 'c' not in S:
        return 'No'
    else:
        return 'Yes'
    
mySort(S)

Fixed submission:
S = input()

def mySort(S):
    if 'a' not in S:
        return 'No'
    elif 'b' not in S:
        return 'No'
    elif 'c' not in S:
        return 'No'
    else:
        return 'Yes'
    
print(mySort(S))
Buggy python submission (verdict: Runtime Error):
import strutils

proc input: string =
  while true:
    let tmp = readChar stdin
    if not isSpace tmp:
      safeAdd result, tmp
    elif tmp != '\r': break

let
  A, B, C, D, E, F = parseInt input()
var
  best = -1.0
  ws, sg = 0

for a in countup(0, F, 100 * A):
  for b in countup(0, F - a, 100 * B):
    let
      w = a + b
      m = min(F - w, w * E div 100)

    if w == 0: continue
    for c in countup(0, m, C):
      for d in countup(0, m - c, D):
        let s = c + d
        if best < s / (w + s):
          best = s / (w + s)
          ws = w + s
          sg = s

echo ws, " ", sg


Fixed submission:
A, B, C, D, E, F = map(int, input().split())

best = -1.0
a = ws = sg = 0

while 100 * a * A <= F:
    b = 0
    while True:
        w = 100 * (a * A + b * B)
        if w > F: break
        c = 0
        while w + c * C <= F and 100 * c * C <= w * E:
            d = 0
            while True:
                s = c * C + d * D
                if w + s > F or 100 * s > w * E:
                    break
                elif w + s != 0 and best < s / (w + s):
                    best = s / (w + s)
                    ws = w + s
                    sg = s
                d += 1
            c += 1
        b += 1
    a += 1
print(ws, sg)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [""]
for i in range(N):
    a.append(int(input()))

button = 1
i = 0

while True:
    i += 1
    button = a[button]

    if button <= 2:
        if button == 1:
            print(-1)
        if button == 2:
            print(i)
        break


Fixed submission:
N = int(input())
a = [""]
for i in range(N):
    a.append(int(input()))

button = 1
i = 0

for i in range(N):
    if button == 2:
        print(i)
        exit()
    button = a[button]
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
from sys import stdin


def main() -> int:
    global W
    W = next_int()
    a, b = map(int, input())

    if b + W < a:
        ans = diff(b + W, a)
    elif a + W < b:
        ans = diff(a + W, b)
    else:
        ans = 0

    print(ans)
    return 0


def diff(a: int, b: int) -> int:
    return abs(a - b)


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Fixed submission:
W, a, b = map(int, input().split())

if a < b:
    print(max(0, b - (a + W)))
else:
    print(max(0, a - (b + W)))
Buggy python submission (verdict: Runtime Error):
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)

    val n = sc.nextInt()
    val c = sc.nextInt()
    val k = sc.nextInt()
    val t = Array(n) { sc.nextInt() }

    var ans = 0
    var waitStart = 0
    var waitPeople = 0

    for (ti in t.sorted()) {
        if (ti - waitStart > k || waitPeople == c) {
            waitPeople = 0
        }
        waitPeople++

        if (waitPeople == 1) {
            waitStart = ti
            ans++
        }
    }
    println(ans)
}


Fixed submission:
def main() -> None:
    n, c, k = map(int, input().split())
    t = [int(input()) for _ in range(n)]
    ans = wait_start = wait_people = 0

    for ti in sorted(t):
        if ti - wait_start > k or wait_people == c:
            wait_people = 0
        wait_people += 1

        if wait_people == 1:
            wait_start = ti
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import math

def gcd(a,b):
    """Compute the greatest common divisor of a and b"""
    while b > 0:
        a, b = b, a % b
    return a

def lcm(a, b):
    """Compute the lowest common multiple of a and b"""
    return a * b / gcd(a, b)


def best_alignment(lst, small):

	ans = 0

	p = []

	if(small):
		p.append(lst[-1])
		p.append(lst[-1])
		del lst[-1:]
	else:
		m = min(lst)
		p.append(lst[0])
		p.append(lst[0])
		lst.pop(0)


	while(len(lst)>0):

		print(small)
		print(lst)
		print(p)
		print(ans)
		print("")

		if(small):
			ans = ans + abs(max(p)-lst[0])
			if(len(lst)==1):
				break

			ans = ans + abs(min(p)-lst[1])

			p = []
			p.append(lst.pop(0))
			p.append(lst.pop(0))
			small = False
			continue
		else:
			ans = ans + abs(min(p)-lst[-1])
			if(len(lst)==1):
				break

			ans = ans + abs(max(p)-lst[-2])

			p = []
			p.append(lst[-1])
			p.append(lst[-2])
			del lst[-2:]
			small = True
			continue

	return ans	




N = int(input().strip())
A = []
for i in range(N):
	A.append(int(input().strip()))

A.sort()
A_=A.copy()

print(max(best_alignment(A, True), best_alignment(A_, False)))

Fixed submission:
import math

def gcd(a,b):
    """Compute the greatest common divisor of a and b"""
    while b > 0:
        a, b = b, a % b
    return a

def lcm(a, b):
    """Compute the lowest common multiple of a and b"""
    return a * b / gcd(a, b)


def best_alignment(lst, small):

	ans = 0

	p = []

	if(small):
		p.append(lst[-1])
		p.append(lst[-1])
		del lst[-1:]
	else:
		m = min(lst)
		p.append(lst[0])
		p.append(lst[0])
		lst.pop(0)


	while(len(lst)>0):

		if(small):
			ans = ans + abs(max(p)-lst[0])
			if(len(lst)==1):
				break

			ans = ans + abs(min(p)-lst[1])

			p = []
			p.append(lst.pop(0))
			p.append(lst.pop(0))
			small = False
			continue
		else:
			ans = ans + abs(min(p)-lst[-1])
			if(len(lst)==1):
				break

			ans = ans + abs(max(p)-lst[-2])

			p = []
			p.append(lst[-1])
			p.append(lst[-2])
			del lst[-2:]
			small = True
			continue

	return ans	




N = int(input().strip())
A = []
for i in range(N):
	A.append(int(input().strip()))

A.sort()
A_=A.copy()

print(max(best_alignment(A, True), best_alignment(A_, False)))