#include using namespace std; #define LL long long int main() { LL a, b, c, d; cin >> a >> b >> c >> d; LL ans = a % d; ans = (ans * (b % d)) % d; ans = (ans * (c % d)) % d; cout << ans << endl; return 0; }