#include<bits/stdc++.h>
using namespace std;
using UL=unsigned int;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(UL i=0; i<(n); i++)

struct RSQ_RUQ{
 UL N;
 struct Node{ LL x; LL s; bool z; };
 vector<Node> V;

 void init(UL n){
  N=1; while(N<n) N<<=1;
  V.assign(N*2,Node{0,0,true});
 }

 void upd(UL l,UL r,LL x,UL a=0,UL b=0,UL i=~0u){
  if(i==~0u){ a=0; i=1; b=N; }
  if(r<=a || b<=l) return;
  if(l<=a && b<=r){ V[i]={x,x*(b-a),true}; return; }
  if(V[i].z){
   V[i<<1] = V[(i<<1)+1] = {V[i].x,V[i].s/2,true};
  }
  upd(l,r,x,a,(b+a)>>1,i<<1);
  upd(l,r,x,(b+a)>>1,b,(i<<1)+1);
  V[i]={0,V[i<<1].s+V[(i<<1)+1].s,false};
 }

 LL sum(UL l,UL r,UL a=0,UL b=0,UL i=~0u){
  if(i==~0u){ a=0; i=1; b=N; }
  if(r<=a || b<=l) return 0;
  if(l<=a && b<=r) return V[i].s;
  if(V[i].z) return V[i].x*(min(r,b)-max(l,a));
  LL q1=sum(l,r,a,(b+a)>>1,i<<1);
  LL q2=sum(l,r,(b+a)>>1,b,(i<<1)+1);
  return q1+q2;
 }

} G;

int main(){
 UL N,Q; scanf("%u%u",&N,&Q);
 G.init(N);
 rep(q,Q){
  UL c; scanf("%u",&c);
  if(c==0){
   UL l,r; LL x; scanf("%u%u%lld",&l,&r,&x);
   G.upd(l,r+1,x);
  }
  if(c==1){
   UL l,r; scanf("%u%u",&l,&r);
   printf("%lld\n",G.sum(l,r+1));
  }
 }
 return 0;
}

