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