#include #include #include #include #include #include #include #include #include #include #include using namespace std; #define ll long long #define INF (1 << 30) #define INFLL (1LL << 60) int main() { ll a,b,c,d; cin >> a >> b >> c >> d; cout << (a + b) * c % d << endl; return 0; }