// yukicoder #include #define ll long long using namespace std; int main() { ll a, b, c, d; cin >> a >> b >> c >> d; ll res = a % d; res *= b; res %= d; res *= c; res %= d; cout << res << "\n"; return 0; }