#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
const int M = 300;
int mn_up[100010];
int mn_down[100010];
struct Block {
  int l, r;
  long long ans;
  map<int, int> cnt_up, cnt_down;
  map<int, int> cnt_up2, cnt_down2;
  int Up, Down;
  int cnt_none;
  void init(int L, int R) {
    l = L;
    r = R;
    cnt_none = r - l + 1;
    ans = 0;
    cnt_up.clear();
    cnt_down.clear();
    cnt_up2.clear();
    cnt_down2.clear();
    Up = Down = INF;
    for (int i = L; i <= R; i++) mn_up[i] = mn_down[i] = INF;
    return;
  }
  void Up_single_update(int pos, int val) {
    if (min(Up, mn_up[pos]) <= val) return;
    if (mn_up[pos] == INF && Up == INF && mn_down[pos] == INF && Down == INF) {
      cnt_none--;
      mn_up[pos] = val;
      cnt_up2[val]++;
      return;
    }
    if (mn_down[pos] == INF && Down == INF) {
      cnt_up2[min(mn_up[pos], Up)]--;
      mn_up[pos] = val;
      cnt_up2[min(mn_up[pos], Up)]++;
      return;
    }
    if (mn_up[pos] == INF && Up == INF) {
      cnt_down2[min(mn_down[pos], Down)]--;
      cnt_down[min(mn_down[pos], Down)]++;
      mn_up[pos] = val;
      cnt_up[min(mn_up[pos], Up)]++;
      ans += min(mn_up[pos], Up) + min(mn_down[pos], Down);
      return;
    }
    ans -= min(mn_up[pos], Up);
    cnt_up[min(mn_up[pos], Up)]--;
    mn_up[pos] = val;
    cnt_up[min(mn_up[pos], Up)]++;
    ans += min(mn_up[pos], Up);
    return;
  }
  void Down_single_update(int pos, int val) {
    if (min(Down, mn_down[pos]) <= val) return;
    if (mn_down[pos] == INF && Down == INF && mn_up[pos] == INF && Up == INF) {
      cnt_none--;
      mn_down[pos] = val;
      cnt_down2[val]++;
      return;
    }
    if (mn_up[pos] == INF && Up == INF) {
      cnt_down2[min(mn_down[pos], Down)]--;
      mn_down[pos] = val;
      cnt_down2[min(mn_down[pos], Down)]++;
      return;
    }
    if (mn_down[pos] == INF && Down == INF) {
      cnt_up2[min(mn_up[pos], Up)]--;
      cnt_up[min(mn_up[pos], Up)]++;
      mn_down[pos] = val;
      cnt_down[min(mn_down[pos], Down)]++;
      ans += min(mn_up[pos], Up) + min(mn_down[pos], Down);
      return;
    }
    ans -= min(mn_down[pos], Down);
    cnt_down[min(mn_down[pos], Down)]--;
    mn_down[pos] = val;
    cnt_down[min(mn_down[pos], Down)]++;
    ans += min(mn_down[pos], Down);
    return;
  }
  void Up_full_update(int val) {
    if (Up <= val) return;
    Up = val;
    map<int, int>::iterator it;
    for (it = cnt_down2.begin(); it != cnt_down2.end(); it++) {
      ans += 1ll * (it->first) * (it->second);
      ans += 1ll * val * (it->second);
      cnt_down[it->first] += it->second;
      cnt_up[val] += it->second;
    }
    cnt_down2.clear();
    int cnt = cnt_none;
    for (it = cnt_up2.upper_bound(val); it != cnt_up2.end(); it++)
      cnt += (it->second);
    it = cnt_up2.upper_bound(val);
    cnt_up2.erase(it, cnt_up2.end());
    cnt_up2[val] += cnt;
    cnt_none = 0;
    cnt = 0;
    for (it = cnt_up.upper_bound(val); it != cnt_up.end(); it++) {
      ans -= 1ll * (it->first) * (it->second);
      cnt += (it->second);
    }
    it = cnt_up.upper_bound(val);
    cnt_up.erase(it, cnt_up.end());
    cnt_up[val] += cnt;
    ans += 1ll * cnt * val;
    return;
  }
  void Down_full_update(int val) {
    if (Down <= val) return;
    Down = val;
    map<int, int>::iterator it;
    for (it = cnt_up2.begin(); it != cnt_up2.end(); it++) {
      ans += 1ll * (it->first) * (it->second);
      ans += 1ll * val * (it->second);
      cnt_up[it->first] += it->second;
      cnt_down[val] += it->second;
    }
    cnt_up2.clear();
    int cnt = cnt_none;
    for (it = cnt_down2.upper_bound(val); it != cnt_down2.end(); it++)
      cnt += (it->second);
    it = cnt_down2.upper_bound(val);
    cnt_down2.erase(it, cnt_down2.end());
    cnt_down2[val] += cnt;
    cnt_none = 0;
    cnt = 0;
    for (it = cnt_down.upper_bound(val); it != cnt_down.end(); it++) {
      ans -= 1ll * (it->first) * (it->second);
      cnt += (it->second);
    }
    it = cnt_down.upper_bound(val);
    cnt_down.erase(it, cnt_down.end());
    cnt_down[val] += cnt;
    ans += 1ll * cnt * val;
    return;
  }
  void range_update(int L, int R, int val) {
    if (r < L || R < l) return;
    if (L <= l && r <= R) {
      if (val > 0)
        Up_full_update(val);
      else
        Down_full_update(-val);
      return;
    }
    L = max(L, l);
    R = min(R, r);
    for (int i = L; i <= R; i++)
      if (val > 0)
        Up_single_update(i, val);
      else
        Down_single_update(i, -val);
    return;
  }
  long long range_calc(int L, int R) {
    if (r < L || R < l) return 0ll;
    if (L <= l && r <= R) return ans;
    L = max(L, l);
    R = min(R, r);
    long long sum = 0;
    for (int i = L; i <= R; i++)
      if (min(Up, mn_up[i]) != INF && min(Down, mn_down[i]) != INF)
        sum += min(Up, mn_up[i]) + min(Down, mn_down[i]);
    return sum;
  }
} B[510];
const int N = 100000;
int main() {
  int Bcnt = 0;
  for (int i = 1; (i - 1) * M < N; i++) {
    Bcnt++;
    B[Bcnt].init((i - 1) * M + 1, min(i * M, N));
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int op;
    scanf("%d", &op);
    if (op == 1) {
      int l, r, x;
      scanf("%d %d %d", &l, &r, &x);
      r--;
      for (int i = 1; i <= Bcnt; i++) B[i].range_update(l, r, x);
    } else {
      int l, r;
      scanf("%d %d", &l, &r);
      r--;
      long long ans = 0;
      for (int i = 1; i <= Bcnt; i++) ans += B[i].range_calc(l, r);
      printf("%I64d\n", ans);
    }
  }
  return 0;
}
