#include <bits/stdc++.h>

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#define PRINTP(p)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#p<<" = ("<<(p.first)<<", "<<(p.second)<<")"<<endl;
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTP(p)
#define PRINTI(a,i)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<class T>
class binary_indexed_tree {
private:
    const size_t size;
    const function<T(T, T)> f;
    const T unit;
    T *a;
public:
    binary_indexed_tree(size_t n, function<T(T, T)>, T unit);
    ~binary_indexed_tree();
    void update(size_t i, T x);
    T query(size_t i) const;
};

template<class T>
binary_indexed_tree<T>::binary_indexed_tree(size_t size, function<T(T, T)> f, T unit): size(size), f(f), unit(unit) {
    a = new T[size];
    fill(a, a + size, unit);
}

template<class T>
binary_indexed_tree<T>::~binary_indexed_tree() {
    delete [] a;
}

template<class T>
void binary_indexed_tree<T>::update(size_t i, T x) {
    for (size_t j = i; j < size; j |= j + 1) {
        a[j] = f(a[j], x);
    }
}

template<class T>
T binary_indexed_tree<T>::query(size_t i) const {
    T result = unit;
    for (size_t j = i; j > 0; j = (j & (j + 1))) {
        result = f(result, a[--j]);
    }
    return result;
}

class range_add_sum_query {
private:
    binary_indexed_tree<ll> *bit1;
    binary_indexed_tree<ll> *bit2;
public:
    range_add_sum_query(size_t n) {
        this->bit1 = new binary_indexed_tree<ll>(n + 1, [](ll x, ll y) { return x + y; }, 0);
        this->bit2 = new binary_indexed_tree<ll>(n + 1, [](ll x, ll y) { return x + y; }, 0);
    }

    ~range_add_sum_query() {
        delete this->bit1;
        delete this->bit2;
    }

    void range_add(size_t first, size_t last, ll x) {
        bit1->update(first, x);
        bit1->update(last, -x);
        bit2->update(first, first * x);
        bit2->update(last, -last * x);
    }

    ll range_sum(size_t last) {
        return bit1->query(last) * last - bit2->query(last);
    }

    ll range_sum(size_t first, size_t last) {
        return range_sum(last) - range_sum(first);
    }
};

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

    int n, q;
    cin >> n >> q;
    range_add_sum_query rasq(n);
    REP(_, q) {
        int query_type;
        cin >> query_type;
        if (query_type == 0) {
            int s, t, x;
            cin >> s >> t >> x;
            --s;
            rasq.range_add(s, t, x);
        } else if (query_type == 1) {
            int s, t;
            cin >> s >> t;
            --s;
            cout << rasq.range_sum(s, t) << "\n";
        }
    }
    cout << flush;
    return 0;
}


Measured memory_bytes: 4420