#include <bits/stdc++.h>
using namespace std;

class segment_tree{
    vector<int64_t> val;
    vector<pair<int64_t, int64_t>> op;
    vector<pair<size_t, size_t>> range;

    size_t N, depth;

    inline void merge(size_t target, int64_t alpha, int64_t beta){
        op[target] = {op[target].first * alpha, op[target].second * alpha + beta};
    }
    inline void propagate(size_t target){
        // min, max -> width = 1
        val[target] = op[target].first * val[target] + op[target].second * (range[target].second - range[target].first);
        if(target  < N){
            merge(2*target, op[target].first, op[target].second);
            merge(2*target+1, op[target].first, op[target].second);
        }
        op[target] = {1, 0};
    }
    
    inline void eval(int n){
        stack<size_t> stk;
        for(;n>0;n>>=1) stk.push(n);
        while(!stk.empty()){
            propagate(stk.top());
            stk.pop();
        }
    }
    inline void get_target(vector<size_t> &target, size_t left, size_t right, stack<size_t> *refresh=nullptr){
        queue<size_t> partial;
        
        if(left <= 0 && right >= N) target.push_back(1);
        else partial.push(1);

        while(!partial.empty()){
            size_t i = partial.front();
            if(refresh != nullptr) refresh->push(i);
            partial.pop();

            propagate(i);

            if(left <= range[i].first){
                if(right < range[i*2].second) partial.push(i*2);
                else{
                    target.push_back(i*2);
                    if(range[i*2+1].first < right) partial.push(i*2+1);
                }
            }else{
                if(left < range[i*2].second){
                    partial.push(i*2);
                    if(range[i*2+1].second <= right) target.push_back(i*2+1);
                    else if(range[i*2].second < right) partial.push(i*2+1); 
                }else{
                    if(left <= range[i*2+1].first && range[i*2+1].second <= right) target.push_back(i*2+1);
                    else partial.push(i*2+1);
                }
            }
        }
    }
public:
    segment_tree(size_t n){
        for(depth=0;(1ULL<<depth)<n;depth++);
        N = 1ULL<<depth;
        val.reserve(1ULL<<(++depth));
        op.reserve(1ULL<<depth);
        range.reserve(1ULL<<depth);
        for(size_t i=2*N-1;i>0;i--){
            if(i>=N) range[i] = {i-N, i-N+1};
            else range[i] = {range[2*i].first, range[2*i+1].second};
        }
    }
    int64_t operator[](size_t i){
        eval(N+i);
        return val[N+i];
    }
    void operate(int64_t alpha, int64_t beta, size_t left, size_t right){
        if(right <= left) return;

        vector<size_t> target;
        stack<size_t> refresh;
        get_target(target, left, right, &refresh);
        for(auto i : target){
            merge(i, alpha, beta);
            propagate(i);
        }
        while(!refresh.empty()){
            size_t i = refresh.top();
            refresh.pop();
            //min, max -> change
            propagate(i*2);
            propagate(i*2+1);
            val[i] = val[i*2] + val[i*2+1];
        }
    }
    int64_t get_sum(size_t left, size_t right){
        if(right <= left) return 0;
        
        vector<size_t> target;
        get_target(target, left, right);
        int64_t ret = 0;
        for(auto i : target){
            ret += op[i].first * val[i] + op[i].second * (range[i].second - range[i].first);
        }
        return ret;
    }
    void update(int64_t val, size_t pos){
        operate(0, val, pos, pos+1);
    }
    void update(int64_t val, size_t left, size_t right){
        operate(0, val, left, right);
    }
    void add(int64_t val, size_t pos){
        operate(1, val, pos, pos+1);
    }
    void add(int64_t val, size_t left, size_t right){
        operate(1, val, left, right);
    }

    void dump(){
        for(int i=1;i<2*N;i++){
            eval(i);
            cerr << val[i] << " ";
        }
        cerr << endl;
    }
};

int main(){
    int n, q;
    cin >> n >> q;
    segment_tree st(n);

    for(int i=0;i<q;i++){
        int com;
        cin >> com;
        if(com == 0){
            int s, t, x;
            cin >> s >> t >> x;
            st.update(x, s, t+1);
        }else{
            int s, t;
            cin >> s >> t;
            cout << st.get_sum(s, t+1) << endl;
        }
        //st.dump();
    }
    
    return 0;
}


Measured memory_bytes: 11732