#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <cstring>

/* 
PascalCase  クラス名
camelCase   メソッド名，関数名，変数名
snake_case  ファイル名，名前空間，std のメソッド名，変数名，型名に準じる場合
SNAKE_CASE	マクロ名，static const 定数，列挙体
*/

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for(int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define Cout(obj) cout << obj << endl
#define Size(obj) (int)(obj).size()
#define fcout cout << fixed << setprecision(10)
#define fi first
#define se second

using namespace std;
using ll = long long int;

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

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

template <typename T>
struct LazzySegTreeSum
{
  private:
    ll N = 1;
    vector<T> node,lazy;

  public:
    LazzySegTreeSum(vector<T> vec)
    {
        ll size = vec.size();

        while (N < size)
        {
            N *= 2;
        }

        node.resize(2 * N - 1);
        lazy.resize(2 * N - 1, 0);

        REP(i, size)
        {
            node[i + N - 1] = vec[i];
        }

        for (int i = N - 2; 0 <= i; i--)
        {
            node[i] = node[2 * i + 1] + node[2 * i + 2];
        }
    }

    void eval(int k, int l, int r)
    {
        if(lazy[k] != 0)
        {
            node[k] += lazy[k];

            if(r - l > 1)
            {
                lazy[2 * k + 1] += lazy[k] / 2;
                lazy[2 * k + 2] += lazy[k] / 2;
            }
        }

        lazy[k] = 0;
    }

    //[a, b]
    void add(int a, int b, T value, 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] += (r - l) * value;
            eval(k, l, r);
        }
        else
        {
            add(a, b, value, 2 * k + 1, l, (l + r) / 2);
            add(a, b, value, 2 * k + 2, (l + r) / 2, r);

            node[k] = node[2 * k + 1] + node[2 * k + 2];
        }
    }

    //[a, b]
    T 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()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, Q;
    cin >> N >> Q;

    LazzySegTreeSum<ll> seg(vector<ll> (N, 0));

    REP(i, Q)
    {
        int com;
        cin >> com;
        if(com == 0)
        {
            int s, t, x;
            cin >> s >> t >> x;

            seg.add(s - 1, t, x);
        }
        else
        {
            int s, t;
            cin >> s >> t;
            
            Cout(seg.getSum(s - 1, t));
        }
    }
    return 0;
}


Measured memory_bytes: 7856