#include using namespace std; int main() { long int x, y, z, n; cin >> x >> y >> z >> n; cout << (x + y + z) % n << endl; }