#include <bits/stdc++.h>
using namespace std;
struct s {
  long long col, colf, flag;
} node[100010 << 2];
void build(int l, int r, int tr) {
  node[tr].col = node[tr].colf = node[tr].flag = 0;
  if (l == r) {
    node[tr].col = l;
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, tr << 1);
  build(mid + 1, r, tr << 1 | 1);
}
long long ABS(long long x) {
  if (x < 0) return -x;
  return x;
}
void pushdown(int tr, int m) {
  if (node[tr].flag) {
    node[tr << 1].flag += node[tr].flag;
    node[tr << 1 | 1].flag += node[tr].flag;
    node[tr << 1].colf += node[tr].flag * (m - (m >> 1));
    node[tr << 1 | 1].colf += node[tr].flag * (m >> 1);
    node[tr].flag = 0;
  }
  if (node[tr].col) {
    node[tr << 1].col = node[tr << 1 | 1].col = node[tr].col;
  }
}
void pushup(int tr) {
  node[tr].colf = node[tr << 1].colf + node[tr << 1 | 1].colf;
  if (node[tr << 1].col == node[tr << 1 | 1].col)
    node[tr].col = node[tr << 1].col;
  else
    node[tr].col = 0;
}
void update(int L, int R, long long val, int l, int r, int tr) {
  if (L <= l && r <= R) {
    if (node[tr].col) {
      node[tr].colf += (r - l + 1) * ABS(node[tr].col - val);
      node[tr].flag += ABS(node[tr].col - val);
      node[tr].col = val;
      return;
    }
  }
  pushdown(tr, r - l + 1);
  int mid = (l + r) >> 1;
  if (L <= mid) update(L, R, val, l, mid, tr << 1);
  if (R > mid) update(L, R, val, mid + 1, r, tr << 1 | 1);
  pushup(tr);
}
long long query(int L, int R, int l, int r, int tr) {
  if (L <= l && r <= R) {
    return node[tr].colf;
  }
  pushdown(tr, r - l + 1);
  long long a, b;
  a = 0;
  b = 0;
  int mid = (l + r) >> 1;
  if (L <= mid) {
    a = query(L, R, l, mid, tr << 1);
  }
  if (R > mid) {
    b = query(L, R, mid + 1, r, tr << 1 | 1);
  }
  return (a + b);
}
int main() {
  int n, m;
  while (scanf("%d%d", &n, &m) != EOF) {
    build(1, n, 1);
    while (m--) {
      int op;
      scanf("%d", &op);
      if (op == 1) {
        int a, b;
        long long c;
        scanf("%d%d%lld", &a, &b, &c);
        update(a, b, c, 1, n, 1);
      } else {
        int a, b;
        scanf("%d%d", &a, &b);
        printf("%lld\n", query(a, b, 1, n, 1));
      }
    }
  }
}
