stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<set>

#include<map>

#include<stack>

#include<queue>

#include<deque>

#include<cmath>

#include<cstdio>

#include<cctype>

#include<string>

#include<vector>

#include<cstdlib>

#include<cstring>

#include<sstream>

#include<iostream>

#include<algorithm>

#define MAXN 1000

#define hlq 1000000007



using namespace std;

int c,d,C[MAXN+8][MAXN+8],dp[MAXN+8][MAXN+8],fac[MAXN+8];

int DP(int l,int r,int res)

{

	if(res==0)

		return 1;

	if(r<l)

		return 0;

	if(~dp[r][res])

		return dp[r][res];

	dp[r][res]=DP(l,r-1,res);

	int i,k=min(d,res/r),f=1,t=res,tmp=0;

	if(c>k)

		return dp[r][res];

	for(i=1;i<c&&t>=r;i++)

	{

		f=(1LL*f*C[t][r])%hlq;

		t-=r;

	}

	for(i=c;i<=k&&t>=r;i++)

	{

		f=(1LL*f*C[t][r])%hlq;

		t-=r;

		tmp=1LL*DP(l,r-1,t)*f%hlq;

		tmp=1LL*tmp*fac[i]%hlq;

		dp[r][res]=(tmp+dp[r][res])%hlq;

	}

	return dp[r][res];

}

int pow_mod(long long a,int x)

{

	long long ans=1;

	while(x)

	{

		if(x&1)

			ans=ans*a%hlq;

		a=a*a%hlq;

		x>>=1;

	}

	return (int)ans;

}

int main()

{

	int n,a,b,i,j;

	scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);

	memset(dp,-1,sizeof(dp));

	for(i=0;i<=n;i++)

	{

		C[i][0]=1;

		for(j=1;j<=i;j++)

			C[i][j]=(C[i-1][j]+C[i-1][j-1])%hlq;

	}

	fac[0]=1;

	for(i=1;i<=n;i++)

		fac[i]=1LL*fac[i-1]*pow_mod(i,hlq-2)%hlq;

	printf("%d",DP(a,b,n));

	return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define LL long long

using namespace std;

int n,a,b,c,d;

const int N=1003;

const int mod=1e9+7;

int f[N],dp[N],C[N][N],power[N],F[N][N];



int mu(int x,int m)

{

    if (m==1) return x;

    int c=mu(x,m/2);

    c=(LL)c*c%mod;

    if (m%2==0) return c;

    return (LL)c*x%mod;

}

int main()

{

   

    ios_base::sync_with_stdio(0);

    cin.tie(0);cout.tie(0);

    cin>>n>>a>>b>>c>>d;

    dp[0]=1;

    for (int i=0;i<=n;i++) C[i][i]=C[i][0]=1;

    for (int i=2;i<=n;i++)

    for (int j=1;j<i;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;

    power[0]=1;

    for (int i=1;i<=n;i++) power[i]=((LL)power[i-1]*i)%mod;

    power[n]=mu(power[n],mod-2);

    for (int i=n-1;i>=0;i--) power[i]=(LL)power[i+1]*(i+1)%mod;

    for (int i=1;i<=n;i++) F[0][i]=1;

    for (int i=1;i<=n;i++)

    for (int j=i;j<=n;j+=i)

         F[j][i]=(LL)F[j-i][i]*C[j][i]%mod;

    for (int i=1;i<=n;i++)

    for (int j=i;j<=n;j+=i)

    {

        F[j][i]=(LL)F[j][i]*power[j/i]%mod;

        //cout<<j<<" "<<i<<" "<<F[j][i]<<"\n";

    }

    dp[0]=1;

    for (int i=a;i<=b;i++)

    {

        for (int h=0;h<=n;h++) f[h]=dp[h];

        for (int j=c;j<=d;j++)

        {

            int k=i*j;

            for (int h=k;h<=n;h++)

            {

                dp[h]=(dp[h]+((LL)f[h-k]*F[k][i]%mod)*C[n-h+k][k]%mod)%mod;

                //cout<<i<<" "<<j<<" "<<h<<" "<<dp[h]<<" "<<f[h-k]<<"\n";

            }

        }

    }

    cout<<dp[n];

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#define llint long long

#define mod 1000000007



using namespace std;



llint fact[2005], fact_i[2005];



llint pow(llint a, llint n)

{

	if(n == 0) return 1;

	if(n % 2){

		return ((a%mod) * (pow(a, n-1)%mod)) % mod;

	}

	else{

		return pow((a*a)%mod, n/2) % mod;

	}

}



void make_fact()

{

	llint val = 1;

	fact[0] = 1;

	for(int i = 1; i < 2005; i++){

		val *= i;

		val %= mod;

		fact[i] = val;

	}

	for(int i = 0; i < 2005; i++){

		fact_i[i] = pow(fact[i], mod-2);

	}

}



llint comb(llint n, llint k)

{

	llint ret = 1;

	ret *= fact[n];

	ret *= fact_i[k], ret %= mod;

	ret *= fact_i[n-k], ret %= mod;

	return ret;

}



llint N;

llint A, B, C, D;

llint dp[1005][1005];



int main(void)

{

	cin >> N;

	cin >> A >> B >> C >> D;

	make_fact();

	

	dp[0][0] = 1;

	llint val;

	for(int i = 0; i < N; i++){

		for(int j = 0; j <= N; j++){

			if(dp[i][j] == 0) continue;

			for(int k = 0; j + (i+1)*k <= N; k++){

				if(k != 0 && (i+1 < A || i+1 > B)) break;

				if(k != 0 && (k < C || k > D)) continue;

				val = 1;

				for(int l = 0; l < k; l++){

					val *= comb(N-j-(i+1)*l, i+1);

					val %= mod;

				}

				val *= fact_i[k];

				val %= mod;

				dp[i+1][j+(i+1)*k] += (dp[i][j] * val) % mod;

				dp[i+1][j+(i+1)*k] %= mod;

			}

		}

	}

	

	cout << dp[N][N] << endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <vector>

#include <utility>

#include <queue>

#include <stdio.h>

#include <math.h>

#include <algorithm>

#define llint long long

#define mod 1000000007

#define inf 1e18



using namespace std;

typedef pair<double, llint> P;

typedef pair<llint, P> E;



llint n;

llint a, b, c, d;

llint dp[1005][1005];



const int FACT_MAX = 2005;

llint fact[FACT_MAX], fact_inv[FACT_MAX];



llint modpow(llint a, llint n)

{

	if(n == 0) return 1;

	if(n % 2){

		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;

	}

	else{

		return modpow((a*a)%mod, n/2) % mod;

	}

}



void make_fact()

{

	llint val = 1;

	fact[0] = 1;

	for(int i = 1; i < FACT_MAX; i++){

		val *= i;

		val %= mod;

		fact[i] = val;

	}

	fact_inv[FACT_MAX-1] = modpow(fact[FACT_MAX-1], mod-2);

	for(int i = FACT_MAX-2; i >= 0; i--){

		fact_inv[i] = fact_inv[i+1] * (i+1) % mod;

	}

}



llint comb(llint n, llint k)

{

	llint ret = 1;

	ret *= fact[n];

	ret *= fact_inv[k], ret %= mod;

	ret *= fact_inv[n-k], ret %= mod;

	return ret;

}



int main(void)

{

	ios::sync_with_stdio(0);

	cin.tie(0);

	make_fact();

	

	cin >> n;

	cin >> a >> b >> c >> d;

	

	dp[a-1][0] = 1;

	for(int i = a-1; i < b; i++){

		for(int j = 0; j <= n; j++){

			dp[i+1][j] += dp[i][j],  dp[i+1][j] %= mod;

			llint mul = 1;

			for(int k = 1; k <= d && j+k*(i+1) <= n; k++){

				mul *= comb(n-j-(k-1)*(i+1), i+1), mul %= mod;

				if(k >= c){

					(dp[i+1][j+k*(i+1)] += dp[i][j] * mul % mod * fact_inv[k] % mod) %= mod;

				}

			}

		}

	}

	

	cout << dp[b][n] << endl;



	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



#define int long long



const int mod = 1e9+7;

int n,a,b,c,d;

int f[1001][1001];

int fact[1001];

int re_fact[1001];



int p(int a,int b)

{

	if (b == 0)

		return 1;

	int tmp = p(a,b/2);

	if (b%2 == 0) return (tmp * tmp)%mod;

	return ((tmp * tmp)%mod * a)%mod;	

}



int comb(int n,int k)

{

	int tmp = ((fact[n] * re_fact[k])%mod * re_fact[n-k])%mod;

	return tmp;

}



int dp(int rem,int cur)

{

	if (rem == 0)

		return 1;

	if (cur > b)

		return 0;

	if (f[rem][cur] != -1)

		return f[rem][cur];

	int ans = dp(rem,cur + 1);

	for (int j=c;j<=d;j++)

	{

		if (rem - j*cur < 0)

			break;

		ans = (((((dp(rem - j*cur,cur + 1)*fact[j*cur])%mod*p(p(fact[cur],j),mod-2))%mod*re_fact[j])%mod*comb(rem,j*cur))%mod + ans)%mod;						

	}

	return f[rem][cur] = ans;

}



int32_t main()

{

	ios::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	                 

	fact[0] = 1;

	for (int i=1;i<=1000;i++)

		fact[i] = (fact[i-1] * i)%mod;

	re_fact[1000] = p(fact[1000],mod-2);

	for (int i=1000;i>=1;i--)

		re_fact[i-1] = (re_fact[i] * i)%mod;	

	cin >> n >> a >> b >> c >> d;

	for (int i=0;i<=1000;i++)

		for (int j=0;j<=1000;j++)

			f[i][j] = -1;

	cout << dp(n,a);

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define int long long

using namespace std;

const int oo =1e18;

const int MOD = 1e9 + 7;

const int Nmax = 1005;



int gt[Nmax];

int inv[Nmax];

int dp[Nmax][Nmax];

int n,a,b,c,d;



int power(int n, int k)

{

    if (k == 0) return 1;

    int tmp = power(n, k / 2);

    tmp = tmp * tmp % MOD;

    if (k % 2) return tmp * n % MOD;

    return tmp;

}



void init()

{

    gt[0] = 1;

    for (int i = 1; i <= 1000; i++)

    {

        gt[i] = gt[i - 1] * i;

        if (gt[i] > MOD) gt[i] %= MOD;

    }

    inv[0] = 1;

    for (int i = 1; i <= 1000; i++)

    {

        inv[i] = power(gt[i], MOD - 2);

    }

}



signed main()

{

    //freopen("file.inp","r",stdin);

    init();

    cin >> n >> a >> b >> c >> d;

    dp[a - 1][0] = 1;

    for (int i = a; i <= b; i++)

    for (int j = 0; j <= n; j++)

    {

        dp[i][j] += dp[i - 1][j];

        for (int k = c; k <= d; k++)

        {

            if (i * k > j) break;

            int res = gt[j] * power(inv[i], k) % MOD * inv[j - k * i] % MOD * inv[k] % MOD;

            dp[i][j] += dp[i - 1][j - i * k] * res % MOD;

            if (dp[i][j] > MOD) dp[i][j] %= MOD;

        }

    }

    cout << dp[b][n];

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;

const int mod = 1000000007;

int N, A, B, C, D, dp[1009][1009], comb[1009][1009], inv[1009];

int main() {

	comb[0][0] = 1;

	for (int i = 1; i <= 1000; i++) {

		for (int j = 0; j <= i; j++) {

			comb[i][j] = comb[i - 1][j];

			if (j >= 1) {

				comb[i][j] += comb[i - 1][j - 1];

				if (comb[i][j] >= mod) comb[i][j] -= mod;

			}

		}

	}

	inv[1] = 1;

	for (int i = 2; i <= 1000; i++) inv[i] = 1LL * inv[mod % i] * (mod - mod / i) % mod;

	cin >> N >> A >> B >> C >> D; dp[0][0] = 1;

	for (int i = 0; i <= B - A; i++) {

		int num = i + A;

		for (int j = 0; j <= N; j++) {

			dp[i + 1][j] = dp[i][j];

			int mul = 1;

			for (int k = 1; k < C && j - num * k >= 0; k++) mul = 1LL * mul * comb[j - num * (k - 1)][num] % mod * inv[k] % mod;

			for (int k = C; k <= D && j - num * k >= 0; k++) {

				mul = 1LL * mul * comb[j - num * (k - 1)][num] % mod * inv[k] % mod;

				dp[i + 1][j] = (dp[i + 1][j] + 1LL * dp[i][j - num * k] * mul) % mod;

			}

		}

	}

	cout << dp[B - A + 1][N] << endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#ifndef ___CLASS_MODINT

#define ___CLASS_MODINT



#include <cstdint>



template<std::uint32_t mod>

class modint {

private:

	std::uint32_t n;

public:

	modint() : n(0) {};

	modint(std::uint64_t n_) : n(n_ % mod) {};

	bool operator==(const modint& m) const { return n == m.n; }

	bool operator!=(const modint& m) const { return n != m.n; }

	std::uint32_t get() const { return n; }

	modint& operator+=(const modint& m) { n += m.n; n = (n < mod ? n : n - mod); return *this; }

	modint& operator-=(const modint& m) { n += mod - m.n; n = (n < mod ? n : n - mod); return *this; }

	modint& operator*=(const modint& m) { n = std::uint64_t(n) * m.n % mod; return *this; }

	modint operator+(const modint& m) const { return modint(*this) += m; }

	modint operator-(const modint& m) const { return modint(*this) -= m; }

	modint operator*(const modint& m) const { return modint(*this) *= m; }

	modint binpow(std::uint64_t b) const {

		modint ans = 1, m = modint(*this);

		while (b) {

			if (b & 1) ans *= m;

			m *= m;

			b >>= 1;

		}

		return ans;

	}

	modint inv() { return (*this).binpow(mod - 2); }

};



#endif // ___CLASS_MODINT



#include <vector>

#include <iostream>

using namespace std;

using modulo = modint<1000000007>;

int main() {

	int N, A, B, C, D;

	cin >> N >> A >> B >> C >> D;

	vector<modulo> fact(N + 1), factinv(N + 1);

	for (int i = 0; i <= N; ++i) {

		fact[i] = (i > 0 ? fact[i - 1] * i : 1);

		factinv[i] = fact[i].inv();

	}

	vector<modulo> dp(N + 1);

	dp[0] = fact[N];

	for (int i = A; i <= B; ++i) {

		for (int j = N; j >= 0; --j) {

			modulo pw = factinv[i].binpow(C);

			for (int k = C; k <= D && k * i <= j; ++k) {

				dp[j] += dp[j - k * i] * pw * factinv[k];

				pw *= factinv[i];

			}

		}

	}

	cout << dp[N].get() << endl;

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define rep(i,s,t) for (int i=s;i<=t;++i)

typedef long long ll;

const int maxn=1e5+10;

const int mod=1e9+7;

using namespace std;

ll fac[maxn],inv[maxn];

ll quick_mod(ll x,ll y){

    ll ans=1;

    for(;y;y>>=1){

        if (y&1) ans=ans*x%mod;

        x=x*x%mod;

    }

    return ans;

}

void init(){

    fac[0]=1;

    rep(i,1,maxn-10) fac[i]=fac[i-1]*i%mod;

    inv[maxn-10]=quick_mod(fac[maxn-10],mod-2);

    for(int i=maxn-11;i>=0;--i) inv[i]=inv[i+1]*(i+1)%mod;

}

ll C(int n,int m){

    return fac[n]*inv[m]%mod*inv[n-m]%mod;

}

ll invv[maxn];

ll dp[1010][1010];

int main()

{

    init();

    int n,a,b,c,d;

    cin>> n >> a >> b >> c >> d;

    rep(i,0,b+1) dp[i][0]=1;

    rep(i,1,n) invv[i]=quick_mod(i,mod-2);

    rep(i,a,b){

        rep(j,0,n){

            if (!dp[i][j]) continue;

            if (j) (dp[i+1][j]+=dp[i][j])%=mod;

            ll tmp=1;

            rep(k,1,d){

                if (j+k*i>n) break;

                (tmp*=C(n-j-i*(k-1),i)*invv[k]%mod)%=mod;

                if (c<=k&&k<=d){

                    (dp[i+1][j+k*i]+=(dp[i][j]*tmp)%mod)%=mod;

                }

            }

        }

    }

    cout<< dp[b+1][n] <<endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#include<bits/stdc++.h> //Ithea Myse Valgulious

namespace chtholly{

typedef long long ll;

#define re0 register int

#define rel register ll

#define rec register char

#define gc getchar

//#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<23,stdin),p1==p2)?-1:*p1++)

#define pc putchar

#define p32 pc(' ')

#define pl puts("")

/*By Citrus*/

char buf[1<<23],*p1=buf,*p2=buf;

inline int read(){

  int x=0,f=1;char c=gc();

  for (;!isdigit(c);c=gc()) f^=c=='-';

  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');

  return f?x:-x;

  }

template <typename mitsuha>

inline bool read(mitsuha &x){

  x=0;int f=1;char c=gc();

  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';

  if (!~c) return 0;

  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');

  return x=f?x:-x,1;

  }

template <typename mitsuha>

inline int write(mitsuha x){

  if (!x) return 0&pc(48);

  if (x<0) pc('-'),x=-x;

  int bit[20],i,p=0;

  for (;x;x/=10) bit[++p]=x%10;

  for (i=p;i;--i) pc(bit[i]+48);

  return 0;

  }

inline char fuhao(){

  char c=gc();

  for (;isspace(c);c=gc());

  return c;

  }

}using namespace chtholly;

using namespace std;

const int aoi=2038,mod=1e9+7;

ll dp[aoi],inv[aoi];



ll kasumi(ll a,ll b=mod-2) {

ll s=1;

for (;b;b>>=1,a=a*a%mod) if (b&1) s=s*a%mod;

return s;

}



int main() {

int n,a,b,c,d,i,j,k;

read(n),read(a),read(b),read(c),read(d);

for (dp[n]=i=1;i<=n;++i) dp[n]=dp[n]*i%mod;

inv[n]=kasumi(dp[n]);

for (i=n;i;--i) inv[i-1]=inv[i]*i%mod;

for (i=a;i<=b;++i)

  for (j=0;j<=n;++j) 

    for (k=c;k<=d&&j+i*k<=n;++k) 

      dp[j]=(dp[j]+dp[j+i*k]*kasumi(inv[i],k)%mod*inv[k]%mod)%mod;

cout<<*dp<<"\n";

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cmath>

#include<cstring>

typedef long long LL;

using namespace std;



bool is_ok(LL N,LL A,LL B){

	if(N == 1 && A == B)

		return true;

	else if(N > 1 && A <= B)

		return true;

	return false;

}





int main(){

	LL N,A,B;

	cin >> N >> A >> B;

	

	if(is_ok(N,A,B)){

		if(N == 1 || A == B)

			cout << 1 << endl;

		else{

			LL diff = B-A;

			cout << diff*(N-2)+1 << endl;

		}

			

	}

	else

		cout << 0 << endl;

	return 0;

} 

// Optimized solution to the same problem (faster):
#include<stdio.h>

typedef long long ll;

int main()

{

	ll n,a,b;

	scanf("%lld %lld %lld",&n,&a,&b);

	ll ans=0;

	if(a>b)  ans=0;

	else if(n==1&&a!=b)  ans=0;

	else if(n==1&&a==b)  ans=1;

	else ans=(n-2)*(b-a)+1;

	printf("%lld\n",ans);

	return 0;

 } 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include<cstdio>

#include<cmath>

using namespace std;



int main()

{

   int n,a,b;

   scanf("%d%d%d",&n,&a,&b);

   if(n==1)

   {

       if(a==b)

        printf("1\n");

       else

       {

           printf("0\n");

       }

   }

   else

   {

       if(a>b)

        printf("0\n");

       else

        printf("%lld\n",(long long)(n-2)*(b-a)+1);

   }



    return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

typedef long long ll;

int main()

{

	ll n,a,b;

	scanf("%lld %lld %lld",&n,&a,&b);

	ll ans=0;

	if(a>b)  ans=0;

	else if(n==1&&a!=b)  ans=0;

	else if(n==1&&a==b)  ans=1;

	else ans=(n-2)*(b-a)+1;

	printf("%lld\n",ans);

	return 0;

 } 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;





#define ONSPEED ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

#define pb push_back

#define f(i,x,n) for(i=x;i<n;i++)

#define rf(i,x,n) for(i=n;i>x;i--)

#define ll long long

#define GCD(a,b) __gcd(a,b)

#define ff first

#define ss second

#define adios return 0;



/*

tacet aquilae

*/



int main()

{

    ONSPEED;

    ll t,n,k,a,b,c,d,s=0,i,j,flag;

    string x,y;

    cin>>n>>a>>b;

    if(n==1)

    {

    	if(a==b) cout<<"1\n";

    	else cout<<"0\n";

    }

    else{

    	if(a>b) cout<<"0\n";

    	else{

    		cout<<(b-a)*(n-2)+1;

    	}

    }



    adios;

}

	


// Optimized solution to the same problem (faster):
#include<stdio.h>

typedef long long ll;

int main()

{

	ll n,a,b;

	scanf("%lld %lld %lld",&n,&a,&b);

	ll ans=0;

	if(a>b)  ans=0;

	else if(n==1&&a!=b)  ans=0;

	else if(n==1&&a==b)  ans=1;

	else ans=(n-2)*(b-a)+1;

	printf("%lld\n",ans);

	return 0;

 } 

// Fastest known solution for this problem:
// Original C++ solution (slower):
/*  TAHMID RAHMAN

    DAMIAN FOREVER

     MATH LOVER

    NEVER GIVE UP

*/

#include<bits/stdc++.h>

using namespace std;

#define pi acos(-1.0)

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#define ll long long

#define pb push_back

#define fi first

#define se second

#define in insert

#define mp make_pair

#define GCD(a,b) __gcd(a,b);

#define endl "\n"

#define FRU freopen("out.txt","w",stdout)

#define FRO freopen("in.txt","r",stdin)

#define INFLL 9223372036854775807

#define debug 0

#define MAXN   100001

#define ar array

const int mxN=2e5;

const int MOD=1e9+7;

bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}

//Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;

int main()

{



    ll i,j,k=0,c1=0,c2=0;

    ll n,a,b;

    cin>>n>>a>>b;

    if(a>b)

    {

        cout<<0<<endl;

    }

    else if(n==1)

    {

        if(a!=b)

            cout<<0<<endl;

        else

            cout<<1<<endl;

    }

    else

        cout<<(n-2)*(b-a)+1<<endl;







    //cout<<endl;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

typedef long long ll;

int main()

{

	ll n,a,b;

	scanf("%lld %lld %lld",&n,&a,&b);

	ll ans=0;

	if(a>b)  ans=0;

	else if(n==1&&a!=b)  ans=0;

	else if(n==1&&a==b)  ans=1;

	else ans=(n-2)*(b-a)+1;

	printf("%lld\n",ans);

	return 0;

 } 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <cstring>

#include <algorithm>

#include <cmath>

#include <queue>

#include <stack>

#include <map>

#include <set>

#include <vector>

#include <iomanip>

#define ALL(x) (x).begin(), (x).end()

#define rt return

#define dll(x) scanf("%I64d",&x)

#define xll(x) printf("%I64d\n",x)

#define sz(a) int(a.size())

#define all(a) a.begin(), a.end()

#define rep(i,x,n) for(int i=x;i<n;i++)

#define repd(i,x,n) for(int i=x;i<=n;i++)

#define pii pair<int,int>

#define pll pair<long long ,long long>

#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

#define MS0(X) memset((X), 0, sizeof((X)))

#define MSC0(X) memset((X), '\0', sizeof((X)))

#define pb push_back

#define mp make_pair

#define fi first

#define se second

#define eps 1e-6

#define gg(x) getInt(&x)

#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;

using namespace std;

typedef long long ll;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}

inline void getInt(int* p);

const int maxn=1000010;

const int inf=0x3f3f3f3f;

/*** TEMPLATE CODE * * STARTS HERE ***/



int main()

{

	// freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);

    int n,a,b;

    while(cin>>n>>a>>b)

    {

    	if(n==1)

    	{

    		if(a!=b)

    		{

    			cout<<0<<endl;

    		}else

    		{

    			cout<<1<<endl;

    		}

    	}else

    	{

    		if(a<=b)

    		{

    			if(n==2)

    			{

    				cout<<1<<endl;

    			}

    			ll ans=1ll*(n-2)*b-1ll*(n-2)*a+1ll;

    			cout<<ans<<endl;

    		}else

    		{

    			cout<<0<<endl;



    		}

    	}

    }

    return 0;

}



inline void getInt(int* p) {

    char ch;

    do {

        ch = getchar();

    } while (ch == ' ' || ch == '\n');

    if (ch == '-') {

        *p = -(getchar() - '0');

        while ((ch = getchar()) >= '0' && ch <= '9') {

            *p = *p * 10 - ch + '0';

        }

    }

    else {

        *p = ch - '0';

        while ((ch = getchar()) >= '0' && ch <= '9') {

            *p = *p * 10 + ch - '0';

        }

    }

}




// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>



using namespace std;





typedef long long LL;



int main(){

    LL N,A,B;

    scanf("%lld%lld%lld",&N,&A,&B);

    LL sum = (B-A)*(N-2)+1;

    if(A>B){

        printf("0");

        return 0;

    }

    if(N == 1 && A != B){

        printf("0");

        return 0;

    }

    if(N == 1 && A == B){

        printf("1");

        return 0;

    }

    printf("%lld", sum);



}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>



using namespace std;





int main()

{

    long long N,A,B,i,j,min,max;

    cin>>N>>A>>B;



    min=(N-1)*A+B;

    max=(N-1)*B+A;





    if(B<A)

        cout<<'0';

    else

        if(B==A)

            cout<<'1';

    else

        if(N==1)

            cout<<'0';

        else

            cout<<max-min+1;



}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>



using namespace std;





typedef long long LL;



int main(){

    LL N,A,B;

    scanf("%lld%lld%lld",&N,&A,&B);

    LL sum = (B-A)*(N-2)+1;

    if(A>B){

        printf("0");

        return 0;

    }

    if(N == 1 && A != B){

        printf("0");

        return 0;

    }

    if(N == 1 && A == B){

        printf("1");

        return 0;

    }

    printf("%lld", sum);



}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

using namespace std;

int main()

{

    long long n,a,b;

    cin>>n>>a>>b;

    if(n>1&&b>=a||n==1&&a==b)

        cout<<(n-2)*(b-a)+1<<endl;

    else

        cout<<0<<endl; 

 } 

// Optimized solution to the same problem (faster):
#include <stdio.h>





int main()

{		

	long long a, b, n;

		

	scanf("%lld%lld%lld", &n, &a, &b);

	if(a == b) puts("1");

	else if(a < b){

		if(n > 1) printf("%lld\n", (b - a) * (n - 2) + 1);

		else puts("0");

	} 

	else puts("0");

				

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>



using namespace std;

int main(){

	int n,a,b;

	cin>>n>>a>>b;

	if(a>b){

		cout<<0<<endl;

		return 0;

	}

	if((n==1)&&(a!=b)) {

		cout<<0<<endl;

		return 0;

	}

	if((n==1)&&(a==b)){

		cout<<1<<endl;

		return 0;

	}

	

//	long max=a+(n-1)*b;

//	long min=(n-1)*a+b;

	printf("%lld\n",(long long)(b-a)*(n-2)+1);	

	return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>



int main()

{

    int A,B,N;

    scanf("%d%d%d",&N,&A,&B);

    if(N==1)

    {

        if(A==B)

            printf("1\n");

        else

            printf("0\n");

    }

    else

    {

        if(A>B)

            printf("0\n");

        else

            printf("%lld\n",(long long )(B-A)*(N-2)+1);

    }

    return 0;

}


// Fastest known solution for this problem: