Harryxun/stf_run huggingface dataset:
# Crank
N,M=map(int, input().split())
import numpy as np
def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

if M==0:
    print(N)
else:
    check_set=set(map(int, input().split()))
    ans_set = set([i for i in range(1,101)])
    lst = list(ans_set-check_set)
    print(getNearestValue(lst, N))

### FIXED CODE ###

N,M=map(int, input().split())
import numpy as np
def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

if M==0:
    print(N)
else:
    check_set=set(map(int, input().split()))
    ans_set = set([i for i in range(-1,102)])
    lst = list(ans_set-check_set)
    sorted_lst=sorted(lst)
    print(getNearestValue(sorted_lst, N))
import copy

####入力
H,W = map(int,input().split())

#gridの定義
grid = []
for i in range(H):
  S = input()
  grid.append( [S[i] for i in range(W) ])
####入力終了


#l_blackの設定
l_black = []
for i in range(H):
  for j in range(W):
    if grid[i][j] == "#":
      l_black.append( [i,j] ) # [行,列]


#探索
cnt = 0

while len(l_black) > 0:

  l_change = []

  #vは黒マスリスト #新たに黒マスになる白マスの座標をl_changeに詰めていく
  for v in l_black:
    #iはvの上下左右のマスの座標[行,列]
    for i in [ [v[0]+1,v[1]] , [v[0],v[1]+1] , [v[0]-1,v[1]] ,[v[0],v[1]-1] ]:
      #場外アウトの場合はスルー
      if (i[0]<0 or i[1] <0 or i[1]>=H or i[0] >= W ):
        continue
      #移動先がもう黒マスの場合スルー
      if grid[i[1]][i[0]] == "#":
        continue
      #移動先が白マスならばそこの座標をl_changeに追加
      if grid[i[1]][i[0]] == ".":
        l_change.append( i )
  
  #l_changeの中の白マスを黒にする
  for i in l_change:
    grid[i[0]][i[1]] = "#" 
  #l_blackの中を新たに黒鱒になったやつの座標だけにする
  l_black = copy.deepcopy( l_change )
  if len(l_black) > 0:
    cnt = cnt + 1
print(cnt)  

### FIXED CODE ###

import copy
from collections import deque

####入力
H,W = map(int,input().split())

#gridの定義
grid = []
for i in range(H):
  S = input()
  grid.append( [S[i] for i in range(W) ])
####入力終了

#distの設定
dist = [[0 for i in range(W)] for j in range(H)]

#l_blackの設定
l_black = deque([])
for i in range(H):
  for j in range(W):
    if grid[i][j] == "#":
      l_black.append( [i,j] ) # [行,列]

#探索
max_d = 0

while len(l_black) > 0:
  #vは黒マスの座標 
  while len(l_black) > 0:
    v = l_black.popleft()
    #iはvの上下左右のマスの座標[行,列]
    for i in [ [v[0]+1,v[1]] , [v[0],v[1]+1] , [v[0]-1,v[1]] ,[v[0],v[1]-1] ]:
      #場外アウトの場合はスルー
      if (i[1]<0 or i[0] <0 or i[0]>=H or i[1] >= W ):
        continue
      #移動先がもう黒マスの場合スルー
      if grid[i[0]][i[1]] == "#":
        continue
      #移動先が白マスならばそこの座標を黒マスにして距離を記録する
      if grid[i[0]][i[1]] == ".":
        #黒マスにする
        grid[i[0]][i[1]] = "#"
        #新たに黒鱒となった座標をl_blackに追加
        l_black.append(i)
        #距離の記録
        dist[i[0]][i[1]] = dist[v[0]][v[1]] + 1
        max_d = max(max_d,dist[i[0]][i[1]])
print(max_d)
import itertools
import numpy as np

n,m,q=map(int, input().split())  
a=[list(map(int, input().split())) for i in range(m)]
b=[list(map(int, input().split())) for i in range(q)]

x=np.zeros(501, 501)

for i in range(m):
    x[a[i][0]][a[i][1]]+=1

x= np.cumsum(x, axis=0)
x= np.cumsum(x, axis=1)

for i in range(q):
    v1=b[i][0]
    v2=b[i][1]
    
    a1=x[v2,v2]
    a2=x[v2,v1-1]
    a3=x[v1-1,v2]
    a4=x[v1-1,v1-1]
    print(a1-a2-a3+a4)

### FIXED CODE ###

import numpy as np

n,m,q=map(int, input().split())  
a=[list(map(int, input().split())) for i in range(m)]
b=[list(map(int, input().split())) for i in range(q)]

x=np.zeros((501, 501), dtype=np.int)

for i in range(m):
    x[a[i][0], a[i][1]]+=1

x = np.cumsum(x, axis=0)
x = np.cumsum(x, axis=1)

for i in range(q):
    v1=b[i][0]
    v2=b[i][1]
    
    a1=x[v2, v2]
    a2=x[v2, v1-1]
    a3=x[v1-1, v2]
    a4=x[v1-1, v1-1]
    print(a1-a2-a3+a4)
n = int(input())
w = [int(i) for i in input().split()]
s = []
for i in range(1,n):
  s.append(abs(sum(w[:i])-sum(w[i:]))
print(min(s))

### FIXED CODE ###

n = int(input())
w = [int(i) for i in input().split()]
s = []
for i in range(1,n):
  a = sum(w[:i])
  b = sum(w[i:])
  s.append(abs(b-a))
print(min(s))
import sys
d={}
B1=['* =',' *=']
B2=[' ****','* ***','** **','*** *','**** ']
f=0
for i in range(9): d[str(i)]=B1[i/5]+B2[i%5]
for s in sys.stdin:
  A=[d[e] for e in ('0'*5+s[:-1])[-5:]]
  if f: print
  for y in range(8): print "".join([A[x][y] for x in range(len(A))])
  f=1

### FIXED CODE ###

import sys
d={}
B1=['* =',' *=']
B2=[' ****','* ***','** **','*** *','**** ']
f=0
for i in range(10): d[str(i)]=B1[i/5]+B2[i%5]
for s in sys.stdin:
  A=[d[e] for e in ('0'*5+s[:-1])[-5:]]
  if f: print
  for y in range(8): print "".join([A[x][y] for x in range(len(A))])
  f=1
import sys
a,b,c,d=map(int,input().split())
if a+b+c+d==7:
  print('a+b+c+d=7')
  sys.exit()
if a+b+c-d==7:
  print('a+b+c-d=7')
  sys.exit()
if a+b-c+d==7:
  print('a+b-c+d=7')
  sys.exit()      
if a-b+c+d==7:
  print('a-b+c+d=7')
  sys.exit()
if a+b-c-d==7:
  print('a+b-c-d=7')
  sys.exit()
if a-b-c+d==7:
  print('a-b-c+d=7')
  sys.exit()
if a-b+c-d==7:
  print('a-b+c-d=7')
  sys.exit()
if a-b-c-d==7:
  print('a-b-c-d=7')
  sys.exit()


### FIXED CODE ###

import sys
S=input()
a,b,c,d=S[0],S[1],S[2],S[3]
lst=['+','-']
for i in lst:
  for j in lst:
    for k in lst:
      if eval(a+i+b+j+c+k+d+'==7'):
        print(a+i+b+j+c+k+d+'=7')
        sys.exit()
import math
n, k = map(int, input().split())
p = 0
for i in range(1,num):
  tmp = 1
  while i * temp < k:
    temp *= 2
  asn += 1/temp
print(p/n)

### FIXED CODE ###

import math
n, k = map(int, input().split())
p = 0
for i in range(1,n+1):
  temp = 1
  while i * temp < k:
    temp *= 2
  p += 1/temp
print(p/n)
h,w=map(int,input().split())
A=[list(input()) for i in range(h)]
B,T=set(),set()
for i in range(w):
  for j in range(h):
    T.add((i,j))
    if A[i][j]=="#":
      B.add((i,j))
T-=B
count=0
while len(T)>0:
  C=set()
  for b in B:
    if b[0]>0:
      C.add((b[0]-1,b[1]))
    if b[1]<w-1:
      C.add((b[0],b[1]+1))
    if b[0]<h-1:
      C.add((b[0]+1,b[1]))
    if b[1]>0:
      C.add((b[0],b[1]-1))
  T-=C
  B=C
  count+=1
print(count)

### FIXED CODE ###

import sys
input = sys.stdin.readline
h,w=map(int,input().split())
A=[[False]*(w+2) for _ in range(h+2)]
chk,chk2=[],[]
for i in range(h):
  s=input()
  for j in range(w):
    A[i+1][j+1]=(s[j]==".")
    if s[j]=="#":
      chk.append((i+1,j+1))
ans=0
d=((1,0),(0,1),(-1,0),(0,-1))
while chk:
  for cx,cy in chk:
    for dx, dy in d:
      if A[cx+dx][cy+dy]==True:
        chk2.append((cx+dx,cy+dy))
        A[cx+dx][cy+dy]=False
  if chk2:
    ans+=1
  chk=chk2
  chk2=[]
print(ans)
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
A1 = LI()
A2 = LI()
ans = 0
for i in range(N):
    tmp = sum(A1[0:i+1]) + sum(A2[i:])
    ans = max(ans, tmp)
print(ans)


### FIXED CODE ###

import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
A1 = LI()
A2 = LI()
ans = 0
for i in range(N):
    tmp = sum(A1[0:i+1]) + sum(A2[i:])
    ans = max(ans, tmp)
print(ans)
N = int(input())
ans = N*(N-1)//2
print(int(ans))

### FIXED CODE ###

pre = input()
gen = input()
ans=0
for i,k in zip(pre, gen):
    if i==k:
        ans+=1
print(ans)
from collections import deque

# 入力
N, M = map(int, input().split())
A, B = zip(*(map(int, input().split()) for _ in range(N - 1 + M)))

# 各頂点の深さを求め、深さを利用して元の木を復元する
G = [set() for _ in range(N + 1)]
for a, b in zip(A, B):
    G[a].add(b)
G_inv = [set() for _ in range(N + 1)]
for a, b in zip(A, B):
    G_inv[b].add(a)

r = next(i for i in range(1, N + 1) if not G_inv[i])

dp = [0 for _ in range(N + 1)]
q = deque([r])
while q:
    i = q.popleft()
    for j in G[i]:
        dp[j] = dp[i] + 1
        q.append(j)

ans = '\n'.join(
    str(max(G_inv[i], key=lambda j: dp[j], default=0))
    for i in range(1, N + 1)
)

# 出力
print(ans)


### FIXED CODE ###

from collections import deque

# 入力
N, M = map(int, input().split())
A, B = zip(*(map(int, input().split()) for _ in range(N - 1 + M)))

# 各頂点の深さを求め、深さを利用して元の木を復元する
G = [set() for _ in range(N + 1)]
G_inv = [set() for _ in range(N + 1)]
for a, b in zip(A, B):
    G[a].add(b)
    G_inv[b].add(a)
deg = [len(G_inv[i]) for i in range(N + 1)]
V = [i for i in range(1, N + 1) if not G_inv[i]]
deq = deque(V)
while deq:
    i = deq.popleft()
    for j in G[i]:
        deg[j] -= 1
        if deg[j] == 0:
            deq.append(j)
            V.append(j)

R = {i: r for r, i in enumerate(V)}
ans = '\n'.join(
    str(max(G_inv[i], key=lambda j: R[j], default=0))
    for i in range(1, N + 1)
)

# 出力
print(ans)
N, X = [int(_) for _ in input().split()]
xs = [int(_) - X for _ in input().split()]

def gcd(p, q):
    if p < 0:
        return gcd(-p, q)
    if q < 0:
        return gcd(p, -q)
    if p < q:
        return gcd(q, p)
    if p % q == 0:
        return q
    return gcd(q, p % q)

def gcdList(numbers):
    if len(numbers) == 1:
        return abs(numbers[0])
    if len(numbers) == 2:
        return gcd(numbers[0], numbers[1])
    else:
        return gcdList([gcd(numbers[0], numbers[1])] + numbers[2:])

print(gcdList(xs))

### FIXED CODE ###

N, X = [int(_) for _ in input().split()]
xs = [abs(int(_) - X) for _ in input().split()]

def gcd(p, q):
    while q != 0:
        p, q = q, p % q
    return p

y = xs[0]
for i in range(N):
    if xs[i] % y != 0:
        y = gcd(y, xs[i])

print(y)
#input
N = int(input())
A = list(map(int, input()))
B = list(map(int, input()))
C = list(map(int, input()))

#output
sum1 = sum(B)
sum2 = 0 
for i in range(N-1):
    if A[i] + 1 == A[i+1]:
        sum2 += C[(A[i]-1)]
print(sum1 + sum2)

### FIXED CODE ###

N = int(input())

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

sum1 = sum(B)
sum2 = 0 
for i in range(N-1):
    if A[i] + 1 == A[i+1]:
        sum2 += C[(A[i]-1)]
print(sum1 + sum2)
#input
N, A, B = map(int, input().split())

#output
if N*A > B:
  print(B)
elif:
  print(N*A)

### FIXED CODE ###

#input
N, A, B = map(int, input().split())
 
#output
if N*A > B:
  print(B)
else:
  print(N*A)
N,M=list(map(int,input().split()))
edge=[list(map(int,input().split())) for _ in range(M)]

current=N*(N-1)//2
ret=[0]*M

par=list(range(N+1))
cnt=[1]*(N+1)

def find(x):
    if x==par[x]:
        return x
    else:
        par[x]=find(par[x])
        return par[x]

def same(x,y):
    return find(x)==find(y)

def size(x):
    return cnt[find(x)]

def unite(x,y):
    x=find(x)
    y=find(y)

    if x==y:
        return
    
    cnt[x]+=size(y)
    par[y]=x


for i in range(M-1,-1,-1):
    ret[i]=current

    a,b=edge[i]

    if not same(a,b):
        current-=size(a)*size(b)
        unite(a,b)

for r in ret:
    print(r)

### FIXED CODE ###

N,M=list(map(int,input().split()))
edge=[list(map(int,input().split())) for _ in range(M)]

current=N*(N-1)//2
ret=[0]*M

par=list(range(N+1))
cnt=[1]*(N+1)
rank=[0]*(N+1)

def find(x):
    if x==par[x]:
        return x
    else:
        par[x]=find(par[x])
        return par[x]

def same(x,y):
    return find(x)==find(y)

def size(x):
    return cnt[find(x)]

def unite(x,y):
    x=find(x)
    y=find(y)

    if x==y:
        return 0
    
    if rank[x]<rank[y]:
        cnt[y]+=size(x)
        par[x]=y
    else:
        cnt[x]+=size(y)
        par[y]=x
        if rank[x]==rank[y]:rank[x]+=1


for i in range(M-1,-1,-1):
    ret[i]=current

    a,b=edge[i]

    if not same(a,b):
        current-=size(a)*size(b)
        unite(a,b)

for r in ret:
    print(r)
N,K = map(int, input().split())
S = sorted( list(map(int, input().split())) )
count=0

for i in S:
  if(i>K):
    count += 1
print(count)

### FIXED CODE ###

import math

N = int(input())

print( math.ceil(N/2)/N )
def dfs(G,v,p):
    for nv,nw in G[v]:
        if(nv==p):
            continue
        if(nw%2==0):
            color[nv]=color[v]
        else:
            color[nv]=int(not color[v])
        dfs(G,nv,v)
N=int(input())
G=[[] for i in range(N)]
color=[-1]*N
for i in range(N-1):
    u,v,w=map(int,input().split())
    u,v=u-1,v-1
    G[u].append((v,w))
    G[v].append((u,w))
color[0]=0
dfs(G,0,-1)
print(*color,sep='\n')

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
def dfs(G,v,p):
    for nv,nw in G[v]:
        if(nv==p):
            continue
        if(nw%2==0):
            color[nv]=color[v]
        else:
            color[nv]=int(not color[v])
        dfs(G,nv,v)
N=int(input())
G=[[] for i in range(N)]
color=[-1]*N
for i in range(N-1):
    u,v,w=map(int,input().split())
    u,v=u-1,v-1
    G[u].append((v,w))
    G[v].append((u,w))
color[0]=0
dfs(G,0,-1)
print(*color,sep='\n')
hoge = input().split()
i = 0
while i <= len(hoge):
  if i%2==0 and hoge[i] == ('L' or 'D' or 'U'):
    pass
  elif i%2==1 and hoge[i] == ('R' or 'D' or 'U'):
    pass
  else:
    break
  i+=1
if i == len(hoge):
  print('Yes')
else:
  print('No')

### FIXED CODE ###

import re
hoge = list(input())
i = 0
while i < len(hoge):
    if i%2==0 and re.findall(r'[RDU]',hoge[i]):
        pass
    elif i%2==1 and re.findall(r'[LDU]',hoge[i]):
        pass
    else:
        break
    i+=1
if i == len(hoge):
  print('Yes')
else:
  print('No')
S=input()
K=int(input())

if len(S) <= K:
    print(S)
else :
    print(S[0:K]+"...")

### FIXED CODE ###

K=int(input())
S=input()

if len(S) <= K:
    print(S)
else :
    print(S[0:K]+"...")
from math import gcd


def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    divisors.sort(reverse=True)
    return divisors


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

div = make_divisors(sum(a))

for x in div:
    s = sum([ai % x for ai in a])

    if s % 2 == 1:
        s -= k

    if s % 2 == 0 and 0 <= s <= 2 * k:
        print(x)
        break

# 3 | 3 1 2 1 | 7
# 4 | 1 2 0 1 3 2 1 0 | 10


### FIXED CODE ###

def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    divisors.sort(reverse=True)
    return divisors


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

div = make_divisors(sum(a))

for x in div:
    aa = [ai % x for ai in a]
    aa.sort()
    ss = aa[:len(aa) - sum(aa) // x]
    s = sum(ss)

    if 0 <= s <= k:
        print(x)
        break

# 2 | 3 5 | 8 _ 3
# 3 | 3 1 2 1 | 7 _ 4
# 4 | 1 2 0 1 3 2 1 0 | 10 _ 5
from itertools import groupby

S = list(input())
K = int(input())

N = len(S)

if len(set(list(S))) == 1:
    print(N * K // 2)
else:
    G = list(map(lambda g: len(list(g[1])) // 2, (groupby(S))))
    cnt = sum(G)

    if S[0] != S[N - 1]:
        print(cnt * K)
    else:
        a = G[0]
        b = G[-1]
        print(cnt * K - (a // 2 - b // 2 + (a + b) // 2) * K - 1)


### FIXED CODE ###

N = int(input())
B = list(map(int, input().split()))

res = []

while len(B) > 0:
    p = -1
    for i, b in enumerate(B[::-1]):
        j = len(B) - i
        if b == j:
            p = j
            break
    if p == -1:
        print(-1)
        exit()
    else:
        res.append(p)
        B.pop(p - 1)

for r in res[::-1]:
    print(r)
L,N = map(int, input().split())
s = sorted([input() for i in range(N)])
print("".join(s))

### FIXED CODE ###

n,l=map(int,input().split())
s=sorted([input() for i in range(n)])
print("".join(s))
N, K = map(int, input().split())
l = list(map(int, input().split()))
h = [0] * N
for i in range(N):
    h[l[i]] += 1
h.sort()
print(sum(h[:-K]))

### FIXED CODE ###

N, K = map(int, input().split())
l = list(map(int, input().split()))
h = [0] * (N + 1)
for i in range(N):
    h[l[i]] += 1
h.sort()
print(sum(h[:-K]))
n, x = [int(i) for i in input().split()]


if n == x == 0:
    break
    
count = 0
for s in range(1, n // 2 + 1):
    for e in range(n, n // 2 +1, - 1):
        m = x - s - e
        if m != s and m != e and m <= n and m > s and m < e:
            count += 1
            
    print(count)

### FIXED CODE ###

while True:
    n, x = [int(i) for i in input().split()]


    if n == x == 0:
        break

    count = 0
    for s in range(1, n - 1):
        for m in range(s+1, n):
            for e in range(m+1, n+1):
                if x == sum([s, m, e]):
                    count += 1

    print(count)
import bisect
def main():
    N, Q = map(int, input().split())
    C = list(map(int, input().split()))
    E = []

    D = {C[i]: -1 for i in range(N)}
    for i in range(N):
        if D[C[i]] == -1:
            D[C[i]] = i
        else:
            E.append((D[C[i]], i, -1))
            D[C[i]] = i

    for i in range(Q):
        l, r = map(int, input().split())
        E.append((l - 1, r - 1, i))

    def f(tup):
        return tup[0]
    E.sort(key=f, reverse=True)

    ANS = [0] * Q
    y_list = [500005]
    for e in E:
        ans = bisect.bisect_right(y_list, e[1])
        if e[2] == -1:
            y_list[ans] = e[1]
        else:
            ANS[e[2]] = e[1] - e[0] + 1 - ans

    for i in range(Q):
        print(ANS[i])

if __name__ == '__main__':
    main()

### FIXED CODE ###

from collections import defaultdict
import sys
def read():
    return sys.stdin.readline().rstrip()
def main():
    N, Q = map(int, read().split())
    C = list(map(int, read().split()))
    E = defaultdict(list)

    D = [-1] * (N + 1)
    for i in range(N):
        D_i = D[C[i]]
        if D_i != -1:
            E[D_i].append((D_i, i))
        D[C[i]] = i

    F = defaultdict(list)
    for i in range(Q):
        l, r = map(int, input().split())
        F[l-1].append((r - 1, i))



    # Binary Indexed Tree (Fenwick Tree)
    class BIT:
        def __init__(self, n):
            self.n = n
            self.data = [0] * (n + 1)
            self.el = [0] * (n + 1)

        def sum(self, i):
            s = 0
            while i > 0:
                s += self.data[i]
                i -= i & -i
            return s

        def add(self, i, x):
            # assert i > 0
            self.el[i] += x
            while i <= self.n:
                self.data[i] += x
                i += i & -i

        def get(self, i, j=None):
            if j is None:
                return self.el[i]
            return self.sum(j) - self.sum(i)

    ANS = [0] * Q
    d = BIT(N)
    for x in range(N - 1, -1, -1):
        for e in E[x]:
            d.add(e[1], 1)
        for f in F[x]:
            ANS[f[1]] = f[0] - x + 1 - d.sum(f[0])

    for i in range(Q):
        print(ANS[i])

if __name__ == '__main__':
    main()
import math
N=int(input)
print(math.factorial(N)%(10**9+7))

### FIXED CODE ###

import math
N=int(input())
print(math.factorial(N) % (10**9+7))
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 CODE ###

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()
import functools
import fractions

def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N = int(input())
    A = list(map(int, input().split()))
    A = list(set(A))
    N = len(A) + 1
  else:
    # N = 3
    # A = [7,6,8]
    # N = 3
    # A = [12,15,18]
    N = 2
    A = [1000000000,1000000000]

  x = 0
  for i in range(N):
    if N == 1 : 
      x = A[0]
    else:
      tmp = functools.reduce(fractions.gcd, A[0:i]+A[i+1:])
    if tmp > x:
      x = tmp
  
  print(x)
  
main()

### FIXED CODE ###

import functools
import fractions

def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N = int(input())
    A = list(map(int, input().split()))
  else:
    # N = 3
    # A = [7,6,8]
    N = 3
    A = [12,15,18]
    # N = 3
    # A = [1,1000000000,1000000000]

  AL = [0] * N    
  AR = [0] * N
  for i in range(N):
    if i != 0:
      AL[i] = fractions.gcd(AL[i-1],A[i])
    else:
      AL[i] = A[i]
    j = N - i - 1
    if j!= N - 1:
      AR[j] = fractions.gcd(AR[j+1],A[j])
    else:
      AR[j] = A[j]
      
  if 'get_ipython' in globals():   
    print(AL)
    print(AR)
  
  x = 0
  for i in range(N):
    if i == 0:
      tmp = AR[i+1]
    elif i == N - 1:
      tmp = AL[i-1]
    else:
      tmp = fractions.gcd(AL[i-1],AR[i+1])
    if tmp > x: x = tmp
  
  print(x)
    
main()
s = input()

for i in range(ord('a'), ord('z')+1):
 print("{0} : {1}".format(chr(i), s.count(chr(i)))

### FIXED CODE ###

import sys 
dataset = sys.stdin.readlines()

for s in range(ord('a'), ord('z') + 1):
 count = 0
 for data in dataset:
  count += data.lower().count(chr(s))
 print("{0} : {1}".format(chr(s), count))
mport sys
N,M=map(int, input().split())
a=[]
b=[]
c=[]
for m in range (0,M):
  A,B,C=map(int, input().split() )
  a+=[A]
  b+=[B]
  c+=[C]
V=[0]+[-10**12]*(N-1)# iに到達するときの最大得点
 
for n in range(N-1):
  for m in range(M):
    u=a[m]
    v=b[m]
    if V[b[m]-1]<V[a[m]-1]+c[m]:#共に有限の時はやる
      V[b[m]-1]=V[a[m]-1]+c[m]
 
moji2=[0]*N
for n in range(N):
  for m in range(M):
    u=a[m]
    v=b[m]
    if V[b[m]-1]<V[a[m]-1]+c[m]:#共に有限の時はやる
        V[b[m]-1]=V[a[m]-1]+c[m]
        moji2[b[m]-1]=1
      if moji2[N-1]:
        print("inf")
        sys.exit()
print(V[N-1])

### FIXED CODE ###

import sys
N,M=map(int, input().split())
a=[]
b=[]
c=[]
for m in range (0,M):
  A,B,C=map(int, input().split() )
  a+=[A]
  b+=[B]
  c+=[C]
V=[0]+[-10**12]*(N-1)# iに到達するときの最大得点
 
for n in range(N-1):
  for m in range(M):
    u=a[m]
    v=b[m]
    if V[b[m]-1]<V[a[m]-1]+c[m]:#共に有限の時はやる
      V[b[m]-1]=V[a[m]-1]+c[m]
 
moji2=[0]*N
for n in range(N):
  for m in range(M):
    u=a[m]
    v=b[m]
    if V[b[m]-1]<V[a[m]-1]+c[m]:#共に有限の時はやる
      V[b[m]-1]=V[a[m]-1]+c[m]
      moji2[b[m]-1]=1
      if moji2[N-1]:
        print("inf")
        sys.exit()
print(V[N-1])
from math import factorial

n,k=map(int, input().split())
mod=10**9+7

def combinations_count(n,r):
    return factorial(n) // (factorial(n-r)*factorial(r))

ans=0
for i in range(1,k+1):
    ans =combinations_count(n-k+1,i)*(i**(k-i))%mod
    print(ans)

### FIXED CODE ###

from math import factorial

n,k=map(int, input().split())
mod=10**9+7

#def combinations_count(n,r):
#    return factorial(n) // (factorial(n-r)*factorial(r))

def comb(m,r):
    if m < 0 or r < 0 or m < r: return 0
    if m==0 or r==0: return 1
    a=factorial(m)%mod
    b=factorial(r)%mod
    c=factorial(m-r)%mod
    return (a*power_func(b,mod-2)*power_func(c,mod-2))%mod

def power_func(a,b):
    if b == 0: return 1
    if b%2==0:
        d=power_func(a,b//2)
        return d*d %mod
    if b%2==1:
        return(a*power_func(a,b-1))%mod

ans=0
for i in range(1,k+1):
    temp=comb(n-k+1,i)
    temp2=comb(k-1,i-1)
    print(int(temp*temp2)%mod)