const lines = require('fs') .readFileSync('/dev/stdin', 'utf-8') .trim().split('\n').values(); const [A, B, C, D] = lines.next().value.split(' ').map(x => BigInt(x)); const ans = [A, B, C].reduce((a, x) => (a * x) % D, 1n); console.log(ans.toString());