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