#include <bits/stdc++.h>
using namespace std;
const int oo = 1e9 + 10;
const int N = 1e5 + 10;
void chkmin(int &x, int y) { x = x < y ? x : y; }
void chkmax(int &x, int y) { x = x > y ? x : y; }
struct Segment_Tree {
  const static int Node = N << 2;
  int Minv[Node][2];
  long long sum[Node];
  int full[Node];
  int Max[Node][2], cnt[Node][2], se[Node][2];
  Segment_Tree() {
    for (int i = 0; i <= Node - 1; i++) {
      full[i] = 0;
      for (int j = 0; j <= 1; j++) Max[i][j] = Minv[i][j] = oo;
    }
  }
  void pushdown(int o, int L, int R) {
    for (int i = 0; i <= 1; i++)
      if (Minv[o][i] != oo) {
        update(i, (o << 1), L, ((L + R) >> 1), L, ((L + R) >> 1), Minv[o][i]);
        update(i, (o << 1 | 1), ((L + R) >> 1) + 1, R, ((L + R) >> 1) + 1, R,
               Minv[o][i]);
        Minv[o][i] = oo;
      }
  }
  void pushup(int o) {
    full[o] = full[(o << 1)] & full[(o << 1 | 1)];
    sum[o] = sum[(o << 1)] + sum[(o << 1 | 1)];
    for (int i = 0; i <= 1; i++) {
      int u = (o << 1), v = (o << 1 | 1);
      Max[o][i] = max(Max[u][i], Max[v][i]);
      se[o][i] = max(se[u][i], se[v][i]);
      if (Max[u][i] == Max[v][i])
        cnt[o][i] = cnt[u][i] + cnt[v][i];
      else {
        if (Max[u][i] < Max[v][i]) swap(u, v);
        chkmax(se[o][i], Max[v][i]);
        cnt[o][i] = cnt[u][i];
      }
    }
  }
  void update(int i, int o, int L, int R, int l, int r, int w) {
    if (L == R) {
      full[o] |= 1 << i;
      chkmin(Max[o][i], w);
      if (full[o] == 3)
        cnt[o][0] = cnt[o][1] = 1, sum[o] = Max[o][0] + Max[o][1];
      return;
    }
    if (l <= L && R <= r && (full[o] & (1 << i))) {
      if (w >= Max[o][i])
        return;
      else if (w > se[o][i]) {
        sum[o] -= 1ll * cnt[o][i] * (Max[o][i] - w);
        Max[o][i] = w, Minv[o][i] = w;
        return;
      }
    }
    pushdown(o, L, R);
    if (l <= ((L + R) >> 1)) update(i, (o << 1), L, ((L + R) >> 1), l, r, w);
    if (r > ((L + R) >> 1))
      update(i, (o << 1 | 1), ((L + R) >> 1) + 1, R, l, r, w);
    pushup(o);
  }
  long long query(int o, int L, int R, int l, int r) {
    if (l <= L && R <= r)
      return sum[o];
    else {
      long long ret = 0;
      pushdown(o, L, R);
      if (l <= ((L + R) >> 1)) ret += query((o << 1), L, ((L + R) >> 1), l, r);
      if (r > ((L + R) >> 1))
        ret += query((o << 1 | 1), ((L + R) >> 1) + 1, R, l, r);
      return ret;
    }
  }
} T;
int main() {
  int n = 1e5, q;
  scanf("%d", &q);
  while (q--) {
    int op, l, r, k;
    scanf("%d%d%d", &op, &l, &r, &k);
    --r;
    if (op == 1) {
      scanf("%d", &k);
      if (k > 0)
        T.update(0, 1, 1, n, l, r, k);
      else
        T.update(1, 1, 1, n, l, r, -k);
    } else
      printf("%I64d\n", T.query(1, 1, n, l, r));
  }
  return 0;
}
