#include<cstdio>
#include<vector>
#include<functional>
using namespace std;
typedef long long ll;

template <typename T>
class SegmentTree {
  ll n;
  vector<T> node;
  function<T(T, T)> fun, fun2;
  bool customChange;
  T initValue;
public:
  void init(ll num, function<T(T, T)> resultFunction, T value, function<T(T, T)> changeFunction = NULL) {
    // changeFunction: (input, beforevalue) => newvalue
    fun = resultFunction;
    fun2 = changeFunction;
    customChange = changeFunction != NULL;
    n = 1;
    while (n < num) n *= 2;
    node.resize(2 * n - 1, value);
    initValue = value;
  }
  void valueChange(ll num, T value) {
    num += n-1;
    if (customChange) node[num] = changeFunction(value, node[num]);
    else node[num] = value;
    while (num > 0) num = (num - 1) / 2, node[num] = fun(node[num * 2 + 1], node[num * 2 + 2]);
  }
  T rangeQuery(ll a, ll b, ll l = 0, ll r = -1, ll k = 0) { // [a, b)
    if (r == -1) r = n;
    if (a <= l && r <= b) return node[k];
    if (b <= l || r <= a) return initValue;
    ll mid = (l + r) / 2;
    return fun(rangeQuery(a, b, l, mid, 2*k+1), rangeQuery(a, b, mid, r, 2*k+2));
  }
};

template <typename T>
class LazySegmentTree {
  ll n;
  vector<T> node;
  vector<T> lazyNode;
  function<T(T, T)> fun, fun2;
  T initValue;
  T substitution(T a, T b) { return a; }
  void eval(ll k, ll l, ll r) {
    if (lazyNode[k] == 0) return;
    node[k] = fun2(lazyNode[k], node[k]);
    if (r - l > 1) {
      lazyNode[2 * k + 1] = fun2(lazyNode[k] / 2, lazyNode[2 * k + 1]);
      lazyNode[2 * k + 2] = fun2(lazyNode[k] / 2, lazyNode[2 * k + 2]);
    }
    lazyNode[k] = initValue;
  }
public:
  void init(ll num, function<T(T, T)> resultFunction, T value, function<T(T, T)> changeFunction = substitution) {
    // changeFunction: (input, beforevalue) => newvalue
    fun = resultFunction;
    fun2 = changeFunction;
    n = 1;
    while (n < num) n *= 2;
    node.resize(2 * n - 1, value);
    lazyNode.resize(2 * n - 1, value);
    initValue = value;
  }
  void rangeChange(ll a, ll b, T value, ll l = 0, ll r = -1, ll k = 0) {
    if (r == -1) r = n;
    eval(k, l, r);
    if (b <= l || r <= a) return;
    if (a <= l && r <= b) {
      lazyNode[k] = fun2(value * (r - l), lazyNode[k]);
      eval(k, l, r);
    } else {
      ll mid = (l + r) / 2;
      rangeChange(a, b, value, l, mid, 2*k+1);
      rangeChange(a, b, value, mid, r, 2*k+2);
      node[k] = fun(node[2*k+1], node[2*k+2]);
    }
  }
  T rangeQuery(ll a, ll b, ll l = 0, ll r = -1, ll k = 0) { // [a, b)
    if (r == -1) r = n;
    if (b <= l || r <= a) return initValue;
    eval(k, l, r);
    if (a <= l && r <= b) return node[k];
    ll mid = (l + r) / 2;
    return fun(rangeQuery(a, b, l, mid, 2*k+1), rangeQuery(a, b, mid, r, 2*k+2));
  }
};

ll n, q, com, s, t, x;
LazySegmentTree<ll> sgt;
ll sum(ll a, ll b) { return a + b; }

int main() {
  scanf("%lld%lld", &n, &q);
  sgt.init(n, sum, 0, sum);
  for (ll i = 0; i < q; i++) {
    scanf("%lld", &com);
    if (com == 0) {
      scanf("%lld%lld%lld", &s, &t, &x);
      sgt.rangeChange(s-1, t, x);
    } else {
      scanf("%lld%lld", &s, &t);
      printf("%lld\n", sgt.rangeQuery(s-1, t));
    }
  }
}



Measured memory_bytes: 6360