#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
long long n,A,B,p,i,j,k,ans=0;
long long f[3002][3002];
int main()
{
freopen("sumcount.in","r",stdin);
freopen("sumcount.out","w",stdout);
scanf("%d%d%d%d",&n,&A,&B,&p);
for (i=0;i<=n;i++)
f[i][0]=1;
for (i=1;i<=n;i++)
for (j=1;j<=B;j++)
f[i][j]=(f[i-1][j]+f[i][j-1])%p;
for (i=A;i<=B;i++)
ans=(ans+f[n][i])%p;
printf("%d\n",ans);
return 0;
}