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 < n; i++ {
		seg[0][i].c = 1
	}
	for h := 0; h < len(seg)-1; h++ {
		for i := 0; i < len(seg[h]); i++ {
			seg[h+1][i>>1].c += seg[h][i].c
		}
	}

	for i := 0; i < q; i++ {
		c := getNextInt(scanner)
		s := getNextInt(scanner)
		t := getNextInt(scanner)
		switch c {
		case 0:
			x := getNextInt(scanner)
			seg.update(s, t+1, x, seg.add)
		case 1:
			fmt.Fprintln(writer, seg.query(s, t+1, 0, seg.add))
		}
	}
}

type lazy struct {
	v, w, c int
	p       bool
}

func (l *lazy) hold(w int) {
	l.w = w
	l.p = true
}
func (l *lazy) assign() {
	l.v = l.w * l.c
	l.w = 0
	l.p = false
}
func (l *lazy) eval() int {
	if l.p {
		return l.w * l.c
	}
	return l.v
}

type segment [][]lazy

func newSegment(n int) segment {
	seg := make(segment, 0)
	for n > 1 {
		seg = append(seg, make([]lazy, n))
		n = (n + 1) >> 1
	}
	seg = append(seg, make([]lazy, 1))
	return seg
}
func (seg segment) push(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[h-1][i<<1].eval(), seg[h-1][i<<1+1].eval())
			continue
		}
		seg[h][i].v = seg[h-1][i<<1].eval()
	}
}
func (seg segment) pull(h, i int) {
	if h >= len(seg) {
		return
	}
	seg.pull(h+1, i>>1)
	if seg[h][i].p {
		if h > 0 {
			seg[h-1][i<<1].hold(seg[h][i].w)
			if i<<1+1 < len(seg[h-1]) {
				seg[h-1][i<<1+1].hold(seg[h][i].w)
			}
		}
		seg[h][i].assign()
	}
}
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.pull(h, l)
			seg[h][l].hold(v)
			seg.push(h, l, f)
			l++
		}
		l >>= 1
		if r&1 == 1 {
			seg.pull(h, r-1)
			seg[h][r-1].hold(v)
			seg.push(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.pull(h, l)
			s = f(s, seg[h][l].eval())
			l++
		}
		l >>= 1
		if r&1 == 1 {
			seg.pull(h, r-1)
			s = f(s, seg[h][r-1].eval())
		}
		r >>= 1
	}
	return s
}

func (seg segment) add(x, y int) int {
	return x + y
}



Measured memory_bytes: 10916