Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

def main():
    input()
    s = raw_input()
    a2 = set()
    a3 = set()
    for i, c1 in enumerate(s[:-2]):
        for j, c2 in enumerate(s[i+1:-1], i + 1):
            ss = c1 + c2
            if ss in a2:
                continue
            a2.add(ss)
            for c3 in set(s[j+1:]):
                a3.add(ss + c3)
    print len(a3)

main()


### FIXED CODE ###

def main():
    n = input()
    s = raw_input()
    a1 = set()
    a2 = set()
    a3 = set()
    jj = [set()]
    for j in xrange(n - 1, 1, -1):
        jj.append(jj[-1] | {s[j]})
    jj = jj[::-1]
    for i, c1 in enumerate(s[:-2]):
        if c1 in a1:
            continue
        a1.add(c1)
        for j in xrange(i + 1, n - 1):
            ss = c1 + s[j]
            if ss in a2:
                continue
            a2.add(ss)
            for c3 in jj[j - 1]:
                a3.add(ss + c3)
    print len(a3)

main()
### BUGGY CODE ###

n=int(input())
A=map(int,input().split())
c=0
loop=True
while(loop):
  for a in A:
    if a%2!=0:
      loop=False
      break
  if loop:
      A = map(lambda i:i//2, A)
      c+=1
  else:
      break
print(c)

### FIXED CODE ###

n=int(input())
A=list(map(int,input().split()))
c=0
loop=True
while(loop):
    for a in A:
        if a%2!=0:
            loop=False
            break
    if loop:
        A = list(map(lambda i:i//2, A))
        c+=1
    else:
        break
print(c)
### BUGGY CODE ###

def main():
    n, k = map(int, input().split())
    lr = [list(map(int, input().split())) for _ in range(k)]

    dp = [0] * (n+1);

    dp[0] = 1
    dp[1] = -1

    for i in range(0, n):
        if i>0: dp[i] += dp[i-1]
        for l,r in lr:
            if i+l > n: continue
            dp[i+l] += dp[i]
            dp[min(n, i+r+1)] -= dp[i]

    print(dp[n-1] % 998244353)

main()


### FIXED CODE ###

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

dp = [0] * (n+1);

dp[0] = 1
dp[1] = -1

for i in range(0, n):
    if i>0: dp[i] += dp[i-1]
    dp[i] %= 998244353
    for l,r in lr:
        if i+l > n: continue
        dp[i+l] += dp[i]
        dp[min(n, i+r+1)] -= dp[i]

print(dp[-2] % 998244353)
### BUGGY CODE ###

import sys
input=sys.stdin.readline
h,w,k=map(int,input().split())
calc=lambda x,y,d:(x*w+y)*4+d
si,sj,ti,tj=map(int,input().split())
si-=1
sj-=1
ti-=1
tj-=1
b=[input()for _ in range(h)]
from heapq import heappop,heappush
edge=[[]for _ in range(h*w*4)]
for i in range(h):
  for j in range(1,w):
    if b[i][j-1]==b[i][j]==".":
      edge[calc(i,j-1,0)].append((calc(i,j,0),1))
      edge[calc(i,j,2)].append((calc(i,j-1,2),1))
for j in range(w):
  for i in range(1,h):
    if b[i-1][j]==b[i][j]==".":
      edge[calc(i-1,j,3)].append((calc(i,j,3),1))
      edge[calc(i,j,1)].append((calc(i-1,j,1),1))
for i in range(h):
  for j in range(w):
    edge[calc(i,j,0)].append((calc(i,j,1),0))
    edge[calc(i,j,1)].append((calc(i,j,0),0))
    edge[calc(i,j,0)].append((calc(i,j,3),0))
    edge[calc(i,j,3)].append((calc(i,j,0),0))
    edge[calc(i,j,2)].append((calc(i,j,1),0))
    edge[calc(i,j,1)].append((calc(i,j,0),0))
    edge[calc(i,j,2)].append((calc(i,j,3),0))
    edge[calc(i,j,3)].append((calc(i,j,2),0))
def dijkstra(s,n,edge):
  inf=10**20
  ans=[inf]*n
  ans[s]=0
  root=[-1]*n
  h=[[0,s]]
  while h:
    c,v=heappop(h)
    if ans[v]<c:continue
    for u,t in edge[v]:
      if t==0:m=int(0--c//1)
      else:m=c+1/k
      if m<ans[u]:
        ans[u]=m
        root[u]=v
        heappush(h,[m,u])
  return ans
ans=dijkstra(calc(si,sj,0),h*w*4,edge)
anss=min(int(0--ans[calc(ti,tj,l)]//1)for l in range(4))
if anss==10**20:print(-1)
else:print(anss)

### FIXED CODE ###

import sys
input=sys.stdin.readline
h,w,k=map(int,input().split())
si,sj,ti,tj=map(int,input().split())
si-=1
sj-=1
ti-=1
tj-=1
b=[input()for _ in range(h)]
ans=[[-1]*w for _ in range(h)]
ans[si][sj]=0
from collections import deque
d=deque()
d.append((si,sj))
while d:
  x,y=d.popleft()
  if x==ti and y==tj:
    exit(print(ans[x][y]))
  for dx,dy in [[1,0],[-1,0],[0,-1],[0,1]]:
    for i in range(1,k+1):
      xx=x+dx*i
      yy=y+dy*i
      if not(0<=xx<h and 0<=yy<w) or b[xx][yy]=="@":break
      if 0<=ans[xx][yy]<=ans[x][y]:break
      if ans[xx][yy]==-1:d.append((xx,yy))
      ans[xx][yy]=ans[x][y]+1
print(-1)
### BUGGY CODE ###

K, S = map(int , input().strip().split(" "))


count = 0
for x in range(K+1):
    if x > S or S - x > 2*K:
        continue
    for y in range(K+1):
        if x + y > S or S - (x+y) > K:
            continue
        for z in range(K+1):
            if x + y + z > S:
                continue
            elif x + y + z == S:
                count +=1
print(count)

### FIXED CODE ###

K, S = map(int , input().strip().split(" "))


count = 0
for x in range(K+1):
    if x > S :
        break
    elif S - x > 2*K:
        continue
    for y in range(K+1):
        if x + y > S:
            break
        elif S - (x+y) > K:
            continue
        count+= 1
print(count)
### BUGGY CODE ###

from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

s = input()
k = INT()
a = set()
for i in range(len(s)):
    t = s[i]
    b = sorted(list(a))
    if len(b) > k and t > b[-1]:
        continue
    else:
        a.add(t)
    if i < len(s) - 1:
        for j in range(i+1, len(s)):
            t += s[j]
            a.add(t)
b = sorted(list(a))
print(b[k-1])

### FIXED CODE ###

from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

s = input()
k = INT()
a = set()
for i in range(len(s)):
    t = s[i]
    a.add(t)
    if i < len(s) - 1:
        for j in range(i+1, min(i+k+1,len(s))):
            t += s[j]
            a.add(t)
b = sorted(list(a))
print(b[k-1])
### BUGGY CODE ###

import math
 
num=int(input())
target=list(map(int, input().split()))
def comb(N, r):
    return math.factorial(N) // (math.factorial(N - r) * math.factorial(r))
 
for i in range(num):
    A=target.copy()
    A.pop(i)
    out=0
    for j in set(A):
        try :
            base = comb(A.count(j),2)
        except:
            base=0
        out=out+base
    print(out)

### FIXED CODE ###

import collections
n = int(input())
arr = list(map(int, input().split()))
cnt = collections.Counter(arr)
total = 0
for i in cnt.keys():
  patern = cnt[i]*(cnt[i]-1)//2
  total += patern
for j in range(n):
  tmp = total
  total -= cnt[arr[j]]*(cnt[arr[j]]-1)//2
  total += (cnt[arr[j]]-1)*(cnt[arr[j]]-2)//2
  print(total)
  total = tmp
### BUGGY CODE ###

s = input()
n = int(input())
for i in range(n):
    x = input()
    if x == "1":
        s = s[::-1]
    else:
        if x.split()[1] == '1':
            s = x.split()[2] + s
        else:
            s = s + x.split()[2]
print(s)


### FIXED CODE ###

s = input()
n = int(input())
top = 0
llist = ""
rlist = ""
for i in range(n):
    x = input()
    if x == "1":
        top += 1
        top = top%2
    else:
        if x.split()[1] == '1':
            if top == 0:
                llist = x.split()[2] + llist
            else:
                rlist += x.split()[2]
        else:
            if top == 1:
                llist = x.split()[2] + llist
            else:
                rlist += x.split()[2]
if top == 0:
    print(llist + s + rlist)
else:
    print(rlist[::-1] + s[::-1] + llist[::-1])
### BUGGY CODE ###

n = int(input())
a_list=[]
ans_head=[-1]
for i in range(n):
  a=int(input())
  for j in range(len(ans_head)):
    if ans_head[j]<a:
      ans_head[j]=a
      break
    else:
      if j==len(ans_head)-1:
        ans_head.append(a)
print(len(ans_head))

### FIXED CODE ###

import bisect
n=int(input())
A=[]
for i in range(n):
  A.append(int(input()))
Ans=[A[-1]]
for i in reversed(range(n-1)):
  a=A[i]
  if a>=Ans[-1]:
    Ans.append(a)
  else:

    Ans[bisect.bisect_right(Ans,a)]=a

print(len(Ans))
### BUGGY CODE ###

# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    from collections import Counter

    person_count = int(input())
    relative_positions = Counter(map(int, input().split()))

    if person_count % 2 == 0:
        odd = [2 * i + 1 for i in range(person_count // 2)]

        for key, value in relative_positions.items():
            if (key % 2 == 0) or (key not in odd) or (value != 2):
                print(0)
                exit()
    else:
        even = [2 * i for i in range((person_count + 1) // 2)]

        for key, value in relative_positions.items():
            if (key % 2 == 1) or (key not in even) or (key == 0 and value != 1) or (key != 0 and value != 2):
                print(0)
                exit()

    print(2 ** (person_count // 2) % (10 ** 9 + 7))


### FIXED CODE ###

# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    from collections import Counter

    person_count = int(input())
    relative_positions = Counter(map(int, input().split()))

    if person_count % 2 == 0:
        for key, value in relative_positions.items():
            if (key % 2 == 0) or (value != 2):
                print(0)
                exit()
    else:
        for key, value in relative_positions.items():
            if (key % 2 == 1) or (key == 0 and value != 1) or (key != 0 and value != 2):
                print(0)
                exit()

    print(2 ** (person_count // 2) % (10 ** 9 + 7))
### BUGGY CODE ###

import collections
import bisect
import sys
input = sys.stdin.readline
N, M, Q = map(int, input().split())
LR = [tuple(map(int, input().split())) for i in range(M)]


table = collections.defaultdict(list)
for L, R in LR:
    table[L].append(R)

for x in table:
    table[x].sort()

for _ in range(Q):
    p, q = map(int, input().split())
    ans = 0
    for i in range(p, q+1):
        ans += bisect.bisect_right(table[i], q)
    print(ans)


### FIXED CODE ###

import collections
import bisect
import sys
input = sys.stdin.readline
N, M, Q = map(int, input().split())
LR = [tuple(map(int, input().split())) for i in range(M)]
dp = [[0]*(N+1) for i in range(N+1)]

for L, R in LR:
    dp[L][R] += 1
for i in reversed(range(1, N)):
    for j in range(1, N+1):
        dp[i][j] += dp[i+1][j]

for i in range(1, N+1):
    for j in range(1, N+1):
        dp[i][j] += dp[i][j-1]


for _ in range(Q):
    p, q = map(int, input().split())
    print(dp[p][q])
### BUGGY CODE ###

n,m = map(int,input().split(" "))
a=[]
mod = 10 ** 9 + 7
ans = 1
for i in range(m):
    a.append(int(input()))
    if a[i]-1 == a[i-1]:
        ans = 0
if ans == 1:
    for j in range(n,-1,-1):
        if j in a:
            ans *= 1
        elif j+1 in a or j+2 in a:
            ans *= 1
        elif j+2 > n:
            ans *= 1
        elif not(j+3 in a) and not(j+3 > n):
            temp = ans
            ans += t
            t = temp
        else:
            t = ans
            ans *= 2

print(ans % mod)


### FIXED CODE ###

n,m = map(int,input().split(" "))
a=[0] * (n+1)
mod = 10 ** 9 + 7
for i in range(m):
    a[int(input())] = 1

dp = [0] * (n+1)
for j in range(n+1):
    if a[j] == 1:
        dp[j] = 0
    elif j == 1 or j == 0:
        dp[j] = 1
    else:
        dp[j] = (dp[j-1] + dp[j-2]) % mod

print(dp[n])
### BUGGY CODE ###

# E TLE
# -*- coding: utf-8 -*-
H, N = map(int, input().split())
A_list = []
B_list = []
for i in range(N):
    A, B = map(int, input().split())
    A_list.append(A)
    B_list.append(B)

dp = [10 ** 9 for _ in range(H + 1)]
dp[0] = 0
 
for i in range(1, H + 1):
    dp[i] = min(dp[i], min([(dp[i - A_list[j]] if i >= A_list[j] else 0) + B_list[j] for j in range(N)]))

print(dp[-1])

### FIXED CODE ###

# E
# -*- coding: utf-8 -*-
H, N = map(int, input().split())
A_list = []
B_list = []
for i in range(N):
    A, B = map(int, input().split())
    A_list.append(A)
    B_list.append(B)

dp = [0 for _ in range(H + 1)]
dp[0] = 0

def test_func(dp, A_list, B_list, i, N):
    return(min([(dp[i - A_list[j]] if i >= A_list[j] else 0) + B_list[j] for j in range(N)]))


for i in range(1, H + 1):
    dp[i] = test_func(dp, A_list, B_list, i, N)

print(dp[-1])
### BUGGY CODE ###

import sys
from collections import deque

sys.setrecursionlimit(10000)
INF = float('inf')

N, L = list(map(int, input().split()))
S = set()
for _ in range(N):
    S.add(input())


# 追加できるのが 01... だけで
# L が 4 とすると
# 01: 次はない
# 010: 011 がある
# 011: 010 がある
# 0100: 011, 0101 がある
# 0101: 011, 0100
# 0110: 010, 0111
# 0111: 010, 0110
# 候補の長さと L だけによって次の候補の長さと数が決まる
def grundy(size):
    """
    :param int size: 候補の長さ
    :return:
    """
    # gs = {0}
    # g = 0
    # for sz in range(size + 1, L + 1):
    #     g ^= grundy(sz)
    #     gs.add(g)
    #
    # i = 0
    # while i in gs:
    #     i += 1
    # return i
    i = 1
    while (L - size + 1) % i == 0:
        i *= 2
    return i // 2


prefixes = set()
for s in S:
    for i in range(len(s)):
        prefixes.add(s[:i + 1])

ok_set = set()
ng_set = deque()
ng_set.append('')
while len(ng_set) > 0:
    ng = ng_set.popleft()
    if len(ng) >= L:
        continue
    for c in '01':
        if ng + c not in prefixes:
            ok_set.add(ng + c)
        elif ng + c not in S:
            ng_set.append(ng + c)

g = 0
for ok in ok_set:
    g ^= grundy(len(ok))
if g != 0:
    print('Alice')
else:
    print('Bob')


### FIXED CODE ###

import sys
from collections import deque

sys.setrecursionlimit(10000)
INF = float('inf')

N, L = list(map(int, input().split()))
S = set()
for _ in range(N):
    S.add(input())


# 追加できるのが 01... だけで
# L が 4 とすると
# 01: 次はない
# 010: 011 がある
# 011: 010 がある
# 0100: 011, 0101 がある
# 0101: 011, 0100
# 0110: 010, 0111
# 0111: 010, 0110
# 候補の長さと L だけによって次の候補の長さと数が決まる
def grundy(size):
    """
    :param int size: 候補の長さ
    :return:
    """
    # gs = {0}
    # g = 0
    # for sz in range(size + 1, L + 1):
    #     g ^= grundy(sz)
    #     gs.add(g)
    #
    # i = 0
    # while i in gs:
    #     i += 1
    # return i
    i = 1
    while (L - size + 1) % i == 0:
        i *= 2
    return i // 2


# S の各要素からトライ木つくる
trie = {}
for s in S:
    t = trie
    for c in s:
        if c not in t:
            t[c] = {}
        t = t[c]

# 候補文字列の長さのリスト
ok_size_list = []
children = deque()
children.append((trie, 0))
while len(children) > 0:
    node, size = children.popleft()
    # 0 か 1 か片方しか行けなかったら、行けない方は S の prefix にならない
    # 両方行けない場合はどう追加しても S のいずれかが prefix になってしまうからダメ
    if len(node) == 1:
        ok_size_list.append(size + 1)
    for c, child in node.items():
        children.append((child, size + 1))

g = 0
for size in ok_size_list:
    g ^= grundy(size)
if g != 0:
    print('Alice')
else:
    print('Bob')
### BUGGY CODE ###

N, M, Q = map(int, input().split())
trains = []
questions = []
def make_range(L, R):
    return (pow(2, (R-L+1))-1)<<L-1

for i in range(M):
    a, b = map(int, input().split())
    trains.append(make_range(a, b))
    
for i in range(Q):
    a, b = map(int, input().split())
    questions.append(make_range(a, b))

    
for question in questions:
    res = 0
    for train in trains:
        if question | train == question:
            res += 1
    print(res)

### FIXED CODE ###

N, M, Q = map(int, input().split())

dp = [[0 for col in range(N)] for row in range(N)]

for i in range(M):
    l, r = map(int, input().split())
    dp[l-1][r-1]+=1

for i in range(N):
    for j in range(N)[:-1]:
        dp[i][j+1] += dp[i][j]
        
for i in range(N)[:0:-1]:
    for j in range(N):
        dp[i-1][j] += dp[i][j]

results = []

for i in range(Q):
    l, r = map(int, input().split())
    results.append(dp[l-1][r-1])

for result in results:
    print(result)
### BUGGY CODE ###

import itertools
import math
import fractions
import functools
k = int(input())
h_list = []
 
 
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            h_list.append([i,j,l])
 
sum = 0
for i in range(len(h_list)):
    a = fractions.gcd(h_list[i][0], h_list[i][1])
    sum += fractions.gcd(a,h_list[i][2])
 
print(sum)

### FIXED CODE ###

import itertools
import math
import fractions
import functools

K = int(input())
 
res = 0
for i in range(1, K+1):
  for j in range(1, K+1):
    gcd1 = math.gcd(i, j)
    for k in range(1, K+1):
      if gcd1 == 1:
        res += 1
      else:
        res += math.gcd(gcd1, k)
print(res)
### BUGGY CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0]*n
dp[1] = abs(h[0]-h[1])
for i in range(2, n):
    res = 10**9+7
    for j in range(1, min(k+1, i+1)):
        res_ = dp[i-j]+abs(h[i]-h[i-j])
        res = min(res, res_)
    dp[i] = res
print(dp[n-1])

### FIXED CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')]*n
dp[0] = 0
for i in range(1, n):
    for j in range(min(i, k)):
        dp[i] = min(dp[i], dp[i-j-1]+abs(h[i-j-1]-h[i]))
print(dp[n-1])
### BUGGY CODE ###

import copy

H, W = map(int, input().split())
A = []
for i in range(H):
  A.append(input())

ans = 0
allblack = False
while not allblack:
  B = copy.deepcopy(A)
  count = 0
  for i in range(H):
    count += A[i].count('.')
  if count > 0:
    ans += 1
  else:
    allblack = True
  for i in range(H):
    for j in range(W):
      if A[i][j] == '#':
        if i - 1 >= 0 and A[i - 1][j] == '.':
          str_list = list(B[i - 1])
          str_list[j] = '#'
          B[i - 1] = ''.join(str_list)
        if j - 1 >= 0 and A[i][j - 1] == '.':
          str_list = list(B[i])
          str_list[j - 1] = '#'
          B[i] = ''.join(str_list)
        if i + 1 < H and A[i + 1][j] == '.':
          str_list = list(B[i + 1])
          str_list[j] = '#'
          B[i + 1] = ''.join(str_list)
        if j + 1 < W and A[i][j + 1] == '.':
          str_list = list(B[i])
          str_list[j + 1] = '#'
          B[i] = ''.join(str_list)
        str_list = list(B[i])
        str_list[j] = '%'
        B[i] = ''.join(str_list)
  A = copy.deepcopy(B)
print(ans)


### FIXED CODE ###

H,W = map(int,input().split())
A = []
for i in range(H):
  A.append(input())
#print(A)

INF = 10000
S = [[INF for _ in range(W)] for _ in range(H)]
for i in range(H):
  flag = False
  for j in range(W):
    if A[i][j] == '#':
      flag  = True
      d = 0
      S[i][j] = 0
    if flag and A[i][j] == '.':
      d += 1
      S[i][j] = min(d,S[i][j])
  flag = False
  for j in range(W-1,-1,-1):
    if A[i][j] == '#':
      flag  = True
      d = 0
      S[i][j] = 0
    if flag and A[i][j] == '.':
      d += 1
      S[i][j] = min(d,S[i][j])
for j in range(W):
  flag = False
  for i in range(H):
    if S[i][j] < INF:
      flag = True
    if flag and i > 0 and A[i][j] == '.':
      S[i][j] = min(S[i][j],S[i-1][j]+1)
  flag = False
  for i in range(H-1,-1,-1):
    if S[i][j] < INF:
      flag = True
    if flag and i < H-1 and A[i][j] == '.':
      S[i][j] = min(S[i][j],S[i+1][j]+1)
#print(S)

ans = 0
for s in S:
  ans = max(ans,max(s))
print(ans)
### BUGGY CODE ###

import math
import numpy as np


def main():
    s = input().split(" ")
    N = int(s[0])
    K = int(s[1])
    A = np.array([int(a) for a in input().split(" ")])
    F = np.array([int(a) for a in input().split(" ")])
    A = np.sort(A)
    F = np.sort(F)[::-1]
    AF = A * F
    m = np.max(AF)

    if(func(0, AF, F, N, K)):
        print(0)
        return
    a = 0
    b = m
    for aaa in range(m):
        if((b - a) <= 1):
            print(b)
            return
        mid = int((b - a) / 2.) + a
        if(func(mid, AF, F, N, K)):
            b = mid
        else:
            a = mid
    print("???????")


def func(saidai, AF, F, N, K):
    lst = (AF[(AF - saidai) > 0] - saidai) / F[(AF - saidai) > 0]
    lst = [math.ceil(a) for a in lst]
    count = np.sum(lst)
    return count <= K


if(__name__ == "__main__"):
    main()


### FIXED CODE ###

import math
import numpy as np


def main():
    s = input().split(" ")
    N = int(s[0])
    K = int(s[1])
    A = np.array([int(a) for a in input().split(" ")])
    F = np.array([int(a) for a in input().split(" ")])
    A = np.sort(A)
    F = np.sort(F)[::-1]
    AF = A * F
    m = np.max(AF)

    if(func(0, AF, F, N, K)):
        print(0)
        return
    a = 0
    b = m
    for aaa in range(m):
        if((b - a) <= 1):
            print(b)
            return
        mid = int((b - a) / 2.) + a
        if(func(mid, AF, F, N, K)):
            b = mid
        else:
            a = mid
    print("???????")


def func(saidai, AF, F, N, K):
    count = np.sum(np.ceil((AF[(AF - saidai) > 0] - saidai) / F[(AF - saidai) > 0]))
    return count <= K


if(__name__ == "__main__"):
    main()
### BUGGY CODE ###

# -*- coding: utf-8 -*-

N = int(input())

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

A_sort = sorted(A, reverse=True)
sum_num = A_sort.pop(0)

i = 2
while i + 2 <= N:
    sum_num += A_sort.pop(0) * 2
    i += 2

if i + 1 <= N:
    sum_num += A_sort.pop(0)

print(sum_num)



### FIXED CODE ###

# -*- coding: utf-8 -*-

N = int(input())

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

A_sort = sorted(A)
sum_num = A_sort.pop(-1)

i = 2
while i + 2 <= N:
    sum_num += A_sort.pop(-1) * 2
    i += 2

if i + 1 <= N:
    sum_num += A_sort.pop(-1)

print(sum_num)
### BUGGY CODE ###

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

for i in range(K):
  if A>=1:
    A=A-1
  elif B>=1:
    B=B-1
  elif A==0 and B==0:
    break

print(A,B)

### FIXED CODE ###

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

if K>=A+B:
  A,B=0,0
elif K<A+B:
  if K>A:
    A,B=0,B-K+A
  if K<=A:
    A,B=A-K,B

print(A,B)
### BUGGY CODE ###

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


dic = {}
ans = 0
for t in A:
    if t in dic.keys():
        continue
    tmp = A.count(t)
    dic[t] = tmp
    ans += tmp*(tmp-1)//2

for i in range(N):
    val = dic.get(A[i])
    print(ans-val+1)

### FIXED CODE ###

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

dic = {}
ans = 0
# for t in A:
#     if t in dic.keys():
#         continue
#     tmp = A.count(t)
#     dic[t] = tmp
#     ans += tmp*(tmp-1)//2

for a in A:
    tmp = dic.get(a)
    if tmp == None:
        dic[a] = 1
    else:
        dic[a] = tmp + 1

for key in list(dic.keys()):
    tmp = dic.get(key)
    ans += tmp * (tmp - 1) // 2
    

for a in A:
    val = dic.get(a)
    print(ans-val+1)
### BUGGY CODE ###

#coding: utf-8
N = int(input())
L = list(map(int, input().split()))

cnt = 0
tri_cnt = 0
mem = 0

#全てが奇数になるまで実行し続ける
while(tri_cnt != len(L)):
    if(L[mem]%2 != 0):
        mem += 1
    else:
        L[mem] //= 2
        for i in range(len(L)):
            if(i != mem):
                #L[i] = L[i] * 3
                print('',end='')
        cnt += 1

    tri_cnt = 0
    for i in range(len(L)):
        if (L[i] % 2 != 0):
            tri_cnt += 1
    # print(L)
    # print(tri_cnt)
else:
    print(cnt)

### FIXED CODE ###

#coding: utf-8
N = int(input())
L = list(map(int, input().split()))

cnt = 0
tri_cnt = 0
mem = 0

#全てが奇数になるまで実行し続ける
while(mem != len(L)):
    if(L[mem]%2 != 0):
        mem += 1
    else:
        L[mem] //= 2
        # for i in range(len(L)):
        #     if(i != mem):
        #         L[i] = L[i] * 3
        #         print('',end='')
        cnt += 1

    # tri_cnt = 0
    # for i in range(len(L)):
    #     if (L[i] % 2 != 0):
    #         tri_cnt += 1
else:
    print(cnt)