let [|n; m; k|] = stdin.ReadLine().Split " " |> Array.map int64 let x = stdin.ReadLine().Split " " let op = x.[0] let b = x.[1..] |> Array.map int64 let a = [| for _ in 0..(n-1L |> int) -> stdin.ReadLine () |> int64 |] if op = "+" then let f a = Array.reduce (fun x y -> (x + y) % k) >> (fun x -> (x * a) % k) ((a |> f m) + (b |> f n)) % k else let f = Array.reduce (fun x y -> (x + y) % k) ((a |> f) * (b |> f)) % (int64 k) |> printfn "%d"