{-# LANGUAGE MultiWayIf #-}

import Control.Monad

factorial 0 = 1
factorial 10000 = 531950728
factorial 20000 = 368774859
factorial 30000 = 548996970
factorial 40000 = 422550956
factorial 50000 = 737935835
factorial 60000 = 309944332
factorial 70000 = 296716438
factorial 80000 = 65533322
factorial 90000 = 851076783
factorial 100000 = 457992974
factorial 110000 = 559938709
factorial 120000 = 118586228
factorial 130000 = 177829816
factorial 140000 = 830760447
factorial 150000 = 240586351
factorial 160000 = 611862881
factorial 170000 = 267145356
factorial 180000 = 334356152
factorial 190000 = 706226766
factorial 200000 = 107146451
factorial 210000 = 469491375
factorial 220000 = 469619345
factorial 230000 = 630906046
factorial 240000 = 658967159
factorial 250000 = 50180518
factorial 260000 = 287209856
factorial 270000 = 372045574
factorial 280000 = 702584502
factorial 290000 = 210306242
factorial 300000 = 373281933
factorial 310000 = 330131954
factorial 320000 = 179035946
factorial 330000 = 642845435
factorial 340000 = 293008185
factorial 350000 = 889591949
factorial 360000 = 832275593
factorial 370000 = 783222990
factorial 380000 = 698245208
factorial 390000 = 968856847
factorial 400000 = 559805077
factorial 410000 = 612250579
factorial 420000 = 425371772
factorial 430000 = 408721018
factorial 440000 = 227278675
factorial 450000 = 231684727
factorial 460000 = 711739673
factorial 470000 = 93615261
factorial 480000 = 795156156
factorial 490000 = 111810641
factorial 500000 = 154425679
factorial 510000 = 950741508
factorial 520000 = 384634755
factorial 530000 = 797824545
factorial 540000 = 581839401
factorial 550000 = 899281002
factorial 560000 = 343434222
factorial 570000 = 924042332
factorial 580000 = 973241307
factorial 590000 = 253333132
factorial 600000 = 679209364
factorial 610000 = 663967499
factorial 620000 = 840761205
factorial 630000 = 567656070
factorial 640000 = 152546903
factorial 650000 = 44613330
factorial 660000 = 82447511
factorial 670000 = 402958911
factorial 680000 = 571952764
factorial 690000 = 757842436
factorial 700000 = 526226141
factorial 710000 = 184978106
factorial 720000 = 402043945
factorial 730000 = 99111089
factorial 740000 = 19484938
factorial 750000 = 419049924
factorial 760000 = 253026585
factorial 770000 = 713158286
factorial 780000 = 874682245
factorial 790000 = 220437571
factorial 800000 = 644158465
factorial 810000 = 63869907
factorial 820000 = 114643102
factorial 830000 = 972816308
factorial 840000 = 728256514
factorial 850000 = 963945752
factorial 860000 = 933338751
factorial 870000 = 18380550
factorial 880000 = 857887831
factorial 890000 = 720850066
factorial 900000 = 730342129
factorial 910000 = 178869710
factorial 920000 = 711198175
factorial 930000 = 194146825
factorial 940000 = 768522507
factorial 950000 = 643362481
factorial 960000 = 281968565
factorial 970000 = 947088120
factorial 980000 = 949574384
factorial 990000 = 121835953
factorial 1000000 = 641102369
factorial x = (x `mod` 1000000007) * factorial (x-1)

main = do
  [n,m] <- map read.words <$> getLine :: IO [Integer]
  if | abs(n-m) > 1 -> print 0
     | n == m -> print $ 2 * ((factorial n `mod` 1000000007) ^ 2) `mod` 1000000007
     | otherwise -> print $ (factorial n `mod` 1000000007) * (factorial m `mod` 1000000007) `mod` 1000000007


Measured memory_bytes: 2428