#include <bits/stdc++.h>
using namespace std;
class SegmentTree {
  const long long inf = 1e18;
  int n, n0;
  long long max_v[4 * 100003], smax_v[4 * 100003], max_c[4 * 100003];
  long long min_v[4 * 100003], smin_v[4 * 100003], min_c[4 * 100003];
  long long sum[4 * 100003], sum0[4 * 100003], max_c0[4 * 100003],
      min_c0[4 * 100003];
  bool max_r[4 * 100003], min_r[4 * 100003];
  void update_node_min(int k, long long x) {
    if (min_v[k] == -inf) {
      sum[k] -= x * min_c[k];
      sum0[k] -= x * min_c0[k];
    } else {
      sum[k] -= (x - min_v[k]) * min_c[k];
      sum0[k] -= (x - min_v[k]) * min_c0[k];
    }
    if (max_r[k]) {
      sum0[k] = sum[k];
      max_c0[k] = max_c[k];
      min_c0[k] = min_c[k];
    }
    min_v[k] = x;
  }
  void update_node_max(int k, long long x) {
    if (max_v[k] == inf) {
      sum[k] += x * max_c[k];
      sum0[k] += x * max_c0[k];
    } else {
      sum[k] += (x - max_v[k]) * max_c[k];
      sum0[k] += (x - max_v[k]) * max_c0[k];
    }
    if (min_r[k]) {
      sum0[k] = sum[k];
      max_c0[k] = max_c[k];
      min_c0[k] = min_c[k];
    }
    max_v[k] = x;
  }
  void push(int k) {
    if (max_r[k] && min_r[k]) {
      sum0[k] = sum[k];
      max_c0[k] = max_c[k];
      min_c0[k] = min_c[k];
    }
    if (max_v[k] < max_v[2 * k + 1]) {
      update_node_max(2 * k + 1, max_v[k]);
    }
    if (max_v[k] < max_v[2 * k + 2]) {
      update_node_max(2 * k + 2, max_v[k]);
    }
    if (min_v[2 * k + 1] < min_v[k]) {
      update_node_min(2 * k + 1, min_v[k]);
    }
    if (min_v[2 * k + 2] < min_v[k]) {
      update_node_min(2 * k + 2, min_v[k]);
    }
  }
  void update(int k) {
    sum[k] = sum[2 * k + 1] + sum[2 * k + 2];
    if (max_r[2 * k + 1] && max_r[2 * k + 2]) {
      max_r[k] = true;
    }
    if (min_r[2 * k + 1] && min_r[2 * k + 2]) {
      min_r[k] = true;
    }
    sum0[k] = sum0[2 * k + 1] + sum0[2 * k + 2];
    if (max_v[2 * k + 1] < max_v[2 * k + 2]) {
      max_v[k] = max_v[2 * k + 2];
      max_c[k] = max_c[2 * k + 2];
      smax_v[k] = max(max_v[2 * k + 1], smax_v[2 * k + 2]);
      max_c0[k] = max_c0[2 * k + 2];
    } else if (max_v[2 * k + 1] > max_v[2 * k + 2]) {
      max_v[k] = max_v[2 * k + 1];
      max_c[k] = max_c[2 * k + 1];
      smax_v[k] = max(smax_v[2 * k + 1], max_v[2 * k + 2]);
      max_c0[k] = max_c0[2 * k + 1];
    } else {
      max_v[k] = max_v[2 * k + 1];
      max_c[k] = max_c[2 * k + 1] + max_c[2 * k + 2];
      smax_v[k] = max(smax_v[2 * k + 1], smax_v[2 * k + 2]);
      max_c0[k] = max_c0[2 * k + 1] + max_c0[2 * k + 2];
    }
    if (min_v[2 * k + 1] < min_v[2 * k + 2]) {
      min_v[k] = min_v[2 * k + 1];
      min_c[k] = min_c[2 * k + 1];
      smin_v[k] = min(smin_v[2 * k + 1], min_v[2 * k + 2]);
      min_c0[k] = min_c0[2 * k + 1];
    } else if (min_v[2 * k + 1] > min_v[2 * k + 2]) {
      min_v[k] = min_v[2 * k + 2];
      min_c[k] = min_c[2 * k + 2];
      smin_v[k] = min(min_v[2 * k + 1], smin_v[2 * k + 2]);
      min_c0[k] = min_c0[2 * k + 2];
    } else {
      min_v[k] = min_v[2 * k + 1];
      min_c[k] = min_c[2 * k + 1] + min_c[2 * k + 2];
      smin_v[k] = min(smin_v[2 * k + 1], smin_v[2 * k + 2]);
      min_c0[k] = min_c0[2 * k + 1] + min_c0[2 * k + 2];
    }
  }
  void push_max_ready(int k, int l, int r) {
    max_r[k] = true;
    if (min_r[k]) sum0[k] = sum[k], max_c0[k] = max_c[k], min_c0[k] = min_c[k];
    if (r <= l + 1) return;
    bool lr = max_r[2 * k + 1], rr = max_r[2 * k + 2];
    push(k);
    if (!lr) push_max_ready(2 * k + 1, l, (l + r) / 2);
    if (!rr) push_max_ready(2 * k + 2, (l + r) / 2, r);
    update(k);
  }
  void push_min_ready(int k, int l, int r) {
    min_r[k] = true;
    if (max_r[k]) sum0[k] = sum[k], max_c0[k] = max_c[k], min_c0[k] = min_c[k];
    if (r <= l + 1) return;
    bool lr = min_r[2 * k + 1], rr = min_r[2 * k + 2];
    push(k);
    if (!lr) push_min_ready(2 * k + 1, l, (l + r) / 2);
    if (!rr) push_min_ready(2 * k + 2, (l + r) / 2, r);
    update(k);
  }
  void _update_min(long long x, int a, int b, int k, int l, int r) {
    if (b <= l || r <= a || max_v[k] <= x) {
      return;
    }
    if (a <= l && r <= b && smax_v[k] < x) {
      update_node_max(k, x);
      push_max_ready(k, l, r);
      return;
    }
    push(k);
    _update_min(x, a, b, 2 * k + 1, l, (l + r) / 2);
    _update_min(x, a, b, 2 * k + 2, (l + r) / 2, r);
    update(k);
  }
  void _update_max(long long x, int a, int b, int k, int l, int r) {
    if (b <= l || r <= a || x <= min_v[k]) {
      return;
    }
    if (a <= l && r <= b && x < smin_v[k]) {
      update_node_min(k, x);
      push_min_ready(k, l, r);
      return;
    }
    push(k);
    _update_max(x, a, b, 2 * k + 1, l, (l + r) / 2);
    _update_max(x, a, b, 2 * k + 2, (l + r) / 2, r);
    update(k);
  }
  long long _query_sum(int a, int b, int k, int l, int r) {
    if (b <= l || r <= a) {
      return 0;
    }
    if (a <= l && r <= b) {
      return sum0[k];
    }
    push(k);
    long long lv = _query_sum(a, b, 2 * k + 1, l, (l + r) / 2);
    long long rv = _query_sum(a, b, 2 * k + 2, (l + r) / 2, r);
    return lv + rv;
  }

 public:
  SegmentTree(int n) : n(n) {
    n0 = 1;
    while (n0 < n) n0 <<= 1;
    for (int i = 0; i < 2 * n0; ++i)
      max_r[i] = min_r[i] = false, sum0[i] = 0, max_c0[i] = min_c0[i] = 0;
    for (int i = 0; i < n; ++i) {
      max_v[n0 - 1 + i] = inf;
      smax_v[n0 - 1 + i] = 0;
      min_v[n0 - 1 + i] = -inf;
      smin_v[n0 - 1 + i] = 0;
      sum[n0 - 1 + i] = 0;
      max_c[n0 - 1 + i] = min_c[n0 - 1 + i] = 1;
    }
    for (int i = n; i < n0; ++i) {
      max_v[n0 - 1 + i] = smax_v[n0 - 1 + i] = -inf;
      min_v[n0 - 1 + i] = smin_v[n0 - 1 + i] = inf;
      sum[n0 - 1 + i] = max_c[n0 - 1 + i] = min_c[n0 - 1 + i] = 0;
    }
    for (int i = n0 - 2; i >= 0; i--) update(i);
  }
  void update_pos(int a, int b, long long x) {
    return _update_min(x, a, b, 0, 0, n0);
  }
  void update_neg(int a, int b, long long x) {
    return _update_max(x, a, b, 0, 0, n0);
  }
  long long query_sum(int a, int b) { return _query_sum(a, b, 0, 0, n0); }
};
int n, t, l, r, k;
SegmentTree stb(100003);
int main() {
  scanf("%d", &n);
  while (n--) {
    scanf("%d %d %d", &t, &l, &r);
    switch (t) {
      case 1:
        scanf("%d", &k);
        if (k > 0) {
          stb.update_pos(l, r, k);
        } else {
          stb.update_neg(l, r, k);
        }
        break;
      case 2:
        printf("%lld\n", stb.query_sum(l, r));
        break;
    }
  }
  return 0;
}
