#include<algorithm>
#include<iostream>
#include<memory>
using Size = int;
template<typename T> class SegmentTree {
 public:
  SegmentTree(Size SIZE, T INF = 2e9) : SIZE(SIZE), INF(INF), ROOT(std::make_unique<Node>(0, INF)) {
    ROOT->update = 0;
  }
  void update(Size a, Size b, T v) {update(a, b, v, ROOT, 0, SIZE);}
  void add(Size a, Size b, T v) {add(a, b, v, ROOT, 0, SIZE);}
  T sum(Size a, Size b) {return query(a, b).sum;}
  T min(Size a, Size b) {return query(a, b).min;}
  T max(Size a, Size b) {return query(a, b).max;}
  Size lower_bound(T v) {}
  void debug() {
    traverse(ROOT, 0, SIZE, 0);
  }
  void traverse(const auto& n, Size l, Size r, Size d) {
    // LEAF
//     push(n, l, r);
//     auto m = (l + r) / 2;
//     if(l + 1 == r) std::cout << n->sum << " : " << n->min << " : " << n->max << std::endl;
//     else {
//       traverse(n->r_child, m, r, d + 1);
//       traverse(n->l_child, l, m, d + 1);
//     }
    // ALL
    push(n, l, r);
    auto m = (l + r) / 2;
    if(l+1 != r) traverse(n->r_child, m, r, d + 1);
    for(auto i = 0; i < d; ++i) std::cout << "    ";
    std::cout << n->sum << ":" << n->min << ":" << n->max;
//     std::cout << l << " to " << r;
    std::cout << std::endl;
    if(l+1 != r) traverse(n->l_child, l, m, d + 1);
  }
 private:
  struct Node {
    T sum;
    T min;
    T max;
    T update;
    T add;
    std::unique_ptr<Node> l_child, r_child;
    Node(T v, T INF) : sum(v), min(v), max(v), update(INF), add(INF) {}
  };
  inline void push(const auto& n, Size l, Size r) {
    if(not n->l_child) n->l_child = std::make_unique<Node>(0, INF);
    if(not n->r_child) n->r_child = std::make_unique<Node>(0, INF);
    if(n->update != INF) {
      n->add = INF;
      n->l_child->update = n->r_child->update = n->update;
      n->sum = (r - l) * n->update;
      n->min = n->update;
      n->max = n->update;
      n->update = INF;
    }
    if(n->add != INF) {
      if(n->l_child->add != INF) n->l_child->add += n->add;
      else                       n->l_child->add = n->add;
      if(n->r_child->add != INF) n->r_child->add += n->add;
      else                       n->r_child->add = n->add;
      if(n->l_child->update != INF) n->l_child->update += n->add;
      if(n->r_child->update != INF) n->r_child->update += n->add;
      n->sum += (r - l) * n->add;
      n->min += n->add;
      n->max += n->add;
      n->add = INF;
    }
  }
  inline void fix(const auto& n) {
    n->sum = n->l_child->sum + n->r_child->sum;
    n->min = std::min(n->l_child->min, n->r_child->min);
    n->max = std::max(n->l_child->max, n->r_child->max);
  }
  void update(Size a, Size b, T v, const auto& n, Size l, Size r) {
    push(n, l, r);
    if(b <= l || r <= a) return;
    if(a <= l && r <= b) {
      n->update = v;
      push(n, l, r);
      return;
    }
    auto m = (l + r) / 2;
    update(a, b, v, n->l_child, l, m);
    update(a, b, v, n->r_child, m, r);
    fix(n);
  }
  void add(Size a, Size b, T v, const auto& n, Size l, Size r) {
    push(n, l, r);
    if(b <= l || r <= a) return;
    if(a <= l && r <= b) {
      n->add = v;
      push(n, l, r);
      return;
    }
    auto m = (l + r) / 2;
    add(a, b, v, n->l_child, l, m);
    add(a, b, v, n->r_child, m, r);
    fix(n);
  }
  Node query(Size a, Size b) {
    Node res(0, INF);
    res.min = INF;
    res.max = -INF;
    query(res, a, b, ROOT, 0, SIZE);
    return res;
  }
  void query(auto& res, Size a, Size b, const auto& n, Size l, Size r) {
    push(n, l, r);
    if(b <= l || r <= a) return;
    if(a <= l && r <= b) {
      res.sum += n->sum;
      res.min = std::min(res.min, n->min);
      res.max = std::max(res.max, n->max);
      return;
    }
    auto m = (l + r) / 2;
    query(res, a, b, n->l_child, l, m);
    query(res, a, b, n->r_child, m, r);
  }
  const Size SIZE;
  const T INF;
  const std::unique_ptr<Node> ROOT;
};

#include<bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n >> q;
  SegmentTree<long long> segtree(n);
  for(auto i = 0; i < q; ++i) {
    int type;
    cin >> type;
    if(type) {
      int s, t;
      cin >> s >> t;
      cout << segtree.sum(s-1, t) << endl;
    } else {
      int s, t, x;
      cin >> s >> t >> x;
      segtree.add(s-1, t, x);
    }
  }
//   segtree.debug();
}

Measured memory_bytes: 26852