stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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);

}

// Faster C++ solution for the same problem (measured speedup: 7.55376637147036x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 3.341782375560744x):
#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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 2.6205986062844344x):
#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";

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 2.5429771798360847x):
#include<bits/stdc++.h>



using namespace std;



#define ll  long long

#define ld  double



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

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



#define pb  emplace_back

#define X   first

#define Y   second



const int   N   = 1005;

const int   mod = 1e9 + 7;



void add(int&a,int b)   {

    a += b;

    if (a >= mod)

        a -= mod;

}

void sub(int&a,int b)   {

    a -= b;

    if (a <  0)

        a += mod;

}

int mul(int a,int b)    {

    return  1ll * a * b % mod;

}

int Pow(int a,int b)    {

    int ans = 1;

    while (b)   {

        if(b & 1)   ans = mul(ans,a);

        a = mul(a,a);   b >>= 1;

    }

    return  ans;

}

int inv(int a,int p)    {

    return  a == 1 ? 1 : p - 1ll * p * inv(p % a,a) / a;

}



int f[N];



int Fac[N];

int Inv[N];



typedef pair<int,int>   ii;



int main()  {

    ios_base::sync_with_stdio(0);

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



    Fac[0] = Inv[0] = 1;



    for(int i = 1 ; i < N ; ++i)    Fac[i] = mul(Fac[i - 1],i);     Inv[N - 1] = inv(Fac[N - 1],mod);

    for(int i = N - 2 ; i ; --i)    Inv[i] = mul(Inv[i + 1],i + 1);



    int n;  cin >> n;

    int a, b;   cin >> a >> b;

    int c, d;   cin >> c >> d;



    f[0] = 1;



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

        int l = c;

        int r = min(d,n / i);



        for(int s = n ; s >= 0 ; --s)   {

            int x = Pow(Inv[i],l);



            for(int j = l ; j <= r ; ++j)   {

                if (i * j > s)

                    break;



                add(f[s],mul(mul(x,Inv[j]),f[s - i * j]));



                x = mul(x,Inv[i]);

            }

        }

    }



    int ans = f[n];



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

        ans = mul(ans,i);



    cout << ans << endl;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 2.583261051427655x):
#include <iostream>

#define mod 1000000007

#define nmax 1000

using std::cin;

using std::cout;

int n, a, b, c, d;

long long ft[nmax+1], rft[nmax+1], dp[2][nmax+1];

long long qmod(long long x)

{

    return (x < mod) ? x : x - mod;

}

long long power(long long b, long long p)

{

    long long res = 1, a = b;

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

      if(p&1) res = res * a % mod;

      a = a * a % mod;

    }

    return res;

}

long long rverse(long long x)

{

    return power(x, mod - 2);

}

void build()

{

    ft[0] = rft[0] = 1;

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

      ft[i] = ft[i - 1] * i % mod;

    rft[n] = rverse(ft[n]);

    for(int i = n - 1; i > 0; --i)

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

}

long long P(long long x, long long k)

{

    if(x < k) return 0;

    return ft[x] * rft[x - k] % mod;

}

int main()

{

    std::ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

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

    build();

    dp[!(a & 1)][0] = 1;

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

      int o = i & 1;

      long long tmp0 = power(rft[i], c);

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

        dp[o][j] = dp[!o][j];

        long long tmp = tmp0;

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

          long long ik = i * k;

          dp[o][j + ik] = qmod(dp[o][j + ik] + dp[!o][j] * P(n - j, ik) % mod * tmp % mod * rft[k] % mod);

          tmp = tmp * rft[i] % mod;

        }

      }

    }

    cout << dp[b & 1][n];

    return 0;

}
// Slower C++ solution:
#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;

} 

// Faster C++ solution for the same problem (measured speedup: 5.244745748753178x):
#include<cstdio>



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;

}
// Slower C++ solution:
#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;

} 

// Faster C++ solution for the same problem (measured speedup: 5.2446997795503645x):
#include<cstdio>



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;

}
// Slower C++ solution:
#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;

} 

// Faster C++ solution for the same problem (measured speedup: 5.244898572375101x):
#include <cstdio>



int main(void)

{

    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 )(B-A)*(N-2)+1);

    }

    return 0;

}
// Slower C++ solution:
#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;

} 

// Faster C++ solution for the same problem (measured speedup: 5.244852601832818x):
#include <cstdio>



int main(void)

{

    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 )(B-A)*(N-2)+1);

    }

    return 0;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.181373359264761x):
#include <cstdio>



int main(void)

{

    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 )(B-A)*(N-2)+1);

    }

    return 0;

}
// Slower C++ solution:
#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;

} 

// Faster C++ solution for the same problem (measured speedup: 5.245426417175496x):
#include <cstdio>

#include <cstring>

typedef long long ll;

int main(){

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

    ll l = 1LL*a*(n-1) + b,r = 1LL*b*(n-1) + a;

    if(l > r) {puts("0");return 0;}

    else printf("%lld\n",(r-l+1));

    return 0;

}
// Slower C++ solution:
#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;

} 

// Faster C++ solution for the same problem (measured speedup: 5.245380442006753x):
#include <cstdio>

#include <cstring>

typedef long long ll;

int main(){

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

    ll l = 1LL*a*(n-1) + b,r = 1LL*b*(n-1) + a;

    if(l > r) {puts("0");return 0;}

    else printf("%lld\n",(r-l+1));

    return 0;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.181894810909411x):
#include <cstdio>

#include <cstring>

typedef long long ll;

int main(){

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

    ll l = 1LL*a*(n-1) + b,r = 1LL*b*(n-1) + a;

    if(l > r) {puts("0");return 0;}

    else printf("%lld\n",(r-l+1));

    return 0;

}
// Slower C++ solution:
#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;

}

	


// Faster C++ solution for the same problem (measured speedup: 5.349600715228897x):
#include <cstdio>

#include <cstring>

typedef long long ll;

int main(){

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

    ll l = 1LL*a*(n-1) + b,r = 1LL*b*(n-1) + a;

    if(l > r) {puts("0");return 0;}

    else printf("%lld\n",(r-l+1));

    return 0;

}
// Slower C++ solution:
/*  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;

}


// Faster C++ solution for the same problem (measured speedup: 5.244884019150089x):
#include <cstdio>

#include <cstring>

typedef long long ll;

int main(){

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

    ll l = 1LL*a*(n-1) + b,r = 1LL*b*(n-1) + a;

    if(l > r) {puts("0");return 0;}

    else printf("%lld\n",(r-l+1));

    return 0;

}