import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

void main() {
    auto nq = readints();
    int n = nq[0], q = nq[1];
    for (int i = 0; i < q; i++) {
        auto xs = readints();

        if (xs[0] == 0) {
            int s = xs[1];
            int t = xs[2];
            int x = xs[3];
            add(s, t + 1, x, 0, 0, N / 2);
        }
        else {
            int s = xs[1];
            int t = xs[2];
            auto v = sum(s, t + 1, 0, 0, N / 2);
            writeln(v);
        }
    }
}

///////////////////////////////////////

const int N = 1 << 18; // ???????????°

long[N * 2] _data;
long[N * 2] _datb;

/// [a, b) ??? x ???????????????
/// k ????????????????????§????????? [l, r) ???????????????
void add(int a, int b, int x, int k, int l, int r) {
    if (a <= l && r <= b) {
        _data[k] += x;
    }
    else if (l < b && a < r) {
        _datb[k] += (min(b, r) - max(a, l)) * x;
        add(a, b, x, k * 2 + 1, l, (l + r) / 2);
        add(a, b, x, k * 2 + 2, (l + r) / 2, r);
    }
}

/// [a, b) ??????????±???????
/// k ????????????????????§????????? [l, r) ???????????????]
long sum(int a, int b, int k, int l, int r) {
    if (b <= l || r <= a)
        return 0;

    if (a <= l && r <= b)
        return _data[k] * (r - l) + _datb[k];

    auto ret = (min(b, r) - max(a, l)) * _data[k];
    ret += sum(a, b, k * 2 + 1, l, (l + r) / 2);
    ret += sum(a, b, k * 2 + 2, (l + r) / 2, r);
    return ret;
}