#include <bits/stdc++.h>
using namespace std;
struct maca {
  long long int b, v, g;
} mg[100005];
struct kuca {
  long long int p, k, s, ta, tb;
} gr[1000];
int main() {
  ios::sync_with_stdio(false);
  long long int i, j, k, m, n, h, koren, res, grupa, ug = 0, pp, l, d, x;
  cin >> n >> m;
  koren = sqrt(n);
  j = 1;
  grupa = 1;
  ug = 1;
  gr[1].p = 1;
  for (i = 1; i <= n; i++, j++) {
    mg[i].b = i;
    mg[i].v = 0;
    if (j <= koren)
      mg[i].g = grupa;
    else {
      gr[ug].k = i - 1;
      grupa++;
      j = 1;
      mg[i].g = grupa;
      ug++;
      gr[ug].p = i;
    }
  }
  gr[ug].k = n;
  for (h = 1; h <= m; h++) {
    cin >> pp >> l >> d;
    if (pp == 1) {
      cin >> x;
      for (i = 1; i <= ug; i++) {
        if (gr[i].p > d)
          continue;
        else if (gr[i].k < l)
          continue;
        else if (gr[i].p >= l && gr[i].k <= d) {
          if (gr[i].ta) {
            gr[i].tb += abs(gr[i].ta - x);
            gr[i].s += abs(gr[i].ta - x) * (gr[i].k - gr[i].p + 1);
          } else {
            for (j = gr[i].p; j <= gr[i].k; j++) {
              mg[j].v += abs(mg[j].b - x);
              gr[i].s += abs(mg[j].b - x);
            }
          }
          gr[i].ta = x;
        } else {
          if (gr[i].ta) {
            for (j = gr[i].p; j <= gr[i].k; j++) mg[j].b = gr[i].ta;
            gr[i].ta = 0;
          }
          for (j = gr[i].p; j <= gr[i].k; j++) {
            if (j >= l && j <= d) {
              mg[j].v += abs(mg[j].b - x);
              gr[i].s += abs(mg[j].b - x);
              mg[j].b = x;
            }
          }
        }
      }
    } else {
      res = 0;
      for (i = 1; i <= ug; i++) {
        if (gr[i].p > d)
          continue;
        else if (gr[i].k < l)
          continue;
        else if (gr[i].p >= l && gr[i].k <= d)
          res = res + gr[i].s;
        else {
          for (j = gr[i].p; j <= gr[i].k; j++) {
            if (j >= l && j <= d) res = res + mg[j].v + gr[i].tb;
          }
        }
      }
      cout << res << endl;
    }
  }
  return 0;
}
