Harryxun/stf_run huggingface dataset:
mod=10**9+7
n,k=map(int,input().split())
a=list(map(int,input().split()))
if max(a)<0:
  if k%2:a.sort(reverse=1)
  else:a.sort()
  ans=1
  for i in a[:k]:ans=(ans*i)%mod
  exit(print(ans))
p=[(0,0)]
m=[(0,0)]
for i in a:
  if i<0:m.append((-i,1))
  else:p.append((i,0))
pp=mm=1
p.sort()
m.sort()
oe=0
ans=1
for i in range(k):
  if p[-1][0]>m[-1][0]:
    t,f=p.pop()
    pp=t
  else:
    t,f=m.pop()
    mm=t
  ans=(ans*t)%mod
  oe^=f
if ans==0:exit(print(0))
if oe:
  if pp*p[-1][0]>mm*m[-1][0]:
    ans=(ans*pow(mm,mod-2,mod)*p[-1][0])%mod
  else:
    ans=(ans*pow(pp,mod-2,mod)*m[-1][0])%mod
print(ans)

### FIXED CODE ###

from itertools import combinations
mod=10**9+7
def solve(n,k,a):
  if min(a)>0:
    ans=1
    a.sort(reverse=1)
    for i in a[:k]:
      ans*=i
      ans%=mod
    return ans
  if max(a)<0:
    if k%2==0:
      a.sort()
      ans=1
      for i in a[:k]:
        ans*=i
        ans%=mod
      return ans
    else:
      a.sort(reverse=1)
      ans=1
      for i in a[:k]:
        ans*=i
        ans%=mod
      return ans
  if n==k:
    ans=1
    for i in a:
      ans*=i
      ans%=mod
    return ans
  if k==1:
    return max(a)
  if n-k==1:
    ans=1
    if a.count(0)>1:return 0
    p=[]
    m=[]
    for i in a:
      if i>0:p.append(i)
      elif i<0:m.append(i)
    if 0 in a:
      if len(m)%2==0:
        for i in a:
          if i==0:continue
          ans=(ans*i)%mod
      else:ans=0
    else:
      if len(m)%2==0:
        for i in sorted(p)[1:]+m:ans=(ans*i)%mod
      else:
        for i in p+sorted(m)[:-1]:ans=(ans*i)%mod
    return ans


  ans=1
  p=[]
  m=[]
  for i in a:
    if i<0:m.append(i)
    elif i>=0:p.append(i)
  p.sort()
  m.sort(reverse=1)

  while k>1:
    if k<=5:
      if len(p)>=10:p=p[-10:]
      if len(m)>=10:m=m[-10:]
      ans*=solve2(len(p)+len(m),k,m+p)
      ans%=mod
      k=0
      break
    if len(p)<2:
      ans*=m.pop()*m.pop()
      k-=2
    elif len(m)<2:
      ans*=p.pop()*p.pop()
      k-=2
    elif m[-1]*m[-2]>p[-1]*p[-2]:
      ans*=m.pop()*m.pop()
      k-=2
    else:
      ans*=p.pop()*p.pop()
      k-=2
    ans%=mod
  if k:
    ans*=p.pop()
  return ans
  print(ans%mod)

def solve2(n,k,a):
  ans=-10**20
  for c in combinations(range(n),k):
    anss=1
    for i in c:anss*=a[i]
    ans=max(ans,anss)
  return ans%mod

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

"""
from random import randint
for i in range(10000):
  n=randint(1,10)
  k=randint(1,n)
  a=sorted([randint(-10,10)for _ in range(n)])
  print(n,k,a)
  ans1=solve(n,k,a)
  ans2=solve2(n,k,a)
  if ans1==ans2:print("ok")
  else:
    print("error")
    print(n,k)
    print(*a)
    print(ans1,ans2)
    exit()
"""
N = int(input())
S = list(range(1, N + 1))
M = list(range(2, N + 1))
n = 0
for a in range(0, N - 1):
    n = n + (S[a] % M[a])
print(n)


### FIXED CODE ###

N = int(input())
print((N * (N - 1)) // 2)
N, Q = map(int, input().split())
G = [[] for _ in range(N)]
cnt = [0]*N


def dfs(start_node, x):
    for i in G[start_node]:
        cnt[i] += x
        dfs(i, x)



for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    G[a].append(b-1)

for i in range(Q):
    start_node, x = map(int, input().split())
    start_node -= 1
    cnt[start_node] += x
    dfs(start_node, x)



ans = map(str, cnt)
print(' '.join(ans))

### FIXED CODE ###

import sys
sys.setrecursionlimit(500000)

N, Q = map(int, input().split())
G = [set() for _ in range(N)]
cnt = [0]*N
visited = [0]*N

def dfs(start_node):
    for i in G[start_node]:
        if visited[i]==0:
            visited[i]=1
            cnt[i] += cnt[start_node]
            dfs(i)

for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].add(b)
    G[b].add(a)

for i in range(Q):
    node, x = map(int, input().split())
    node -= 1
    cnt[node] += x

visited[0]=1
#dfs(0)
st = [0]
while st:
    v = st.pop()
    for u in G[v]:
        if visited[u]: continue
        visited[u] = 1
        cnt[u] += cnt[v]
        st.append(u)    

ans = map(str, cnt)
print(' '.join(ans))
a = raw_input()
x,y = a.split(" ")
n = int(x)
m = int(y)
print n*m + " " + n*2 + m*2

### FIXED CODE ###

x = raw_input().split(" ")
 
a = int(x[0])
b = int(x[1])
 
print str(a*b) + " " + str(2*(a+b))
from math import factorial
def comb(n, r):
  if r < 0 or r > n:
    return 0
  else:
    return factorial(n) // (factorial(n - r) * factorial(r))

# 左から i 桁目以降について、0 以外の値を残り K 個使用可能
# smaller: i 桁目までが 一致している時=False, 小さい時=True  
def solve(i, k, smaller):
  if i == n:
    if k == 0:
      return 1
    else:
      return 0
  if k == 0:
    return 1
  if smaller:
    return comb(n - i, k) * 9 ** k
  else:
    if S[i] == "0":
      return solve(i + 1, k, Flase)
    else:
      zero = solve(i + 1, k, True)
      aida = solve(i + 1, k - 1, True) * (int(S[i]) - 1)
      icchi = solve(i + 1, k - 1, False)
      return zero + aida + icchi

S = input()  
n = len(S)
k = int(input())
print(solve(0, k, False))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 6)

from math import factorial
def comb(n, r):
  if r < 0 or r > n:
    return 0
  else:
    return factorial(n) // (factorial(n - r) * factorial(r))

# 左から i 桁目以降について、0 以外の値を残り K 個使用可能
# smaller: i 桁目までが 一致している時=False, 小さい時=True  
def solve(i, k, smaller):
  if i == n:
    if k == 0:
      return 1
    else:
      return 0
  if k == 0:
    return 1
  if smaller:
    return comb(n - i, k) * 9 ** k
  else:
    if S[i] == "0":
      return solve(i + 1, k, False)
    else:
      zero = solve(i + 1, k, True)
      aida = solve(i + 1, k - 1, True) * (int(S[i]) - 1)
      icchi = solve(i + 1, k - 1, False)
      return zero + aida + icchi

S = input()  
n = len(S)
k = int(input())
print(solve(0, k, False))
x = int(input())
if x =3 or x= 5 or x = 7:
  print("YES")
else:
  print('NO')


### FIXED CODE ###

x = int(input())
if x ==3 or x== 5 or x == 7:
  print("YES")
else:
  print('NO')
print(''.join(sorted(input() for _ in range(int(input())))))

### FIXED CODE ###

n, m = map(int, input().split())
print(''.join(sorted(input() for _ in range(n))))
s = list(input())

cnt = 0
# print(s, cnt)

i = 0
while i < len(s)-2:
    # print(i)
    if s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C':
        s[i] = 'B'
        s[i+1] = 'C'
        s[i+2] = 'A'
        cnt = cnt + 1
        i = i - 1
        if i < 0:
            i = 0
        print(i, s, cnt)
    else:
        i = i + 1

print(cnt)

### FIXED CODE ###

s = input()
t = s.replace('BC', 'D')

a = 0 # 連続するaの数
ans = 0 # 答え

for i in t:
    if i == 'A':
        a += 1
    elif i == 'D':
        ans += a
    else:
        a = 0

print(ans)
a,b = map(int,input().split())

if a >= b:
  print(1)
else:
  c = 1
  count=0
  while b > c:
    c + = a-1
    
    count += 1
  print(count)


### FIXED CODE ###

a,b = map(int,input().split())

c = 1
count=0
while b > c:
  c += a-1
    
  count += 1
print(count)
h, n = map(int, input().split())
a = input().split()
b = 0
for i in range(n):
    b += int(a[i])
if (h < b and has_duplicates(a) and len(a)>n ):
    print("No")
else:
    print("Yes")


### FIXED CODE ###

h, n = map(int, input().split())
a = input().split()
b = 0
def has_duplicates(seq):
    return len(seq) != len(set(seq))

for i in range(n):
    b += int(a[i])
if (h > b ):
    print("No")
else:
    print("Yes")
# A V
# B W
# T
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if (V-W)*T >= B-A and (B-A) % (V-W) == 0 or (W-V)*T >= A-B and (A-B) % (W-V) == 0:
    print('YES')
else:
    print('NO')

### FIXED CODE ###

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

if (V-W)*T >= abs(B-A):
    print('YES')
else:
    print('NO')
n = input()

if ('7' in n):
  print('Yes')
else:
  pritn('No')

### FIXED CODE ###

n = input()

if ('7' in n):
  print('Yes')
else:
  print('No')
n,m = list(map(int,input().split()))
path = [list(map(int,input().split())) for _ in range(m)]

graph = [[] for _ in range(m)]
for a,b in path:
    graph[a-1].append(b-1); graph[b-1].append(a-1)

parents = [-1]*n
children = [[] for _ in range(n)]
orders = []
stack = [0]
flags = [True] * n
flags[0] = False

while any(flags):
    while stack:
        tmp = stack.pop()
        for node in graph[tmp]:
            if flags[node]:
                flags[node] = False
                children[tmp].append(node)
                parents[node] = tmp
                orders.append(node)
    stack = orders[:]
    
print("Yes")
for i in parents[1:]:
    print(i+1)

### FIXED CODE ###

n,m = list(map(int,input().split()))
path = [list(map(int,input().split())) for _ in range(m)]

graph = [[] for _ in range(n)]
for a,b in path:
    graph[a-1].append(b-1); graph[b-1].append(a-1)

parents = [-1]*n
tmparr = []
children = [0]
flags = [True] * n
flags[0] = False

while any(flags):
    while children:
        tmp = children.pop()
        for node in graph[tmp]:
            if flags[node]:
                flags[node] = False
                parents[node] = tmp
                tmparr.append(node)
    children = tmparr[:]
    tmparr = []
    
print("Yes")
for i in parents[1:]:
    print(i+1)
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

lis=[]
for i in range(0,n-1):
  if a[i]==a[i+1]-1:
    lis.append(a[i])
plus=0
for j in range(0,len(lis)):
  plus+=c[a[j]-1]
print(sum(b)+plus)

### FIXED CODE ###

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

lis=[]
for i in range(0,n-1):
  if a[i]==a[i+1]-1:
    lis.append(a[i])
plus=0
for j in range(0,len(lis)):
  plus+=c[lis[j]-1]
print(sum(b)+plus)
sa = list(input())
sb = list(input())
sc = list(input())
start  = sa.pop(0)

for i in range(399):
  if len(sa) == 0 and start == "a" :
    print("A")
    exit()
  if len(sb) == 0 and start == "b":
    print("B")
    exit()
  if len(sc) == 0 and start == "c":
    print("C")
    exit()
  if start == "a":
    start = sa.pop(0)
  if start == "b":
    start = sb.pop(0)
  if start == "c":
    start = sc.pop(0)


### FIXED CODE ###

a = list(input())
b = list(input())
c = list(input())
next = a.pop(0)
while True:
  if next == "a":
    if a == []:
      print("A")
      break
    else:
      next = a.pop(0)
  elif next == "b":
    if b == []:
      print("B")
      break
    else:
      next = b.pop(0)
  else:
    if c == []:
      print("C")
      break
    else:
      next =c.pop(0)
n,m = map(int, input().split())
p = list(map(int, input().split()))
par = list(range(n))
rank = [0 for x in range(n)]

def root(x):
	if par[x] == x:
		return x
	else:
		return root(par[x])
def merge(x, y):
	x = root(x)
	y = root(y)
	if x == y:
		pass
	else:
		if rank[x] > rank[y]:
			par[y] = x
			rank[y] += 1
		else:
			par[x] = y
			rank[x] += 1
	pass

for i in range(m):
	x, y = map(int, input().split())
	merge(x-1, y-1)

ans = 0

for i in range(n):
	if p[i]-1 == i:
		ans += 1
	elif root(p[i]-1) == root(i):
		ans += 1

print(ans)

### FIXED CODE ###

n,m = map(int, input().split())
p = list(map(int, input().split()))
par = [i for i in range(n)]
rank = [0 for x in range(n)]

def root(x):
	tmp = par[x]
	if tmp == x:
		return x
	else:
		a = root(tmp)
		par[x] = a
		return a

def merge(x, y):
	x = root(x)
	y = root(y)
	if x == y:
		return
	else:
		if rank[x] > rank[y]:
			par[y] = x
			rank[y] += rank[x]
		else:
			par[x] = y
			rank[x] += rank[y]
		return

for i in range(m):
	x, y = map(int, input().split())
	merge(x-1, y-1)

ans = 0

for i in range(n):
	if p[i]-1 == i:
		ans += 1
	elif root(p[i]-1) == root(i):
		ans += 1

print(ans)
N = int(input())
words = {}
for i in range(N):
  name = input()
  if name not in words:
    words[name] = 1
  else:
    words[name] += 1
    
res_name = []
for i in res_dict.keys():
  if res_dict[i] == max(res_dict.values()):
    res_name.append(i)
res_name = sorted(res_name)
for i in res_name:
  print(i)

### FIXED CODE ###

N = int(input())
words = {}
for i in range(N):
  name = input()
  if name not in words:
    words[name] = 1
  elif name in words:
    words[name] += 1
    
res_name = []
Max = max(words.values())
for i in words.keys():
  if words[i] == Max:
    res_name.append(i)
res_name = sorted(res_name)
for i in res_name:
  print(i)
a,b,c = map(str, input().split())
print(upper(a[0])+upper(b[0])+upper(c[0]))

### FIXED CODE ###

a,b,c = map(str, input().split())
print(str.upper(a[0])+str.upper(b[0])+str.upper(c[0]))
A, B = map(int, input().split())
if A == B:
	print('Draw)
elif A == 1:
	pirnt('Alice')
elif B == 1:
	print('Bob')
elif A > B:
	print('Alice')
else:
	print('Bob')          

### FIXED CODE ###

A, B = map(int, input().split())
if A == B:
	print('Draw')
elif A == 1:
	print('Alice')
elif B == 1:
	print('Bob')
elif A > B:
	print('Alice')
else:
	print('Bob')
a = []
a = input().split()

A = int(a[0])
B = int(a[1])
C = int(a[2])

if A - B > C :
  ans = 0
if A - B < C :
  ans = C - (A - B)
  
print(ans)

### FIXED CODE ###

a = []
a = input().split()

A = int(a[0])
B = int(a[1])
C = int(a[2])

if (A - B) >= C :
  ans = 0
if (A - B) < C :
  ans = C - (A - B)
  
print(ans)
H,W = list(map(int,input89.split()))
picture = [input() for i in range(H)]

for i in range(2*H):
  print(picture[i//2])

### FIXED CODE ###

H,W = list(map(int,input().split()))
picture = [input() for i in range(H)]

for i in range(2*H):
  print(picture[i//2])
S = input()
str_list = [*S]
even_str = str_list[0::2]
odd_str = str_list[1::2]
if ('L' in even_str):
  print('No')
elif ('R' in odd_str):
  print('No')
else:
  print('Yes')

### FIXED CODE ###

S = input()
str_list = list(S)
odd_str = str_list[0::2]
even_str = str_list[1::2]
if ('R' in even_str):
  print('No')
elif ('L' in odd_str):
  print('No')
else:
  print('Yes')
n=int(input())
v=input().split()
vodd=[]
veven=[]
for i in range(n):
    if i%2:
        veven.append(int(v[i]))
    else:
        vodd.append(int(v[i]))

changeCnt=0

voddNum=[vodd[0]]
voddCnt=[0]
j=0
for i,odd in enumerate(vodd):
    if voddNum[j]!=odd:
        for k,num in enumerate(voddNum):
            if num==odd:
                j=k
                break
        else:
            j=k+1
            voddNum.append(odd)
            voddCnt.append(0)
            
    voddCnt[j]+=1

voddSet=list(zip(voddCnt, voddNum))
print(voddSet)
for i in range(len(voddSet)):
    voddSet[i]=list(voddSet[i])

voddSet=list(reversed(sorted(voddSet,key=lambda x:x[0])))

'''
print(vodd)
print(voddNum)
print(voddCnt)
print(voddSet)
'''

vevenNum=[veven[0]]
vevenCnt=[0]
j=0
for i,even in enumerate(veven):
    if vevenNum[j]!=even:
        for k,num in enumerate(vevenNum):
            if num==even:
                j=k
                break
        else:
            j=k+1
            vevenNum.append(even)
            vevenCnt.append(0)

    vevenCnt[j]+=1
vevenSet=list(zip(vevenCnt, vevenNum))
print(vevenSet)
for i in range(len(vevenSet)):
    vevenSet[i]=list(vevenSet[i])

vevenSet=list(reversed(sorted(vevenSet,key=lambda x:x[0])))

'''
print()
print(veven)
print(vevenNum)
print(vevenCnt)
print(vevenSet)
'''

changeCnt+=len(vodd)+len(veven)
if voddSet[0][1]==vevenSet[0][1]:
    if len(voddSet==1):
        changeCnt+=-len(vodd)
    else:
        if voddSet[1][0]>vevenSet[1][0]:
            changeCnt+=-voddSet[1][0]-vevenSet[0][0]
        else:
            changeCnt+=-voddSet[0][0]-vevenSet[1][0]
else:
    changeCnt+=-voddSet[0][0]-vevenSet[0][0]
    
print(changeCnt)
               


### FIXED CODE ###

n=int(input())
v=map(int,input().split())
vodd={-1:0}
veven={-1:0}
for i,vi in enumerate(v):
    if i%2:
        if(vi in veven):
            veven[vi]+=1
        else:
            veven[vi]=1
    else:
        if(vi in vodd):
            vodd[vi]+=1
        else:
            vodd[vi]=1
veven=list(veven.items())
veven.sort(key=lambda x:-x[1])
vodd=list(vodd.items())
vodd.sort(key=lambda x:-x[1])
if veven[0][0]==vodd[0][0]:
    a=veven[0][1]+vodd[1][1]
    b=veven[1][1]+vodd[0][1]
    changeCnt=n-a if a>b else n-b
else:
    changeCnt=n-veven[0][1]-vodd[0][1]

print(changeCnt)
A = map(int,input().split())
if A[0]+A[1]+A[2] < 22:
  print("win")
else:
  print("bust")

### FIXED CODE ###

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

if sum(A)<=21:
  print("win")
else:
  print("bust")
n = int(input())
table = map(int,input().split())
print("{}{}{}".format(max(table[n],min(table[n],sum(table[n])))))


### FIXED CODE ###

n = input()
table = list(map(int,input().split()))
print("{} {} {}".format(min(table),max(table),sum(table)))
s = list(map(str,input()))
t = list(map(str,input()))

ans = len(t)

for i in range(0,len(s)-len(t)+1):
    df = 0
    if s[i+j] != t[j]:
        df += 1
        ans = min(ans,df)

print(ans)

### FIXED CODE ###

s = list(map(str,input()))
t = list(map(str,input()))

ans = len(t)

for i in range(0,len(s)-len(t)+1):
    df = 0
    for j in range(0,len(t)):
        if s[i+j] != t[j]:
            df += 1
    ans = min(ans,df)

print(ans)
import sys

def f(x):
    p=0
    cnt=0
    for i in range(n-1,-1,-1):
        while p<n and a[i]+a[p]<x:
            p+=1
        cnt+=n-p
    return cnt

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

l,r=a[0]*2,a[n-1]*2

while r-l>0:
    if r-l<=1:
        if f(r)==m: md=r;break 
        else: md=l;break
    md=(r+l)//2
    k=f(md)
    if k==m: break
    elif k>m: l=md
    else: r=md

p=0
cnt=0
ans=0

for i in range(n-1,-1,-1):
    try:
        while p<n and a[i]+a[p]<=md:
            p+=1
        if p==n: break
        cnt+=n-p
        ans+=a[i]*(n-p)*2
    except:
        ans+=0




ans+=(m-cnt)*md
print(ans)

### FIXED CODE ###

import sys

def f(x):
    p=0
    cnt=0
    for i in range(n-1,-1,-1):
        while p<n and a[i]+a[p]<x:
            p+=1
        cnt+=n-p
    return cnt

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

l,r=a[0]*2,a[n-1]*2
md=(r+l)//2
while r-l>0:
    if r-l<=1:
        if f(r)==m: md=r;break 
        else: md=l;break
    md=(r+l)//2
    k=f(md)
    if k==m: break
    elif k>m: l=md
    else: r=md

p=0
cnt=0
ans=0

for q in range(n-1,-1,-1):
    try:
        while p<n and a[q]+a[p]<=md:
            p+=1
    except:
        b=1
        while True:
            b+=1

    if p==n: break
    cnt+=n-p
    ans+=a[q]*(n-p)*2


ans+=(m-cnt)*md
print(ans)
num = map(int, input().split())
a = num[0]
b = num[1]
c = num[2]

if a == b == c:
    print(1)

elif (a==b and b!=c) or (b==c and a!=b) or (a==c and b!=a):
    print(2)

else:
    print(3)




### FIXED CODE ###

a, b, c = map(int, input().split())

if a == b == c:
    print(1)

elif (a==b and b!=c) or (b==c and a!=b) or (a==c and b!=a):
    print(2)

else:
    print(3)
import math
a, b, h, m = map(int,input().split())

a_s = (30 * h) % 360 + 0.5 * m
b_s = (6*m)

s = max(a_s,b_s) - min(a_s,b_s)
ans = math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(s)))
print(ans)

### FIXED CODE ###

N = int(input())
n = N % 10

if n == 3:
    print('bon')
elif n in [0, 1, 6, 8]:
    print('pon')
else:
    print('hon')
import sys
input = sys.stdin.readline
n = int(input())

cnt = [0]*n

for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            if x**2 + y**2 + z**2 + x*y + x*z + y*z - 1 < n:
                cnt[x**2 + y**2 + z**2 + x*y + x*z + y*z - 1] += 1
print(*cnt,sep='\n')
        

### FIXED CODE ###

l,r,d = map(int,input().split())

ans = 0

for i in range(l,r+1):
    if i%d == 0:
        ans += 1
print(ans)
#a,b=map(int,input().split())
n=int(input())
#s=input()
ans=1
for i in range(n):
  ans*=(n%mod)
  ans%=mod
print(ans)

### FIXED CODE ###

#a,b=map(int,input().split())
n=int(input())
mod=10**9+7
#s=input()
ans=1
for i in range(1,n+1):
  ans*=(i%mod)
  ans%=mod
print(ans%mod)
import numpy as np
N = int(input())
x = [0]*N
u = [0]*N
for i in range(N):
    x[i], u[i]= map(input().split())
    
x_int = [float(j) for j in x]
u_replace = [1 if k =="JPY" else 380000.0 for k in u]

x_arr = np.array(x_int)
u_arr = np.array(u_replace).reshape(N, 1)


### FIXED CODE ###

import numpy as np
N = int(input())
x = [0]*N
u = [0]*N
for i in range(N):
    x[i], u[i]= map(str, input().split())
    
x_int = [float(j) for j in x]
u_replace = [1 if k =="JPY" else 380000.0 for k in u]

x_arr = np.array(x_int)
u_arr = np.array(u_replace).reshape(N, 1)

ans = np.dot(x_arr, u_arr)
print(ans[0])
n, m, q = map(int, input().split())
a = [0]*q
b = [0]*q
c = [0]*q
d = [0]*q
for i in range(q):
  a[i], b[i], c[i], d[i] = map(int, input().split())
A = [1] * 10

def check(A, ans):
  t = 0
  for i in range(q):
    if A[b[i]] - A[a[i]] == c[i]:
      t += d[i]
  if ans < t:
    return t
  else:
    return ans

ans = 0
for i1 in range(1, m):
  A[1] = i1
  for i2 in range(i1, m):
    A[2] = i2
    for i3 in range(i2, m):
      A[3] = i3
      for i4 in range(i3, m):
        A[4] = i4
        for i5 in range(i4, m):
          A[5] = i5
          for i6 in range(i5, m):
            A[6] = i6
            for i7 in range(i6, m):
              A[7] = i7
              for i8 in range(i7, m):
                A[8] = i8
                for i9 in range(i8, m):
                  A[9] = i9
                  ans = check(A, ans)
print(ans)

### FIXED CODE ###

n, m, q = map(int, input().split())
a = [0]*q
b = [0]*q
c = [0]*q
d = [0]*q
for i in range(q):
  a[i], b[i], c[i], d[i] = map(int, input().split())
A = [1] * 10

def check(A, ans):
  t = 0
  for i in range(q):
    if A[b[i]-1] - A[a[i]-1] == c[i]:
      t += d[i]
  if ans < t:
    return t
  else:
    return ans

ans = 0
for i1 in range(1, m+1):
  A[1] = i1
  if n >= 3:
    for i2 in range(i1, m+1):
      A[2] = i2
      if n >= 4:
        for i3 in range(i2, m+1):
          A[3] = i3
          if n >= 5:
            for i4 in range(i3, m+1):
              A[4] = i4
              if n >= 6:
                for i5 in range(i4, m+1):
                  A[5] = i5
                  if n >= 7:
                    for i6 in range(i5, m+1):
                      A[6] = i6
                      if n >= 8:
                        for i7 in range(i6, m+1):
                          A[7] = i7
                          if n >= 9:
                            for i8 in range(i7, m+1):
                              A[8] = i8
                              if n >= 10:
                                for i9 in range(i8, m+1):
                                  A[9] = i9
                                  ans = check(A, ans)
                              else:
                                ans = check(A, ans)
                          else:
                            ans = check(A, ans)
                      else:
                        ans = check(A, ans)
                  else:
                    ans = check(A, ans)
              else:
                ans = check(A, ans)
          else:
            ans = check(A, ans)
      else:
        ans = check(A, ans)
  else:
    ans = check(A, ans)
print(ans)
N, K = map(int, input().split())
T_list = list(map(int, input().split()))
T_list = [T_list[i]-1 for i in range(N)]

if K < N:
  while i < K:
    point = T_list[point]
    i += 1  

else:
  point = 0
  syuuki = 0
  i = 0
  while i < N:
    point = T_list[point]
    if point == 0:
      syuuki = i+1
      break
    i += 1

  second_point = point
  if syuuki != 0:
    L = K % syuuki

  else:
    j = 0
    while j < N:
      point = T_list[point]
      if point == second_point:
        syuuki = j+1
        break
      j += 1
    L = (K-i) % syuuki

  k = 0
  while k < L:
    point = T_list[point]
    k += 1
  
print(point+1)

### FIXED CODE ###

N, K = map(int, input().split())
T_list = list(map(int, input().split()))
T_list = [T_list[i]-1 for i in range(N)]
point = 0
syuuki = 0

if K < N:
  i = 0
  while i < K:
    point = T_list[point]
    i += 1  

else:
  i = 0
  while i < N:
    point = T_list[point]
    if point == 0:
      syuuki = i+1
      break
    i += 1
  second_point = point
  
  if syuuki != 0:
    L = K % syuuki

  else:
    j = 0
    while j < N:
      point = T_list[point]
      if point == second_point:
        syuuki = j+1
        break
      j += 1
    L = (K-i) % syuuki

  k = 0
  while k < L:
    point = T_list[point]
    k += 1
  
print(point+1)