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


N = int(input())
p = 1

for i in range(1, N+1):
    p *= i

print(p % 1000000007)


### FIXED CODE ###


N = int(input())
p = 1

for i in range(1, N+1):
    p *= i
    p = p % (10**9+7)

print(p)
### BUGGY CODE ###

# import bisect
from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    N=int(input())
    S=list(input())
    ans=10**10
    for i in range(N):
        ans=min(S[:i].count('W')+S[i+1:].count('E'),ans)
    print(ans)


resolve()

### FIXED CODE ###

# import bisect
from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    N=int(input())
    S=list(input())
    from itertools import accumulate

    W=[0]*N
    E=[0]*N
    for i in range(N):
        if S[i]=='W':
            W[i]=1
        else:
            E[i]=1
    WW=[0]+W
    EE=[0]+E

    from itertools import accumulate

    WW = list(accumulate(WW))
    EE=list(accumulate(EE))# 累積和を格納したリスト作成


    # この問題は長さが1-Nの連続部分の和の最大値を出せというものなので以下の通り
    ans=10**10
    for i in range(1, N + 1):
        ans = min(WW[i-1]+EE[N]-EE[i],ans)
    print(ans)



resolve()
### BUGGY CODE ###

x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sorted(list(map(int, input().split())), reverse = True)

list = []
for i in range(x):
    for j in range(y):
        list.append(a[i]+b[j])
list = sorted(list, reverse = True)[:k]

list1 = []
for i in range(len(list)):
    for j in range(z):
        list1.append(list[i]+c[j])
list1 = sorted(list1, reverse = True)

for i in range(k):
    print(list1[i])

### FIXED CODE ###

x, y, z, k = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse = True)
b = sorted(list(map(int, input().split())), reverse = True)
c = sorted(list(map(int, input().split())), reverse = True)

list = []
for aa in a:
    for bb in b:
        list.append(aa+bb)
list.sort(reverse = True)
list = list[:k]

list1 = []
for ab in list:
    for cc in c:
        list1.append(ab+cc)
list1.sort(reverse = True)
list1 = list1[:k]

for i in range(k):
    print(list1[i])
### BUGGY CODE ###

import math
def comb(n,r):
  if r>n: return 0
  else: return int(math.factorial(n)/(math.factorial(r)*math.factorial(n-r)))

N,P=map(int,input().split())
A=list(map(int,input().split()))
odd=0
even=0
a=0
for i in range(N):
  if A[i]%2==0: even+=1
  else: odd+=1
  a+=A[i]
if (a-P)%2==0: flag=0
else: flag=1
n=2**even

ans=0
if flag==0:#evenの場合
  for i in range(odd//2+1):
    ans+=comb(odd,2*i)
else:#oddの場合
  for i in range(2*(n+1)//2+1):
    ans+=comb(odd,1+2*i)
print(ans*n)

### FIXED CODE ###

N,P=map(int,input().split())
A=list(map(int,input().split()))
odd=0
for i in range(N):
  if A[i]%2==1: odd+=1
if odd==0:
  if P==1: print(0)
  else: print(2**N)
else:
  print(2**(N-1))
### BUGGY CODE ###

def my_index(l, x):
    return [i for i, _x in enumerate(l) if _x == x]

H,W,M=map(int,input().split())
P=list()
P_X=[0]*(H+1)
P_Y=[0]*(W+1)
for _ in range(M):
    P.append(list(map(int,input().split())))
for m in range(M):
    P_X[P[m][0]]+=1
    P_Y[P[m][1]]+=1
Max_X=max(P_X)
Max_Y=max(P_Y)
max_X=my_index(P_X,Max_X)
max_Y=my_index(P_Y,Max_Y)
m_count=0
for k in range(M):
    if P[k][0] in max_X and P[k][1] in max_Y:
        m_count += 1
if m_count==len(max_X)*len(max_Y):
    answer=Max_X+Max_Y-1
else:
     answer=Max_X+Max_Y
    
print(answer)

### FIXED CODE ###


def my_index(l, x):
    return [i for i, _x in enumerate(l) if _x == x]

H,W,M=map(int,input().split())
P=list()
P_X=[0]*(H+1)
P_Y=[0]*(W+1)
for m  in range(M):
    P.append(list(map(int,input().split())))
    P_X[P[m][0]]+=1
    P_Y[P[m][1]]+=1
Max_X=max(P_X)
Max_Y=max(P_Y)
max_X=my_index(P_X,Max_X)
max_Y=my_index(P_Y,Max_Y)
m_count=0
for k in P:
    if  P_X[k[0]] == Max_X and P_Y[k [1]] == Max_Y:
        m_count += 1
if m_count==len(max_X)*len(max_Y):
    answer=Max_X+Max_Y-1
else:
     answer=Max_X+Max_Y
    
print(answer)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, p: "List[float]"):
    #dp[i][j]: i枚投げて、j枚表の確率
    dp=[[0]*(N+1) for _ in range(N+1)]

    dp[0][0]=1

    # dp[1][0]=dp[0][0]*p[1]
    # dp[1][1]=dp[0][0]*(1-p[1])

    # dp[2][0]=dp[1][0]*p[2]
    # dp[2][1]=dp[1][0]*(1-p[2])
    # dp[2][1]+=dp[1][1]*p[2]
    # dp[2][2]=dp[1][2]*(1-p[2])
    for i in range(1,N+1):
        for j in range(i):
            dp[i][j]+=dp[i-1][j]*p[i-1]
            dp[i][j+1]+=dp[i-1][j]*(1-p[i-1])
            #print("#",i,j,dp)

    ans=0
    for j in range(-(-N//2)):
        ans+=dp[N][j]

    print(ans)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    p = [float(next(tokens)) for _ in range(N)]  # type: "List[float]"
    solve(N, p)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

def solve(N: int, p: "List[float]"):
    #dp[i][j]: i枚投げて、j枚表の確率
    dp=[[0]*(N+1) for _ in range(N+1)]

    dp[0][0]=1

    # dp[1][0]=dp[0][0]*p[1]
    # dp[1][1]=dp[0][0]*(1-p[1])

    # dp[2][0]=dp[1][0]*p[2]
    # dp[2][1]=dp[1][0]*(1-p[2])
    # dp[2][1]+=dp[1][1]*p[2]
    # dp[2][2]=dp[1][2]*(1-p[2])
    for i in range(1,N+1):
        for j in range(i):
            dp[i][j]+=dp[i-1][j]*p[i-1]
            dp[i][j+1]+=dp[i-1][j]*(1-p[i-1])
            #print("#",i,j,dp)

    ans=0
    for j in range(-(-N//2)):
        ans+=dp[N][j]

    print(ans)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    p = [float(next(tokens)) for _ in range(N)]  # type: "List[float]"
    solve(N, p)

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

import sys
input = sys.stdin.readline

def calc():
    n = int(input())
    a = [int(x) for x in input().split()]
    cnt = 0
    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            if a[i] % a[j] == 0:
                break
        else:
            cnt += 1
    print(cnt)

calc()

### FIXED CODE ###

import sys
input = sys.stdin.readline

n = int(input())
a = [int(x) for x in input().split()]
maxval = 10 ** 6
factor_cnt = [0] * (maxval+1)
factor_cnt[0] = 2
for i in range(n):
    if factor_cnt[a[i]] > 1:
        continue
    for k in range(a[i], maxval+1, a[i]):
        factor_cnt[k] += 1

result = sum(factor_cnt[v] <= 1 for v in a)
print(result)
### BUGGY CODE ###

from collections import deque
"""
-1 -> not visited
else -> step count
"""
def bfs(maze, visited, sh, sw, gh, gw):
    stack = deque([[sh, sw]])
    visited[sh][sw] = 1
    while stack:
        h, w = stack.popleft()
        # ゴールの条件
        if h == gh and w == gw:
            break
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_h, new_w = h+j, w+k
            if new_h < 0 or new_h >= H or \
               new_w < 0 or new_w >= W:
                continue
            elif maze[new_h][new_w] != "#" and \
                 visited[new_h][new_w] == -1:
                visited[new_h][new_w] = visited[h][w] + 1
                stack.append([new_h, new_w])
    
    return visited[gh][gw]

if __name__ == "__main__":
    H, W = map(int, input().split())
    maze = [input() for _ in range(H)]

    ans = 0
    for sh in range(H):
        for sw in range(W):
            for gh in range(H):
                for gw in range(W):
                    if maze[sh][sw] != "#" and maze[gh][gw] != "#":
                        visited = [[-1] * W for _ in range(H)]
                        step_cnt = bfs(maze, visited, sh, sw, gh, gw)
                        ans = max(ans, step_cnt)

    print(ans - 1)


### FIXED CODE ###

from collections import deque
"""
-1 -> not visited
else -> step count
"""
def bfs(maze, visited, sh, sw):
    stack = deque([[sh, sw]])
    visited[sh][sw] = 1
    longest = 0
    while stack:
        h, w = stack.popleft()
        # # ゴールの条件
        # if h == gh and w == gw:
        #     break
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_h, new_w = h+j, w+k
            if new_h < 0 or new_h >= H or \
                new_w < 0 or new_w >= W:
                    continue
            elif maze[new_h][new_w] != "#" and \
                visited[new_h][new_w] == -1:
                    visited[new_h][new_w] = visited[h][w] + 1
                    longest = max(longest, visited[new_h][new_w])
                    stack.append([new_h, new_w])
    
    # return visited[gh][gw]
    return longest

if __name__ == "__main__":
    H, W = map(int, input().split())
    maze = [input() for _ in range(H)]

    vd = [[[[0 for _ in range(W)] for _ in range(H)] for _ in range(W)] for _ in range(H)]
    ans = 0
    for sh in range(H):
        for sw in range(W):
            if maze[sh][sw] != "#": 
                visited = [[-1] * W for _ in range(H)]
                step_cnt = bfs(maze, visited, sh, sw)
                ans = max(ans, step_cnt)
    print(ans - 1)
### BUGGY CODE ###

s=input()
n=int(input())
for i in range(n):
    q=list(input().split())
    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 ###

s=input()
n=int(input())
r=-1
f=[]
b=[]
for i in range(n):
    q=input().split()
    if q[0]=='1':
        r*=-1
    else:
        t=int(q[1])
        if t*r==-1 or t*r==2 :
            f.append(q[2])
        else:
            b.append(q[2])
f=''.join(f)
b=''.join(b)
s=f[::-1]+s+b
if r==1:
    s=s[::-1]
print(s)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
B = [0]*(max(A))

for i in A:
    B[i-1] += 1

ans = 0
for i in sorted(A):
    if B[i-1] == 0:
        continue
    if B[i-1] == 1:
        ans += 1
    for j in range(i,max(A)+1,i):
        B[j-1] = 0

print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
maxA = max(A)
B = [0]*(maxA)

for i in A:
    B[i-1] += 1

ans = 0
for i in sorted(A):
    if B[i-1] == 0:
        continue
    if B[i-1] == 1:
        ans += 1
    for j in range(i,maxA+1,i):
        B[j-1] = 0

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

line = input().split(" ")
k = int(line[0])
s = int(line[1])
count = 0
for i in range(k+1):
  for j in range(k+1):
    for l in range(k+1):
      if s == i + j + l:
        count += 1
print(count)
        

### FIXED CODE ###

line = input().split(" ")
k = int(line[0])
s = int(line[1])
count = 0
for i in range(k+1):
  for j in range(k+1):
    if s - i - j <= k and s - i - j >= 0:
      count += 1
print(count)
### BUGGY CODE ###

MOD = 998244353

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

DP = [[[0] * 3 for _ in range(S + 1)] for _ in range(N + 1)]
DP[0][0][0] = 1

for i in range(N):
    DP[i + 1][0][0] = DP[i][0][0] 
    a = A[i]
    for j in range(S + 1):
        if j == 0: #左側を決めて合計0になるのは、
            # DP[i + 1][j][0] = DP[i][j][0] 
            DP[i + 1][j][1] = DP[i][j][0] + DP[i][j][1]
        elif j < a: #左側を決めて合計jになるとき、ただしaはjより大きいので使えない
            # DP[i + 1][j][0] = DP[i][j][0] 
            DP[i + 1][j][1] = DP[i][j][0] + DP[i][j][1] #以前から合計jになっている場合のみOK
        else: #左側を決めて合計j > aになるとき, aだけでは足りない = 左側はこれより前で決まっている
            DP[i + 1][j][1] = DP[i][j][0] + DP[i][j][1] + DP[i][j - a][0] + DP[i][j - a][1]
        # DP[i + 1][j][0] %= MOD
        DP[i + 1][j][0] %= MOD
    DP[i + 1][S][2] = DP[i][S][1] + DP[i][S][2]
    if a <= S:
        DP[i + 1][S][2] += DP[i][S - a][0] + DP[i][S - a][1]
    DP[i + 1][S][2] %= MOD

print (DP[N][S][2])

# for i in range(N + 1):
#     print (DP[i])

### FIXED CODE ###

def main():
    MOD = 998244353

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

    DP0 = [[0] * (S + 1) for _ in range(N + 1)]
    DP1 = [[0] * (S + 1) for _ in range(N + 1)]
    DP2 = [[0] * (S + 1) for _ in range(N + 1)]

    DP0[0][0] = 1

    for i in range(N):
        DP0[i + 1][0] = DP0[i][0] 
        DP1[i + 1][0] = DP0[i][0] + DP1[i][0]
        a = A[i]
        if a > S:
            for j in range(1, S + 1):
                DP1[i + 1][j] = DP1[i][j] #以前から合計jになっている場合のみOK
        else:
            for j in range(1, a):
                DP1[i + 1][j] = DP1[i][j] #以前から合計jになっている場合のみOK
            for j in range(a, S + 1):
                DP1[i + 1][j] = (DP1[i][j] + DP0[i][j - a] + DP1[i][j - a]) % MOD
                # DP[i + 1][j][1] = (DP[i][j][0] + DP[i][j][1] + DP[i + 1][j - a][1]) % MOD

        DP2[i + 1][S] = (DP1[i][S] + DP2[i][S])
        if a <= S:
            DP2[i + 1][S] += DP0[i][S - a] + DP1[i][S - a]
        DP2[i + 1][S] %= MOD

    print (DP2[N][S])

    # for i in range(N + 1):
    #     print (DP[i])

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

N=int(input())
L=sorted(list(map(int,input().split())))
ans=0
for i in range(0,N-1):
    for j in range(i+1,N):
        D=L[i]+L[j]
        l=j
        r=N
        while r-l>1:
            med=(l+r)//2
            if D>L[med]:
                l=med
            else:
                r=med
        ans+=l-j
print(ans)

### FIXED CODE ###

N=int(input())
L=sorted(list(map(int,input().split())))
ans=0
for i in range(0,N-1):
    for j in range(i+1,N):
        D=L[i]+L[j]
        l=j
        r=N
        while r-l>1:
            med=(l+r)//2
            if D>L[med]:
                l=med
            else:
                r=med
        ans+=l-j
print(ans)
### BUGGY CODE ###

from collections import deque

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

ab = [[int(i) for i in input().split()] for j in range(N-1)]
G = [[] for i in range(N)]
for i in range(N-1):
    a, b = ab[i]
    G[a-1].append(b-1)
    G[b-1].append(a-1)

q = [[int(i) for i in input().split()] for j in range(Q)]
count = [0 for i in range(N)]
for i in range(Q):
    p, x = q[i]
    count[p-1] += x

ls = deque([0])
seen = [0 for i in range(N)]
while len(ls) > 0:
    root = ls.popleft()
    seen[root] = 1

    for next_v in G[root]:
        if not seen[next_v]:
            count[next_v] += count[root]
            ls.append(next_v)

for i in range(N):
    if i == N-1:
        print(count[i])
    else:
        print(count[i], end=" ")

### FIXED CODE ###

from collections import deque

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

ab = [[int(i) for i in input().split()] for j in range(N-1)]
G = [[] for i in range(N)]
for i in range(N-1):
    a, b = ab[i]
    G[a-1].append(b-1)
    G[b-1].append(a-1)

q = [[int(i) for i in input().split()] for j in range(Q)]
count = [0 for i in range(N)]
for i in range(Q):
    p, x = q[i]
    count[p-1] += x

ls = deque([0])
seen = [0 for i in range(N)]
while len(ls) > 0:
    root = ls.popleft()
    seen[root] = 1

    for next_v in G[root]:
        if not seen[next_v]:
            count[next_v] += count[root]
            ls.append(next_v)

for i in range(N):
    print(count[i], end=" ")
### BUGGY CODE ###

line = str(input())
lines = line.split(' ')

n = int(lines[0])
k = int(lines[1])

d = list()

line = str(input())
lines = line.split(' ')

for l in lines:
    d.append(int(l))

ds = list()

for i in range(0,n):
    for len in range(1,n-i+1):
        sum = 0
        for j in range(i,i+len):
            sum += d[j]
        ds.append(sum)

digit = 0
o = list()

for i in range(40,-1,-1):
    count = 0
    o.clear()

    for dss in ds:
        if dss & (1 << i) > 0 :
            count += 1
            o.append(dss)

    if count >= k :
        ds = o.copy()

    if count == k :
        break

sum = ds[0]
for i in range(1,k):
    sum = sum & ds[i]

print(sum)

### FIXED CODE ###

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

ds = []

for i in range(0,n):
    sum = 0
    for j in range(i,n):
        sum += d[j]
        ds.append(sum)
        #print(str(sum) + " ",end='')
    #print()

ds.sort(reverse=True)

sum = 0
for i in range(40,-1,-1):
    count = 0
    o = []
    for dss in ds:
        if dss & (1 << i) > 0 :
            count += 1
            o.append(dss)

    if count >= k :
        sum += 1 << i
        ds = o

print(sum)
### BUGGY CODE ###

#158_D
s = input()
q = int(input())

rev = 1
for _ in range(q):
    a = list(input().split())
    if a[0] == "1":
        rev *= -1
    elif a[0] == "2":
        if (a[1]=="1" and rev==1) or (a[1]=="2" and rev==-1):
            s = a[2] + s
        elif (a[1]=="2" and rev==1) or (a[1]=="1" and rev==-1):
            s = s + a[2]
if rev == -1:
    s = s[::-1]
print(s)

### FIXED CODE ###

#158_D
s = input()
q = int(input())

from collections import deque

s = deque(s)

rev = 1
for _ in range(q):
    Q = list(input().split())
    if Q[0] == "1":
        rev *= -1
    elif Q[0] == "2":
        if (Q[1]=="1" and rev==1) or (Q[1]=="2" and rev==-1):
            s.appendleft(Q[2])
        elif (Q[1]=="2" and rev==1) or (Q[1]=="1" and rev==-1):
            s.append(Q[2])
            
s = "".join(s)
            
if rev == -1:
    s = s[::-1]

print(s)
### BUGGY CODE ###

e=enumerate
h,w=map(int,input().split())
a=[list(map(int,input().split()))for _ in range(h)]
b=[list(map(int,input().split()))for _ in range(h)]
dp=[[]for _ in range(w)]
dp[0]={a[0][0]-b[0][0],b[0][0]-a[0][0]}
for i,(a,b)in e(zip(a,b)):
  for j,(d,x,y)in e(zip(dp,a,b)):
    x,y=x-y,y-x
    t=set()
    add=t.add
    if i:
      for v in d:
        add(v+x)
        add(v+y)
    if j:
      for v in dp[j-1]:
        add(v+x)
        add(v+y)
    if i+j:dp[j]=t
print(min(map(abs,dp[w-1])))

### FIXED CODE ###

e=enumerate
h,w=map(int,input().split())
a=[list(map(int,input().split()))for _ in range(h)]
b=[list(map(int,input().split()))for _ in range(h)]
dp=[0]*w
c=13000
for i,(a,b)in e(zip(a,b)):
  for j,(x,y)in e(zip(a,b)):
    x=abs(x-y)
    if i==j==0:
      dp[j]=2**c<<x
      continue
    t=0
    if j:
      t|=dp[j-1]<<x
      t|=dp[j-1]>>x
    if i:
      t|=dp[j]<<x
      t|=dp[j]>>x
    dp[j]=t
*a,=map(int,(bin(dp[w-1])[2:]).zfill(26001))
print(min([i for i,f in e(a[13000:])if f]+[i for i,f in e(a[13000::-1])if f]))
### BUGGY CODE ###

S = input()
det = 0
count = 0

while True:
  #"BW"の並びがあることを検出する。
  for i in range(len(S)-1):
    if (S[len(S) - i - 1] == "W") and (S[len(S) - i - 2] == "B"):
      break
  for i in range(len(S)-1):
    if (S[len(S) - i - 1] == "W") and (S[len(S) - i - 2]) == "B":
      if i == 0:
        S = S[:len(S) - i - 2] + "WB"
        count += 1
        break
      elif 0 < i < len(S) - 1:
        S = S[:len(S) - i - 2] + "WB" + S[len(S) - i:]
        count += 1
        break
      else:
        S = "WB" + S[len(S) - i:]
        count += 1
        break
  else:
    break
  
print(count)

### FIXED CODE ###

S = input()
white = []
count = 0

for i in range(len(S)):
  if S[i] == "W":
    white.append(i)

for i in range(len(white)):
  count += white[i] - i

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

n = int(input())
A = [int(input()) for i in range(n)]
X = list(set(A))
X.sort()
X.reverse()
if len(X) == 1 or A.count(max(A)) >= 2:
  for i in range(n):
    print(max(A))
else:
  for i in range(n):
    if A[i] == X[0]:
      print(X[1])
    else:
      print(X[0])

### FIXED CODE ###

N = int(input())
A = [int(input()) for i in range(N)]
B = list(set(A))
B.sort()
B.reverse()
if len(B) == 1 or A.count(B[0])>= 2:
  for i in range(N):
    print(B[0])
else:
  for i in range(N):
    if A[i] == B[0]:
      print(B[1])
    else:
      print(B[0])
### BUGGY CODE ###

from time import*
from fractions import*
start=time()
M=10**9+7
lcm=lambda x,y:x//gcd(x,y)*y
n,*a=map(int,open(0).read().split())
if n==1:
    print(1)
    exit()
s=a[0]
for t in a[1:]:
    s=lcm(s,t)
    if time()-start>.7:
        s=max(a)
        break
c=0
for i in a:
    c+=s//i
    c%=M
print(c)

### FIXED CODE ###

from fractions import*
from functools import*
M=10**9+7
_,a=open(0)
*a,=map(int,a.split())
s=reduce(lambda x,y:x//gcd(x,y)*y,a)%M
c=0
for i in a:
    c+=s*pow(i,M-2,M)
    c%=M
print(c)
### BUGGY CODE ###

n,a,b=map(int,input().split())
s=input()
Pass=[]
out=1
for i in range(n):
    if s[i]=="a" and len(Pass)+1<=a+b:
            Pass.append(i)
    if s[i]=="b" and len(Pass)+1<=a+b and out<=b:
            Pass.append(i)
            out+=1
for i in range(n):
    print("Yes" if i in Pass else "No")


### FIXED CODE ###

n,a,b=map(int,input().split())
s=input()
for i in s:
    if a+b>0:
        if i=="a":
            a-=1
            print("Yes")
            continue
        if i=="b" and b>0:
            b-=1
            print("Yes")
            continue
    print("No")
### BUGGY CODE ###

#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())

k = I()
a = 7
if k%2 == 0:
    print(-1)
    exit()
for i in range(10**7):
    if a%k == 0:
        print(i+1)
        exit()
    a = a*10 + 7
print(-1)


### FIXED CODE ###

#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())

k = I()
a = 7
if k%2 == 0:
    print(-1)
    exit()
for i in range(10**6):
    if a%k == 0:
        print(i+1)
        exit()
    a = (a*10 + 7)%k

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

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

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
x = 1
if 0 in a:
    x = 0
else:
    for i in range(n):
        x = x * a[i]
        if x > 10 ** 18:
            x = -1
            break
print(x)
### BUGGY CODE ###

n,m = map(int,input().split())
a=[]
b=[]
sum=0
for i in range(n):
  aa,bb=map(int,input().split())
  a.append(aa)
  b.append(bb)
while True:
  s=min(a)
  t=a.index(s)
  sum += s*b[t]
  m -= b[t]
  if m<=0:
    sum += s*m
    break
  del a[t],b[t]
print(sum)

### FIXED CODE ###

n,m=map(int,input().split())
a=[]
for i in range(n):
  a.append(tuple(map(int,input().split())))
a.sort()
count=0
for i in range(n):
  m-=a[i][1]
  count+=a[i][0]*a[i][1]
  if m<=0:
    count+=a[i][0]*m
    print(count)
    break