var
n,a,ans,now,i,b,p:longint;
function jc(x:longint):longint;
var
i,s:longint;
begin
s:=1;
for i:=1 to x do s:=s*i;
jc:=s;
end;
begin
assign(input,'sumcount.in'); reset(input);
assign(output,'sumcount.out'); rewrite(output);
readln(n,a,b,p);
ans:=0;
for i:=a to b do
begin
now:=jc(i+n-1) div (jc(i)*jc(n-1));
ans:=(ans+now) mod p;
end;
writeln(ans);
close(input);
close(output);
end.