CodeEff/ECCO huggingface dataset:
# Original solution
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


class UnionFind:
    # Reference: https://note.nkmk.me/python-union-find/
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

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


def main():
    N, M = list(map(int, readline().split()))
    P = [int(s) - 1 for s in readline().split()]
    XY = list(map(int, read().split()))

    uf = UnionFind(N)
    for x, y in zip(*[iter(XY)] * 2):
        uf.union(x - 1, y - 1)

    Q = [0] * N
    for i, p in enumerate(P):
        Q[p] = i

    ans = 0
    for i, p in enumerate(P):
        if i == p or uf.same(i, Q[i]):
            ans += 1

    print(ans)
    return


if __name__ == '__main__':
    main()


# Optimized solution
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


class UnionFind:
    # Reference: https://note.nkmk.me/python-union-find/
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

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


def main():
    N, M = list(map(int, readline().split()))
    P = [int(s) - 1 for s in readline().split()]
    XY = list(map(int, read().split()))

    uf = UnionFind(N)
    for x, y in zip(*[iter(XY)] * 2):
        uf.union(x - 1, y - 1)

    ans = 0
    for i, p in enumerate(P):
        if i == p or uf.same(i, p):
            ans += 1

    print(ans)
    return


if __name__ == '__main__':
    main()
# Original solution
tmp = list(map(int,input().split()))
n,p,q = tmp[0],tmp[1],tmp[2]
cs = []
for i in range(n):
    cs.append(int(eval(input())))
ans = [sum(cs)]
difs = [p * (q-i) - cs[i] for i in range(n)]
difs.sort(reverse = True)
for i in range(n):
    ans.append(ans[-1] + 2 * i * p + difs[i])
print((max(ans)))



# Optimized solution
#着席位置は中央*奥
#問題は「Dinner」(http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2642&lang=jp)
#方針としては、自炊をする回数(0~n)を決め打ちし、それぞれの時の最大値を計算してその最大値を返すことにする
#n回自炊するとき、自炊パワーはn-1回自壊する時に比べ最終的に2増える。
#これを考えると、n回自炊する時、高まる自炊パワーによる幸福度の増加分はn*(n+1)となる
#したがって、まずリストdifsに「自炊と食堂の幸福度の差分」を全て入れる
#これを降順にソートし、n回自炊した時の幸福度の最大値をansに入れていく
#ansの最大値を出力して、終了
n,p,q = list(map(int,input().split()))
cs = []
for i in range(n):
    cs.append(int(eval(input())))
ans = [sum(cs)]
difs = [p * (q-i) - cs[i] for i in range(n)]
difs.sort(reverse = True)
for i in range(n):
    ans.append(ans[-1] + 2 * i * p + difs[i])
print((max(ans)))
# Original solution
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


a,b,c,d = MI()
print((max(a*c,a*d,b*c,b*d)))


# Optimized solution
import sys
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))


a,b,c,d = MI()
print((max(a*c,a*d,b*c,b*d)))
# Original solution
a,b,c,d=list(map(int,input().split()))
ans=0
if a>=0:
    if c>=0:
        ans=b*d
    elif d>=0:
        ans=b*d
    else:
        ans=a*d
elif b>=0:
    if c>=0:
        ans=b*d
    elif d>=0:
        ans=max(b*d,a*c)
    else:
        ans=a*c
else:
    if c>=0:
        ans=b*c
    elif d>=0:
        ans=a*c
    else:
        ans=a*c
print(ans)

# Optimized solution
a,b,c,d=list(map(int,input().split()))
ans=max(a*c,a*d,b*c,b*d)
print(ans)
# Original solution
def LI():return list(map(int,input().split()))
def II():return int(input())
def yes():return print("Yes")
def no():return print("No")
INF=float("inf")
from collections import deque, defaultdict, Counter
from heapq import heappop, heappush
from itertools import product, combinations
from functools import reduce, lru_cache
from math import pi, gcd
from decimal import Decimal

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

class Unionfind:
    def __init__(self, N):
        self.p = list(range(N))
        self.rank = [0] * N
        self.size = [1] * N

    def root(self, x):
        if self.p[x] != x:
            self.p[x] = self.root(self.p[x])

        return self.p[x]

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        u = self.root(x)
        v = self.root(y)

        if u == v: return

        if self.rank[u] < self.rank[v]:
            self.p[u] = v
            self.size[v] += self.size[u]
            self.size[u] = 0
        else:
            self.p[v] = u
            self.size[u] += self.size[v]
            self.size[v] = 0

            if self.rank[u] == self.rank[v]:
                self.rank[u] += 1

    def count(self, x):
        return self.size[self.root(x)]


a,b,c,d=LI()

print(max(a*c,b*c,a*d,b*d))


# Optimized solution
a,b,c,d=list(map(int,input().split()))
print((max(a*c,a*d,b*c,b*d)))
# Original solution
#!/usr/bin/env python3

import sys
input=sys.stdin.readline

a,b,c,d=list(map(int,input().split()))
ans=-10**18
#x=0 or y=0
if a<=0<=b or c<=0<=d:
    ans=max(ans,0)
#x<0 and y>0
ans=max(ans,b*c)
#x>0 and y>0
ans=max(ans,b*d)
#x<0 and y<0
ans=max(ans,a*c)
#x>0 and y<0
ans=max(ans,a*d)
print(ans)

# Optimized solution
ans=-10**18
a,b,c,d=list(map(int,input().split()))
if a<=0<=b or c<=0<=d:
  ans=0
ans=max(ans,a*c,a*d,b*c,b*d)
print(ans)
# Original solution
a=list(map(int,input().split()))
b=a[0]*a[2]
c=a[0]*a[3]
d=a[1]*a[2]
e=a[1]*a[3]
print((max(b,c,d,e)))

# Optimized solution
t=list(map(int,input().split()))
print((max(t[0]*t[2],t[0]*t[3],t[1]*t[2],t[1]*t[3])))
# Original solution
a,b,c,d = list(map(int,input().split()))
print((max([a*c,a*d,b*c,b*d])))


# Optimized solution
a,b,c,d = list(map(int,input().split()))
ans=[]
for X in [a,b]:
  for Y in [c,d]:
    ans.append(X*Y)
print((max(ans)))
# Original solution
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    a, b, c, d = list(map(int, readline().split()))

    ans = -INF

    for x in (a, b):
        for y in (c, d):
            ans = max(ans, x * y)

    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
a, b, c, d = list(map(int, input().split()))

ans = -float("INF")  # 答えがマイナスになることがあるので、負の無限大を初期値にしておきます

for x in (a, b):
    for y in (c, d):
        ans = max(ans, x * y)

print(ans)
# Original solution
a,b,c,d=list(map(int,input().split()))
print((max(max(max(a*c,a*d),b*c),b*d)))

# Optimized solution
a,b,c,d=list(map(int,input().split()))
l=[a*c,a*d,b*c,b*d]
print((max(l)))
# Original solution
def l_in(type_): return list(map(type_, input().split()))
def i_in(): return int(eval(input()))
def m_in(type_): return list(map(type_, input().split()))
def r_in(n, type_): return [type_(eval(input())) for _ in range(n)]
ans = None

def absmax(a, b):
    if abs(a) > abs(b): return a
    return b

def absmin(a, b):
    if abs(a) < abs(b): return a
    return b

a, b, c, d = m_in(int)
aa, bb, cc, dd = abs(a), abs(b), abs(c), abs(d)
x, y = 0, 0

abm = absmax(a, b)
cdm = absmax(c, d)
if (abm>0) == (cdm>0):
    ans = abm*cdm
else:
    abi = absmin(a, b)
    cdi = absmin(c, d)
    if (abi>0) == (cdm>0):
        k = abi*cdm
        if ans is None or k > ans: ans = k
    if (abm>0) == (cdi>0):
        k = abm*cdi
        if ans is None or k > ans: ans = k
    k = abi*cdi
    if ans is None: ans = k

print(ans)


# Optimized solution
def l_in(type_): return list(map(type_, input().split()))
def i_in(): return int(eval(input()))
def m_in(type_): return list(map(type_, input().split()))
def r_in(n, type_): return [type_(eval(input())) for _ in range(n)]
ans = None

a, b, c, d = m_in(int)
ans = max(a*c, a*d, b*c, b*d)

print(ans)
# Original solution
from sys import stdin


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    a, b, c, d = list(map(int, _in[0].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = -float('inf')
    cnt = max(cnt, a * c)
    cnt = max(cnt, a * d)
    cnt = max(cnt, b * c)
    cnt = max(cnt, b * d)
    ans = cnt
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(ans)


if __name__ == "__main__":
    main()


# Optimized solution
from sys import stdin


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    a, b, c, d = list(map(int, _in[0].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    ans = -float('inf')
    for _ in [a * c, a * d, b * c, b * d]:
        ans = max(ans, _)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(ans)


if __name__ == "__main__":
    main()
# Original solution
a, b, c, d = list(map(int, input().split()))
answer = 0

if a < 0 and 0 <= b:
    if c < 0 and 0 <= d:
        answer = max(a * c, b * d)
    elif 0 <= c and 0 <= d:
        answer = b * d 
    elif c < 0 and d < 0:
        answer = a * c

elif 0 <= a and 0 <= b:
    if c < 0 and 0 <= d:
        answer = b * d
    elif 0 <= c and 0 <= d:
        answer = b * d
    elif c < 0 and d < 0:
        answer = a * d

elif a < 0 and b < 0:
    if c < 0 and 0 <= d:
        answer = a * c
    elif 0 <= c and 0 <= d:
        answer = b * c
    elif c < 0 and d < 0:
        answer = a * c

print(answer)

# Optimized solution
a, b, c, d = list(map(int, input().split()))
answer = max(a*c, a*d, b*c, b*d)
print(answer)
# Original solution
a,b,c,d = list(map(int, input().split()))

ans = b*d
ans = max(ans, a*c)
ans = max(ans, b*d)
ans = max(ans, a*d)
ans = max(ans, b*c)
print(ans)


# Optimized solution
a, b, c, d = list(map(int, input().split()))
print((max(a*c, a*d, b*c, b*d)))
# Original solution
a,b,c,d=list(map(int,input().split()))
X=[a,b]
Y=[c,d]
ans=-10**30
for x in X:
    for y in Y:
        if ans<x*y:
            ans=x*y
print(ans)



# Optimized solution
a,b,c,d=list(map(int,input().split()))
print((max(a*c,a*d,b*c,b*d)))
# Original solution
a, b, c, d = list(map(int, input().split()))
if a > 0 and b > 0 and c > 0 and d > 0:
  print((max(a,b)*max(c,d)))
elif a == 0 or b == 0 or c == 0 or d == 0:
  print((max([a*c, a*d, b*c, b*d])))
else:
  res = []
  for i in range(a, b+1):
    for j in range(c, d+1):
      res.append(i*j)
  print((max(res)))

# Optimized solution
a, b, c, d = list(map(int, input().split()))
print((max([a*c, b*c, a*d, b*d])))
# Original solution
(X1,X2,Y1,Y2)=list(map(int,input().split()))
ans=X2*Y2
ans=max(ans,X1*Y1)
ans=max(ans,X1*Y2)
ans=max(ans,X2*Y1)
print (ans)

# Optimized solution
(X1,X2,Y1,Y2)=list(map(int,input().split()))
ans=max(X2*Y2,X1*Y1,X1*Y2,X2*Y1)
print (ans)
# Original solution
a, b, c, d = list(map(int, input().split()))
cnt = []
if a == c and b == d:
    print((max(a*c, b*d)))
    exit()
else:
    for i in range(a, b+1):
        for j in range(c, d+1):
            cnt.append(i*j)
            
C = sorted(cnt)
print((max(C[0],C[-1])))


# Optimized solution
a, b, c, d = list(map(int,input().split()))

if a == c and b == d:
    print((max(a*c, b*d)))
    exit()
else:
    print((max(a*c, a*d,b*c,b*d)))
# Original solution
a,b,c,d=list(map(int,input().split()))

if a>=0:
    if c>=0:
        print((b*d))
    elif c<0 and d>=0:
        print((b*d))
    elif d<0:
        print((a*d))

elif a<0 and b>=0:
    if c>=0:
        print((b*d))
    elif c<0 and d>=0:
        print((max(a*c,b*d)))
    elif d<0:
        print((a*c))

elif b<0:
    if c>=0:
        print((b*c))
    elif c<0 and d>=0:
        print((a*c))
    elif d<0:
        print((a*c))


# Optimized solution
a,b,c,d=list(map(int,input().split()))
maxxy=max(a*c,a*d,b*c,b*d)
print(maxxy)
# Original solution
a, b, c, d = list(map(int, input().split()))

minx = min(a, b)
miny = min(c, d)
maxx = max(a, b)
maxy = max(c, d)

print((max(miny * minx, maxx * maxy, maxx * miny, minx * maxy)))


# Optimized solution
a, b, c, d = list(map(int, input().split()))

print((max(a * c, b * d, b * c, a * d)))
# Original solution
import itertools
a,b,c,d=list(map(int,input().split()))
ans=-10**9

if  b<=0 and d<=0:
    ans=a*c

else :
    x=list(int(x) for x in range(a,b+1))
    y=list(int(y) for y in range(c,d+1))
    l=list(itertools.product(x, y))
    
    for i in range(len(l)):
        if ans<l[i][0]*l[i][1]:
            ans=l[i][0]*l[i][1]

print(ans)

# Optimized solution
a,b,c,d=list(map(int,input().split()))
ans=max(a*c,a*d,b*c,b*d)
print(ans)
# Original solution
def main():
    a, b, c, d = list(map(int, input().split()))
    if (a <= 0 and b >= 0) or (c <=0 and d >= 0):
        print((max(a*c, b*d, 0)))
    else:
        print((max(a*c, b*d, a*d, b*c)))

if __name__ == "__main__":
    main()

# Optimized solution
def main():
    a, b, c, d = list(map(int, input().split()))
    if a*b > 0 and c*d > 0 and a*c < 0:
        print((max(a*d, b*c)))
    else:
        print((max(a*c, b*d, 0)))

if __name__ == "__main__":
    main()
# Original solution
a,b,c,d = list(map(int, input().split()))
t = list()
ac = a*c
bc = b*c
ad = a*d
bd = b*d
t.append(ac)
t.append(bc)
t.append(ad)
t.append(bd)
ans = -1 * 10**18
for i in range(4):
  ans = max(t[i],ans)
print(ans)

# Optimized solution
a,b,c,d = list(map(int, input().split()))

ans = max(a*c, a*d, b*c, b*d)
print(ans)
# Original solution
from collections import Counter
import copy

N = int(eval(input()))
D = list(map(int, input().split()))
if N == 1:
    print((min(D[0], 24-D[0])))
    exit()

D.append(0)
D.append(24)

c = Counter(D)

times = []
p = []
for num, cnt in list(c.items()):
    if (num == 0 or num == 12) and cnt >= 2:
        # D==24-D になるかつ時差０の組がいるので時差の最小は０で確定
        print((0))
        exit()
    elif cnt >= 3:
        # 時差０の組み合わせがある
        print((0))
        exit()
    elif cnt == 2:
        # Dと24-Dに一人ずつ
        times.append(num)
        times.append(24-num)
    elif cnt == 1:
        # D or 24-D のどちらか一方に一人だけいる状態なので別枠で確保
        p.append((num, 24-num))

num_b = len(p)
ans = 0
# D or 24-Dの可能性があるものについて全パターン試すために、2進表記を利用
for b in range(2**num_b):
    b = bin(b)[2:].zfill(num_b)
    time = copy.deepcopy(times)
    for i in range(num_b):
        if b[i] == "0":
            time.append(p[i][0])
        else:
            time.append(p[i][1])
    tmp = 24
    for i in range(len(time)):
        for j in range(i+1, len(time)):
            tmp = min(tmp, abs(time[i] - time[j]))

    ans = max(ans, tmp)

print(ans)

# Optimized solution
from collections import Counter
import copy

N = int(eval(input()))
D = list(map(int, input().split()))
if N == 1:
    print((min(D[0], 24-D[0])))
    exit()

D.append(0)
D.append(24) # 24-0のパターン

c = Counter(D)

times = []
p = []
for num, cnt in list(c.items()):
    if (num == 0 or num == 12) and cnt >= 2:
        # D==24-D になるかつ時差０の組がいるので時差の最小は０で確定
        print((0))
        exit()
    elif cnt >= 3:
        # 時差０の組み合わせがある
        print((0))
        exit()
    elif cnt == 2:
        # Dと24-Dに一人ずつ
        times.append(num)
        times.append(24-num)
    elif cnt == 1:
        # D or 24-D のどちらか一方に一人だけいる状態なので別枠で確保
        p.append((num, 24-num))

num_b = len(p)
ans = 0
# D or 24-Dの可能性があるものについて全パターン試すために、2進表記を利用
for b in range(2**num_b):
    b = bin(b)[2:].zfill(num_b)
    time = copy.deepcopy(times)
    for i in range(num_b):
        if b[i] == "0":
            time.append(p[i][0])
        else:
            time.append(p[i][1])
    tmp = 24
    for i in range(len(time)):
        for j in range(i+1, len(time)):
            tmp = min(tmp, abs(time[i] - time[j]))

    ans = max(ans, tmp)

print(ans)
# Original solution
from collections import Counter
import copy

N = int(eval(input()))
D = list(map(int, input().split()))
if N == 1:
    print((min(D[0], 24-D[0])))
    exit()

D.append(0)
D.append(24) # 24-0のパターン

c = Counter(D)

times = []
p = []
for num, cnt in list(c.items()):
    if (num == 0 or num == 12) and cnt >= 2:
        # D==24-D になるかつ時差０の組がいるので時差の最小は０で確定
        print((0))
        exit()
    elif cnt >= 3:
        # 時差０の組み合わせがある
        print((0))
        exit()
    elif cnt == 2:
        # Dと24-Dに一人ずつ
        times.append(num)
        times.append(24-num)
    elif cnt == 1:
        # D or 24-D のどちらか一方に一人だけいる状態なので別枠で確保
        p.append((num, 24-num))

num_b = len(p)
ans = 0
# D or 24-Dの可能性があるものについて全パターン試すために、2進表記を利用
for b in range(2**num_b):
    b = bin(b)[2:].zfill(num_b)
    time = copy.deepcopy(times)
    for i in range(num_b):
        if b[i] == "0":
            time.append(p[i][0])
        else:
            time.append(p[i][1])
    tmp = 24
    for i in range(len(time)):
        for j in range(i+1, len(time)):
            tmp = min(tmp, abs(time[i] - time[j]))

    ans = max(ans, tmp)

print(ans)

# Optimized solution


from collections import Counter
from collections import defaultdict

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




c = Counter(D)


# 高橋君と同じ時間帯の人が一人でもいれば、時差の最小は常に0
if c[0] >= 2:
    print((0))
    exit(0)

# 高橋君との時差がdの人が3人以上いる場合も、時差の最小は常に0（同じ時間帯の都市に二人以上いることになるから）
for i in list(c.values()):
    if i >= 3:
        print((0))
        exit()


times = defaultdict(int)
c[0] += 1
# 0時との時間差をとるときに24がいたほうがよいか？なくてもいいか。
c[24] += 1
before_12 = True
D.sort()
for d in D:
    if before_12:
        times[d] += 1
        before_12 = False
    else:
        times[24-d] += 1
        before_12 = True


# 高橋君との時差で答えを初期化
ans = min(D)

tlst = list(times.keys())
tlst.sort()

for a,b in zip(tlst, tlst[1:]):
    ans = min(ans, b - a)

print(ans)
# Original solution


from collections import Counter
from collections import defaultdict

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




c = Counter(D)


# 高橋君と同じ時間帯の人が一人でもいれば、時差の最小は常に0
if c[0] >= 2:
    print((0))
    exit(0)

# 高橋君との時差がdの人が3人以上いる場合も、時差の最小は常に0（同じ時間帯の都市に二人以上いることになるから）
for i in list(c.values()):
    if i >= 3:
        print((0))
        exit()


times = defaultdict(int)
c[0] += 1
# 0時との時間差をとるときに24がいたほうがよいか？なくてもいいか。
c[24] += 1
before_12 = True
D.sort()
for d in D:
    if before_12:
        times[d] += 1
        before_12 = False
    else:
        times[24-d] += 1
        before_12 = True


# 高橋君との時差で答えを初期化
ans = min(D)

tlst = list(times.keys())
tlst.sort()

for a,b in zip(tlst, tlst[1:]):
    ans = min(ans, b - a)

print(ans)


# Optimized solution


from collections import Counter
from collections import defaultdict

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




c = Counter(D)

c[0] += 1
# 高橋君と同じ時間帯の人が一人でもいれば、時差の最小は常に0
if c[0] >= 2:
    print((0))
    exit(0)

# 高橋君との時差がdの人が3人以上いる場合も、時差の最小は常に0（同じ時間帯の都市に二人以上いることになるから）
for i in list(c.values()):
    if i >= 3:
        print((0))
        exit()


times = defaultdict(int)

# 0時との時間差をとるときに24がいたほうがよいか？なくてもいいか。
c[24] += 1
before_12 = True
D.sort()
for d in D:
    if before_12:
        times[d] += 1
        before_12 = False
    else:
        times[24-d] += 1
        before_12 = True


# 高橋君との時差で答えを初期化
ans = min(D)

tlst = list(times.keys())
tlst.sort()

for a,b in zip(tlst, tlst[1:]):
    ans = min(ans, b - a)

print(ans)
# Original solution
N = int(eval(input()))
D = list(map(int, input().split()))

if N >= 24:
    print((0))

else:
    res = 0
    for bit in range(2**N):
        d = [0 for _ in range(24)]
        for i in range(N):
            if (bit >> i) & 1:
                d[D[i]] += 1
            else:
                d[(24 - D[i]) % 24] += 1
        md = 25
        tmp = 0
        for i in range(24):
            if d[i] > 1:
                md = 0
                break
            elif d[i] == 1:
                md = min(md, i - tmp)
                tmp = i
        md = min(24 - tmp, md)
        res = max(res, md)
    print(res)

# Optimized solution
N = int(eval(input()))
D = list(map(int, input().split()))

if N >= 24:
    print((0))

elif N == 23:
    d = [0 for _ in range(13)]
    d[0] = 1
    for i in range(N):
        d[D[i]] += 1
    if d[0] > 1 or d[12] > 1:
        print((0))
    else:
        for i in range(1, 12):
            if d[i] > 2:
                print((0))
                break
        else:
            print((1))

else:
    res = 0
    for bit in range(2**N):
        d = [0 for _ in range(24)]
        d[0] = 1
        for i in range(N):
            if (bit >> i) & 1:
                d[D[i]] += 1
            else:
                d[(24 - D[i]) % 24] += 1
        s = 25
        tmp = 0
        if d[0] > 1:
            s = 0
        else:
            for i in range(1, 24):
                if d[i] > 1:
                    s = 0
                    break
                elif d[i] == 1:
                    s = min(s, i - tmp)
                    tmp = i
            s = min(s, (24 - tmp) % 24)
        res = max(res, s)
    print(res)
# Original solution
from collections import Counter
from itertools import product


def solve(LIST):
    stmp = [i for i, li in enumerate(LIST * 2) if li == 1]
    S = min(stmp[i] - stmp[i - 1] for i in range(1, len(stmp)))
    return S


n = int(eval(input()))
d = Counter(list(map(int, input().split())) + [0])

if any(d[num] > (2 - (num in {0, 12})) for num in d):
    print((0))
    exit()

ans, cnt = [0] * 24, []
for num in d:
    if (num in {0, 12}) and d[num] == 1:
        ans[num] = 1 
    elif d[num] == 2:
        ans[num], ans[24 - num] = 1, 1
    elif d[num] == 1:
        cnt.append(num)

s = 0
if len(cnt) == 0:
    s = max(s, solve(ans))
for bit in product([1, -1], repeat=len(cnt)):
    tmp = ans[:]
    for bi, ci in zip(bit, cnt):
        tmp[(ci - 12) * bi + 12] = 1
    s = max(s, solve(tmp))
print(s)


# Optimized solution
n = int(eval(input()))
d = sorted(list(map(int, input().split())) + [0])

bit, cnt = [0] * 24, 1
for num in d:
    bit[((num - 12) * cnt + 12) % 24] += 1
    cnt *= -1

if any(i > 1 for i in bit):
    print((0))
    exit()
ans = [i for i, li in enumerate(bit * 2) if li == 1]
s = min(ans[i] - ans[i - 1] for i in range(1, len(ans)))
print(s)