#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chkmax(T &a, T b) {
  return (a < b) ? a = b, 1 : 0;
}
template <typename T>
bool chkmin(T &a, T b) {
  return (a > b) ? a = b, 1 : 0;
}
inline int read() {
  int x = 0, fh = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') fh = -1;
  for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ '0');
  return x * fh;
}
int q, n;
struct node {
  int minn[400005][2];
  long long tree[400005];
  int full[400005];
  int maxn[400005][2], cnt[400005][2], se[400005][2];
  void pushup(int rt) {
    full[rt] = full[rt << 1] & full[rt << 1 | 1];
    tree[rt] = tree[rt << 1] + tree[rt << 1 | 1];
    for (int i = (0), _end_ = (int)(1); i <= _end_; ++i) {
      maxn[rt][i] = max(maxn[rt << 1][i], maxn[rt << 1 | 1][i]);
      se[rt][i] = max(se[rt << 1 | 1][i], se[rt << 1][i]);
      if (maxn[rt << 1][i] == maxn[rt << 1 | 1][i])
        cnt[rt][i] = cnt[rt << 1][i] + cnt[rt << 1 | 1][i];
      else {
        if (maxn[rt << 1][i] < maxn[rt << 1 | 1][i]) {
          chkmax(se[rt][i], maxn[rt << 1][i]);
          cnt[rt][i] = cnt[rt << 1 | 1][i];
        } else {
          chkmax(se[rt][i], maxn[rt << 1 | 1][i]);
          cnt[rt][i] = cnt[rt << 1][i];
        }
      }
    }
  }
  void pushdown(int rt, int l, int r) {
    for (int i = (0), _end_ = (int)(1); i <= _end_; ++i)
      if (minn[rt][i] != 0x3f3f3f3f) {
        update(i, rt << 1, l, ((l + r) >> 1), l, ((l + r) >> 1), minn[rt][i]);
        update(i, rt << 1 | 1, ((l + r) >> 1) + 1, r, ((l + r) >> 1) + 1, r,
               minn[rt][i]);
        minn[rt][i] = 0x3f3f3f3f;
      }
  }
  void update(int opt, int rt, int l, int r, int L, int R, int val) {
    if (l == r) {
      full[rt] |= (1 << opt);
      chkmin(maxn[rt][opt], val);
      if (full[rt] == 3)
        cnt[rt][0] = cnt[rt][1] = 1, tree[rt] = maxn[rt][0] + maxn[rt][1];
      return;
    }
    if (L <= l && r <= R && (full[rt] & (1 << opt))) {
      if (val >= maxn[rt][opt])
        return;
      else if (val > se[rt][opt]) {
        tree[rt] -= 1ll * cnt[rt][opt] * (maxn[rt][opt] - val);
        maxn[rt][opt] = val;
        minn[rt][opt] = val;
        return;
      }
    }
    pushdown(rt, l, r);
    if (L <= ((l + r) >> 1)) update(opt, rt << 1, l, ((l + r) >> 1), L, R, val);
    if (R > ((l + r) >> 1))
      update(opt, rt << 1 | 1, ((l + r) >> 1) + 1, r, L, R, val);
    pushup(rt);
  }
  long long query(int rt, int l, int r, int L, int R) {
    if (L <= l && r <= R) return tree[rt];
    long long res = 0;
    pushdown(rt, l, r);
    if (L <= ((l + r) >> 1)) res = query(rt << 1, l, ((l + r) >> 1), L, R);
    if (R > ((l + r) >> 1))
      res += query(rt << 1 | 1, ((l + r) >> 1) + 1, r, L, R);
    return res;
  }
} T;
int main() {
  n = 1e5;
  for (int i = (0), _end_ = (int)(3 * n - 1); i <= _end_; ++i) {
    T.full[i] = 0;
    for (int j = (0), _end_ = (int)(1); j <= _end_; ++j)
      T.maxn[i][j] = T.minn[i][j] = 0x3f3f3f3f;
  }
  q = read();
  while (q--) {
    int opt = read(), l = read(), r = read();
    r--;
    if (opt == 1) {
      int k = read();
      if (k > 0)
        T.update(0, 1, 1, n, l, r, k);
      else
        T.update(1, 1, 1, n, l, r, -k);
    } else
      printf("%lld\n", T.query(1, 1, n, l, r));
  }
  return 0;
}
