#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int main(){ int i, j; long a, b, c, d; cin >> a >> b >> c >> d; a %= d; b %= d; c %= d; long long ans = 0, num = 1; if (a >= d || b >= d || c >= d) { if (a >= d) { num *= a; } if (b >= d) { num *= b; } if (c >= d) { num *= c; } cout << num%d << endl; return 0; } else { if (a + b + c >= d) { ans = (a + b + c) % d; } else { ans = a + b + c; } } cout << ans << endl; getchar(); getchar(); return 0; }