#include <bits/stdc++.h>
using namespace std;
int smax(int u, int v) {
  if (min(u, v) == 0) return 0;
  return max(u, v);
}
int q;
class segtree {
 public:
  struct node {
    bool pany = false;
    bool nany = false;
    int pbig = 0;
    int spbig = 0;
    long long psum = 0;
    int psecondbig = INT_MIN;
    int nbig = 0;
    int snbig = 0;
    long long nsum = 0;
    int nsecondbig = INT_MIN;
    int pnbig = INT_MIN;
    int spnbig = 0;
    long long pnsum = 0;
    int npbig = INT_MIN;
    int snpbig = 0;
    long long npsum = 0;
    int p = 0;
    int n = 0;
    bool tag(int v) {
      return (((v > 0) & (psecondbig < v)) | ((v < 0) & (nsecondbig < -v)));
    }
    void apply(int l, int r, int v) {
      if (v == 0) {
        spbig = snbig = r - l + 1;
        return;
      }
      assert(tag(v));
      if (v > 0) {
        p = p + v - smax(p, v);
        pany = true;
        if (v == smax(v, pbig)) return;
        psum += (long long)(v - pbig) * spbig;
        pbig = v;
        if (nany && v != smax(v, pnbig)) {
          pnsum += (long long)(v - pnbig) * spnbig;
          pnbig = v;
        }
        npbig = nbig;
        snpbig = snbig;
        npsum = nsum;
      }
      if (v < 0) {
        v = -v;
        n = n + v - smax(n, v);
        nany = true;
        if (v == smax(v, nbig)) return;
        nsum += (long long)(v - nbig) * snbig;
        nbig = v;
        if (pany && v != smax(v, npbig)) {
          npsum += (long long)(v - npbig) * snpbig;
          npbig = v;
        }
        pnbig = pbig;
        spnbig = spbig;
        pnsum = psum;
      }
    }
  };
  node unite(const node &a, const node &b) const {
    node res;
    res.pany = a.pany | b.pany;
    res.nany = a.nany | b.nany;
    res.pbig = smax(a.pbig, b.pbig);
    if (a.pbig == b.pbig) {
      res.spbig = a.spbig + b.spbig;
      res.psecondbig = smax(a.psecondbig, b.psecondbig);
    } else {
      res.spbig = (a.pbig == res.pbig ? a.spbig : b.spbig);
      int v = a.pbig + b.pbig - res.pbig;
      res.psecondbig = smax(v, smax(a.psecondbig, b.psecondbig));
    }
    res.psum = a.psum + b.psum;
    res.nbig = smax(a.nbig, b.nbig);
    if (a.nbig == b.nbig) {
      res.snbig = a.snbig + b.snbig;
      res.nsecondbig = smax(a.nsecondbig, b.nsecondbig);
    } else {
      res.snbig = (a.nbig == res.nbig ? a.snbig : b.snbig);
      int v = a.nbig + b.nbig - res.nbig;
      res.nsecondbig = smax(v, smax(a.nsecondbig, b.nsecondbig));
    }
    res.nsum = a.nsum + b.nsum;
    if (res.nany) {
      if (!a.nany || !b.nany) {
        res.pnbig = (a.nany ? a.pnbig : b.pnbig);
        res.spnbig = (a.nany ? a.spnbig : b.spnbig);
      } else {
        res.pnbig = smax(a.pnbig, b.pnbig);
        if (a.pnbig == b.pnbig) {
          res.spnbig = a.spnbig + b.spnbig;
        } else
          res.spnbig = (res.pnbig == a.pnbig ? a.spnbig : b.spnbig);
      }
    }
    res.pnsum = a.pnsum + b.pnsum;
    if (res.pany) {
      if (!a.pany || !b.pany) {
        res.npbig = (a.pany ? a.npbig : b.npbig);
        res.snpbig = (a.pany ? a.snpbig : b.snpbig);
      } else {
        res.npbig = smax(a.npbig, b.npbig);
        if (a.npbig == b.npbig) {
          res.snpbig = a.snpbig + b.snpbig;
        } else
          res.snpbig = (res.npbig == a.npbig ? a.snpbig : b.snpbig);
      }
    }
    res.npsum = a.npsum + b.npsum;
    return res;
  }
  inline void push(int x, int l, int r) {
    int y = (l + r) >> 1;
    int z = x + ((y - l + 1) << 1);
    if (tree[x].p != 0) {
      tree[x + 1].apply(l, y, tree[x].p);
      tree[z].apply(y + 1, r, tree[x].p);
      tree[x].p = 0;
    }
    if (tree[x].n != 0) {
      tree[x + 1].apply(l, y, -tree[x].n);
      tree[z].apply(y + 1, r, -tree[x].n);
      tree[x].n = 0;
    }
  }
  inline void pull(int x, int z) { tree[x] = unite(tree[x + 1], tree[z]); }
  int n;
  vector<node> tree;
  void build(int x, int l, int r) {
    tree[x].apply(l, r, 0);
    if (l == r) {
      return;
    }
    int y = (l + r) >> 1;
    int z = x + ((y - l + 1) << 1);
    build(x + 1, l, y);
    build(z, y + 1, r);
    pull(x, z);
  }
  node get(int x, int l, int r, int ll, int rr) {
    if (ll <= l && r <= rr) {
      return tree[x];
    }
    int y = (l + r) >> 1;
    int z = x + ((y - l + 1) << 1);
    push(x, l, r);
    node res{};
    if (rr <= y) {
      res = get(x + 1, l, y, ll, rr);
    } else {
      if (ll > y) {
        res = get(z, y + 1, r, ll, rr);
      } else {
        res = unite(get(x + 1, l, y, ll, rr), get(z, y + 1, r, ll, rr));
      }
    }
    pull(x, z);
    return res;
  }
  void modify(int x, int l, int r, int ll, int rr, int v) {
    if (ll <= l && r <= rr && tree[x].tag(v)) {
      tree[x].apply(l, r, v);
      return;
    }
    int y = (l + r) >> 1;
    int z = x + ((y - l + 1) << 1);
    push(x, l, r);
    if (ll <= y) {
      modify(x + 1, l, y, ll, rr, v);
    }
    if (rr > y) {
      modify(z, y + 1, r, ll, rr, v);
    }
    pull(x, z);
  }
  segtree(int _n) : n(_n) {
    assert(n > 0);
    tree.resize(2 * n - 1);
    build(0, 0, n - 1);
  }
  node get(int ll, int rr) {
    assert(0 <= ll && ll <= rr && rr <= n - 1);
    return get(0, 0, n - 1, ll, rr);
  }
  void modify(int ll, int rr, int v) {
    assert(0 <= ll && ll <= rr && rr <= n - 1);
    modify(0, 0, n - 1, ll, rr, v);
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  const int n = 100000;
  segtree st(n);
  cin >> q;
  for (int tc = 1; tc <= q; tc++) {
    int t, l, r;
    cin >> t >> l >> r;
    r--;
    if (t == 1) {
      int k;
      cin >> k;
      st.modify(l, r, k);
    } else {
      auto s = st.get(l, r);
      cout << s.pnsum + s.npsum << endl;
    }
  }
  return 0;
}
