#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define sz(s) (int)(s.size())
#define endl "\n"
#define BI acos(-1)
#define all(a) a.begin(), a.end()
void Open() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif !ONLINEJUDGE
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int dx[]{ 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[]{ 0, 0, 1, -1, 1, -1, 1, -1 };
const int OO = 0x3f3f3f3f;
int main()
{
Open();
ll l, r, x, y, k,md=7+1e9;
cin >> l >> r >> x >> y >> k;
ll sum = ((r * (r + 1)) / 2 - (l * (l - 1)) / 2);
ll w = (r-1)/k, ww=(l-1)/k;
ll qe = (((r-1) % k+1) ) * w ; // end
ll qf = (k-((l-1) % k ) )%md * ww%md ; // first
ll qbt = ((w * (w - 1)) / 2)- (ww * (ww + 1)) / 2; // between
qbt = qbt % md * k % md;
if (w==ww )qbt = 0,qe=0,qf=(r-l+1)*w;
qbt = qbt % md * y % md,qe = qe % md * y % md, qf = qf % md * y % md;
//cout << ww << ' ' << w << ' ' << qf << ' ' << qe << ' ' << qbt << endl;
ll ans = ((((sum % md) * x%md) % md) + (((qbt%md+qe%md) % md)+qf%md)%md) % md;
cout << ans;
}
Copy