#include using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); unsigned long long A, B, C, D; cin >> A >> B >> C >> D; cout << (((A%D)*(B%D))%D * (C%D)) % D << endl; return 0; }