let [| A; B; C; D |] = stdin.ReadLine().Split(' ') |> Array.map int let n = [A;B;C] |> List.fold (fun acc n -> acc * (n % D)) 1 printfn "%d" <| n % D