CodeEff/ECCO huggingface dataset:
# Original solution
import math
a,b=list(map(int, input().split()))

if abs(a-b) == 1:
    print((math.factorial(a)*math.factorial(b)))
if abs(a-b) == 0:
    print((math.factorial(a)*math.factorial(b)*2))
if abs(a-b) >= 2:
    print((0))

# Optimized solution
import math
a,b=list(map(int, input().split()))

if abs(a-b) == 1:
    c = math.factorial(a)%(10**9+7)
    d = math.factorial(b)%(10**9+7)
    print((c*d%(10**9+7)))
if abs(a-b) == 0:
    c = math.factorial(a)%(10**9+7)
    d = math.factorial(b)%(10**9+7)
    print((c*d*2%(10**9+7)))
if abs(a-b) >= 2:
    print((0))
# Original solution
import math
mod = 10**9+7
n,m = list(map(int,input().split()))

if abs(n-m) > 1:
	print(0)
	quit()

if max(n,m) > min(n,m):
	print(math.factorial(max(n,m)) % mod * math.factorial(min(n,m)) % mod)

else :
	print((((math.factorial(n))%mod)**2 * 2)%mod)

# Optimized solution

mod = 10**9+7
n,m = list(map(int,input().split()))
def factorial(x):
	retval = 1
	for i in range(2,x+1):
		retval = (retval * i)% mod
	return retval

if abs(n-m) > 1:
	print(0)
	quit()

if max(n,m) > min(n,m):
	print((factorial(max(n,m)) * factorial(min(n,m))) % mod)

else :
	print(((factorial(n)**2)%mod * 2)%mod)
# Original solution
n, m = list(map(int, input().split()))
MOD = 1000000007
a, b = n, m
count_n = n
count_m =m
count = 0
if abs(n-m) == 1:
  for _ in range(n-1):
    n -= 1
    count_n *= (n % MOD)
  for _ in range(m-1):
    m -= 1
    count_m *= (m % MOD)
  count = (count_m % MOD) * (count_n % MOD)
elif abs(n-m) == 0:
  for _ in range(n-1):
    n -= 1
    count_n *= (n % MOD)
  for _ in range(m-1):
    m -= 1
    count_m *= (m % MOD)
  count = 2 * (count_m % MOD) * (count_n % MOD)
  count %= MOD
else:
  count = 0

print(count)

# Optimized solution
import math
n, m = list(map(int, input().split()))
MOD = 1000000007
count_n = 0
count_m = 0
count = 0
if abs(n-m) == 1:
  count_n = math.factorial(n) % MOD
  count_m = math.factorial(m) % MOD
  count = count_m * count_n % MOD
elif abs(n-m) == 0:
  count_n = math.factorial(n) % MOD
  count_m = math.factorial(m) % MOD
  count = 2 * count_m * count_n % MOD
else:
  count = 0

print((count % MOD))
# Original solution
import math
n, m = list(map(int, input().split()))
MOD = 1000000007
count_n = 0
count_m = 0
count = 0
if abs(n-m) == 1:
  count_n = math.factorial(n) % MOD
  count_m = math.factorial(m) % MOD
  count = count_m * count_n % MOD
elif abs(n-m) == 0:
  count_n = math.factorial(n) % MOD
  count_m = math.factorial(m) % MOD
  count = 2 * count_m * count_n % MOD
else:
  count = 0

print((count % MOD))

# Optimized solution
import math
N, M = list(map(int, input().split()))
mod = 10**9+7

if abs(N-M) > 1:
  print((0))
  exit()

if N < M:
  N, M = M, N

if N == M:
  ans = math.factorial(N)
  ans %= mod
  ans *= math.factorial(M)
  ans %= mod
  ans *= 2
  ans %= mod
else:
  ans = math.factorial(M)
  ans %= mod
  ans *= math.factorial(N)
  ans %= mod
  

print(ans)
# Original solution
n, m = list(map(int, input().split()))
ans = 1
if n==m:
    for i in range(1, n+1):
        ans *= i
        ans %= 10**9+7
    print(((ans**2*2)%(10**9+7)))
elif abs(n-m)==1:
    for i in range(1, n+1):
        ans *= i
        ans %= 10**9+7
    for i in range(1, m+1):
        ans *= i
        ans %= 10**9+7
    print((ans%(10**9+7)))
else:
    print((0))

# Optimized solution
n, m = list(map(int, input().split()))
ans = 1
mod = 10**9+7
if n==m:
    for i in range(1, n+1):
        ans *= i
        ans %= mod
    print(((ans**2*2)%mod))
elif abs(n-m)==1:
    for i in range(1, n+1):
        ans *= i
        ans %= mod
    for i in range(1, m+1):
        ans *= i
        ans %= mod
    print(ans)
else:
    print((0))
# Original solution
n, m = list(map(int, input().split()))
ans = 1
mod = 10**9+7
a = lambda x, y: x*y % mod
if n==m:
    for i in range(1, n+1):
        ans = a(ans, i)
    print(((ans**2*2)%(mod)))
elif abs(n-m)==1:
    for i in range(1, n+1):
        ans = a(ans, i)
    for i in range(1, m+1):
        ans = a(ans, i)
    print(ans)
else:
    print((0))

# Optimized solution
n, m = list(map(int, input().split()))
ans = 1
mod = 10**9+7
def a(x, y):
    return x*y%mod

if n==m:
    for i in range(1, n+1):
        ans = a(ans, i)
    print(((ans**2*2)%(mod)))
elif abs(n-m)==1:
    for i in range(1, n+1):
        ans = a(ans, i)
    for i in range(1, m+1):
        ans = a(ans, i)
    print(ans)
else:
    print((0))
# Original solution
def frac(n):
  sum = 1
  for i in range(1,n+1):
    sum*=i
  return sum

import sys,fractions
N,M=list(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)))

# Optimized solution
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=list(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)))
# Original solution
def 解():
    iN,iM = [int(_) for _ in input().split()]
    iD = 10**9+7

    if abs(iN - iM) <= 1:
        if iN < iM:
            iN,iM = iM,iN
        iFacM = 1
        for i in range(1,iM+1):
            iFacM *= i
            iFacM %=iD
        if iN == iM:
            print(( iFacM * iFacM % iD * 2 % iD ))
        else:
            iFacN = iFacM
            for i in range(iM+1,iN+1):
                iFacN *= i
                iFacN %=iD
            print(( iFacM * iFacN % iD  ))
    else:
        print((0))
解()


# Optimized solution
def 解():
    iN,iM = [int(_) for _ in input().split()]
    iD = 10**9+7

    if abs(iN - iM) <= 1:
        if iN < iM:
            iN,iM = iM,iN
        iFacM = 1
        for i in range(1,iM+1):
            iFacM *= i
            iFacM %=iD
        if iN == iM:
            print(( iFacM ** 2 % iD * 2 % iD ))
        else:
            #うーむ。たしかに。差分が1だからNかけるだけでいいわけだ。
            print(( iFacM ** 2 % iD * iN % iD  ))
    else:
        print((0))
解()
# Original solution
# -*- coding: utf-8 -*-

from math import factorial

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


def solve(m, n):
    if m > n:
        m, n = n, m
    if n - m > 1:
        return 0
    fct = factorial(m)
    if n - m == 1:
        return fct ** 2 * n
    else:  # n - m == 0
        return fct ** 2 * 2


mod = 10 ** 9 + 7
ans = solve(m, n) % mod
print(ans)


# Optimized solution
# -*- coding: utf-8 -*-

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

mod = 10 ** 9 + 7


def factorial(x):
    ret = 1
    for i in range(1, x + 1):
        ret *= i
        ret %= mod

    return ret


def solve(m, n):
    if m > n:
        m, n = n, m
    if n - m > 1:
        return 0
    fct = factorial(m)
    if n - m == 1:
        return fct ** 2 * n % mod
    else:  # n - m == 0
        return fct ** 2 * 2 % mod


ans = solve(m, n)
print(ans)
# Original solution
N, M = list(map(int, input().split()))

a = 1
b = 1
if N == M:
    for i in range(1,N+1):
        a *= i % 1000000007
    b = a

elif N - M == 1:
    for i in range(1,M+1):
        b *= i % 1000000007
    a = b * N 
elif M - N == 1:
    for i in range(1,N+1):
        a *= i % 1000000007
    b = a * M 
    

if abs(N-M) == 1:
    ans = a * b %1000000007
elif N == M:
    ans = 2*a*b % 1000000007
else:
    ans = 0

print(ans)

# Optimized solution
import math
import time

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

st = time.time()

a = math.factorial(N) % 1000000007
b = math.factorial(M) % 1000000007
"""
if N == M:
    for i in range(1,N+1):
        a *= i % 1000000007
    b = a

elif N - M == 1:
    for i in range(1,M+1):
        b *= i % 1000000007
    a = b * N 
elif M - N == 1:
    for i in range(1,N+1):
        a *= i % 1000000007
    b = a * M 
"""

if abs(N-M) == 1:
    ans = a * b %1000000007
elif N == M:
    ans = 2*a*b % 1000000007
else:
    ans = 0

print(ans)

ed = time.time() -st
#print(ed)
# Original solution
n,m=list(map(int,input().split()))
div=10**9+7
if abs(n-m)>1:
  print((0))
else:
  ans=1
  for i in range(1,n+1):
    ans=ans*i%div
  for i in range(1,m+1):
    ans=ans*i%div
  if n==m:
    ans*=2
  print((ans%div))

# Optimized solution
n,m=list(map(int,input().split()))
div=10**9+7
if abs(n-m)>1:
  print((0))
else:
  ans=1
  for i in range(1,min(m,n)+1):
    ans=ans*i%div
  ans*=ans
  if n!=m:
    ans*=max(m,n)
  if n==m:
    ans*=2
  print((ans%div))
# Original solution
import math
n,m=list(map(int,input().split()))
ans=math.factorial(m)*math.factorial(n)
if n==m:
  ans*=2
elif abs(n-m)>1:
  ans=0
print(ans)


# Optimized solution
import math
n,m=list(map(int,input().split()))
ans=math.factorial(m)*math.factorial(n)%(10**9+7)
if n==m:
  ans*=2
  ans%=(10**9+7)
elif abs(n-m)>1:
  ans=0
print(ans)
# Original solution
import sys
readline = sys.stdin.readline
from math import factorial
MOD = 10 ** 9 + 7

def main():
    N, M = list(map(int, readline().rstrip().split()))
    if abs(N-M) > 1:
        ans = 0
    elif N == M:
        ans = (factorial(N) % MOD) * (factorial(M) % MOD) * 2
    else:
        ans = (factorial(N) % MOD) * (factorial(M) % MOD)

    print((ans % MOD))


if __name__ == '__main__':
    main()

# Optimized solution
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7

def factorial(N, mod=MOD):
    res = 1
    for i in range(2, N+1):
        res *= i
        res %= mod
    return res

def main():
    N, M = list(map(int, readline().rstrip().split()))
    if abs(N-M) > 1:
        ans = 0
    elif N == M:
        ans = factorial(N) * factorial(M) * 2
    else:
        ans = factorial(N) * factorial(M)

    print((ans % MOD))


if __name__ == '__main__':
    main()
# Original solution
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7

def factorial(N, mod=MOD):
    res = 1
    for i in range(2, N+1):
        res *= i
        res %= mod
    return res

def main():
    N, M = list(map(int, readline().rstrip().split()))
    if abs(N-M) > 1:
        ans = 0
    elif N == M:
        ans = factorial(N) * factorial(M) * 2
    else:
        ans = factorial(N) * factorial(M)

    print((ans % MOD))


if __name__ == '__main__':
    main()

# Optimized solution
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7

def factorial(N, mod=MOD):
    res = 1
    for i in range(2, N+1):
        res *= i
        res %= mod
    return res

def main():
    N, M = list(map(int, readline().rstrip().split()))
    if abs(N-M) > 1:
        ans = 0
    elif N == M:
        ans = factorial(N) ** 2 * 2
    else:
        ans = factorial(min(N, M)) ** 2 * max(N, M)

    print((ans % MOD))


if __name__ == '__main__':
    main()
# Original solution
n,m = list(map(int,input().split()))
lst = [0]
for i in range(n - 1):
  lst.append(lst[-1] + int(eval(input())))
ans = 0
num = 0
for i in range(m):
  a = int(eval(input()))
  ans += abs(lst[num] - lst[num + a])
  ans %= 100000
  num += a
print(ans)



# Optimized solution
def solve():
  n,m = list(map(int,input().split()))
  lst = [0]
  for i in range(n - 1):
    lst.append(lst[-1] + int(eval(input())))
  ans = 0
  num = 0
  for i in range(m):
    a = int(eval(input()))
    ans += abs(lst[num] - lst[num + a])
    num += a
  print((ans % 100000))
solve()
# Original solution
def solve(n):
	ans=0
	for a in range(int(n/4)+1):
		for b in range(a,int(n/3)+1):
			if b>1000:
				break
			for c in range(b,int(n/2)+1):
				if c>1000:
					break
				d=n-(a+b+c)
				if d>=c:
					if a==b==c==d:
						ans+=1#4!/4!
					elif a==b==c or b==c==d:
						ans+=4#4!/3!
					elif a==b and c==d:
						ans+=6#4!/(2!*2!)
					elif (a==b and c!=d) or (b==c) or (a!=b and c==d):
						ans+=12#4!/2!
					else:
						ans+=24#4!
				else:
					break
	return ans 


while True:
	try:
		n=int(eval(input()))
		print((solve(n)))
	except EOFError:
		break

# Optimized solution
M = 1000
DM = M * 2 + 1
 
def count(n):
    global M
    res = n + 1
    if n > M:
        res -= (n-M) * 2
    return res
 
def solve(n):
    cnt = 0
    for a in range(min(DM, n), -1, -1):
        b = n - a
        if b > DM:
            break
        cnt += count(a) * count(b)
    return cnt
 
while True:
    try:
        l = eval(input())
    except EOFError:
        break
    nm = int(l)
    print((solve(nm)))
# Original solution
b=[0]*2001
for i in range(1001):
    for j in range(1001):
        b[i+j]+=1
while 1:
    try:n=int(eval(input()))
    except:break
    c=0;a=[1000,n][n<1000]
    for i in range(2*a+1):
        for j in range(2*a+1):
            if i+j==n:c+=b[i]*b[j]
    print(c)

# Optimized solution
s=[0]*4001
for i in range(2001):
    a=a+2*(i-999)*(i-1000) if i>1000 else 0
    s[i]=(i+3)*(i+2)*-~i//6-a
    s[4000-i]=s[i]
while 1:
    try:print((s[int(eval(input()))]))
    except:break
# Original solution
import sys
a=[0]*4001
for i in range(1999):a[i]=a[4000-i]=(i+3)*(i+2)*(i+1)//6-a[i-1001]*4*(i>999)
for e in sys.stdin:print((a[int(e)]))


# Optimized solution
import sys
a=[0]*4001
for i in range(2001):a[i]=a[4000-i]=(i+3)*(i+2)*(i+1)//6-a[i-1001]*4*(i>999)
for e in sys.stdin:print((a[int(e)]))
# Original solution
from collections import Counter

two_dict = Counter()

for i in range(1001):
  for j in range(1001):
    two_dict[i + j] += 1

while True:
  try:
    n = int(eval(input()))
    ans = 0
    for i in range(n + 1):
      ans += two_dict[i] * two_dict[n - i]
    print(ans)

  except EOFError:
    break



# Optimized solution
from collections import Counter

pair_dict = Counter()
for i in range(2001):
  pair_dict[i] = min(i, 2000 - i) + 1 

while True:
  try:
    n = int(eval(input()))
    ans = 0
    for i in range(n + 1):
      ans += pair_dict[i] * pair_dict[n - i]
    print(ans)

  except EOFError:
    break
# Original solution
# -*- coding: utf-8 -*-

import sys
import os

for s in sys.stdin:
    n = int(s)

    T = [0] * 2001
    for a in range(1001):
        for b in range(1001):
            T[a+b] += 1

    sum_n_num = 0
    for a_b_sum in range(0, n+1):
        c_d_sum = n - a_b_sum
        if a_b_sum <= 2000 and c_d_sum <= 2000:
            sum_n_num += T[a_b_sum] * T[c_d_sum]

    print(sum_n_num)

# Optimized solution
# -*- coding: utf-8 -*-

import sys
import os
import math

T = [0] * 2001
for a in range(1001):
    for b in range(1001):
        T[a + b] += 1

for s in sys.stdin:
    n = int(s)

    sum_n_num = 0
    for a_b_sum in range(0, n+1):
        c_d_sum = n - a_b_sum
        if a_b_sum <= 2000 and c_d_sum <= 2000:
            sum_n_num += T[a_b_sum] * T[c_d_sum]

    print(sum_n_num)
# Original solution
while True:
    try:
        n = int(input())
        count = 0
        for a in range(1000,-1,-1):
             if 0 <= n - a <= 3000:
                for b in range(1000,-1,-1):
                    if n - a - b > 2000:
                        break
                    elif 0 <= n - a - b <= 1000:
                        count += n-a-b+1
                    elif 1001 < n - a - b <= 2000:
                        count += (2000 - (n-a-b) + 1)
        print(count)
    except:
        break

# Optimized solution
while True:
    try:
        n = int(input())
        count = 0
        for a in range(1000,-1,-1):
            na = n - a
            if 3000 < na:
                break
            elif 0 <= na <= 3000:
                for b in range(1000,-1,-1):
                    nab = n - a - b
                    if nab > 2000:
                        break
                    elif 0 <= nab <= 1000:
                        count += nab+1
                    elif 1001 < nab <= 2000:
                        count += (2000 - nab + 1)
        print(count)
    except:
        break
# Original solution
T = 1000
memo = [[0] * (2 * T + 1) for _ in range(3)] 
#Java: int[][] memo = new int[3][2*T+1];
memo[0][0] = 1
for i in range(1,3):
    for j in range(i*T+1):
        memo[i][j] = sum([memo[i-1][k] for k in range(max(0,j-T),j+1)])

while True:
    try:
        n = eval(input()) 
    except EOFError:
        break
    cnt = 0
    for a in range(T+1):
        for b in range(T+1):
            cnt += memo[2][n-(a+b)] if 0 <= n - (a + b) <= 2 * T else 0 
            # 0 <= n - (a + b) <= 2 * T ? memo[n-(a+b)] : 0
    print(cnt)

#O(T^2), 2.15s

# Optimized solution
T = 1000
N = 4000
dp = [[0] * (N + 1) for _ in range(5)] 
#Java: int[][] dp = new int[5][N];
dp[0][0] = 1
for i in range(1,5):
    for j in range(i*T+1):
        dp[i][j] = sum([dp[i-1][k] for k in range(max(0,j-T),j+1)])

while True:
    try:
        n = eval(input()) 
    except EOFError:
        break
    print(dp[4][n])

#O(T^2), 0.954
# Original solution
T = 1000
N = 4000
dp = [[0] * (N + 1) for _ in range(5)] 
#Java: int[][] dp = new int[5][N];
dp[0][0] = 1
for i in range(1,5):
    for j in range(i*T+1):
        dp[i][j] = sum([dp[i-1][k] for k in range(max(0,j-T),j+1)])

while True:
    try:
        n = eval(input()) 
    except EOFError:
        break
    print(dp[4][n])

#O(T^2), 0.954

# Optimized solution
T = 1000
def f(x):
    return max(0, T + 1 - abs(T - x))
while True:
    try:
        n = eval(input()) 
    except EOFError:
        break
    cnt = 0
    for i in range(n+1):
        cnt += f(i) * f(n-i)
    print(cnt)

#O(n),
# Original solution
# -*- coding: utf-8 -*-
"""
Sum of 4 Integers II
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0096

"""
import sys
from sys import stdin
from collections import defaultdict
input = stdin.readline


def main(args):
    lut = defaultdict(list)
    for a in range(1001):
        for b in range(1001):
            lut[a+b].append((a, b))

    for line in sys.stdin:
        n = int(line)
        ans = 0
        for i in range(n+1):
            for a, b in lut[i]:
                for c, d in lut[n-i]:
                    ans += 1
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])



# Optimized solution
# -*- coding: utf-8 -*-
"""
Sum of 4 Integers II
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0096

"""
import sys
from sys import stdin
from collections import defaultdict
input = stdin.readline


def main(args):
    lut = defaultdict(int)
    for a in range(1001):
        for b in range(1001):
            lut[a+b] += 1

    for line in sys.stdin:
        n = int(line)
        ans = 0
        for i in range(n+1):
            ans += lut[i] * lut[n-i]
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
# Original solution
import sys
a=[0]*2001
b=[0]*4001
n=1001
for i in range(n):
  for j in range(n):
    a[i+j]+=1
n=2001
for i in range(n):
  for j in range(n):
    b[i+j]+=a[i]*a[j]
for i in sys.stdin:
  print(b[int(i)])

# Optimized solution
import sys

n=1001
a=[0]*2001
for i in range(n):
  for j in range(n):
    a[i+j]+=1
for n in map(int,sys.stdin):
  x=0
  for i in range(max(0,n-2000),min(n,2000)+1):
    x+=a[i]*a[n-i]
  print(x)
# Original solution
import sys

n=1001
a=[0]*2001
for i in range(n):
  for j in range(n):
    a[i+j]+=1
for n in map(int,sys.stdin):
  x=0
  for i in range(max(0,n-2000),min(n,2000)+1):
    x+=a[i]*a[n-i]
  print(x)

# Optimized solution
import sys
n=1001
a=list(range(1,n))
a+=[n]+a[::-1]
for n in map(int,sys.stdin):
  x=0
  for i in range(max(0,n-2000),min(n,2000)+1):
    x+=a[i]*a[n-i]
  print(x)
# Original solution
import sys
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

s = LS2()
a = ''.join(s[0:5])
b = ''.join(s[6:13])
c = ''.join(s[14:19])
print(('{} {} {}'.format(a,b,c)))


# Optimized solution
import sys
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

s = LS2()
s[5] = ' '
s[13] = ' '
print((''.join(s)))
# Original solution
s = list( map( str, input().split(",") ) )
print(( s[0] + " " + s[1] + " " + s[2] )) 

# Optimized solution
print(( input().replace( ",", " " ) ))
# Original solution
print((input().replace(',', ' ')))

# Optimized solution
*S, = input()
S[5] = S[13] = ' '
print(*S, sep='')
# Original solution
s = input().split(",")
s = " ".join(s)
print(s)

# Optimized solution
S = input().strip()
x = S[:5]+" "+S[6:13]+" "+S[14:]
print(x)
# Original solution
s1, s2, s3 = input().split(',')
print((s1 + ' ' + s2 + ' ' + s3))

# Optimized solution
s = list(input().split(','))
print((' '.join(s)))
# Original solution
L,R = list(map(int,input().split()))

mod = 10**9+7
m = 64 +1
fac = [1]*m
ninv = [1]*m
finv = [1]*m
for i in range(2,m):
    fac[i] = fac[i-1]*i%mod
    ninv[i] = (-(mod//i)*ninv[mod%i])%mod
    finv[i] = finv[i-1]*ninv[i]%mod

def comb(n,k):
    return (fac[n]*finv[k]%mod)*finv[n-k]%mod

def f(L,R):
    if L>R : return 0
    R = bin(R)[2:]
    N = len(R)
    ret = f(L,int("0"+"1"*(N-1),2))
    L = bin(L)[2:]
    if len(L) != N : L = "1"+"0"*(N-1)
    for i in range(N):
        if R[i] == "0" : continue
        R2 = R[:i] + "0" + "?"*(N-i-1)
        if i==0: R2 = R
        for j in range(N):
            if L[j] == "1" and j!=0 : continue
            L2 = L[:j] + "1" + "?"*(N-j-1)
            if j==0 : L2 = L
            if L2[0] == "0" : break
            tmp = 1
            for r,l in zip(R2[1:],L2[1:]):
                if r=="0" and l=="1" : tmp *= 0
                if r=="?" and l=="?" : tmp *= 3
                if r=="?" and l=="0" : tmp *= 2
                if r=="1" and l=="?" : tmp *= 2
                tmp %= mod
            ret += tmp
            ret %= mod
    return ret%mod

print((f(L,R)))

# Optimized solution
L,R = list(map(int,input().split()))

mod = 10**9+7

def f(L,R):
    if L>R : return 0
    R = bin(R)[2:]
    N = len(R)
    ret = f(L,int("0"+"1"*(N-1),2))
    L = bin(L)[2:]
    if len(L) != N : L = "1"+"0"*(N-1)
    for i in range(N):
        if R[i] == "0" : continue
        R2 = R[:i] + "0" + "?"*(N-i-1)
        if i==0: R2 = R
        for j in range(N):
            if L[j] == "1" and j!=0 : continue
            L2 = L[:j] + "1" + "?"*(N-j-1)
            if j==0 : L2 = L
            if L2[0] == "0" : break
            tmp = 1
            for r,l in zip(R2[1:],L2[1:]):
                if r=="0" and l=="1" : tmp *= 0 ; break
                if r=="?" and l=="?" : tmp = tmp*3%mod
                if r=="?" and l=="0" : tmp = tmp*2%mod
                if r=="1" and l=="?" : tmp = tmp*2%mod
            ret += tmp
            ret %= mod
    return ret

print((f(L,R)))
# Original solution
L,R = list(map(int,input().split()))

mod = 10**9+7

def f(L,R):
    if L>R : return 0
    R = bin(R)[2:]
    N = len(R)
    ret = f(L,int("0"+"1"*(N-1),2))
    L = bin(L)[2:]
    if len(L) != N : L = "1"+"0"*(N-1)
    for i in range(N):
        if R[i] == "0" : continue
        R2 = R[:i] + "0" + "?"*(N-i-1)
        if i==0: R2 = R
        for j in range(N):
            if L[j] == "1" and j!=0 : continue
            L2 = L[:j] + "1" + "?"*(N-j-1)
            if j==0 : L2 = L
            if L2[0] == "0" : break
            tmp = 1
            for r,l in zip(R2[1:],L2[1:]):
                if r=="0" and l=="1" : tmp *= 0 ; break
                if r=="?" and l=="?" : tmp = tmp*3%mod
                if r=="?" and l=="0" : tmp = tmp*2%mod
                if r=="1" and l=="?" : tmp = tmp*2%mod
            ret += tmp
            ret %= mod
    return ret

print((f(L,R)))

# Optimized solution
L,R = list(map(int,input().split()))

mod = 10**9+7

def f(L,R):
    if L>R : return 0
    R = bin(R)[2:]
    N = len(R)
    ret = f(L,int("0"+"1"*(N-1),2))
    L = bin(L)[2:]
    if len(L) != N : L = "1"+"0"*(N-1)
    for i in range(N):
        if R[i] == "0" : continue
        R2 = R[:i] + "0" + "?"*(N-i-1)
        if i==0: R2 = R
        for j in range(N):
            if L[j] == "1" and j!=0 : continue
            L2 = L[:j] + "1" + "?"*(N-j-1)
            if j==0 : L2 = L
            tmp = 1
            for r,l in zip(R2,L2):
                if r=="0" and l=="1" : tmp *= 0 ; break
                elif r=="?" and l=="?" : tmp = tmp*3%mod
                elif r=="?" and l=="0" : tmp = tmp*2%mod
                elif r=="1" and l=="?" : tmp = tmp*2%mod
            ret += tmp
            ret %= mod
    return ret

print((f(L,R)))