#include using namespace std; typedef long long ll; int main(){ ll a,b,c,d,x,y,z; cin>>a>>b>>c>>d; x=a+b; x%=d; y=c; y%=d; z=x+y; z%=d; cout<