#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   const int N = 1e5 + 10;   const long long mod = 1e9 + 7;   const long long mod2 = 998244353;   const int inf = 1e9;   const int LOG = 22;   long long pw(long long a, long long b, long long M) {     return (!b ? 1                : (b & 1 ? (a * pw(a * a % M, b / 2, M)) % M                         : pw(a * a % M, b / 2, M)));   }   struct node {     int mx1, mx2, cnt, lz;     long long sum;     node(int m1 = -inf, int m2 = -inf, int c = 0, int l = inf, long long s = 0) {       mx1 = m1, mx2 = m2, cnt = c, lz = l, sum = s;     }     friend node operator|(node L, node R) {       if (L.mx1 < R.mx1) swap(L, R);       if (L.mx1 == R.mx1)         L.cnt += R.cnt;       else         L.mx2 = max(L.mx2, R.mx1);       L.mx2 = max(L.mx2, R.mx2);       L.sum += R.sum;       L.lz = inf;       return L;     }   };   struct segment_beats {     node seg[N << 2];     void shift(int v, int lz) {       seg[v].lz = min(seg[v].lz, lz);       seg[v].sum -= 1ll * seg[v].cnt * max(0, seg[v].mx1 - lz);       seg[v].mx1 = min(seg[v].mx1, lz);     }     void second(int v, int tl, int tr) {       if (tl == tr) return;       shift(v << 1, seg[v].lz);       shift(v << 1 | 1, seg[v].lz);     }     void change(int p, int x, int v = 1, int tl = 1, int tr = N - 1) {       second(v, tl, tr);       if (p > tr || p < tl) return;       if (tl == tr) {         seg[v] = node(x, -inf, 1, inf, x);         return;       }       int mid = (tl + tr) >> 1;       change(p, x, v << 1, tl, mid), change(p, x, v << 1 | 1, mid + 1, tr);       seg[v] = seg[v << 1] | seg[v << 1 | 1];     }     void upd(int l, int r, int x, int v = 1, int tl = 1, int tr = N - 1) {       second(v, tl, tr);       if (l > tr || r < tl || l > r || seg[v].mx1 <= x) return;       if (l <= tl && tr <= r && seg[v].mx2 < x) {         shift(v, x);         return;       }       int mid = (tl + tr) >> 1;       upd(l, r, x, v << 1, tl, mid), upd(l, r, x, v << 1 | 1, mid + 1, tr);       seg[v] = seg[v << 1] | seg[v << 1 | 1];     }     long long get(int l, int r, int v = 1, int tl = 1, int tr = N - 1) {       second(v, tl, tr);       if (l > tr || r < tl || l > r) return 0ll;       if (l <= tl && tr <= r) {         return seg[v].sum;       }       int mid = (tl + tr) >> 1;       return get(l, r, v << 1, tl, mid) + get(l, r, v << 1 | 1, mid + 1, tr);     }   } seg1, seg2;   struct segment {     int lz[N << 2];     segment() {       for (int i = 0; i < N << 2; i++) lz[i] = inf;     }     void upd(int l, int r, int x, int v = 1, int tl = 1, int tr = N - 1) {       if (l > tr || r < tl || l > r) return;       if (l <= tl && tr <= r) {         lz[v] = min(lz[v], x);         return;       }       int mid = (tl + tr) >> 1;       upd(l, r, x, v << 1, tl, mid), upd(l, r, x, v << 1 | 1, mid + 1, tr);     }     int ask(int p, int v = 1, int tl = 1, int tr = N - 1) {       if (tl == tr) {         return lz[v];       }       int mid = (tl + tr) >> 1;       if (p <= mid) {         return min(lz[v], ask(p, v << 1, tl, mid));       }       return min(lz[v], ask(p, v << 1 | 1, mid + 1, tr));     }   } Seg1, Seg2;   set<int> st1, st2;   int main() {     for (int i = 1; i < N; i++) st1.insert(i), st2.insert(i);     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int tp, l, r;       scanf( %d%d%d , &tp, &l, &r);       r--;       if (tp == 1) {         int x;         scanf( %d , &x);         if (x < 0) {           x = abs(x);           seg1.upd(l, r, x);           Seg1.upd(l, r, x);           while (1) {             auto it = st1.lower_bound(l);             if (it == st1.end() || *it > r) break;             int cu = *it;             st1.erase(cu);             if (st2.count(cu) == 0) {               seg1.change(cu, x);               seg2.change(cu, Seg2.ask(cu));             }           }         } else {           seg2.upd(l, r, x);           Seg2.upd(l, r, x);           while (1) {             auto it = st2.lower_bound(l);             if (it == st2.end() || *it > r) break;             int cu = *it;             st2.erase(cu);             if (st1.count(cu) == 0) {               seg2.change(cu, x);               seg1.change(cu, Seg1.ask(cu));             }           }         }       } else {         printf( %lld n , seg1.get(l, r) + seg2.get(l, r));       }     }     return 0;   }   