#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
struct SegmentBeats {
  struct node {
    long long sum;
    int mx1, mx2, cnt, lz;
  } seg[N << 2];
  SegmentBeats() { build(); }
  inline node merge(node a, node b) {
    if (a.mx1 < b.mx1) swap(a, b);
    a.mx1 > b.mx1 ? a.mx2 = max(a.mx2, b.mx1) : a.cnt += b.cnt;
    a.sum += b.sum, a.lz = 0, a.mx2 = max(a.mx2, b.mx2);
    return a;
  }
  inline void change(int id, int x) {
    if (seg[id].mx1 > x) {
      seg[id].sum += 1LL * seg[id].cnt * (x - seg[id].mx1);
      seg[id].mx1 = seg[id].lz = x;
    }
  }
  inline void shift(int id) {
    if (seg[id].lz) {
      change(id << 1 | 1, seg[id].lz);
      change(id << 1, seg[id].lz);
      seg[id].lz = 0;
    }
  }
  void build(int id = 1, int st = 0, int en = N) {
    seg[id].cnt = en - st;
    if (en - st == 1) return;
    int mid = st + en >> 1;
    build(id << 1, st, mid);
    build(id << 1 | 1, mid, en);
  }
  void set(int p, int x, int id = 1, int st = 0, int en = N) {
    if (en - st == 1) {
      seg[id] = {x, x, 0, 1, 0};
      return;
    }
    shift(id);
    int mid = st + en >> 1;
    p < mid ? set(p, x, id << 1, st, mid) : set(p, x, id << 1 | 1, mid, en);
    seg[id] = merge(seg[id << 1], seg[id << 1 | 1]);
  }
  void update(int l, int r, int x, int id = 1, int st = 0, int en = N) {
    if (r <= st || en <= l || seg[id].mx1 <= x) return;
    if (l <= st && en <= r && seg[id].mx2 < x) return change(id, x);
    shift(id);
    int mid = st + en >> 1;
    update(l, r, x, id << 1, st, mid);
    update(l, r, x, id << 1 | 1, mid, en);
    seg[id] = merge(seg[id << 1], seg[id << 1 | 1]);
  }
  long long get(int l, int r, int id = 1, int st = 0, int en = N) {
    if (r <= st || en <= l) return 0;
    if (l <= st && en <= r) return seg[id].sum;
    shift(id);
    int mid = st + en >> 1;
    return get(l, r, id << 1, st, mid) + get(l, r, id << 1 | 1, mid, en);
  }
} A[2];
struct SegmentMin {
  int seg[N << 2];
  SegmentMin() { memset(seg, 63, sizeof seg); }
  void update(int l, int r, int x, int id = 1, int st = 0, int en = N) {
    if (r <= st || en <= l) return;
    if (l <= st && en <= r) {
      seg[id] = min(seg[id], x);
      return;
    }
    int mid = st + en >> 1;
    update(l, r, x, id << 1, st, mid);
    update(l, r, x, id << 1 | 1, mid, en);
  }
  int get(int p, int id = 1, int st = 0, int en = N) {
    if (en - st == 1) return seg[id];
    int mid = st + en >> 1;
    return min(seg[id], p < mid ? get(p, id << 1, st, mid)
                                : get(p, id << 1 | 1, mid, en));
  }
} B[2];
set<int> S[3];
int main() {
  int q;
  scanf("%d", &q);
  for (int i = 0; i < N; i++) S[2].insert(i);
  while (q--) {
    int t, l, r;
    scanf("%d%d%d", &t, &l, &r);
    if (t & 1) {
      int k;
      scanf("%d", &k);
      auto it = S[2].lower_bound(l);
      while (it != S[2].end() && *it < r) {
        S[k < 0].insert(*it), S[2].erase(it);
        it = S[2].lower_bound(l);
      }
      it = S[k > 0].lower_bound(l), B[k < 0].update(l, r, abs(k));
      while (it != S[k > 0].end() && *it < r) {
        A[k < 0].set(*it, B[k < 0].get(*it));
        A[k > 0].set(*it, B[k > 0].get(*it));
        S[k > 0].erase(it), it = S[k > 0].lower_bound(l);
      }
      A[k < 0].update(l, r, abs(k));
    } else
      printf("%lld\n", A[0].get(l, r) + A[1].get(l, r));
  }
}
