//sub-BOF
#define _AOJ_
        /*vvv>
        zzzzzI
 .---.  zzuzuI                 .vgggg&,.
+++++=  dAC:|I  .WbbWo       JMM9^```?TMB`  ..&gNNg,.   gggggggJ,   qgggggggg] (&&&&&&&&[   c+OA&J,   (&&&&&&+J,   .cJeAA&-.  (&&&&&&&&x   .&AA&=-.
+++++=  dTqk|I  Xpbpbp      JM#`           (M#^   ?MMp  MM|   +TMN. JMF      ' |yk      ` dVY    7Vk,  Vy     XV  cVf     ?Y!  JM         V$      `
+++++=  dcf:|I  Xppppp      dMN           .MM+     .MM  MM|     MM] JMMMMMM+   |@tqkoh)  ,y0      (V$  yyyyyyyV7  VV           JMWyZWr    TWVVVVW&,
++++++  d7qk|0  Xppppp      ^HMN,    _.db  WMm,   .MMF  MM|   ..MM` JMF      . |yk       .WV&.   .XW'  yy   4yn.  jyn      +.  JM                #S
`++++`  ?ZZZX=  ?WWWW=        -THMMMMH9^    (TMMMMM9!   MMMMMMM""   JMMMMMMMME |UU.        ?TUUUUY=    UU.   (UU-  ^7TUUUV7!   JUUUUUUUU  7TUNKO*/


//basic
#pragma GCC target("sse4")
#include "bits/stdc++.h"
using namespace std;
typedef long long lint;
typedef long double ld;
typedef string cs;
#define all(v) v.begin(),v.end()
#define pb push_back

//rep
#define _vcppunko4(tuple) _getname4 tuple
#define _getname4(_1,_2,_3,_4,name,...) name
#define _getname3(_1,_2,_3,name,...) name
#define _trep2(tuple) _rep2 tuple
#define _trep3(tuple) _rep3 tuple
#define _trep4(tuple) _rep4 tuple
#define _rep1(n) for(lint i=0;i<n;++i)
#define _rep2(i,n) for(lint i=0;i<n;++i)
#define _rep3(i,a,b) for(lint i=a;i<b;++i)
#define _rep4(i,a,b,c) for(lint i=a;i<b;i+=c)
#define _trrep2(tuple) _rrep2 tuple
#define _trrep3(tuple) _rrep3 tuple
#define _trrep4(tuple) _rrep4 tuple
#define _rrep1(n) for(lint i=n-1;i>=0;--i)
#define _rrep2(i,n) for(lint i=n-1;i>=0;--i)
#define _rrep3(i,a,b) for(lint i=b-1;i>=a;--i)
#define _rrep4(i,a,b,c) for(lint i=a+(b-a-1)/c*c;i>=a;i-=c)
#define rep(...) _vcppunko4((__VA_ARGS__,_trep4,_trep3,_trep2,_rep1))((__VA_ARGS__))
#define per(...) _vcppunko4((__VA_ARGS__,_trrep4,_trrep3,_trrep2,_rrep1))((__VA_ARGS__))
#define each(c) for(auto &e:c)

//io
template<class T>
istream& operator>>(istream& is,vector<T>& vec);
template<class T,size_t size>
istream& operator>>(istream& is,array<T,size>& vec);
template<class T,class L>
istream& operator>>(istream& is,pair<T,L>& p);
template<class T>
ostream& operator<<(ostream& os,vector<T>& vec);
template<class T,class L>
ostream& operator<<(ostream& os,pair<T,L>& p);
template<class T>
istream& operator>>(istream& is,vector<T>& vec){ for(T& x: vec) is>>x;return is; }
template<class T,class L>
istream& operator>>(istream& is,pair<T,L>& p){ is>>p.first;is>>p.second;return is; }
template<class T,class L>
ostream& operator<<(ostream& os,pair<T,L>& p){ os<<p.first<<" "<<p.second;return os; }
template<class T>
ostream& operator<<(ostream& os,vector<T>& vec){ os<<vec[0];rep(i,1,vec.size())os<<' '<<vec[i];return os; }
template<class T>
ostream& operator<<(ostream& os,deque<T>& deq){ os<<deq[0];rep(i,1,deq.size())os<<' '<<deq[i];return os; }

#ifdef __ENV_TQK__
#include<Windows.h>
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
inline void in(){ SetConsoleTextAttribute(hConsole,10); }
template <class Head,class... Tail>
inline void in(Head&& head,Tail&&... tail){
	SetConsoleTextAttribute(hConsole,15);
	cin>>head;in(move(tail)...);
}
#else
inline void in(){}
template <class Head,class... Tail>
inline void in(Head&& head,Tail&&... tail){ cin>>head;in(move(tail)...); }
#endif



inline bool out(){ return(cout<<'\n',0); }
template <class T>
inline bool out(T t){ return(cout<<t<<'\n',0); }
template <class Head,class... Tail>
inline bool out(Head head,Tail... tail){ cout<<head<<' ';out(move(tail)...);return 0; }
template <class T>
inline void alloc(T &c,lint s){ rep(c.size())c[i].resize(s); }
#define alc alloc

//TA
#define lin(...) lint __VA_ARGS__;in(__VA_ARGS__)
#define stin(...) string __VA_ARGS__;in(__VA_ARGS__)
#define vin(type,name,size) vector<type> name(size);in(name)
#define vvin(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__));in(name)
#define fi e.first
#define se e.second
#define YES(c) cout<<((c)?"YES\n":"NO\n"),0
#define Yes(c) cout<<((c)?"Yes\n":"No\n"),0
#define POSSIBLE(c) cout<<((c)?"POSSIBLE\n":"IMPOSSIBLE\n"),0
#define Possible(c) cout<<((c)?"Possible\n":"Impossible\n"),0
#define o(p) cout<<p<<endl,0
#define sp(p) cout<<p<<" "
#define no(p) cout<<p
inline constexpr lint gcd(lint a,lint b){ if(!a||!b)return 0;while(b){ lint c=b;b=a%b;a=c; }return a; }
template<typename T>
inline constexpr bool chmin(T &mn,const T &cnt){ if(mn>cnt){ mn=cnt;return 1; } else return 0; }
template<typename T>
inline constexpr bool chmax(T &mx,const T &cnt){ if(mx<cnt){ mx=cnt;return 1; } else return 0; }
#define ve(type) vector<type>
#define fn(ty1,ty2,ex) [](ty1 a,ty2 b){ return(ex); }
#define lfn(ex) [](lint a,lint b){ return(ex); }

//other
#ifdef __ENV_TQK__
#define deb(p) cout<<p<<endl,0
#else
#define deb(p) 0
#endif
struct Fastio{
	Fastio(){
		cin.tie(0),cout.tie(0);
		ios::sync_with_stdio(0);
		cout<<fixed<<setprecision(10);
	}
} __fastio;


//mint
#define md_tmp template<uint_fast64_t md=1000000007>
md_tmp class mint{
	using u64=uint_fast64_t;

public:
	u64 a;

	constexpr mint(const u64 x=0) noexcept: a(x%md){}
	constexpr u64 &value() noexcept{ return a; }
	constexpr const u64 &value() const noexcept{ return a; }
	constexpr mint operator+(const mint rhs) const noexcept{
		return mint(*this)+=rhs;
	}
	constexpr mint operator-(const mint rhs) const noexcept{
		return mint(*this)-=rhs;
	}
	constexpr mint operator*(const mint rhs) const noexcept{
		return mint(*this)*=rhs;
	}
	constexpr mint operator^(const lint rhs) const noexcept{
		return mint(*this)^=rhs;
	}
	constexpr mint operator/(const mint rhs) const noexcept{
		return mint(*this)/=rhs;
	}
	constexpr mint &operator+=(const mint rhs) noexcept{
		a+=rhs.a;
		if(a>=md)a-=md;
		return *this;
	}
	constexpr mint &operator-=(const mint rhs) noexcept{
		if(a<rhs.a)a+=md;
		a-=rhs.a;
		return *this;
	}
	constexpr mint &operator*=(const mint rhs) noexcept{
		a=a*rhs.a%md;
		return *this;
	}
	constexpr mint &operator^=(const lint rhs) noexcept{
		if(!rhs)return *this=1;
		u64 exp=rhs-1;
		mint base=this->a;
		while(exp){
			if(exp&1)*this*=base;
			base*=base;
			exp>>=1;
		}
		return *this;
	}
	constexpr mint &operator/=(const mint rhs) noexcept{
		a=(*this*(rhs^(md-2))).a;
		return *this;
	}
};
md_tmp istream& operator>>(istream& os,mint<md>& m){
	os>>m.a,m.a%=md;
	return os;
}
md_tmp ostream& operator<<(ostream& os,const mint<md>& m){
	return os<<m.a;
}
md_tmp mint<md> ncr(lint n,lint r){
	if(n<r||n<0||r<0)return mint<md>(0);
	mint<md>ncr_res=1,ncr_div=1;
	rep(r)ncr_res*=(n-i),ncr_div*=(r-i);
	return ncr_res/ncr_div;
}
#ifndef _AOJ_
mint<> operator""m(const unsigned long long n){ return mint<>(n); }
mint<998244353> operator""m9(const unsigned long long n){ return mint<998244353>(n); }
mint<1000003> operator""m3(const unsigned long long n){ return mint<1000003>(n); }
#endif


//const
#define linf 1152921504606846976
#define inf linf
#define MAXN 330
#define md_1e9_7 1000000007
#define md_998244353 998244353
#define pi 3.14159265358979323846
//#define mod md_1e9_7
const int d4[5]={0,1,0,-1,0};

//main------

class P{ public:lint f,s; P(lint a,lint b):f(a),s(b){}; P():f(0),s(0){}; };
istream& operator>>(istream& os,P& p){ os>>p.f>>p.s;return os; }
bool operator<(const P& l,const P& r){ return(l.f-r.f?l.f<r.f:l.s<r.s); }
bool operator>(const P& l,const P& r){ return(l.f-r.f?l.f>r.f:l.s>r.s); }

template < class M_act >
struct Lazy{
public:
	using Monoid = typename M_act::Monoid;
	using X = typename Monoid::T;
	using M = typename M_act::M;

private:
	size_t n;
	int h;
	vector< X > data;
	vector< M > lazy;
	vector< size_t > nodeLength;
	// call before use data[i]
	void eval(size_t i){
		if(lazy[i] == M_act::identity()) return;
		data[i] = M_act::actInto(lazy[i],nodeLength[i],data[i]);
		if(i < n){
			lazy[i * 2] = M_act::op(lazy[i],lazy[i * 2]);
			lazy[i * 2 + 1] = M_act::op(lazy[i],lazy[i * 2 + 1]);
		}
		lazy[i] = M_act::identity();
	}
	// call before use seg[i] = data[i + n]
	void evalDown(size_t i){
		i += n;
		for(int j = h - 1; j >= 0; j--) eval(i >> j);
	}
	// call after touch seg[i] = data[i + n]
	void propUp(size_t i){
		i += n;
		while(i >>= 1)
			eval(i * 2),eval(i * 2 + 1),data[i] = Monoid::op(data[i * 2],data[i * 2 + 1]);
	}

public:
	Lazy(): n(0){}
	Lazy(size_t n,X initial = Monoid::identity()): n(n){
		if(n > 0){
			h = 1;
			while(1u << h < n) h++;
			data.resize(2 * n,initial);
			lazy.resize(2 * n,M_act::identity());
			nodeLength.resize(2 * n,1);
			for(size_t i = n - 1; i > 0; i--) // fill from deep
				data[i] = Monoid::op(data[i * 2],data[i * 2 + 1]),
				nodeLength[i] = nodeLength[i * 2] + nodeLength[i * 2 + 1];
		}
	}
	template < class InputIter,class = typename iterator_traits< InputIter >::value_type >
	Lazy(InputIter first,InputIter last)
		: Lazy(distance(first,last)){
		if(n > 0){
			copy(first,last,begin(data) + n);
			for(size_t i = n - 1; i > 0; i--) // fill from deep
				data[i] = Monoid::op(data[i * 2],data[i * 2 + 1]);
		}
	}
	Lazy(vector< X > v): Lazy(v.begin(),v.end()){}
	Lazy(initializer_list< X > v): Lazy(v.begin(),v.end()){}
	void act(int l,int r,const M &m){
		if(l < 0) l = 0;
		if(l >= r) return;
		if(r >(int) n) r = n;
		evalDown(l);
		evalDown(r - 1);
		int tl = l,tr = r;
		for(l += n,r += n; l < r; l >>= 1,r >>= 1){
			if(l & 1) eval(l),lazy[l] = m,eval(l),l++;
			if(r & 1) --r,eval(r),lazy[r] = m,eval(r);
		}
		propUp(tl);
		propUp(tr - 1);
	}
	void set(size_t i,const X &x){
		assert(i < n);
		evalDown(i);
		data[i + n] = x;
		propUp(i);
	}
	X get(size_t i){
		assert(i < n);
		evalDown(i);
		return data[i + n];
	}
	X fold(int l,int r){
		if(l < 0) l = 0;
		if(l >= r) return Monoid::identity();
		if(r >(int) n) r = n;
		evalDown(l);
		evalDown(r - 1);
		X tmpL = Monoid::identity(),tmpR = Monoid::identity();
		for(l += n,r += n; l < r; l >>= 1,r >>= 1){
			if(l & 1) eval(l),tmpL = Monoid::op(tmpL,data[l]),l++;
			if(r & 1) --r,eval(r),tmpR = Monoid::op(data[r],tmpR);
		}
		return Monoid::op(tmpL,tmpR);
	}
	int size(){ return n; }
	inline void dum(int r = -1){
#ifdef DEBUG
		if(r < 0) r = n;
		DEBUG_OUT << "{";
		for(int i = 0; i < min(r,(int)n); i++) DEBUG_OUT << (i ? ", " : "") << get(i);
		DEBUG_OUT << "}" << endl;
#endif
	}
};

constexpr long long inf_monoid = 1e18 + 100;
struct Nothing{
	using T = char;
	using Monoid = Nothing;
	using M = T;
	static constexpr T op(const T &,const T &){ return T(); }
	static constexpr T identity(){ return T(); }
	template < class X >
	static constexpr X actInto(const M &,long long,const X &x){
		return x;
	}
};

template < class U = long long >
struct RangeMin{
	using T = U;
	static T op(const T &a,const T &b){ return std::min< T >(a,b); }
	static constexpr T identity(){ return T(inf_monoid); }
};

template < class U = long long >
struct RangeMax{
	using T = U;
	static T op(const T &a,const T &b){ return std::max< T >(a,b); }
	static constexpr T identity(){ return T(-inf_monoid); }
};

template < class U = long long >
struct RangeSum{
	using T = U;
	static T op(const T &a,const T &b){ return a + b; }
	static constexpr T identity(){ return T(0); }
};

template < class U >
struct RangeProd{
	using T = U;
	static T op(const T &a,const T &b){ return a * b; }
	static constexpr T identity(){ return T(1); }
};

template < class U = long long >
struct RangeOr{
	using T = U;
	static T op(const T &a,const T &b){ return a | b; }
	static constexpr T identity(){ return T(0); }
};

template < class U = long long >
struct RangeAnd{
	using T = U;
	static T op(const T &a,const T &b){ return a & b; }
	static constexpr T identity(){ return T(-1); }
};

template < size_t N >
struct RangeAnd< std::bitset< N > >{
	using T = std::bitset< N >;
	static T op(const T &a,const T &b){ return a & b; }
	static constexpr T identity(){ return std::bitset< N >().set(); }
};

template < class U = long long,class V = U >
struct RangeMinAdd{
	using X = U;
	using M = V;
	using Monoid = RangeMin< U >;
	static M op(const M &a,const M &b){ return a + b; }
	static constexpr M identity(){ return 0; }
	static X actInto(const M &m,long long,const X &x){ return m + x; }
};

template < class U = long long,class V = U >
struct RangeMaxAdd{
	using X = U;
	using M = V;
	using Monoid = RangeMax< U >;
	static M op(const M &a,const M &b){ return a + b; }
	static constexpr M identity(){ return 0; }
	static X actInto(const M &m,long long,const X &x){ return m + x; }
};

template < class U = long long,class V = U >
struct RangeMinSet{
	using M = U;
	using Monoid = RangeMin< U >;
	using X = typename Monoid::T;
	static M op(const M &a,const M &){ return a; }
	static constexpr M identity(){ return M(-inf_monoid); }
	static X actInto(const M &m,long long,const X &x){ return m == identity() ? x : m; }
};

template < class U = long long,class V = U >
struct RangeMaxSet{
	using M = U;
	using Monoid = RangeMax< U >;
	using X = typename Monoid::T;
	static M op(const M &a,const M &){ return a; }
	static constexpr M identity(){ return M(-inf_monoid); }
	static X actInto(const M &m,long long,const X &x){ return m == identity() ? x : m; }
};

template < class U = long long,class V = U >
struct RangeSumAdd{
	using X = U;
	using M = V;
	using Monoid = RangeSum< U >;
	static M op(const M &a,const M &b){ return a + b; }
	static constexpr M identity(){ return 0; }
	static X actInto(const M &m,long long n,const X &x){ return m * n + x; }
};

template < class U = long long,class V = U >
struct RangeSumSet{
	using X = U;
	using M = V;
	using Monoid = RangeSum< U >;
	static M op(const M &a,const M &){ return a; }
	static constexpr M identity(){ return M(-inf_monoid); }
	static X actInto(const M &m,long long n,const X &x){
		return m == identity() ? x : m * n;
	}
};

template < class U,class V = U >
struct RangeProdMul{
	using X = U;
	using M = V;
	using Monoid = RangeProd< U >;
	static M mpow(M a,long long b){
		X r(1);
		while(b){
			if(b & 1) r = r * a;
			a = a * a;
			b >>= 1;
		}
		return r;
	}
	static M op(const M &a,const M &b){ return a * b; }
	static constexpr M identity(){ return M(1); }
	static X actInto(const M &m,long long n,const X &x){ return x * mpow(m,n); }
};

template < class U,class V = U >
struct RangeProdSet{
	using X = U;
	using M = V;
	using Monoid = RangeProd< U >;
	static M op(const M &a,const M &){ return a; }
	static constexpr M identity(){ return V::unused; }
	static X actInto(const M &m,long long n,const X &){
		if(m == identity()) return;
		return RangeProdMul< U,V >::mpow(m,n);
	}
};

template < class U = long long,class V = U >
struct RangeOr2{
	using X = U;
	using M = V;
	using Monoid = RangeOr< U >;
	static M op(const M &a,const M &b){ return a | b; }
	static constexpr M identity(){ return M(0); }
	static X actInto(const M &m,long long,const X &x){ return m | x; }
};

template < class U = long long,class V = U >
struct RangeAnd2{
	using X = U;
	using M = V;
	using Monoid = RangeAnd< U >;
	static M op(const M &a,const M &b){ return a & b; }
	static constexpr M identity(){ return M(-1); }
	static X actInto(const M &m,long long,const X &x){ return m & x; }
};

template < class U,size_t N >
struct RangeAnd2< U,std::bitset< N > >{
	using X = U;
	using M = std::bitset< N >;
	using Monoid = RangeAnd< U >;
	static M op(const M &a,const M &b){ return a & b; }
	static constexpr M identity(){ return std::bitset< N >().set(); }
	static X actInto(const M &m,long long,const X &x){ return m & x; }
};

int main(){

	lint n,q;in(n,q);
	Lazy<RangeSumAdd<>>ki(n);
	while(q--){
		lint ty,s,t,x;in(ty);
		if(ty){
			in(s,t);
			out(ki.fold(--s,t));
		} else{
			in(s,t,x);
			ki.act(--s,t,x);
		}
	}
}

//sub-EOF


Measured memory_bytes: 7588