#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <list>
#include <bitset>

using namespace std;
typedef long long ll;

// #define DEBUG

class RangeAddorUpdateQuery // 0-index
{
    int const intmax = 2147483647;
    int const intmin = 0;
    vector<ll> segtree;
    vector<ll> lazytree; //　遅延ツリーの方はintで収まらないことがある
    int n;
    int k;

public:
    RangeAddorUpdateQuery(int n1, int f = -1)
    {
        if (f == -1)
            f = intmax;
        else if (f == 0)
            f = intmin;
        int na = 1;
        int ka = 0;
        while (na < n1)
        {
            na *= 2;
            ka++;
        }
        for (int i = 0; i < 2 * na; i++)
        {
            segtree.push_back(f);
            lazytree.push_back(f);
        }
        n = na;
        k = ka;
    }

    void lazyupgladeevaluation(int k, int l, int r)
    {
        if (lazytree[k] != intmax)
        {
            segtree[k] = lazytree[k];
            if (r - l > 1) //最下段以外は一段下に伝播
            {
                lazytree[2 * k + 1] = lazytree[k];
                lazytree[2 * k] = lazytree[k];
            }
            lazytree[k] = intmax;
        }
    }

    void lazyaddevaluation(int k, int l, int r)
    {
        if (lazytree[k] != 0)
        {
            segtree[k] += lazytree[k];
            if (r - l > 1) //最下段以外は一段下に伝播
            {
                lazytree[2 * k + 1] += lazytree[k] / 2;
                lazytree[2 * k] += lazytree[k] / 2;
            }
            lazytree[k] = 0;
        }
    }

    void rangeupdate(int a, int b, ll x, int k = 1, int l = 0, int r = -1) //閉区間 l <= x < r とする
    {
        if (r == -1)
            r = n;
        lazyupgladeevaluation(k, l, r);
        if (r <= a || b <= l)
            return;
        if (a == l && b == r)
        {
            lazytree[k] = x;
            lazyupgladeevaluation(k, l, r);
        }
        else
        {
            rangeupdate(a, min(b, (l + r) / 2), x, 2 * k, l, (l + r) / 2);
            rangeupdate(max(a, (l + r) / 2), b, x, 2 * k + 1, (l + r) / 2, r);
        }
    }

    void rangeadd(int a, int b, ll x, int k = 1, int l = 0, int r = -1) //閉区間 l <= x < r とする
    {
        if (r == -1)
            r = n;
        lazyaddevaluation(k, l, r);
        if (r <= a || b <= l)
            return;
        if (a == l && b == r)
        {
            lazytree[k] = x * (r - l);
            lazyaddevaluation(k, l, r);
        }
        else
        {
            rangeadd(a, min(b, (l + r) / 2), x, 2 * k, l, (l + r) / 2);
            rangeadd(max(a, (l + r) / 2), b, x, 2 * k + 1, (l + r) / 2, r);
            segtree[k] = segtree[2 * k] + segtree[2 * k + 1];
        }
    }

    int getmin(int a, int b, int k = 1, int l = 0, int r = -1) //閉区間 l <= x < r とする
    {
        if (r == -1)
            r = n;
        lazyaddevaluation(k, l, r);
        if (r <= a || b <= l)
            return intmax;
        if (a == l && b == r)
            return segtree[k];
        else
            return min(getmin(a, min(b, (l + r) / 2), 2 * k, l, (l + r) / 2), getmin(max(a, (l + r) / 2), b, 2 * k + 1, (l + r) / 2, r));
    }
    int getmax(int a, int b, int k = 1, int l = 0, int r = -1) //閉区間 l <= x < r とする
    {
        if (r == -1)
            r = n;
        lazyaddevaluation(k, l, r);
        if (r <= a || b <= l)
            return intmin;
        if (a == l && b == r)
            return segtree[k];
        else
            return min(getmax(a, min(b, (l + r) / 2), 2 * k, l, (l + r) / 2), getmax(max(a, (l + r) / 2), b, 2 * k + 1, (l + r) / 2, r));
    }
    ll getsum(int a, int b, int k = 1, int l = 0, int r = -1) //閉区間 l <= x < r とする
    {
        if (r == -1)
            r = n;
        lazyaddevaluation(k, l, r);
        if (r <= a || b <= l)
            return intmin;
        if (a == l && b == r)
        {
            return segtree[k];
        }
        else
            return getsum(a, min(b, (l + r) / 2), 2 * k, l, (l + r) / 2) + getsum(max(a, (l + r) / 2), b, 2 * k + 1, (l + r) / 2, r);
    }

    void printsegtree()
    {
        for (int i = 0; i < 2 * n; i++)
        {
            cout << segtree[i] << " ";
        }
        cout << endl;
        for (int i = 0; i < 2 * n; i++)
        {
            cout << lazytree[i] << " ";
        }
        cout << endl;
    }
};

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, q, k, c, s, t;
    ll x, y;
    cin >> n >> q;
    RangeAddorUpdateQuery segtree(n, 0);

    for (int i = 0; i < q; i++)
    {
        cin >> c;
        if (c == 0)
        {
            cin >> s >> t >> x;
            segtree.rangeadd(s - 1, t, x);
        }
        else
        {
            cin >> x >> y;
            cout << segtree.getsum(x - 1, y) << endl;
        }
    }
    return 0;
}

// getline(cin,s);
// a = strtok(s, ",");  ","で分解
// for (int i = 0; i < n; i++)


Measured memory_bytes: 7136