Harryxun/stf_run huggingface dataset:
N,K=map(int,(input().split()))
TO=list(map(int,input().split()))

visit_flag=[[0]*2 for i in [1]*N]
visit_count=1
first_visit=0
last_visit=0
next_town=1
visit_flag[0][0]=1
visit_flag[0][1]=1

for i in range(K):
    visit_count+=1
    next_town = TO[next_town-1]
    if visit_flag[next_town-1][0]==0:
        visit_flag[next_town-1][0]=1
        visit_flag[next_town-1][1]=visit_count
    else:
        first_visit=visit_flag[next_town-1][1]
        last_visit=visit_count
        break

roop=last_visit-first_visit

if K<=roop:
    for i in range(K):
        next_town = 1
        next_town = TO[next_town-1]
    ans=next_town
else:
    for i in range((K-roop)%roop):
        next_town = TO[next_town-1]
    ans=next_town

print(ans)


### FIXED CODE ###

N,K=map(int,(input().split()))
TO=list(map(int,input().split()))

visit_flag=[[0]*2 for i in [1]*N]
visit_count=0
first_visit=0
last_visit=0
next_town=1
visit_flag[0][0]=1
visit_flag[0][1]=0

for i in range(K):
    visit_count+=1
    next_town = TO[next_town-1]
    if visit_flag[next_town-1][0]==0:
        visit_flag[next_town-1][0]=1
        visit_flag[next_town-1][1]=visit_count
    else:
        first_visit=visit_flag[next_town-1][1]
        last_visit=visit_count
        break

roop=last_visit-first_visit
span=visit_flag[next_town-1][1]

if K<=roop:
    next_town = 1
    for i in range(K):     
        next_town = TO[next_town-1]
    ans=next_town
else:
    if roop==0:
        ans=next_town
    else:
        for i in range((K-span)%roop):
            next_town = TO[next_town-1]
        ans=next_town

print(ans)
n_cards = int(input())
taro_cards = []
for i in range(n_cards):
    taro_card = input()
    taro_cards.append(taro_card)
full_cards = []
for mark in ['S', 'H', 'C', 'D']:
    for card_number in range(13):
        full_cards.append(mark + " " + str(card_number+1))

missing_cards = []
for card in full_cards:
    if card not in taro_cards:
        missing_cards.append(card)

for missing_card in missing_cards:
    print(missing_card)



### FIXED CODE ###

n_cards = int(input())
taro_cards = []
for i in range(n_cards):
    taro_card = input()
    taro_cards.append(taro_card)
full_cards = []
for mark in ['S', 'H', 'C', 'D']:
    for card_number in range(13):
        full_cards.append(mark + " " + str(card_number+1))

missing_cards = []
for card in full_cards:
    if card not in taro_cards:
        missing_cards.append(card)

for missing_card in missing_cards:
    print(missing_card)
n,l=map(int,input().split())
d=114514
num=114514
for j in range(n):
  if abs(l+j)<d:
    d=abs(l+j)
    num=j
s=0
for in range(n):
  s+=1
print(s+(n-1)*l-num)


### FIXED CODE ###

n,l=map(int,input().split())
d=114514
num=114514
for j in range(n):
  if abs(l+j)<d:
    d=abs(l+j)
    num=j
s=0
for i in range(n):
  s+=i
print(s+(n-1)*l-num)
N=int(input())
S=input()

count=0
for i in range(0,N):
    if(S[i]=="A"):
        i=i+1
        if(S[i]=="B"):
            i=i+1
            if(S[i]=="C"):
                count+=1

print(count)

### FIXED CODE ###

N=int(input())
S=input()

count=0
for i in range(0,N):
    if(S[i]=="A"):
        if(i<=N-3):
            if(S[i+1]=="B"):
                if(S[i+2]=="C"):
                    count+=1

print(count)
n,m,k = map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A,B = [0],[0]
 
for i in range(n):
  A.append(a[i] + A[i])
for i in range(m):
  B.append(b[i] + B[i])
 
num,x = 0,m-1
A.pop(0)
B.pop(0)
 
for i in range(len(A)-1):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x + 2)
  
print(num)


### FIXED CODE ###

n,m,k = map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A,B = [0],[0]

for i in range(n):
  A.append(a[i] + A[i])
for i in range(m):
  B.append(b[i] + B[i])

num,x = 0,m

for i in range(n+1):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x)
  
print(num)
import math

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

def get_num(a, lcm):
    return lcm // a


N_str = input()
a_str = input()
a_str_list = a_str.split(" ")
a_list = list(map(lambda x: int(x), a_str_list))
lcm = 1
for a in a_list:
    lcm = get_lcm(lcm, a)

sum_a = 0
for a in a_list:
    sum_a += get_num(a, lcm)

result = lcm / sum_a
print(result)

### FIXED CODE ###

import fractions

def get_lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

def get_num(a, lcm):
    return lcm // a


N_str = input()
a_str = input()
a_str_list = a_str.split(" ")
a_list = list(map(lambda x: int(x), a_str_list))
lcm = 1
for a in a_list:
    lcm = get_lcm(lcm, a)

sum_a = 0
for a in a_list:
    sum_a += get_num(a, lcm)

result = lcm / sum_a
print(result)
# -*- coding: utf-8 -*-
from sys import stdin
import numpy as np
input = stdin.readline
N = int(input())
A = list(map(int,input().split()))
np_A = np.array(A)
ans = np_A[0]

2
for i in range(1, N, 1):
    ans = ans*np_A[i]
    if ans > 10**18:
        flag = False
        break


if flag == False:
    print(-1)

else:
    print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
from sys import stdin
from decimal import *
import numpy as np
input = stdin.readline
N = int(input())
A = list(map(Decimal,input().split()))
np_A = np.array(A)
ans = np_A[0]

zero_flag = False
if 0 in A:
    zero_flag = True

flag = True

for i in range(1, N, 1):
    ans = Decimal(ans)*Decimal(np_A[i])
    #print(ans)
    if ans > 10**18:
        flag = False
        break


if zero_flag == True:
    print(0)


else:
    if flag == False:
        print(-1)

    else:
        print(ans)
# -*- coding: utf-8 -*-

import math

x,y,z,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a.sort()
a.reverse()
b.sort()
b.reverse()
c.sort()
c.reverse()

cnum = []

takadaka = math.ceil(k ** 0.67)

for i in range(min(takadaka,x)):
    for j in range(min(takadaka,y)):
        for l in range(min(takadaka,z)):
            cnum.append(a[i] + b[j] + c[l])

cnum.sort()
cnum.reverse()

for i in range(k):
    print(cnum[i])


### FIXED CODE ###

# -*- coding: utf-8 -*-
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

if e - a <= k:
    print("Yay!")
else:
    print(":(")
sent=""
while True:
    ex=input().lower()
    print(ex)
    sent+=ex
    if ex.find('.')==1:
        break
for i in range(ord("a"),ord("z")+1):
    x=sent.count(chr(i))
    print(chr(i),":",x)

### FIXED CODE ###

sent=""
while True:
    try:
        ex=input().lower()
        sent+=ex
    except:
        break
for i in range(ord("a"),ord("z")+1):
    x=sent.count(chr(i))
    print(chr(i),":",x)
A, B, C, D = map(int, input().split())
if(A<C):
  print(max(0, B-D))
if(A>C):
  print(max(0, D-B))
if(A=C):
  print(min(B-A, D-A))
        

### FIXED CODE ###

A, B, C, D = map(int, input().split())
print(max(0, min(B,D) - max(A,C)))
n=int(input())
a=list(map(int,input().split()))
c=[0]*9

for r in a:
  x=r//400
  if x>8:
    x==8
  c[x]+=1
ans=0
for i in range(9):
  if i==8:
    if ans==0:
      mn=1
      mx=n
    else:
      mn=ans
      mx=ans+c[i]
  if c[i]!=0:
    ans+=1

print("{} {}".format(mn,mx))

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
c=[0]*9

for r in a:
  x=r//400
  if x>8:
    x=8
  c[x]+=1
ans=0
for i in range(9):
  if i==8:
    if ans==0:
      mn=1
      mx=n
    else:
      mn=ans
      mx=ans+c[i]
  if c[i]!=0:
    ans+=1

print("{} {}".format(mn,mx))
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

print("Yes" if "9" in ns else "No")


### FIXED CODE ###

import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

print("Yes" if "9" in ns() else "No")
a= input()
b = input()
for i in range(len(a)*2):
    if i%2:
        print(a[i/2],end='')
    else:
        print(b[i/2],end='')
print()

### FIXED CODE ###

a= input()
b = input()
for i in range(len(a)*2):
    if i%2:
        if i//2>=len(b):
            continue
        print(b[i//2],end='')
    else:
        if i//2 >= len(a):
            continue
        print(a[i//2],end='')
print()
import math
A,B = map(int,input().split())
ans = 0
for i in range (A,B+1):
    s = str(i)
    kai = True
    for j in range (0, math.celi(len(s)/2)):
        if s[j] != s[-j - 1]:
            kai = False
            break
    if kai == True:
        ans += 1
print(ans)

### FIXED CODE ###

import math
A,B = map(int,input().split())
ans = 0
for i in range (A,B+1):
    s = str(i)
    kai = True
    for j in range (0, math.ceil(len(s)/2)):
        if s[j] != s[-j - 1]:
            kai = False
            break
    if kai == True:
        ans += 1
print(ans)
def fact(n):
	return 1 if n == 0 else n*fact(n-1)

S = raw_input()
l,s = len(S),set(list(S))
lens = len(s)
d = [S.count(i) for i in s]
if l%2 == 0:
	for i in range(lens):
		if d[i]%2 == 1:
			print 0
			break
	else:
		denomi = 1
		for i in range(lens):
			denomi *= fact(d[i]/2)
		print fact(l/2)/denomi
else:
	for i in range(m):
		if sum([d[i]%2 for i in range(lens)]) != 1:
			print 0
			break
	else:
		denomi = 1
		for i in range(lens):
			denomi *= fact(d[i]/2) if d[i]%2 == 0 else fact((d[i]-1)/2)
		print fact((l-1)/2)/denomi

### FIXED CODE ###

from math import factorial as f
S = raw_input()
L = len(S)
d = [S.count(i) for i in set(list(S))]
dd = sum([i%2 for i in d])
if (L%2 == 0 and dd != 0 ) or (L%2 == 1 and dd != 1): 
		print 0
else:
	ans = f(L/2)
	for i in d:
		ans /= f(i/2)
	print ans
e True:
    try:
        a = map(long,raw_input().split())
        m = a[0]*a[4]-a[1]*a[3]

        x = (a[4]*a[2] - a[1]*a[5])/m
        y = (a[0]*a[5] - a[2]*a[3])/m

	if x == -0:
            x = 0
	if y == -0:
            y = 0

	print "%.3f %.3f" % (x,y)

    except EOFError:
	break

### FIXED CODE ###

while True:
    try:
        a = map(float,raw_input().split())
        m = a[0]*a[4]-a[1]*a[3]

        x = (a[4]*a[2] - a[1]*a[5])/m
        y = (a[0]*a[5] - a[2]*a[3])/m

	if x == -0:
            x = 0
	if y == -0:
            y = 0

	print "%.3f %.3f" % (x,y)

    except EOFError:
	break
#!/usr/bin/env python3

# from numba import njit

# input = stdin.readline

def calcGroup(s):
  whiteCount = 0
  blackCount = 0
  prev = ""
  for i in range(len(s)):
    if s[i] == prev:
      pass
    else:
      if s[i] = "W":
        whiteCount += 1
      elif s[i] = "B":
        blackCount += 1
      else:
        raise ValueError
    prev = s[i]
  return whiteCount,blackCount

# @njit
def solve(s):
  # white,black = calcGroup(s)
  return min(calcGroup(s))



def main():
  s = input()
  print(solve(s))
  return

if __name__ == '__main__':
  main()

### FIXED CODE ###

#!/usr/bin/env python3

# from numba import njit

# input = stdin.readline

def calcGroup(s):
  whiteCount = 0
  blackCount = 0
  prev = ""
  for i in range(len(s)):
    if s[i] == prev:
      pass
    else:
      if s[i] == "W":
        whiteCount += 1
      elif s[i] == "B":
        blackCount += 1
      else:
        raise ValueError
    prev = s[i]
  return whiteCount,blackCount

# @njit
def solve(s):
  white,black = calcGroup(s)
  if abs(white-black) == 0:
    return (white-1)*2+1
  else:
    return min(white,black)*2



def main():
  s = input()
  print(solve(s))
  return

if __name__ == '__main__':
  main()
p,q,r = map(int,input().split())

min = p + q
if(min > q + r):
    min = q + r
elif(min > p + r):
    min = P + r
print(min)

### FIXED CODE ###

p,q,r = map(int,input().split())

mintime = p + q + r - max(p,q,r)

print(mintime)
n, x, y = map(int, input().split())

ans = {}
for i in range(n-1):
  ans[i+1] = 0
  
for i in range(n):
  for j in range(i+1,n):
    if i <= x-i:
      if j <= x-1:
      	t=j-i
      	ans[t] += 1
      elif j <= y-1:
      	t = min(j-i, (x-1)-i + 1 + (y-1) -j)
      	ans[t] += 1
      else: #j > y-1
      	t = (x-1)-i + 1 + j -(y-1)
      	ans[t] += 1
    elif i < y-1:
      if j < y-1:
      	t = min(j-i, i-(x-1) + 1 + (y-1) -j)
      	ans[t] += 1
      else: #j >= y-1:
      	t = min(j-i, i-(x-1) + 1 + j - (y-1))
      	ans[t] += 1
    elif i >= y-1:
      t=j-i
      ans[t] += 1
    else:
      print("error")

for i in range(1,n):
  print(ans[i])


### FIXED CODE ###

n, x, y = map(int, input().split())

ans = {}
for i in range(n-1):
  ans[i+1] = 0
  
for i in range(n):
  for j in range(i+1,n):
    if i <= x-1:
      if j <= x-1:
      	t=j-i
      	ans[t] += 1
      elif j <= y-1:
      	t = min(j-i, (x-1)-i + 1 + (y-1) -j)
      	ans[t] += 1
      else: #j > y-1
      	t = (x-1)-i + 1 + j -(y-1)
      	ans[t] += 1
    elif i < y-1:
      if j < y-1:
      	t = min(j-i, i-(x-1) + 1 + (y-1) -j)
      	ans[t] += 1
      else: #j >= y-1:
      	t = min(j-i, i-(x-1) + 1 + j - (y-1))
      	ans[t] += 1
    elif i >= y-1:
      t=j-i
      ans[t] += 1
    else:
      print("error")

for i in range(1,n):
  print(ans[i])
S = input()
T = "AKIHABARA"
if S[-1] != "A":
    S += "A"
l = len(S)
t = 0
ans = "YES"
K = ""
c = 0
for i in range(9):
    if T[i] == S[t]:
        K += T[i]
        t += 1
        continue
    elif T[i] == "A":
        K += "A"
        c += 1
        continue
    else:
        ans = "NO"
        break

if T == K and c+l == 9:
    print(ans)
else:
    print("NO")


### FIXED CODE ###

S = list(input())
T = list("AKIHABARA")
ans = "YES"
i = 0
while i < len(S) and i < 9:
    if S[i] != T[i]:
        if T[i] == "A":
            S.insert(i,"A")
    i += 1
if S[-1] != "A":
    S += "A"

if S == T:
    print("YES")
else:
    print("NO")
#using
a=input()
b=input()
print(b)
m=int(a)+int(b)
if int(m)<10:
	print(int(m))
else:
	print("error")

### FIXED CODE ###

# coding: utf-8
a,b=input().split()
m=int(a)+int(b)
if m<10:
  print(int(m))
else:
  print("error")
import sys

def main():
    arg = sys.argv[1:]
    a = int(arg[0])
    b = int(arg[2])
    op = arg[1]
    #if a < 1 or b > 10 **9:
    #    return 0

    if op == "+":
        return a + b
    elif op == "-":
        return a - b
    #else:
    #    return 0

print main()


### FIXED CODE ###

import sys

def main():
    arg = raw_input().split(" ")
    a = int(arg[0])
    b = int(arg[2])
    op = arg[1]
    if a < 1 or b > 10 **9:
        return 0

    if op == "+":
        return a + b
    elif op == "-":
        return a - b
    else:
        return 0

print main()
import heapq
n = int(input())
tree = [0]*n
input_list = [0]*n
 
for i in range(n-1):
    a, b = map(int, input().split())
    input_list[i] = [a, b]
    tree[a-1] = tree[a-1] + 1
    tree[b-1] = tree[b-1] + 1

ans = max(tree)
print(ans)

keyofkey = [[int(i) for i in range(1, ans+1)] for i in range(n)]

for i in range(n-1):
    a, b = input_list[i][0], input_list[i][1]
    key_list = list(set(keyofkey[a-1]) & set(keyofkey[b-1]))
    p = key_list[0]
    keyofkey[a-1].remove(p)
    keyofkey[b-1].remove(p)
    print(p)

### FIXED CODE ###

from collections import deque
import sys

def main():
    input = sys.stdin.readline
    n = int(input())
    
    node = [0]*(n-1)
    next_node = [[] for _ in range(n)]
    for i in range(n-1):
        a, b = map(int, input().split())
        node[i] = (a-1, b-1)
        next_node[a-1].append(b-1)
        next_node[b-1].append(a-1)
    
    ans = 0
    for i in range(n):
        if ans < len(next_node[i]):
            ans = len(next_node[i])
    print(ans)
    
    not_yet = deque([])
    already = [False]*n
    parent = [0]*n
    ans_list = dict()
    k = 1
    
    already[0] = True
    for value in next_node[0]:
        not_yet.append(value)
        ans_list[(0, value)] = k
        parent[value] = k
        already[value] = True
        k += 1
    
    
    while not_yet:
        k = 1
        key = not_yet.popleft()
        for value in next_node[key]:
            if already[value]:
                continue
            already[value] = True
            not_yet.append(value)
            if k == parent[key]:
                k += 1
            parent[value] = k
            p, q = min([key, value]), max([key, value])
            ans_list[(p, q)] = k
            k += 1
            
    
    for value in node:
        print(ans_list[value])


if __name__ == "__main__":
    main()
class Inv:
  def __init__(s, mod):
    s.MOD = mod
  def modpow(s, a, n):
    res = 1
    while n > 0:
      if n & 1:
        res = res * a % s.MOD
      a = a * a % s.MOD
      n >>= 1
    return res
  def invx(s, a):
    return s.modpow(a, s.MOD - 2)
  def invpowL(s, a, n): # a^-x (0 <= x <= n)リスト
    ia = s.invx(a)
    L = [1] * (n + 1)
    for i in range(1, n + 1):
      L[i] = L[i - 1] * ia % s.MOD
    return L
  def invL(s, n): # 0 <= x <= n 逆元リスト
    I = [0, 1]
    for i in range(2, n + 1):
      I.append(s.MOD - I[s.MOD % i] * (s.MOD // i) % s.MOD)
    return I


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

DP = [[0] * (S + 1) for _ in range(N + 1)]

inv = Inv(MOD)
v = inv.invx(2)

p = inv.modpow(2, N - 1)
for i in range(1, N + 1):
  a = A[i - 1]
  if a > S: 
    for j in range(S + 1):
      DP[i][j] = DP[i - 1][j]
  for j in range(a):
    DP[i][j] = DP[i - 1][j]
  DP[i][a] = (DP[i - 1][a] + p) % MOD
  for j in range(a + 1, S + 1):
    DP[i][j] = (DP[i - 1][j] + DP[i - 1][j - a] * v) % MOD

for i in DP:
  print(i)
print(DP[-1][S])


### FIXED CODE ###

class Inv:
  def __init__(s, mod):
    s.MOD = mod
  def modpow(s, a, n):
    res = 1
    while n > 0:
      if n & 1:
        res = res * a % s.MOD
      a = a * a % s.MOD
      n >>= 1
    return res
  def invx(s, a):
    return s.modpow(a, s.MOD - 2)
  def invpowL(s, a, n): # a^-x (0 <= x <= n)リスト
    ia = s.invx(a)
    L = [1] * (n + 1)
    for i in range(1, n + 1):
      L[i] = L[i - 1] * ia % s.MOD
    return L
  def invL(s, n): # 0 <= x <= n 逆元リスト
    I = [0, 1]
    for i in range(2, n + 1):
      I.append(s.MOD - I[s.MOD % i] * (s.MOD // i) % s.MOD)
    return I


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

DP = [[0] * (S + 1) for _ in range(N + 1)]

inv = Inv(MOD)
v = inv.invx(2)

p = inv.modpow(2, N - 1)
for i in range(1, N + 1):
  a = A[i - 1]
  if a > S: 
    for j in range(S + 1):
      DP[i][j] = DP[i - 1][j]
    continue
  for j in range(a):
    DP[i][j] = DP[i - 1][j]
  DP[i][a] = (DP[i - 1][a] + p) % MOD
  for j in range(a + 1, S + 1):
    DP[i][j] = (DP[i - 1][j] + DP[i - 1][j - a] * v) % MOD

print(DP[-1][S])
a=int(input())
b=list(input())
c=0
d
for i in range(a):
  if b[i]=="A":
    d+=1
  
    if d==1 and b[i+1]=='B':
      
        
      d+=1
      if d==2 and b[i+2]='C':
          
          
        
        
          d=0
          c+=1
  else:
    d=0
        
      
print(c)


### FIXED CODE ###

n=int(input())
s=list(input())
d=0
for i in range(n):
  if n-(i+1)>=2:
    if s[i]=='A' and s[i+1]=='B' and s[i+2]=='C':
      d+=1
  else:
    pass
print(d)
h, w, k = map(int,input().split())
c = []
for i in range(h):
  c.append(input())
  
def countb(c):
  num = 0
  for i in range(h):
    num += c[i].count("#")
  return(num)

def printb(c, row, col):
  c = c[:]
  #print(row,col)
  cnt = 0
  while row != 0:
    if row  & 0b1:
     
      c[cnt] = "."*w
    cnt += 1
    row = row >> 1
  
  cnt = 0
  while col != 0:
    #print(col&0b1)
    if col & 0b1:
      for i in range(h):
        c[i] = c[i][:cnt]+"."+c[i][cnt+1:]
    cnt += 1
    col = col >> 1
    
  #print("\n".join(c))
  return countb(c)

if countb(c) == k:
  print(0)
else:
  ans = 0
  for i in range(2**h):
    for j in range(2**w):
      if printb(c,i,j) == k:
        ans += 1
        
  
print(ans)


### FIXED CODE ###

h, w, k = map(int,input().split())
c = []
for i in range(h):
  c.append(input())
  
def countb(c):
  num = 0
  for i in range(h):
    num += c[i].count("#")
  return(num)

def printb(c, row, col):
  c = c[:]
  #print(row,col)
  cnt = 0
  while row != 0:
    if row  & 0b1:
     
      c[cnt] = "."*w
    cnt += 1
    row = row >> 1
  
  cnt = 0
  while col != 0:
    #print(col&0b1)
    if col & 0b1:
      for i in range(h):
        c[i] = c[i][:cnt]+"."+c[i][cnt+1:]
    cnt += 1
    col = col >> 1
    
  #print("\n".join(c))
  return countb(c)

ans = 0
for i in range(2**h):
  for j in range(2**w):
    if printb(c,i,j) == k:
      ans += 1
print(ans)
import heapq
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
count=0
Q=[]
heapq.heapify(Q) 
heapq.heappush(Q, (-A[0],-A[0],0))
for i in range(1,N):
    B=heapq.heappop(Q)
    count+=-B[0]
    heapq.heappush(Q, (-A[1],-A[i],B[1]))
    heapq.heappush(Q, (-A[2],-A[i],B[2]))
print(count)

### FIXED CODE ###

import heapq
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
count=0
Q=[]
heapq.heapify(Q) 
heapq.heappush(Q, (-A[0],-A[0],0))
for i in range(1,N):
    B=heapq.heappop(Q)
    count+=-B[0]
    heapq.heappush(Q, (-A[i],-A[i],B[1]))
    heapq.heappush(Q, (-A[i],-A[i],B[2]))
print(count)
n = int(input())
ls = []
l = [0 for i in range(n)]
for i in range(n):
  ls.append(input())
for i in range(n):
  for j in range(10):
    alpha = ord(ls[i][j]) - ord("a")
    l[i]+=10**alfa
ans = 0
for i in range(n):
  for j in range(i+1,n):
    if l[i] == l[j]:
      ans+=1
print(ans)


### FIXED CODE ###

n = int(input())
ls = []
dic = {}
ans = 0
for i in range(n):
    ls.append(input())
for i in range(n):
    tmp = "".join(sorted(ls[i]))
    if tmp in dic:
        ans += dic[tmp]
        dic[tmp] += 1
    else:
        dic[tmp] = 1
print(ans)
n = int(input())
L = list(map(int, input().split()))


### FIXED CODE ###

T, X = map(int, input().split())
print(T/X)
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a=list(set(a))
b=list(set(b))
c=list(set(c))
a.sort()
b.sort()
c.sort()
i,j=0,0
d1=dict()
for k in a:
  if b[i]>k:
    j+=1
  else:
    d1[b[i]]=j
    i+=1
for t in range(i,n):
  d1[b[t]]=j
i,j=0,0
d2=dict()
for k in b:
  if c[i]>k:
    j+=d1[k]
  else:
    d2[c[i]]=j
    i+=1
for t in range(i,n):
  d2[c[t]]=j
print(sum(d2.values()))


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
i,j,k=0,0,0
m1=[]
while k<n and i<n:
  if b[i]>a[k]:
    j+=1
    k+=1
  else:
    m1.append(j)
    i+=1
for t in range(len(m1),len(b)):
  m1.append(j)
i,j,k=0,0,0
m2=[]
while k<n and i<n:
  if c[i]>b[k]:
    j+=m1[k]
    k+=1
  else:
    m2.append(j)
    i+=1
for t in range(len(m2),len(c)):
  m2.append(j)
print(sum(m2))
n,m=map(input().split())

a=n*(n-1)/2+m*(m-1)/2

print(str(a))
  

### FIXED CODE ###

n,m=map(int, input().split())
 
a=n*(n-1)/2+m*(m-1)/2
 
print(str(int(a)))
s=list(input())
t=list(input())
ans=[]
for i in range(len(s)-len(t)):
  cnt=0
  for j in range(i,len(t)+i):
    if s[j]!=t[j-i]:
      cnt+=1
  ans.append(cnt)
print(min(ans))


### FIXED CODE ###

s=list(input())
t=list(input())
ans=[]
for i in range(len(s)-len(t)+1):
  cnt=0
  for j in range(i,len(t)+i):
    if s[j]!=t[j-i]:
      cnt+=1
  ans.append(cnt)
print(min(ans))
n = int(input())
s = input()
l = []
 
for i in range(n):
  l.append(s[i])
 
 
print(len(set(l)))

### FIXED CODE ###

n = int(input())
s = [input() for i in range(n)]
S = len(set(s))

print(S)