program sumcount;
var
f:array[0..1,0..1000000] of longint;
n,a,b,p,i,j,ans,h:longint;
begin
assign(input,'sumcount.in');
reset(input);
assign(output,'sumcount.out');
rewrite(output);
readln(n,a,b,p);
f[0,0]:=1;
h:=0;
for i:=1 to n do
begin
h:=1-h;
for j:=0 to b do
f[h,j]:=(f[1-h,j]+f[h,j-1]) mod p;
end;
ans:=0;
for i:=a to b do
ans:=(ans+f[h,i]) mod p;
writeln(ans);
close(input);
close(output);
end.