Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
reverse_flg = False
for q in range(Q):
  r = input().split()
  if len(r) == 1:
    reverse_flg = not reverse_flg
  else:
    if int(r[1]) == 1:
      S = r[2] + S if not reverse_flg else S + r[2]
    else:
      S = S + r[2] if not reverse_flg else r[2] + S

if reverse_flg:
  S = S[::-1]

print(S)

Fixed submission:
S = input()
Q = int(input())
reverse_flg = False

b_str = ""
f_str = ""

for q in range(Q):
  r = input().split()
  if len(r) == 1:
    reverse_flg = not reverse_flg
  else:
    # Sは最終的に加えればいいので、それを最適化する
    if int(r[1]) == 1:
      if reverse_flg:
        f_str = f_str + r[2]
      else:
        b_str = r[2] + b_str
    else:
      if reverse_flg:
        b_str = r[2] + b_str
      else:
        f_str = f_str + r[2]

S = b_str + S + f_str

if reverse_flg:
  S = S[::-1]

print(S)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
for q in range(Q):
  r = input().split()
  if len(r) == 1:
    S = S[::-1]
  else:
    if int(r[1]) == 1:
      S = r[2] + S
    else:
      S = S + r[2] 
  
print(S)

Fixed submission:
S = input()
Q = int(input())
reverse_flg = False

b_str = ""
f_str = ""

for q in range(Q):
  r = input().split()
  if len(r) == 1:
    reverse_flg = not reverse_flg
  else:
    # Sは最終的に加えればいいので、それを最適化する
    if int(r[1]) == 1:
      if reverse_flg:
        f_str = f_str + r[2]
      else:
        b_str = r[2] + b_str
    else:
      if reverse_flg:
        b_str = r[2] + b_str
      else:
        f_str = f_str + r[2]

S = b_str + S + f_str

if reverse_flg:
  S = S[::-1]

print(S)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
word_count = {}
for n in range(N):
  s = input()
  if s in word_count:
    word_count[s] += 1
  else:
    word_count[s] = 1
max_word_list = [kv[0] for kv in word_count.items() if kv[1] == max(word_count.values())]
# 辞書順にソートして出力
max_word_list = sorted(max_word_list)
for word in max_word_list:
  print(word)


Fixed submission:
from collections import Counter
N = int(input())
l=[input() for i in range(N)]
count=Counter(l).most_common()
d = []
most = count[0][1]
for si,c in count:
  if c==most:
    d.append(si)
d.sort()
for i in d:
  print(i)



# # O(N)
# max_word_list = [kv[0] for kv in word_count.items() if kv[1] == max(word_count.values())]

# # 辞書順にソートして出力
# max_word_list = sorted(max_word_list)
# for word in max_word_list:
#   print(word)
Buggy python submission (verdict: Time Limit Exceeded):
"""
注意点：ACしていないWAはペナルティ数とはカウントされない
      また、ACの後にペナルティしたものはカウントされない
データ構造：
  WA:dict形式でカウントアップ
  AC:配列で末尾に挿入
一通り舐めた後AD配列をforで回してペナルティ数合計するか？
"""

N,M = list(map(lambda x: int(x), input().split()))
l = [(str(n + 1) , 0) for n in range(N)]
wa_count = dict(l)
ac_list = []
answer = 0

for _ in range(M):
  p,s = input().split()
  if s == 'WA':
    wa_count[p] += 1
  else:
    if p not in ac_list:
      answer += wa_count[p]
      ac_list.append(p)
    

print(len(ac_list), answer)


Fixed submission:
"""
注意点：ACしていないWAはペナルティ数とはカウントされない
      また、ACの後にペナルティしたものはカウントされない
データ構造：
  WA:dict形式でカウントアップ
  AC:配列で末尾に挿入
一通り舐めた後AD配列をforで回してペナルティ数合計するか？
"""

N,M = list(map(lambda x: int(x), input().split()))
wa_count = [0] * N
ac_list = [False] * N
answer = 0

for _ in range(M):
  p,s = input().split()
  p = int(p)
  if s == 'WA':
    wa_count[p-1] += 1
  if s == 'AC' and ac_list[p-1] == False:
    answer += wa_count[p-1]
    ac_list[p-1] = True

ac_count = ac_list.count(True)

print(ac_count, answer)

Buggy python submission (verdict: Time Limit Exceeded):
"""
注意点：ACしていないWAはペナルティ数とはカウントされない
      また、ACの後にペナルティしたものはカウントされない
データ構造：
  WA:dict形式でカウントアップ
  AC:配列で末尾に挿入
一通り舐めた後AD配列をforで回してペナルティ数合計するか？
"""

N,M = list(map(lambda x: int(x), input().split()))
results = []
for n in range(M):
  results.append(input().split())


l = [(str(n + 1) , 0) for n in range(N)]
wa_count = dict(l)
ac_list = []
answer = 0

for p, s in results:
  if s == 'WA':
    wa_count[p] += 1
  else:
    if p not in ac_list:
      answer += wa_count[p]
      ac_list.append(p)
    

print(len(ac_list), answer)


Fixed submission:
"""
注意点：ACしていないWAはペナルティ数とはカウントされない
      また、ACの後にペナルティしたものはカウントされない
データ構造：
  WA:dict形式でカウントアップ
  AC:配列で末尾に挿入
一通り舐めた後AD配列をforで回してペナルティ数合計するか？
"""

N,M = list(map(lambda x: int(x), input().split()))
wa_count = [0] * N
ac_list = [False] * N
answer = 0

for _ in range(M):
  p,s = input().split()
  p = int(p)
  if s == 'WA':
    wa_count[p-1] += 1
  if s == 'AC' and ac_list[p-1] == False:
    answer += wa_count[p-1]
    ac_list[p-1] = True

ac_count = ac_list.count(True)

print(ac_count, answer)
Buggy python submission (verdict: Runtime Error):
import math

A, B = list(map(lambda x: int(x), input().split()))

print(int((A * B) / math.gcd(A, B)))

Fixed submission:
import fractions

A, B = list(map(lambda x: int(x), input().split()))

print(int((A * B) / fractions.gcd(A, B)))

Buggy python submission (verdict: Runtime Error):
import math

def lcm(x, y):
  return (x * y) // math.gcd(x, y)

A, B = list(map(lambda x: int(x), input().split()))

print(lcm(A, B))

Fixed submission:
import fractions

A, B = list(map(lambda x: int(x), input().split()))

print(int((A * B) / fractions.gcd(A, B)))

Buggy python submission (verdict: Runtime Error):
import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

A, B = list(map(lambda x: int(x), input().split()))

print(lcm(A, B))

Fixed submission:
import fractions

A, B = list(map(lambda x: int(x), input().split()))

print(int((A * B) / fractions.gcd(A, B)))
Buggy python submission (verdict: Time Limit Exceeded):
N = input()

S = input()
len_S = len(S)

key_list = range(0, 1000)

key_list = tuple(map(lambda key: '0' * (3 - len(str(key))) + str(key), key_list))

ans_list = []

for key in key_list:
    target_num = 0
    for s in S:
        if key[target_num] == s:
            target_num += 1
        if target_num == 3:
            ans_list.append(key)
            break

print(len(ans_list))


Fixed submission:
import copy

N = input()
S = input()

key_list = range(0, 1000)
key_list = tuple(map(lambda key: '0' * (3 - len(str(key))) + str(key), key_list))

ans_list = []
for key in key_list:
    flg = True
    cS = copy.copy(S)
    for i in key:
        index = cS.find(i)
        if index == -1:
            flg = False
            break
        cS = cS[index+1:]
    if flg:
        ans_list.append(key)
        
print(len(ans_list))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

S = input()
len_S = len(S)

key_list = []

for a in range(len_S - 2):
    for b in range(a+1, len_S-1):
        for c in range(b+1, len_S):
            key = S[a] + S[b] + S[c]
            if key not in key_list:
                key_list.append(key)

print(len(key_list))


Fixed submission:
import copy

N = input()
S = input()

key_list = range(0, 1000)
key_list = tuple(map(lambda key: '0' * (3 - len(str(key))) + str(key), key_list))

ans_list = []
for key in key_list:
    flg = True
    cS = copy.copy(S)
    for i in key:
        index = cS.find(i)
        if index == -1:
            flg = False
            break
        cS = cS[index+1:]
    if flg:
        ans_list.append(key)
        
print(len(ans_list))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = []

# 二つの掛け算の組み合わせを列挙
for n in range(1, int(N/2) + 1):
  if N % n == 0:
    a.append( int(n + N/n) )

# その中で一番足した数が少ないものを選択する
print(min(a) - 2)


Fixed submission:
import math

N = int(input())

# 証明できないけど、真ん中の方の数字の方が数を足すと小さい値になると思う。
for n in reversed(range(1, int(math.sqrt(N)) + 1)):
  if N % n == 0:
    a = int(n + N/n)
    break


print(a - 2)
Buggy python submission (verdict: Time Limit Exceeded):
def add(x, y):
  if dp_list[x][y] == 0:
    dp_list[x][y] = lists[x] + lists[y]
  return dp_list[x][y]


N = int(input())
lists = list(map(lambda x: int(x), input().split()))
# 昇順ソート
lists.sort()
dp_list = [[0 for i in range(N)] for j in range(N)]
count = 0

for a in range(len(lists)):
  if(a + 1) >= len(lists):
    break
  for b in range(a + 1, len(lists)):
    if(b + 1) >= len(lists):
      break
    for c in range(b + 1, len(lists)):
      if add(a, b) > lists[c]:
        count += 1
      else:
        break
#      if add(a, b) > lists[c] and add(b, c) > lists[a] and add(a, c) > lists[b]:
#        count += 1
            
print(count)

Fixed submission:
from bisect import bisect_left
n = int(input())
l = list(map(int,input().split()))
l.sort()
 
ans = 0
for i in range(n-2):
  for j in range(i+1,n-1):
   ans += bisect_left(l,l[i] + l[j]) - j - 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def add(x, y):
  if dp_list[x][y] == 0:
    dp_list[x][y] = lists[x] + lists[y]
  return dp_list[x][y]


N = int(input())
lists = list(map(lambda x: int(x), input().split()))
dp_list = [[0 for i in range(N)] for j in range(N)]
count = 0

for a in range(len(lists)):
  if(a + 1) >= len(lists):
    break
  for b in range(a + 1, len(lists)):
    if(b + 1) >= len(lists):
      break
    for c in range(b + 1, len(lists)):
      if add(a, b) > lists[c] and add(b, c) > lists[a] and add(a, c) > lists[b]:
        count += 1
            
print(count)

Fixed submission:
from bisect import bisect_left
n = int(input())
l = list(map(int,input().split()))
l.sort()
 
ans = 0
for i in range(n-2):
  for j in range(i+1,n-1):
   ans += bisect_left(l,l[i] + l[j]) - j - 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy

"""

+ その範囲の6の倍数の数
+ その範囲の8の倍数の数
- その範囲の48の倍数の数
で答えが求まる

"""

def v_count(n, start, end):
  start_pop = start % n
  start = start + (n - start_pop)
  return int((end - start) / n) + 1

A, B, C, D = list(map(lambda x: int(x), input().split()))

all_count = B - A + 1

c_count = v_count(C, A, B)
d_count = v_count(D, A, B)
min_cd = numpy.lcm(C, D)
cd_count = v_count(min_cd, A, B)

print(all_count - c_count - d_count + cd_count)


Fixed submission:
from fractions import gcd

"""

+ その範囲の6の倍数の数
  これはBまでの倍数の数からAまでの倍数の数を引く
+ その範囲の8の倍数の数
- その範囲の48の倍数の数
で答えが求まる

"""

def v_count(n, start, end):
  a = (start - 1) // n
  b = end // n
  return b - a

A, B, C, D = list(map(lambda x: int(x), input().split()))

all_count = B - A + 1

c_count = v_count(C, A, B)
d_count = v_count(D, A, B)
min_cd = (C * D) // gcd(C, D)
cd_count = v_count(min_cd, A, B)

print(all_count - c_count - d_count + cd_count)
Buggy python submission (verdict: Time Limit Exceeded):
def acNumberInString(word):
  count = 0
  while len(word) > 0:
    index = word.find('AC')
    if index == -1:
      return count

    count += 1
    word = word[index+2:]
  return count

N, Q = map(int, input().split())
S = input()
for q in range(Q):
  start, end = map(int, input().split())
  tmp_word = S[start-1:end]
  print(acNumberInString(tmp_word))


Fixed submission:
N, Q = map(int, input().split())
S = input()
AC_numbers = [0]

# そうか、まず累積和で全体のACのかずを数えるのか
for i in range(1, N):
  if S[i-1] == 'A' and S[i] == 'C':
    AC_numbers.append(AC_numbers[i - 1] + 1)
  else:
    AC_numbers.append(AC_numbers[i-1])

# そこから引いて数を求める
for q in range(Q):
  start, end = map(int, input().split())
  count = AC_numbers[end-1] - AC_numbers[start-1]
  print(count)

Buggy python submission (verdict: Time Limit Exceeded):
def acNumberInString(word):
  count = 0
  for i in range(len(word) - 1):
    if word[i] == 'A' and word[i+1] == 'C':
      count += 1
  return count


N, Q = map(int, input().split())
S = input()
for q in range(Q):
  start, end = map(int, input().split())
  tmp_word = S[start-1:end]
  print(acNumberInString(tmp_word))


Fixed submission:
N, Q = map(int, input().split())
S = input()
AC_numbers = [0]

# そうか、まず累積和で全体のACのかずを数えるのか
for i in range(1, N):
  if S[i-1] == 'A' and S[i] == 'C':
    AC_numbers.append(AC_numbers[i - 1] + 1)
  else:
    AC_numbers.append(AC_numbers[i-1])

# そこから引いて数を求める
for q in range(Q):
  start, end = map(int, input().split())
  count = AC_numbers[end-1] - AC_numbers[start-1]
  print(count)
Buggy python submission (verdict: Runtime Error):
INF = 100000000000
import math
N = int(input())
lists = list(map(int, input().split()))

min_gcd = INF

for a in range(len(lists) - 1):
  min_gcd = min(min_gcd, math.gcd(lists[a], lists[a+1]))

print(min_gcd)

Fixed submission:
import fractions
INF = 100000000000

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

min_gcd = INF

for a in range(len(lists) - 1):
  min_gcd = min(min_gcd, fractions.gcd(lists[a], lists[a+1]))

print(min_gcd)
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())

lists = [[] for _ in range(N)]
items = [list(map(int, input().split())) for _ in range(M)]
for p, y in items:
  lists[p-1].append(y)

for n in range(N):
  lists[n].sort()  

for p, y in items:
  index = lists[p-1].index(y)
  print("{:06g}{:06g}".format(p,index+1))

Fixed submission:
N,M=map(int,input().split())

lists = [[] for _ in range(N)]
items = [list(map(int, input().split())) for _ in range(M)]
for p, y in items:
  lists[p-1].append(y)

dic = {}

for n in range(N):
  lists[n].sort()  

for n in range(N):
  l = lists[n]
  count = 1
  for i in l:
    dic[i] = count
    count+=1

for p, y in items:
  print("{:06g}{:06g}".format(p,dic[y]))

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())

lists = [[] for _ in range(N)]
items = [list(map(int, input().split())) for _ in range(M)]
for p, y in items:
  lists[p-1].append(y)

for n in range(N):
  lists[n].sort()  

for p, y in items:
  index = lists[p-1].index(y)
  f = lambda x: ('0' * (6 - len(str(x))) +  str(x))
  print(f(p) + f(index+1))

Fixed submission:
N,M=map(int,input().split())

lists = [[] for _ in range(N)]
items = [list(map(int, input().split())) for _ in range(M)]
for p, y in items:
  lists[p-1].append(y)

dic = {}

for n in range(N):
  lists[n].sort()  

for n in range(N):
  l = lists[n]
  count = 1
  for i in l:
    dic[i] = count
    count+=1

for p, y in items:
  print("{:06g}{:06g}".format(p,dic[y]))

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
lists = []
for n in range(N):
  lists.append([])
items = []
for m in range(M):
  p, y = map(int, input().split())
  items.append(tuple([p, y]))
  lists[p-1].append(y)

sorted_lists = []

for l in range(len(lists)):
  sort_list = sorted(lists[l])
  sorted_lists.append(sort_list)

for p, y in items:
  index = sorted_lists[p-1].index(y)
  f = lambda x: ('0' * (6 - len(str(x))) +  str(x))
  print(f(p) + f(index+1))

Fixed submission:
N,M=map(int,input().split())

lists = [[] for _ in range(N)]
items = [list(map(int, input().split())) for _ in range(M)]
for p, y in items:
  lists[p-1].append(y)

dic = {}

for n in range(N):
  lists[n].sort()  

for n in range(N):
  l = lists[n]
  count = 1
  for i in l:
    dic[i] = count
    count+=1

for p, y in items:
  print("{:06g}{:06g}".format(p,dic[y]))
Buggy python submission (verdict: Runtime Error):
import collections

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

# 偶数列と奇数列に分ける
even_num = items[::2]
odd_num = items[1::2]

# それらの配列で一番数が多いものを判定、それに合わせる
dev = Counter(even_num).most_common(2)
dod = Counter(odd_num).most_common(2)

if dev[0][0] == dod[0][0] :
    if len(dev) == len(dod) == 1 :
        print(N//2)
    elif len(dev) < len(dod) :
        print(N//2 - dod[1][1])
    elif len(dev) > len(dod) :
        print(N//2 - dev[1][1])
    else :
        print(N - max(dod[1][1] + dev[0][1], dod[0][1] + dev[1][1]))
else :
    print(N - dod[0][1]- dev[0][1])



Fixed submission:
from collections import Counter

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

# 偶数列と奇数列に分ける
even_num = items[::2]
odd_num = items[1::2]

# それらの配列で一番数が多いものを判定、それに合わせる
dev = Counter(even_num).most_common(2)
dod = Counter(odd_num).most_common(2)

if dev[0][0] == dod[0][0] :
    if len(dev) == len(dod) == 1 :
        print(N//2)
    elif len(dev) < len(dod) :
        print(N//2 - dod[1][1])
    elif len(dev) > len(dod) :
        print(N//2 - dev[1][1])
    else :
        print(N - max(dod[1][1] + dev[0][1], dod[0][1] + dev[1][1]))
else :
    print(N - dod[0][1]- dev[0][1])
Buggy python submission (verdict: Time Limit Exceeded):
INF = 1000000
N = int(input())
S = input()

"""
まあまずは愚直にOrder（N*N）でやろう
"""

ans = INF

for i in range(N):
  count = 0
  for t in range(N):
    if i == t:
      continue
    if t < i and S[t] == "W" or t > i and S[t] == "E":
      count += 1

  ans = min(ans, count)

print(ans)

Fixed submission:
"""
まあまずは愚直にOrder（N*N）でやろう
これナイーブ計算というらしい
→無理でした。

前処理でWの累積和を計算する
そのあとにインデックス回して最小値を計算する
確かに前処理がO(N)でできるなら、
O(N)　＋　O（N）で計算可能になる！！
"""

INF = 1000000
N = int(input())
S = input()
ans = INF

sum_n = [0]
add_n = 0
# 前処理
# Westを向いている人の数を数える
for s in S:
  if s == "W":
    add_n += 1
  sum_n.append(add_n)

# リーダーの添字 = i
for i in range(N):
  # i番目より西にいる人のWを向いている人の数
  if i > 0:
    b_i = sum_n[i] - sum_n[0]
  else:
    b_i = 0

  # i番目より東にいる人のWを向いている人の数
  if i < N:
    f_i = (N - (i + 1)) - (sum_n[N] - sum_n[i+1])
  else:
    f_i = 0
  
  tmp = b_i + f_i
  ans = min(ans, tmp)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
K=int(input())
l = []
for alpha in [chr(i) for i in range(97, 97+26)]:
  indexs = [k for k, v in enumerate(list(S)) if v == alpha]
  for index in indexs:
    for j in range(index,len(S)+1):
      sub_s = S[index:j]
      l.append(sub_s)
  l = sorted(list(set(l)))
  if '' in l:
    l.remove('')
  if len(l) >= K:
    break
print(l[K-1])


Fixed submission:
S=input()
K=int(input())
l = []
for alpha in [chr(i) for i in range(97, 97+26)]:
  indexs = [k for k, v in enumerate(list(S)) if v == alpha]
  for index in indexs:
    for j in range(index,min(index+6,len(S)+1)):
      sub_s = S[index:j]
      l.append(sub_s)
  l = sorted(list(set(l)))
  if '' in l:
    l.remove('')
  if len(l) >= K:
    break
print(l[K-1])

Buggy python submission (verdict: Runtime Error):
S=input()
K=int(input())
l = []
for i in range(len(S)):
  for j in range(i,len(S)):
    sub_s = S[i:j]
    l.append(sub_s)
ans = sorted(list(set(l)))
ans.remove('')
print(ans[K-1])

Fixed submission:
S=input()
K=int(input())
l = []
for alpha in [chr(i) for i in range(97, 97+26)]:
  indexs = [k for k, v in enumerate(list(S)) if v == alpha]
  for index in indexs:
    for j in range(index,min(index+6,len(S)+1)):
      sub_s = S[index:j]
      l.append(sub_s)
  l = sorted(list(set(l)))
  if '' in l:
    l.remove('')
  if len(l) >= K:
    break
print(l[K-1])
Buggy python submission (verdict: Runtime Error):
import math
import sys


def dudge_answer(a, b):
    ave = (a+b)/2
    return math.ceil(ave)


print(dudge_answer(a, b))


Fixed submission:
a, b = map(int, input().split())
print((a + b + 1) // 2)

Buggy python submission (verdict: Runtime Error):
import math
import sys


def dudge_answer(a, b):
    ave = (a+b)/2
    return math.ceil(ave)


print(dudge_answer(float(sys.argv[1]), float(sys.argv[2])))


Fixed submission:
a, b = map(int, input().split())
print((a + b + 1) // 2)

Buggy python submission (verdict: Runtime Error):
import math
import sys


def dudge_answer(a, b):
    ave = (a+b)/2
    return math.ceil(ave)


print(dudge_answer(sys.argv[1], sys.argv[2]))


Fixed submission:
a, b = map(int, input().split())
print((a + b + 1) // 2)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
count = 0
# ソートして
for c in C:
  under_c = bisect.bisect_left(B, c)
  for b in B[:under_c]:
    under_b = bisect.bisect_left(A, b)
    count += under_b
print(count)


Fixed submission:
import bisect
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
count = 0
# ソートして
for b in B:
  upeer_b = N - bisect.bisect_right(C, b)
  downer_b = bisect.bisect_left(A, b)
  count += upeer_b * downer_b

# for c in C:
#   under_c = bisect.bisect_left(B, c)
#   for b in B[:under_c]:
#     under_b = bisect.bisect_left(A, b)
#     count += under_b

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
def frac(n):
  sum = 1
  for i in range(1,n+1):
    sum*=i
  return sum

import sys,fractions
N,M=map(int,input().split(' '))
# abs(N-M) > 1なら無理
if (abs(N-M) > 1):
  print(0)
  sys.exit()

# それぞれの階乗を求める
frac_n = frac(N)
frac_m = frac(M)

if N == M:
  ans = frac_m * frac_n * 2
else:
  ans = frac_n * frac_m

print(ans % (10**9 + 7))

Fixed submission:
divisor = 10**9 + 7

def frac(n):
  sum = 1
  for i in range(1,n+1):
    sum = sum * i % divisor
  return sum

import sys,fractions
N,M=map(int,input().split(' '))
# abs(N-M) > 1なら無理
if (abs(N-M) > 1):
  print(0)
  sys.exit()

# それぞれの階乗を求める
frac_n = frac(N)
frac_m = frac(M)

if N == M:
  ans = frac_m * frac_n * 2
else:
  ans = frac_n * frac_m

print(ans % (10**9 + 7))
Buggy python submission (verdict: Time Limit Exceeded):
import math
N=int(input())
# rootを求める
root_n = int(math.sqrt(N))
up_n = root_n
up_ans = 0
keta = lambda x: len(str(x))
while up_n <= N:
  if N % up_n == 0:
    pair = int(N/up_n)
    # 桁数を求める
    up_ans = max(keta(pair), keta(up_n))
    break
  else:
    up_n+=1

print(up_ans)



Fixed submission:
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)

    # divisors.sort()
    return divisors

import math
N=int(input())
INF = 3000000
# rootを求める
# 二分探索すればいいのか！！！
ans = INF
pairs = make_divisors(N)
keta = lambda x: len(str(x))
for pair in pairs:
  tmp_ans = max(keta(pair), keta(int(N/pair)))
  ans = min(ans,tmp_ans)

print(ans)

# root_n = int(math.sqrt(N))
# up_n = root_n
# up_ans = 0

# while up_n <= N:
#   if N % up_n == 0:
#     pair = int(N/up_n)
#     # 桁数を求める
    
#     break
#   else:
#     up_n+=1

# print(up_ans)
Buggy python submission (verdict: Time Limit Exceeded):
H,W=map(int,input().split())
Grid=[]
for _ in range(H):
  Grid.append(list(input()))
tmp=0
ans=0
up=[[0 for _ in range(W)] for _ in range(H)]
down=[[0 for _ in range(W)] for _ in range(H)]
left=[[0 for _ in range(W)] for _ in range(H)]
right=[[0 for _ in range(W)] for _ in range(H)]

for i in range(H):
  for j in range(W):
    if Grid[i][j]=='.':
      left[i][j]=left[i][j-1]+1
      up[i][j]=up[i-1][j]+1
    if Grid[H-i-1][j]=='.':
      down[H-i-1][j]=down[-i][j]+1
    if Grid[i][W-j-1]=='.':
      right[i][W-j-1]=right[i][-j]+1
      
for i in range(H):
  for j in range(W):
    ans=max(ans,left[i][j]+up[i][j]+down[i][j]+right[i][j]-3)
print(ans)    

Fixed submission:
H,W=map(int,input().split())
Grid=[]
for _ in range(H):
  Grid.append(list(input()))
tmp=0
ans=0
up=[[0 for _ in range(W)] for _ in range(H)]
down=[[0 for _ in range(W)] for _ in range(H)]
left=[[0 for _ in range(W)] for _ in range(H)]
right=[[0 for _ in range(W)] for _ in range(H)]

for i in range(H):
  for j in range(W):
    if Grid[i][j]=='.':
      left[i][j]=left[i][j-1]+1
      up[i][j]=up[i-1][j]+1
    if Grid[H-i-1][j]=='.':
      down[H-i-1][j]=down[-i][j]+1
    if Grid[i][W-j-1]=='.':
      right[i][W-j-1]=right[i][-j]+1
      
for i in range(H):
  for j in range(W):
    ans=max(ans,left[i][j]+up[i][j]+down[i][j]+right[i][j]-3)
print(ans)