Harryxun/stf_run huggingface dataset:
N=int(input())
K=int(input()) 
S=list(map(int, input().split()))
total=0
for i in range(A):
    if abs(S[i]-K)<S[i]:
        total+=abs(S[i]-K)*2
    else:
        total+=2*S[i]
print(total)

### FIXED CODE ###

N=int(input())
K=int(input()) 
S=list(map(int, input().split()))
total=0
for i in range(N):
    if abs(S[i]-K)<S[i]:
        total+=abs(S[i]-K)*2
    else:
        total+=2*S[i]
print(total)
from collections import deque

MOD = 10**9 + 7

def rec(vNow, vPar):
    W, B = 1, 1
    for v2 in adjL[vNow]:
        if v2 == vPar: continue
        W2, B2 = rec(v2, vNow)
        W = (W * (W2+B2)) % MOD
        B = (B * W2) % MOD
    return (W, B)

N = int(input())
adjL = [[] for v in range(N)]
for _ in range(N-1):
    x, y = map(int, input().split())
    adjL[x-1].append(y-1)
    adjL[y-1].append(x-1)

print(sum(rec(0, -1)) % MOD)


### FIXED CODE ###

from collections import deque

MOD = 10**9 + 7

N = int(input())
adjL = [[] for v in range(N)]
degs = [0] * N
for _ in range(N-1):
    x, y = map(int, input().split())
    adjL[x-1].append(y-1)
    adjL[y-1].append(x-1)
    degs[x-1] += 1
    degs[y-1] += 1

dpWhite = [1] * N
dpBlack = [1] * N
vNow = 0
Q = deque([v for v in range(N) if degs[v] == 1])
while Q:
    vNow = Q.popleft()
    if degs[vNow] == 0: break
    dpW, dpB = dpWhite[vNow], dpBlack[vNow]
    for v2 in adjL[vNow]:
        if degs[v2] == 0: continue
        dpWhite[v2] *= dpW + dpB
        dpWhite[v2] %= MOD
        dpBlack[v2] *= dpW
        dpBlack[v2] %= MOD
        degs[v2] -= 1
        if degs[v2] == 1:
            Q.append(v2)
    degs[vNow] = 0

print((dpWhite[vNow] + dpBlack[vNow]) % MOD)
a = int(input())

ans = a(1+a+a**2)
print(int(ans))

### FIXED CODE ###

a = int(input())

ans = a + a**2 + a**3
print(int(ans))
W, H, N = map(int, input().split(' '))
minx = 0
maxx = W
miny = 0
maxy = H
for i in range(N):
    x, y, a = map(int, input().split(' '))
    if a == 1:
        minx = max(minx, x)
    elif a == 2:
        maxx = min(maxx, x)
    elif a == 3:
        miny = max(miny, y)
    else:
        maxy = min(maxy, y)
if minx <= maxx and miny <= maxy:
    print((maxx-minx) * (maxy-miny))
else:
    print(0)

### FIXED CODE ###

W, H, N = map(int, input().split(' '))
minx = 0
maxx = W
miny = 0
maxy = H
for i in range(N):
    x, y, a = map(int, input().split(' '))
    if a == 1:
        minx = max(minx, x)
    elif a == 2:
        maxx = min(maxx, x)
    elif a == 3:
        miny = max(miny, y)
    else:
        maxy = min(maxy, y)
if minx <= maxx and miny <= maxy:
    print((maxx-minx) * (maxy-miny))
else:
    print(0)
a_list=("abcdefghijklmnopqrstuvwxyz")
word=(raw_input())
flag=0
out="None"
for i in a_list:
    for n,k in enumerate(word):
        if i==k:
            break
        if n==len(word)-1:
            out=i
            flag=1
    if flag==1:
        break
print(out)

### FIXED CODE ###

a_list=("abcdefghijklmnopqrstuvwxyz")
word=(raw_input())
flag=0
out="None"
for i in a_list:
    for n,k in enumerate(word):
        if i==k:
            break
        if n==len(word)-1:
            out=i
            flag=1
    if flag==1:
        break
print(out)
import sys
import datetime

lines = sys.stdin.readlines()
X = lines[0]

d = datetime.datetime.strptime(X, '%Y/%m/%d')

if d > datetime.datetime(2019,4,30):
  print('TBD')
else:
  print('Heisei')



### FIXED CODE ###

import sys

lines = sys.stdin.readlines()
S = lines[0]

Ss = S.split('/')

if int(Ss[0]) >= 2019:
  if int(Ss[1]) >= 5:
    print('TBD')
    exit(0)
print('Heisei')
n,c=map(int,input().split())
lists=[[] for i in range(31)]
for i in range(n):
    s,t,c=map(int,input().split())
    lists[c].append((s,t))
for i in range(31):
    lists[c]=sorted(lists[c],key=lambda x:x[0])

for i in range(1,31):
    if len(lists[i])>=2:
        sublists=[]
        start=lists[i][0][0]
        end=lists[i][0][1]
        for j in range(1,len(lists[i])):
                if end==lists[i][j][0]:
                    start=start
                    end=lists[i][j][1]

                elif end!=lists[j][0]:
                    sublists.append((start,end))
                    start=lists[i][j][0]
                    end=lists[i][j][1]
                if j==len(lists[i])-1:
                    sublists.append((start,end))

        lists[i]=sublists
    else:
        pass

startlists={i:0 for i in range(100001)}
endlists={i:0 for i in range(100001)}

for i in range(31):
    if len(lists[i])>=1:
        for some in lists[i]:
            startlists[some[0]-1]+=1
            endlists[some[1]]+=1
for i in range(1,100001):
  startlists[i]+=startlists[i-1]
  endlists[i]+=endlists[i-1]


maxi=0
for i in range(100001):
  maxi=max(maxi,startlists[i]-endlists[i])
print(maxi)

### FIXED CODE ###


N, C = map(int, input().split())
stc = [list(map(int, input().split())) for _ in range(N)]
 
record = [[0] * 10 ** 5 for _ in range(C)]
for s, t, c in stc:
    for i in range(s, t + 1):
        record[c-1][i-1] = 1
 
ans = 0
for i in range(10 ** 5):
    cnt = 0
    for j in range(C):
        cnt += record[j][i]
    ans = max(ans, cnt)
 
print(ans)
N = int(input())
A = [int(input()) for i in range(N)]
Amin = min(A)
Amax = max(A)
print(abs(Amax-Amin))

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
Amin = min(A)
Amax = max(A)
print(abs(Amax-Amin))
import sys
read = sys.stdin.read
from math import gcd

def main():
    n, m, *a = map(int, read().split())
    d = [0] * n
    for i, ae in enumerate(a):
        t1 = 0
        while ae > 0:
            if ae % 2 == 0:
                t1 += 1
                ae /= 2
            else:
                break
        d[i] = t1
    d_c = [de == d[0] for de in d]
    if not all(d_c):
        print(0)
        sys.exit()
    div = 2**d[0]
    a2 = [ae // div for ae in a]
    m /= div
    g = (a2[0] * a2[1]) // gcd(a2[0], a2[1])
    for i1 in range(1, n):
        g = (g * a2[i1]) // gcd(g, a2[i1])
        if g > m:
            print(0)
            sys.exit()

    r = m // g + 1
    print(int(r))

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
read = sys.stdin.read
from math import gcd
from math import floor
def main():
    n, m, *a = map(int, read().split())
    if n == 1:
        r = m >= a[0]//2
        r += floor((m - a[0]//2) / a[0])
        print(int(r))
        sys.exit()
    d = [0] * n
    for i, ae in enumerate(a):
        t1 = 0
        while ae > 1:
            if ae % 2 == 0:
                t1 += 1
                ae /= 2
            else:
                break
        d[i] = t1
    d_c = [de == d[0] for de in d]
    if not all(d_c):
        print(0)
        sys.exit()
    
    div = 2
    a2 = [ae // div for ae in a]
    g = (a2[0] * a2[1]) // gcd(a2[0], a2[1])
    for i1 in range(1, n):
        g = (g * a2[i1]) // gcd(g, a2[i1])
        if g > m:
            print(0)
            sys.exit()
    r = m >= g
    r += floor((m - g) / (g * 2))
    print(int(r))

if __name__ == '__main__':
    main()
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))

ans=[[0]*w for _ in range(h)]
i=0
j=0
jugh=0
for z in range(n):
    count=0
    while count<a[z]:
        #print(i,j,z+1)
        if jugh==0:
            ans[i][j]=z+1
            j+=1
            c=0
        elif jugh==2:
            if j==0:
                jugh=0
                c=1
                ans[i][j]=z+1
                j+=1
            else:
                
                jugh=1
                c=1
                
                ans[i][j]=z+1
                j-=1
        else:
            ans[i][j]=z+1
            j-=1
            c=0

        if j==w and c==0:
            i+=1
            j-=1
            jugh=2
        if j==-1 and c==0:
            i+=1
            j+=1
            jugh=2
            
        count+=1

for i in range(h):
    for j in range(w):
        print(ans[i][j],end=" ")
    print()

### FIXED CODE ###

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

ans=[[0]*w for _ in range(h)]
i=0
j=0
jugh=0


if w==1:
    for i in range(n):
        for j in range(a[i]):
            print(i+1)
    exit()



for z in range(n):
    count=0
    while count<a[z]:
       # print(i,j,z+1)
        if jugh==0:
            ans[i][j]=z+1
            j+=1
            c=0
        elif jugh==2:
            if j==0:
                jugh=0
                c=1
                ans[i][j]=z+1
                j+=1
            else:
                
                jugh=1
                c=1
                
                ans[i][j]=z+1
                j-=1
        else:
            ans[i][j]=z+1
            j-=1
            c=0

        if j==w and c==0:
            i+=1
            j-=1
            jugh=2
        if j==-1 and c==0:
            i+=1
            j+=1
            jugh=2
            
        count+=1

for i in range(h):
    for j in range(w):
        print(ans[i][j],end=" ")
    print()
s = input()
j = 0
for i in range(len(s)):
    #print("i=",i)
    if s[i-(2*j)] == "B":
        #print(i-(2*j))
        #print(s)
        if s[0] == "B":
            s = 'x'+s[1:]
            #print(s)
            #print(s[0])
        else:
            #print(i-(2*j))
            s = s.replace(s[i-1-(2*j)]+s[i-(2*j)],'')
            j += 1
            s += 'xx'
            #print(s)
ans = s.replace('x','')
print(ans)

### FIXED CODE ###

s = input()
j = 0
for i in range(len(s)):
    #print("i=",i)
    if s[i-(2*j)] == "B":
        #print(i-(2*j))
        #print(s)
        if s[0] == "B":
            s = 'x'+s[1:]
            #print(s)
            #print(s[0])
        else:
            #print(i-(2*j))
            s = s[:i-1-(2*j)]+s[i-(2*j)+1:]
            j += 1
            
            #print("s=",s)
            #print(s[:i-1-(2*j)-1])
ans = s.replace('x','')
print(ans)
from fractions import gcd
import sys
input = sys.stdin.readline

N = int(input())

T = list([int(input()) for _ in range(N)])

ans = T[0]

for i in T:
    ans = int(ans* i/gcd(ans, i))
print(ans)
    

### FIXED CODE ###

from fractions import gcd
import sys
input = sys.stdin.readline

N = int(input())

T = list([int(input()) for _ in range(N)])

ans = T[0]

T= set(T)

for i in T:
    ans = i//gcd(ans, i)* ans
print(ans)
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
    
N = int(input())
Ts = [None for i in range(N)]

a = input()
b = 0
for i in range(N-1):
    b = int(input())
    a = (a*b) // gcd(a,b)
    
print(a)

### FIXED CODE ###

def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
    
N = int(input())
 
a = int(input())
b = 0
for i in range(N-1):
    b = int(input())
    a = (a*b) // gcd(a,b)
    
print(a)
N = int(input())
counter = {}
for a in map(int, input().split()):
    if a % 4 == 0:
        counter[2] = counter.get(2, 0) + 1
    elif a % 2 == 0:
        counter[1] = counter.get(1, 0) + 1
    else:
        counter[0] = counter.get(0, 0) + 1
print('Yes') if counter[0] <= counter[2] else print('No')


### FIXED CODE ###

from collections import defaultdict


N = int(input())
counter = defaultdict(int)
for a in map(int, input().split()):
    if a % 4 == 0:
        counter[2] += 1
    elif a % 2 == 0:
        counter[1] += 1
    else:
        counter[0] += 1
if counter[1] == 0:
    print('Yes') if counter[0] <= counter[2] + 1 else print('No')
else:
    print('Yes') if counter[0] <= counter[2] else print('No')
s = raw_input()
total = 0
for t in s:
  if t == '+':
    total += 1
  else:
    total -= 1
print(total)


### FIXED CODE ###

s = raw_input()
total = 0
for t in s:
  if t == '+':
    total += 1
  else:
    total -= 1
print(total)
a, b = map(int, input().split())
li = []
for i in range(1, 10**5+1):
  if a%i=0 and b%i=0:
    li.append(i)
print((a*b)/li[-1])
    

### FIXED CODE ###

a, b = map(int, input().split())
li = []
for i in range(1, 10**5+1):
  if a%i==0 and b%i==0:
    li.append(i)
print(int((a*b)/li[-1]))
,b=map(float,input().split())
res = a*b
res = int(res)
print(res)

### FIXED CODE ###

import decimal
a,b=map(str,input().split())
RES = decimal.Decimal(a)*decimal.Decimal(b)
res = int(RES)
print(res)
# 整数列A 
# abs(A1-(b+1))+abs(A2-(b+2))+...+abs(An-(b+N))の最小値
# bは任意
# すなわち、その時のbを求めれば良い問題

# 結局、bを、Ai-iの中央値にすれば最適解。

def calcVal(b):
	val = 0
	for n in range(N):
		val += abs(A[n]-(b+n+1))
	return val

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

M=[]

for i,a in enumerate(A):
	M.append( a - (i+1) )

M.sort()

if N%2==0:
	med1=N//2
	med2=N//2+1
	ans=min(calcVal(M[med1]),calcVal(M[med2]))

else:
	med=(N+1)//2
	ans = calcVal(M[med])


print(ans)



### FIXED CODE ###

# 整数列A 
# abs(A1-(b+1))+abs(A2-(b+2))+...+abs(An-(b+N))の最小値
# bは任意
# すなわち、その時のbを求めれば良い問題

# 結局、bを、Ai-iの中央値にすれば最適解。

def calcVal(b):
	# print(b)
	val = 0
	for n in range(N):
		val += abs(A[n]-(b+n+1))
		# print(A[n])
		# print(n)
		# print(val)
		# print(abs(A[n]-(b+n+1)))
		# print("")
	return val

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

M=[]

for i,a in enumerate(A):
	#if a - (i+1) not in M:
	M.append( a - (i+1) )

M.sort()
lenM=len(M)

if lenM==1:
	ans=calcVal(M[0])

elif lenM==2:
	ans=min(calcVal(M[0]),calcVal(M[1]))


else:
	med1=lenM//2-1
	med2=lenM//2
	#print(M)
	ans=min(calcVal(M[med1]),calcVal(M[med2]),calcVal(0))



print(ans)
n, q = input().split()
Q = int(q)
s = input()
S = list(s)

array = []
count = 0
ff = False
for i in range(len(S)):
    if len(S) < i+1:
        break
    if S[i] == 'A':
        flag = True
    elif flag == True and S[i] == 'C':
        count += 1
        array.append(-1)
        array.append(count)
        ff = True
    elif flag == True:
        array.append(0)
        array.append(0)
        flag = False
    else:
        array.append(0)

array_q = []
for q in range(Q):
    l, r = input().split()
    array_q.append([int(l), int(r)])

for arr in array_q:
    try:
        if ff != True:
            print(0)
            continue

        if len(array[arr[0]-1:arr[1]-1]) < 2:
            print(0)
            continue

        for a in array[arr[0]-1:]:
            if a == -1:
                flag = True
            elif flag == True:
                minv = a
                break

        for b in reversed(array[:arr[1]]):
            if b != 0 and b != -1:
                maxv = b
                break

        if minv == maxv and maxv != 0:
            print(1)
            
        elif maxv == 0:
            print(0)

        else:
            print(maxv - minv + 1)
            maxv = 0
            minv = 0
    except:
        print(0)

### FIXED CODE ###

h = input()

if h == 'A':
    print("T")
elif h == 'T':
    print("A")
elif h == 'C':
    print("G")
elif h == 'G':
    print("C")
from functools import lru_cache
import sys
sys.setrecursionlimit(2*10**5)


# 入力
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[b].add(a)


@lru_cache(maxsize=None)
def f(v):
    return 1 + max((f(p) for p in G[v]), default=0)


ans = '\n'.join(
    str(max(G[i], key=f, 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,M = [int(i) for i in input().split()]
submissions = {str(i):[] for i in range(1,N+1)}
AC,WA = 0,0
for i in range(M):
    P,S = [j for j in input().split()]
    submissions[P].append(S)
for i in submissions:
    if(not 'AC' in submissions[i]):
        continue
    for j in submissions[i]:
        if j == 'AC':
            AC+=1
            break
        WA +=1
print(AC,WA)

### FIXED CODE ###

C = input()
alphs = "abcdefghijklmnopqrstuvwxyz"
print(alphs[alphs.find(C)+1])
s, t = map(input().split())

if t.startswith(s):
  print('Yes')
else:
  print('No')

### FIXED CODE ###

s = input()
t = input()
 
if t.startswith(s):
  print('Yes')
else:
  print('No')
n, m = map(int, input().split())
A = sorted(map(int, input().split()))
info = []
for _ in range(m):
    b, c = map(int, input().split())
    info.append([b, c])
info.sort(key=lambda x: x[1], reverse=True)
# print(info, A)
index = 0
for i in range(m):
    for j in range(info[i][0]):
        if A[index] <= info[i][1]:
            A[index] = info[i][1]
            index += 1
        else:
            break

ans = sum(A)
print(ans)

### FIXED CODE ###

n, m = map(int, input().split())
A = sorted(map(int, input().split()))
info = []
for _ in range(m):
    b, c = map(int, input().split())
    info.append([b, c])
info.sort(key=lambda x: x[1], reverse=True)
# print(info, A)
index = 0
for i in range(m):
    if index == n:
        break
    for j in range(info[i][0]):
        if index == n:
            break
        if A[index] < info[i][1]:
            A[index] = info[i][1]
            index += 1
        else:
            break

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


if N == 2:
    print(max(A[0], A[1]))
else:
    m = min(A)

    ans = -1
    for i in range(m+1, 1, -1):
        count = 0
        for n in range(N):
            if count > 1:
                break
            if A[n] % i != 0:
                count += 1
        if count <= 1:
            ans = i
            break

    print(ans)


### FIXED CODE ###

A, B, T = map(int, input().split())

ans = 0
for i in range(1, T+1):
    if i % A == 0:
        ans += B
print(ans)
d = input()
t = input()
s = input()

if d / s < t:
  return 'yes'

else:
  return 'no'

### FIXED CODE ###

d,t,s = map(int, input().split())
if t >= (d / s):
    print("Yes")
else:
    print("No")
n = int(input())

h = list(map(int, input().split()))

ans = []
result = 0

for x in range(n - 1):
    if h[x] >= h[x + 1] :
        result += 1
        ans.append(result)
    else :
        ans.append(result)
        result = 0

print(max(ans))


### FIXED CODE ###

n = int(input())

h = list(map(int, input().split()))

ans = 0
result = 0

for x in range(n - 1):
    if h[x] >= h[x + 1] :
        result += 1
    else :
        ans = max(ans, result)
        result = 0
ans = max(ans, result)

print(ans)
x,y,a,b,c = map(int,input().split())
p = [int(i) for i in input().split()]
q = [int(i) for i in input().split()]
r = [int(i) for i in input().split()]
p.sort(reverse=True)
q.sort(reverse=True)
for i in range(x): r.append(p[i])
for i in range(y): r.append(q[i])
r.sort(reverse=True)
print(sum(r[:x+y])

### FIXED CODE ###

x,y,a,b,c = map(int,input().split())
p = [int(i) for i in input().split()]
q = [int(i) for i in input().split()]
r = [int(i) for i in input().split()]
p.sort(reverse=True)
q.sort(reverse=True)
for i in range(x): r.append(p[i])
for i in range(y): r.append(q[i])
r.sort(reverse=True)
print(sum(r[:x+y]))
N = int(input())
L = list(map(int,input().split()))
L_copy = L.copy()
max = max(L)
L_copy.pop(L.index(min))

if max > sum(L_copy):
  print("Yes")
else:
  print("No")


### FIXED CODE ###

N = int(input())
L = list(map(int,input().split()))
L_copy = L.copy()
MAX = max(L)
L_copy.pop(L.index(MAX))


if MAX < sum(L_copy):
  print("Yes")
else:
  print("No")
i = input()
j = i.split()
num_balls = j[0]
num_colors = j[1]
product = num_colors
if(num_balls > 1 and num_colors == 1):
  print(0)
for i in range(1, num_balls):
  product *= (num_balls - 1)
print(product)

### FIXED CODE ###

i = input()
j = i.split()
num_balls = int(j[0])
num_colors = int(j[1])
product = num_colors
if(num_balls > 1 and num_colors == 1):
  print(0)
else:
  for i in range(1, num_balls):
    product *= (num_colors - 1)
  print(product)
a=input()
b=input()
x=""
for i in range(len(a)//2):
  x=x+a[2i]
for i in range(len(b)//2):
  x=x+b[2i+1]
print(x)

### FIXED CODE ###

a=input()
b=input()
c=len(a)
d=len(b)
x=""
if c<=d:
  for i in range(c):
    x=x+a[i]
    x=x+b[i]
  print(x)
if c>d:
  for i in range(d):
    x=x+a[i]
    x=x+b[i]
  x=x+a[len(a)-1]
  print(x)
from datetime import datetime

input_ = raw_input()
date = datetime.strptime(input_, '%Y/%m/%d')
if date > datetime.strptime("2019/04/30", '%Y/%m/%d'):
    print("TBD")
else:
    print("Heisei")




### FIXED CODE ###

from datetime import datetime

input_ = raw_input()
date = datetime.strptime(input_, '%Y/%m/%d')
if date > datetime.strptime("2019/04/30", '%Y/%m/%d'):
    print("TBD")
else:
    print("Heisei")
def func():
  A,B= map(int,input().split())
  if A >= B*2:
  	print(A-2B)
  else:
  	print(0)
  
if __name__=="__main__":
  print("Input two Integers with space")
  func()


### FIXED CODE ###

def func():
    A,B=map(int,input().split())
    
    if A>=B*2:
        C=A-2*B
        print(C)
    else:
        print(0)
        
if __name__=="__main__":
    func()
n = int(input())
A = list(map(int, input().split()))
s = min(A)
def solve():
    ans = 0
    V = [False] * n
    # B = sorted(A)
    # T = {B[i]: i for i in range(n)}
	T = {B: i for i, B in enumerate(sorted(A))}
    for i in range(n):
        if V[i]:
            continue
        cur = i
        S = an = 0
        m = 10000
        while not V[cur]:
            V[cur] = True
            an += 1
            v = A[cur]
            m = min(m, v)
            S += v
            cur = T[v]
        ans += min(S + (an - 2) * m, m + S + (an + 1) * s)
    return ans
print(solve())



### FIXED CODE ###

n = int(input())
A = list(map(int, input().split()))
s = min(A)
def solve():
    ans = 0
    V = [False] * n
    B = sorted(A)
    T = {B[i]: i for i in range(n)}
    for i in range(n):
        if V[i]:
            continue
        cur = i
        S = an = 0
        m = 10000
        while not V[cur]:
            V[cur] = True
            an += 1
            v = A[cur]
            m = min(m, v)
            S += v
            cur = T[v]
        ans += min(S + (an - 2) * m, m + S + (an + 1) * s)
    return ans
print(solve())
n= int(input())
s="abcdefghijklmnopqrstuvwxyz"
def fn(n):
  if(n<=26):
    return s[n-1]
  return f(n-1)//26+s[f(n-1)%26]
  
print(f(n))  

### FIXED CODE ###

n = int(input())
ans = ''
while n > 0:
    n -= 1
    ans += chr(ord('a') + n % 26)
    n//= 26
print(ans[::-1])
import sympy
n = int(input())
a = 0
for i in range(1,n+1):
    a += i*sympy.divisor_count(i)
print(a)

### FIXED CODE ###

n=int(input())
ans=0
for i in range(1,n+1):
  ans+=(i+i*(n//i))*(n//i)//2
print(ans)
a,b = input().spilt()

if a==b:
  print('H')
else:
  print('D')

### FIXED CODE ###

a,b = input().split()
 
if a==b:
  print('H')
else:
  print('D')
s = list(input())
t = list(input())
pair = []
li =[]
ans = "Yes"

for i in range(len(s)):
    if [s[i],t[i]] in li:
        pass
    else:
        li.append([s[i],t[i]])

def check2(pair,i,li):
    for j in range(len(pair)):
        if (li[i][0]==pair[j][0] and li[i][1]!=pair[j][1])or(li[i][0]!=pair[j][0] and li[i][1]==pair[j][1]):
            return False
    return True

for i in range(len(s)):
    if check2(pair,i,li):
        pair.append([li[i][0],li[i][1]])
    else:
        ans = "No"
        break

print(ans)


### FIXED CODE ###

s = list(input())
t = list(input())
pair = []
li =[]
ans = "Yes"

for i in range(len(s)):
    if [s[i],t[i]] in li:
        pass
    else:
        li.append([s[i],t[i]])

def check2(pair,i,li):
    for j in range(len(pair)):
        if (li[i][0]==pair[j][0] and li[i][1]!=pair[j][1])or(li[i][0]!=pair[j][0] and li[i][1]==pair[j][1]):
            return False
    return True

for i in range(len(li)):
    if check2(pair,i,li):
        pair.append([li[i][0],li[i][1]])
    else:
        ans = "No"
        break

print(ans)
N=int(input())
ans=0
for i in range(N):
    x=int(input())
    u=input()
    if(u=="JPY"):
        ans+=x
    else :
        ans+=int(x*380000)
print(ans)

### FIXED CODE ###

n=int(input())
money=0

for i in range(n):
    gt=input().split()
    if gt[1]=="BTC":
        money+=float(gt[0])*380000
    else:
        money+=float(gt[0])

print(money)