Scanf.scanf "%d %d" (fun n m ->
    let mm = 1_000_000_007 in
    let ( +@) a b = (((a + b) mod mm) + mm) mod mm in
    let ( *@) a b = (a * b) mod mm in
    let calc lim =
        Scanf.scanf " %d" (fun offset ->
            let rec loop i coeff acc =
                if i = lim then acc else
                    let acc = acc +@ coeff *@ Scanf.scanf " %d" (fun x -> x - offset) in
                    loop (i + 1) (coeff + 2) acc
            in
            loop 1 (3 - lim) 0
        )
    in
    Printf.printf "%d\n" @@ (calc m *@ calc n)
)