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