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

from collections import defaultdict, deque
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate
import sys


def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n = I()
num = LI()
cnt = 0
for i in range(n):
    ret = 0
    for j in range(i, n):
        if ret & num[j] == 0:
            ret ^= num[j]
            cnt += 1
        else:
            break


print(cnt)

### FIXED CODE ###

from collections import defaultdict, deque
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate
import sys


def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n = I()
num = LI()
ans = n
l = 0
r = 0
cnt = 0
ret = num[0]
while r < n-1:
    if ret & num[r+1] == 0:
        ret ^= num[r+1]
        cnt += 1
        r += 1
        ans += cnt
    elif l == r:
        l +=1; r += 1;
        ret = num[l]
    else:
        ret ^= num[l]
        cnt -= 1
        l += 1



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

from itertools import permutations


def warshall_floyd(d, n):
    # d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d


N, M, R = map(int, input().split())
r = list(map(int, input().split()))
d = [[float('inf')] * N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    d[a-1][b-1] = c
    d[b-1][a-1] = c

d = warshall_floyd(d, N)

ans = float('inf')
for p in permutations(r):
    total = 0
    for i in range(1, len(p)):
        total += d[p[i-1]-1][p[i]-1]
    ans = min(ans, total)
print(ans)


### FIXED CODE ###

from itertools import permutations


def warshall_floyd(d, n):
    # d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d


N, M, R = map(int, input().split())
r = list(map(int, input().split()))
d = [[float('inf')] * N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    d[a-1][b-1] = c
    d[b-1][a-1] = c

d = warshall_floyd(d, N)

ans = float('inf')
for p in permutations(r):
    total = 0
    for i in range(1, len(p)):
        total += d[p[i-1]-1][p[i]-1]
    ans = min(ans, total)
print(ans)
### BUGGY CODE ###

from random import randint
import sys
input = sys.stdin.readline
INF = 9223372036854775808


def calc_score(D, C, S, T):
    """
    開催日程Tを受け取ってそこまでのスコアを返す
    コンテストi 0-indexed
    d 0-indexed
    """
    score = 0
    last = [0]*26  # コンテストiを前回開催した日
    for d, t in enumerate(T):
        last[t] = d + 1
        for i in range(26):
            score -= (d + 1 - last[i]) * C[i]
        score += S[d][t]
    return score


def update_score(D, C, S, T, score, ct, ci):
    """
    ct日目のコンテストをコンテストciに変更する
    スコアを差分更新する

    ct: change t 変更日 0-indexed
    ci: change i 変更コンテスト 0-indexed
    """
    last = [0]*26  # コンテストiを前回開催した日
    for d in range(ct):
        last[T[d]] = d + 1
    prei = T[ct]  # 変更前に開催する予定だったコンテストi
    score -= S[ct][prei]
    score += S[ct][ci]
    for d in range(ct, D):
        if d != ct and T[d] == prei:
            break
        score += C[prei]*(d + 1 - ct - 1)
        score -= C[prei]*(d + 1 - last[prei])
    for d in range(ct, D):
        if d != ct and T[d] == ci:
            break
        score += C[ci]*(d + 1 - last[ci])
        score -= C[ci]*(d + 1 - ct - 1)
    T[ct] = ci
    return score, T


def local_search(D, C, S, T, today_score, d):
    pass


def evaluate(D, C, S, T, k):
    """
    d日目終了時点での満足度を計算し，
    d + k日目終了時点での満足度の減少も考慮する
    """
    score = 0
    last = [0]*26
    for d, t in enumerate(T):
        last[t] = d + 1
        for i in range(26):
            score -= (d + 1 - last[i]) * C[i]
        score += S[d][t]

    for d in range(len(T), min(len(T) + k, D)):
        for i in range(26):
            score -= (d + 1 - last[i]) * C[i]
    return score


def greedy(D, C, S):
    Ts = []
    for k in range(26):
        T = []  # 0-indexed
        for d in range(D):
            # d+k日目終了時点で満足度が一番高くなるようなコンテストiを開催する
            max_score = -INF
            best_i = 0
            for i in range(26):
                T.append(i)
                score = evaluate(D, C, S, T, k)
                if max_score < score:
                    max_score = score
                    best_i = i
                T.pop()
            T.append(best_i)
        Ts.append((max_score, T))
    return max(Ts, key=lambda pair: pair[0])[1]


if __name__ == '__main__':
    D = int(input())
    C = [int(i) for i in input().split()]
    S = [[int(i) for i in input().split()] for j in range(D)]
    T = greedy(D, C, S)
    for t in T:
        print(t+1)


### FIXED CODE ###

from random import randint
import sys
input = sys.stdin.readline


def main(D, C, S):
    for _ in range(D):
        print(randint(1, 26))


if __name__ == '__main__':
    D = int(input())
    C = [int(i) for i in input().split()]
    S = [[int(i) for i in input().split()] for j in range(D)]
    main(D, C, S)
### BUGGY CODE ###

N = int(input())
S = [input() for i in range(N)]
r = N*(N-1)//2
ans = 0
for i in range(N):
    g = 0
    for j in range(N):
        ji = (j+i) % N
        for k in range(j+1, N):
            if S[j][(k+i)%N] == S[k][ji]:
                g += 1
    if g == r:
        ans += 1
    for j in range(N-1):
        ji = (j+i) % N
        for k in range(N-1):
            if S[(1+k+j)%N][ji] == S[j][(ji+k+1)%N]:
                g += 1
            if S[(j+k)%N][ji] == S[j][(ji+k)%N]:
                g -= 1
        if g == r:
            ans += 1
print(ans)


### FIXED CODE ###

N = int(input())
S = [input() for i in range(N)]
r = N*(N-1)//2
ans = 0
for i in range(N):
    g = 0
    for j in range(N):
        ji = (j+i) % N
        for k in range(j+1, N):
            if S[j][k+i-N] == S[k][ji]:
                g += 1
    if g == r:
        ans += 1
    for j in range(N-1):
        ji = (j+i) % N
        for k in range(N-1):
            if S[1+k+j-N][ji] == S[j][ji+k+1-N]:
                g += 1
            if S[j+k-N][ji] == S[j][ji+k-N]:
                g -= 1
        if g == r:
            ans += 1
print(ans)
### BUGGY CODE ###

from collections import deque


def main():
    n, k = [int(x) for x in input().split()]
    scores = [int(x) for x in input().split()]
    scores_q = deque(scores)
    news = deque(scores[k:])
    former = 0
    rank = 1
    for score in scores[:k]:
        rank *= score

    for shift in range(n - k):
        former = rank
        remover = scores_q.popleft()
        new_commer = news.popleft()
        rank //= remover
        rank *= new_commer
        if former < rank:
            print('Yes')
        else:
            print('No')


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    n, k = [int(x) for x in input().split()]
    scores = [int(x) for x in input().split()]

    for remover, new_commer in zip(scores, scores[k:]):
        if remover < new_commer:
            print('Yes')
        else:
            print('No')


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

N=int(input())
P=list(map(int,input().split()))
cnt=1
for i in range(1,N):
    if min(P[0:i])>P[i]:
        cnt+=1 
print(cnt)

### FIXED CODE ###

N=int(input())
P=list(map(int,input().split()))
cnt,minimum=0,max(P)
for i in range(N):
    if P[i]<=minimum:
        cnt+=1
        minimum=P[i]
print(cnt)
### BUGGY CODE ###

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

dp = [[0 for _ in range(N)] for _ in range(K)]

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


for i in range(1,K):
	for j in range(1,N):
		if j <= i:
			dp[i][j] = dp[i-1][j]
		else:
			temp = []
			for k in range(i+1):
				temp.append(dp[i][j-(k+1)]+abs(H[j]-H[j-(k+1)]))
			dp[i][j] = min(dp[i-1][j], min(temp))

print(dp[K-1][N-1])


### FIXED CODE ###

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

DP = [0 for _ in range(N)]

for i in range(1,N):
	temp = []
	for j in range(min(i,K)):
		temp.append(DP[i-(j+1)] + abs(H[i]-H[i-(j+1)]))

	DP[i] = min(temp)

print(DP[N-1])
### BUGGY CODE ###

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

C =[[],[],[]]
for i in range(N):
    if S[i] == 'R':
        C[0].append(i)
    elif S[i] == 'G':
        C[1].append(i)
    else:
        C[2].append(i)

count = 0
for i in C[0]:
    for j in C[1]:
        count += len(C[2])
        if max(i,j) + abs(j-i) in C[2]:
            count -= 1
        if min(i,j) - abs(j-i) in C[2]:
            count -= 1
        if (i + j)%2 == 0 and (i + j)//2 in C[2]:
            count -= 1
        

print(count)


### FIXED CODE ###

N = int(input())
S = input()
from collections import deque
C =[deque([]),deque([]),deque([])]
for i in range(N):
    if S[i] == 'R':
        C[0].append(i)
    elif S[i] == 'G':
        C[1].append(i)
    else:
        C[2].append(i)

count = len(C[0])*len(C[1])*len(C[2])

for i in C[0]:
    for j in C[1]:
        if max(i,j) + abs(j-i)<N and S[max(i,j) + abs(j-i)] == "B":
            count -= 1
        if min(i,j) - abs(j-i)>=0 and S[min(i,j) - abs(j-i)] == "B":
            count -= 1
        if (i + j)%2 == 0 and S[(i + j)//2] == "B":
            count -= 1


print(count)
### BUGGY CODE ###

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

for i in range(a, b+1):
    if i<=a+k-1 or b-k+1<=i:
        print(i)


### FIXED CODE ###

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

for i in range(a, b+1):
    if i<=a+k-1 or b-k+1<=i:
        print(i)
### BUGGY CODE ###

def framod(n, mod, a=1):
    for i in range(1,n+1):
        a=a * i % mod
    return a

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod

def main():
    mod = (10 ** 9) + 7
    n, a, b = map(int, input().split())

    ans = 0

    if n % 2 == 0:
        for i in range(0, (n//2)):
            tmp = comb(n, i, mod)
            if (a != i) and (b != i):
                ans += tmp
            if (a != (n - i)) and (b != (n - i)):
                ans += tmp
        ans -= 1
        if (a != (n//2)) and (b != (n//2)):
            ans += comb(n, n//2, mod)
    else:
        for i in range(0, (n//2)+1):
            tmp = comb(n, i, mod)
            if (a != i) and (b != i):
                ans += tmp
            if (a != (n - i)) and (b != (n - i)):
                ans += tmp
        ans -= 1

    print(ans)
    return 0



if __name__ == '__main__':
    main()

### FIXED CODE ###

import math
def main():
    m = (10 ** 9) + 7
    n, a, b = map(int, input().split())

    a_k = math.factorial(a)
    b_k = math.factorial(b)

    # フェルマーの小定理
    a_k = pow(a_k, m - 2, m)
    b_k = pow(b_k, m - 2, m)

    n_a = 1
    for i in range(n-a+1, n+1):
        n_a = (n_a * i) % m

    n_b = 1
    for i in range(n-b+1, n+1):
        n_b = (n_b * i) % m

    n_C_a = a_k * n_a
    n_C_b = b_k * n_b

    n_C_a = n_C_a % m
    n_C_b = n_C_b % m

    p = pow(2, n, m)

    print((p - n_C_a - n_C_b - 1)%m)
    return 0


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

import sys
input = sys.stdin.readline

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

def lcm(a, b):
    return a*b//gcd(a, b)

N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7

L = 1

for Ai in A:
    L = lcm(L, Ai)

ans = 0

for Ai in A:
    ans += L//Ai
    ans %= MOD

print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import defaultdict

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

def lcm(a, b):
    return a//gcd(a, b)*b
    
def inv(x):
    return pow(x, MOD-2, MOD)
    

def factorize(n):
    factors = []
    
    for i in range(2, int(n**0.5)+1):
        cnt = 0
        
        while n%i==0:
            n //= i
            cnt += 1
    
        if cnt>0:
            factors.append((i, cnt))
    
    if n>1:
        factors.append((n, 1))
    
    return factors

N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7
#N = 10**4
#A = [i for i in range(10**6, 10**6-N, -1)]

L = 1
d = defaultdict(int)

for Ai in A:
    f = factorize(Ai)
    
    for n, c in f:
        d[n] = max(d[n], c)

for v, c in d.items():
    L *= v**c
    L %= MOD
    
ans = 0

for Ai in A:
    ans += L*inv(Ai)
    ans %= MOD

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

N = int(input())
a = list(map(str,input().split()))
a.sort()
a_set = list(set(a))
cnt = 0
for i in a_set:
    if int(a.count(str(i))) >= int(i):
        
        cnt +=  (int(a.count(str(i))) - int(i))
    elif  int(a.count(str(i))) < int(i):
        cnt +=  int(a.count(str(i)))
print(cnt)

### FIXED CODE ###

from collections import Counter
N = int(input())
a = list(map(str,input().split()))
a_set = list(set(a))
cnt = 0
c = Counter(a)
for i in a_set:
    if c[i] >= int(i):
        
        cnt +=  (c[i] - int(i))
    elif  c[i] < int(i):
        cnt +=  c[i]
print(cnt)
### BUGGY CODE ###

from itertools import combinations

N = int(input())
s_li = []
for _ in range(N):
    s = input()
    if s[0] in "MARCH":
        s_li.append(s)
s_set = set(s_li)
# print(len(list(combinations(s_set, 3))))
ans = 0
for c in combinations(s_set, 3):
    initial = []
    for name in c:
        if name[0] in initial:
            break
        initial.append(name[0])
    else:
        ans += 1
print(ans)


### FIXED CODE ###

N = int(input())
cnt_li = [0, 0, 0, 0, 0]
comb = [
    [0, 1, 2],
    [0, 1, 3],
    [0, 1, 4],
    [0, 2, 3],
    [0, 2, 4],
    [0, 3, 4],
    [1, 2, 3],
    [1, 2, 4],
    [1, 3, 4],
    [2, 3, 4],
]
for _ in range(N):
    s = input()
    if s[0] == 'M':
        cnt_li[0] += 1
    if s[0] == 'A':
        cnt_li[1] += 1
    if s[0] == 'R':
        cnt_li[2] += 1
    if s[0] == 'C':
        cnt_li[3] += 1
    if s[0] == 'H':
        cnt_li[4] += 1
ans = 0
for i in range(len(comb)):
    one, two, three = comb[i]
    mid = cnt_li[one] * cnt_li[two] * cnt_li[three]
    ans += mid
print(ans)
### BUGGY CODE ###

def mpw(n,m):
    ret=1
    while m>0:
        if m&1:
            ret*=n
            ret%=M
        n*=n
        n%=M;
        m>>=1
    return ret;
def pw(n,m):
    ret=1
    while m>0:
        if m&1:
            ret*=n
        n*=n
        m>>=1
    return ret;

L,A,B,M=map(int,input().split())
ans=0
d=0
for k in range(18,0,-1):
    l=max((pw(10,(k-1))-A+B-1)//B,0)
    r=min((pw(10,k)-A-1)//B,L-1)
    if l<=r:
        ans+=mpw(10,d)*(B*pw(10,k)*(pw(10,(r-l)*k)-1)//(pw(10,k)-1)+(A+B*l)*pw(10,(r-l+1)*k)-(A+B*r))//(pw(10,k)-1)
        ans%=M
        d+=(r-l+1)*k
print(ans)


### FIXED CODE ###

def mpw(n,m):
    ret=1
    while m>0:
        if m&1:
            ret*=n
            ret%=M
        n*=n
        n%=M;
        m>>=1
    return ret;
def pw(n,m):
    ret=1
    while m>0:
        if m&1:
            ret*=n
        n*=n
        m>>=1
    return ret;
def delta(i,j):
    if i==j:
        return 1
    return 0
def mtxmpw(A,m):
    ret=[[delta(i,j) for i in range(len(A))] for j in range(len(A))]
    while m>0:
        if m&1:
            ret=mul(ret,A)
        A=mul(A,A)
        m>>=1
    return ret
def mul(A,B):
    ret=[[0 for i in range(len(B[0]))] for j in range(len(A))]
    for i in range(len(A)):
        for j in range(len(B[0])):
            for k in range(len(B)):
                ret[i][j]+=A[i][k]*B[k][j]
                ret[i][j]%=M
    return ret

L,A,B,M=map(int,input().split())
ans=0
d=0
for k in range(18,0,-1):
    l=max((pw(10,(k-1))-A+B-1)//B,0)
    r=min((pw(10,k)-A-1)//B,L-1)
    if l<=r:
        MT=[[1,mpw(10,k),0],[0,mpw(10,k),(M-B*mpw(10,k)%M)%M],[0,0,mpw(10,k)]]
        v=[[(A+B*r)%M],[(A+B*(r-1)%M+M)%M],[1]]
        u=mul(mtxmpw(MT,r-l),v)
        ans+=mpw(10,d)*u[0][0]%M;
        ans%=M;
        d+=(r-l+1)*k
print(ans)
### BUGGY CODE ###

N = int(input())
ans = 1
A = [int(i) for i in input().split()]
for a in A:
  ans *= a
if ans > 10**18:
  print(-1)
else:
  print(ans)

### FIXED CODE ###

N = int(input())
ans = 1
A = [int(i) for i in input().split()]
if 0 in A:
  print(0)
  exit()
for a in A:
  ans *= a
  if ans > 10**18:
    print(-1)
    exit()
print(ans)
### BUGGY CODE ###

import sys
def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N,K = map(int, input().split())
    h = []
    for _ in range(N):
      h.append(int(input()))
  else:
    N = 5
    K = 3
    h = [10,15,11,14,12]
    # N = 5
    # K = 3
    # h = [5,7,5,7,7]

  h.sort()
  ans = 0
  
  for n in range(0,K-1):
    ans += (h[n+1] - h[n])
  
  max_i = len(h)-K+1
  for i in range(1,max_i):
    tmp = 0
    max_j =  range(i, i+K-1)
    for n in max_j:
      tmp += (h[n+1] - h[n])
    if ans > tmp:
      ans = tmp
    if ans == 0:
      print(ans)
      sys.exit()
  
  print(ans)

main()

### FIXED CODE ###

import sys
def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N,K = map(int, input().split())
    h = []
    for _ in range(N):
      h.append(int(input()))
  else:
    N = 5
    K = 3
    h = [10,15,11,14,12]
    # N = 5
    # K = 3
    # h = [5,7,5,7,7]

  h.sort()  

  ans = (h[K-1] - h[0])
  
  max_i = len(h)-K+1
  for i in range(1,max_i):
    tmp = (h[i+K-1] - h[i])
    if ans > tmp:
      ans = tmp
    if ans == 0:
      print(ans)
      sys.exit()
  
  print(ans)

main()
### BUGGY CODE ###

def resolve():
    a = [int(input()) for _ in range(int(input()))]
    for i, v in enumerate(a):
        _a = a.copy()
        del _a[i]
        print(max(_a))


resolve()

### FIXED CODE ###

def resolve():
    a = [int(input()) for _ in range(int(input()))]
    st = sorted(a)
    first = st[-1]
    second = st[-2]
    for i in a:
        if i == first:
            print(second)
        else:
            print(first)


resolve()
### BUGGY CODE ###

import heapq

def main():
    n, m = map(int, input().split())
    dics = [{} for _ in range(n)]
    rmky = [set() for _ in range(n)]
    for _ in range(m):
        l, r, c = map(int, input().split())
        ky = (l-1, r-1)
        if ky in dics[l-1]:
            if c < dics[l-1][ky]:
                dics[l-1][ky] = c
        else:
            dics[l-1][ky] = c
        if r < n:
            rmky[r].add(ky)
    for i in range(1, n):
        dics[i].update(dics[i-1])
        for v in rmky[i]:
            dics[i].pop(v)
    dist = [float("inf")]*n
    dist[0] = 0
    hq = []
    heapq.heappush(hq, [0, 0])
    st = set()
    while len(hq) > 0:
        v, p = heapq.heappop(hq)
        if v > dist[p]:
            continue
        if p == n-1:
            break
        for l, r in dics[p].keys():
            if (l, r) in st:
                continue
            for i in range(l, r+1):
                if dist[i] > v + dics[p][(l, r)]:
                    dist[i] = v + dics[p][(l, r)]
                    heapq.heappush(hq, [dist[i], i])
            st.add((l, r))
    if dist[n-1] == float("inf"):
        print(-1)
    else:
        print(dist[n-1])

if __name__ == "__main__":
    main()


### FIXED CODE ###

import heapq

def main():
    n, m = map(int, input().split())
    dics = [{} for _ in range(n)]
    for _ in range(m):
        l, r, c = map(int, input().split())
        ky = r-1
        if ky in dics[l-1]:
            if c < dics[l-1][ky]:
                dics[l-1][ky] = c
        else:
            dics[l-1][ky] = c
    dist = [float("inf")]*n
    dist[0] = 0
    hq = []
    heapq.heappush(hq, [0, 0])
    idx = 0
    while len(hq) > 0:
        v, p = heapq.heappop(hq)
        if p < idx:
            continue
        if p == n-1:
            break
        for i in range(idx+1, p):
            if len(dics[i]) > 0:
                for ky in dics[i].keys():
                    if ky in dics[p]:
                        if dics[p][ky] > dics[i][ky]:
                            dics[p][ky] = dics[i][ky]
                    else:
                        if p < ky:
                            dics[p][ky] = dics[i][ky]
        idx = p
        for r in dics[p].keys():
            if dist[r] > v + dics[p][r]:
                dist[r] = v + dics[p][r]
                heapq.heappush(hq, [v + dics[p][r], r])
    if dist[n-1] == float("inf"):
        print(-1)
    else:
        print(dist[n-1])

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

def make_divisors(n):
    div=[]
    i = 1
    ap=div.append
    while i*i <= n:
        if n % i == 0:
            ap(i)
            ap(n//i)
        i += 1
    return set(div)-{n}
def main():
    from collections import Counter
    n,*a=map(int,open(0).read().split())
    d=Counter(a)
    s=set(a)
    c=0
    for t in s:
        if d[t]<2:
            for t in make_divisors(t):
                if t in s:break
            else:c+=1
    print(c)
main()

### FIXED CODE ###

m=8**7
c=[0]*m
for a in[*open(0)][1].split():c[int(a)]+=1
i=r=0
while~i+m:
 i+=1;r+=c[i]==1
 if c[i]:c[::i]=[0]*-(-m//i)
print(r)
### BUGGY CODE ###

# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, M = map(int, input().split())
keys = []
for _ in range(M):
    a, _ = map(int, input().split())
    c = set(map(int, input().split()))
    keys.append([a, c])

ans = float('inf')
for b in range(2**(M)):
    opened = set()
    money = 0
    for key in range(M):
        if (b >> key) & 1:  # key番目の鍵を買う
            money += keys[key][0]
            opened |= keys[key][1]
        if len(opened) == N:
            break
    if len(opened) == N:
        ans = min(ans, money)
if ans == float('inf'):
    ans = -1
print(ans)


### FIXED CODE ###

# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
N, M = map(int, input().split())
keys = []
for _ in range(M):
    a, _ = map(int, input().split())
    key_set = set(map(int, input().split()))
    key_bin = 0
    for c in key_set:
        key_bin += (2**(c-1))
    keys.append([a, key_bin])


N_bin = 2**N
# i番目までのkeyで
dp = [[float('inf')]*N_bin for _ in range(2)]
dp[0][0] = 0
for key in range(M):  # 新加えるkey
    key_val, key_set = keys[key]
    for bit in range(N_bin):  # 加える前の状態
        dp[(key+1) % 2][bit] = min(dp[(key+1) %
                                      2][bit], dp[key % 2][bit])  # くわえない
        dp[(key+1) % 2][bit | key_set] = min(dp[(key+1) % 2][bit | key_set],
                                             dp[key % 2][bit]+key_val)  # 加える
ans = float('inf')
for c in range(2):
    ans = min(ans, dp[c][-1])
if ans == float("inf"):
    ans = -1
print(ans)