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

from functools import lru_cache

import sys
sys.setrecursionlimit(1000000)

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

A = [int(input()) for _ in range(M)]

@lru_cache(None)
def dfs(pos):
    if pos > N:
        return 0
    if pos == N:
        return 1
    if pos in A:
        return 0
    return dfs(pos + 2) + dfs(pos + 1)

for i in reversed(range(N+1)):
    dfs(i)

print(dfs(0) % 1000000007)


### FIXED CODE ###

from functools import lru_cache

import sys
sys.setrecursionlimit(1000000)

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

A = set(int(input()) for _ in range(M))

@lru_cache(None)
def dfs(pos):
    if pos > N:
        return 0
    if pos == N:
        return 1
    if pos in A:
        return 0
    return dfs(pos + 2) + dfs(pos + 1)

for i in reversed(range(N+1)):
    dfs(i)

print(dfs(0) % 1000000007)
### BUGGY CODE ###

n,k = [int(i) for i in input().split()]
edges = [[int(i)-1 for i in input().split()] for j in range(n-1)]

node = [[] for _ in range(n)]
for edge in edges:
    node[edge[0]].append(edge[1])
    node[edge[1]].append(edge[0])

M = 0
for i in range(n):
    count = 1
    que = []
    check = [False]*n
    if k%2==0:
        check[i] = True
        que.append(i)
    elif i!=n-1:
        check[edges[i][0]]=True
        check[edges[i][1]]=True
        que.append(edges[i][0])
        que.append(edges[i][1])
        count = 2
    for j in range(k//2):
        newque = []
        while len(que)!=0:
            q = que.pop()
            for l in node[q]:
                if check[l]:
                    continue
                newque.append(l)
                check[l] = True
                count += 1
        que = newque
    M = max(M,count)
print(n-M)

### FIXED CODE ###

n,k = [int(i) for i in input().split()]
edges = [[int(i)-1 for i in input().split()] for j in range(n-1)]

node = [[] for _ in range(n)]
for edge in edges:
    node[edge[0]].append(edge[1])
    node[edge[1]].append(edge[0])

M = 0
for i in range(n):
    count = 1
    que = []
    check = [False]*n
    if k%2==0:
        check[i] = True
        que.append(i)
    elif i!=n-1:
        check[edges[i][0]]=True
        check[edges[i][1]]=True
        que.append(edges[i][0])
        que.append(edges[i][1])
        count = 2
    for j in range(k//2):
        newque = []
        while len(que)!=0:
            q = que.pop()
            for l in node[q]:
                if check[l]:
                    continue
                newque.append(l)
                check[l] = True
                count += 1
        que = newque
    M = max(M,count)
print(n-M)
### BUGGY CODE ###

H,W=map(int,input().split())
board=[[True]*(W+2)]
for i in range(H):
    board.append([True]+[a=='#' for a in input()]+[True])
board.append([True]*(W+2))

q=[]
for i in range(1,H+1):
    for j in range(1,W+1):
        if board[i][j]:
            q.append([i,j])

cnt=0
while q:
    nq=[]
    for h,w in q:
        if not board[h+1][w]:
            board[h+1][w]=True
            nq.append([h+1,w])
        if not board[h-1][w]:
            board[h-1][w]=True
            nq.append([h-1,w])
        if not board[h][w+1]:
            board[h][w+1]=True
            nq.append([h,w+1])
        if not board[h][w-1]:
            board[h][w-1]=True
            nq.append([h,w-1])

    q=nq
    cnt+=1

print(cnt-1)




### FIXED CODE ###

H,W=map(int,input().split())
board=[[True]*(W+2)]
for i in range(H):
    board.append([True]+[a=='#' for a in input()]+[True])
board.append([True]*(W+2))

q=[]
for h in range(1,H+1):
    for w in range(1,W+1):
        if board[h][w]:
            q.append((h,w))

cnt=0
while q:
    nq=[]
    for h,w in q:
        if not board[h+1][w]:
            board[h+1][w]=True
            nq.append((h+1,w))
        if not board[h-1][w]:
            board[h-1][w]=True
            nq.append((h-1,w))
        if not board[h][w+1]:
            board[h][w+1]=True
            nq.append((h,w+1))
        if not board[h][w-1]:
            board[h][w-1]=True
            nq.append((h,w-1))

    q=nq
    cnt+=1

print(cnt-1)
### BUGGY CODE ###

N = int(input())
tmp = input()
count = 0
for i in range(N):
    tmp_l = int(tmp.split(' ')[i])
    while(tmp_l % 2 == 0):
        count += 1
        tmp_l = tmp_l / 2

print(count)


### FIXED CODE ###

import math
N = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(N):
  while a[i] % 2 == 0:
    ans += 1
    a[i] = a[i] // 2
print(ans)
### BUGGY CODE ###

X = input()
Y = input()

dp = [[0]*(len(Y)+1) for _ in [0]*(len(X)+1)]

for i, x in enumerate(X):
    i += 1
    for j, y in enumerate(Y):
        j += 1
        dp[i][j] = max(dp[i-1][j-1]+int(x == y),
                       dp[i-1][j], dp[i][j-1])

ans = []
cnt = dp[-1][-1]
x = y = -1
while cnt:
    while dp[x-1][y] == cnt:
        x -= 1
    while dp[x][y-1] == cnt:
        y -= 1
    ans.append(X[x])
    cnt -= 1
    x -= 1
    y -= 1
ans = ''.join(ans)[::-1]
print(ans)


### FIXED CODE ###

X = input()
Y = input()

dp = [[0]*(len(Y)+1) for _ in [0]*(len(X)+1)]

for i, x in enumerate(X):
    i += 1
    for j, y in enumerate(Y):
        j += 1
        dp[i][j] = max(dp[i-1][j-1]+int(x == y),
                       dp[i-1][j], dp[i][j-1])

ans = []
cnt = dp[-1][-1]
x = y = -1
while cnt:
    while dp[x-1][y] == cnt:
        x -= 1
    while dp[x][y-1] == cnt:
        y -= 1
    ans.append(X[x])
    cnt -= 1
    x -= 1
    y -= 1
ans = ''.join(ans)[::-1]
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
h,w=map(int,input().split())
a=[]
for i in range(h):
    a.append(list(map(int,input().split())))
b=[]
for i in range(h):
    b.append(list(map(int,input().split())))
dp=[[set([]) for i in range(w)] for j in range(h)]
dp[0][0].add(a[0][0]-b[0][0])
dp[0][0].add(b[0][0]-a[0][0])
for i in range(h):
    for j in range(w):
        if i==j==0:
            continue
        if i==0:
            for k in dp[i][j-1]:
                if k<=3550:
                    dp[i][j].add(abs(k+a[i][j]-b[i][j]))
                    dp[i][j].add(abs(k+b[i][j]-a[i][j]))
        elif j==0:
            for k in dp[i-1][j]:
                if k<=3550:
                    dp[i][j].add(abs(k+a[i][j]-b[i][j]))
                    dp[i][j].add(abs(k+b[i][j]-a[i][j]))
        else:
            for k in (dp[i][j-1]|dp[i-1][j]):
                if k<=6000:
                    dp[i][j].add(abs(k+a[i][j]-b[i][j]))
                    dp[i][j].add(abs(k+b[i][j]-a[i][j]))             
#dp[h-1][w-1]
ans=10**10
for i in dp[h-1][w-1]:
    ans=min(ans,abs(i))
print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline
H,W=map(int,input().split())
a = [[] for _ in range(H)]
for i in range(H):
    a[i] = list(map(int, input().split()))
b = [[] for _ in range(H)]
for i in range(H):
    b[i] = list(map(int, input().split()))

for i in range(H):
    for j in range(W):
        a[i][j] =abs(a[i][j]-b[i][j])

dp = [[set() for _ in range(W)] for _ in range(H)]
dp[0][0].add(a[0][0])
for i in range(1,H):
    t = a[i][0]
    tmp = set()
    for k in dp[i-1][0]:
        tmp.add(k+t)
        tmp.add(abs(k-t))
    dp[i][0] = tmp
for j in range(1,W):
    t = a[0][j]
    tmp = set()
    for k in dp[0][j-1]:
        tmp.add(k+t)
        tmp.add(abs(k-t))
    dp[0][j] = tmp
for i in range(1,H):
    for j in range(1,W):
        t = a[i][j]
        tmp = set()
        for k in (dp[i-1][j] | dp[i][j-1]):
            tmp.add(k+t)
            tmp.add(abs(k-t))
        dp[i][j] = tmp
        dp[i-1][j-1] = set()

ls = list(dp[H-1][W-1])
print(min(ls))
### BUGGY CODE ###

S = input()
n = len(S)
mod = (10**9 + 7)

A = [0] * n
C = [0] * n
Q = [0] * n
Bi = []
Qi = []

for i, s in enumerate(S):
    if s == 'A':
        A[i] = 1
    elif s == 'B':
        Bi.append(i)
    elif s == 'C':
        C[i] = 1
    else:
        Q[i] = 1
        Qi.append(i)

for i in range(1, n):
    A[i] += A[i - 1]
    C[i] += C[i - 1]
    Q[i] += Q[i - 1]

def mod_pow(x, n, mod):
    if n == 0: return 1
    d, m = n >> 1, n & 1
    p = mod_pow(x, d, mod)
    return (p * p * (x if m else 1)) % mod

from itertools import chain
ans = 0
for b in chain(Bi, Qi):
    if b == 0 or n - 1 <= b: continue
    ai = A[b - 1]
    qa = Q[b - 1]
    a = (ai * mod_pow(3, qa, mod))
    if qa > 0:
        a += (mod_pow(3, qa - 1, mod) * qa)

    lc = C[n - 1] - C[b]
    lqc = Q[n - 1] - Q[b]
    c = (lc * mod_pow(3, lqc, mod))
    if lqc > 0:
        c += (mod_pow(3, lqc - 1, mod) * lqc)
    
    ans += (a * c) % mod

print(ans % mod)

### FIXED CODE ###

S = input()
n = len(S)
mod = (10**9 + 7)

dp = [[0] * 4 for _ in range(n + 1)]

dp[n] = [0, 0, 0, 1]
for i in range(n-1, -1, -1):
    if S[i] == '?':
        dp[i][3] =  dp[i+1][3] * 3 % mod
        dp[i][2] = (dp[i+1][2] * 3 + dp[i+1][3]) % mod
        dp[i][1] = (dp[i+1][1] * 3 + dp[i+1][2]) % mod
        dp[i][0] = (dp[i+1][0] * 3 + dp[i+1][1]) % mod
    elif S[i] == 'C':
        dp[i][3] =  dp[i+1][3] % mod
        dp[i][2] = (dp[i+1][2] + dp[i+1][3]) % mod
        dp[i][1] =  dp[i+1][1] % mod
        dp[i][0] =  dp[i+1][0] % mod
    elif S[i] == 'B':
        dp[i][3] =  dp[i+1][3] % mod
        dp[i][2] =  dp[i+1][2] % mod
        dp[i][1] = (dp[i+1][1] + dp[i+1][2]) % mod
        dp[i][0] =  dp[i+1][0] % mod
    elif S[i] == 'A':
        dp[i][3] =  dp[i+1][3]
        dp[i][2] =  dp[i+1][2]
        dp[i][1] =  dp[i+1][1]
        dp[i][0] = (dp[i+1][0] + dp[i+1][1]) % mod
print(dp[0][0])
### BUGGY CODE ###

import itertools
import numpy as np
n,m=map(int,input().split()) #<=2*10**3
#n
s=list(map(int,input().split()))
#m
t=list(map(int,input().split()))
mod=10**9+7
ans=np.zeros(m,dtype="int64")

for u in s:
    h=np.zeros(m,dtype="int64")
    if u==t[0]:
        h[0]+=1
    for i in range(1,m):
        if t[i]==u:
            h[i]+=ans[i-1]+1
        h[i]+=h[i-1]
    ans=(ans+h)%mod
print(ans[-1]+1)

### FIXED CODE ###

n,m=map(int,input().split()) #<=2*10**3
#n
s=list(map(int,input().split()))
#m
t=list(map(int,input().split()))
mod=10**9+7
ans=[0]*m

for u in s:
    h=[0]*m
    if u==t[0]:
        h[0]=1
    for i in range(1,m):
        if t[i]==u:
            h[i]+=ans[i-1]+1
        h[i]+=h[i-1]
    for i in range(m):
        ans[i]=(ans[i]+h[i])%mod
print((ans[-1]+1)%mod)
### BUGGY CODE ###

import numpy as np
m = 10**9 + 7
n = int(input())
an = list(map(int, input().split()))
an_np = np.array(an)
summary = 0
for i in range(0, n-1):
    summary = (summary + sum(an_np[i] * an_np[i+1: n])) % m
print(summary)

### FIXED CODE ###

m = 10**9 + 7
n = int(input())
an = list(map(int, input().split()))
wa = []
total = 0
for i in reversed(range(1, len(an))):
    total = total + an[i]
    wa.append(total)
wa = sorted(wa, reverse=True)
ans = 0
for i in range(0, n-1):
#     print(an[i] * wa[i])
    ans = ans + an[i] * (wa[i]%m)
    ans = ans % m
print(ans)
### BUGGY CODE ###

N = int(input())
colors = input()
data = [int(c == 'R') for c in colors]

min_move = float('inf')

for i in range(N + 1):
    left = data[:i]
    lm = len(left) - sum(left)
    right = data[i:]
    rm = sum(right)
    move = min(lm, rm) + abs(lm - rm)
    min_move = min(min_move, move)

print(min_move)


### FIXED CODE ###

N = int(input())
colors = input()
data = [int(c == 'R') for c in colors]

lm = 0
rm = sum(data)
min_move = rm

for i in range(N):
    if data[i]:
        rm -= 1
    else:
        lm += 1
    move = min(lm, rm) + abs(lm - rm)
    min_move = min(min_move, move)

print(min_move)
### BUGGY CODE ###

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

for i in range(M):
    B, C = map(int,input().split())

    counter=0
    while counter < B:
        counter+=1
        minA = min(A)
        if minA < C:
            idx = A.index(minA)
            A[idx] = C
        else:
            break


print(sum(A))




### FIXED CODE ###

N, M = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse=True)

BC = [[] for i in range(M)]

for i in range(M):
    BC[i]=list(map(int,input().split()))

BC = sorted(BC, key=lambda x: x[1], reverse=True)
maxC = BC[0][1]

count = 0
result = 0
while count < N:
    if len(BC) >0:
        if A[0] < BC[0][1]:
            for i in range(BC[0][0]):
                if count < N:
                    result += BC[0][1]
                    count+=1
                else:
                    break
            else:
                BC.pop(0)
        else:
            result+=A.pop(0)
            count+=1
    else:
        result+=A.pop(0)
        count+=1

print(result)
### BUGGY CODE ###

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

N, W = map(int, input().split())
items = [list(map(int, input().split())) for _ in range(N)]
dp = [[0]*(W+1) for _ in range(N)]

# init
first_item = items[0]
for i in range(W+1):
    if i >= first_item[0]:
        dp[0][i] = first_item[1]

# update
for i in range(1, N):
    for w in range(W+1):
        if w-items[i][0] >= 0:
            dp[i][w] = max(dp[i-1][w], dp[i-1][w-items[i][0]]+items[i][1])
        else:
            dp[i][w] = dp[i-1][w]

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


### FIXED CODE ###

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

N, W = map(int, input().split())
items = [list(map(int, input().split())) for _ in range(N)]
dp = [[0]*(W+1) for _ in range(N)]

# init
first_item = items[0]
for i in range(W+1):
    if i >= first_item[0]:
        dp[0][i] = first_item[1]

# update
for i in range(1, N):
    for w in range(W+1):
        if w-items[i][0] >= 0:
            dp[i][w] = max(dp[i-1][w], dp[i-1][w-items[i][0]]+items[i][1])
        else:
            dp[i][w] = dp[i-1][w]

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

N = int(input())
MOD = 10 ** 9 + 7
ans = 1
for i in range(1, N + 1):
  ans *= i

print(ans % MOD)

### FIXED CODE ###

N = int(input())
MOD = 10 ** 9 + 7
ans = 1
for i in range(1, N + 1):
  ans *= i
  ans %= MOD

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

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


### FIXED CODE ###

N=int(input())
P=list(map(int,input().split()))
count=0
min=2*10**5
for i in range(N):
    if P[i]<=min:
        min=P[i]
        count+=1
print(count)
### BUGGY CODE ###

n, m = map(int, input().split())
l, r = map(int, input().split())
S = set(range(l, r + 1))
for i in range(m - 1):
	l, r = map(int, input().split())
	S &= set(range(l, r + 1))
print(len(S))

### FIXED CODE ###

n, m = map(int, input().split())
maxl, minr = map(int, input().split())
for i in range(m - 1):
	l, r = map(int, input().split())
	maxl = max(maxl, l)
	minr = min(minr, r)
print(max(0, minr - maxl + 1))
### BUGGY CODE ###

import itertools

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

#N人の参加者から、M組選ぶ
#これをNセット実施。
#組合わせの距離が重複しなければ、成立


#全ての組み合わせは、
arr=list(itertools.permutations(range(1,N+1), M*2))


#全てのパターンで検証
#成立すればそこで出力
for i in range(len(arr)):
    #チェックリスト初期化
    check_list=[0]*N
    for j in range(M):
        #一人目
        ent1=arr[i][j]
        #二人目
        ent2=arr[i][M*2-j-1]
        #二人の距離は
        dist1=max(ent1,ent2)-min(ent1,ent2)-1
        dist2=N-max(ent1,ent2)+min(ent1,ent2)-1
        #被ってないか評価
        if check_list[dist1]==0:#まだ使われていない距離
            check_list[dist1]=1
        else:
            break
        if check_list[dist2]==0:#まだ使われていない距離
            check_list[dist2]=1
        else:
            break
    else:#全てのMを被り無しで選べたら、出力
        for k in range(M):
            print(str(arr[i][k])+' '+str(arr[i][M*2-k-1]))
        break

### FIXED CODE ###

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

#N人の参加者から、M組選ぶ
#これをNセット実施。
#組合わせの距離が重複しなければ、成立


#参加者を半分に分け、
#前半を距離奇数、後半を距離偶数にする

#参加者を半分に分ける
div_point=int((N/2))
#前半グループを奇数にする
if div_point%2==0:
    div_point-=1
#後半グループは更に半分に分ける
re_point=div_point+int((N-div_point)/2)

#組を作る
i=0 #初期化
while 1<div_point-i*2 and i<re_point and i<M:#前半グループ・・・距離が奇数になるように組み分け
    ent1=i+1 #前半グループ：一人目
    ent2=div_point-i #前半グループ：二人目
    print(str(ent1) + ' ' + str(ent2))
    i+=1
for j in range(M-i):#後半グループ
    ent1=re_point-j #後半グループ：一人目
    ent2=re_point+j+1 #後半グループ：二人目
    print(str(ent1) + ' ' + str(ent2))
### BUGGY CODE ###

import sys


def fusion(xs):
    if len(xs) < 2:
        yield from xs
    elif xs[0] == xs[1]:
        yield from fusion(xs[1:])
    else:
        yield xs[0]
        yield from fusion(xs[1:])


def main():
    sys.setrecursionlimit(101010)
    N = input()
    S = input()
    print(sum(1 for _ in fusion(S)))


if __name__ == "__main__":
    main()


### FIXED CODE ###

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

count = 1
for i in range(N - 1):
    if S[i] != S[i + 1]:
        count += 1

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

N, K = map(int, input().split())
x = list(map(int, input().split()))
m = 10000000000000
for i in range(N-K+1):
  X = x[i:i+K]
  if X[0]*X[K-1] <= 0: # 区間に0を含む時
    m = min(m, 2*abs(X[0])+X[K-1], abs(X[0])+2*X[K-1])
  elif X[0]>0:
    m = min(m, X[K-1])
  else:
    m = min(m, abs(X[0]))
print(m)

### FIXED CODE ###

N, K = map(int, input().split())
x = list(map(int, input().split()))
m = 10000000000000
for i in range(N-K+1):
  x1 = x[i]
  xk = x[i+K-1]
  if x1*xk <= 0: # 区間に0を含む時
    m = min(m, 2*abs(x1)+xk, abs(x1)+2*xk)
  elif x1>0:
    m = min(m, xk)
  else:
    m = min(m, abs(x1))
print(m)
### BUGGY CODE ###

import sys
input = sys.stdin.readline


class UnionFind():
    def __init__(self, n):
        self.parent = [-1 for _ in range(n)]

    def size(self, x):
        return -self.parent[self.find(x)]

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

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if (x == y):
            return False
        if (self.size(x) < self.size(y)):
            self.parent[y] += self.parent[x]
            self.parent[x] = y
        else:
            self.parent[x] += self.parent[y]
            self.parent[y] = x
        return True

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


def main():
    N = int(input())
    x_list = []
    y_list = []
    x_app = x_list.append
    y_app = y_list.append
    for i in range(N):
        x, y = (int(x) for x in input().split())
        x_app([x, i])
        y_app([y, i])

    x_list.sort()
    y_list.sort()
    adj = []
    adj_app = adj.append
    for i in range(N-1):
        adj_app([x_list[i + 1][0] - x_list[i][0], x_list[i + 1][1], x_list[i][1]])
        adj_app([y_list[i + 1][0] - y_list[i][0], y_list[i + 1][1], y_list[i][1]])

    adj.sort()
    uf = UnionFind(N)
    ans = 0
    for edge in adj:
        if not uf.same(edge[1], edge[2]):
            ans += edge[0]
            uf.unite(edge[1], edge[2])
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

# 6199094

import array
import sys
input = sys.stdin.readline

class UnionFind():
    def __init__(self,n):
        self.parent = [-1 for _ in range(n)]

    def size(self,x):
        return -self.parent[self.find(x)]

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

    def unite(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if(x == y):
            return False
        if(self.size(x)<self.size(y)):
            self.parent[y]+=self.parent[x]
            self.parent[x]=y
        else:
            self.parent[x]+=self.parent[y]
            self.parent[y]=x
        return True

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

def main():
    N = int(input())
    xli = []
    yli = []
    x_app = xli.append
    y_app = yli.append


    for i in range(N):
        x,y = (int(x) for x in input().split())
        x_app([x-1,i])
        y_app([y-1,i])
    xli.sort()
    yli.sort()

    edges = []
    edges_app = edges.append
    for i in range(N-1):
        edges_app((xli[i][1],xli[i+1][1],xli[i+1][0]-xli[i][0]))
        edges_app((yli[i][1],yli[i+1][1],yli[i+1][0]-yli[i][0]))


    edges.sort(key=lambda edge: edge[2])
    uf = UnionFind(N)
    weight = 0

    for edge in edges:
        if not uf.same(edge[0], edge[1]):
            uf.unite(edge[0], edge[1])
            weight+=edge[2]
    print(weight)

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

import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, k = map(int, input().split())
a=list(map(int, input().split()))
a.sort()
mod=10**9+7
min=0
max=0
for i in range(n-k+1):

    min+=a[i]*(combinations_count(n-i-1,k-1)%mod)
    max+=a[n-1-i]*(combinations_count(n-i-1,k-1)%mod)
    min%=mod
    max%=mod

ans=max-min


print(ans%mod)

### FIXED CODE ###

def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r=min(r,n-r)

    return g1[n] * g2[r] * g2[n - r] % mod


mod = 10 ** 9 + 7  # 出力の制限
N = 10 ** 5
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
mod =10**9+7
mi = 0
ma = 0
for i in range(n - k + 1):
    x = cmb(n - i - 1, k - 1, mod)
    mi += a[i] * x
    ma += a[n - 1 - i] * x
    mi %= mod
    ma %= mod

ans = ma - mi

print(ans % mod)
### BUGGY CODE ###

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

excess = []
shortage = []

ans = 0

for i in range(n):
    if a[i] >= b[i]:
        excess.append(a[i] - b[i])
    else:
        shortage.append(b[i] - a[i])

ans = len(shortage)

if sum(excess) < sum(shortage):
    print(-1)
elif len(shortage) == 0:
    print(0)
else:
    excess.sort(reverse=True)
    excess_num = 0
    for i in range(n):
        excess_num += excess[i]
        ans += 1
        if excess_num >= sum(shortage):
            print(ans)
            exit()

### FIXED CODE ###

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

excess = []
shortage = []

ans = 0

for i in range(n):
    if a[i] >= b[i]:
        excess.append(a[i] - b[i])
    else:
        shortage.append(b[i] - a[i])

ans = len(shortage)

if sum(excess) < sum(shortage):
    print(-1)
elif len(shortage) == 0:
    print(0)
else:
    excess.sort(reverse=True)
    excess_num = 0
    shortage_num = sum(shortage)
    for i in range(n):
        excess_num += excess[i]
        ans += 1
        if excess_num >= shortage_num:
            print(ans)
            exit()