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

"""
keyword: 二項係数

与えられた文字列sの最後の文字以降は何を置いても(26通り)良い一方で、最後の文字より前は同じ文字は置けない(25通り)
そこで最後の文字より後と前で分けて場合の数を考える


"""

import sys
sys.setrecursionlimit(10**6)

k = int(input())
s = input()

mod = 10**9+7

n = len(s)
fact = [1, 1] # あとでnの階乗を求める初期値　[0!, 1!]

# n!を求める
for i in range(2, 2*(10**6)+1):
    fact.append(fact[-1]*i % mod)

# 二項係数nCrを求める nCr = n!/r!(n-r)!
def nCr(n, r, mod=10**9+7):
    return pow(fact[n-r]*fact[r] % mod, mod-2, mod)*fact[n] % mod # modの世界では逆元はpow(x,mod-2)をかけることと同じ

ans = 0
#for i in range(k+1):
#    ans = (ans+nCr(n+k, i)*pow(25, i, mod)) % mod
#print(ans)

for i in range(k+1):
    now = 26**(k-i) % mod
    now *= 25**i % mod
    now *= nCr(i+n-1, n-1) % mod
    ans += now % mod
print(ans)

### FIXED CODE ###

"""
keyword: 二項係数

与えられた文字列sの最後の文字以降は何を置いても(26通り)良い一方で、最後の文字より前は同じ文字は置けない(25通り)
そこで最後の文字より後と前で分けて場合の数を考える


"""

import sys
sys.setrecursionlimit(10**6)

k = int(input())
s = input()

mod = 10**9+7

n = len(s)
fact = [1, 1] # あとでnの階乗を求める初期値　[0!, 1!]

# n!を求める
for i in range(2, 2*(10**6)+1):
    fact.append(fact[-1]*i % mod)

# 二項係数nCrを求める nCr = n!/r!(n-r)!
def nCr(n, r, mod=10**9+7):
    return pow(fact[n-r]*fact[r] % mod, mod-2, mod)*fact[n] % mod # modの世界では逆元はpow(x,mod-2)をかけることと同じ

ans = 0
#for i in range(k+1):
#    ans = (ans+nCr(n+k, i)*pow(25, i, mod)) % mod
#print(ans)

for i in range(k+1):
    now = pow(26, k-i, mod) * pow(25, i, mod) * nCr(i+n-1, n-1)
    ans = (ans+now) % mod
print(ans)
### BUGGY CODE ###

n,m=map(int,input().split())
s=list(str(input()))
f=0
mf=0
for i in range(n+1):
    if s[i]=='1':
        f+=1
        mf=max(mf,f)
    else:
        f=0
if mf>=m:
    print(-1)
    exit()
reans=[]
s.reverse()
nk=-1
while nk<n+1:
    for i in range(min(n-nk,m),0,-1):
        if s[nk+i]=='0':
            nk=nk+i
            reans.append(i)
            break
reans.reverse()
print(*reans)
        


### FIXED CODE ###

n,m=map(int,input().split())
s=list(str(input()))
f=0
mf=0
for i in range(n+1):
    if s[i]=='1':
        f+=1
        mf=max(mf,f)
    else:
        f=0
if mf>=m:
    print(-1)
    exit()
reans=[]
s.reverse()
nk=0
while nk<n:
    for i in range(min(n-nk,m),0,-1):
        if s[nk+i]=='0':
            nk=nk+i
            reans.append(i)
            break
reans.reverse()
print(*reans)
### BUGGY CODE ###

n,k=map(int,input().split())
x,y=[[0,0] for i in range(n)],[[0,0] for i in range(n)]
xy=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
    x_sub,y_sub=xy[i]
    x[i][0]=x_sub
    x[i][1]=i
    y[i][0]=y_sub
    y[i][1]=i
x.sort(key=lambda z:z[0])
y.sort(key=lambda z:z[0])
ans=(10**18)*5
for i1 in range(n):
    for l1 in range(n-i1,0,-1):
        for i2 in range(n):
            for l2 in range(n-i2,0,-1):
                if l1*l2<k:
                    break
                z=[0]*n
                for i in range(i1,i1+l1):
                    l=x[i][1]
                    z[l]=1
                for i in range(i2,i2+l2):
                    l=y[i][1]
                    z[l]=1
                if sum(z)>=k:
                    x_sub1,y_sub1=10**9+1,10**9+1
                    x_sub2,y_sub2=-10**9-1,-10**9-1
                    for i in range(n):
                        if z[i]==1:
                            x_sub1=min(xy[i][0],x_sub1)
                            x_sub2=max(xy[i][0],x_sub2)
                            y_sub1=min(xy[i][1],y_sub1)
                            y_sub2=max(xy[i][1],y_sub2)
                    ans=min((x_sub2-x_sub1)*(y_sub2-y_sub1),ans)
                else:
                    break
print(ans)


### FIXED CODE ###

n,k=map(int,input().split())
x,y=[[0,0] for i in range(n)],[[0,0] for i in range(n)]
xy=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
    x_sub,y_sub=xy[i]
    x[i][0]=x_sub
    x[i][1]=i
    y[i][0]=y_sub
    y[i][1]=i
x.sort()
y.sort()
ans=(10**18)*5
for i1 in range(n):
    for l1 in range(n-i1,1,-1):
        for i2 in range(n):
            for l2 in range(n-i2,1,-1):
                x_sub1=x[i1][0]
                x_sub2=x[i1+l1-1][0]
                y_sub1=y[i2][0]
                y_sub2=y[i2+l2-1][0]
                z=[0]*n
                for i in range(n):
                    if x_sub1<=xy[i][0]<=x_sub2 and y_sub1<=xy[i][1]<=y_sub2:
                        z[i]=1
                if sum(z)>=k:
                    ans=min((x_sub2-x_sub1)*(y_sub2-y_sub1),ans)
                else:
                    break
print(ans)
### BUGGY CODE ###

_ = int(input())
a = [int(i) for i in input().split()]

isOverflow = False

mul = 1
for ai in a:
    mul *= ai

print(-1 if mul > 1000000000000000000 else mul)

### FIXED CODE ###

def main():
    _ = int(input())
    a = [int(i) for i in input().split()]

    if 0 in a:
        print(0)
        return

    mul = 1
    for ai in a:
        mul *= ai
        if mul > 1000000000000000000:
            print(-1)
            return

    print(mul)

main()
### BUGGY CODE ###

import sys
from collections import Counter
n, m = [int(i) for i in sys.stdin.readline().split()]
a_ls = [int(i) for i in sys.stdin.readline().split()]
ct = Counter(a_ls)
for j in range(m):
    b, c = [int(i) for i in sys.stdin.readline().split()]
    if ct.get(c) is None:
        ct[c] = 0
    a_ls += [c] * b
    ct[c] += b
a_ls.sort()
print(sum(a_ls[-n:]))

### FIXED CODE ###

import sys
from collections import Counter
n, m = [int(i) for i in sys.stdin.readline().split()]
a_ls = [int(i) for i in sys.stdin.readline().split()]
ct = Counter(a_ls)
ls = []
for j in range(m):
    b, c = [int(i) for i in sys.stdin.readline().split()]
    if ct.get(c) is None:
        ct[c] = 0
    ls.append((b, c))
    ct[c] += b
ls.sort(key=lambda x:x[1], reverse=True)
cnt = 0
for b, c in ls:
    if cnt + b < n:
        a_ls += [c] * b
        cnt += b
    else:
        a_ls += [c] * (n - cnt)
        break
a_ls.sort()
print(sum(a_ls[-n:]))
### BUGGY CODE ###

#editorial
n,k=map(int,input().split())
*lr,=[tuple(map(int, input().split())) for _ in range(k)]
res =[0]*(2*n+3)
##############
diff=[0]*(2*n+3)
######
#res[0]=1

diff[0]=1
diff[1]=-1
mod=998244353

for i in range(n+1):
    res[i]=res[i-1]+diff[i]
    for li,ri in lr:
        diff[i+li]+=res[i]
        diff[i+ri+1]-=res[i]
    #print(res[:n+1])
    #print((diff[:n+1]))
print(res[n-1]%mod)
#print(res[:n+1])
#print((diff[:n+1]))
    

### FIXED CODE ###

#editorial
n,k=map(int,input().split())
*lr,=[tuple(map(int, input().split())) for _ in range(k)]
res =[0]*(2*n+3)
##############
diff=[0]*(2*n+3)
######
#res[0]=1

diff[0]=1
diff[1]=-1
mod=998244353

for i in range(n+1):
    res[i]=res[i-1]+diff[i]
    res[i]%=mod
    diff[i]%=mod
    for li,ri in lr:
        diff[i+li]+=res[i]
        diff[i+ri+1]-=res[i]
    #print(res[:n+1])
    #print((diff[:n+1]))
print(res[n-1]%mod)
#print(res[:n+1])
#print((diff[:n+1]))
### BUGGY CODE ###

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

from collections import defaultdict
dp = defaultdict(lambda : -1)

def dfs(tpl):
    if dp[tpl] != -1:
        return dp[tpl]
    if len(tpl) == 0:
        return 0
    if len(tpl) == 1:
        dp[tpl] = tpl[0]
        return tpl[0]

    lst_candidates = []
    now_cost = []
    for i in range(len(tpl)-1):
        # print("i: ", i )
        lst_candidates.append (   tpl[0:i] + ( tpl[i]+tpl[i+1], )  + tpl[i+2: ]   )
        now_cost.append ( tpl[i] + tpl[i+1] ) 

    total_cost = []
    for i in range(len(now_cost)):
        total_cost.append ( now_cost [i] + dfs(lst_candidates[i]))

    # print("totla_cost: ", total_cost)
    # print("lst_candidates: ", lst_candidates)
    res = min(total_cost)
    dp[tpl] = res

    return res

print(dfs(A) - sum(A))

### FIXED CODE ###

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

from itertools import accumulate
Accum = list(accumulate([0] + A))

dp = [ [inf]*(N+1) for _ in range(N+1)]

def dfs(l,r):
    if dp[l][r] != inf:
        return dp[l][r]
    if l == r: 
        return 0
    if l+1 == r: 
        dp[l][r] = A[l]
        return A[l]

    local_ans = inf
    for i in range(l+1, r): # 0 to 4, 0-1, 1-4
        local_ans = min(local_ans, dfs(l,i) + dfs(i,r))
    dp[l][r] = local_ans + Accum[r] - Accum[l]
    return dp[l][r]
print (dfs(0,N)- sum(A))
### BUGGY CODE ###

import sys
 
N, Z, W = map(int, input().split())
A = list(map(int, input().split()))
inf = 10 ** 9 + 7
 
sys.setrecursionlimit(inf)
 
def calc(a, b):
  return abs(a - b)
 
def alphaBeta(X, Y, turn, depth, alpha, beta):
    if depth == N:
        return calc(X, Y)
    if turn:
        for i in range(depth, N):
            alpha = max(alpha, alphaBeta(A[i], Y, False, i+1, alpha, beta))
            if alpha >= beta:
                break
        return alpha
    else:
        for i in range(depth, N):
            beta = min(beta, alphaBeta(X, A[i], True, i+1, alpha, beta))
            if alpha >= beta:
                break
        return beta
 
print(alphaBeta(Z, W, True, 0, -1, inf))

### FIXED CODE ###

import sys

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

ans = abs(A[-1] - W)
if N != 1:
    ans = max(ans, abs(A[-1] - A[-2]))
print(ans)
### BUGGY CODE ###

S = input()
Q = int(input())
Query=[input().split() for q in range(Q)]

for i, q in enumerate(Query):
  if q[0]=='1':
    S=S[::-1]
  else:
    if q[1]=='1':
      S=q[2]+S
    else:
      S=S+q[2]
print(S)


### FIXED CODE ###

def main():
  S = input()
  Q = int(input())
  Query=[input().split() for q in range(Q)]
  cnt=0
  prefix, suffix = '', ''
  for q in Query:
    if q[0]=='1':
      cnt=1^cnt
      prefix, suffix = suffix, prefix
      #print(cnt)
    else:
      if q[1]=='1':
        prefix=prefix+q[2]
      else:
        suffix=suffix+q[2]
  if cnt:
    S=S[::-1]
  print(prefix[::-1]+S+suffix)

main()
### BUGGY CODE ###

from collections import defaultdict, deque

N, M, K = map(int, input().split())
# F = [list(map(int, input().split())) for _ in range(M)]
# B = [list(map(int, input().split())) for _ in range(K)]

F = defaultdict(set)
for _ in range(M):
    u, v = map(int, input().split())
    F[u].add(v)
    F[v].add(u)
B = defaultdict(set)
for _ in range(K):
    u, v = map(int, input().split())
    B[u].add(v)
    B[v].add(u)

VV = defaultdict(set)
res = [0]*N
for i in range(N):
    cand = 0
    visited = [0]*N
    q = deque()
    q.append((i+1, 0))
    visited[i] = 1

    while q:
        curNode, lv = q.popleft()
        for node in F[curNode]:
            if visited[node-1] == 0 and i+1 not in VV[node-1]:
                visited[node-1] = 1
                q.append((node, lv+1))
                if lv >= 1 and i+1 not in B[node]:
                    cand += 1
                    res[i] += 1
                    VV[node-1].add(i+1)

print(' '.join(map(str, res)))


### FIXED CODE ###

from collections import defaultdict

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

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

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

    def get_group_size(self, x):
        return -self.parents[self.find(x)]

N, M, K = map(int, input().split())
uf = UnionFind(N)

friends = defaultdict(set)
for _ in range(M):
    u, v = map(lambda x: int(x)-1, input().split())
    friends[u].add(v)
    friends[v].add(u)
    uf.union(u, v)
blocks = [0]*N
for _ in range(K):
    u, v = map(lambda x: int(x)-1, input().split())
    if uf.is_same_root(u, v):
        blocks[u] += 1
        blocks[v] += 1

res = [uf.get_group_size(i)-len(friends[i])-blocks[i]-1 for i in range(N)]
print(' '.join(map(str, res)))
### BUGGY CODE ###

n=int(input())
segSize=n+1
def init_max(init_max_val):
    for i in range(segSize):
        seg_max[i+num_max-1]=init_max_val[i]
    for i in range(num_max-2,-1,-1) :
        seg_max[i]=max(seg_max[2*i+1],seg_max[2*i+2]) 
    
def update_max(k,x):
    k += num_max-1
    seg_max[k] = x
    while k:
        k = (k-1)//2
        seg_max[k] = max(seg_max[k*2+1],seg_max[k*2+2])
    
def query_max(p,q):
    if q<=p:
        return ide_ele_max
    p += num_max-1
    q += num_max-2
    res=ide_ele_max
    while q-p>1:
        if p&1 == 0:
            res = max(res,seg_max[p])
        if q&1 == 1:
            res = max(res,seg_max[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = max(res,seg_max[p])
    else:
        res = max(max(res,seg_max[p]),seg_max[q])
    return res

from array import *
ide_ele_max = 0
num_max =2**(segSize-1).bit_length()
seg_max=[ide_ele_max]*2*num_max
seg_max=array("i",seg_max)
mod=998244353


XD=[tuple(map(int,input().split()))for i in range(n)]
XD.sort()
X=[x for x,d in XD]
X.append(XD[-1][0])
X=array("i",X)

import bisect

init_max(list(range(segSize)))
update_max(n,n)
combs=[1]*(n+2)
t=0
for x,d in XD[::-1]:
    idx=n-1-t
    t+=1
    p=bisect.bisect_right(X,x+d-1)
    p=query_max(idx,p)
    update_max(idx,p)
    combs[idx]=(combs[p+1]+combs[idx+1])%mod
print(combs[0])

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

n=int(readline())
segSize=n+1
def init_max(init_max_val):
    for i in range(segSize):
        seg_max[i+num_max-1]=init_max_val[i]
    for i in range(num_max-2,-1,-1) :
        seg_max[i]=max(seg_max[2*i+1],seg_max[2*i+2]) 
    
def update_max(k,x):
    k += num_max-1
    seg_max[k] = x
    while k:
        k = (k-1)//2
        seg_max[k] = max(seg_max[k*2+1],seg_max[k*2+2])
    
def query_max(p,q):
    if q<=p:
        return ide_ele_max
    p += num_max-1
    q += num_max-2
    res=ide_ele_max
    while q-p>1:
        if p&1 == 0:
            res = max(res,seg_max[p])
        if q&1 == 1:
            res = max(res,seg_max[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = max(res,seg_max[p])
    else:
        res = max(max(res,seg_max[p]),seg_max[q])
    return res
ide_ele_max = 0
num_max =2**(segSize-1).bit_length()
seg_max=[ide_ele_max]*2*num_max
mod=998244353

m = map(int,read().split())
XD = sorted(zip(m,m))
X=[x for x,d in XD]

from bisect import bisect_right
X=[bisect_right(X,x+d-1)for x,d in XD]

init_max(list(range(segSize)))
update_max(n,n)
combs=[1]*(n+1)
t=0
for x,d in reversed(XD):
    idx=n-1-t
    t+=1
    p=X[idx]
    p=query_max(idx,p)
    update_max(idx,p)
    combs[idx]=(combs[p+1]+combs[idx+1])%mod
print(combs[0])
### BUGGY CODE ###

x=int(input())
y=list(map(int, input().split()))
z=1
for i in range(x):
  z = z*y[i]
if z > 10**18:
  print(-1)
else:
  print(z)

### FIXED CODE ###

x=int(input())
y=list(map(int, input().split()))
z=1
if 0 in y:
  print(0)
  exit()

for i in range(x):
  z = z*y[i]
  if z > 10**18:
    z=-1
    break
print(z)
### BUGGY CODE ###

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

### FIXED CODE ###

import math
  
def main():
  k=int(input())
  cur=0
  for a in range(1,k+1):
    for b in range(1,k+1):
      for c in range(1,k+1):
        cur+=math.gcd(math.gcd(a,b),c)
        
  return cur
print(main())
### BUGGY CODE ###

from numba import njit
import numpy as np


def main(N, P):
    lista = [1, -1, N, -N]
    d = np.zeros((N, N), dtype=np.int32)
    d = d.ravel()
    sit = np.ones_like(d)
    stack = np.empty_like(d)
    count = 0
    for i in range(N*N):
        d[i] = min(i % N, (N-1-i) % N, i//N, N-1-i//N)
    for player in P:
        sit[player-1] = 0
        count += d[player-1]
        stack[0] = player
        num = 0
        while num >= 0:
            p = stack[num]
            num -= 1
            a = d[p-1]+sit[p-1]
            for i in lista:
                if p+i < 1 or p + i > N*N:
                    continue
                if d[p+i-1] > a:
                    d[p+i-1] = a
                    num += 1
                    stack[num] = p+i
    print(count)


def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('main', '(i8,i8[:])')(main)
    cc.compile()


if __name__ == '__main__':
    import sys
    if sys.argv[-1] == 'ONLINE_JUDGE':
        cc_export()
        exit(0)
    #from my_module import main
    N = int(input())
    P = np.array(input().split(), np.int32)
    #N = 500
    #P = [(i+4030) % N*N for i in range(N*N)]
    main(N, P)


### FIXED CODE ###

from numba import njit
import numpy as np

@njit
def main(N, P):
    lista = [1, -1, N, -N]
    d = np.zeros((N, N), dtype=np.int32)
    d = d.ravel()
    sit = np.ones_like(d)
    stack = np.empty_like(d)
    count = 0
    for i in range(N*N):
        d[i] = min(i % N, (N-1-i) % N, i//N, N-1-i//N)
    for player in P:
        sit[player-1] = 0
        count += d[player-1]
        stack[0] = player
        num = 0
        while num >= 0:
            p = stack[num]
            num -= 1
            a = d[p-1]+sit[p-1]
            for i in lista:
                if p+i < 1 or p + i > N*N:
                    continue
                if d[p+i-1] > a:
                    d[p+i-1] = a
                    num += 1
                    stack[num] = p+i
    print(count)

N = int(input())
P = np.array(input().split(), np.int32)

main(N, P)
### BUGGY CODE ###

K = int(input())
INF = float('inf')
D = [-1]*K
C = [1]*K
D[1] = 0
while C[0]:
    m = min(filter(lambda x:C[x] and D[x] != -1,range(K)),key=lambda x:D[x])
    j = (10*m)%K
    D[j] = D[m] if D[j]==-1 else min(D[j],D[m])
    l = (m+1)%K
    D[l] = D[m]+1 if D[l]==-1 else min(D[l],D[m]+1)
    C[m] = 0

print(D[0]+1)

### FIXED CODE ###

from collections import deque

K = int(input())
D = [-1]*K
Q = deque()
Q.append([1,0])
while D[0] == -1:
    k,v = Q.popleft()
    D[k] = v
    j = (k*10)%K
    if D[j] == -1:
        Q.appendleft([j,v])
    l = (k+1)%K
    if D[l] == -1:
        Q.append([l,v+1])

print(D[0]+1)
### BUGGY CODE ###

n, a, b, c = map(int, input().split())
mod = 10 ** 9 + 7
def comb(n, r):
    if n < r:return 0
    if n < 0 or r < 0:return 0
    return fa[n] * fi[r] % mod * fi[n - r] % mod
fa = [1] * (2 * n + 2)
fi = [1] * (2 * n + 2)
for i in range(1, 2 * n + 2):
    fa[i] = fa[i - 1] * i % mod
    fi[i] = pow(fa[i], mod - 2, mod)
ans = 0
for i in range(n):
    ans += (comb(n + i - 1, i) * (pow(a * pow(a + b, mod - 2, mod), n, mod) * pow(b * pow(a + b, mod - 2, mod), i, mod) + pow(b * pow(a + b, mod - 2, mod), n, mod) * pow(a * pow(a + b, mod - 2, mod), i, mod)) * (n + i)) % mod
    ans %= mod
print(ans * 100 * pow(100 - c, mod - 2, mod) % mod)

### FIXED CODE ###

n, a, b, c = map(int, input().split())
mod = 10 ** 9 + 7
def comb(n, r):
    if n < r:return 0
    if n < 0 or r < 0:return 0
    return fa[n] * fi[r] % mod * fi[n - r] % mod
fa = [1] * (2 * n + 2)
fi = [1] * (2 * n + 2)
for i in range(1, 2 * n + 2):
    fa[i] = fa[i - 1] * i % mod
    fi[i] = pow(fa[i], mod - 2, mod)
ans = 0
for i in range(n):
    ans += (comb(n + i - 1, i) * (pow(a * pow(a + b, mod - 2, mod), n, mod) * pow(b * pow(a + b, mod - 2, mod), i, mod) + pow(b * pow(a + b, mod - 2, mod), n, mod) * pow(a * pow(a + b, mod - 2, mod), i, mod)) * (n + i)) % mod
    ans %= mod
print(ans * 100 * pow(100 - c, mod - 2, mod) % mod)
### BUGGY CODE ###

n=int(input())
a=list(map(int, input().split()))
nagasa=len(a)
count=0
for i in range(1,n+1):
    for j in range (nagasa):
        if a[j] == i:
            count += 1
    else:
        print(count)
        count = 0

### FIXED CODE ###

import collections
n=int(input())
a=list(map(int, input().split()))
ct=collections.Counter(a)
for i in range(n):
    print(ct[i+1])
### BUGGY CODE ###

# -*- coding: utf-8 -*-
H, N = map(int, input().split())
A_list = []
B_list = []
for i in range(N):
    A, B = map(int, input().split())
    A_list.append(A)
    B_list.append(B)

dp = [10 ** 9 for _ in range(H + 1)]
dp[0] = 0

for i in range(1, H + 1):
    min_ij = 10 ** 9
    for j in range(N):
        A = A_list[j]
        B = B_list[j]
        min_ij = min(min_ij, (dp[i - A] if i >= A else 0) + B)
    dp[i] = min(dp[i], min_ij)

print(dp[-1])

### FIXED CODE ###

# E
# -*- coding: utf-8 -*-
H, N = map(int, input().split())
A_list = []
B_list = []
for i in range(N):
    A, B = map(int, input().split())
    A_list.append(A)
    B_list.append(B)

dp = [0 for _ in range(H + 1)]
dp[0] = 0

def test_func(dp, A_list, B_list, i, N):
    return(min([(dp[i - A_list[j]] if i >= A_list[j] else 0) + B_list[j] for j in range(N)]))


for i in range(1, H + 1):
    dp[i] = test_func(dp, A_list, B_list, i, N)

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

S=input()
MOD=10**9+7
dp=[]
for _ in range(len(S)):
    dp.append([0]*13)
if S[0]=='?':
    for i in range(10):
        dp[0][(i*10**(len(S)-1))%13]=1
else:
    dp[0][(int(S[0])*10**(len(S)-1))%13]=1
for j in range(0,len(S)-1):
    for k in range(13):
        if S[j+1]=='?':
            L=[]
            for l in range(10):
                l=(l*10**(len(S)-j-2)%13)
                L.append(dp[j][k-l]%MOD)
            dp[j+1][k]+=sum(L)%(7+10**9)
        else:
            dp[j+1][k]=dp[j][k-(int(S[j+1]))*10**(len(S)-j-2)%13]
print((dp[len(S)-1][5])%(7+10**9))


### FIXED CODE ###

def main():
    MOD = 7 + 10**9
    S = tuple(input())
    N = len(S)
    dp = [[0]*13 for _ in range(N+1)]
    dp[0][0] += 1
    s=[1]
    for n in range(1,N):
        s.append((s[n-1]*10)%13)
    for i in range(N):
        for k in range(13):
            if S[-(i+1)] != '?':
                dp[i+1][(k+int(S[-(i+1)])*s[i])%13] += dp[i][k] 
                dp[i+1][(k+int(S[-(i+1)])*s[i])%13] %= MOD
            else:
                for l in range(10):
                    dp[i+1][(k+l*s[i])%13] += dp[i][k]
                    dp[i+1][(k+l*s[i])%13] %= MOD
    print(dp[-1][5])

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

from itertools import accumulate
n,m = [int(a) for a in input().strip().split(' ')]
As = accumulate([int(a)%m for a in input().strip().split(' ')])
As = [0] + [i%m for i in As]

def isok(i,j):
    di = As[j] - As[i-1]
    if di % m == 0:
        return True
    return False


counter = 0
for i in range(n):
    for j in range(i, n):
        di = As[j+1] - As[i]
        if di % m == 0:
            counter += 1
print(counter)


### FIXED CODE ###

from itertools import accumulate
n,m = [int(a) for a in input().strip().split(' ')]
As = accumulate([int(a)%m for a in input().strip().split(' ')])
As = [0] + [i%m for i in As]
As = sorted(As)
count = 0
ba = None
Bs = []
for a in As:
    if a == ba:
        count += 1
    elif ba != None:
        Bs.append(count*(count+1))
        count = 0
    ba = a
if count != 0:
    Bs.append(count*(count+1))
print(int(sum(Bs)/2))
### BUGGY CODE ###

from math import gcd
from itertools import product
N = int(input())
List = list(product(list(range(1,N+1)),repeat = 3))
NewList= []
for i in range(len(List)):
    Number = gcd(List[i][0], gcd(List[i][1], List[i][2]))
    NewList.append(Number)
print(sum(NewList))


### FIXED CODE ###

from math import gcd

N = int(input())
answer = 0
for a in range(1, N+1):
    for b in range(1, N+1):
        for c in range(1, N+1):
            answer += gcd(gcd(a, b), c)
print(answer)