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

import sys
from collections import deque

def q(d, c):
    if c == 1: 
        if d < 10: return str(d), 0
        else:
            a = d //10 + d % 10
            if a < 10: return str(a), 1
            else: return str(a - 9), 2
    a = d * 2
    if a < 10:
        lem, count = q(a, c//2)
    else:
        lem, count = q(a - 9, c//2)
        count += c // 2
    count += c//2
    if c % 2 == 1: lem += str(d)
    return lem, count

def solve():
    input = sys.stdin.readline
    M = int(input())
    N = ""
    count = 0
    dq = deque()

    for _ in range(M):
        d, c = map(int, input().split())
        lem, add = q(d, c)
        for i in range(len(lem)): 
            dq.append(lem[i])
        count += add
    
    digit = len(dq)
    for _ in range(digit - 1):
        #print(dq)
        a = int(dq.pop())
        a += int(dq.pop())
        if a >= 10:
            dq.append(str(a % 10 + a // 10))
            count += 2
        else: 
            dq.append(str(a))
            count += 1

    print(count)
    
    return 0

if __name__ == "__main__":
    solve()

### FIXED CODE ###

import sys
from collections import deque

def q(d, c): #dは9以下、cは桁数
    digsum = d * c
    add = c - 1 + (digsum - 1) // 9
    rem = digsum - 9 * ((digsum - 1) // 9)
    return add, rem

def solve():
    input = sys.stdin.readline
    M = int(input())
    count = -1
    ans = 0
    for _ in range(M):
        d, c = map(int, input().split())
        add, rem = q(d, c)
        count += add
        ans += rem
        count += 1
        if ans > 9:
            ans -= 9
            count += 1

    print(count)
    
    return 0

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

a,b = map(int,input().split())
def gcd(x,y):
    q = max(x,y)  %  min(x,y)
    if q == 0 :
        return [min(x,y),0]
    return gcd(min(x,y),q)

L = gcd(a,b)
K = [ i for i in reversed(range(1, L[0] +1 )) if a % i == 0 ]

print(max(K))



### FIXED CODE ###

a,b = map(int,input().split())
def gcd(x,y):
    q = max(x,y)  %  min(x,y)
    if q == 0 :
        return [min(x,y),0]
    return gcd(min(x,y),q)

print(max(gcd(a,b)))
### BUGGY CODE ###

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

### FIXED CODE ###

n=int(input())
B=list(map(int,input().split()))
cnt=0
maxi=max(B)
for i in range(n):
  if maxi>=B[i]:
    cnt+=1
    maxi=B[i]
print(cnt)
### BUGGY CODE ###

def check(s_i, n_i, count, i_set):
    for i in range(9):
        print("s:",s_i,"n:",n_i,"i:",i,"count:",count)
        i_set_tmp = set(i_set)
        if i not in i_set:
            continue
        s_tmp = s_i - i*n_i
        n_tmp = n_i - 1
        if s_tmp == 0 and n_tmp == 0:
            return count + 1
        elif s_tmp < 0 or n_tmp < 0:
            break
        else:
            i_set_tmp.remove(i)
            count = check(s_tmp, n_tmp, count, i_set_tmp)
    return count

while True:
    try:
        n, s = map(int, input().split())
        print(check(s, n, 0, set([0,1,2,3,4,5,6,7,8,9])))
    except:
        break



### FIXED CODE ###

s_max = [0]
for i in range(1,11):
    s = 0
    for j in range(i):
        s += (10 - j - 1)*(i - j)
    s_max.append(s)

def check(u, r, s, m):
    if r == 0:
        return s == 0
    n = 0
    for i in range(10):
        n *= 2
        if u[i]:
            n += 1
    if (n, r, s) in m:
        return m[(n, r, s)]
    if s < 0 or s > s_max[r]:
        return 0

    ans = 0
    for i in range(10):
        if not u[i]:
            u[i] = True
            ans += check(u, r - 1, s - i*r, m)
            u[i] = False
    m[(n, r, s)] = ans
    return m[(n, r, s)]

memo = {}
while True:
    try:
        n, s = map(int, input().split())
        used = [False for i in range(10)]
        ans = check(used, n, s, memo)
        print(ans)
    except:
        break
### BUGGY CODE ###

import copy
from collections import deque

N = int(input())
C = [input() for i in range(N)]

C2 = []
re = ""
L = {}
for i in C:
  if i != re:
    if i in L:
      L[i].append(len(C2))
    else:
      L[i] = deque([])
    C2.append(i)
  re = i

LL = [-1] * len(C2)
for i in range(len(C2)):
  if L[C2[i]] != []:
    LL[i] = copy.deepcopy(L[C2[i]])
    if len(L[C2[i]]) > 0:
      L[C2[i]].popleft()

DP = [-1] * (len(C2) + 1)

DP[-1] = 1
for i in range(len(C2) - 1, -1, -1):
  DP[i] = DP[i + 1]
  if LL[i] != -1:
    for j in LL[i]:
      DP[i] += DP[j + 1]

print(DP[0])

### FIXED CODE ###

N = int(input())
C = [input() for i in range(N)]

MOD = 1e9 + 7

C2 = []
re = ""
L = {}
LL = [-1] * N
for i in C:
  if i != re:
    if i in L:
      LL[L[i]] = len(C2)
      L[i] = len(C2)
    else:
      L[i] = len(C2)
    C2.append(i)
  re = i


DP = [-1] * (len(C2) + 1)

DP[-1] = 1
for i in range(len(C2) - 1, -1, -1):
  DP[i] = DP[i + 1]
  if LL[i] != -1:
    DP[i] += DP[LL[i]] % MOD
print(int(DP[0] % MOD))
### BUGGY CODE ###

[N,L] = [int(x) for x in input().split()]
A = {}
B = [0]*N
ANS = {}
count = 0
for i,x in enumerate(input().split()):
    i = int(i)
    x = int(x)
    B[i] = x
    if x in A : A[x] += [i]
    else : A[x] = [i]
for i in sorted(A) :
    for j in A[i] :
        for k in range(L) :
            if j + k not in ANS :
                ANS[j+k] = i
                count += 1
    if count * count * count > N * N : break
        
for i in range(L):
    if i not in ANS : ANS[i] = min(B[:i+1])
for i in range(L,N):
    if i not in ANS : ANS[i] = min(B[i+1-L:i+1])
for i in range(L-1,N-1) : print(ANS[i], end=" ")
print(ANS[N-1])

### FIXED CODE ###

def ascend(a,b):
    mini = min(A[a:a+L])
    ans[a] = mini
    for i in range(a+1,b):
        if A[i+L-1] <= mini : mini = A[i+L-1]
        elif A[i-1] == mini : mini = min(A[i:i+L])
        ans[i] = mini

def descend(a,b):
    mini = min(A[b-1:b+L-1])
    ans[b-1] = mini
    for i in range(b-2,a-1,-1):
        if A[i] <= mini : mini = A[i]
        elif A[i+L] == mini: mini = min(A[i:i+L])
        ans[i] = mini
    
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = [None]*(N-L+1)
count = 0;
if N > 10 ** 4:
    for i in range(100):
        if A[i+1] > A[i] : count += 1
    if count > 80 : descend(0, N-L+1)
    else : ascend(0,N-L+1)
else :
    ascend(0, N-L+1)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])
### BUGGY CODE ###

# 2018/06/02
 
class Deque2(object):
    def __init__(self):
        self.a = list()
 
    def push(self, d, x):
        if d == 0:
            self.a = [x] + self.a
        elif d == 1:
            self.a.append(x)
 
    def randomAccess(self, p):
        print self.a[p]
 
    def pop(self, d):
        if d == 0:
            self.a = self.a[1:]
        elif d == 1:
            self.a = self.a[:-1]
 
    def __repr__(self):
        return " ".join([str(i) for i in self.a])
 
if __name__ == "__main__":
    d = Deque2()
    q = int(raw_input())
    for i in range(q):
        query = [int(j) for j in raw_input().split()]
        if query[0] == 0:
            d.push(query[1], query[2])
        elif query[0] == 1:
            d.randomAccess(query[1])
        elif query[0] == 2:
            d.pop(query[1])


### FIXED CODE ###

# 2018/06/02

from collections import deque

d = deque()
q = int(raw_input())

for i in range(q):
    query = [int(j) for j in raw_input().split()]
    if query[0] == 0:
        if query[1] == 0:
            d.appendleft(query[2])
        else:
            d.append(query[2])
    elif query[0] == 1:
        print  d[query[1]]
    elif query[0] == 2:
        if query[1] == 0:
            d.popleft()
        else:
            d.pop()
### BUGGY CODE ###

import math
import fractions
import copy
#以下てんぷら
def j(q):
    if q==1: print("YES")
    elif q == 0:print("NO")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


#n = ip()                                     #入力整数1つ
n,k= (int(i) for i in input().split())       #入力整数横2つ以上
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しに4 3sum変数使用はsum関数使用できないので注意
a.sort()
cnum = a[0]
ct =1
st = []
for i in range(1,n):
    if a[i] != cnum:
        cnum = a[i]
        st.append(ct)
        ct = 1
    else:ct+=1
st.append(ct)
st.sort()
total = 0
while len(st)>k:
    total+=st.pop(0)
print(total)

### FIXED CODE ###

import math
import fractions
import copy
#以下てんぷら
def j(q):
    if q==1: print("YES")
    elif q == 0:print("NO")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


#n = ip()                                     #入力整数1つ
n,k= (int(i) for i in input().split())       #入力整数横2つ以上
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しに4 3sum変数使用はsum関数使用できないので注意
a.sort()
cnum = a[0]
ct =1
st = []
for i in range(1,n):
    if a[i] != cnum:
        cnum = a[i]
        st.append(ct)
        ct = 1
    else:ct+=1
st.append(ct)
st.sort(reverse=True)
total = 0
for i in range(min(k,len(st))):
    total+=st[i]
print(n-total)
### BUGGY CODE ###

H, W = map(int, input().split())
maze = [list(input()) for _ in range(H)]


def bfs(x, y):
    visited, queue = [], [(x, y, 0)]
    max_cost = 0
    while queue:
        px, py, cost = queue.pop(0)
        max_cost = max(max_cost, cost)

        candidate = ((px + 1, py), (px - 1, py), (px, py + 1), (px, py - 1))
        visited.append((px, py))
        for cx, cy in candidate:
            if not (0 <= cx < W and 0 <= cy < H):
                continue
            if (cx, cy) in visited:
                continue
            if maze[cy][cx] == "#":
                continue
            queue.append((cx, cy, cost + 1))
    return max_cost


ans = 0
for y in range(H):
    for x in range(W):
        if maze[y][x] == "#":
            continue
        ans = max(ans, bfs(x, y))

print(ans)

### FIXED CODE ###

H, W = map(int, input().split())
m = [list(input()) for _ in range(H)]
inf = 10**3

V = H*W
maze = [[inf]*V for _ in range(V)]

for i in range(V):
    maze[i][i] = 0

for py in range(H):
    for px in range(W):
        if m[py][px] == "#":
            continue
        candidate = [(px+1, py), (px-1, py), (px, py+1), (px, py-1)]
        for x, y in candidate:
            if not (0<=x<W and 0<=y<H):continue
            if m[y][x] == "#":
                continue
            maze[W*py+px][W*y+x] = 1

for k in range(V):
    for i in range(V):
        for j in range(V):
            maze[i][j] = min(maze[i][j], maze[i][k]+maze[k][j])

print(max([j for i in maze for j in i if j!=inf]))
### BUGGY CODE ###

#ABC120C-Unification.py

from sys import stdin

input = stdin.readline

S = input().rstrip()

Nblock = 0

while True:
    for i in range(len(S)-1):
        if S[i:i+1] != S[i+1:i+2]:
            Nblock += 2
            S = S[:i] + S[i+2:]
            break
    else:
        break

print(Nblock)


### FIXED CODE ###

#ABC120C-Unification.py

from sys import stdin

input = stdin.readline

S = input().rstrip()

Nblock = min(S.count('1'), S.count('0'))

print(Nblock*2)
### BUGGY CODE ###

N = int(input())

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

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

d = prime_factorize(N)

ans = 2**64

A = d

for i in range(1 << len(A)):
    a = []
    b = []
    ao = 1
    bo = 1
    for j in range(len(A)):
        if ((i >> j) & 1) == 1:
            a.append(A[j])
        else:
            b.append(A[j])
            
    for j in range(len(a)):
        ao *= a[j]
    for j in range(len(b)):
        bo *= b[j]
        
    ans = min(ans, ao+bo-2)
    
print(ans)




### FIXED CODE ###

N = int(input())

a = 1
ans = 2**64
while a*a<=N:
    b = N/a
    if b!=int(b):
        a += 1
        continue
    b = int(b)
    ans = min(ans, a+b-2)

    a += 1

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

from collections import deque
n, m = map(int, input().split())
d = {}
ans = [0] * (n)
for _ in range(m):
    a, b = map(int, input().split())
    if not a in d.keys():
        d[a] = [b]
    else:
        d[a].append(b)
    if not b in d.keys():
        d[b] = [a]
    else:
        d[b].append(a)
    if a == 1:
        ans[b-1] = 1
    if b == 1:
        ans[a-1] = 1

q = deque([1])
alr = [1]
while not len(q) == 0:
    x = q.popleft()
    for i in d[x]:
        if ans[i-1] == 0:
            ans[i-1] = x
        if i in alr:
            continue
        alr.append(i)
        q.append(i)

if 0 in ans:
    print('No')
else:
    print('Yes')
    for j in ans[1:]:
        print(j)

### FIXED CODE ###

from collections import deque
n, m = map(int, input().split())
d = [[] for _ in range(n+1)]
ans = [0] * (n)
for _ in range(m):
    a, b = map(int, input().split())
    d[a].append(b)
    d[b].append(a)

q = deque([1])
while not len(q) == 0:
    x = q.popleft()
    for i in d[x]:
        if ans[i-1] == 0:
            ans[i-1] = x
            q.append(i)

if 0 in ans:
    print('No')
else:
    print('Yes')
    s  = "\n".join(map(str, ans[1:]))
    print(s)
### BUGGY CODE ###

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

sum_A = 1
for i in range(0,len(A)):
    sum_A *= A[i]
if(sum_A > 1000000000000000000):
        print("-1")
        exit()
print(sum_A)


### FIXED CODE ###

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

sum_A = 1

for i in range(0,len(A)):
  if(A[i] == 0):
        print(0)
        exit()

for i in range(0,len(A)):
  if(sum_A > 1000000000000000000):
        break
  sum_A *= A[i]
if(sum_A > 1000000000000000000):
        print("-1")
        exit()
print(sum_A)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from collections import deque

H,W=map(int,input().split())
sh,sw=map(int,input().split())
gh,gw=map(int,input().split())
MAP=[input().strip() for i in range(H)]

ANS=[[1<<30]*W for i in range(H)]

sh-=1
sw-=1
gh-=1
gw-=1

ANS[sh][sw]=0

Q=deque([(sh,sw)])

while Q:
    x,y=Q.popleft()

    for i in range(x-2,x+3):
        if 0<=i<H:           
            for j in range(y-2,y+3):
                if 0<=j<W:                
                    if MAP[i][j]=="." and abs(i-x)+abs(j-y)==1 and ANS[i][j]>ANS[x][y]:
                        ANS[i][j]=ANS[x][y]
                        Q.append((i,j))
                    elif MAP[i][j]=="." and abs(i-x)+abs(j-y)>1 and ANS[i][j]>ANS[x][y]+1:
                        ANS[i][j]=ANS[x][y]+1
                        Q.append((i,j))

if ANS[gh][gw]==1<<30:
    print(-1)
else:
    print(ANS[gh][gw])



### FIXED CODE ###

import sys
input = sys.stdin.readline
import heapq

H,W=map(int,input().split())
sh,sw=map(int,input().split())
gh,gw=map(int,input().split())
MAP=[input().strip() for i in range(H)]

ANS=[[1<<30]*W for i in range(H)]

sh-=1
sw-=1
gh-=1
gw-=1

ANS[sh][sw]=0

def ca(sc,x,y):
    return sc*(10**8)+x*(10**4)+y

def inv(w):
    sc=w//(10**8)
    w%=(10**8)
    x=w//(10**4)
    y=w%(10**4)

    return sc,x,y

Q=[ca(0,sh,sw)]

while Q:
    sc,x,y=inv(heapq.heappop(Q))

    if sc>ANS[x][y]:
        continue

    for i,j in [(x-2,y-2),(x-2,y-1),(x-2,y),(x-2,y+1),(x-2,y+2),(x-1,y-2),(x-1,y-1),(x-1,y),(x-1,y+1),(x-1,y+2),(x,y-2),(x,y-1),(x,y+1),(x,y+2),(x+1,y-2),(x+1,y-1),(x+1,y),(x+1,y+1),(x+1,y+2),(x+2,y-2),(x+2,y-1),(x+2,y),(x+2,y+1),(x+2,y+2)]:
        if 0<=i<H and 0<=j<W:
            if MAP[i][j]=="." and abs(i-x)+abs(j-y)==1 and ANS[i][j]>sc:
                ANS[i][j]=sc
                heapq.heappush(Q,ca(ANS[i][j],i,j))
            elif MAP[i][j]=="." and abs(i-x)+abs(j-y)>1 and ANS[i][j]>sc+1:
                ANS[i][j]=sc+1
                heapq.heappush(Q,ca(ANS[i][j],i,j))

if ANS[gh][gw]==1<<30:
    print(-1)
else:
    print(ANS[gh][gw])
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
from collections import deque

H,W = map(int,input().split())
INF = 10**18
q = deque()

d = [[0]*(W+2)] + [[0]+[INF]*W+[0] for _ in range(H)] + [[0]*(W+2)]# '#'からの距離

for i in range(1,H+1):
  for j,c in enumerate(input(),1):
    if c == '#':
      d[i][j] = 0
      q.append((0,i,j))

ans = 0
qq = []
while q:
  for dv,x,y in q:
    for dx,dy in [(0,1),(0,-1),(1,0),(-1,0)]:
      xx = x+dx
      yy = y+dy
      if d[xx][yy] == INF:
        d[xx][yy] = dv+1
        ans = dv+1
        qq.append((dv+1,xx,yy))
  q = qq
  qq = []
  
print(ans)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

H,W = map(int,input().split())
INF = 10**18
q = []

visited = [[True]*(W+2)]
visited += [[True] + [x == '#' for x in input().rstrip()] + [True] for _ in range(H)]
visited.append([True]*(W+2))
  
for i in range(1,H+1):
  for j in range(1,W+1):
    if visited[i][j]:
      q.append((i,j))

moves = [(0,1),(0,-1),(1,0),(-1,0)]

ans = -1
while q:
  qq = []
  ans += 1
  for x,y in q:
    if not visited[x-1][y]:
      visited[x-1][y] = True
      qq.append((x-1,y))
    if not visited[x+1][y]:
      visited[x+1][y] = True
      qq.append((x+1,y))
    if not visited[x][y-1]:
      visited[x][y-1] = True
      qq.append((x,y-1))
    if not visited[x][y+1]:
      visited[x][y+1] = True
      qq.append((x,y+1))
  q = qq
  
print(ans)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split(' ')))
answer = True
for i in range(len(A)):
    if A.count(A[i]) > 1:
        answer = False
if answer:
    print('YES')
else:
    print('NO')

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split(' ')))
uniqu_a = list(set(A))
if N == len(uniqu_a):
    print('YES')
else:
    print('NO')
### BUGGY CODE ###

import itertools
n = input()
l = [int(i) for i in input().split()]

p = list(itertools.combinations(l,3))
        
ans = [1 for i in p if i[0] < i[1] + i[2] and  i[1] < i[0] + i[2] and i[2] < i[0] + i[1]]

print(len(ans))

### FIXED CODE ###

import bisect
n = int(input())
l = sorted([int(i) for i in input().split()])

ans = 0
for i in range(n):
    for j in range(i+1,n):
        a = l[i]
        b = l[j]
        tri = bisect.bisect_left(l,a+b)
        ans += tri-j-1
        
print(ans)
### BUGGY CODE ###

n = int(input())
string = input()

# r=g=b=0

# for idx, s in enumerate(string):
#     if s == 'R':
#         r+=1
#     elif s == 'B':
#         b+=1
#     elif s == 'G':
#         g+=1

ans = string.count('R')*string.count('G')*string.count('B')

for i in range(n):
    for k in range(i+1, n):
        if string[i] != string[k]:
            if (k+i)%2 == 0 and len(set([string[i], string[k], string[(k+i)//2]])) ==3:
                ans -= 1

print(ans)
            



### FIXED CODE ###

n = int(input())
string = input()
r = 0
g = 0
b = 0
for c in string:
    if c == 'R':
        r += 1
    elif c == 'G':
        g += 1
    else:
        b += 1
ans = r*g*b
for i in range(n):
    for j in range(i+1, n):
        if 2*j - i >= n:
            break
        
        if string[i] != string[j] and string[i] != string[2*j-i] and string[j] != string[2*j-i]:
            ans -= 1
print(ans)
### BUGGY CODE ###

N = int(raw_input())
x = 1
for i in xrange(N):
    x *= i+1

print x%1000000007

### FIXED CODE ###

# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n = II()

ans = 1
for i in range(1, n + 1):
    ans *= i
    ans %= MOD

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

""" C
"""
import sys
import math
from functools import reduce
from bisect import bisect_left

def readString():
    return sys.stdin.readline()

def readInteger():
    return int(readString())

def readStringSet(n):
    return sys.stdin.readline().split(" ")[:n]

def readIntegerSet(n):
    return list(map(int, readStringSet(n)))

def readIntegerMatrix(n, m):
    return reduce(lambda acc, _: acc + [readIntegerSet(m)], range(0, n), [])

def _pattern(N):
    if N > 1:
        pa = _pattern(N-1)
        return [[0] + p for p in pa] + [[1] + p for p in pa]
    else:
        return [[0], [1]]

def main(N, A):
    M = pow(10, 9) + 7
    result = 0
    for i in range(len(A)):
        for j in range(i+1, len(A)):
            result = (result + A[i] * A[j]) % M
    return result

if __name__ == "__main__":
    _N = readInteger()
    _A = readIntegerSet(_N)

    print(main(_N, _A))

### FIXED CODE ###

""" C
"""
import sys
import math
from functools import reduce
from bisect import bisect_left

def readString():
    return sys.stdin.readline()

def readInteger():
    return int(readString())

def readStringSet(n):
    return sys.stdin.readline().split(" ")[:n]

def readIntegerSet(n):
    return list(map(int, readStringSet(n)))

def readIntegerMatrix(n, m):
    return reduce(lambda acc, _: acc + [readIntegerSet(m)], range(0, n), [])

def main(N, A):
    M = pow(10, 9) + 7
    result = 0
    S = sum(A)
    for i in range(len(A)):
        S = S - A[i]
        result = (result + A[i] * S) % M
    return result

if __name__ == "__main__":
    _N = readInteger()
    _A = readIntegerSet(_N)

    print(main(_N, _A))
### BUGGY CODE ###

#D
import numpy as np
N = int(input())
A = list(map(int, input().split()))
x = 0
for i in range(N):
    for j in range(N):
        if i < j:
            if np.abs(i-j) == A[i] + A[j]:
                x += 1
print(x)

### FIXED CODE ###

import numpy as np
N = int(input())
A = list(map(int, input().split()))
d = {}
x = 0

for i, a in enumerate(A):
    if i+a not in d:
        d[i+a] = 1
    else:
        d[i+a] += 1
    if i-a in d:
        x += d[i-a] 

print(x)
### BUGGY CODE ###

s = input() + 'R'


t = []
b = 0
for i in range(1, len(s)):
    if s[i - 1] + s[i] == 'LR':
        t.append(s[b:i])
        b = i

ans = []


for ss in t:
    nR = ss.find('L')
    nL = len(ss) - nR

    R = nR // 2 + (nR % 2) + nL // 2
    L = nL // 2 + (nL % 2) + nR // 2
    ans = ans + [0 for _ in range(nR - 1)]+[R] + \
        [L] + [0 for _ in range(nL - 1)]

for i in range(len(ans)):
    if i != 0:
        print(' ', end='')
    print(ans[i])

### FIXED CODE ###

s = input() + 'R'


t = []
b = 0
for i in range(1, len(s)):
    if s[i - 1] + s[i] == 'LR':
        t.append(s[b:i])
        b = i

ans = []


for ss in t:
    nR = ss.find('L')
    nL = len(ss) - nR

    R = nR // 2 + (nR % 2) + nL // 2
    L = nL // 2 + (nL % 2) + nR // 2

    ans += [0 for _ in range(nR - 1)]+[R, L] + [0 for _ in range(nL - 1)]

for i in range(len(ans)):
    if i != 0:
        print(' ', end='')
    print(ans[i],end='')