defmodule Main do def main do toi = &String.to_integer/1 split = &String.split/1 [n, m, k] = IO.gets("") |> split.() |> Enum.map(toi) [op | b] = IO.gets("") |> split.() b = Enum.map(b, toi) |> Enum.sum() |> (&rem(&1,k)).() Enum.map(1..n, fn _ -> a = IO.gets("") |> String.trim |> toi.() if op == "+", do: rem(a*m + b, k), else: rem(a * b, k) end) |> Enum.sum |> (&rem(&1, k)).() |> IO.puts end end