/* Author : Triet Do Thanh - FPT University */
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
typedef pair<int, int> ii;
const int N = 2e5 + 7;
const long long oo = 1e18 + 7;
const long long MOD = 1e9 + 7;
int n, q;
int a[N];
int st[3][N * 4], lz[3][N * 4];
void push1(int id, int l, int r) {
if (lz[1][id]) {
int mid = (l + r) >> 1;
(st[1][id * 2] += lz[1][id] * (mid - l + 1)) %= MOD;
(st[1][id * 2 + 1] += lz[1][id] * (r - (mid + 1) + 1)) %= MOD;
(lz[1][id * 2] += lz[1][id]) %= MOD;
(lz[1][id * 2 + 1] += lz[1][id]) %= MOD;
lz[1][id] = 0;
}
}
void upd1(int id, int l, int r, int u, int v, int val) {
if (l > v || r < u) return;
if (l >= u && r <= v) {
(st[1][id] += (r - l + 1) * val) %= MOD;
(lz[1][id] += val) %= MOD;
return;
}
push1(id, l, r);
int mid = (l + r) >> 1;
upd1(id * 2, l, mid, u, v, val); upd1(id * 2 + 1, mid + 1, r, u, v, val);
st[1][id] = (st[1][id * 2] + st[1][id * 2 + 1]) % MOD;
}
int g1(int id, int l, int r, int u, int v) {
push1(id, l, r);
if (l > v || r < u) return 0;
if (l >= u && r <= v) {
return st[1][id] % MOD;
}
int mid = (l + r) >> 1;
return ((g1(id * 2, l, mid, u, v) % MOD) + (g1(id * 2 + 1, mid + 1, r, u, v) % MOD)) % MOD;
}
int calc(int pos) {
return pos * (pos + 1) / 2;
}
void push2(int id, int l, int r) {
if (lz[2][id]) {
int mid = (l + r) >> 1;
(st[2][id * 2] += lz[2][id] * (calc(mid) - calc(l - 1))) %= MOD;
(st[2][id * 2 + 1] += lz[2][id] * (calc(r) - calc(mid))) %= MOD;
(lz[2][id * 2] += lz[2][id]) %= MOD;
(lz[2][id * 2 + 1] += lz[2][id]) %= MOD;
lz[2][id] = 0 ;
}
}
void upd2(int id, int l, int r, int u, int v, int val) {
if (l > v || r < u) return;
if (l >= u && r <= v) {
(st[2][id] += (calc(r) - calc(l - 1)) * val) %= MOD;
(lz[2][id] += val) %= MOD;
return;
}
push2(id, l, r);
int mid = (l + r) >> 1;
upd2(id * 2, l, mid, u, v, val); upd2(id * 2 + 1, mid + 1, r, u, v, val);
st[2][id] = (st[2][id * 2] + st[2][id * 2 + 1]) % MOD;
}
int g2(int id, int l, int r, int u, int v) {
push2(id, l, r);
if (l > v || r < u) return 0;
if (l >= u && r <= v) {
return st[2][id] % MOD;
}
int mid = (l + r) >> 1;
return ((g2(id * 2, l, mid, u, v) % MOD) + (g2(id * 2 + 1, mid + 1, r, u, v) % MOD)) % MOD;
}
void update(int l, int r, int a, int b) {
upd1(1,1,n,l,r,b);
upd1(1,1,n,l,r,((-l * a) + MOD * MOD) % MOD);
upd2(1,1,n,l,r,a);
}
int get(int l, int r) {
return (g1(1,1,n,l,r) + g2(1,1,n,l,r)) % MOD;
}
void solve() {
cin >> n >> q;
while (q-->0) {
int op; cin >> op;
if (op == 1) {
int l, r, a, b; cin >> l >> r >> a >> b;
update(l, r, a, b);
}
else {
int l, r; cin >> l >> r;
cout << get(l, r) << endl;
}
}
}
#define TASK "test"
signed main()
{
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
if (fopen("input.txt", "r")) {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
solve();
return 0;
}
LyogQXV0aG9yIDogVHJpZXQgRG8gVGhhbmggLSBGUFQgVW5pdmVyc2l0eSAqLwoKI2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CgojZGVmaW5lIGVuZGwgICAgICAgICAgICdcbicKI2RlZmluZSBpbnQgICAgICAgICAgICBsb25nIGxvbmcKCnVzaW5nIG5hbWVzcGFjZSAgICAgICAgc3RkOwoKdHlwZWRlZiBwYWlyPGludCwgaW50PiBpaTsKCmNvbnN0IGludCAgICAgICBOICAgICAgPSAyZTUgKyA3Owpjb25zdCBsb25nIGxvbmcgb28gICAgID0gMWUxOCArIDc7CmNvbnN0IGxvbmcgbG9uZyBNT0QgICAgPSAxZTkgKyA3OwoKaW50IG4sIHE7CmludCBhW05dOwoKaW50IHN0WzNdW04gKiA0XSwgbHpbM11bTiAqIDRdOwoKdm9pZCBwdXNoMShpbnQgaWQsIGludCBsLCBpbnQgcikgewogICAgaWYgKGx6WzFdW2lkXSkgewogICAgICAgIGludCBtaWQgPSAobCArIHIpID4+IDE7CiAgICAgICAgKHN0WzFdW2lkICogMl0gKz0gbHpbMV1baWRdICogKG1pZCAtIGwgKyAxKSkgJT0gTU9EOwogICAgICAgIChzdFsxXVtpZCAqIDIgKyAxXSArPSBselsxXVtpZF0gKiAociAtIChtaWQgKyAxKSArIDEpKSAlPSBNT0Q7CiAgICAgICAgKGx6WzFdW2lkICogMl0gKz0gbHpbMV1baWRdKSAlPSBNT0Q7CiAgICAgICAgKGx6WzFdW2lkICogMiArIDFdICs9IGx6WzFdW2lkXSkgJT0gTU9EOwogICAgICAgIGx6WzFdW2lkXSA9IDA7CiAgICB9Cn0KCnZvaWQgdXBkMShpbnQgaWQsIGludCBsLCBpbnQgciwgaW50IHUsIGludCB2LCBpbnQgdmFsKSB7CiAgICBpZiAobCA+IHYgfHwgciA8IHUpIHJldHVybjsKICAgIGlmIChsID49IHUgJiYgciA8PSB2KSB7CiAgICAgICAgKHN0WzFdW2lkXSArPSAociAtIGwgKyAxKSAqIHZhbCkgJT0gTU9EOwogICAgICAgIChselsxXVtpZF0gKz0gdmFsKSAlPSBNT0Q7CiAgICAgICAgcmV0dXJuOwogICAgfQogICAgcHVzaDEoaWQsIGwsIHIpOwogICAgaW50IG1pZCA9IChsICsgcikgPj4gMTsKICAgIHVwZDEoaWQgKiAyLCBsLCBtaWQsIHUsIHYsIHZhbCk7IHVwZDEoaWQgKiAyICsgMSwgbWlkICsgMSwgciwgdSwgdiwgdmFsKTsKICAgIHN0WzFdW2lkXSA9IChzdFsxXVtpZCAqIDJdICsgc3RbMV1baWQgKiAyICsgMV0pICUgTU9EOwp9CgppbnQgZzEoaW50IGlkLCBpbnQgbCwgaW50IHIsIGludCB1LCBpbnQgdikgewogICAgcHVzaDEoaWQsIGwsIHIpOwogICAgaWYgKGwgPiB2IHx8IHIgPCB1KSByZXR1cm4gMDsKICAgIGlmIChsID49IHUgJiYgciA8PSB2KSB7CiAgICAgICAgcmV0dXJuIHN0WzFdW2lkXSAlIE1PRDsgICAKICAgIH0KICAgIGludCBtaWQgPSAobCArIHIpID4+IDE7CiAgICByZXR1cm4gKChnMShpZCAqIDIsIGwsIG1pZCwgdSwgdikgJSBNT0QpICsgKGcxKGlkICogMiArIDEsIG1pZCArIDEsIHIsIHUsIHYpICUgTU9EKSkgJSBNT0Q7Cn0KCmludCBjYWxjKGludCBwb3MpIHsKICAgIHJldHVybiBwb3MgKiAocG9zICsgMSkgLyAyOwp9Cgp2b2lkIHB1c2gyKGludCBpZCwgaW50IGwsIGludCByKSB7CiAgICBpZiAobHpbMl1baWRdKSB7CiAgICAgICAgaW50IG1pZCA9IChsICsgcikgPj4gMTsKICAgICAgICAoc3RbMl1baWQgKiAyXSArPSBselsyXVtpZF0gKiAoY2FsYyhtaWQpIC0gY2FsYyhsIC0gMSkpKSAlPSBNT0Q7CiAgICAgICAgKHN0WzJdW2lkICogMiArIDFdICs9IGx6WzJdW2lkXSAqIChjYWxjKHIpIC0gY2FsYyhtaWQpKSkgJT0gTU9EOwogICAgICAgIChselsyXVtpZCAqIDJdICs9IGx6WzJdW2lkXSkgJT0gTU9EOwogICAgICAgIChselsyXVtpZCAqIDIgKyAxXSArPSBselsyXVtpZF0pICU9IE1PRDsKICAgICAgICBselsyXVtpZF0gPSAwIDsKICAgIH0KfQoKdm9pZCB1cGQyKGludCBpZCwgaW50IGwsIGludCByLCBpbnQgdSwgaW50IHYsIGludCB2YWwpIHsKICAgIGlmIChsID4gdiB8fCByIDwgdSkgcmV0dXJuOwogICAgaWYgKGwgPj0gdSAmJiByIDw9IHYpIHsKICAgICAgICAoc3RbMl1baWRdICs9IChjYWxjKHIpIC0gY2FsYyhsIC0gMSkpICogdmFsKSAlPSBNT0Q7CiAgICAgICAgKGx6WzJdW2lkXSArPSB2YWwpICU9IE1PRDsKICAgICAgICByZXR1cm47CiAgICB9CiAgICBwdXNoMihpZCwgbCwgcik7CiAgICBpbnQgbWlkID0gKGwgKyByKSA+PiAxOwogICAgdXBkMihpZCAqIDIsIGwsIG1pZCwgdSwgdiwgdmFsKTsgdXBkMihpZCAqIDIgKyAxLCBtaWQgKyAxLCByLCB1LCB2LCB2YWwpOwogICAgc3RbMl1baWRdID0gKHN0WzJdW2lkICogMl0gKyBzdFsyXVtpZCAqIDIgKyAxXSkgJSBNT0Q7Cn0KCmludCBnMihpbnQgaWQsIGludCBsLCBpbnQgciwgaW50IHUsIGludCB2KSB7CiAgICBwdXNoMihpZCwgbCwgcik7CiAgICBpZiAobCA+IHYgfHwgciA8IHUpIHJldHVybiAwOwogICAgaWYgKGwgPj0gdSAmJiByIDw9IHYpIHsKICAgICAgICByZXR1cm4gc3RbMl1baWRdICUgTU9EOwogICAgfQogICAgaW50IG1pZCA9IChsICsgcikgPj4gMTsKICAgIHJldHVybiAoKGcyKGlkICogMiwgbCwgbWlkLCB1LCB2KSAlIE1PRCkgKyAoZzIoaWQgKiAyICsgMSwgbWlkICsgMSwgciwgdSwgdikgJSBNT0QpKSAlIE1PRDsKfQoKdm9pZCB1cGRhdGUoaW50IGwsIGludCByLCBpbnQgYSwgaW50IGIpIHsKICAgIHVwZDEoMSwxLG4sbCxyLGIpOwogICAgdXBkMSgxLDEsbixsLHIsKCgtbCAqIGEpICsgTU9EICogTU9EKSAlIE1PRCk7CiAgICB1cGQyKDEsMSxuLGwscixhKTsKfQoKaW50IGdldChpbnQgbCwgaW50IHIpIHsKICAgIHJldHVybiAoZzEoMSwxLG4sbCxyKSArIGcyKDEsMSxuLGwscikpICUgTU9EOwp9Cgp2b2lkIHNvbHZlKCkgewogICAgY2luID4+IG4gPj4gcTsKICAgIAogICAgd2hpbGUgKHEtLT4wKSB7CiAgICAgICAgaW50IG9wOyBjaW4gPj4gb3A7CiAgICAgICAgaWYgKG9wID09IDEpIHsKICAgICAgICAgICAgaW50IGwsIHIsIGEsIGI7IGNpbiA+PiBsID4+IHIgPj4gYSA+PiBiOwogICAgICAgICAgICB1cGRhdGUobCwgciwgYSwgYik7CiAgICAgICAgfQogICAgICAgIGVsc2UgewogICAgICAgICAgICBpbnQgbCwgcjsgY2luID4+IGwgPj4gcjsKICAgICAgICAgICAgY291dCA8PCBnZXQobCwgcikgPDwgZW5kbDsKICAgICAgICB9CiAgICB9Cn0KCiNkZWZpbmUgVEFTSyAidGVzdCIKCnNpZ25lZCBtYWluKCkKewogICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKSwgY2luLnRpZSgwKSwgY291dC50aWUoMCk7CiAgIGlmIChmb3BlbigiaW5wdXQudHh0IiwgInIiKSkgewogICAgICBmcmVvcGVuKCJpbnB1dC50eHQiLCAiciIsIHN0ZGluKTsKICAgICAgZnJlb3Blbigib3V0cHV0LnR4dCIsICJ3Iiwgc3Rkb3V0KTsKICAgfQogICBzb2x2ZSgpOwogICByZXR1cm4gMDsKfQ==