#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

template<typename T>
class LazySegmentTree{
    std::vector<T> data;
    std::vector<T> lazy;
    int size;
    int binSize;
    T initial;

    void eval(int L,int R,T X){
        if(L > R)std::swap(L,R);
        int Lidx = 1;
        int Ridx = 1;
        T LX = X*(R-L+1);
        T RX = 0;
        std::pair<int,int> LRange = std::make_pair(1,binSize);
        std::pair<int,int> RRange = std::make_pair(1,binSize);
        while(Lidx < binSize && Ridx < binSize){
            data[Lidx] += lazy[Lidx];
            lazy[Lidx*2] += lazy[Lidx]/2;
            lazy[Lidx*2+1] += lazy[Lidx]/2;
            lazy[Lidx] = initial;
            data[Ridx] += lazy[Ridx];
            lazy[Ridx*2] += lazy[Ridx]/2;
            lazy[Ridx*2+1] += lazy[Ridx]/2;
            lazy[Ridx] = initial;
            if(Lidx == Ridx){
                data[Lidx] += LX;
                std::pair<int,int> nextLRange = std::make_pair(LRange.first,(LRange.first + LRange.second)/2);
                std::pair<int,int> nextRRange = std::make_pair(1 + (LRange.first + LRange.second)/2,LRange.second);
                bool LNext,RNext;
                if(nextLRange.first <= L && L <= nextLRange.second){
                    LNext = true;
                }else{
                    LNext = false;
                }
                if(nextLRange.first <= R && R <= nextLRange.second){
                    RNext = true;
                }else{
                    RNext = false;
                }
                if(LNext == RNext){
                    if(LNext){
                        LRange = RRange = nextLRange;
                        Lidx = Ridx = Lidx*2;
                    }else{
                        LRange = RRange = nextRRange;
                        Lidx = Ridx = Lidx*2 + 1;
                    }
                }else{
                    LX = (nextLRange.second - L + 1) * X;
                    Lidx = Lidx*2;
                    RX = (R - nextRRange.first + 1) * X;
                    Ridx = Ridx*2 + 1;
                    LRange = nextLRange;
                    RRange = nextRRange;
                }
            }else{
                data[Lidx] += LX;
                data[Ridx] += RX;
                std::pair<int,int> nextLRangeForL = std::make_pair(LRange.first,(LRange.first + LRange.second)/2);
                std::pair<int,int> nextRRangeForL = std::make_pair(1 + (LRange.first + LRange.second)/2,LRange.second);
                std::pair<int,int> nextLRangeForR = std::make_pair(RRange.first,(RRange.first + RRange.second)/2);
                std::pair<int,int> nextRRangeForR = std::make_pair(1 + (RRange.first + RRange.second)/2,RRange.second);
                if(nextLRangeForL.first <= L && L <= nextLRangeForL.second){
                    lazy[Lidx*2+1] += X*(nextRRangeForL.second - nextRRangeForL.first + 1);
                    LX -= X*(nextRRangeForL.second - nextRRangeForL.first + 1);
                    Lidx = Lidx*2;
                    LRange = nextLRangeForL;
                }else{
                    Lidx = Lidx*2 + 1;
                    LRange = nextRRangeForL;
                }
                if(nextLRangeForR.first <= R && R <= nextLRangeForR.second){
                    Ridx = Ridx*2;
                    RRange = nextLRangeForR;
                }else{
                    lazy[Ridx*2] += X*(nextLRangeForR.second - nextLRangeForR.first + 1);
                    RX -= X*(nextLRangeForR.second - nextLRangeForR.first + 1);
                    Ridx = Ridx*2 + 1;
                    RRange = nextRRangeForR;
                }
            }
        }
        data[Lidx] += LX;
        data[Ridx] += RX;
    }

    T get(int l,int r){
        if(l > size || r > size || l <= 0 || r <= 0)return initial;
        l = binSize+l-1;
        r = binSize+r-1;
        int prel = l;
        int prer = r;
        data[l] += lazy[l];
        lazy[l] = initial;
        data[r] += lazy[r];
        lazy[r] = initial;
        if(l == r)return data[l];
        T lnum = data[l];
        T rnum = data[r];
        l >>= 1;
        r >>= 1;
        while(l != r){
            data[l] += lazy[l];
            lazy[l*2] += lazy[l]/2;
            lazy[l*2+1] += lazy[l]/2;
            lazy[l] = initial;
            data[r] += lazy[r];
            lazy[r*2] += lazy[r];
            lazy[r*2+1] += lazy[r];
            lazy[r] = initial;
            if(l*2 == prel){
                data[l*2+1] += lazy[l*2+1];
                if(l*2+1 < binSize){
                    lazy[(l*2+1)*2] += lazy[l*2+1]/2;
                    lazy[(l*2+1)*2+1] += lazy[l*2+1]/2;
                }
                lazy[l*2+1] = initial;
                lnum += data[l*2+1];
            }
            if(r*2+1 == prer){
                data[r*2] += lazy[r*2];
                if(r*2 < binSize){
                    lazy[(r*2)*2] += lazy[r*2]/2;
                    lazy[(r*2)*2+1] += lazy[r*2]/2;
                }
                lazy[r*2] = initial;
                rnum += data[r*2];
            }
            prel = l;
            prer = r;
            l >>= 1;
            r >>= 1;
        }
        return lnum+rnum;
    }

    public:
    LazySegmentTree(int N,T init):size(N),initial(init){
        int tmp = 1;
        while(tmp < N){
            tmp *= 2;
        }
        binSize = tmp;
        data = std::vector<T>(2*tmp,initial);
        lazy = std::vector<T>(2*tmp,initial);
    }

    void RangeAdd(int L,int R,T X){
        eval(L,R,X);
    }

    T RangeGet(int L,int R){
        eval(L,R,initial);
        return get(L,R);
    }
};

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n,q;
    cin >> n >> q;
    
    LazySegmentTree<ll> LST = LazySegmentTree<ll>(n,0);

    for(int i = 0; i < q; i++){
        ll a;
        cin >> a;
        if(a == 0){
            ll x,y,z;
            cin >> x >> y >> z;
            LST.RangeAdd(x,y,z);
        }else{
            ll s,t;
            cin >> s >> t;
            cout << LST.RangeGet(s,t) << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 7016