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