#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>

using namespace std;

#ifdef unix
#define LL "%lld"
#else
#define LL "%I64d"
#endif

const int maxn=100000;
const long long mo=1000000007;

long long va,vb,vc,l,r;

struct state
{
	long long mod,x,y,z;
	bool operator<(const state &a)const
	{
		return mod<a.mod;
	}
}s[maxn],sum[maxn],bsum[maxn];

int find(int size,long long delta_mod)
{
	if (delta_mod<s[1].mod) return 1;
	if (delta_mod>s[size].mod) return size+1;
	int l=0,r=size;
	while (l+1!=r)
	{
		int m=(l+r)>>1;
		if (s[m].mod>=delta_mod) r=m;
		else l=m;
	}
	return r;
}

long long getans(int size,long long nowp)
{
	long long delta_mod=nowp*va%vb;
	int p=find(size,vb-delta_mod);
	long long deltav=nowp*va/vb%mo;
	long long ans=0;
	long long delta=nowp;
	p--;
	if (p) ans=(ans+sum[p].z+sum[p].x*deltav%mo+delta*sum[p].y%mo+delta*deltav%mo*p%mo)%mo;
	p++;
	deltav++;
	if (p<=size) ans=(ans+bsum[p].z+bsum[p].x*deltav%mo+delta*bsum[p].y%mo+delta*deltav%mo*(size-p+1)%mo)%mo;
	return ans;
}

long long solve(long long p)
{
	if (p==0) return 0;
	int size=(int)sqrt(p);
	for (int a=1;a<=size;a++)
	{
		s[a].mod=(va*a+vc)%vb;
		s[a].x=a;
		s[a].y=(va*a+vc)/vb%mo;
		s[a].z=s[a].x*s[a].y%mo;
	}
	sort(s+1,s+size+1);
	sum[0].x=sum[0].y=sum[0].z=0;
	for (int a=1;a<=size;a++)
		sum[a].x=(sum[a-1].x+s[a].x)%mo,sum[a].y=(sum[a-1].y+s[a].y)%mo,sum[a].z=(sum[a-1].z+s[a].z)%mo;
	bsum[size+1].x=bsum[size+1].y=bsum[size+1].z=0;
	for (int a=size;a>=1;a--)
		bsum[a].x=(bsum[a+1].x+s[a].x)%mo,bsum[a].y=(bsum[a+1].y+s[a].y)%mo,bsum[a].z=(bsum[a+1].z+s[a].z)%mo;
	long long nowp=1,ans=0;
	while (nowp+size-1<=p)
	{
		ans=(ans+getans(size,nowp-1))%mo;
		nowp+=size;
	}
	for (long long a=nowp;a<=p;a++)
		ans=(ans+(va*a+vc)/vb%mo*a%mo)%mo;
	return ans;
}

int main()
{
	scanf(LL LL LL LL LL,&va,&vb,&vc,&l,&r);
	printf(LL "\n",(solve(r)-solve(l-1)+mo)%mo);

	return 0;
}