#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = static_cast<ll>(1e9) + 7;
const int MAXN = static_cast<int>(1e5) + 17;
struct bang {
  static const int S = 9;
  static const int MAGIC = (1 << S);
  struct block {
    map<int, int> mp;
    int F;
    ll res;
    vector<int> f;
    block() : res(0), F(INF) { f.resize(MAGIC, INF); }
  };
  vector<block> A, B;
  set<int> freeA, freeB;
  bang() {
    A.resize(MAGIC);
    B.resize(MAGIC);
    for (ll i = 0; i < (ll)(MAXN); ++i) {
      freeA.insert(i);
      freeB.insert(i);
    }
  }
  void upd(int lq, int rq, vector<block>& A, vector<block>& B, int k,
           set<int>& freeA, set<int>& freeB) {
    for (int i = lq; i <= rq;)
      if ((i & (MAGIC - 1)) == 0 && i + MAGIC <= rq) {
        A[i >> S].F = min(A[i >> S].F, k);
        while (!A[i >> S].mp.empty() && A[i >> S].mp.rbegin()->first > k) {
          A[i >> S].mp[k] += A[i >> S].mp.rbegin()->second;
          A[i >> S].res += (ll)A[i >> S].mp.rbegin()->second *
                           (k - A[i >> S].mp.rbegin()->first);
          A[i >> S].mp.erase(--A[i >> S].mp.end());
        }
        i += MAGIC;
      } else {
        if (min(A[i >> S].f[i & (MAGIC - 1)], A[i >> S].F) > k) {
          if (!freeA.count(i) && !freeB.count(i)) {
            A[i >> S].res += k - min(A[i >> S].f[i & (MAGIC - 1)], A[i >> S].F);
            --A[i >> S].mp[min(A[i >> S].f[i & (MAGIC - 1)], A[i >> S].F)];
            ++A[i >> S].mp[A[i >> S].f[i & (MAGIC - 1)] = k];
          } else {
            A[i >> S].f[i & (MAGIC - 1)] = k;
          }
        }
        ++i;
      }
    for (;;) {
      auto it = freeA.lower_bound(lq);
      if (it == freeA.end() || *it > rq) break;
      auto i = *it;
      freeA.erase(it);
      if (freeB.find(i) == freeB.end()) {
        A[i >> S].res += min(A[i >> S].f[i & (MAGIC - 1)], A[i >> S].F);
        ++A[i >> S].mp[min(A[i >> S].f[i & (MAGIC - 1)], A[i >> S].F)];
        B[i >> S].res += min(B[i >> S].f[i & (MAGIC - 1)], B[i >> S].F);
        ++B[i >> S].mp[min(B[i >> S].f[i & (MAGIC - 1)], B[i >> S].F)];
      }
    }
  }
  void upd(int lq, int rq, int k) {
    if (k < 0)
      upd(lq, rq, A, B, -k, freeA, freeB);
    else
      upd(lq, rq, B, A, k, freeB, freeA);
  }
  ll baby(int b, int l, int r) {
    ll res = 0;
    for (int i = l; i <= r; ++i)
      if (min(A[b].f[i], A[b].F) < INF && min(B[b].f[i], B[b].F) < INF)
        res += min(A[b].f[i], A[b].F) + min(B[b].f[i], B[b].F);
    return res;
  }
  ll giant(int l, int r) {
    ll res = 0;
    for (int i = l; i <= r; ++i) res += A[i].res + B[i].res;
    return res;
  }
  ll get(int lq, int rq) {
    if ((lq >> S) == (rq >> S))
      return baby((lq >> S), (lq & (MAGIC - 1)), (rq & (MAGIC - 1)));
    auto L = baby((lq >> S), (lq & (MAGIC - 1)), MAGIC - 1);
    auto M = giant((lq >> S) + 1, (rq >> S) - 1);
    auto R = baby((rq >> S), 0, (rq & (MAGIC - 1)));
    return L + M + R;
  }
};
int n, q;
bool read() {
  if (!(cin >> q)) return false;
  return true;
}
void solve() {
  bang T;
  for (ll ppp = 0; ppp < (ll)(q); ++ppp) {
    int t;
    cin >> t;
    if (t == 1) {
      int l, r, k;
      cin >> l >> r >> k;
      T.upd(l - 1, r - 2, k);
    } else {
      int l, r;
      cin >> l >> r;
      cout << T.get(l - 1, r - 2) << '\n';
    }
  }
}
int main() {
  cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::mt19937 rand('S' + 'E' + 'R' + 'E' + 'Z' + 'H' + 'K' + 'A');
  while (read()) solve();
  return 0;
}
