const reader = require("readline").createInterface({ input: process.stdin, output: process.stdout }); let lines = []; reader.on("line", line => lines.push(line)); reader.on("close", () => { const [a, b, c, d] = lines[0].split(' ').map(x => parseInt(x)); console.log((a % d) * (b % d) % d * (c % d) % d); });