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

n = int(input())
s = list(input())
ans = []
for i in range(n):
    ans.append(s[:i].count('W') + s[i+1:].count('E') )
print(sorted(ans)[0])

### FIXED CODE ###

n = int(input())
s = input()
num = s[1:].count('E')
ans = [num]

for i in range(1,n):
    if s[i] == 'E':
        num -= 1
    if s[i-1] == 'W':
        num += 1
    ans.append(num)
print(min(ans))
### BUGGY CODE ###

# D - Digits Parade

# dp[i][j] 末尾からi桁の数で、あり得るもののうち、13で割った余りがjになるものの個数。0桁スタート

S = input()

MOD = 10**9 + 7
dp = [[0]*13 for _ in range(len(S))]

if S[-1] == "?":
    for j in range(10):
        dp[0][j] = 1
else:
    for j in range(13):
        if j == int(S[-1]):
            dp[0][j] = 1

for i in range(2, len(S)+1):
    if S[-i] == "?":
        for q_number in range(10): # ?の中身としてあり得る数字
            for back_number in range(13):
                dp[i-1][(q_number * 10**(i-1) + back_number) % 13] += dp[i-2][back_number] % MOD
    else:
        for back_number in range(13):
            dp[i-1][(int(S[-i]) * 10**(i-1) + back_number) % 13] += dp[i-2][back_number] % MOD

print(dp[len(S)-1][5] % MOD)

### FIXED CODE ###

# D - Digits Parade

# dp[i][j] Sの大きい位からi桁の数で、あり得るもののうち、13で割った余りがjになるものの個数。0桁スタート
# 大きい位から順に始めないと13で割ったときの余りを求める計算量が大きくなる

S = input()

MOD = 10**9 + 7
dp = [[0]*13 for _ in range(len(S))]

if S[0] == "?":
    for j in range(10):
        dp[0][j] = 1
else:
    dp[0][int(S[0])] = 1

for i in range(1, len(S)):
    if S[i] == "?":
        for q_number in range(10): # ?の中身としてあり得る数字
            for front_number in range(13):
                dp[i][(10 * front_number + q_number) % 13] += dp[i-1][front_number]
                dp[i][(10 * front_number + q_number) % 13] %= MOD
    else:
        for front_number in range(13):
            dp[i][(10 * front_number + int(S[i])) % 13] += dp[i-1][front_number]
            dp[i][(10 * front_number + int(S[i])) % 13] %= MOD

print(dp[len(S)-1][5] % MOD)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"):
    isAC = [False] * N
    
    end = N - 1
    for i in range(end):
        if S[i] == 'A' and S[i+1] == 'C':
            isAC[i] = True

    for i in range(Q):
        res = 0
        begin = l[i] - 1
        end   = r[i] - 1
        for j in range(begin,end):
            if isAC[j]:
                res += 1
        print(res)


# Generated by 1.1.4 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
    Q = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    l = [int()] * (Q)  # type: "List[int]" 
    r = [int()] * (Q)  # type: "List[int]" 
    for i in range(Q):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    solve(N, Q, S, l, r)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
from bisect import bisect_left
from bisect import bisect_right


def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"):
    aclist = [] 
    end = N - 1
    for i in range(end):
        if S[i] == 'A' and S[i+1] == 'C':
            aclist.append(i)

    len_ac = len(aclist)

    for i in range(Q):
        res = 0
        begin = l[i] - 1
        end   = r[i] - 2

        s_start = bisect_left(aclist,begin)
        s_end   = bisect_right(aclist,end)

        print(s_end-s_start)
            


# Generated by 1.1.4 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
    Q = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    l = [int()] * (Q)  # type: "List[int]" 
    r = [int()] * (Q)  # type: "List[int]" 
    for i in range(Q):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    solve(N, Q, S, l, r)

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

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

x = 7
ans = 1
while True:
    if x < K:
        x = x*10 + 7
        ans += 1
        continue
    q,m = divmod(x,K)
    if m == 0:
        break
    x = m
print(ans)


### FIXED CODE ###

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

m = set()
x = 7
ans = 1
while x > 0:
    if x < K:
        x = x*10 + 7
        ans += 1
    x = x % K
    if x in m:
        print(-1)
        exit(0)
    else:
        m.add(x)

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

def solve():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    INF=float('inf')
    n,m=map(int,input().split())
    l=[list(map(int,input().split())) for _ in range(m)]
    d=[INF]*n
    nbr=[[] for _ in range(n)]
    used=[False]*m
    for x in l:
        x[0]-=1
        x[1]-=1
    #print(l)
    for i in range(m):
        nbr[l[i][0]].append(i)
        nbr[l[i][1]].append(i)
    #print(nbr)
    def sol(i):
        for x in nbr[i]:
            if used[x]:continue
            used[x]=True
            i1=l[x][0]^l[x][1]^i
            dd=d[i]+l[x][2]*(2*(l[x][0]==i)-1)
            if d[i1]==INF:
                d[i1]=dd
            elif d[i1]!=dd:
                print('No')
                exit()
            sol(i1)
    for i in range(n):
        if d[i]==INF:
            d[i]=0
            sol(i)
    #print(d)
    print('Yes')
solve()

### FIXED CODE ###

def solve():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    INF=float('inf')
    n,m=map(int,input().split())
    l=[list(map(int,input().split())) for _ in range(m)]
    d=[INF]*n
    nbr=[[] for _ in range(n)]
    used=[False]*m
    for x in l:
        x[0]-=1
        x[1]-=1
    #print(l)
    for i in range(m):
        nbr[l[i][0]].append(i)
        nbr[l[i][1]].append(i)
    #print(nbr)
    def sol(i):
        for x in nbr[i]:
            if used[x]:continue
            used[x]=True
            i1=l[x][0]^l[x][1]^i
            dd=d[i]+l[x][2]*(2*(l[x][0]==i)-1)
            if d[i1]!=dd and d[i1]!=INF:
                print('No')
                exit()
            elif d[i1]==INF:
                d[i1]=dd
                sol(i1)
    for i in range(n):
        if d[i]==INF:
            d[i]=0
            sol(i)
    #print(d)
    print('Yes')
solve()
### BUGGY CODE ###

x,k,d = list(map(int, input().split()))
x = abs(x)
for i in range(k,0,-1):
  if x > 0:
    x -= d
  else:
    x += d * (i % 2)
    break
print(abs(x))


### FIXED CODE ###

x,k,d = list(map(int, input().split()))
x = abs(x)
a,b = divmod(x, d)
a = min(a, k)
x -= a * d
#print('a=',a)
#print('x=',x)
#print('ka=',k-a)
x -= d * ((k-a) % 2)
print(abs(x))
### BUGGY CODE ###

def can_construct_q(q, array, i, sum_sofar):
    if sum_sofar == q or sum_sofar + array[i] == q:
        return True
    elif sum_sofar > q or i >= len(array) - 1:
        return False
    if can_construct_q(q, array, i + 1, sum_sofar + array[i]):
        return True
    if can_construct_q(q, array, i + 1, sum_sofar):
        return True


def main():
    input()
    array_a = list(map(int, input().split()))
    input()
    array_q = map(int, input().split())
    for q in array_q:
        if can_construct_q(q, array_a, 0, 0):
            print('yes')
        else:
            print('no')
    return


main()


### FIXED CODE ###

def main():
    input()
    array_a = list(map(int, input().split()))
    input()
    array_q = map(int, input().split())

    def can_construct_q (q, i, sum_sofar):
        if sum_sofar == q or sum_sofar + array_a[i] == q:
            return True
        elif sum_sofar > q or i >= len (array_a) - 1:
            return False
        if can_construct_q(q, i + 1, sum_sofar + array_a[i]):
            return True
        if can_construct_q(q, i + 1, sum_sofar):
            return True
    sum_array_a = sum(array_a)
    for q in array_q:
        #print(q)
        if sum_array_a < q:
            print('no')
        elif can_construct_q(q, 0, 0):
            print('yes')
        else:
            print('no')
    return


main()
### BUGGY CODE ###

import numpy as np
N, M, Q = map(int, input().split())
LR = []
for i in range(M):
    l, r = map(int, input().split())
    LR.append([l, r])
PQ = []
for i in range(Q):
    p, q = map(int, input().split())
    PQ.append([p, q])

ar = np.zeros([N, N])
for i in range(M):
    l, r = LR[i][0], LR[i][1]
    ar[l - 1][r - 1] += 1
for i in range(Q):
    p, q = PQ[i][0]-1, PQ[i][1]
    print(int(ar[p:q, p:q].sum()))

### FIXED CODE ###

import numpy as np
N, M, Q = map(int, input().split())
LR = []
for i in range(M):
    l, r = map(int, input().split())
    LR.append([l, r])
PQ = []
for i in range(Q):
    p, q = map(int, input().split())
    PQ.append([p, q])
ar_sec = np.zeros([N, N])
for i in range(M):
    l, r = LR[i][0], LR[i][1]
    ar_sec[l-1][r-1] += 1


ar_sum = np.zeros([N+1, N+1])
for i in range(N):
    for j in range(N):
        ar_sum[i+1][j+1] = ar_sum[i][j+1]+ar_sum[i+1][j]-ar_sum[i][j]+ar_sec[i][j]

for i in range(Q):
    p, q = PQ[i][0], PQ[i][1]
    print(int(ar_sum[q][q]-ar_sum[p-1][q]))
### BUGGY CODE ###

from fractions import gcd
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
def lcm(a,b):
    return (a * b // gcd(a, b))
h = reduce(lcm, A)
B = [(h // A[i] % MOD) for i in range(N)]
print(sum(B) % MOD)


### FIXED CODE ###

from fractions import gcd
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7

def lcm(a,b):
    return (a * b // gcd(a, b))

def modpow(a, n, mod): # a^n mod
    result = 1
    while n > 0:
        if n & 1: result = result * a % mod
        a = a * a % mod
        n >>= 1
    return result

h = reduce(lcm, A)
B = [h * modpow(A[i], MOD-2, MOD) for i in range(N)]
print(sum(B) % MOD)
### BUGGY CODE ###

n,k = map(int,input().split())
h = [int(input()) for i in range(n)]
h.sort()
ans = 99999999999999999999999999
for i in range(n-k+1):
    x = h[i:i+k]
    ans = min(ans,max(x)-min(x))
print(ans)

### FIXED CODE ###

n,k = map(int,input().split())
h = [int(input()) for i in range(n)]
h.sort()
l = [h[i+k-1]-h[i] for i in range(n-k+1)]
print(min(l))
### BUGGY CODE ###

class Calc:
    def __init__(self, max_value, mod):
        """combination(max_value, all)"""
        fact = [-1] * (max_value + 1)
        fact[0] = 1
        fact[1] = 1
        for x in range(2, max_value + 1):
            fact[x] = x * fact[x - 1] % mod

        invs = [1] * (max_value + 1)
        invs[max_value] = pow(fact[max_value], mod - 2, mod)
        for x in range(max_value - 1, 0, -1):
            invs[x] = invs[x + 1] * (x + 1) % mod

        self.fact = fact
        self.invs = invs
        self.mod = mod

    def combination(self, n, r):
        if n - r < r:
            return self.combination(n, n - r)
        if r < 0:
            return 0
        if r == 0:
            return 1
        if r == 1:
            return n
        return self.fact[n] * self.invs[r] * self.invs[n - r] % self.mod


def main():
    MOD = 10 ** 9 + 7

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

    def decom(n) -> list:
        ret = []

        d = 2
        cnt = 0
        while n % d == 0:
            n //= d
            cnt += 1
        ret.append(cnt)

        d = 3
        while n > 1:
            cnt = 0
            while n % d == 0:
                n //= d
                cnt += 1
            ret.append(cnt)
            d += 2

        return ret

    dlis = decom(M)

    cal = Calc(max_value=N + 30, mod=MOD)

    ans = 1
    for cnt in dlis:
        ans = (ans * cal.combination(N + cnt - 1, cnt)) % MOD
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

MOD = 10 ** 9 + 7


def prime_factorization(n):
    i = 2
    res = []
    while i * i <= n:
        cnt = 0
        while n % i == 0:
            n /= i
            cnt += 1
        if cnt > 0:
            res.append(cnt)
        i += 1
    if n > 1:
        res.append(1)
    return res


def comb(a, b):
    b = min(b, a - b)
    if b < 0:
        return 0
    elif b == 0:
        return 1
    elif b == 1:
        return a
    else:
        return (a % MOD) * pow(b, MOD - 2, MOD) % MOD * comb(a - 1, b - 1) % MOD


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

ans = 1
for power in prime_factorization(M):
    ans *= comb(N - 1 + power, power)
    ans %= MOD

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

S = input()[::-1]
N = len(S)

"""
    例： S = '31415926535'
        S[3:8] = '15926535' が 2019 で割り切れるかどうか？
     <=> S[3:-1] - S[8:-1] が 2019 で割り切れるかどうか
     <=> S[3:-1] % 2019 == S[8:-1] % 2019 か
    よって、2019で割ったときの異なるあまりをそれぞれカウントすればよい
"""

mod_cnts = [0] * 2019
mod_cnts[0] = 1 # 累積和のはじめ
current_cusum, ans = 0, 0
# O(N)
# d = 1
for i in range(N):
# for s in S:
    s = S[i]
    current_cusum += (pow(10, i)% 2019) * int(s) # 累積和
    # current_cusum += d * int(s)
    current_cusum %= 2019
    mod_cnts[current_cusum] += 1

    # d *= 10 % 2019

# O(2019)
for cnt in mod_cnts:
    ans += cnt * (cnt - 1) // 2 # n_C_2 2つ選ぶ組み合わせ
 
print(ans)


### FIXED CODE ###

S = input()
N = len(S)

num = [0] * 2019
num[0] = 1
now, ans = 0, 0
_10 = 1

for i in range(N-1, -1, -1):
    now = (now + int(S[i]) * _10) % 2019
    _10 *= 10
    _10 %= 2019
    ans += num[now]
    num[now] += 1
 
print(ans)
### BUGGY CODE ###

N, M = map( int, input().split())
Q = []
for i in range(M):
    a,b = map(int,input().split())
    Q.append([a,b])
Q = sorted(Q)
ans = 1
while len(Q) != 0:
    stan = Q[0][1]
    k = 1
    while len(Q) != 0:
        if Q[0][0] < stan:
            stan = min(stan,Q.pop(0)[1])
        else:
            ans += 1
            break
print(ans)

### FIXED CODE ###

N, M = map( int, input().split())
Q = []
for i in range(M):
    a,b = map(int,input().split())
    Q.append([a,b])
Q = sorted(Q)
ans = 1
LQ = len(Q)
while LQ != 0:
    stan = Q[0][1]
    k = 1
    while LQ != 0:
        if Q[0][0] < stan:
            stan = min(stan,Q.pop(0)[1])
            LQ -= 1
        else:
            ans += 1
            break
print(ans)
### BUGGY CODE ###

_ = input()
data = list(map(int, input().split()))
p = 1
for d in data:
  p *= d

if 10 ** 18 < p:
  print(-1)
else:
  print(p)

### FIXED CODE ###

_ = input()
data = list(map(int, input().split()))
p = 1
m = 10 ** 18

if data.count(0) > 0:
  print(0)
  exit()

for d in data:
  p *= d
  if m < p:
    print(-1)
    exit()
print(p)
### BUGGY CODE ###

H,W = map(int,input().split())
m = ["" for _ in range(H)] 
sharps = []
for i in range(H):
    m[i] = input()
    for j in enumerate(m[i]):
        if j[1] == "#":
            sharps += [(i,j[0])]

coord = [[(i,j)for i in range(W)] for j in range(H)]

ref_max = 0
for i in range(H):
    for j in range(W):
        tmp_max = min([abs(coord[i][j][0] - one[0]) + abs(coord[i][j][1] - one[1]) for one in sharps])
        if tmp_max > ref_max:
            ref_max = tmp_max
            
print(ref_max)

### FIXED CODE ###

import numpy as np
import sys
# https://atcoder.jp/contests/agc033/submissions/6021787
buf = sys.stdin.buffer
H,W = map(int,buf.readline().split())
# +1周分だけ
black = np.zeros((H+2,W+2),dtype=np.bool)
# \nがあることに注意
black[1:-1,1:] = (np.frombuffer(buf.read(H*(W+1)),dtype='S1') == b'#').reshape(H,W+1)

INF = 10 ** 4
dist = np.zeros((H,W),dtype=np.int16)
# .のところは０それ以外はINFで初期化
dist[~black[1:-1,1:-1]] = INF
# 右、左、下、上と展開させていく感じ
for n in range(1,H):
    np.minimum(dist[n-1]+1,dist[n],out=dist[n])
for n in range(H-2,-1,-1):
    np.minimum(dist[n+1]+1,dist[n],out=dist[n])
for n in range(1,W):
    np.minimum(dist[:,n-1]+1,dist[:,n],out=dist[:,n])
for n in range(W-2,-1,-1):
    np.minimum(dist[:,n+1]+1,dist[:,n],out=dist[:,n])

print(dist.max())
### BUGGY CODE ###


#n:
#m:
#k:
n,m,k=map(int,input().split())
friend={}
block={}
result=[]
for i in range(1,n+1):
    friend[i]=set([])
    block[i]=set([])
    result.append(0)

for _ in range(m):
    a,b=map(int,input().split())
    friend[a].add(b)
    friend[b].add(a)

for _ in range(k):
    a,b=map(int,input().split())
    block[a].add(b)
    block[b].add(a)


checked=[]
bfbf=[]
for i in range(1,n+1):
    #print(i,checked)
    if i not in checked:
        checked.append(i)
        group=[i]
        bf=[i]
        while len(group)!= 0:
            temp=group.pop(0)
            for item in friend[temp]:
                if item not in checked:
                    checked.append(item)
                    group.append(item)
                    bf.append(item)
        lenbf=len(bf)
        for item1 in bf:
            bl=0
            for item2 in bf:
                if item2 in block[item1]:
                    bl+=1
            result[item1-1]=lenbf-1-len(list(friend[item1]))-bl



        bfbf.append(bf)
result=list(map(str,result))
print(" ".join(result))







### FIXED CODE ###

#n:
#m:
#k:
n,m,k=map(int,input().split())
friend={}
block={}
result=[]
friendGroup=[]
for i in range(1,n+1):
    friend[i]=set([])
    block[i]=set([])
    result.append(0)
    friendGroup.append(0)

for _ in range(m):
    a,b=map(int,input().split())
    friend[a].add(b)
    friend[b].add(a)

checked=set([])
bfbf=[]
for i in range(1,n+1):
    #print(i,checked)
    if i not in checked:
        checked.add(i)
        group=set([i])
        bf=set([i])
        friendGroup[i-1]=i
        while len(group)!= 0:
            temp=group.pop()
            for item in friend[temp]:
                if item not in checked:
                    checked.add(item)
                    group.add(item)
                    bf.add(item)
                    friendGroup[item-1]=i
        lenbf=len(bf)
        for item1 in bf:
            result[item1-1]=lenbf-1-len(list(friend[item1]))

for _ in range(k):
    a,b=map(int,input().split())
    if friendGroup[a-1]!=0 and friendGroup[a-1]==friendGroup[b-1]:
        result[a-1]-=1
        result[b-1]-=1

result=list(map(str,result))
print(" ".join(result))
### BUGGY CODE ###

N = int(input())
P = list(map(int,input().split()))
a = 0
ans = 0
for i in range(N):
    for j in range(i + 1):
        if P[i] <= P[j]:
            a += 1
    if a == i + 1:
        ans += 1
    a = 0
print(ans)

### FIXED CODE ###

N = int(input())
P = list(map(int,input().split()))
ans = 0
x = P[0]


for i in P:
    if i == 1:
        ans += 1
        x = 1
    else:
        if x >= i:
            ans += 1
            x = i



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

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

N = int(input())
S = input().rstrip()

s = set()


for i in range(0, N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            s.add(S[i]+S[j]+S[k])

print(len(s))


### FIXED CODE ###

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

N = int(input())
S = input().rstrip()

ans = 0
for i in range(1000):
    t = str(i).zfill(3)
    t1 = S.find(t[0])
    if t1 == -1:
        continue
    t2 = S.find(t[1], t1+1)
    if t2 == -1:
        continue
    t3 = S.find(t[2], t2+1)
    if t3 == -1:
        continue
    ans += 1

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

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

m = (n-1)//2
l = sorted(x)
for i in x:
  if l.index(i) > m: print(l[m])
  else: print(l[m+1])

### FIXED CODE ###

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

m = (n-1)//2
l = sorted(x)
for i in x:
  if i > l[m]: print(l[m])
  else: print(l[m+1])
### BUGGY CODE ###

n = int(input())
s = list(input())
b = 27
mod = pow(2, 61) - 1
m = n // 2
x = [1] * (m + 1)
for i in range(1, m + 1):
    x[i] = (x[i - 1] * b) % mod
h0 = [0] * m
h0[0] = ord(s[0]) - 96
d = [{} for _ in range(m + 1)]
for i in range(1, m):
    h0[i] = (h0[i - 1] * b + (ord(s[i]) - 96)) % mod
for i in range(m, 0, -1):
    h = h0[i - 1]
    d[i][h] = 0
    for j in range(i, n):
        h *= b
        h %= mod
        h -= (x[i] * (ord(s[j - i]) - 96) % mod)
        h += (ord(s[j]) - 96)
        h %= mod
        if h in d[i]:
            if (j - i + 1 - d[i][h]) >= i:
                print(i)
                exit()
        else:
            d[i][h] = j - i + 1
print(0)

### FIXED CODE ###

n = int(input())
s = list(input())
b = 27
mod = 67280421310721
m = n // 2
x = [1] * (m + 1)
for i in range(1, m + 1):
    x[i] = (x[i - 1] * b) % mod
h0 = [0] * m
h0[0] = ord(s[0]) - 96
d = [{} for _ in range(m + 1)]
for i in range(1, m):
    h0[i] = (h0[i - 1] * b + (ord(s[i]) - 96)) % mod
for i in range(m, 0, -1):
    h = h0[i - 1]
    d[i][h] = 0
    for j in range(i, n):
        h *= b
        h %= mod
        h -= (x[i] * (ord(s[j - i]) - 96) % mod)
        h += (ord(s[j]) - 96)
        h %= mod
        if h in d[i]:
            if (j - i + 1 - d[i][h]) >= i:
                print(i)
                exit()
        else:
            d[i][h] = j - i + 1
print(0)
### BUGGY CODE ###

def factorial(n):
    f=1
    for i in range(1,n+1):
        f*=i%(10**9+7)
    return f
n,m=map(int,input().split())
N=factorial(n)
if abs(n-m)>1:
    print(0)
elif abs(n-m)==0:
    print(2*N*N%(10**9+7))
elif n>m:
    print((N*N//n)%(10**9+7))
else:
    print(N*N*m%(10**9+7))

### FIXED CODE ###

import math
n,m=map(int,input().split())
N=math.factorial(n)
if abs(n-m)>1:
    print(0)
elif abs(n-m)==0:
    print(2*N*N%(10**9+7))
elif n>m:
    print((N*N//n)%(10**9+7))
else:
    print(N*N*m%(10**9+7))
### BUGGY CODE ###

N=int(input())
S_list = []
for i in range(N):
  s = str(input())
  if not (s in S_list):
    S_list.append(s)
print(len(S_list))

### FIXED CODE ###

import numpy as np
N=int(input())
S_list = np.zeros(N)
#S_list = np.zeros(N,dtype=str)
e_list = "abcdefghijklmnopqrstuvwxyz"

for i in range(N):
  s = input()
  n = 0
  for k in range(len(s)):
    n = n + (e_list.index(s[k])+1)*(100**k)
  S_list[i] = n
print(len(np.unique(S_list)))
### BUGGY CODE ###

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
for a in A:
    B = sorted(A,reverse=True)
    B.remove(a)
    print(B[0])

### FIXED CODE ###

import copy
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
B = sorted(A,reverse=True)
for a in A:
    if a < B[0]:
        print(B[0])    
    else:
        print(B[1])
### BUGGY CODE ###

# coding: utf-8
# Your code here!
import sys

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

N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]
li = [1] + [0 for _ in range(N)]

for i in range(1, N + 1):
    if i in a:
        li[i] = 0
    else:
        li[i] = li[i - 1] + li[i - 2]
print(li[-1] % (pow(10,9) + 7))

### FIXED CODE ###

# coding: utf-8
# Your code here!
import sys

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

N, M = map(int, input().split())
a = set(int(input()) for _ in range(M))
li = [1] + [0 for _ in range(N)]

for i in range(1, N + 1):
    if i in a:
        continue
    else:
        li[i] = li[i - 1] + li[i - 2]
print(li[-1] % 1000000007)
### BUGGY CODE ###

n, a, b = map(int, input().split())
s = ''
while len(s) < n:
    for _ in range(a):
        s += 'a'
    for _ in range(b):
        s += 'b'

print(s[0:n].count('a'))


### FIXED CODE ###

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

ans = n // (a + b) * a
rem = n % (a + b)
ans += min(rem, a)

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

# -*- coding: utf-8 -*-
import math

n = input()

N = math.factorial(int(n))

j= 0

for i in range(1, N+1):
    if N % i == 0:
        j += 1
    
print(j % 1000000007)


### FIXED CODE ###

# -*- coding: utf-8 -*-
import math
import collections

n = input()

# 階乗を計算する
N = math.factorial(int(n))

# 試し割り方で素因数分解を行う
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

a = prime_factorize(N)

# 素因数の値と個数を辞書型にする
c = collections.Counter(a)

# 個数だけをリストで取得
d = list(c.values())

# 個数+1の総積が約数の個数となる
e = 1
for i in range(len(d)):
    e = e*(d[i]+1)

# 求められていた値の出力
print(e % 1000000007)