using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

struct Pair
{
    public long a;
    public long b;
}

class Program
{
    static void Main()
    {
        var nq = ReadLine().Split().Select(int.Parse).ToArray();
        var n = nq[0];
        var q = nq[1];
        var v = new Pair[n];
        for (int i = 0; i < v.Length; i++)
        {
            v[i] = new Pair { a = 0, b = 1 };
        }
        Func<Pair, Pair, Pair> f = (x, y) => new Pair { a = x.a + y.a, b = x.b + y.b };
        Func<Pair, long, Pair> g = (x, y) => new Pair { a = x.a + y * x.b, b = x.b };
        Func<long, long, long> h = (x, y) => x + y;
        var segtree = new SegmentTree<Pair, long>(v, f, g, h, new Pair { a = 0, b = 0 }, 0);
        for (int i = 0; i < q; i++)
        {
            var com = ReadLine().Split().Select(int.Parse).ToArray();
            if (com[0] == 0)
            {
                segtree.Update(com[1] - 1, com[2], com[3]);
            }
            else
            {
                WriteLine(segtree.Query(com[1] - 1, com[2]).a);
            }
        }
    }
}

//beet //何も理解していない
class SegmentTree<T, E> where E : IEquatable<E>
{
    T[] buffer;
    E[] lazy;
    int n;
    int height;
    Func<T, T, T> F;
    Func<T, E, T> G;
    Func<E, E, E> H;
    T TI;
    E EI;

    public SegmentTree(int cap, Func<T, T, T> f, Func<T, E, T> g, Func<E, E, E> h, T ti, E ei)
    {
        F = f;
        G = g;
        H = h;
        TI = ti;
        EI = ei;

        n = 1;
        height = 0;
        while (n < cap) { n <<= 1; height++; }

        buffer = new T[2 * n];
        for (int i = 0; i < buffer.Length; i++) buffer[i] = TI;//Array.Fill

        lazy = new E[2 * n];
        for (int i = 0; i < lazy.Length; i++) lazy[i] = EI;//Array.Fill
    }

    public SegmentTree(T[] init, Func<T, T, T> f, Func<T, E, T> g, Func<E, E, E> h, T ti, E ei)
    {
        F = f;
        G = g;
        H = h;
        TI = ti;
        EI = ei;

        n = 1;
        height = 0;
        while (n < init.Length) { n <<= 1; height++; }

        buffer = new T[2 * n];
        Array.Copy(init, 0, buffer, n, init.Length);
        for (int i = n + init.Length; i < buffer.Length; i++) buffer[i] = TI;
        for (int i = n - 1; i != 0; i--) buffer[i] = F(buffer[(i << 1) | 0], buffer[(i << 1) | 1]);

        lazy = new E[2 * n];
        for (int i = 0; i < lazy.Length; i++) lazy[i] = EI;//Array.Fill
    }

    T Reflect(int k)
    {
        return lazy[k].Equals(EI) ? buffer[k] : G(buffer[k], lazy[k]);//Type Classes!//lazy[k] == EI
    }

    void Eval(int k)
    {
        if (lazy[k].Equals(EI)) return;//Type Classes!//lazy[k] == EI
        lazy[(k << 1) | 0] = H(lazy[(k << 1) | 0], lazy[k]);
        lazy[(k << 1) | 1] = H(lazy[(k << 1) | 1], lazy[k]);
        buffer[k] = Reflect(k);
        lazy[k] = EI;
    }

    void Thrust(int k)
    {
        for (int i = height; i != 0; i--) Eval(k >> i);
    }

    void Recalc(int k)
    {
        while ((k >>= 1) != 0) buffer[k] = F(Reflect((k << 1) | 0), Reflect((k << 1) | 1));
    }

    public void Update(int a, int b, E x)
    {
        Thrust(a += n);
        Thrust(b += n - 1);
        for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1)
        {
            if ((l & 1) != 0) { lazy[l] = H(lazy[l], x); l++; }
            if ((r & 1) != 0) { --r; lazy[r] = H(lazy[r], x); }
        }
        Recalc(a);
        Recalc(b);
    }

    public void Set_val(int a, T x)
    {
        Thrust(a += n);
        buffer[a] = x;
        lazy[a] = EI;
        Recalc(a);
    }

    public T Query(int a, int b)
    {
        Thrust(a += n);
        Thrust(b += n - 1);
        T vl = TI, vr = TI;
        for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1)
        {
            if ((l & 1) != 0) vl = F(vl, Reflect(l++));
            if ((r & 1) != 0) vr = F(Reflect(--r), vr);
        }
        return F(vl, vr);
    }
}



Measured memory_bytes: 29760