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