#include using namespace std; using lint = long long int; template using V = vector; template using VV = V< V >; template void assign(V& v, int n, const T& a = T()) { v.assign(n, a); } template void assign(V& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); } constexpr lint mod = 1e9 + 7; inline lint emod(lint a, lint p = mod) { return (a % p + p) % p; } struct Monoid { using T = struct { lint v, fib; }; static T op(const T& lhs, const T& rhs) { return {(lhs.v + rhs.v) % mod, (lhs.fib + rhs.fib) % mod}; } static constexpr T e() { return {0, 0}; } }; template struct MonoidAct { using T = struct { lint a, b, c; }; static void ap(const T& f, typename Monoid::T& a, int len) { a.v = (f.a * a.v + f.b * len + f.c * a.fib) % mod; } static void cp(const T& f, T& g) { (g.a *= f.a) %= mod, g.b = (f.a * g.b + f.b) % mod, g.c = (f.a * g.c + f.c) % mod; } static constexpr T id() { return {1, 0, 0}; } static bool is_id(const T& f) { return f.a == 1 and f.b == 0 and f.c == 0; } }; template struct SegmentTree { using Tv = typename Monoid::T; using Ta = typename MonoidAct::T; struct Node { Tv val = Monoid::e(); Ta act = MonoidAct::id(); unique_ptr cl, cr; }; const Int n; unique_ptr root; SegmentTree(Int n) : n(n) {} Tv get(Int l, Int r) { return get(l, r, root, 0, n); } void act(Int l, Int r, const Ta& f) { act(l, r, f, root, 0, n); } void set(Int i, const Tv& a) { set(i, a, root, 0, n); } void push(const unique_ptr& v, Int vl, Int vm, Int vr) { if (MonoidAct::is_id(v->act)) return; if (!v->cl) v->cl = make_unique(); MonoidAct::ap(v->act, v->cl->val, vm - vl); MonoidAct::cp(v->act, v->cl->act); if (!v->cr) v->cr = make_unique(); MonoidAct::ap(v->act, v->cr->val, vr - vm); MonoidAct::cp(v->act, v->cr->act); v->act = MonoidAct::id(); } Tv get(Int l, Int r, const unique_ptr& v, Int vl, Int vr) { if (!v) return Monoid::e(); if (l <= vl and vr <= r) return v->val; Int vm = vl + vr >> 1; push(v, vl, vm, vr); Tv resl = l < vm ? get(l, r, v->cl, vl, vm) : Monoid::e(), resr = vm < r ? get(l, r, v->cr, vm, vr) : Monoid::e(); return Monoid::op(resl, resr); } void act(Int l, Int r, const Ta& f, unique_ptr& v, Int vl, Int vr) { if (!v) v = make_unique(); if (l <= vl and vr <= r) { MonoidAct::ap(f, v->val, vr - vl); MonoidAct::cp(f, v->act); return; } Int vm = vl + vr >> 1; push(v, vl, vm, vr); if (l < vm) act(l, r, f, v->cl, vl, vm); if (vm < r) act(l, r, f, v->cr, vm, vr); v->val = Monoid::op(v->cl ? v->cl->val : Monoid::e(), v->cr ? v->cr->val : Monoid::e()); } void set(Int i, const Tv& a, unique_ptr& v, Int vl, Int vr) { if (!v) v = make_unique(); if (vr - vl == 1) { v->val = a; return; } Int vm = vl + vr >> 1; push(v, vl, vm, vr); if (i < vm) set(i, a, v->cl, vl, vm); else set(i, a, v->cr, vm, vr); v->val = Monoid::op(v->cl ? v->cl->val : Monoid::e(), v->cr ? v->cr->val : Monoid::e()); } }; int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int n, Q; cin >> n >> Q; V v(n); v[1].fib = 1; for (int i = 2; i < n; ++i) v[i].fib = (v[i - 1].fib + v[i - 2].fib) % mod; SegmentTree< Monoid, MonoidAct > st(n); for (int i = 0; i < n; ++i) st.set(i, v[i]); for (int i = 0; i < Q; ++i) { int q, l, r, k; cin >> q >> l >> r >> k, ++r; switch (q) { case 0: cout << emod(k * st.get(l, r).v) << '\n'; break; case 1: st.act(l, r, {0, k, 0}); break; case 2: st.act(l, r, {1, k, 0}); break; case 3: st.act(l, r, {k, 0, 0}); break; case 4: st.act(l, r, {1, 0, k}); break; } } }