//????????£?????????

#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 each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#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

using namespace std;

typedef pair<int,int>P;

const int N = 1 << 17;
const int NIL = 0;

struct LazySegmentTree {
private:
    int n;
    vector<ll> node, lazy;

public:
    LazySegmentTree(vector<ll> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);

        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2];
    }
    // k ???????????????????????????????????¶???????????????
    void eval(int k, int l, int r) {
        // ?????¶??????????????§????????´??????????????????????????????????????????
        // ????????????????????????
        if(lazy[k] != 0) {
            node[k] += lazy[k];

            // ?????????????????????????????§??????????????????
            // ?????????????????????????????? 1/2 ???????????§???????????????
            // ?????????????????¨?????????????????????
            if(r - l > 1) {
                lazy[2*k+1] += lazy[k] / 2;
                lazy[2*k+2] += lazy[k] / 2;
            }
            // ?????????????????£????????§???????????????????????¶?????????????????????
            lazy[k] = 0;
        }
    }
    void add(int a, int b, ll x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        // k ???????????????????????????????????¶???????????????
        eval(k, l, r);
        // ??????????????????????????????
        if(b <= l || r <= a) return;

        // ?????¨????¢????????????????????????°????????¶?????????????????\??????????????????
        if(a <= l && r <= b) {
            lazy[k] += (r - l) * x;
            eval(k, l, r);
        }

        // ????????§??????????????°?????????????????????????????°???????¨?????????????
        // ?¨???????????????????????????£?????????
        else {
            add(a, b, x, 2*k+1, l, (l+r)/2);
            add(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = node[2*k+1] + node[2*k+2];
        }
    }
    ll getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;

        // ??¢??°???????????????????????????????????????
        eval(k, l, r);

        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return node[k];
        ll vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }
};

int main()
{
    int n,q;
    cin >> n >> q;
    vector<ll> a(n,0);
    LazySegmentTree st(a);
	rep(i,q){
        int a;
        scanf("%d",&a);
        if(a == 0){
            int x,y,z;
            scanf("%d%d%d",&x,&y,&z);
            st.add(x-1,y,z);
        }else{
            int x,y;
            scanf("%d%d",&x,&y);
            cout << st.getsum(x-1,y) << "\n";
        }
    }
}

Measured memory_bytes: 8412