#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

template <typename T> class RBST {
public:
    struct node{
        T val, kind, lazy, al;
        int st_size;   // ??¨?????¨????????????
        node* left; node* right;
        bool lazy_flag;
        node(){};
        node(T v,T k) : val(v), kind(k), al(v), left(nullptr), right(nullptr), st_size(1), lazy(0), lazy_flag(false){}
        ~node() { delete left; delete right; }
    };
    using pnn = pair<node*,node*>;
    node* root;
    T id1,id2;  //opr1,opr2????????????
    //?????¨?????????????????????(sum?????????)
    T opr1(T l, T r) {
    	return l + r;
    }
    //?????¶???????????????(add?????????)
    T opr2(T l, T r) {
    	return l + r;
    }
    RBST() : root(nullptr), id1(0), id2(0){}
    RBST(vector<T>& vec) : root(nullptr), id1(0), id2(0){
    	rep(i,len(vec)){
    		insert(i,vec[i]);
    	}
    }
    int size(node* t) { return t ? t->st_size : 0; }
    T que(node* t) { return t ? opr2(t->al,t->lazy*size(t)) : id1; }
    //?????¶??????
    node* push(node* t){
        if(!t) return t;
        if(t->lazy_flag){
            if(t->left){
                t->left->lazy_flag = true;
                t->left->lazy = opr2(t->left->lazy, t->lazy);
            }
            if(t->right){
                t->right->lazy_flag = true;
                t->right->lazy = opr2(t->right->lazy,t->lazy);
            }
            t->val = opr2(t->val, t->lazy);
            t->al = opr1(que(t->left), opr1(t->val, que(t->right)));
            t->lazy = id2;
            t->lazy_flag = false;
        }
        return t;
    }
    node* update(node *t){
        push(t);
        node* l = t->left; node* r = t->right;
        t->st_size = size(l) + size(r) + 1;
        push(l),push(r);
        t->al = opr1(opr1(que(l),que(r)),t->val);
        return t;
    }
    unsigned rnd(){
        static unsigned x = 123456789, y = 362436069, z = 521288629, w = 86675123;
        unsigned t = (x^(x<<11));
        x = y,y = z,z = w;
        return (w = (w^(w>>19))^(t^(t>>8)));
    }
    node* merge(node* l, node* r){
        if (!l || !r) return (!l) ? r : l;
        update(l),update(r);
        if(rnd() % (size(l) + size(r)) < (unsigned)size(l)){
            l->right = merge(l->right, r);
            return update(l);
        }else{
            r->left = merge(l, r->left);
            return update(r);
        }
    }
    pnn split(node* t, int k){   //??¨???????????????(k,n-k)??¨???????????????????????????
        if(!t) return pnn(nullptr, nullptr);
        update(t);
        if(k <= size(t->left)){
            pnn s = split(t->left, k);
            t->left = s.second;
            return pnn(s.first,update(t));
        }else{
            pnn s = split(t->right, k-size(t->left)-1);
            t->right = s.first;
            return pnn(update(t), s.second);
        }
    }
    node* insert(node* t, int k, node* u){
        pnn s = split(t, k);
        return merge(merge(s.first, u), s.second);
    }
    //0_indexed??§k???insert
    void insert(int k, T val,T num){
        root = insert(root, k, new node(val,num));
    }
    pnn erase(node* t, int k){
        pnn sr = split(t, k+1);
        pnn sl = split(sr.first, k);
        return pnn(merge(sl.first, sr.second), sl.second);
    }
    //0_indexed??§k??????erase
    void erase(int k){
        node *p;
        tie(root, p) = erase(root, k);
        p->left = p->right = nullptr;
        delete p;
    }
    pair<T,T> get(int k){
        auto sr = split(root, k+1);
        auto sl = split(sr.first, k);
        auto lr = sl.second;
        pair<T,T> res = make_pair(lr->val,lr->kind);
        root = merge(merge(sl.first, lr), sr.second);
        return res;
    }
    void range(int l, int r, T val){
        auto sr = split(root, r);
        auto sl = split(sr.first, l);
        auto lr = sl.second;
        lr->lazy = val;
        lr->lazy_flag = true;
        root = merge(merge(sl.first,lr),sr.second);
    }
    T query(int l,int r){
        auto sr = split(root,r);
        auto sl = split(sr.first,l);
        auto lr = sl.second;
        T res = que(lr);
        root = merge(merge(sl.first, lr), sr.second);
        return res;
    }
};

int main()
{
    int n,q;
    cin >> n >> q;
    RBST<ll> rb;
    rep(i,n){
        rb.insert(i,0,0);
    }
    rep(i,q){
        // rep(i,rb.size(rb.root)){
        //     spair(rb.get(i));
        // }
        // cout << "\n";
        int a;
        cin >> a;
        if(a == 0){
            int u,v,w;
            cin >> u >> v >> w;
            --u,--v;
            rb.range(u,v+1,w);
        }else{
            int u,v;
            cin >> u >> v;
            --u,--v;
            cout << rb.query(u,v+1) << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 10928