#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

template <typename T>
class SegmentTree {
    const T unit;
    const function<T(const T&, const T&)> op;
    vector<T> container;

public:
    template <typename Op>
    SegmentTree(int size, const T& identity, const Op& operation)
        : unit(identity)
        , op(operation)
        , container(msb1(size * 2 - 1))
    {
        fill(container.begin(), container.end(), unit);
    }

    void update(size_t i, const T& v)
    {
        size_t n = container.size() / 2;
        size_t j = n + i;
        container[j] = v;
        j /= 2;
        while (j != 0) {
            container[j] = op(container[j * 2], container[j * 2 + 1]);
            j /= 2;
        }
    }

    T find(size_t s, size_t t)
    {
        if (s >= t) {
            return unit;
        }
        return find_inner(s, t, 0, container.size() / 2, 1);
    }

private:
    T find_inner(size_t s, size_t t, size_t lb, size_t ub, size_t node)
    {
        if (s == lb && t == ub) {
            return container[node];
        }

        T result = unit;
        size_t mid = (lb + ub) / 2;
        if (mid > s) {
            result = op(result, find_inner(s, min(mid, t), lb, mid, node * 2));
        }
        if (mid < t) {
            result = op(result, find_inner(max(s, mid), t, mid, ub, node * 2 + 1));
        }

        return result;
    }
    int msb1(int x)
    {
        x |= x >> 1;
        x |= x >> 2;
        x |= x >> 4;
        x |= x >> 8;
        x |= x >> 16;

        return x + 1;
    }
};

class LazySegmentTree {
    vector<int64_t> container;
    vector<int64_t> lazyContainer;

public:
    LazySegmentTree(int size)
        : container(msb1(size * 2 - 1))
        , lazyContainer(msb1(size * 2 - 1))
    {
    }

    void add(size_t s, size_t t, int64_t x)
    {
        add_inner(s, t, 0, container.size() / 2, 1, x);
    }

    int64_t find(size_t s, size_t t)
    {
        if (s >= t) {
            return 0;
        }
        return find_inner(s, t, 0, container.size() / 2, 1);
    }

    void debug()
    {
        for (int64_t i : container) {
            cout << i << " ";
        }
        cout << endl;
        for (int64_t i : lazyContainer) {
            cout << i << " ";
        }
        cout << endl;
    }

private:
    void add_inner(size_t s, size_t t, size_t lb, size_t ub, size_t node, int64_t x)
    {
        if (s == lb && t == ub) {
            lazyContainer[node] += x * (t - s);
            return;
        }
        container[node] += x * (t - s);

        size_t mid = (lb + ub) / 2;
        if (mid > s) {
            add_inner(s, min(mid, t), lb, mid, node * 2, x);
        }
        if (mid < t) {
            add_inner(max(mid, s), t, mid, ub, node * 2 + 1, x);
        }
    }
    int64_t find_inner(size_t s, size_t t, size_t lb, size_t ub, size_t node)
    {
        container[node] += lazyContainer[node];
        size_t ch = node * 2;
        if (ch < container.size()) {
            lazyContainer[ch] += lazyContainer[node] / 2;
            lazyContainer[ch + 1] += lazyContainer[node] / 2;
        }
        lazyContainer[node] = 0;

        if (s == lb && t == ub) {
            return container[node];
        }

        int64_t result = 0;
        size_t mid = (lb + ub) / 2;
        if (mid > s) {
            result = result + find_inner(s, min(mid, t), lb, mid, node * 2);
        }
        if (mid < t) {
            result = result + find_inner(max(s, mid), t, mid, ub, node * 2 + 1);
        }

        return result;
    }
    int msb1(int x)
    {
        x |= x >> 1;
        x |= x >> 2;
        x |= x >> 4;
        x |= x >> 8;
        x |= x >> 16;

        return x + 1;
    }
};

int main()
{
    int n, q;
    cin >> n >> q;

    LazySegmentTree seg(n);

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

            seg.add(s - 1, t, x);
        } else {
            cout << seg.find(s - 1, t) << endl;
        }
        //seg.debug();
    }
    return 0;
}


Measured memory_bytes: 7052