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

N,M=map(int,input().split())
*H,=map(int,input().split())

rode=[[0 for _ in range(N)] for _ in range(N)] 
dmax=[0 for _ in range(N+1)]

for j in range(M):
    a,b=map(int,input().split())
    rode[a-1][b-1]=1
    dmax[a-1]=max(dmax[a-1],H[b-1])
    dmax[b-1]=max(dmax[b-1],H[a-1])    
          
goodv = [1 for i in range(N) if dmax[i]<H[i]]
print(len(goodv))



### FIXED CODE ###

N,M=map(int,input().split())
*H,=map(int,input().split())

dmax=[0 for _ in range(N+1)]

for j in range(M):
    a,b=map(int,input().split())
    dmax[a-1]=max(dmax[a-1],H[b-1])
    dmax[b-1]=max(dmax[b-1],H[a-1])    
          
goodv = [1 for i in range(N) if dmax[i]<H[i]]
print(len(goodv))
### BUGGY CODE ###

n = int(input())
word = [input() for i in range(n)]
test = list([x,word.count(x)] for x in set(word))
max_num = int(max(test, key=lambda x: x[1])[1])
if(max_num == 1):
  print('\n'.join(sorted(word)))
else:
  print('\n'.join(sorted([num[0] for num in test if int(num[1]) == max_num])))


### FIXED CODE ###

from collections import Counter
n = int(input())
word = Counter([input() for i in range(n)]).most_common()
print('\n'.join(sorted([num[0] for num in word if int(num[1]) == word[0][1]])))
### BUGGY CODE ###

def main():
	n=int(input())
	a=list(map(int, input().split()))
	count=[1]*n
	while sum(count)==n:
		for i in range(n):
			count[i] = a.count(a[i])
	if sum(count)==n:
		print('YES')
	else:
		print('NO')
main()

### FIXED CODE ###

def main():
	n=int(input())
	a=list(map(int, input().split()))
	a.sort()
	c=0
	for i in range(n-1):
		if a[i] == a[i+1]:
			print('NO')
			c+=1
			break
	if c==0:
		print('YES')
main()
### BUGGY CODE ###

n,t=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(n)]
AB.sort()
ma=AB[-1][0]
dp=[0]*(t+ma)    
for a,b in AB:
    for i in range(t+ma-1,a-1,-1):
        if i-a<t:
            dp[i]=max(dp[i],dp[i-a]+b)

print(max(dp))

### FIXED CODE ###

n,t=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(n)]
AB.sort()
ma=AB[-1][0]
dp=[0]*(t+ma)    
for a,b in AB:
    for i in range(t+ma-1,a-1,-1):
        if i-a<t:
            dp[i]=max(dp[i],dp[i-a]+b)

print(max(dp))
### BUGGY CODE ###

n = int(input())
a = list(input().split())
b = []
for i in a:
    b.append(i)
    b = b[::-1]

for s in b:
    print(s,end= ' ')


### FIXED CODE ###

n = int(input())
a = list(input().split())
num = list(range(n-1,-(n-1)-2,-2) )
for i in range(len(num)):
    if num[i]<0:
        num[i] = abs(num[i]+1)
    print(a[num[i]], end = ' ')
### BUGGY CODE ###

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

mn_ln = [[0 for _ in range(n-1)] for _ in range(n)]

dic = {}
x = x-1
y = y-1
for i in range(n):
    for j in range(n):
        if(i == j):
            break

        nm = abs(j - i)
        if(abs(x-i) > abs(y-i)):
            lp = abs(y-i) + abs(x-j) + 1
        else:
            lp = abs(x-i) + abs(y-j) + 1
        
        k = min(nm,lp)
        if(k in dic):
            dic[k] += 1
        else:
            dic[k] = 1
#print(dic[2])


for i in range(1,n):
    if not (i in dic):
        print(0)
    else:
        print(dic[i])


### FIXED CODE ###

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


dic = {}
x = x-1
y = y-1
for i in range(n):
    for j in range(n):
        if(i == j):
            break

        nm = abs(j - i)
        if(abs(x-i) > abs(y-i)):
            lp = abs(y-i) + abs(x-j) + 1
        else:
            lp = abs(x-i) + abs(y-j) + 1
        
        k = min(nm,lp)
        if(k in dic):
            dic[k] += 1
        else:
            dic[k] = 1



for i in range(1,n):
    if not (i in dic):
        print(0)
    else:
        print(dic[i])
### BUGGY CODE ###

import sys
import numpy as np

def main():
    n, w = map(int, input().split())
    a = np.array([list(map(int, x.split())) for x in sys.stdin.readlines()])
    dp = np.array([[0]*(w+1) for _ in range(n+1)])

    for i, aa in zip(range(n), a):
        for j in range(w+1):
            if j - aa[0] >= 0:
                dp[i+1][j] = max(dp[i+1][j] , dp[i][j - aa[0]] + aa[1])

            dp[i+1][j] = max(dp[i+1][j], dp[i][j])
    print(dp[n][w])

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys

def main():
    n, w = map(int, input().split())
    a = [list(map(int, x.split())) for x in sys.stdin.readlines()]
    dp = [[0]*(w+1) for _ in range(n+1)]

    for i in range(n):
        for j in range(w+1):
            if j - a[i][0] >= 0:
                dp[i+1][j] = max(dp[i+1][j] , dp[i][j - a[i][0]] + a[i][1])

            dp[i+1][j] = max(dp[i+1][j], dp[i][j])
    print(dp[n][w])

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

def main():
    n = int(input())
    h_li = list(map(int, input().split()))
    i = 0
    count = 0
    f = 0
    discount = max(h_li)
    while True:
        if h_li[i] >= discount:
            count += 1
            h_li[i] -= 1
            while i < len(h_li) - 1:
                if h_li[i + 1] >= discount:
                    i += 1
                    h_li[i] -= 1
                else:
                    i += 1
                    break
        if i == len(h_li) - 1:
            i = 0
            discount -= 1
            if max(h_li) == 0:
                f = 1
        else:
            i += 1
        if f == 1:
            break
    print(count)
if __name__ == '__main__':
    main()

### FIXED CODE ###

n = int(input())
h_li = list(map(int, input().split()))
count = 0
for i in range(100):
    f = 0
    for j in range(n):
        if h_li[j] >= i + 1:
            if f == 0:
                count += 1
                f = 1
        else:
            f = 0
print(count)
### BUGGY CODE ###

import collections
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

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

for k in range(N):
  A[k] -= (10**6)
  C = collections.Counter(A)
  A[k] += (10**6)
  values, counts = zip(*C.most_common())
  ans = 0
  for i in range(len(counts)):
    if counts[i] == 1:
      pass
    else:
      ans += cmb(counts[i],2)
  print(ans)

### FIXED CODE ###

from collections import Counter
N = int(input())
A = list(map(int, input().split()))
B = Counter(A)
ans = 0

for i in B.values():
  ans += i*(i-1)//2
for a in A:
  k = B[a]
  print(ans - (k*(k-1)//2)+((k-1)*(k-2)//2))
### BUGGY CODE ###

import sys
from heapq import heappop, heappush


class UnionFind:
    def __init__(self, n):
        self.table = [-1] * n

    def _root(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self._root(self.table[x])
            return self.table[x]

    def find(self, x, y):
        return self._root(x) == self._root(y)

    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            self.table[r1] += d2
        else:
            self.table[r1] = r2
            self.table[r2] += d1

    def united_count(self, x):
        return -self.table[self._root(x)]


def dijkstra(s, links, f9, f30):
    q = [s]
    ret = [-1] * n
    visited = set()
    limit = uft.united_count(s)
    while q:
        item = heappop(q)

        v = item & f9
        if v in visited:
            continue
        visited.add(v)

        count = item >> 39
        used = (item >> 9) & f30
        ret[v] = count

        if len(visited) >= limit:
            break

        for u, c in links[v]:
            if u in visited:
                continue
            if l - used < c:
                new_item = ((count + 1) << 39) + (c << 9) + u
            else:
                new_item = (count << 39) + ((used + c) << 9) + u
            heappush(q, new_item)

    return ret


n, m, l = list(map(int, input().split()))
lines = sys.stdin.readlines()

links = [set() for _ in range(n)]
uft = UnionFind(n)

for line in lines[:m]:
    a, b, c = map(int, line.split())
    a -= 1
    b -= 1
    if l < c:
        continue
    links[a].add((b, c))
    links[b].add((a, c))
    uft.union(a, b)

f9 = (1 << 9) - 1
f30 = (1 << 30) - 1

ans = [dijkstra(v, links, f9, f30) for v in range(n)]
buf = []

for line in lines[m + 1:]:
    s, t = map(int, line.split())
    buf.append(ans[s - 1][t - 1])

print('\n'.join(map(str, buf)))


### FIXED CODE ###

import sys

n, m, l = list(map(int, input().split()))
lines = sys.stdin.readlines()
INF = 10 ** 18

dists = [[INF] * n for _ in range(n)]

for i in range(n):
    dists[i][i] = 0

for line in lines[:m]:
    a, b, c = map(int, line.split())
    a -= 1
    b -= 1
    if c > l:
        continue
    dists[a][b] = c
    dists[b][a] = c

for k in range(n):
    dk = dists[k]
    for i in range(n):
        di = dists[i]
        for j in range(n):
            new_dist = di[k] + dk[j]
            if new_dist > l:
                continue
            if di[j] > new_dist:
                di[j] = new_dist

refuels = [[1 if dist < INF else INF for dist in row] for row in dists]

for k in range(n):
    rk = refuels[k]
    for i in range(n):
        ri = refuels[i]
        for j in range(n):
            new_dist = ri[k] + rk[j]
            if ri[j] > new_dist:
                ri[j] = new_dist

buf = []

for line in lines[m + 1:]:
    s, t = map(int, line.split())
    refuel = refuels[s - 1][t - 1]
    buf.append(-1 if refuel == INF else refuel - 1)

print('\n'.join(map(str, buf)))
### BUGGY CODE ###

S = input()[::-1]
dp = [0]*2019
dp[0] = 1
P = [int(S[:i][::-1]) for i in range(1,len(S)+1)]
for i in P:
    dp[i%2019] += 1
print(sum([i*(i-1)//2 for i in dp]))

### FIXED CODE ###

P = 2019
S = input()
N = len(S)
res = 0
 
if P in [2,5]:
    for i in range(N):
        if int(S[i])% P == 0:
            res += i+1
else:
    dic = {0:1}
    t1 = 0
    t2 = 1
    for i in range(N):
        t2 = (10*t2) % P
        t1 = (int(S[N-1-i])*t2 + t1) % P
        if t1 in dic:
            res += dic[t1]
            dic[t1] += 1
        else:
            dic[t1] = 1
 
print(res)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
from collections import Counter
from itertools import combinations
import string

N = int(input())
s = [str(input()) for x in range(N)]


cs = [Counter(x) for x in s]

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

### FIXED CODE ###

# -*- coding: utf-8 -*-
from collections import Counter
from itertools import combinations

N = int(input())
c = ["".join(sorted(str(input()))) for x in range(N)]
cs = Counter(c)

ans=0
for i in cs.values():
    if i!=1:
        ans += (i * (i-1))/2

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




def main()->None:
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    if len(A) > K:
        set_A = set(A)
        count = []
        for s_a in set_A:
            card = A.count(s_a)
            count.append(card)
        sorted_count = sorted(count)
        reduce_num = len(count) - K
        sum_count = 0
        counter = 0
        for c in sorted_count:
            if counter == reduce_num :
                break
            sum_count += c
            counter += 1

        print(sum_count)
    else:
        print(0)

if __name__ == "__main__":
    main()

### FIXED CODE ###

from collections import Counter


def main()->None:
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a = sorted(Counter(a).values(), reverse=True)
    print(sum(a[k:]))

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

import sys
from collections import deque
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline().strip()

def main():
    N, u, v = map(int, input().split())
    u -= 1
    v -= 1
    repn = [[] for _ in range(N)]
    for i in range(N - 1):
        a, b = map(int, input().split())
        repn[a - 1].append((b - 1, i))
        repn[b - 1].append((a - 1, i)) # (to, id)

    """
    まずu, vを結ぶ単純パス上にあるnodeを列挙する。
    これはvを根とする根付き木に対するdfs（再帰）により求まる（参考：ABC152F）
    """

    path = []
    def connected(v, tv, p=-1):
        if v == tv:
            return True
        for w, _ in repn[v]:
            if w == p:
                continue
            elif connected(w, tv, v):
                path.append(w)
                return True
        return False
    connected(v, u)
    path.append(v)
    #print("path={}".format(path))

    """
    次にu, vを結ぶ単純パスP上の各頂点wに対して、wからPに沿わない向きにどれだけ深く潜れるかを求める。
    ただしu-v間のuより半分だけ求めれば十分。全く潜れない場合を０とする。
    """

    def dfs(v, P): # Pに含まれない頂点方向にdfsして深さを求める
        d = -1
        for w, _ in repn[v]:
            if w in P:
                continue
            else:
                d = max(d, dfs(w, [v]))
        return d + 1
    
    depth = []
    dist = len(path)
    for i, w in enumerate(path):
        if i == 0:
            depth.append(dfs(w, path[:2]))
        elif i < dist // 2:
            depth.append(dfs(w, [path[i - 1],path[i + 1]]))
        else:
            break
    #print("depth={}".format(depth))

    """
    これで準備は完了。あとはu-v間の距離から高橋君が青木君から逃げるのにpath上の
    どの頂点から潜るのかを求めればよい。
    """

    ans = 0
    for i in range(dist // 2):
        val = (dist - i - 1) + depth[i] - 1
        ans = max(ans, val)
    print(ans)
   


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
from collections import deque
sys.setrecursionlimit(10**5)
def input(): return sys.stdin.readline().strip()

"""
Pypyは再帰が遅いらしいのでPythonで通してみる
"""

def main():
    N, u, v = map(int, input().split())
    u -= 1
    v -= 1
    repn = [[] for _ in range(N)]
    for i in range(N - 1):
        a, b = map(int, input().split())
        repn[a - 1].append((b - 1, i))
        repn[b - 1].append((a - 1, i)) # (to, id)

    """
    まずu, vを結ぶ単純パス上にあるnodeを列挙する。
    これはvを根とする根付き木に対するdfs（再帰）により求まる（参考：ABC152F）
    """

    path = []
    def connected(v, tv, p=-1):
        if v == tv:
            return True
        for w, _ in repn[v]:
            if w == p:
                continue
            elif connected(w, tv, v):
                path.append(w)
                return True
        return False
    connected(v, u)
    path.append(v)
    #print("path={}".format(path))

    """
    次にu, vを結ぶ単純パスP上の各頂点wに対して、wからPに沿わない向きにどれだけ深く潜れるかを求める。
    しかし最終的には「頂点vから（高橋君が逃げ込める中で）最も遠い頂点」を求めればよいので、
    uvの中点からdfsすれば十分。
    """

    def dfs(v, p): # Pと異なる頂点方向にdfsして深さを求める
        d = -1
        for w, _ in repn[v]:
            if w == p:
                continue
            else:
                d = max(d, dfs(w, v))
        return d + 1
    
    dist = len(path)
    mid = path[dist // 2 - 1]
    par = path[dist // 2]
    ans = dfs(mid, par)
    print(ans + (dist - 1) // 2)
   


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

p=[0]*10000;mp=[];inf=65536;v=[0]*10000;t=[0]*10000


ans=100000

n,m,r=map(int,raw_input().split(' '))

p=map(int,raw_input().split(' '))

def dsss(x,now):
	global ans
	if x==r+1:
		ans=min(ans,now)
		return 
	else :
		for i in range(r):
			if v[p[i]]==0 :
				v[p[i]]=1
				t[x]=p[i]
				if x==1:
					dsss(x+1,now)
				else :
					dsss(x+1,now+mp[p[i]-1][t[x-1]-1])
				v[p[i]]=0
	return 


for i in range(n+5):
	mp.append(range(n+5))


for i in range(n+5):
    for j in range(n+5):
        mp[i][j]=inf

for i in range(m):
	a,b,c=map(int,raw_input().split(' '))
	a-=1;b-=1;
	mp[a][b]=min(mp[a][b],c)
	mp[b][a]=min(mp[b][a],c)

for i in range(n):
	for j in range(n):
		for k in range(n):
			mp[j][k]=min(mp[j][k],mp[j][i]+mp[i][k])

dsss(1,0)

print ans


### FIXED CODE ###

#!/usr/bin/python

import sys

p=[0]*10000;mp=[];inf=65530060;v=[0]*1000;t=[0]*1000
 
 
ans=100000000

 
n,m,r=map(int,sys.stdin.readline().split(" "))



s=sys.stdin.readline().replace("\n","")

p=map(int,s.split(" "))


def dsss(x,now):
	global ans,v,p,t,mp
	if x==r+1:
		ans=min(ans,now)
		return 
	else :
		for i in range(r):
			if v[p[i]]==0 :
				v[p[i]]=1
				t[x]=p[i]
				if x==1:
					dsss(x+1,now)
				else :
					dsss(x+1,now+mp[p[i]-1][t[x-1]-1])
				v[p[i]]=0
	return 
 
 
for i in range(n+5):
	mp.append(range(n+5))
 
 
for i in range(n+5):
    for j in range(n+5):
            mp[i][j]=inf


for i in range(m):
	a,b,c=map(lambda x: int(x),sys.stdin.readline().split(" ",3))
	a-=1;b-=1;
	mp[a][b]=min(mp[a][b],c)
	mp[b][a]=min(mp[b][a],c)


for i in xrange(n):
	for j in xrange(n):
		for k in xrange(n):
			if mp[j][i]+mp[i][k]<mp[j][k]:
			    mp[j][k]=mp[j][i]+mp[i][k]

dsss(1,0)
 
print ans
### BUGGY CODE ###

n=int(input())
a=input().split()
b=[]

for i in range(n):
    b.append(a[i])
    b.reverse()
print(' '.join(b))


### FIXED CODE ###

n=int(input())
a=input().split()
a_even=[a[i] for i in range(0,n,2)]
a_odd=[a[i] for i in range(1,n,2)]

if n%2==1:
    a_even.reverse()
    ans=' '.join(a_even) +' ' + ' '.join(a_odd)
    print(ans)
else:
    a_odd.reverse()
    ans=' '.join(a_odd)+' '+' '.join(a_even)
    print(ans)
### BUGGY CODE ###

import sys

def input():
    return sys.stdin.readline().strip()

def main():

    K = int(input())

    if K % 2 == 0:
        print(-1)
        exit()

    ans = 1
    X = 7
    while True:
        mod = X % K
        if mod == 0:
            break
        else:
            ans += 1
            X = mod * 10 + 7
    print(ans)
        

if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys

def input():
    return sys.stdin.readline().strip()

def main():

    K = int(input())

    if K % 2 == 0:
        print(-1)
        exit()

    ans = 1
    X = 7
    count = K
    while count > 0:
        mod = X % K
        if mod == 0:
            break
        else:
            ans += 1
            X = mod * 10 + 7
            count -= 1
    print(ans if count > 0 else -1)
        

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

N = int(input())
A = input().split()
for i in A:
    A = [j for j in A if j != i]
    if len(A) == N - 1:
        N -= 1
        continue
    else:
        print("NO")
        break
if N == 0:
    print("YES")


### FIXED CODE ###

N = int(input())
A = input().split()
if len(A) == len(set(A)):
    print("YES")
else:
    print("NO")
### BUGGY CODE ###

import math
N,M = list(map(int,input().split()))
a = [-1]
for i in range(M):
    a.append(int(input()))
a.append(N+1)
b = []
c = []
for i in range(M+1):
    b.append(a[i+1]-a[i]-2)
    for i in range(len(b)):
        counter= 0
        for num2 in range(b[i]//2+1):
            counter += math.factorial(num2+(b[i]-2*num2))//math.factorial(num2)//math.factorial(b[i]-2*num2)
    c.append(counter)
ans = 1
for i in range(len(c)):
    ans *= c[i]
print(ans%1000000007)


### FIXED CODE ###

n,m = map(int,input().split())
a = [ int(input()) for _ in range(m)]
M=10**9+7
lis = [1] + [0]*n

for i in a:
  lis[i]=-1
lis[1] += 1
for i in range(n-1):
  if lis[i+2]<0:
    lis[i+2]= 0
  else:
    lis[i+2] = (lis[i+1] + lis[i])%M
print(lis[n])
### BUGGY CODE ###

def solve(n, x, a):
	costs = []
	cost_min = 0
	for k in range(n):
		if k == 0:
			costs = a.copy()
		else:
			for i in range(n):
				costs[i] = min(costs[i], a[(i-k)%n])
		cost_k = sum(costs) + k*x
		if k == 0:
			cost_min = cost_k
		else:
			cost_min = min(cost_min, cost_k)		
		if cost_min < (k+1) *x:
			break

	return cost_min

n, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
print(solve(n,x,a))



### FIXED CODE ###

def solve(n, x, a):
	costs = []
	cost_min = 0
	for k in range(n):
		if k == 0:
			costs = a.copy()
		else:
			for i in range(n):
				costs[i] = min(costs[i], a[(i-k)%n])
		cost_k = sum(costs) + k*x
		if k == 0:
			cost_min = cost_k
		else:
			cost_min = min(cost_min, cost_k)
			if cost_min != cost_k:
				break
		if cost_min < (k+1) *x:
			break

	return cost_min
n, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
print(solve(n,x,a))
### BUGGY CODE ###

t,n=map(int,input().split())
x=list(map(int,input().split()))
xx=[i+t for i in x]
x=x+xx
dis=[]
for i in range(2*n-1):
    dis.append(x[i+1]-x[i])

ans=[]
for j in range(2*n-2):
    ans2=dis[j:j+n-1]
    ans.append(sum(ans2))
print(min(ans))

### FIXED CODE ###

t,n=map(int,input().split())
x=list(map(int,input().split()))
x.insert(0,x[-1]-t)
dis=[x[i+1]-x[i] for i in range(n)]
print(sum(dis)-max(dis))
### BUGGY CODE ###

N = int(input())
a = sorted(list(map(int, input().split())))
import numpy as np
from scipy.misc import comb

def find_p(n, i):
    lo = 0
    hi = i
    mid = (hi-lo)//2
    xl = a[0]
    xh = a[i]
    while hi - lo > 1:
        mid = (hi+lo)//2
        if a[mid] > n//2:
            hi = mid
        else:
            lo = mid
    if abs(a[lo] - n/2) > abs(a[hi] - n/2):
        return a[hi]
    else:
        return a[lo]

ans = (0, 0)
x = 0
for j in range(N):
    i = N-j-1
    if a[i] < ans[1]:
        break
    n = a[i]
    p = find_p(n, i)
    y = comb(n, p)
    if y > x:
        ans = (n, p)
        x = y

print(str(ans[0]) + ' ' + str(ans[1]))


### FIXED CODE ###

N = int(input())
a = sorted(list(map(int, input().split())))

def find_p(n, i):
    lo = 0
    hi = i
    mid = (hi-lo)//2
    xl = a[0]
    xh = a[i]
    while hi - lo > 1:
        mid = (hi+lo)//2
        if a[mid] > n//2:
            hi = mid
        else:
            lo = mid
    if abs(a[lo] - n/2) > abs(a[hi] - n/2):
        return a[hi]
    else:
        return a[lo]



print(str(a[-1]) + ' ' + str(find_p(a[-1], N-1)))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)

S = list(input())
S.pop()
length=len(S)
dp = [[0 for _ in range(13)] for _ in range(length+1)]
dp[0][0]=1
for i in range(length):
    for j in range(13):
        if S[length-i-1] == "?":
            for k in range(10):
                j_sub = j-k*10**i%13
                if j_sub < 0: j_sub+= 13
                dp[i+1][j]+=dp[i][j_sub]
        else: 
            j_sub = j-int(S[length-i-1])*10**i%13
            if j_sub < 0: j_sub+= 13
            dp[i+1][j]+=dp[i][j_sub]
print(dp[length][5]%1000000007)

### FIXED CODE ###

import sys
input = sys.stdin.readline
def main():  
    S = list(input())
    S.pop()
    length=len(S)
    dp = [0]*13
    dp[0]=1
    mul=1
    mod=1000000007
    for i in range(1,length+1):
        next_dp = [0]*13
        for j in range(13):
            if S[length-i] == "?":
                for k in range(10):
                    j_sub=(j+k*mul)%13
                    next_dp[j_sub]+=dp[j]
                    next_dp[j_sub]%=mod
            else:
                j_sub=(j+int(S[length-i])*mul)%13
                next_dp[j_sub]+=dp[j]
                next_dp[j_sub]%=mod
        dp=next_dp
        mul=mul*10%13
    print(dp[5]%1000000007)
if __name__ == "__main__":
    main()
### BUGGY CODE ###

import itertools
 
S = list(map(int, input().strip().split()))
N = S[0]
K = S[1]
p = list(map(int, input().strip().split()))
lists = [1000000000000]
for l in list(itertools.combinations(p, K)):
  sums = sum(list(l))
  if sums <= lists[0]:
    lists.append(sums)

print(min(lists))


### FIXED CODE ###

S = list(map(int, input().strip().split()))
N = S[0]
K = S[1]
p = list(map(int, input().strip().split()))
lists = []
for l in range(K):
  lists.append(min(p))
  p.remove(min(p))
  
print(sum(lists))
### BUGGY CODE ###

import numpy as np


n, m = [int(x) for x in input().split()]

INF = int(10e8 + 1)
dp = np.full(1 << n, INF, dtype=int)
dp[0] = 0

for j in range(m):
    cost = int(input().split()[0])

    boxes = [int(x)-1 for x in input().split()]
    mask = 0

    mask = sum(1 << box for box in boxes)
    
    for i in range(1 << n):
        dp[i | mask] = min(
                dp[i | mask],
                dp[i] + cost
            )

res = dp[-1] if dp[-1] != INF else -1
print(res)


### FIXED CODE ###

n, m = [int(x) for x in input().split()]

INF = int(10e8 + 1)
dp = [INF] * (1 << n)
dp[0] = 0

for j in range(m):
    cost = int(input().split()[0])

    boxes = [int(x)-1 for x in input().split()]
    mask = 0

    mask = sum(1 << box for box in boxes)
    
    for i in range(1 << n):
        if dp[i] + cost < dp[i | mask]:
            dp[i | mask] = dp[i] + cost

res = dp[-1] if dp[-1] != INF else -1
print(res)