#include <bits/stdc++.h>
using namespace std;
const int N = 800005;
const int inf = 2e9;
const long long M = 2e9;
struct Seg {
  int l[N], r[N], mi[N];
  inline void build(int x, int y, int k) {
    l[k] = x;
    r[k] = y;
    int mid = (x + y) >> 1;
    mi[k] = inf;
    if (x == y) return;
    build(x, mid, k << 1);
    build(mid + 1, y, k << 1 | 1);
  }
  void modify(int x, int y, int k, int z) {
    int left = l[k], right = r[k], mid = (left + right) >> 1;
    if (left == x && right == y) {
      mi[k] = min(mi[k], z);
      return;
    }
    if (y <= mid)
      modify(x, y, k << 1, z);
    else if (x > mid)
      modify(x, y, k << 1 | 1, z);
    else {
      modify(x, mid, k << 1, z);
      modify(mid + 1, y, k << 1 | 1, z);
    }
  }
  int query(int x, int k) {
    int left = l[k], right = r[k], mid = (left + right) >> 1;
    if (left == right) return mi[k];
    if (x <= mid)
      return min(mi[k], query(x, k << 1));
    else
      return min(mi[k], query(x, k << 1 | 1));
  }
} s1, s2;
const int P = 100000;
struct Segb {
  int mx[N], mx2[N], tag[N];
  long long sum[N];
  int l[N], r[N], cnt[N], pos[N];
  void push_up(int x) {
    int L = x << 1, R = (x << 1 | 1);
    mx[x] = mx[L];
    if (mx[L] > mx[R]) {
      cnt[x] = cnt[L];
      mx2[x] = max(mx2[L], mx[R]);
    } else if (mx[L] < mx[R]) {
      cnt[x] = cnt[R], mx[x] = mx[R];
      mx2[x] = max(mx[L], mx2[R]);
    } else {
      cnt[x] = cnt[L] + cnt[R];
      mx2[x] = max(mx2[L], mx2[R]);
    }
    sum[x] = sum[x << 1] + sum[x << 1 | 1];
  }
  int updmin(int x, int y) {
    tag[x] = min(tag[x], y);
    if (y >= mx[x]) return 1;
    if (y > mx2[x]) {
      tag[x] = min(tag[x], y);
      sum[x] -= (long long)(mx[x] - y) * (long long)cnt[x];
      mx[x] = y;
      return 1;
    }
    return 0;
  }
  void push_down(int x) {
    if (tag[x] < M) {
      updmin(x << 1, tag[x]);
      updmin(x << 1 | 1, tag[x]);
      tag[x] = M;
    }
  }
  inline void build(int x, int y, int k) {
    l[k] = x;
    r[k] = y;
    int mid = (x + y) >> 1;
    mx[k] = 0;
    tag[k] = M;
    mx2[k] = 0;
    cnt[k] = 1;
    sum[k] = 0;
    if (x == y) {
      pos[x] = k;
      return;
    }
    build(x, mid, k << 1);
    build(mid + 1, y, k << 1 | 1);
    push_up(k);
  }
  void update(int x, int f) {
    int y = pos[x];
    mx[y] = f;
    sum[y] = f;
    y >>= 1;
    while (y) {
      push_up(y);
      y >>= 1;
    }
  }
  long long query(int x, int y, int k) {
    int left = l[k], right = r[k], mid = (left + right) >> 1;
    push_down(k);
    if (left == x && right == y) return sum[k];
    if (y <= mid)
      return query(x, y, k << 1);
    else if (x > mid)
      return query(x, y, k << 1 | 1);
    else
      return query(x, mid, k << 1) + query(mid + 1, y, k << 1 | 1);
  }
  void modify(int x, int y, int k, int z) {
    int left = l[k], right = r[k], mid = (left + right) >> 1;
    if (left == x && right == y)
      if (updmin(k, z)) return;
    push_down(k);
    if (y <= mid)
      modify(x, y, k << 1, z);
    else if (x > mid)
      modify(x, y, k << 1 | 1, z);
    else {
      modify(x, mid, k << 1, z);
      modify(mid + 1, y, k << 1 | 1, z);
    }
    push_up(k);
  }
} t1, t2;
struct node {
  int x, y;
  int k, type;
} q[N];
vector<int> vec[N];
int st[N];
int main() {
  int n;
  scanf("%d", &n);
  s1.build(1, P, 1);
  s2.build(1, P, 1);
  t1.build(1, P, 1);
  t2.build(1, P, 1);
  for (int i = (1); i <= (n); i++) {
    scanf("%d", &q[i].type);
    if (q[i].type == 2) {
      scanf("%d%d", &q[i].x, &q[i].y);
      q[i].y--;
    } else {
      scanf("%d%d%d", &q[i].x, &q[i].y, &q[i].k);
      q[i].y--;
      if (q[i].k > 0)
        s1.modify(q[i].x, q[i].y, 1, i);
      else
        s2.modify(q[i].x, q[i].y, 1, i);
    }
  }
  for (int i = (1); i <= (P); i++) st[i] = s1.query(i, 1);
  for (int i = (1); i <= (P); i++) st[i] = max(st[i], s2.query(i, 1));
  for (int i = (1); i <= (P); i++)
    if (st[i] <= n) vec[st[i]].push_back(i);
  s1.build(1, P, 1);
  s2.build(1, P, 1);
  for (int i = (1); i <= (n); i++) {
    if (q[i].type == 1) {
      if (q[i].k > 0)
        s1.modify(q[i].x, q[i].y, 1, q[i].k);
      else
        s2.modify(q[i].x, q[i].y, 1, -q[i].k);
      if (q[i].k > 0)
        t1.modify(q[i].x, q[i].y, 1, q[i].k);
      else
        t2.modify(q[i].x, q[i].y, 1, -q[i].k);
      for (int j = 0; j < vec[i].size(); j++) {
        int cur = vec[i][j];
        t1.update(cur, M), t2.update(cur, M);
        if (q[i].k < 0)
          t1.modify(cur, cur, 1, s1.query(cur, 1));
        else
          t2.modify(cur, cur, 1, s2.query(cur, 1));
      }
      if (q[i].k > 0)
        t1.modify(q[i].x, q[i].y, 1, q[i].k);
      else
        t2.modify(q[i].x, q[i].y, 1, -q[i].k);
    } else
      printf("%lld\n",
             t1.query(q[i].x, q[i].y, 1) + t2.query(q[i].x, q[i].y, 1));
  }
  return 0;
}
