/* Author : Nguyen Thanh Tung */
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
typedef pair<int, int> ii;
const int N = 1e6 + 7;
const long long oo = 1e18 + 7;
const long long MOD = 1e9 + 7;
int n, m;
int a[N];
int lazy1[N << 2], lazy2[N << 2], st1[N << 2], st2[N << 2];
int calc(int x) {
return x * (x + 1) / 2;
}
void fix1(int id, int l, int r) {
if(lazy1[id]) {
int m = (l + r) >> 1;
(st1[id << 1] += lazy1[id] * (m - l + 1)) %= MOD;
(st1[id << 1 | 1] += lazy1[id] * (r - m)) %= MOD;
(lazy1[id << 1] += lazy1[id]) %= MOD;
(lazy1[id << 1 | 1] += lazy1[id]) %= MOD;
lazy1[id] = 0;
}
}
void update1(int id, int l, int r, int u, int v, int val) {
if(v < l || u > r) {
return;
}
if(u <= l && v >= r) {
(st1[id] += val * (r - l + 1)) %= MOD;
(lazy1[id] += val) %= MOD;
return;
}
fix1(id, l, r);
int m = (l + r) >> 1;
update1(id << 1, l, m, u, v, val);
update1(id << 1 | 1, m + 1, r, u, v, val);
st1[id] = ((st1[id << 1] + st1[id << 1 | 1])) % MOD ;
}
int get1(int id, int l, int r, int u, int v) {
fix1(id, l, r);
if(v < l || u > r) {
return 0;
}
if(u <= l && v >= r) {
return st1[id] % MOD;
}
int m = (l + r) >> 1;
return ((get1(id << 1, l, m, u, v) % MOD) + (get1(id << 1 | 1, m + 1, r, u, v) % MOD)) % MOD ;
}
void fix2(int id, int l, int r) {
if(lazy2[id]) {
int m = (l + r) >> 1;
(st2[id << 1] += lazy2[id] * (calc(m) - calc(l - 1))) %= MOD;
(st2[id << 1 | 1] += lazy2[id] * (calc(r) - calc(m))) %= MOD;
(lazy2[id << 1] += lazy2[id]) %= MOD;
(lazy2[id << 1 | 1] += lazy2[id]) %= MOD;
lazy2[id] = 0;
}
}
void update2(int id, int l, int r, int u, int v, int val) {
if(v < l || u > r) {
return;
}
if(u <= l && v >= r) {
st2[id] += val * (calc(r) - calc(l - 1)) % MOD;
(lazy2[id] += val) %= MOD;
return;
}
fix2(id, l, r);
int m = (l + r) >> 1;
update2(id << 1, l, m, u, v, val);
update2(id << 1 | 1, m + 1, r, u, v, val);
st2[id] = ((st2[id << 1] + st2[id << 1 | 1])) % MOD;
}
int get2(int id, int l, int r, int u, int v) {
fix2(id, l, r);
if(v < l || u > r) {
return 0;
}
if(u <= l && v >= r) {
return st2[id] % MOD;
}
int m = (l + r) >> 1;
return ((get2(id << 1, l, m, u, v) % MOD) + (get2(id << 1 | 1, m + 1, r, u, v) % MOD)) % MOD;
}
void solve() {
cin >> n >> m;
while(m--) {
int op, l, r;
cin >> op >> l >> r;
if(op == 1) {
int A, B;
cin >> A >> B;
update1(1, 1, n, l, r, B - A * l);
update2(1, 1, n, l, r, A);
}
else {
cout << (get1(1, 1, n, l, r) % MOD + get2(1, 1, n, l, r) % MOD) % MOD << endl;
}
}
}
#define TASK "code"
signed main () {
ios_base::sync_with_stdio (false);
cin.tie(nullptr), cout.tie(nullptr);
if (fopen(TASK".INP", "r")) {
freopen(TASK".INP", "r", stdin);
freopen(TASK".OUT", "w", stdout);
}
solve();
return 0;
}
LyogQXV0aG9yIDogTmd1eWVuIFRoYW5oIFR1bmcgKi8KCiNpbmNsdWRlIDxiaXRzL3N0ZGMrKy5oPgoKI2RlZmluZSBlbmRsIAkJICAgICAgICAgJ1xuJwojZGVmaW5lIGludCAJCSAgICAgICAgIGxvbmcgbG9uZwoKdXNpbmcgbmFtZXNwYWNlIAkgICAgICAgICBzdGQ7Cgp0eXBlZGVmIHBhaXI8aW50LCBpbnQ+ICAgICAgIGlpOwoKY29uc3QgaW50ICAgICAgIE4gICAgICAgICAgICA9IDFlNiArIDc7CmNvbnN0IGxvbmcgbG9uZyBvbyAgICAgICAgICAgPSAxZTE4ICsgNzsKY29uc3QgbG9uZyBsb25nIE1PRCAgICAgICAgICA9IDFlOSArIDc7CgppbnQgbiwgbTsKaW50IGFbTl07CmludCBsYXp5MVtOIDw8IDJdLCBsYX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AxXSkpICUgTU9EIDsKfQoKaW50IGdldDEoaW50IGlkLCBpbnQgbCwgaW50IHIsIGludCB1LCBpbnQgdikgewogICAgZml4MShpZCwgbCwgcik7CiAgICBpZih2IDwgbCB8fCB1ID4gcikgewogICAgICAgIHJldHVybiAwOwogICAgfQogICAgaWYodSA8PSBsICYmIHYgPj0gcikgewogICAgICAgIHJldHVybiBzdDFbaWRdICUgTU9EOwogICAgfQogICAgaW50IG0gPSAobCArIHIpID4+IDE7CiAgICByZXR1cm4gKChnZXQxKGlkIDw8IDEsIGwsIG0sIHUsIHYpICUgTU9EKSArIChnZXQxKGlkIDw8IDEgfCAxLCBtICsgMSwgciwgdSwgdikgJSBNT0QpKSAlIE1PRCA7Cn0KCnZvaWQgZml4MihpbnQgaWQsIGludCBsLCBpbnQgcikgewogICAgaWYobGF6eTJbaWRdKSB7CiAgICAgICAgaW50IG0gPSAobCArIHIpID4+IDE7CiAgICAgICAgKHN0MltpZCA8PCAxXSArPSBsYXp5MltpZF0gKiAoY2FsYyhtKSAtIGNhbGMobCAtIDEpKSkgJT0gTU9EOwogICAgICAgIChzdDJbaWQgPDwgMSB8IDFdICs9IGxhenkyW2lkXSAqIChjYWxjKHIpIC0gY2FsYyhtKSkpICU9IE1PRDsgICAgICAgIAogICAgICAgIChsYXp5MltpZCA8PCAxXSArPSBsYXp5MltpZF0pICU9IE1PRDsKICAgICAgICAobGF6eTJbaWQgPDwgMSB8IDFdICs9IGxhenkyW2lkXSkgJT0gTU9EOwogICAgICAgIGxhenkyW2lkXSA9IDA7CiAgICB9ICAgIAp9Cgp2b2lkIHVwZGF0ZTIoaW50IGlkLCBpbnQgbCwgaW50IHIsIGludCB1LCBpbnQgdiwgaW50IHZhbCkgewogICAgaWYodiA8IGwgfHwgdSA+IHIpIHsKICAgICAgICByZXR1cm47CiAgICB9CiAgICBpZih1IDw9IGwgJiYgdiA+PSByKSB7CiAgICAgICAgc3QyW2lkXSArPSB2YWwgKiAoY2FsYyhyKSAtIGNhbGMobCAtIDEpKSAlIE1PRDsKICAgICAgICAobGF6eTJbaWRdICs9IHZhbCkgJT0gTU9EOwogICAgICAgIHJldHVybjsKICAgIH0KICAgIGZpeDIoaWQsIGwsIHIpOwogICAgaW50IG0gPSAobCArIHIpID4+IDE7CiAgICB1cGRhdGUyKGlkIDw8IDEsIGwsIG0sIHUsIHYsIHZhbCk7CiAgICB1cGRhdGUyKGlkIDw8IDEgfCAxLCBtICsgMSwgciwgdSwgdiwgdmFsKTsKICAgIHN0MltpZF0gPSAoKHN0MltpZCA8PCAxXSArIHN0MltpZCA8PCAxIHwgMV0pKSAlIE1PRDsKfQoKaW50IGdldDIoaW50IGlkLCBpbnQgbCwgaW50IHIsIGludCB1LCBpbnQgdikgewogICAgZml4MihpZCwgbCwgcik7CiAgICBpZih2IDwgbCB8fCB1ID4gcikgewogICAgICAgIHJldHVybiAwOwogICAgfQogICAgaWYodSA8PSBsICYmIHYgPj0gcikgewogICAgICAgIHJldHVybiBzdDJbaWRdICUgTU9EOwogICAgfQogICAgaW50IG0gPSAobCArIHIpID4+IDE7CiAgICByZXR1cm4gKChnZXQyKGlkIDw8IDEsIGwsIG0sIHUsIHYpICUgTU9EKSArIChnZXQyKGlkIDw8IDEgfCAxLCBtICsgMSwgciwgdSwgdikgJSBNT0QpKSAlIE1PRDsKfQoKdm9pZCBzb2x2ZSgpIHsKICAgIGNpbiA+PiBuID4+IG07CiAgICB3aGlsZShtLS0pIHsKICAgICAgICBpbnQgb3AsIGwsIHI7CiAgICAgICAgY2luID4+IG9wID4+IGwgPj4gcjsKICAgICAgICBpZihvcCA9PSAxKSB7CiAgICAgICAgICAgIGludCBBLCBCOwogICAgICAgICAgICBjaW4gPj4gQSA+PiBCOwogICAgICAgICAgICB1cGRhdGUxKDEsIDEsIG4sIGwsIHIsIEIgLSBBICogbCk7CiAgICAgICAgICAgIHVwZGF0ZTIoMSwgMSwgbiwgbCwgciwgQSk7CiAgICAgICAgfQogICAgICAgIGVsc2UgewogICAgICAgICAgICBjb3V0IDw8IChnZXQxKDEsIDEsIG4sIGwsIHIpICUgTU9EICsgZ2V0MigxLCAxLCBuLCBsLCByKSAlIE1PRCkgJSBNT0QgPDwgZW5kbDsKICAgICAgICB9CiAgICB9Cn0KCiNkZWZpbmUgVEFTSyAiY29kZSIKCnNpZ25lZCBtYWluICgpIHsKICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyAoZmFsc2UpOwogICBjaW4udGllKG51bGxwdHIpLCBjb3V0LnRpZShudWxscHRyKTsKICAgaWYgKGZvcGVuKFRBU0siLklOUCIsICJyIikpIHsKICAgICAgZnJlb3BlbihUQVNLIi5JTlAiLCAiciIsIHN0ZGluKTsKICAgICAgZnJlb3BlbihUQVNLIi5PVVQiLCAidyIsIHN0ZG91dCk7CiAgIH0KICAgc29sdmUoKTsKICAgcmV0dXJuIDA7Cn0K