#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

template<typename Monoid,typename Action,typename F,typename G,typename H>
struct LazySegmentTree{
    int sz;
    vector<Monoid> node;
    vector<Action> lazy;
    const F FM;//モノイド同士の演算
    const G FA;//モノイドへの作用
    const H FL;//作用の合成
    const Monoid UNITY_MONOID;//モノイドの単位元
    const Action UNITY_ACTION;//作用素の単位元

    LazySegmentTree(int n,const F FM,const G FA,const H FL,const Monoid &UNITY_MONOID,const Action &UNITY_ACTION)
    :FM(FM),FA(FA),FL(FL),UNITY_MONOID(UNITY_MONOID),UNITY_ACTION(UNITY_ACTION){
        sz=1;
        while(sz<n) sz*=2;
        node.assign(2*sz,UNITY_MONOID);
        lazy.assign(2*sz,UNITY_ACTION);
    }

    void build(const vector<Monoid> &v){
        int n=v.size();
        for(int i=0;i<n;i++) node[i+sz-1]=v[i];
        for(int i=sz-2;i>=0;i--) node[i]=fm(node[2*i+1],node[2*i+2]);
    }

    void evaluate(int k,int l,int r){
        if(lazy[k]==UNITY_ACTION) return ;
        if(r-l>1){//最下段かどうかチェック
            FL(lazy[2*k+1],lazy[k]);
            FL(lazy[2*k+2],lazy[k]);
        }
        FA(node[k],lazy[k]);
        lazy[k]=UNITY_ACTION;
    }

    void update(int a,int b,const Action &x,int k=0,int l=0,int r=-1){
        if(r<0) r=sz;
        evaluate(k,l,r);
        if(b<=l || r<=a) return ;
        if(a<=l && r<=b){
            lazy[k]+=x*(r-l);
            evaluate(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]=FM(node[2*k+1],node[2*k+2]);
        }
    }

    Monoid query(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0) r=sz;
        evaluate(k,l,r);
        if(b<=l || r<=a) return UNITY_MONOID;
        else if(a<=l && r<=b) return node[k];
        else return FM(query(a,b,2*k+1,l,(l+r)/2),query(a,b,2*k+2,(l+r)/2,r));
    }
};

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll n,q;
	cin>>n>>q;
	auto fm=[](ll a,ll b){return a+b;};
	auto fa=[](ll &a,ll b){a+=b;};
	auto fl=[](ll &a,ll b){a+=b/2;};
	LazySegmentTree<ll,ll,decltype(fm),decltype(fa),decltype(fl)> seg(n,fm,fa,fl,0,0);
	while(q--){
		ll c;
		cin>>c;
		ll s,t,x;
		if(c){
			cin>>s>>t;
			cout<<seg.query(s-1,t)<<endl;
		}else{
			cin>>s>>t>>x;
			seg.update(s-1,t,x);
		}
	}
}


Measured memory_bytes: 7076