use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());

    let n = scan.read::<usize>();
    let q = scan.read::<usize>();
    let mut segtree = SegRangeAdd::new(vec![0;n]);
    for _ in 0..q {
        let com = scan.read::<i32>();
        if com == 0 {
            let s = scan.read::<usize>()-1;
            let t = scan.read::<usize>()-1;
            let x = scan.read::<i64>();
            segtree.add(s..t+1, x);
        } else {
            let s = scan.read::<usize>()-1;
            let t = scan.read::<usize>()-1;
            println!("{}", segtree.sum(s..t+1));
        }
    }
}

use std::ops::Range;

fn contains(p: &Range<usize>, q: &Range<usize>) -> bool {
    p.start <= q.start && q.end <= p.end
}

fn separates(p: &Range<usize>, q: &Range<usize>) -> bool {
    p.end <= q.start || q.end <= p.start
}

fn size(p: &Range<usize>) -> usize {
    p.end - p.start
}

struct SegRangeAdd {
    node: Vec<i64>,
    lazy: Vec<i64>,
    n: usize,
}

impl SegRangeAdd {
    fn new(v: Vec<i64>) -> SegRangeAdd {
        let size = v.len();
        let mut n = 1;
        while n < size {n *= 2}
        let mut node = vec![0;2*n-1];
        let mut lazy = vec![0;2*n-1];
        for i in 0..size {node[i+n-1] = v[i]}
        for i in (0..n - 1).rev() {node[i] = node[i*2+1] + node[i*2+2]}
        SegRangeAdd {node: node, lazy: lazy, n: n}
    }

    fn eval(&mut self, k: usize, range: Range<usize>) {
        if self.lazy[k] != 0 {
            self.node[k] += self.lazy[k];
            if size(&range) > 1 {
                self.lazy[2*k+1] += self.lazy[k] / 2;
                self.lazy[2*k+2] += self.lazy[k] / 2;
            }
            self.lazy[k] = 0;
        }
    }

    fn add(&mut self, query: Range<usize>, x: i64) {
        let n = self.n;
        self.addrec(query, x, 0, 0..n)
    }

    fn addrec(&mut self, query: Range<usize>, x: i64, k: usize, range: Range<usize>) {
        self.eval(k, range.clone());
        if separates(&query, &range) {return}
        if contains(&query, &range) {
            self.lazy[k] += size(&range) as i64 * x;
            self.eval(k, range.clone());
        } else {
            self.addrec(query.clone(), x, 2*k+1, range.start..(range.start+range.end)/2);
            self.addrec(query.clone(), x, 2*k+2, (range.start+range.end)/2..range.end);
            self.node[k] = self.node[2*k+1] + self.node[2*k+2];
        }
    }

    fn sum(&mut self, query: Range<usize>) -> i64 {
        let n = self.n;
        self.sumrec(query, 0, 0..n)
    }

    fn sumrec(&mut self, query: Range<usize>, k: usize, range: Range<usize>) -> i64 {
        if separates(&query, &range) {return 0}
        self.eval(k, range.clone());
        if contains(&query, &range) {return self.node[k]}
        let vl = self.sumrec(query.clone(), 2*k+1, range.start..(range.start+range.end)/2);
        let vr = self.sumrec(query.clone(), 2*k+2, (range.start+range.end)/2..range.end);
        vl + vr
    }
}

// region template
#[allow(dead_code)]
fn uz(i: i32) -> usize { i as usize }

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: i32) -> Vec<T> {
        let mut ret = vec![];
        for _ in 0..n { ret.push(self.read::<T>()) }
        ret
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion


Measured memory_bytes: 9020