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