local ffi = require 'ffi' local C = ffi.C ffi.cdef 'int printf(const char *, ...);' C.printf("%ld\n", (function (a, b, c, d) a,b,c,d = a%d+0ULL,b%d+0ULL,c%d+0ULL,d+0ULL return (((a*b)%d)*c)%d end)(io.stdin:read("*n"), io.stdin:read("*n"), io.stdin:read("*n"), io.stdin:read("*n")))