#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
  char c;
  bool nega = 0;
  while ((!isdigit(c = getchar())) && (c != '-'))
    ;
  if (c == '-') {
    nega = 1;
    c = getchar();
  }
  x = c - 48;
  while (isdigit(c = getchar())) x = x * 10 + c - 48;
  if (nega) x = -x;
}
template <typename T>
inline void writep(T x) {
  if (x > 9) writep(x / 10);
  putchar(x % 10 + 48);
}
template <typename T>
inline void write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  writep(x);
}
template <typename T>
inline void writeln(T x) {
  write(x);
  putchar('\n');
}
int n, a[100003];
struct node {
  int mx[2], mxn[2], se[2], lazy[2], f;
  long long v;
  node() : v(0), f(0) {
    for (int i = 0; i < 2; i++)
      mx[i] = 0x3f3f3f3f, mxn[i] = 0, se[i] = 0, lazy[i] = 0x3f3f3f3f;
  }
} seg[100003 << 2];
void chkmin(int &x, int y) { x = x < y ? x : y; }
void chkmax(int &x, int y) { x = x > y ? x : y; }
void pushup(int rt) {
  seg[rt].v = seg[(rt << 1)].v + seg[((rt << 1) | 1)].v;
  seg[rt].f = seg[(rt << 1)].f & seg[((rt << 1) | 1)].f;
  for (int t = 0; t < 2; t++) {
    seg[rt].mx[t] = max(seg[(rt << 1)].mx[t], seg[((rt << 1) | 1)].mx[t]);
    if (seg[(rt << 1)].mx[t] > seg[((rt << 1) | 1)].mx[t]) {
      seg[rt].mxn[t] = seg[(rt << 1)].mxn[t];
      seg[rt].se[t] = max(seg[(rt << 1)].se[t], seg[((rt << 1) | 1)].mx[t]);
    } else if (seg[(rt << 1)].mx[t] < seg[((rt << 1) | 1)].mx[t]) {
      seg[rt].mxn[t] = seg[((rt << 1) | 1)].mxn[t];
      seg[rt].se[t] = max(seg[((rt << 1) | 1)].se[t], seg[(rt << 1)].mx[t]);
    } else {
      seg[rt].mxn[t] = seg[(rt << 1)].mxn[t] + seg[((rt << 1) | 1)].mxn[t];
      seg[rt].se[t] = max(seg[(rt << 1)].se[t], seg[((rt << 1) | 1)].se[t]);
    }
  }
}
void dec_tag(int t, int rt, int v) {
  if (seg[rt].mx[t] > v) {
    seg[rt].v -= 1ll * seg[rt].mxn[t] * (seg[rt].mx[t] - v);
    seg[rt].mx[t] = v;
  }
}
void upd(int, int, int, int, int, int, int);
void pushdown(int rt, int l, int r) {
  for (int t = 0; t < 2; t++) {
    if (seg[rt].lazy[t] != 0x3f3f3f3f) {
      upd(t, rt << 1, l, ((r + l) >> 1), l, ((r + l) >> 1), seg[rt].lazy[t]);
      upd(t, (rt << 1) | 1, ((r + l) >> 1) + 1, r, ((r + l) >> 1) + 1, r,
          seg[rt].lazy[t]);
      seg[rt].lazy[t] = 0x3f3f3f3f;
    }
  }
}
void upd(int t, int rt, int l, int r, int L, int R, int x) {
  if (x >= seg[rt].mx[t]) return;
  if (l == r) {
    seg[rt].mx[t] = min(x, seg[rt].mx[t]);
    seg[rt].f |= (1 << t);
    if (seg[rt].f == 3) {
      seg[rt].v = 1ll * seg[rt].mx[0] + seg[rt].mx[1];
      seg[rt].mxn[0] = seg[rt].mxn[1] = 1;
    }
    return;
  }
  if (l >= L && r <= R && (seg[rt].f & (1 << t))) {
    if (x > seg[rt].se[t]) {
      seg[rt].v -= 1ll * seg[rt].mxn[t] * (seg[rt].mx[t] - x);
      seg[rt].mx[t] = x;
      seg[rt].lazy[t] = x;
      return;
    }
  }
  pushdown(rt, l, r);
  if (L <= ((r + l) >> 1)) upd(t, rt << 1, l, ((r + l) >> 1), L, R, x);
  if (R > ((r + l) >> 1)) upd(t, (rt << 1) | 1, ((r + l) >> 1) + 1, r, L, R, x);
  pushup(rt);
}
long long query(int rt, int l, int r, int L, int R) {
  if (l >= L && r <= R) return seg[rt].v;
  pushdown(rt, l, r);
  long long ans = 0;
  if (L <= ((r + l) >> 1)) ans = query(rt << 1, l, ((r + l) >> 1), L, R);
  if (R > ((r + l) >> 1))
    ans += query((rt << 1) | 1, ((r + l) >> 1) + 1, r, L, R);
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int i, j, t, type, x, y, d;
  n = 100003;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d%d", &type, &x, &y);
    --y;
    if (type == 1) {
      scanf("%d", &d);
      if (d > 0)
        upd(0, 1, 1, n, x, y, d);
      else
        upd(1, 1, 1, n, x, y, -d);
    } else {
      printf("%lld\n", query(1, 1, n, x, y));
    }
  }
  return 0;
}
