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

MOD = 10**9+7
n = int(input())
c = list(map(int, input().split()))
c.sort(reverse=True)
cnt = 0
pt = [2**i for i in range(n+1)]

for i, x in enumerate(c):
    r = n-i-1
    cnt += (pt[i] + (0 if i <= 0 else pt[i-1]) * i) * pt[r] * x
    cnt %= MOD

print(cnt * (pt[n] % MOD) % MOD)


### FIXED CODE ###

MOD = 10**9+7
n = int(input())
c = list(map(int, input().split()))
c.sort(reverse=True)
cnt = 0
a, b = pow(2, n-1, MOD), 0 if n <= 1 else pow(2, n-2, MOD)
for i, x in enumerate(c):
    cnt += (a + b*i) * x
    cnt %= MOD

print(cnt * pow(2, n, MOD) % MOD)
### BUGGY CODE ###

H, W = map(int, input().split())
A = tuple(tuple(map(int, input().split())) for _ in range(H))
B = tuple(tuple(map(int, input().split())) for _ in range(H))

dp = [[set() for _ in range(W)] for _ in range(H)]
dp[0][0].add(A[0][0] - B[0][0])
dp[0][0].add(B[0][0] - A[0][0])
lim = 160 * 80 // 2

for i in range(H):
    for j in range(W):
        c = abs(A[i][j]-B[i][j])
        if i > 0:
            dp[i][j] |= {x + c for x in dp[i - 1][j] if x + c <= lim}
            dp[i][j] |= {x - c for x in dp[i - 1][j] if x - c >= -lim}
        if j > 0:
            dp[i][j] |= {x + c for x in dp[i][j - 1] if x + c <= lim}
            dp[i][j] |= {x - c for x in dp[i][j - 1] if x - c >= -lim}

ans = min(abs(x) for x in dp[-1][-1])
print(ans)

### FIXED CODE ###

import numpy as np
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

H, W = map(int, input().split())
A = np.array([input().split() for _ in range(H)], dtype=int)
B = np.array([input().split() for _ in range(H)], dtype=int)
dif = np.abs(A - B).tolist()

U = (H + W) * 80
Um = U // 2

dp = [[[] for _ in range(W)] for _ in range(H)]
X = np.zeros(U + 1, dtype=bool)
X[Um + dif[0][0]] = True
X[Um - dif[0][0]] = True
dp[0][0] = X


for i in range(H):
    for j in range(W):
        if i == j == 0:
            continue
        d = dif[i][j]
        X = np.zeros(U + 1, dtype=bool)
        if d:
            if i > 0:
                X[d:] |= dp[i - 1][j][:-d]
                X[:-d] |= dp[i - 1][j][d:]
            if j > 0:
                X[d:] |= dp[i][j - 1][:-d]
                X[:-d] |= dp[i][j - 1][d:]
        else:
            if i > 0:
                X |= dp[i - 1][j]
            if j > 0:
                X |= dp[i][j - 1]
        dp[i][j] = X

tmp = np.arange(U+1)[dp[H-1][W-1]]
ans = np.abs(tmp - Um).min()
print(ans)
### BUGGY CODE ###

n=int(input())
if n%2==0: print(-1)
else:
    i=1
    x=7
    while x%n!=0:
        x*=10
        x+=7
        i+=1
    print(i)


### FIXED CODE ###

k=int(input())
if (k%2)*(k%5)==0: print(-1)
else:
    i=1
    x=7
    while x%k:
        x=(x*10+7)%k
        i+=1
    print(i)
### BUGGY CODE ###

N,K = map(int,input().split())
group = [[] for i in range(N)]
for i in range(N):
    t,d = map(int,input().split())
    t -= 1
    group[t].append(d)
for e in group:
    e.sort()
    e.reverse()
head = []
remain = []
for e in group:
    if e == []:
        continue
    head.append(e[0])
    for i in range(1,len(e)):
        remain.append(e[i])
head.sort()
head.reverse()
remain.sort()
remain.reverse()
ans = -float("inf")
for i in range(1,min(K,len(head))+1):
    if K - i > len(remain):
        continue
    deli = sum(head[:i]) + sum(remain[:K-i])
    kind = i**2
    res = deli + kind
    if res > ans:
        ans = res
print(ans)

### FIXED CODE ###

N,K = map(int,input().split())
note = [list(map(int,input().split())) for i in range(N)]
note = sorted(note,key=lambda x:(x[0],-x[1]))
cnt = 0
head = []
remain = []
for i in range(N):
    if note[i][0] > cnt:
        cnt = note[i][0]
        head.append(note[i][1])
    else:
        remain.append(note[i][1])
head = sorted(head,reverse = True)
remain = sorted(remain,reverse = True)
ans = 0
acc_head = [0]
acc_remain = [0]
tmp_head = 0
tmp_remain = 0
for i in range(len(head)):
    tmp_head += head[i]
    acc_head.append(tmp_head)
for i in range(len(remain)):
    tmp_remain += remain[i]
    acc_remain.append(tmp_remain)
for i in range(max(0,K-len(remain)),min(K,len(head))+1):
    deli = acc_head[i] + acc_remain[K-i]
    kind = i**2
    res = deli + kind
    if res > ans:
        ans = res
print(ans)
### BUGGY CODE ###

k = int(input())
 
 
def gcd(a, b):
    if a > b:
        a, b = b, a
    while a != 0:
        a, b = b % a, a
    return b
 
 
ans = 0
for p in range(1, k + 1):
    for q in range(1, k + 1):
        for r in range(1, k + 1):
            ans += gcd(gcd(p, q), r)
print(ans)

### FIXED CODE ###

from math import gcd
K=int(input())

result=[]
count=0
cnt=0
# def gcd(a,b):
#   while b!=0:
#     a,b=b,a%b
#   return a

 
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      cnt+=gcd(gcd(i,j),k)


print(cnt)
### BUGGY CODE ###

N, T = map(int, input().split())
food = [0] * N
for i in range(N):
  food[i] = list(map(int, input().split()))

food = sorted(food)  
#i番目までの商品でj分いないに完食できる美味しさの最大値  
dp = [[0] * (T + 1) for i in range(N + 1)]  

for i in range(N):
  for j in range(1, T + 1):
    #i番目の商品を使わない場合
    now = max(dp[i + 1][j - 1], dp[i][j])
    #使う場合
    if (j - food[i][0]) >= 0:
      now2 = dp[i][j - food[i][0]] + food[i][1]
    else:
      now2 = 0
    dp[i + 1][j] = max(now, now2)
    
#print(dp)
#T - 1分に i + 1番目の商品を注文
ans = 0
for i in range(N):
  now3 = dp[i][T - 1] + food[i][1]
  #print(dp[i][T - 1], food[i][1])
  ans = max(ans, now3)
  
print(ans)  
  
  
  

### FIXED CODE ###

N, T = map(int, input().split())
food = [0] * N
for i in range(N):
  food[i] = list(map(int, input().split()))

food = sorted(food)  
#i番目までの商品でj分いないに完食できる美味しさの最大値  
dp = [[0] * (T + 1) for i in range(N + 1)]  

for i in range(N):
  for j in range(1, T + 1):
    #i番目の商品を使わない場合
    now = max(dp[i + 1][j - 1], dp[i][j])
    #使う場合
    if (j - food[i][0]) >= 0:
      now2 = dp[i][j - food[i][0]] + food[i][1]
    else:
      now2 = 0
    dp[i + 1][j] = max(now, now2)
    
#print(dp)
#T - 1分に i + 1番目の商品を注文
ans = 0
for i in range(N):
  now3 = dp[i][T - 1] + food[i][1]
  #print(dp[i][T - 1], food[i][1])
  ans = max(ans, now3)
  
print(ans)
### BUGGY CODE ###

N,W = map(int,input().split())
info = [list(map(int,input().split())) for i in range(N)]
# dp[i+1][w] i+1番目まで品物を選んで重さwのときの価値の最大値
# dp[0] = [0]*(W+1)
dp = [[0]*(W+1) for i in range(N+1)]
for i in range(N):
    for w in range(W+1):
        if  w - info[i][0] >= 0:
            dp[i+1][w] = max(dp[i][w-info[i][0]] + info[i][1],dp[i][w])
        else:    
            dp[i+1][w] = dp[i][w]
print(dp[N][W])

### FIXED CODE ###

N,W = map(int,input().split())
info = [list(map(int,input().split())) for i in range(N)]
# dp[i+1][w] i+1番目まで品物を選んで重さwのときの価値の最大値
# dp[0] = [0]*(W+1)
dp = [[0]*(W+1) for i in range(N+1)]
for i in range(N):
    for w in range(W+1):
        if  w - info[i][0] >= 0:
            dp[i+1][w] = max(dp[i][w-info[i][0]] + info[i][1],dp[i][w])
        else:    
            dp[i+1][w] = dp[i][w]
print(dp[N][W])
### BUGGY CODE ###

#!python
# -*- coding: utf-8 -*-

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

a = 0
I = 0
for b in A + [0]:
    I += abs(a - b)
    a = b

for i in range(1, N + 1):
    A_ = [0] + A + [0]
    if A_[i - 1] <= A_[i] <= A_[i + 1]:
        print(I)
    else:
        del A_[i]
        a = 0
        n = 0
        for b in A_:
            n += abs(a - b)
            a = b
        print(n)


### FIXED CODE ###

#!python
# -*- coding: utf-8 -*-

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

a = 0
I = []
for b in A + [0]:
    I.append(b - a)
    a = b
S = sum(map(abs, I))

for i in range(N):
    j = i + 1
    n = S - (abs(I[i]) + abs(I[i + 1])) + abs(I[i] + I[i + 1])
    print(n)
### BUGGY CODE ###

if __name__ == '__main__':
	S = input()
	L = len(S)
	lst = [0] * 2019
	lst[0] = 1
	amari = 0
	ans = 0
	for i in range(1,L+1):
		amari = ( int(S[L-i]) * pow(10,i-1) + amari ) % 2019
		lst[amari] += 1

	for i in range(2019):
		m = lst[i]
		ans += m * (m-1) / 2

	print(int(ans))

### FIXED CODE ###

def POW(x, n, mod):
    ans = 1
    # n が 0 になるまで計算を続ける
    while n > 0:
        if n % 2 == 1:
            ans *= x%mod
        x = (x*x)%mod						#x = x**2
        n >>= 1						#ビットシフト
    return ans

if __name__ == '__main__':
	S = input()
	L = len(S)
	lst = [0] * 2019
	lst[0] = 1
	amari = 0
	ans = 0
	for i in range(1,L+1):
		amari = ( int(S[L-i]) * POW(10,i-1,2019) + amari ) % 2019
		lst[amari] += 1

	for i in range(2019):
		m = lst[i]
		ans += m * (m-1) / 2

	print(int(ans))
### BUGGY CODE ###

import math
n=int(input())

for p in range(1, n+1):
  right=math.floor(math.sqrt(p))+1
  cnt=0
  for i in range(1, right):
    for j in range(1, i+1):
      for k in range(1, j+1):
        if i**2+j**2+k**2+i*j+j*k+k*i==p:
          if i==j and j==k:
            cnt+=1
          elif i==j and j!=k:
            cnt+=3
          elif j==k and k!=i:
            cnt+=3
          elif k==i and i!=j:
            cnt+=3
          elif i!=j and j!=k and k!=i:
            cnt+=6
  print(cnt)

### FIXED CODE ###

n=int(input())
lst=[0]*10000000
for i in range(1, 101):
  for j in range(1, i+1):
    for k in range(1, j+1):
      temp=i**2+j**2+k**2+i*j+j*k+k*i
      if i==j and j==k:
        lst[temp+1]+=1
      elif i==j and j!=k:
         lst[temp+1]+=3
      elif j==k and k!=i:
         lst[temp+1]+=3
      elif k==i and i!=j:
         lst[temp+1]+=3
      elif i!=j and j!=k and k!=i:
         lst[temp+1]+=6
for p in range(1, n+1):
  print(lst[p+1])
### BUGGY CODE ###

# import sys


# fin = sys.stdin.readline
MOD = 10 ** 9 + 7
S = input()[::-1]
dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1
for i, c in enumerate(S, start=1):
    base = 10 ** (i - 1) % 13
    if c != '?':
        d = int(c) * base % 13
        for r in range(13):
            c = (d + r) % 13
            dp[i][c] += dp[i - 1][r]
            dp[i][c] %= MOD
    else:
        for d in range(10):
            d = d * base % 13
            for r in range(13):
                c = (d + r) % 13
                dp[i][c] += dp[i - 1][r]
                dp[i][c] %= MOD
print(dp[-1][5])


### FIXED CODE ###

# import sys


# fin = sys.stdin.readline
MOD = 10 ** 9 + 7
S = input()[::-1]
dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1
for i, c in enumerate(S, start=1):
    base = pow(10, i - 1, 13)
    if c != '?':
        d = int(c) * base % 13
        for r in range(13):
            c = (d + r) % 13
            dp[i][c] += dp[i - 1][r]
            dp[i][c] %= MOD
    else:
        for d in range(10):
            d = d * base % 13
            for r in range(13):
                c = (d + r) % 13
                dp[i][c] += dp[i - 1][r]
                dp[i][c] %= MOD
print(dp[-1][5])
### BUGGY CODE ###


lis = []

N,M = [int(i) for i in input().split()]
M_ = M
i = 2

while True:
    if M % i == 0:
        M = M // i
        lis.append(i)
    elif M == 1:
        break
    else:
        i += 1
ans = M_
ret = 1
for n in range(2**len(lis)):
    m = bin(n)[-1:1:-1]
    ret = 1
    for l in range(len(m)):
        if int(m[l]):
            ret *= lis[l]
            if  ret >= N:
                continue
    if ret >= N and ret <=ans:
        ans = ret

print(M_//ans)


### FIXED CODE ###

import  math
lis = []

N,M = [int(i) for i in input().split()]

for i in range(1,int(math.sqrt(M))):
    if M % i == 0:
        lis.append(i)
        lis.append(M//i)


lis.sort()
i =1
for i in lis:
    if i >= N:
        break

print(M//i )
### BUGGY CODE ###

#!/usr/bin/python3
# -*- coding: utf-8 -*-
from collections import defaultdict


def solve():
  N = int(input())
  S = str(input())

  dct = defaultdict(lambda:[N+1,-1])
  for i in range(N):
    for j in range(i+1,N+1):
      dct[S[i:j]][0] = min(dct[S[i:j]][0],i)
      dct[S[i:j]][1] = max(dct[S[i:j]][1],i)

  ret = 0
  for sn in dct.keys():
    if dct[sn][1]-dct[sn][0]>=len(sn):
      ret = max(ret,len(sn))
  return ret

print(solve())

### FIXED CODE ###

#!/usr/bin/python3
# -*- coding: utf-8 -*-



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

r,i,j = 0,0,0
while j < N:
  t = S[i:j]
  if t in S[j:]:
    r = max(r,j-i)
    j += 1
  else:
    i += 1
print(r)
### BUGGY CODE ###

N = int(input())
ans = [0]*(N+1)
RANGE = 333
for i in range(1, RANGE):
  for j in range(1, RANGE):
    if i**2 + j**2 < N:
      for k in range(1, RANGE):
        wd = i**2 + j**2 + k**2 + i*j + j*k + k*i
        if wd < N:
          #print(wd)
          #print(i, j, k)
          ans[wd] += 1
for i in range(1,N+1):
  print(ans[i])

### FIXED CODE ###

N = int(input())
ans = [0]*(N+1)
RANGE = 333
for i in range(1, RANGE):
  if i**2 <= N+1:
    for j in range(1, RANGE):
      if i**2 + j**2 + i*j <= N+1:
        for k in range(1, RANGE):
          wd = i**2 + j**2 + k**2 + i*j + j*k + k*i
          if wd < N+1:
            #print(wd)
            #print(i, j, k)
            ans[wd] += 1
          else:
            break
      else:
        break
  else:
    break
    
for i in range(1,N+1):
  print(ans[i])
### BUGGY CODE ###

n, m =  map(int, input().split())
py = [map(int, input().split()) for _ in range(m)]
p, y = [list(i) for i in zip(*py)]
pre = {}
for i in range(m):
    if p[i] not in pre.keys():
        pre[p[i]] = []
    pre[p[i]].append(y[i])
for i in pre.keys():
    pre[i].sort()
for i in range(m):
    num = str(p[i]*(10**6)+(pre[p[i]].index(y[i])+1))
    while len(num) < 12:
        num = '0' + num
    print(num)

### FIXED CODE ###

import sys
n,m = map(int, sys.stdin.readline().rstrip("\n").split())
city = {}
yton = {}
for i in range(m):
    p,y = map(int, sys.stdin.readline().rstrip("\n").split())
    if p not in city.keys():
        city[p] = []
        city[p].append(y)
        yton[y] = i
    else:
        city[p].append(y)
        yton[y] = i
ans = [None]*m
for p in city.keys():
    city[p].sort()
    for i,y in enumerate(city[p]):
        ans[yton[y]] = str(p*(10**6)+i+1).zfill(12)
print(*ans, sep = '\n')
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
b = [0 for i in range(n)]
for k in a:
    b[k-1] += 1
for k in a:
    b[k-1] -= 1
    result = 0
    for el in b:
        result += el*(el-1)//2
    print(result)
    b[k-1] += 1

### FIXED CODE ###

from collections import Counter
n = int(input())
a = list(map(int, input().split()))
counter = Counter(a)
d = [0]*(n+1)
count = 0
for el, cnt in counter.most_common():
    d[el] = cnt
    count += cnt*(cnt-1)
count //= 2
for el in a:
    print(count - d[el] + 1)
### BUGGY CODE ###

N = int(input())
s = [None]*N
for i in range(N):
    s[i] = input()

for i in range(N):
    s[i] = sorted(s[i])

ans = 0
for i in range(N):
    for j in range(i+1, N):
        if s[i] == s[j]:
            ans += 1

print(ans)

### FIXED CODE ###

N = int(input())
anagram = {}

ans = 0
for i in range(N):
    tmp = str(sorted(input()))
    if tmp in anagram:
        ans += anagram[tmp]
        anagram[tmp] += 1
    else:
        anagram[tmp] = 1

print(ans)
### BUGGY CODE ###

import bisect
n,m=map(int,input().split())
A=sorted(list(map(int,input().split())))
for i in range(m):
  b,c=map(int,input().split())
  d=bisect.bisect_right(A,c)
  b=min(b,d)
  A=A[b:d]+[c]*b+A[d:]
print(sum(A))

### FIXED CODE ###

from operator import itemgetter
n,m=map(int,input().split())
A=list(map(int,input().split()))
B=[list(map(int,input().split())) for _ in range(m)]
B.sort(key=itemgetter(1),reverse=True)
C=[]
for b,c in B:
  C+=[c]*b
  if len(C)>=n:break
print(sum(sorted(A+C)[-n:]))
### BUGGY CODE ###

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

x = 1
for i in range(n):
    x *= a[i]
    
if x > 1000000000000000000:
    print(-1)
else:
    print(x)


### FIXED CODE ###

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

x = 1
flag = False
INF = 10**18
if 0 in a:
    print(0)
else:
    for i in range(n):
        if flag == False:
            x *= a[i]
        if x > INF:
            flag = True
    
    if flag:
        print(-1)
    else:
        print(x)
### BUGGY CODE ###

n, k = map(int, input().split())
step = list(map(int, input().split()))

ans = [float('inf')]*(10**6)

ans[0] = 0
def dp(n):
  for i in range(n):
    for j in range(k+1):
      if i+j < n:
        ans[i+j] = min(ans[i+j], ans[i] + abs(step[i+j] - step[i]))
  return ans[n-1]

print(dp(n))

### FIXED CODE ###

n, k = map(int, input().split())
step = list(map(int, input().split()))

ans = [float('inf')]*(10**6)

ans[0] = 0
def dp(n):
  for i in range(n):
    for j in range(k+1):
      if i+j < n:
        ans[i+j] = min(ans[i+j], ans[i] + abs(step[i+j] - step[i]))
  return ans[n-1]

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

N,M=map(int, raw_input().split())
A=map(int, raw_input().split())

match=[None,2,5,5,4,5,6,3,7,6]

dp=[ None for i in range(N+1) ] 
dp[0]=""


for i in range(N):
	if dp[i] is not None:
		for a in A:
			match_cnt=match[a]
			if 0<=i+match_cnt<=N:
				if dp[i+match_cnt] is None:
					dp[i+match_cnt]=dp[i]+str(a)
				else:
					if int(dp[i+match_cnt]) < int( dp[i]+str(a) ):
						dp[i+match_cnt]=dp[i]+str(a)				

print dp[N]

### FIXED CODE ###

T=[(1,2),(2,5),(3,5),(4,4),(5,5),(6,6),(7,3),(8,7),(9,6)]

N,M=map(int, raw_input().split())
A=map(int, raw_input().split())


P=[]
for i in A:
	P.append(T[i-1])


dp=[ None for i in range(N+1) ]
dp[0]=""


for i in range(N):
	#print "i :::: ",i,dp
	if dp[i] is not None:
		for num, match in P:
			if i+match<=N:

				if dp[i+match] is None:
					dp[i+match]=dp[i]+str(num)
				else:
					l1=len(dp[i+match])
					l2=len(dp[i]+str(num))
					if l1>l2:
						pass
					elif l1<l2:
						dp[i+match]=dp[i]+str(num)
					else:
						dp[i+match]=max( dp[i+match] , dp[i]+str(num) )


print dp[N]
### BUGGY CODE ###

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

li.sort()
mod_li=[[i,num] for i,num in enumerate(li)]

result=0
for i in range(len(li)-2):
  for j in range(i+1,len(li)-1):
    temp_li=[num for num in mod_li[j+1:]]
    while(len(temp_li)>1):
      if temp_li[len(temp_li)//2][1]>=li[i]+li[j]:
        temp_li=temp_li[:len(temp_li)//2]
      else:
        temp_li=temp_li[len(temp_li)//2:]
    if temp_li[0][1]>=li[i]+li[j]:
      result+=temp_li[0][0]-j-1
    else:
      result+=temp_li[0][0]-j
print(result)

### FIXED CODE ###

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

li.sort()
#mod_li=[[i,num] for i,num in enumerate(li)]

result=0
for i in range(len(li)-2):
  tmp=i+2
  for j in range(i+1,len(li)-1):
    for k in range(tmp,len(li)):
      if li[i]+li[j]<=li[k]:
        tmp=k-1
        if tmp-j>0:
          result+=tmp-j
        break
      elif k==len(li)-1:
        tmp=k
        result+=tmp-j
        break
print(result)
### BUGGY CODE ###

n = int(input())
a = [int(stdins) for stdins in input().split()]

a.sort()

ans = n
divisibles = [False for i in range(n)]
for i in range(n):
    divisible = False
    for j in range(n):
        if i == j:
            continue
        elif divisibles[i]:
            continue
        elif a[i] < a[j]:
            break
        elif a[i] % a[j] == 0:
            ans -= 1
            divisibles[i] = True
            break

print(ans)


### FIXED CODE ###

# ABC170

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

a.sort()
a_max = max(a)
dp = [True for _ in range(a_max+1)]

ans = 0
for i in range(n):
    if dp[a[i]]:
        for j in range(0, a_max+1, a[i]):
            dp[j] = False
        if i > 0:
            if a[i] == a[i-1]:
                continue
        if i < n-1:
            if a[i] == a[i+1]:
                continue
        ans += 1

print(ans)
### BUGGY CODE ###

n =int(input())
a =list(map(int,input().split()))
ans =1
if '0' in a:
    ans =0
else:
    for i in range(n):
        ans =a[i]*ans
        if ans >10**18:
            ans =-1

print(ans)

### FIXED CODE ###

n =int(input())
a =list(map(int,input().split()))
ans =1
if 0 in a:
    print(0)
    exit()
else:
    for i in a:
        ans *=i
        if ans >10**18:
            print(-1)
            exit()
print(ans)
### BUGGY CODE ###

import sys

sys.setrecursionlimit(4100000)
input = sys.stdin.readline


def f(l, c, s, n):
    if not l:
        if s == n:
            return -1
        return s

    if l[0] != c:
        return f(l[1:], c, s + 1, n)
    return f(l[1:], c + 1, s, n)

def main():
    n = int(input()[:-1])
    l = list(map(int, input()[:-1].split(" ")))
    print(f(l, 1, 0, n))

main()

### FIXED CODE ###

import sys

input = sys.stdin.readline

def main():
    n = int(input()[:-1])
    l = list(map(int, input()[:-1].split(" ")))

    c = 1
    s = 0
    tmp = 0
    while l:
        if tmp >= n:
            break
        if l[tmp] != c :
            s += 1
        else:
            c += 1
        tmp += 1

    res = s
    if s == n:
        res = -1

    print(res)

main()
### BUGGY CODE ###



n=int(input())
l=list(map(int,input().split()))
res=1
f=1
for x in l:
    res=res*x
    if(res>1000000000000000000):
        
        f=0
    else:
        f=1
if(f==1):
    print(res)
else:
    print(-1)
    
        
    
    


### FIXED CODE ###



n=int(input())
l=list(map(int,input().split()))
res=1
f=1
if(0 in l):
    print(0)
    f=0
if(f==1):
    
    for x in l:
        res=res*x
        if(res>1000000000000000000):
            print(-1)    
            f=0
            break
    
    if(f==1):
        print(res)
### BUGGY CODE ###

n=int(input())
strl=[input() for i in range(n)]

def anagram(sa,sb) :
  flag=True
  sal=list(sa)
  sbl=list(sb)
  sal.sort()
  sbl.sort()
  if sal==sbl:
    return True
  else :
    return False
  """
  for i in range(10) :
    if sal[i] in sbl :
      sbl.remove(sal[i])
    else :
      flag=False
      break
  """
  #return flag
   
#print(anagram("peanutbomb","constraint"))    
count=0
for i in range(n) :
  for j in range(n) :
    if i>= j :
      continue
    if anagram(strl[i],strl[j]) ==True :
      count+=1
print(count)

### FIXED CODE ###

#import numpy as np
n=int(input())
strl=[list(input()) for i in range(n)]

count=0
pt={}
#il=np.arange(n)
for i in range(n) :
  sal=strl[i]
  sal.sort()
  temp="".join(sal)
  if temp in pt.keys() :
    #ptがある
    tempc=pt[temp]
    count+=tempc
    pt[temp]=tempc+1
  else :
    pt[temp]=1
print(count)
#print(count)
### BUGGY CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = int(1e+9 + 7)
a = sorted(a)

kai = [1]*(n+1)
gyaku = [1]*(n+1)

for i in range(2, n+1):
    kai[i] = kai[i-1]*i % mod
    gyaku[i] = gyaku[i-1]*pow(i, mod-2, mod) %mod

answer = 0
for i in range(n-k+1):
    for j in range(i+k-1,n):
        answer = (answer + (a[j] - a[i])%mod * (kai[j-i-1] *gyaku[j-i-1-(k-2)])%mod * gyaku[k-2])%mod

if k == 1:
    print(0)
else:
    print(answer)

### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = int(1e+9 + 7)
a = sorted(a)

kai = [1]*(n+1)
gyaku = [1]*(n+1)

for i in range(2, n+1):
    kai[i] = kai[i-1]*i % mod
    gyaku[i] = gyaku[i-1]*pow(i, mod-2, mod) %mod

answer = 0
for i in range(k-1,n):
    answer = (answer + a[i] * kai[i] * gyaku[(i)-(k-1)] * gyaku[k-1]) % mod

answer2 = 0
for i in range(n-k+1):
    answer2 = (answer2 + a[i] * kai[n-i-1] * gyaku[(n-i)-k] * gyaku[k-1]) % mod


if k == 1:
    print(0)
else:
    print((answer - answer2)%mod)
### BUGGY CODE ###

H, N = map(int, input().split())
A = [0 for _ in range(N)]
B = [0 for _ in range(N)]
for i in range(N):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b
MP = [0 for _ in range(H+1)]
tmp = [0 for _ in range(N)]
for h in range(1, H+1):
    for n in range(N):
        if A[n] >= h:
            tmp[n] = B[n]
        else:
            tmp[n] = MP[h-A[n]]+B[n]
    MP[h] = min(tmp)
print(MP[H])


### FIXED CODE ###

H, N = map(int, input().split())
A = [0 for _ in range(N)]
B = [0 for _ in range(N)]
for i in range(N):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b
MP = [0 for _ in range(H+1)]
tmp = [0 for _ in range(N)]
for h in range(1, H+1):
    for n in range(N):
        if A[n] >= h:
            tmp[n] = B[n]
        else:
            tmp[n] = MP[h-A[n]]+B[n]
    MP[h] = min(tmp)
print(MP[H])
### BUGGY CODE ###

n = int(input())
p = list(map(int, input().split()))
for i in range(1, n):
    if p[i] in p[:i]:
        print('NO')
        break
else: print('YES')

### FIXED CODE ###

n = int(input())
p = list(map(int, input().split()))
q = set(p)
if len(p) == len(q):
    print('YES')
else: print('NO')