#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MINF = 0x3f3f3f3f;
const int MAXN = 100007;
const int DIVI = 307;
const int MAXS = 407;
int q;
int qtp, ql, qr, qk;
set<int> ncov[2];
set<int>::iterator sit;
map<int, int, greater<int> > mp[MAXS][2];
map<int, int, greater<int> >::iterator it;
long long bans[MAXS];
int a[MAXN][2], tag[MAXS][2];
void init();
void input();
void inputq();
void work();
void add(int l, int r, int k);
long long query(int l, int r);
void upd_item(int b, int l, int r, int t, int k);
void upd_block(int b, int t, int k);
void downtag(int b, int t);
void cover(int b, int t, int k);
long long query_item(int b, int l, int r);
int main() {
  init();
  input();
  work();
}
void init() { ios::sync_with_stdio(false); }
void input() { scanf("%d", &q); }
void inputq() {
  scanf("%d%d%d", &qtp, &ql, &qr);
  if (qtp == 1) scanf("%d", &qk);
}
void work() {
  for (int i = 0; i < MAXN; ++i) ncov[0].insert(i), ncov[1].insert(i);
  memset(tag, MINF, sizeof(tag));
  for (int i = 0; i < q; ++i) {
    inputq();
    --qr;
    if (qtp == 1)
      add(ql, qr, qk);
    else
      printf("%I64d\n", query(ql, qr));
  }
}
void add(int l, int r, int k) {
  int lb = l / DIVI, rb = r / DIVI;
  int t = (k > 0) ? 0 : 1;
  k = (((k) >= 0) ? (k) : (-(k)));
  upd_item(lb, l, (((r) < ((lb + 1) * DIVI - 1)) ? (r) : ((lb + 1) * DIVI - 1)),
           t, k);
  if (lb ^ rb) upd_item(rb, rb * DIVI, r, t, k);
  for (int i = lb + 1; i < rb; ++i) {
    upd_block(i, t, k);
  }
}
long long query(int l, int r) {
  int lb = l / DIVI, rb = r / DIVI;
  long long ans = query_item(
      lb, l, (((r) < ((lb + 1) * DIVI - 1)) ? (r) : ((lb + 1) * DIVI - 1)));
  if (lb ^ rb) ans += query_item(rb, rb * DIVI, r);
  for (int i = lb + 1; i < rb; ++i) ans += bans[i];
  return ans;
}
void upd_item(int b, int l, int r, int t, int k) {
  downtag(b, 0), downtag(b, 1);
  for (int i = l; i <= r; ++i) {
    if (!a[i][t]) {
      ncov[t].erase(i);
      a[i][t] = k;
      if (a[i][t ^ 1]) {
        ++mp[b][t][k];
        ++mp[b][t ^ 1][a[i][t ^ 1]];
        bans[b] += a[i][t] + a[i][t ^ 1];
      }
    } else if (k < a[i][t]) {
      if (a[i][t ^ 1]) {
        bans[b] += k - a[i][t];
        --mp[b][t][a[i][t]];
        a[i][t] = k;
        ++mp[b][t][a[i][t]];
      } else
        a[i][t] = k;
    }
  }
}
void upd_block(int b, int t, int k) {
  tag[b][t] = (((tag[b][t]) < (k)) ? (tag[b][t]) : (k));
  cover(b, t, k);
  long long dec = 0;
  int cc = 0;
  while (!mp[b][t].empty() && (it = mp[b][t].begin())->first > k) {
    cc += it->second;
    dec += static_cast<long long>(it->second) * it->first;
    mp[b][t].erase(it);
  }
  bans[b] -= dec;
  bans[b] += static_cast<long long>(cc) * k;
  mp[b][t][k] += cc;
}
void downtag(int b, int t) {
  if (tag[b][t] == MINF) return;
  int l = b * DIVI, r = (b + 1) * DIVI - 1;
  for (int i = l; i <= r; ++i)
    a[i][t] = (((a[i][t]) < (tag[b][t])) ? (a[i][t]) : (tag[b][t]));
  tag[b][t] = MINF;
}
void cover(int b, int t, int k) {
  int l = b * DIVI, r = (b + 1) * DIVI - 1, now;
  while (1) {
    sit = ncov[t].lower_bound(l);
    if (sit == ncov[t].end() || (*sit > r)) break;
    now = *sit;
    a[now][t] = k;
    a[now][t ^ 1] = (((a[now][t ^ 1]) < (tag[b][t ^ 1])) ? (a[now][t ^ 1])
                                                         : (tag[b][t ^ 1]));
    if (a[now][t ^ 1]) {
      bans[b] += a[now][t] + a[now][t ^ 1];
      ++mp[b][t][k];
      ++mp[b][t ^ 1][a[now][t ^ 1]];
    }
    ncov[t].erase(sit);
  }
}
long long query_item(int b, int l, int r) {
  downtag(b, 0), downtag(b, 1);
  long long ans = 0;
  for (int i = l; i <= r; ++i) {
    if (a[i][0] && a[i][1]) ans += a[i][0] + a[i][1];
  }
  return ans;
}
