Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

a,b,c,k=map(int,input().split())
for i in range(k):
  a,b,c=(b+c),(a+c),(b+c)
ans=a-b
if ans<=10**18:
  print(ans)
else:
  print("Unfair")

### FIXED CODE ###

a,b,c,k=map(int,input().split())
if k%2==0:
  ans=a-b
else:
  ans=b-a
if ans<=10**18:
  print(ans)
else:
  print("Unfair")
### BUGGY CODE ###

# -*- coding: utf-8 -*-
n, m = map(int, input().split())
a= list(map(int, input().split()))
bc=[[0, 0]]
for i in range(m):
  bc.append(list(map(int, input().split())))
del bc[0]
bc=sorted(bc, key=lambda x: x[1], reverse=True)
a.sort()
count = 0;
for j in range(m):
  for i in range(bc[j][0]):
    if a[0] < bc[j][1]:
      del a[0]
      a.append(bc[j][1])
      count = count + 1
    else:
      break
    if count > n + 1:
      break
  else: 
    continue
  break
print(sum(a))


### FIXED CODE ###

# -*- coding: utf-8 -*-
n, m = map(int, input().split())
a= list(map(int, input().split()))
bc=[[0, 0]]
for i in range(m):
  bc.append(list(map(int, input().split())))
del bc[0]
bc=sorted(bc, key=lambda x: x[1], reverse=True)
a.sort()
count = 0
s = 0
for j in range(m):
  for i in range(bc[j][0]):
    if a[count] < bc[j][1]:
      s = s + bc[j][1]
      count = count + 1
    else:
      break
    if count > n - 1 :
      break
  else: 
    continue
  break
if count > n - 1:
  print(s)
else:
  print(s + sum(a[count:]))
### BUGGY CODE ###

n = int(input())
s = input()
r = []
g = []
b = []
for i in range(n):
    if s[i] == "R":
        r.append(i)
    elif s[i] == "G":
        g.append(i)
    else:
        b.append(i)
ans = len(r)*len(g)*len(b)
for i in r:
    for j in g:
        a = max(i,j)
        u = min(i,j)
        if a*2-u >= 0 and a*2-u < n :
            if s[a*2-u] == 'B':
                ans -= 1
        if 2*u-a >= 0 and 2*u-a < n:
            if s[2*u-a] == 'B':
                ans -= 1
        if (a-u)%2 == 0 and u+(a-u)/2 >= 0 and u+(a-u)/2 < n:
            if s[u+(a-u)//2] == 'B':
                ans -= 1
print(ans)


### FIXED CODE ###

n = int(input())
s = input()
r = []
g = []
b = []
for i in range(n):
    if s[i] == "R":
        r.append(i)
    elif s[i] == "G":
        g.append(i)
    else:
        b.append(i)
ans = len(r)*len(g)*len(b)
for i in b:
    for j in g:
        a = max(i,j)
        u = min(i,j)
        if a*2-u >= 0 and a*2-u < n :
            if s[a*2-u] == 'R':
                ans -= 1
        if 2*u-a >= 0 and 2*u-a < n:
            if s[2*u-a] == 'R':
                ans -= 1
        if (a-u)%2 == 0 and u+(a-u)/2 >= 0 and u+(a-u)/2 < n:
            if s[u+(a-u)//2] == 'R':
                ans -= 1
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))

ans = a[0]
for i in range(1, n, 1):
    ans = ans * a[i]
if ans > 1e+18:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

if min(a) == 0:
    print(0)
    exit()
else:
    ans = a[0]
    for i in range(1, n, 1):
        ans = ans * a[i]
        if ans > 1e+18:
            print(-1)
            exit()
    print(ans)
### BUGGY CODE ###

import numpy as np

s = input()
l = len(s)
mod = (10**9)+7

dp = np.zeros((l,13), dtype=np.int64)

if s[0] == '?':
    dp[0][0:10] = 1
else:
    dp[0][int(s[0])] = 1

dp_memo = dp[0]

for i in range(l-1):
    a = i+1
    x = s[a]
    if x == '?':
        for j in range(10):
            for k in range(13):
                dp[a][(k*10+j)%13] += dp_memo[k]%mod
    else:
        for k in range(13):
            dp[a][(k*10+int(x))%13] += dp_memo[k]%mod
    dp_memo = dp[a]

print(dp[-1][5]%mod)

### FIXED CODE ###

s = input()
l = len(s)
mod = (10**9)+7

dp = [[0 for j in range(13)] for i in range(l)]

if s[0] == '?':
    dp[0][0:9] = [1 for x in range(10)]
else:
    dp[0][int(s[0])] = 1

for i in range(l-1):
    a = i+1
    x = s[a]
    if x == '?':
        for j in range(10):
            for k in range(13):
                dp[a][(k*10+j)%13] += dp[a-1][k]%mod
    else:
        for k in range(13):
            dp[a][(k*10+int(x))%13] += dp[a-1][k]%mod

print(dp[-1][5]%mod)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))

rsl = []
for i in range(1,n):
    rsl.append(a.count(i))

for _ in rsl:
    print(_)
print(0)

### FIXED CODE ###

import numpy as np
n = int(input())
a = list(map(int,input().split()))

rsl = np.zeros(n)

for i in a:
    rsl[i-1] += 1

for i in range(n):
    print(int(rsl[i]))
### BUGGY CODE ###

# -*- coding: utf-8 -*-

s = list(input())
q = int(input())
reverse_counter = 0
for q0 in range(q):
    A = [i for i in input().split()]
    if len(A) == 1:
        reverse_counter += 1
    else:
        if A[1] == '1':
            if reverse_counter % 2 == 0:
                s.insert(0, A[2])
            else:
                s.append(A[2])
        else:
            if reverse_counter % 2 == 0:
                s.append(A[2])
            else:
                s.insert(0, A[2])

if reverse_counter % 2 == 1:
    s.reverse()

print(''.join(s))

### FIXED CODE ###

# -*- coding: utf-8 -*-

s = list(input())
q = int(input())
reverse_counter = 0
left = []
for q0 in range(q):
    A = [i for i in input().split()]
    if len(A) == 1:
        reverse_counter += 1
    else:
        if A[1] == '1':
            if reverse_counter % 2 == 0:
                left.append(A[2])
            else:
                s.append(A[2])
        else:
            if reverse_counter % 2 == 0:
                s.append(A[2])
            else:
                left.append(A[2])

left.reverse()

res = left + s

if reverse_counter % 2 == 1:
    res.reverse()

print(''.join(res))
### BUGGY CODE ###

import numpy as np
N , K = map( int , input().split())
lst = list(map(int, input().split()))
ans = 10 ** 9

def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """
    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

nearzero = getNearestValue(lst, 0)
start = max(0 , nearzero- K -1)  
end = min(N - K + 1 , nearzero +  K + 1)
for i in range(start , end):
    # Ｋ個のサブリストを作成する
    lst2 = lst[i: i+K]
    # 全て正（先頭がゼロ以上）であれば、最大の正数（一番右の数）が最小時間となる
    if lst2[0] >= 0:
        ans = min(ans, lst2[-1])
    # 全て負（一番右がゼロ以下）であれば、最小の整数（一番左の数）が最小時間となる
    elif lst2[-1] <= 0:
        ans = min(ans, abs(lst2[0]))
    # 上記以外は、正負混在のケース    
    else:
        #  一番右の方が大きいとき
        if abs(lst2[0]) < lst2[-1]:
            # 負の方向から折り返してくる方が最小なので
            ans = min(ans , abs(lst2[0]) * 2 + lst2[-1])
        else:
            # 正の方向から折り返してくる方が最小なので
            ans = min(ans , abs(lst2[0]) + lst2[-1] * 2)

print(ans)


### FIXED CODE ###

import numpy as np
N , K = map( int , input().split())
lst = list(map(int, input().split()))
ans = 10 ** 9

for i in range(N - K + 1):
    # 全て正（先頭がゼロ以上）であれば、最大の正数（一番右の数）が最小時間となる
    if lst[i] >= 0:
        ans = min(ans, lst[i + K -1])
    # 全て負（一番右がゼロ以下）であれば、最小の整数（一番左の数）が最小時間となる
    elif lst[i + K -1] <= 0:
        ans = min(ans, abs(lst[i]))
    # 上記以外は、正負混在のケース    
    else:
        #  一番右の方が大きいとき
        if abs(lst[i]) < lst[i + K -1]:
            # 負の方向から折り返してくる方が最小なので
            ans = min(ans , abs(lst[i]) * 2 + lst[i + K -1])
        else:
            # 正の方向から折り返してくる方が最小なので
            ans = min(ans , abs(lst[i]) + lst[i + K -1] * 2)

print(ans)
### BUGGY CODE ###

n = int(input())
s = [input() for i in range(n)]

def yoi(s, a, b):
  for i in range(n):
    for j in range(i+1, n):
      if s[(i + a) % n][(j + b) % n] != s[(j + a) % n][(i + b) % n]:
        return 0
  return 1

sol = sum(yoi(s, a, b) for a in range(n) for b in range(n))
print(sol)

### FIXED CODE ###

n = int(input())
s = [input() for i in range(n)]
st = [str().join(s_) for s_ in zip(*s)]

sol = 0

for i in range(n):
    for k in range(n):
        if s[k] != st[k]:
            break
    else:
        sol += 1
    
    s = [s_l[1:]+s_l[0] for s_l in s]
    st = st[1:] + [st[0]]
    
print(sol * n)
### BUGGY CODE ###

N = int(input())
s = str(input())
maxlen = N//2

def solve(tgt):
    for i in range(N-tgt*2+1):
        if s[i:i+tgt] in s[i+tgt:]:
            return True
    return False

ng = maxlen + 1
ok = 0
first = 1
while ng-ok > 1:
    tgt = (ok+ng)//2
    if first == 1:
        tgt == (ok+ng)//32
        first = 0
    if solve(tgt):
        ok = tgt
    else:
        ng = tgt
print(ok)


### FIXED CODE ###

from collections import defaultdict as dd
N = int(input())
s = str(input())
maxlen = N//2

def solve(tgt):
    dic = dd(int)
    st = s[tgt:2*tgt]
    dic[st] += 1
    ls = [st]
    for char in s[2*tgt:]:
        st = st[1:]+char
        dic[st] += 1
        ls.append(st)
    st = s[:tgt]
    if dic[st] > 0:
        return True
    dic[ls[0]] -= 1
    for i,char in enumerate(s[tgt:N-tgt]):
        st = st[1:]+char
        if dic[st] > 0:
            return True
        dic[ls[i+1]] -= 1
    return False

ng = maxlen + 1
ok = 0
while ng-ok > 1:
    tgt = (ok+ng)//2
    if solve(tgt):
        ok = tgt
    else:
        ng = tgt
print(ok)
### BUGGY CODE ###

# -*- coding: utf-8 -*-

def main():
    n = int(input())
    a = list(map(int, input().split()))

    for i in range(n):
        dis = 0
        bef = 0
        for idx, b in enumerate(a):
            if idx == i:
                continue
            dis += abs(bef - b)
            bef = b
        dis += abs(0 - bef)
        print(dis)

if __name__ == '__main__':
    main()


### FIXED CODE ###

# -*- coding: utf-8 -*-

def main():
    n = int(input())
    a = list(map(int, input().split()))

    dis = 0
    bef = 0
    for b in a:
        dis += abs(bef - b)
        bef = b
    dis += abs(bef)
    for i in range(n):
        m = 0 if i == 0 else a[i-1]
        l = 0 if i == len(a) - 1 else a[i+1]
        print(dis - (abs(m - a[i]) + abs(a[i] - l) - abs(m - l)))

if __name__ == '__main__':
    main()
### BUGGY CODE ###

H, N = map(int, input().split())
dp = [0 for i in range(H + 10 ** 4 + 1)]

ab = []
for i in range(N):
    a, b = map(int, input().split())
    ab.append([a, b])

for i in range(1, H + 1):
    values = []
    for a, b in ab:
        values.append(dp[i - a] + b)
    dp[i] = min(values)

print(dp[H])


### FIXED CODE ###

import numpy as np

H, N = map(int, input().split())

ab = []
for i in range(N):
    a, b = map(int, input().split())
    ab.append([a, b])

ab = np.array(ab)
a_list = ab[:, 0]
b_list = ab[:, 1]
max_a = ab.max()

inf = float('inf')
dp = np.array([inf for _ in range(H + max_a)])
dp[0] = 0

for i in range(1, len(dp)):
    dp[i] = np.amin(dp[np.maximum(i - a_list, 0)] + b_list)

print(int(min(dp[H:])))
### BUGGY CODE ###

N = int(input())
S = list(input())
l = []
ans = 0
for x in range(1000) :
    X = list(str(x).zfill(3))
    c = 0
    I = 0
    J = 0
    for i in range(N-2) :
        if X[0] == S[i] :
            I = i
            c += 1
            break
    for j in range(I+1,N-1) :
        if X[1] == S[j] :
            c += 1
            J = j
            break
    for k in range(J+1,N) :
        if X[2] == S[k] :
            c += 1
            break
    if c == 3 :
        ans += 1
                        
print(ans)

### FIXED CODE ###

N = int(input())
S = list(input())
ans = 0
for x in range(1000) :
    X = list(str(x).zfill(3))
    i = 0
    j = 0
    if X[0] in S[:N-2] :
        i = S.index(X[0])
    else :
        continue
    if X[1] in S[i+1:N-1] :
        j = S[i+1:N-1].index(X[1])+i+1
    else :
        continue
    if X[2] in S[j+1:N] :
        ans += 1
                        
print(ans)
### BUGGY CODE ###

def calc( s , k , n):

	bruh = {}
	for i  in range(1, n + 1): # length
		for j in range( n - ( i - 1)): # start 
			bruh[s[j: j + i:]] = 0
	another = bruh.keys()
	another = sorted(another)
	print( another[k - 1])

s = input()

k = int(input())

n = len(s)
 
calc( s , k , n)

### FIXED CODE ###

def calc( s , k , n):

	bruh = {}
	for i  in range(1, k + 1): # length
		for j in range( n - ( i - 1)): # start 
			bruh[s[j: j + i:]] = 0
	another = bruh.keys()
	another = sorted(another)
	print( another[k - 1])

s = input()

k = int(input())

n = len(s)
 
calc( s , k , n)
### BUGGY CODE ###

s = input()
num = int(input())

reverse = False

for _ in range(num):
    row = input().split()
    if len(row) == 1:
        if reverse == False:
            reverse = True
        else:
            reverse = False
    else:
        if row[1] == "1":
            if reverse:
                s = s + row[2]
            else:
                s = row[2] + s
        else:
            if reverse:
                s = row[2] + s
            else:
                s = s + row[2]

if reverse:
    print(s[::-1])
else:
    print(s)

### FIXED CODE ###

s = input()
num = int(input())
t = "X"
reverse = False

for _ in range(num):
    row = input().split()
    if len(row) == 1:
        if reverse == False:
            reverse = True
        else:
            reverse = False
    else:
        x = row[1]
        y = row[2]
        if x == "1" and reverse:
            t += y
        elif x == "1" and not reverse:
            t = y + t
        elif x == "2" and reverse:
            t = y + t
        else:
            t += y

if reverse:
    t = t.replace("X", s)
    print(t[::-1])
else:
    t = t.replace("X", s)
    print(t)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
MOD = 1000000007
SUM = 0
for i in range(N-1):
    for j in range(i+1,N):
        SUM += A[i]*A[j] % MOD
print(SUM % MOD)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
MOD = 1000000007
S = sum(A) % MOD
ans = 0

for x in A:
    S -= x
    S %= MOD
    ans += S * x
    ans %= MOD
ans %= MOD
print(ans)
### BUGGY CODE ###

import sys

def lcs_count(A,B):
    # initial value setting
    dp = [list(0 for _ in range(l2+1)) for _ in range(l1+1)]
    # create table
    for i in range(1,l1+1):
        for j in range(1,l2+1):
            if A[i-1] == B[j-1]:
                dp[i][j] = dp[i-1][j-1] + 1
            else:
                dp[i][j] = max(dp[i-1][j],dp[i][j-1])
    return dp

def lcs_string(dp):
    string = []
    for i,j in zip([m for m in range(l1,0,-1)],[n for n in range(l2,0,-1)]):
        if dp[i][j] > dp[i-1][j-1]:
            string.insert(0,s[i-1])
    print("".join(string))

s = sys.stdin.readline().rstrip()
t = sys.stdin.readline().rstrip()
l1 = len(s)
l2 = len(t)

DP = lcs_count(s,t)
lcs_string(DP)





### FIXED CODE ###

import sys

s = [ord(a)-97 for a in list(sys.stdin.readline().rstrip())]
t = [ord(b)-97 for b in list(sys.stdin.readline().rstrip())]
len_s = len(s)
len_t = len(t)

dp = [[0] * (len_t+1) for i in range(len_s+1)]
for i in range(len_s):
    for j in range(len_t):
        if s[i] == t[j]:
            dp[i+1][j+1] = dp[i][j] + 1
        else:
            dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])

strings = []
while len_s > 0 and len_t > 0:
    if s[len_s-1] == t[len_t-1]:
        len_s -= 1
        len_t -= 1
        strings.insert(0,chr(s[len_s]+97))
    elif dp[len_s][len_t-1] > dp[len_s-1][len_t]:
        len_t -= 1
    else:
        len_s -= 1

print("".join(strings))
### BUGGY CODE ###

#!/usr/bin/env python3
#ABC98 D

import sys
input = sys.stdin.readline
def d():
    n = int(input())
    a = list(map(int,input().split()))
    ans = 0
    bit = [[] for _ in range(n)]
    for i in range(n):
        for j in range(20):
            if (a[i] >> j) & 1:
                bit[i].append(j)
    for r in range(n):
        for l in range(r+1):
            s = []
            f = 1
            for c in range(l,r+1):
                for b in bit[c]:
                    if b not in s:
                        s.append(b)
                    else:
                        f = 0
                        break
                if not f:
                    break
            if f:
                ans += 1
    print(ans)

if __name__ == '__main__':
    d()


### FIXED CODE ###

#!/usr/bin/env python3
#ABC98 D

import sys
input = sys.stdin.readline
def d():
    n = int(input())
    a = list(map(int,input().split()))
    ans = 0
    l = 0
    r = 0
    s = 0
    while l < n and r < n:
        while s&a[r] == 0:
            s += a[r]
            r += 1
            ans += r-l
            if r == n:
                break
        if l==r:
            s += a[r]
            r += 1
        s -= a[l]
        l += 1
    print(ans)

if __name__ == '__main__':
    d()
### BUGGY CODE ###

import collections

N,X,Y=map(int,input().split())
if X > Y:
    exc=X
    X=Y
    Y=exc
L=[]
for i in range(N-1):
    for j in range(i+1,N):
        if i >= Y-1 or j <= X-1:
            L.append(j-i)
        elif j-i == 1:
            L.append(1)
        else:
            L1=j-i
            L2=min(j-i,1+abs(X-1-i)+abs(Y-1-j))
            L.append(min(L1,L2))

c=collections.Counter(L)

for i in range(1,N):
    print(c[i])




### FIXED CODE ###

N,X,Y=map(int,input().split())
if X > Y:
    exc=X
    X=Y
    Y=exc
L=[0]*N
for i in range(N-1):
    for j in range(i+1,N):
        if i >= Y-1 or j <= X-1 or j-i ==1:
            L[j-i]+=1
        elif i <= X-1 and j >= Y-1:
            L[1+abs(X-1-i)+abs(Y-1-j)]+=1
        elif i >= X-1 and i-(X-1) > (Y-1)-i:
            L[j-i]+=1
        else:
            L1=j-i
            L2=min(j-i,1+abs(X-1-i)+abs(Y-1-j))
            L[min(L1,L2)]+=1

for i in range(1,N):
    print(L[i])
### BUGGY CODE ###

import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = int(sys.stdin.buffer.readline().rstrip())
    A = list(map(int, sys.stdin.buffer.readline().split()))
    P = set(A)

    obj = {}
    for p in P:
        obj[p] = A.count(p)

    p = 0
    for v in obj.values():
        p += v * (v - 1) // 2

    for a in A:
        print(p - (obj[a] - 1))


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import os
import collections

def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = int(sys.stdin.buffer.readline().rstrip())
    A = list(map(int, sys.stdin.buffer.readline().split()))

    obj = collections.Counter(A)

    p = 0
    for v in obj.values():
        if v > 1:
            p += v * (v - 1) // 2

    for a in A:
        print(p - (obj[a] - 1))


if __name__ == '__main__':
    main()
### BUGGY CODE ###

R,C,k=map(int,input().split())
A=[[0]*C for i in range(R)]
for i in range(k):
  r,c,v=map(int,input().split())
  A[r-1][c-1]=v
dp=[[[0,0,0,0] for j in range(C+1)] for i in range(R+1)]
for i in range(1,R+1):
  for j in range(1,C+1):
    dp[i][j][0]=max(dp[i-1][j][0],dp[i-1][j][1],dp[i-1][j][2],dp[i-1][j][3],dp[i][j-1][0])
    dp[i][j][1]=max(dp[i-1][j][0]+A[i-1][j-1],dp[i-1][j][1]+A[i-1][j-1],dp[i-1][j][2]+A[i-1][j-1],dp[i-1][j][3]+A[i-1][j-1],dp[i][j-1][0]+A[i-1][j-1],dp[i][j-1][1])
    dp[i][j][2]=max(dp[i][j-1][1]+A[i-1][j-1],dp[i][j-1][2])
    dp[i][j][3]=max(dp[i][j-1][2]+A[i-1][j-1],dp[i][j-1][3])
print(max(dp[-1][-1]))

### FIXED CODE ###

import sys
input=sys.stdin.readline
R,C,k=map(int,input().split())
A=[[0]*C for i in range(R)]
for i in range(k):
  r,c,v=map(int,input().split())
  A[r-1][c-1]=v
dp0=[[0]*(C+1) for i in range(R+1)]
dp1=[[0]*(C+1) for i in range(R+1)]
dp2=[[0]*(C+1) for i in range(R+1)]
dp3=[[0]*(C+1) for i in range(R+1)]
for i in range(1,R+1):
  for j in range(1,C+1):
    V=A[i-1][j-1]
    dp0[i][j]=max(dp0[i-1][j],dp1[i-1][j],dp2[i-1][j],dp3[i-1][j],dp0[i][j-1])
    dp1[i][j]=max(dp0[i][j]+V,dp1[i][j-1])
    dp2[i][j]=max(dp1[i][j-1]+V,dp2[i][j-1])
    dp3[i][j]=max(dp2[i][j-1]+V,dp3[i][j-1])
print(max(dp0[-1][-1],dp1[-1][-1],dp2[-1][-1],dp3[-1][-1]))
### BUGGY CODE ###

N=int(input())
num=[]
for i in range(N):
  num.append(int(input()))
num.sort()
jun=[]
sig=[i for i in range(1,N+1)]
if N%2!=0: #kisu
  manaka=int(N/2)
  if abs(num[manaka]-num[0])<abs(num[manaka]-num[N-1]):
    jun.append(manaka)
    for i in range(int((N-1)/2)):
      jun.append(max(sig)-1)
      sig.remove(max(sig))
      jun.append(min(sig)-1)
      sig.remove(min(sig))
  else:
    jun.append(manaka)
    for i in range(int((N-1)/2)):
      jun.append(min(sig)-1)
      sig.remove(min(sig))
      jun.append(max(sig)-1)
      sig.remove(max(sig))
else:
  manaka=int(N/2)
  jun.append(manaka)
  for i in range(manaka-1):
    jun.append(min(sig)-1)
    sig.remove(min(sig))
    jun.append(max(sig)-1)
    sig.remove(max(sig))
  jun.append(sig[0]-1)
sum=0
for i in range(N-1):
  sum+=abs(num[jun[i]]-num[jun[i+1]])
print(sum)

### FIXED CODE ###

N=int(input())
num=[int(input()) for i in range(N)]
num.sort()

if N%2!=0: #kisu
  manaka=int(N/2)  
  sum_a=abs(num[manaka]-num[N-1])
  sum_a+=abs(num[N-1]-num[0])
  for i in range(int((N-1)/2)-1):
    sum_a+=abs(num[N-2-i]-num[i])
    sum_a+=abs(num[i+1]-num[N-2-i])
  sum_b=abs(num[manaka]-num[0])
  sum_b+=abs(num[0]-num[N-1])
  for i in range(int((N-1)/2)-1):
    sum_b+=abs(num[i+1]-num[N-1-i])
    sum_b+=abs(num[i+1]-num[N-2-i])
  print(max(sum_a,sum_b))
else:
  manaka=int(N/2)
  sum=abs(num[manaka]-num[0])
  for i in range(manaka-1):
    sum+=abs(num[i]-num[N-1-i])
    sum+=abs(num[i+1]-num[N-1-i])
  print(sum)
### BUGGY CODE ###

X,Y,Z,K = map(int,input().split())

A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

AB=[]

for a in A:
    for b in B:
        AB.append(a+b)

AB.sort(reverse=True)

AB = AB[0:K]

ABC=[]
for ab in AB:
    for c in C:
        ABC.append(ab+c)

ABC.sort(reverse=True)

for i in range(K):
    print(ABC[i])


### FIXED CODE ###

X,Y,Z,K = map(int,input().split())

A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

A.sort(reverse=True)
A = A[0:K]
B.sort(reverse=True)
B = B[0:K]
AB = [a+b for a in A for b in B]

AB.sort(reverse=True)

AB = AB[0:K]

C.sort(reverse=True)
C=C[0:K]
ABC = [ab+c for ab in AB for c in C]

ABC.sort(reverse=True)

for i in range(K):
    print(ABC[i])
### BUGGY CODE ###

import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()

cnt = 0
for i in a:
	x = bisect.bisect_right(b,i)
	for j in b[x:]:
		y = bisect.bisect_right(c,j)
		cnt += n-y
print (cnt)

### FIXED CODE ###

import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
cnt = 0

for i in b:
	x = bisect.bisect_left(a,i)
	y = bisect.bisect_right(c,i)
	cnt += x*(n-y)
print (cnt)