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