#include typedef long long ll; #define INF 1000000000 #define MOD 1000000007 using namespace std; int main(void){ ll a,b,c,d; cin>>a>>b>>c>>d; a%=d; b%=d; c%=d; ll ans; ans=(((a*b)%d)*c)%d; cout<