Harryxun/stf_run huggingface dataset:
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
from heapq import heappush, heappushpop

def resolve():
    it = map(int, sys.stdin.read().split())

    T = next(it)
    if T == 3: raise 1
    ans = []
    for i in range(T):
        N = next(it)

        val = 0
        a1 = [[] for i in range(N)]
        a2 = [[] for i in range(N)]
        #for i, v1, v2 in ((next(it)-1, next(it), next(it)) for i in range(N)):
        for _, i, v1, v2 in zip(range(N), it, it, it):
            i -= 1
            diff = v1 - v2
            if diff == 0 or i == N-1:
                val += v1
            elif diff > 0:
                a1[i].append(diff)
                val += v2
            else:
                i = N-1-i-1
                a2[i].append(-diff)
                val += v1

        for ax in (a1, a2):
            dq = []
            for i, aa in enumerate(ax):
                if not aa: continue
                for diff in aa:
                    ld = len(dq)
                    if ld <= i:
                        heappush(dq, diff)
                        val += diff
                    else:
                        df = heappushpop(dq, diff)
                        val += diff - df

        ans.append(val)


    print(*ans, sep="\n")



if __name__ == "__main__":
    resolve()


### FIXED CODE ###

#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
sys.setrecursionlimit(1000000000)

def resolve():
    it = map(int, sys.stdin.read().split())

    T = next(it)
    ans = []
    for i in range(T):
        N = next(it)

        val = 0; a1 = []; a2 = []
        for i, v1, v2 in ((next(it), next(it), next(it)) for i in range(N)):
            diff = v1 - v2
            a, v, diff = (a1, v2, diff) if diff >= 0 else (a2, v1, -diff)
            a.append((diff, i))
            val += v
        a1.sort(reverse=True); a2.sort(reverse=True)

        ls = len(a1)
        vis = [None]*(N+1)
        def root(x):
            if vis[x] == None: return x

            vis[x] = root(vis[x])
            return vis[x]
        def root(x):
            a = []
            while True:
                y = vis[x]
                if y == None:
                    break
                a.append(x)
                x = y
            for i in a:
                vis[i] = x
            return x

        for diff, i in a1:
            j = min(i, ls) - 1
            k = root(j)
            #print(diff, i, j, k,  vis)
            if k < 0: continue
            val += diff
            vis[k] = k - 1


        for diff, i in a2:
            j, v2 = max(i, ls), [[-1]]
            k = root(j)
            #print(diff, i, j, k,  vis)
            if k >= N: continue
            val += diff
            vis[k] = k + 1

        ans.append(val)

    print(*ans, sep="\n")



if __name__ == "__main__":
    resolve()
n=int(input())
s=input()


if(n%2==1):
  print('No')

else:  
   
    
    if s[0:n//2]==s[(n//2)+1:n]:
    print('Yes')
    else:
      print("No")
    

        
     

### FIXED CODE ###

n=int(input())
s=input()

if(n%2==1):
    print('No')
    exit()

else:  
   
    if s[0:n//2]==s[(n//2):n]:
     	print('Yes')
    else:
        print("No")
# -*- coding: utf-8 -*-
# 整数の入力
n = int(input())
h_list = input().split()
h_list = [int(h) for h in h_list]

count = 0

for i in range(n):
    a_height = h_list[i]
    for k in range(i + 1 + a_height, i+21):
        b_height = h_list[k]
        if k - i == a_height + b_height:
            count += 1

print(count)


### FIXED CODE ###

# -*- coding: utf-8 -*-
# 整数の入力
n = int(input())
h_list = input().split()
h_list = [int(h) for h in h_list]

count = 0
result_dict = {}

for i in range(n):
    key = (i+1) + h_list[i]
    value = result_dict.get(key, 0)
    result_dict[key] = value + 1

for j in range(n):
    key = (j+1) - h_list[j]
    count += result_dict.get(key, 0)

print(count)
from collections import Counter

def prime_factor(num):
  factor_list = []
  while num % 2 == 0:
    factor_list.append(2)
    num /= 2
  f = 3
  while f * f <= num:
    if num % f == 0:
      factor_list.append(f)
      num /= f
    else:
      f += 2
  if num!=1:
    factor_list.append(num)
  return factor_list

def get_count(c):
  ans = 0
  _max = c
  for i in range(1,c+1):
    if i <= _max:
      ans += 1
      _max -= i
    else:
      break
  return ans
a = int(input())
counter = Counter(prime_factor(a))
ans = 0
for i in counter:
  ans += get_count(counter[i])
print(ans)

### FIXED CODE ###

a,b = map(int,input().split())
print(a*b)
import numpy as np
s = int(input())

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)
        if len(str(divisors[-1]))<=9:
            break
    raise ValueError("error!")
    return divisors

tmp = int(np.ceil(np.sqrt(s)))
tmp2 = tmp*(tmp) - s
if tmp2<=1:
    tmp2 = tmp*(tmp+1) - s
    y3 = tmp + 1
else:
    y3 = tmp
div = make_divisors(tmp2)[-2:]

x1 = 0
y1 = 0
x2 = tmp
y2 = div[0]
try:
    x3 = div[1]
except:
    x3 = div[0]
    
print(x1, y1, x2, y2, x3, y3)

### FIXED CODE ###

import numpy as np
s = int(input())

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)
        if len(str(divisors[-1]))<=9:
            break
    return divisors

if s != 1000000000000000000:
    tmp = int(np.ceil(np.sqrt(s)))
    tmp2 = tmp*(tmp) - s
    if tmp2<=1:
        tmp2 = tmp*(tmp+1) - s
        y3 = tmp +1
    else:
        y3 = tmp
    div = make_divisors(tmp2)[-2:]

    x1 = 0
    y1 = 0
    x2 = tmp
    y2 = div[0]
    try:
        x3 = div[1]
    except:
        x3 = div[0]
    if x2==x3 and y2==y3:
        dummy = y2
        y2 = x3
        x3 = dummy
else:
    x1, y1, x2, y2, x3, y3 = 0, 0, 0, 1000000000, 1000000000, 0
    
print(x1, y1, x2, y2, x3, y3)
S = list(input())
lst = [chr(i) for i in range(97, 97+26)]
res = sorted(list(set(lst) - set(S)))

if res = []:
    print("None")
else:
    print(res[0])


### FIXED CODE ###

S = list(input())
lst = [chr(i) for i in range(97, 97+26)]
res = sorted(list(set(lst) - set(S)))

if res == []:
    print("None")
else:
    print(res[0])
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
m = 0
for i in range(N):
    m += B[a[i] - 1]
for t in range(N-1):
    if a[t] + 1 == a[t + 1]:
        m += C[a[t] - 1]
print(m)
         

### FIXED CODE ###

N=int(input())
n= N*N*N
print(n)
import scipy.misc as scm

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

a = sorted(a, reverse=True)

comb = -1
for i in range(n-1):
    if scm.comb(a[i], int(a[i]/2)) <= comb:
        break
    else:
        r_list = a[i+1:]
        for r in r_list:
            c = scm.comb(a[i], r)
            if tmp_c < c:
                tmp_c = c
                tmp_r = r
        if tmp_c > comb:
            a_i = a[i]
            a_j = tmp_r
            comb = tmp_c
print(a_i, a_j)


### FIXED CODE ###

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

a = sorted(a, reverse=True)

comb = -1
a_i = a[0]
if a_i % 2 == 0:
    mid = int(a_i/2)
    dif = 10**9
    for i in range(1, n):
        if dif > abs(a[i]-mid):
            dif = abs(a[i]-mid)
            a_j = a[i]
else:
    mid = int(a_i/2)
    dif = 10**9
    for i in range(1, n):
        if a[i] > mid:
            if dif > abs(a[i]-mid-1):
                dif = abs(a[i]-mid-1)
                a_j = a[i]
        else:
            if dif > abs(a[i]-mid):
                dif = abs(a[i]-mid)
                a_j = a[i]

print(a_i, a_j)
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

S=list(ns())
S.reverse()

modmap=[[0]*10 for i in range(10**5)]
for i in range(10):
    modmap[0][i]=i

for i in range(1,10**5):
    for j in range(10):
        modmap[i][j]=(modmap[i-1][j]*10)%13


q_list=[]
moda=0
for i in range(len(S)):
    if(S[i]=='?'):
        q_list.append(i)
    else:
        moda=(moda+modmap[i][int(S[i])])%13


modlist=[[0]*13 for i in range(len(q_list))]
mlist=[i for i in range(13)]

for i in range(10):
    modlist[0][modmap[q_list[0]][i]]=1

for i in range(1,len(q_list)):
    for j in range(10):
        tmpmod=modmap[q_list[i]][j]
        for k in range(13):
            modlist[i][(tmpmod+k)%13]+=(modlist[i-1][k]%(10**9+7))

print(modlist[len(q_list)-1][mlist[5-moda]]%(10**9+7))

### FIXED CODE ###

import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

A,B=nm()

print((A+B)//2 if (A+B)%2==0 else 'IMPOSSIBLE')
r, g, b = map(int, input().split())
if (100 * a + 10 * b + c % 4 == 0):
  print('YES')
else:
  print('NO')


### FIXED CODE ###

r, g, b = map(int, input().split())
if ((100 * r + 10 * g + b) % 4 == 0):
  print('YES')
else:
  print('NO')
N = int(input())
nums=[int(input()) for _ in range(N)]
sum_nums = sum(nums)
MAX = 10*4
dp = [0] * (MAX+1)
dp[0] = 1
for num in nums:
  for i in range(MAX+1):
    if dp[i] == 1 and i + num <= MAX:
      dp[i+num] = 1
ans = 0
for i in range(sum_nums+1):
  if dp[i] == 1 and i%10 != 0:
    ans = i
print(ans)


### FIXED CODE ###

N = int(input())
INF =101
sum_num = 0
min_num = INF

for _ in range(N):
  num = int(input())
  if num%10 != 0:
    min_num = min(min_num, num)
  sum_num += num
if min_num == INF:
  print(0)
elif sum_num%10 == 0:
  print(sum_num-min_num)
else:
  print(sum_num)
# -*- coding: utf-8 -*-
n=int(input())
x=[]
y=[]
total=[]
count=[]
for _ in range(n):
    x1,y1=map(int,input().split())
    x.append(x1)
    y.append(y1)
for i in range(n):
    for j in range(n):
        if i==j:
            continue
        else:
            temporary=(x[i]-x[j],y[i]-y[j])
            if temporary in total:
                count[total.index(temporary)]=count[total.index(temporary)]+1
            else:
                total.append(temporary)
                count.append(0)
print(n-max(count)-1)

### FIXED CODE ###

# -*- coding: utf-8 -*-
n=int(input())
x=[]
y=[]
total=[]
count=[]
for _ in range(n):
    x1,y1=map(int,input().split())
    x.append(x1)
    y.append(y1)
for i in range(n):
    for j in range(n):
        if i==j:
            continue
        else:
            temporary=(x[i]-x[j],y[i]-y[j])
            if temporary in total:
                count[total.index(temporary)]=count[total.index(temporary)]+1
            else:
                total.append(temporary)
                count.append(0)
if n==1:
    print(1)
else:
    print(n-max(count)-1)
a,b,c=map(int,input().split())
d=0
for i in range(a,b+1):
    if c%i==0:
        d+=1
print(str(d))

### FIXED CODE ###

a,b,c=map(int,raw_input().split())
d=0
for i in range(a,b+1):
    if c%i==0:
        d+=1
print(str(d))
INF = 10**10 - 1


#指定数分の３つの整数を順番に受けてリストに入力
# スペース区切りの整数入力
N,Wmax = map(int, input().split())
w = [0]*(N+1)
v = [0]*(N+1)
for i in range(1,N+1):
    w[i],v[i] = map(int, input().split())

#dpの初期化
dp = [[-INF] * (Wmax+1) for i in range(N+1)]
for i in range(0,N+1):
    dp[i][0] = 0
#print(dp[0])

for i in range(1,N+1):
    for ww in range(1,Wmax+1):
        if w[i] > ww:
            dp[i][ww] = dp[i-1][ww]        
        else:
            dp[i][ww] = max(dp[i-1][ww],dp[i-1][ww-w[i]]+v[i])
    #print(dp[i])

Vmax = 0
for ww in range(1,Wmax+1):
    Vmax = max(Vmax,dp[N][ww])
print(Vmax)


### FIXED CODE ###

INF = 10**10 - 1

#指定数分の複数の整数を順番に受けてリストに入力
N,Wmax = map(int, input().split())
w = [0]*(N+1)
v = [0]*(N+1)
Vsum = 0
for i in range(1,N+1):
    w[i],v[i] = map(int, input().split())
    Vsum += v[i]

#dpの初期化
dp = [[INF] * (Vsum+1) for i in range(N+1)]
for i in range(0,N+1):
    dp[i][0] = 0
#print(dp[0])

for i in range(1,N+1):
    for vv in range(1,Vsum+1):
        if v[i] > vv:
            dp[i][vv] = dp[i-1][vv]
        else:
            dp[i][vv] = min(dp[i-1][vv],dp[i-1][vv-v[i]]+w[i])
    #print(dp[i])

Vmax = 0
for vv in range(1,Vsum+1):
    if dp[N][vv] <= Wmax:
        Vmax = vv
print(Vmax)
n = int(input())
a = list(map(int, input().split()))

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
  
k = lcm_list(a)
cnt=0
for i in range(n):
  cnt+=k//a[i]
print(cnt)

### FIXED CODE ###

import fractions
n = int(input())
a = list(map(int, input().split()))
ans = a[0]
p = 10**9+7
for i in range(1, n):
    ans = ans * a[i] // fractions.gcd(ans, a[i])
cnt=0
for i in range(n):
  cnt+=ans//a[i]
print(cnt%p)
n,k=map(int,input().split())
l=[int(i) for i in input().split()]
right=[i for i in l if i>0]
left=[i for i in l if i<=0]
k=k-l.count(0)
le=len(left)
ri=len(right)
rl=[0]*le 
rr=[0]*ri 
left=[abs(i) for i in left]
#print(left)
left=left[::-1]
rl[0]=left[0]
for i in range(1,le):
    rl[i]=rl[i-1]+(left[i]-left[i-1])
rr[0]=right[0]
mini=10**9 
for i in range(1,ri) :
    rr[i]=rr[i-1]+(right[i]-right[i-1])
#print(rl)
#print(rr)
for a in range(1,len(left)):
    b=k-a 
    #print(a,b,rl[a],rr[b-1])
    mini=min(mini,2*rl[a-1]+rr[b-1],rl[a-1]+2*rr[b-1])
print(mini)

### FIXED CODE ###

n,k=map(int,input().split())
l=[int(i) for i in input().split()]
right=[i for i in l if i>0]
left=[i for i in l if i<=0]
if not left: 
    sm=0 
    sm+=l[0]
    for i in range(1,k):
        sm+=(l[i]-l[i-1])
    print(sm)
    exit()
if not right: 
    sm=0 
    l=[abs(i) for i in l]
    l.sort()
    sm=l[0]
    for i in range(1,k):
        sm+=(l[i]-l[i-1])
    print(sm)
    exit()
le=len(left)
ri=len(right)
rl=[0]*le 
rr=[0]*ri 
left=[abs(i) for i in left]
left=left[::-1]
rl[0]=left[0]
for i in range(1,le):
    rl[i]=rl[i-1]+(left[i]-left[i-1])
rr[0]=right[0]
mini=10**20 
for i in range(1,ri) :
    rr[i]=rr[i-1]+(right[i]-right[i-1])
if len(left)>=k:
    mini=min(mini,rl[k-1])
if len(right)>=k:
    mini=min(mini,rr[k-1])
#print(left,right,rl,rr)
for a in range(1,len(left)+1):
    b=k-a 
    #print(a,b)
    if b>len(rr):
        #print('hsef')
        continue 
    mini=min(mini,2*rl[a-1]+rr[b-1],rl[a-1]+2*rr[b-1])
print(mini)
S = input()
List = list(S)

ans = 0
arr = []
for i in range(len(List)):
  if List[i] == "A" or List[i] == "C" or List[i] == "G" or List[i] == "T":
    ans += 1
  else:
    arr.append(ans)
    ans = 0
    
print(max(arr))


### FIXED CODE ###

S = input()
List = list(S)

ans = 0
arr = []
for i in range(len(List)):
  if List[i] == "A" or List[i] == "C" or List[i] == "G" or List[i] == "T":
    ans += 1
  else:
    arr.append(ans)
    ans = 0
    
arr.append(ans)

print(max(arr))
count = 0
N,K = map(int,input().split( ))
J = list(map(int,input().split( )))
for i,j in zip(range(N),J):
    if j==1:
        s = i
        t = N-1-i
for _ in range(N+N):
    if s<=0:
        break
    else:
        s -= K-1
        count += 1

for _ in range(N+N):
    if t<=0:
        break
    else:
        t -= K-1
        count += 1
        
if N<=K:
    count = 1
print(count)

### FIXED CODE ###

kazu = 0
S = input()
for s in S:
    if s=='+':
        kazu += 1
    else:
        kazu -= 1
        
print(kazu)
n = int(raw_input())
lst = []
#store all the cards
for i in ["S","H","C","D"]:
	for j in xrange(1,14):
		lst.append("{0} {1}".format((i,j))
#discard the given cards
for i in xrange(0,n):
	a = raw_input()
	lst.remove(a)
#print the result
for i in lst:
	print i

### FIXED CODE ###

n = int(raw_input())
lst = []
#store all the cards
for i in ["S","H","C","D"]:
	for j in xrange(1,14):
		lst.append("{0} {1}".format(i,j))
#discard the given cards
for i in range(n):
	a = raw_input()
	lst.remove(a)
#print the result
for i in range(len(lst)):
	print lst[i]
def index_1_sumall(list):
    return list[1]


n, m = tuple(int(i) for i in input().split(" "))
num_list = [int(i) for i in input().split(" ")]
num_list.sort()
change_list = []
ans_list = []
for j in range(m):
    change_list.append([int(i) for i in input().split(" ")])
change_list.sort(key=index_1_sumall, reverse=1)
break_is = 0
for i in change_list:
    for j in range(i[0]):
        if i[1] > num_list[0]:
            num_list.pop(0)
            ans_list.append(i[1])
        else:
            break_is = 1
            break
    if break_is:
        break
num_list.append(0)
print(sum(num_list) + sum(ans_list))


### FIXED CODE ###

def index_1_sumall(list):
    return list[1]


n, m = tuple(int(i) for i in input().split(" "))
num_list = [int(i) for i in input().split(" ")]
num_list.sort()
change_list = []
ans_list = []
for j in range(m):
    change_list.append([int(i) for i in input().split(" ")])
change_list.sort(key=index_1_sumall, reverse=1)
break_is = 0
for i in change_list:
    for j in range(i[0]):
        try:
            if i[1] > num_list[0]:
                num_list.pop(0)
                ans_list.append(i[1])
            else:
                break_is = 1
                break
        except IndexError:
            break_is = 1
            break
    if break_is:
        break
num_list.append(0)
print(sum(num_list) + sum(ans_list))
N,K=map(int,input().split())
a=list(map(int, input().split()))
if 0 in a:
  K -=1
b=list(map(abs, a))
i=b.index(min(b))
c=list(filter(lambda x: x>=0, a))
e=sorted(c)
d=list(map(abs, filter(lambda x: x<0, a)))
f=sorted(d)

lp=len(c)
lm=len(d)
s=[]
v=[]
for i in range(lp):
    if K-i<=lm:
        if i==K:
            u=e[i-1]
        else:
            u=2*e[i-1]+f[K-i-1]
        s.append(u)
for t in range(lm):
    if K-t<=lp:
        if t==K:
            q=f[t-1]
        else:
            q=2*f[t-1]+e[K-t-1]
        s.append(q)

print(min(s))

    

### FIXED CODE ###

N,K=map(int,input().split())
a=list(map(int, input().split()))
b=list(map(abs, a))
i=b.index(min(b))
c=list(filter(lambda x: x>=0, a))
e=sorted(c)
d=list(map(abs, filter(lambda x: x<0, a)))
f=sorted(d)

lp=len(c)
lm=len(d)
s=[]
if 0 in a:
    K -=1

if K==0:
    print(0)
elif lp==0:
    print(f[K-1])
elif lm==0:
    print(e[K-1])
elif K==N:
    print(min(2*e[lp-1]+f[lm-1],2*f[lm-1]+e[lp-1]))
else:
    for i in range(lp):
        if K-i<=lm:
            if i==K:
                u=e[i-1]
            else:
                u=2*e[i-1]+f[K-i-1]
            s.append(u)
    for t in range(lm):
        if K-t<=lp:
            if t==K:
                q=f[t-1]
            else:
                q=2*f[t-1]+e[K-t-1]
            s.append(q)

    print(min(s))
import numpy as np
from copy import deepcopy


def dijkstra(N, matrix, s):
    d = [np.inf for _ in range(N)]
    d[s] = 0
    prev = [-1 for _ in range(N)]
    Q = set([i for i in range(N)])

    def min_index():
        mi = np.inf
        mii = 0
        for i in Q:
            if d[i] < mi:
                mii = i
        return mii

    while Q:
        u = min_index()
        Q.remove(u)
        for v in range(N):
            if matrix[u][v] >= 0:
                alt = d[u] + matrix[u][v]
                if d[v] > alt:
                    d[v] = alt
                    prev[v] = u
    return d


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

c = []
for _ in range(10):
    c.append([int(x) for x in input().split()])

c_tmp = deepcopy(c)

for i in range(10):
    for j in range(10):
        c_tmp[i][j] = c[j][i]

c = c_tmp

k = [0 for _ in range(10)]
for i in range(H):
    xs = [int(x) for x in input().split()]
    for x in xs:
        if x > 0:
            k[x] += 1

d = dijkstra(10, c, 1)

count = 0
for i in range(10):
    if i != 1:
        count += d[i] * k[i]

print(count)



### FIXED CODE ###

N = int(input())

counter = 0
current = 11
flag = False
while N > 0:
    tmp = N % 10
    if tmp == current:
        counter += 1
    else:
        counter = 0
        current = tmp
    if counter > 1:
        flag = True
    N = N // 10
if flag is True:
    print('Yes')
else:
    print('No')
X = int(input())

if X >= 0 and X <= 10 ** 9:
    while True:
        if X >= 500:
            C = X // 500
            X = X - (500 * C)
        elif X >= 5:
            D = X // 5
            X = X - (5 * D)
        else:
            break

total = (500 * C) + (5 * D)

print(total)

### FIXED CODE ###

X = int(input())

C = 0
P = 0
D = 0
L = 0
total = 0

if X >= 0 and X <= 10 ** 9:
    while True:
        if X >= 500:
            C = X // 500
            P = 500 * C
            X = X - P
        elif X >= 5:
            D = X // 5
            L = 5 * D
            X = X - L
        else:
            break
man = 1000 * C
t   = 5 * D

total = man + t

print(total)
import bisect
x,n=map(int,input().split())
P=list(map(int,input().split()))
Q=[]
for i in range(1,101):
    if i not in P:
        Q.append(i)

i=bisect.bisect_left(Q,x)

if abs(Q[i-1]-x)>abs(Q[i]-x):
    print(Q[i])
else:
    print(Q[i-1])

### FIXED CODE ###

x,n=map(int,input().split())
P=list(map(int,input().split()))
Q=[-1,0]
for i in range(1,102):
    if i not in P:
        Q.append(i)

ans=10**9
A=[]
for i,q in enumerate(Q):
    A.append([i,abs(q-x)])
A.sort(key=lambda x:(x[1],x[0]))
print(Q[A[0][0]])
import math

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

A.sort()
A[1]=A[0]
ans=A[0]
for i in range(N):
    ans=math.gcd(ans,A[i])
print(ans)

### FIXED CODE ###

import fractions

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

L=[0,A[0]]
R=[0,A[-1]]
for i in range(N-1):
    #l=fractions.gcd(L[i+1],A[i+1])
    #r=fractions.gcd(R[i+1],A[N-i-2])
    L.append(fractions.gcd(L[i+1],A[i+1]))
    R.append(fractions.gcd(R[i+1],A[N-i-2]))
    #print(L[i+1],A[i+1],R[i+1],A[N-i-2])
#print(L)
#print(R)
arr=[]
for i in range(N):
    a=fractions.gcd(L[i],R[N-i-1])
    arr.append(a)
    #print(i,L[i],R[N-i-1],a,arr)
print(max(arr))
n,x=map(int,input().split())
l=list(map(int,input().split()))
def gcd(n,m):
  a=max(n,m)
  b=min(n,m)
  while b!=0:
    a,b=b,a%b
  return a
a=abs(l[0]-x)
for i in range(l):
  a=gcd(a,abs(l[i]-x))
print(a)

### FIXED CODE ###

n,x=map(int,input().split())
l=list(map(int,input().split()))
def gcd(n,m):
  a=max(n,m)
  b=min(n,m)
  while b!=0:
    a,b=b,a%b
  return a
a=abs(l[0]-x)
for i in range(n):
  a=gcd(a,abs(l[i]-x))
print(a)
_ = input()
lst = map(int, input().split())

print(max(lst) - min(lst))

### FIXED CODE ###

_ = input()
lst = [int(i) for i in input().split()]

print(max(lst) - min(lst))
n=input()
line[n]
x=int(line[1])
y=int(line[3])
print(x*y)

### FIXED CODE ###

a,b,c,d=map(int,input().split( ))
print(max(a*d,b*c,a*c,b*d))
import math
r=int(input())
print("{:6f} {:6f}".format(r**2*math.pi,r*2*math.pi))

### FIXED CODE ###

import math
r=float(input())
print("{:0.6f} {:0.6f}".format(r**2*math.pi,r*2*math.pi))
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

m, d = na()
if d < 22:
    print(0)
else:
    d10max = int(str(d)[0])
    d1max = int(str(d)[1])
    c = 0
    if d1max < 2:
        for d10 in range(2, int(str(d)[0])):
            for i in range(2, 9):
                if d10 * i <= m:
                    c += 1
    else:
        for d10 in range(2, int(str(d)[0])):
            for i in range(2, 9):
                if d10 * i <= m:
                    c += 1

        for i in range(2, d1max+ 1):
            if d10 * i <= m:
                c += 1
    print(c)




### FIXED CODE ###

import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

m, d = na()
if d < 22:
    print(0)
else:
    d10max = int(str(d)[0])
    d1max = int(str(d)[1])
    c = 0
    for d10 in range(2, d10max):
        for i in range(2, 10):
            if d10 * i <= m:
                c += 1

    for i in range(2, d1max+ 1):
        if d10max * i <= m:
            c += 1
    print(c)
n = int(input().split())
list = map(int, input()split())

sum = 0
for i in range(n)
    sum += list[i]

print(min(list), max(list), sum)


### FIXED CODE ###

#
# 4d
#


def main():
    n = int(input())
    a = list(map(int, input().split()))
    print(f"{min(a)} {max(a)} {sum(a)}")


if __name__ == '__main__':
    main()