Scanf.scanf "%d %d" (fun n m ->
    let a, b = min n m, max n m in
    let z = 1000000007 in
    let ( *@) a b = (a * b) mod z in
    let fact k =
        let rec loop i acc =
            if i = 0 then acc else loop (i - 1) (acc *@ i)
        in
        loop k 1
    in
    let c = fact a in
    Printf.printf "%d\n" @@
        if a = b then 2 *@ c *@ c else
        if a + 1 = b then c *@ c *@ b else 0
)