defmodule Main do def input, do: IO.read(:line) |> String.trim def ii, do: input() |> String.to_integer def li, do: input() |> String.split |> Enum.map(&String.to_integer/1) def yn(b), do: IO.puts (if b, do: "Yes", else: "No") def f("+", a, b, mod) do na = length(a) nb = length(b) sa = rem(Enum.sum(a), mod) sb = rem(Enum.sum(b), mod) rem(sa*nb + sb*na, mod) end def f("*", a, b, mod) do sa = rem(Enum.sum(a), mod) sb = rem(Enum.sum(b), mod) rem(sa * sb, mod) end def main do {_ok, s} = File.read("/dev/stdin") ss = s |> String.trim() |> String.split("\n") [_n, _m, k] = hd(ss) |> String.split() |> Enum.map(&String.to_integer/1) s = hd(tl(ss)) |> String.split() op = hd(s) b = tl(s) |> Enum.map(&String.to_integer/1) a = tl(tl(ss)) |> Enum.map(&String.to_integer/1) ans = f(op, a, b, k) IO.puts ans end end