var
f:array[0..500,0..500]of int64;
n,a,b,p,i:longint;
ans:int64;
function dfs(i,j:longint):int64;
var
k:longint;
begin
if f[i,j]>0 then exit(f[i,j]);
if j=1 then exit(1);
dfs:=0;
for k:=0 to i do
dfs:=dfs+dfs(i-k,j-1);
dfs:=dfs mod p;
f[i,j]:=dfs;
end;
begin
assign(input,'sumcount.in');reset(input);
assign(output,'sumcount.out');rewrite(output);
read(n,a,b,p);
for i:=a to b do
ans:=(ans+dfs(i,n)) mod p;
writeln(ans);
close(input);close(output);
end.