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

#input
N, K, Q = map(int, input().split())
A = [int(input()) for i in range(Q)]

points = [K] * N

for ans in A:
    for i in range(len(points)):
        if ans - 1 == i:
            continue
        points[i] -= 1

for point in points:
    if (point > 0):
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

#input
N, K, Q = map(int, input().split())
A = [int(input()) for i in range(Q)]

points = [K-Q] * N

for ans in A:
    points[ans - 1] += 1

for point in points:
    if (point > 0):
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

import numpy as np 
H, N = map(int, input().split())

dp = [np.inf for _ in range(H+1)]

min_cost = np.inf
dp[0]=0
for n in range(N):
    a,b =  map(int, input().split())
    for h in range(H):
        if dp[h]!=np.inf:
            if h+a<H:
                dp[h+a] = np.min([dp[h+a], dp[h]+b])
            elif dp[h]+b<min_cost:
                min_cost = dp[h]+b
print(int(min_cost))



### FIXED CODE ###

H, N = map(int, input().split())
inf =1000100001001000
dp = [inf for _ in range(H+1)]
 
# min_cost = np.inf
dp[0]=0
for n in range(N):
    a,b =  map(int, input().split())
    for h in range(H):
        nj = min(h+a,H)
        dp[nj] = min([dp[nj],dp[h]+b])
        
print(int(dp[H]))
### BUGGY CODE ###

N=int(input())
A= list(map(int, input().split()))
for i in range (N):
    z=0
    for j in range (N):
        for k in range(N):
            if j!=i and k!=i and j<k and A[j]==A[k]:
                z+=1
    print(z)

### FIXED CODE ###

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

d=[0]*(N+1)

for i in range (0,N):
    c=A[i]
    d[c]+=1
    
z=0

for x in range (1,N+1):
    z+=d[x]*(d[x]-1)//2
    
for y in range (0,N):
    r=A[y]
    print(z+1-d[r])
### BUGGY CODE ###

n = int(input())
lis = list(map(int, input().split()))
ans = 1
for i in range(1, n):
    if min(lis[:(i+1)]) == lis[i]:
        ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
lis = list(map(int, input().split()))
m = float('inf')
ans = 0
for i in range(n):
    m = min(m, lis[i])
    if min(m, lis[i]) == lis[i]:
        ans += 1
print(ans)
### BUGGY CODE ###

from copy import copy
import sys
input = sys.stdin.readline

def main():
    n,k = map(int,input().split())
    a = list(map(int,input().split()))

    for i in range(k):
        imos = [0] * (n+1)
        for i in range(n):
            imos[max(0, i-a[i])] += 1
            imos[min(n, i+a[i]+1)] -= 1
        for i in range(n):
            imos[i+1] += imos[i]
        for i in range(n):
            a = copy(imos)
        if all((a[i]==n for i in range(n))):
            break

    for i in a[:-1]:
        print(i, end = ' ')

if __name__ == '__main__':
    main()


### FIXED CODE ###

from copy import copy
import sys
input = sys.stdin.readline

def main():
    n,k = map(int,input().split())
    a = list(map(int,input().split()))

    for i in range(k):
        imos = [0] * (n+1)
        for i in range(n):
            imos[max(0, i-a[i])] += 1
            imos[min(n, i+a[i]+1)] -= 1
        for i in range(n):
            imos[i+1] += imos[i]
        a = copy(imos[:-1])
        if all((a[i]==n for i in range(n))):
            break

    for i in a:
        print(i, end = ' ')

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

import sys
import numpy as np

sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

H, W = map(int,input().split())
#A = [list(map(int,input().split())) for _ in range(H)]
A = np.array([list(input()) for _ in range(H)], 'U1')
eq = A == '.'

dp = np.zeros((H+1,W+1), dtype=int)
#np.zeros(W+1, dtype=int)
dp[1][1] = 1

for i in range(H):
    for j in range(W):
        if eq[i][j]:
            dp[i+1][j+1] = dp[i][j+1] + dp[i+1][j]
#            print(i,j,dp[i])
            if i == 0 and j== 0:
                dp[i+1][j+1] = 1
    dp %= mod

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

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sun Jan  6 21:36:22 2019

@author: Yamazaki Kenichi
"""

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

r =[[0]*W for i in range(H)]
r[0][0]=1


for i in range(1,W):
    if a[0][i]== '.':
        r[0][i] = r[0][i-1]

for j in range(1,H):
    if a[j][0] =='.':
        r[j][0] = r[j-1][0]
            
for j in range(1,H):
    for i in range(1,W):
        if a[j][i] == '.':
            r[j][i] = r[j-1][i]+r[j][i-1]

print(r[H-1][W-1]%1000000007)
### BUGGY CODE ###

from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import time
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()
N,M=map(int,input().split())
LRC=[list(map(int,input().split())) for i in range(M)]
stack=[[0,-1]]
idle_max=10**18
visited=[idle_max for i in range(N+1)]
visited2=[0 for i in range(N+1)]
while stack:
    m,a=heappop(stack)
    a=-a
    if a==N:
        print(m)
        break
    if not visited2[a]:
        visited2[a]=1
        for l,r,c in LRC:
            if l<=a<r:
                _m=m+c
                if _m<visited[r]:
                    visited[r]=_m
                    heappush(stack,[_m,-r])
else:
    print(-1)


### FIXED CODE ###

from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import time
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))

N,M=map(int,input().split())
LRC=[list(map(int,input().split())) for i in range(M)]
LRC.sort()


stack=[[0,-1,0]]
idle_max=10**18
visited=[idle_max for i in range(N+1)]
visited2=[0 for i in range(N+1)]
visited[1]=0
x=0
while stack:
    #print(stack)
    m,a,p=heappop(stack)
    a=-a
    if a==N:
        print(m)
        break
    if not visited2[a]:
        visited2[a]=1
        for i in range(x,M):
            l,r,c=LRC[i]
            x=i
            if l<=a:
                _m=m+c
                if _m<visited[r]:
                    visited[r]=_m
                    heappush(stack,[_m,-r,a+1])
            else:
                break
else:
    print(-1)
### BUGGY CODE ###

inp1 = input().split()
inp2 = input().split()
a = int(inp1[0])
b = inp2
b = [int(s) for s in inp2]
ansno = a
maxno = b[0]

ii = 0
for i in b:
  if ii ==0:
    ii+=1
    continue
  bslice = b[:ii+1]
#  print(ii)
#  print(bslice)
  if min(bslice) != i:
#    print("min(bslice)",min(bslice)," i ",i)
    ansno -=1
  ii+=1
#  print("ansno: ",ansno)
print(ansno)


### FIXED CODE ###

n = int(input())
m = input().split()
ppp = list(map(int, m))
max = 2*10**5+1
ans = 0
for p in ppp:
    if p < max:
        ans += 1
        max = p
print(ans)
### BUGGY CODE ###

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

dp = [1] * (n-k+1)

for i in range(0,k):
    dp[0] = dp[0] * a_list[i]

for j in range(1, n-k+1):
    dp[j] = dp[j-1] * a_list[k+j-1] / a_list[j-1]

for l in range(len(dp)-1):
    if dp[l] < dp[l+1]:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

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

for i in range(0, n-k):
    if a_list[i] < a_list[k+i]:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

k, s = map(int, input().split())
if s < k:
    k = s

count = 0
for x in range(k+1):
    if x > s:
        break
    for y in range(k+1):
        if x+y > s:
            break
        for z in range(k+1):
            if x+y+z == s:
                count += 1

print(count)


### FIXED CODE ###

k, s = map(int, input().split())
count = 0

for x in range(k+1):
    for y in range(k+1):
        z = s-x-y
        if z < 0:
            break
        if z <= k:
            count += 1

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

import sys
from numba import jit

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++
@jit
def cc(v, pp):
	if v == pp[-1]:
		return False, -1
	
	for p in pp:
		if v % p == 0:
			return False, 0
		if v < 2*p:
			return True, 0
	return True, 0
			
@jit
def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	al = lin()
	al.sort()
	pp=[al[0]]
	n_same=0
	n_same_set=set()
	for v in al[1:]:
		tf, vv = cc(v, pp)
		if tf:
			pp.append(v)
		if vv == -1 and pp[-1] not in n_same_set:
			n_same_set.add(pp[-1])
			n_same += vv
	print(len(pp) + n_same)
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

### FIXED CODE ###

import sys
import collections

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = tin()
	al = lin()
	al.sort()
	
	unique_al = list(set(al))
	unique_al.sort()
	
	al_counter = collections.Counter(al)
	ok=[v for v in al_counter.keys() if al_counter[v] == 1]
	d = {v:i for i,v in enumerate(ok)}
	max_v = 10**6+1
	for check in unique_al:
		for v in range(2*check, max_v, check):
			if v in d:
				ok[d[v]]=0
				
	return sum([v > 0 for v in ok ])
		
	
	
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from collections import deque
from heapq import heapify, heappush as hpush, heappop as hpop
N, M, L = map(int, input().split())
X = [[] for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    X[a-1].append([b-1, c])
    X[b-1].append([a-1, c])

def dijkstra(n, E, i0=0):
    h = [[0, i0]]
    D = [-1] * n
    done = [0] * n
    D[i0] = 0
    
    while h:
        d, i = hpop(h)
        done[i] = 1
        for j, w in E[i]:
            nd = d + w
            if D[j] < 0 or D[j] >= nd:
                if done[j] == 0:
                    hpush(h, [nd, j])
                    D[j] = nd
    return [d if d >= 0 else 1<<100 for d in D]
def BFS(n, E, i0=0):
    Q = deque([i0])
    D = [-1] * n
    D[i0] = 0
    while Q:
        x = Q.popleft()
        for c in E[x]:
            if D[c] == -1:
                D[c] = D[x] + 1
                Q.append(c)
    return [d if d >= 0 else 1<<100 for d in D]

Y = [[] for _ in range(N)]
for i in range(N):
    D1 = dijkstra(N, X, i)
    for j in range(N):
        if i == j: continue
        if D1[j] <= L:
            Y[i].append(j)

D2 = []
for i in range(N):
    D2.append(BFS(N, Y, i))

ans = []
for _ in range(int(input())):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    a = D2[s][t]-1
    ans.append(str(a if a < 1 << 50 else -1))

print("\n".join(ans))

### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline
from collections import deque
N, M, L = map(int, input().split())
D = [[1<<40] * N for _ in range(N)]
for i in range(N):
    D[i][i] = 0
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    D[a][b] = c
    D[b][a] = c

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])
Y = [[] for _ in range(N)]
for i in range(N):
    for j in range(N):
        if i == j: continue
        if D[i][j] <= L:
            Y[i].append(j)
def BFS(n, E, i0=0):
    Q = deque([i0])
    D = [-1] * n
    D[i0] = 0
    while Q:
        x = Q.popleft()
        for c in E[x]:
            if D[c] == -1:
                D[c] = D[x] + 1
                Q.append(c)
    return D
D2 = []
for i in range(N):
    D2.append(BFS(N, Y, i))

ans = []
for _ in range(int(input())):
    s, t = map(int, input().split())
    a = D2[s-1][t-1]-1
    ans.append(str(a if a >= 0 else -1))
print("\n".join(ans))
### BUGGY CODE ###

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

max = 0
for x in range(N + 1):
    f = math.floor(A * x / B) - A * math.floor(x / B)
    if f > max:
        max = f
print(max)

### FIXED CODE ###

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

if N >= B:
    max = (A * (B - 1) ) // B
else:
    max = A * N // B
print(max)
### BUGGY CODE ###

#!usr/bin/env python3
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LIR(n):
    return [LI() for i in range(n)]

def solve():
    def add(i,x):
        while i < len(bit):
            bit[i] += x
            i += i&-i
    def sum_(i):
        res = 0
        while i > 0:
            res += bit[i]
            i -= i&-i
        return res
    n,Q = LI()
    c = LI()
    c = [0]+c
    q = LIR(Q)
    q = [[i,q[i]] for i in range(Q)]
    q.sort(key = lambda x:x[1][1])
    bit = [0]*(n+2)
    i = 1
    p = [None]*(n+1)
    ans = [0]*Q
    for ind,(l, r) in q:
        while i <= r:
            ci = c[i]
            j = p[ci]
            if j is not None:
                add(j,-1)
            add(i,1)
            p[ci] = i
            i += 1
        ans[ind] = sum_(r)-sum_(l-1)
    for i in ans:
        print(i)
    return

#Solve
if __name__ == "__main__":
    solve()


### FIXED CODE ###

#!usr/bin/env python3
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LIR(n):
    return [LI() for i in range(n)]
class BIT:
    def __init__(self, size):
        self.size = size + 1
        self.dat = [0]*self.size

    def add(self, i, x=1):
        while i < self.size:
            self.dat[i] += x
            i += i&-i

    # sum[l,r)
    # sum[0,l] (r = None)
    def sum(self, l, r=None):
        if r is None:
            res = 0
            while l > 0:
                res += self.dat[l]
                l -= l&-l
            return res

        else:
            rres = 0
            while r > 0:
                rres += self.dat[r]
                r -= r&-r

            l -= 1
            lres = 0
            while l > 0:
                lres += self.dat[l]
                l -= l&-l

            return rres - lres


def solve():
    n,Q = LI()
    c = LI()
    c = [0]+c
    q = LIR(Q)
    q = [[i,q[i]] for i in range(Q)]
    q.sort(key = lambda x:x[1][1])
    bit = BIT(n+1)
    i = 1
    p = [None]*(n+1)
    ans = [0]*Q
    s = 0
    for ind,(l, r) in q:
        l -= 1
        while i <= r:
            ci = c[i]
            j = p[ci]
            if j is not None:
                bit.add(j)
            else:
                s += 1
            p[ci] = i
            i += 1
        ans[ind] = s-l+bit.sum(l)
    for i in ans:
        print(i)
    return

#Solve
if __name__ == "__main__":
    solve()
### BUGGY CODE ###

n = int(input())
sn = []
dic_sn = []
cnt = 0
for i in range(n):
    sn.append(input())
    set_sn = set(sn[i])
    dic_sn.append({})
    for si in set_sn:
        dic_sn[i][si] = sn[i].count(si)

for i in range(n):
    for j in range(i + 1, n):
        if dic_sn[i] == dic_sn[j]:
            cnt += 1
print(cnt)

### FIXED CODE ###

n = int(input())
dic_sorted_s = {}
count = 0
for i in range(n):
    s = input()
    str_sorted_s = ''.join(sorted(s))
    try:
        count += dic_sorted_s[str_sorted_s]
        dic_sorted_s[str_sorted_s] += 1
    except KeyError:
        dic_sorted_s[str_sorted_s] = 1
print(count)
### BUGGY CODE ###

import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

n = int(input())
ans = set()

for x in make_divisors(n-1):
    ans.add(x)

for x in make_divisors(n):
    m = n
    while m % x == 0:
        m = m//x
    
    for y in sorted(make_divisors(m-1)):
        if y != m-1:
            ans.add(y)

print(len(ans))

### FIXED CODE ###

import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    # divisors.sort()
    return divisors

n = int(input())
ans = set()

for x in make_divisors(n-1):
    if x != 1:
        ans.add(x)

for x in make_divisors(n):
    if x ==1 :
        continue
    if x == n:
        ans.add(x)
        continue
    m = n
    while m % x == 0:
        m = m//x
    
    if m % x == 1:
        ans.add(x)

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

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

### FIXED CODE ###

def resolve():
    N = int(input())
    P = list(map(int, input().split()))
    min = P[0]
    ans = 1
    for i in P:
        if i < min:
            min = i
            ans += 1
    print(ans)
resolve()
### BUGGY CODE ###

import copy
R, C, K = map(int,input().split())
i = [list(map(int,input().split())) for k in range(K)]
dp0 = [[0] * C for r in range(R)]
location = copy.deepcopy(dp0)
dp1 = copy.deepcopy(dp0)
dp2 = copy.deepcopy(dp0)
dp3 = copy.deepcopy(dp0)
for k in range(K):
   location[i[k][0]-1][i[k][1]-1] = i[k][2]
dp1[0][0] = location[0][0]
if R > 1:
   for r in range(R-1):
      dp1[r+1][0] = location[r+1][0] + dp1[r][0]
      dp0[r+1][0] = dp1[r][0]
if C > 1:
   for c in range(C-1):
      dp0[0][c+1] = dp0[0][c]
      dp1[0][c+1] = max(location[0][c+1] + dp0[0][c], dp1[0][c])
      dp2[0][c+1] = max(location[0][c+1] + dp1[0][c], dp2[0][c])
      dp3[0][c+1] = max(location[0][c+1] + dp2[0][c], dp3[0][c])
   if R > 1:
      for r in range(R-1):
         for c in range(C-1):
            if location[r+1][c+1] > 0:
               dp0[r+1][c+1] = max(dp0[r+1][c], dp0[r][c+1], dp1[r][c+1], dp2[r][c+1], dp3[r][c+1])
               dp1[r+1][c+1] = max(dp0[r+1][c+1] + location[r+1][c+1], dp1[r+1][c])
               dp2[r+1][c+1] = max(dp1[r+1][c] + location[r+1][c+1], dp2[r+1][c])
               dp3[r+1][c+1] = max(dp2[r+1][c] + location[r+1][c+1], dp3[r+1][c])
            else:
               dp0[r+1][c+1] = max(dp0[r+1][c], dp0[r][c+1], dp1[r][c+1], dp2[r][c+1], dp3[r][c+1])
               dp1[r+1][c+1] = max(dp0[r+1][c+1], dp1[r+1][c])
               dp2[r+1][c+1] = max(dp1[r+1][c], dp2[r+1][c])
               dp3[r+1][c+1] = max(dp2[r+1][c], dp3[r+1][c])
if R==1 and C==1:
   ans = i[-1][-1]
else:
   ans = max(dp0[R-1][C-1], dp1[R-1][C-1], dp2[R-1][C-1], dp3[R-1][C-1])
print(ans)

### FIXED CODE ###

import sys
import copy
R, C, K = map(int, input().split())
item = [[0] * (C + 1) for _ in range(R + 1)]  # dp配列と合わせるために, 0行目, 0列目を追加している.
for s in sys.stdin.readlines():
    r, c, v = map(int, s.split())
    r -= 1
    c -= 1
    item[r][c] = v
    
dp0 = [[0] * (C+1) for r in range(R+1)]
dp1 = [[0] * (C+1) for r in range(R+1)]
dp2 = [[0] * (C+1) for r in range(R+1)]
dp3 = [[0] * (C+1) for r in range(R+1)]
 
for r in range(R):
   for c in range(C):
      dp3[r][c] = max(dp3[r][c], dp2[r][c] + item[r][c])
      dp2[r][c] = max(dp2[r][c], dp1[r][c] + item[r][c])
      dp1[r][c] = max(dp1[r][c], dp0[r][c] + item[r][c])
      dp1[r][c+1] = max(dp1[r][c], dp1[r][c+1])
      dp2[r][c+1] = max(dp2[r][c], dp2[r][c+1])
      dp3[r][c+1] = max(dp3[r][c], dp3[r][c+1])
      dp0[r+1][c] = max(dp0[r+1][c], dp1[r][c])
      dp0[r+1][c] = max(dp0[r+1][c], dp2[r][c])
      dp0[r+1][c] = max(dp0[r+1][c], dp3[r][c])
ans = max(dp0[R-1][C-1], dp1[R-1][C-1])
ans = max(ans, dp3[R-1][C-1])
ans = max(ans, dp2[R-1][C-1])
print(ans)
### BUGGY CODE ###

from sys import setrecursionlimit

def read_key():
    a, _ = map(int, input().split())
    m = 0
    for c in map(int, input().split()):
        m |= 1 << (c - 1)
    return (a, m)

def solve(keys, amount, cm, dp):
  if cm == (1 << N) - 1:
    return amount
  if len(keys) == 0:
    return INF
  a, m = keys[0]
  if dp[cm | m] < amount + a:
    return solve(keys[1:], amount, cm, dp)
  else:
    dp[cm | m] = amount + a
    return min(solve(keys[1:], amount + a, cm | m, dp), solve(keys[1:], amount, cm, dp))

setrecursionlimit(1000000)
INF = float('inf')

N, M = map(int, input().split())
keys = [read_key() for _ in range(M)]

dp = [INF] * (1 << N)
t = solve(keys, 0, 0, dp)
if t == INF:
  print(-1)
else:
  print(t)


### FIXED CODE ###

def read_key():
    a, _ = map(int, input().split())
    m = 0
    for c in map(int, input().split()):
        m |= 1 << (c - 1)
    return (a, m)


def main():
    INF = float('inf')

    N, M = map(int, input().split())
    keys = [read_key() for _ in range(M)]

    dp = [[INF] * (1 << N) for _ in range(M + 1)]

    dp[0][0] = 0
    for i in range(M):
        a, m = keys[i]
        dpi = dp[i]
        dpi1 = dp[i + 1]
        for j in range(1 << N):
            if dpi[j] == INF:
                continue
            if dpi[j] + a < dpi1[j | m]:
                dpi1[j | m] = dpi[j] + a
            if dpi[j] < dpi1[j]:
                dpi1[j] = dpi[j]

    if dp[M][(1 << N) - 1] == INF:
        print(-1)
    else:
        print(dp[M][(1 << N) - 1])


main()