#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long int ll; typedef pair pii; typedef pair pll; typedef vector vi; #define rep(i,x) for(int i=0;i<(int)(x);++i) #define reps(i,x) for(int i=1;i<=(int)(x);++i) #define pb push_back int a, b, c, d; int main(){ ios::sync_with_stdio(false); cin >> a >> b >> c >> d; cout << (a%d) * (b%d) * c % d << endl; return 0; }