let [| A; B; C; D |] = stdin.ReadLine().Split(' ') |> Array.map int64 printfn "%d" <| A * B % D * C % D