#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;
typedef pair<pii,int> ppi;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}

class LazySegmentTree{
private:
    int n;
    vector<long long> node, lazy;
    long long init = 0; // sum, max, update
    //long long init = LINF; // min

    long long lazy_update(long long a,long long b){
        return a+b/2; // sum query
        //return max(a,b); // max query
        //return min(a,b); // min query
        //return b; // update query
    }

    long long combine(long long a,long long b){
        return a+b; // sum query
        //return max(a,b); // max query
        //return min(a,b); // min query
    }

public:
    LazySegmentTree(){}
    LazySegmentTree(vector<long long> in){
        n = 1;
        while(n < in.size())n <<= 1;
        node = lazy = vector<long long>(2*n, init);
        for(int i = n-1+in.size()-1; i >= 0; i--){
            if(n-1 <= i)node[i] = in[i-(n-1)];
            else node[i] = combine(node[i*2+1], node[i*2+2]);
        }
    }
    void eval(int k, int l, int r){
        if(lazy[k] != init){
            node[k] = combine(node[k], lazy[k]);
            if(r - l > 1){
                lazy[2*k+1] = lazy_update(lazy[2*k+1], lazy[k]);
                lazy[2*k+2] = lazy_update(lazy[2*k+2], lazy[k]);
            }
            lazy[k] = init;
        }
    }
    void update(int a, int b, long long x, int k = 0, int l = 0, int r = -1){
        if(r < 0)r = n;
        eval(k,l,r);
        if(b <= l || r <= a)return;
        if(a <= l && r <= b){
            lazy[k] = combine(lazy[k], x*(r-l));//sum query
            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);
            node[k] = combine(node[2*k+1], node[2*k+2]);
        }
    }
    long long query(int a, int b, int k = 0, int l = 0, int r = -1){
        if(r < 0)r = n;
        if(b <= l || r <= a)return init;
        eval(k,l,r);
        if(a <= l && r <= b)return node[k];
        return combine(query(a,b,2*k+1,l,(l+r)/2), query(a,b,2*k+2,(l+r)/2,r));
    }
    void show(){
        cout << "node :";
        for(int i = 0; i < 2*n; i++){
            cout << " " << node[i];
        }
        cout << endl;
        cout << "lazy :";
        for(int i = 0; i < 2*n; i++){
            cout << " " << lazy[i];
        }
        cout << endl;
    }
};

signed main(void) {

    int n,q;
    cin >> n >> q;
    LazySegmentTree lazy = LazySegmentTree(vi(n));

    rep(i,q){
        int a;
        cin >> a;
        if(a == 0){//update
            int s,t,x;
            cin >> s >> t >> x;
            lazy.update(s-1,t,x);
        }else{//query
            int s,t;
            cin >> s >> t;
            cout << lazy.query(s-1,t) << endl;
        }
        //lazy.show();
    }

}



Measured memory_bytes: 9748