package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	q := getNextInt(scanner)
	seg := newSegment(n)
	for i := 0; i < q; i++ {
		switch getNextInt(scanner) {
		case 0:
			s := getNextInt(scanner) - 1
			t := getNextInt(scanner)
			x := getNextInt(scanner)
			seg.update(s, t, x, seg.add)
		case 1:
			s := getNextInt(scanner) - 1
			t := getNextInt(scanner)
			fmt.Fprintln(writer, seg.query(s, t, 0, seg.add))
		}
	}

}

type vertex struct {
	v, lv int
	p     bool
}
type segment [][]vertex

func newSegment(n int) segment {
	seg := make(segment, 0)
	for n > 1 {
		seg = append(seg, make([]vertex, n))
		n = (n + 1) >> 1
	}
	seg = append(seg, make([]vertex, 1))
	return seg
}
func (seg segment) propagate(h, i int) {
	if h >= len(seg) {
		return
	}
	seg.propagate(h+1, i>>1)
	if seg[h][i].p == false {
		return
	}
	if h-1 >= 0 {
		seg[h-1][i<<1].lv += seg[h][i].lv
		seg[h-1][i<<1].p = true
		if i<<1+1 < len(seg[h-1]) {
			seg[h-1][i<<1+1].lv += seg[h][i].lv
			seg[h-1][i<<1+1].p = true
		}
	}
	seg[h][i].v += seg[h][i].lv * seg.count(h, i)
	seg[h][i].lv = 0
	seg[h][i].p = false
}
func (seg segment) count(h, i int) int {
	l := i
	r := i + 1
	for h := h - 1; h >= 0; h-- {
		l <<= 1
		r <<= 1
	}
	return r - l
}
func (seg segment) up(h, i int, f func(x, y int) int) {
	for h = h + 1; h < len(seg); h++ {
		i >>= 1
		if i<<1+1 < len(seg[h-1]) {
			seg[h][i].v = f(seg.sum(h-1, i<<1), seg.sum(h-1, i<<1+1))
		} else {
			seg[h][i].v = seg.sum(h-1, i<<1)
		}
	}
}
func (seg segment) sum(h, i int) int {
	return seg[h][i].v + seg[h][i].lv*seg.count(h, i)
}
func (seg segment) update(l, r int, v int, f func(x, y int) int) {
	for h := 0; h < len(seg) && l < r; h++ {
		if l&1 == 1 {
			seg[h][l].lv += v
			seg[h][l].p = true
			seg.propagate(h, l)
			seg.up(h, l, f)
			l++
		}
		l >>= 1
		if r&1 == 1 {
			seg[h][r-1].lv += v
			seg[h][r-1].p = true
			seg.propagate(h, r-1)
			seg.up(h, r-1, f)
		}
		r >>= 1
	}
}
func (seg segment) query(l, r int, s int, f func(x, y int) int) int {
	for h := 0; h < len(seg) && l < r; h++ {
		if l&1 == 1 {
			seg.propagate(h, l)
			seg.up(h, l, f)
			s = f(s, seg[h][l].v)
			l++
		}
		l >>= 1
		if r&1 == 1 {
			seg.propagate(h, r-1)
			seg.up(h, r-1, f)
			s = f(s, seg[h][r-1].v)
		}
		r >>= 1
	}
	return s
}
func (seg segment) add(x, y int) int {
	return x + y
}



Measured memory_bytes: 9316