//AOJ-DSL-2-G
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

/*
    LazySegmentTree<int, int> seg(f, g, h, p, def, laz_def) のように宣言する
    RMQ and RUQ の場合 : 
    auto f = [](int a, int b){return min(a, b);};
    auto g = [](int a, int b){return b;};
    auto h = [](int a, int b){returm b;};
    auto p = [](int a, int b){return a;};
    RSQ and RAQ の場合 : 
    auto f = [](ll a, ll b){return a + b;};
    auto g = [](ll a, ll b){return a + b;};
    auto h = [](ll a, ll b){returm a + b;};
    auto p = [](ll a, int b){return a * b;};
*/
template <typename Monoid, typename OperatorMonoid>
struct LazySegmentTree{
    using F = function<Monoid(Monoid, Monoid)>;
    using G = function<Monoid(Monoid, OperatorMonoid)>;
    using H = function<OperatorMonoid(OperatorMonoid, OperatorMonoid)>;
    using P = function<OperatorMonoid(OperatorMonoid, int)>;
    int n;
    vector<Monoid> dat;
    vector<OperatorMonoid> laz;
    F f;
    G g;
    H h;
    P p;
    Monoid def;
    OperatorMonoid laz_def;

    LazySegmentTree(F f, G g, H h, P p, Monoid def, OperatorMonoid laz_def) : f(f), g(g), h(h), p(p), def(def), laz_def(laz_def){}

    void build(const vector<Monoid> & vec){
        int siz = vec.size();
        n = 1;
        while(n < siz) n *= 2;
        dat.assign(2 * n - 1, def);
        laz.assign(2 * n - 1, laz_def);
        for(int i = 0; i < siz; i++) dat[n - 1 + i] = vec[i];
        for(int i = n - 2; i >= 0; i--) dat[i] = f(dat[2 * i + 1], dat[2 * i + 2]);
    }

    void update(int a, int b, OperatorMonoid x){
        update(a, b, x, 0, 0, n);
    }

    Monoid query(int a, int b){
        return query(a, b, 0, 0, n);
    }

private:
    void eval(int k, int l, int r){
        if(laz[k] != laz_def){
            dat[k] = g(dat[k], p(laz[k], r - l));
            if(r - l > 1){
                laz[2 * k + 1] = h(laz[2 * k + 1], laz[k]);
                laz[2 * k + 2] = h(laz[2 * k + 2], laz[k]);
            }
            laz[k] = laz_def;
        }
    }

    void update(int a, int b, OperatorMonoid x, int k, int l, int r){
        eval(k, l, r);
        if(r <= a || b <= l) return;
        if(a <= l && r <= b){
            laz[k] = h(laz[k], x);
            eval(k, l, r);
        }else{
            update(a, b, x, 2 * k + 1, l, (l + r) / 2);
            update(a, b, x, 2 * k + 2, (l + r) / 2, r);
            dat[k] = f(dat[2 * k + 1], dat[2 * k + 2]);
        }
    }

    Monoid query(int a, int b, int k, int l, int r){
        if(r <= a || b <= l) return def;
        eval(k, l, r);
        if(a <= l && r <= b) return dat[k];
        Monoid vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
        Monoid vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return f(vl, vr);
    }
};

signed main(){
    int n,q;
    cin >> n >> q;
    auto f = [](ll a, ll b){return a + b;};
    auto g = [](ll a, ll b){return a + b;};
    auto h = [](ll a, ll b){return a + b;};
    auto p = [](ll a, int b){return a * b;};
    LazySegmentTree<ll, ll> seg(f, g, h, p, 0, 0);
    seg.build(vector<ll>(n, 0));
    int Q;
    REP(i,q){
        cin >> Q;
        int s,t,x;
        if(Q == 0){
            cin >> s >> t >> x;
            s--;
            seg.update(s, t, x);
        }else{
            cin >> s >> t;
            s--;
            cout << seg.query(s, t) << endl;;
        }
    }
    return 0;
}


Measured memory_bytes: 7600