def add(a, w, d)
  while a <= $n
#    p "a: #{a}"
    d[a] += w
    a += a & -a
  end
end

def sum(i, d)
  ret = 0
  x = i
  while x > 0
    ret += d[x]
    x -= x & -x
  end
  return ret
end

$n, q = gets.split.map(&:to_i)
d = Array.new($n+1){0}
p = Array.new($n+1){0}

q.times{
  com, s, t, x = gets.split.map(&:to_i)
  case com
  when 0
    add(s, x, d)
    add(t+1, -x, d)
    add(s, -x*s, p)
    add(t+1, x*(t+1), p)
  when 1
    p sum(t, p) + sum(t, d)*(t+1) - sum(s, p) - sum(s, d) * s
  end
}