#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > V[2][100005];
vector<long long> Partial[2][100005];
vector<int> Partial2[2][100005];
set<int> S[2];
const int limit = 300;
int B[100005], Block[100005];
int Val[2][100005];
int Ok[2][100005];
const int N = 100000;
int P[100005];
void precalcB() {
  int cnt = limit;
  for (int i = 1; i <= N; i++) {
    B[i] = B[i - 1];
    ++cnt;
    S[0].insert(i);
    S[1].insert(i);
    if (cnt == 1 + limit)
      cnt = 1, B[i]++, Block[B[i]] = i,
      Val[0][B[i]] = Val[1][B[i]] = 1000000005;
    V[0][B[i]].push_back(make_pair(1000000005, i));
    V[1][B[i]].push_back(make_pair(1000000005, i));
    P[i] = cnt - 1;
    Partial[0][B[i]].push_back(0);
    Partial[1][B[i]].push_back(0);
    Partial2[0][B[i]].push_back(0);
    Partial2[1][B[i]].push_back(0);
  }
  Block[B[N] + 1] = N + 1;
}
int binarySearch(int ind, int bl, int val) {
  int left = 0, right = V[ind][bl].size() - 1, sol = right + 1, mid;
  while (left <= right) {
    mid = (left + right) / 2;
    if (V[ind][bl][mid].first >= val) {
      sol = mid;
      right = mid - 1;
    } else
      left = mid + 1;
  }
  return sol;
}
long long Query(int ind, int bl) {
  int val = Val[ind][bl];
  int pos = binarySearch(ind, bl, val);
  long long x = 0;
  if (pos > 0) x = Partial[ind][bl][pos - 1];
  int y = 0;
  if (pos > 0) y = Partial2[ind][bl][pos - 1];
  return x + (1LL * (Partial2[ind][bl].back() - y) * val);
}
inline bool cmp(pair<int, int> a, pair<int, int> b) {
  return a.second < b.second;
}
void Update(int ind, int bl) {
  for (int i = 0; i < V[ind][bl].size(); i++) {
    V[ind][bl][i].first = min(V[ind][bl][i].first, Val[ind][bl]);
  }
  Val[ind][bl] = 1000000005;
  sort(V[ind][bl].begin(), V[ind][bl].end());
  for (int i = 0; i < V[ind][bl].size(); i++) {
    long long x = 0, y = 0;
    if (i > 0) x = Partial[ind][bl][i - 1], y = Partial2[ind][bl][i - 1];
    if (Ok[0][V[ind][bl][i].second] == 1 && Ok[1][V[ind][bl][i].second] == 1) {
      Partial[ind][bl][i] = V[ind][bl][i].first + x;
      Partial2[ind][bl][i] = y + 1;
    } else {
      Partial[ind][bl][i] = x;
      Partial2[ind][bl][i] = y;
    }
  }
}
void Update(int x, int y, int val) {
  int ind = 0;
  if (val < 0) {
    val = -val;
    ind = 1;
  }
  auto it = S[ind].lower_bound(x);
  auto it2 = S[ind].upper_bound(y);
  for (auto it3 = it; it3 != it2; it3 = next(it3)) {
    int val = *it3;
    int bl = B[val];
    Ok[ind][val] = 1;
    if (Ok[ind][val] == Ok[1 - ind][val]) {
      Update(ind, bl);
      Update(1 - ind, bl);
    }
  }
  if (it != S[ind].end()) S[ind].erase(it, it2);
  if (B[x] == B[y]) {
    int bl = B[x];
    sort(V[ind][bl].begin(), V[ind][bl].end(), cmp);
    int start = P[x], fin = P[y];
    for (int i = start; i <= fin; i++)
      V[ind][bl][i].first = min(V[ind][bl][i].first, val);
    Update(ind, bl);
    return;
  }
  int start = P[x], bl = B[x];
  sort(V[ind][bl].begin(), V[ind][bl].end(), cmp);
  for (int i = start; i < V[ind][bl].size(); i++)
    V[ind][bl][i].first = min(V[ind][bl][i].first, val);
  Update(ind, bl);
  start = P[y];
  bl = B[y];
  sort(V[ind][bl].begin(), V[ind][bl].end(), cmp);
  for (int i = 0; i <= start; i++)
    V[ind][bl][i].first = min(V[ind][bl][i].first, val);
  Update(ind, bl);
  for (int i = B[x] + 1; i < B[y]; i++) Val[ind][i] = min(Val[ind][i], val);
}
long long Query2(int x, int y) {
  if (B[x] == B[y]) {
    int ind = 0;
    int bl = B[x];
    sort(V[ind][bl].begin(), V[ind][bl].end(), cmp);
    sort(V[1][bl].begin(), V[1][bl].end(), cmp);
    long long ans = 0;
    int start = P[x], fin = P[y];
    for (int i = start; i <= fin; i++) {
      if (Ok[ind][V[ind][bl][i].second] == 1 &&
          Ok[1 - ind][V[1 - ind][bl][i].second] == 1)
        ans += min(Val[ind][bl], V[ind][bl][i].first) +
               min(Val[1 - ind][bl], V[1 - ind][bl][i].first);
    }
    Update(ind, bl);
    ind = 1;
    Update(ind, bl);
    return ans;
  }
  int start = P[x], bl = B[x];
  int ind = 0;
  long long ans = 0;
  sort(V[ind][bl].begin(), V[ind][bl].end(), cmp);
  sort(V[1][bl].begin(), V[1][bl].end(), cmp);
  for (int i = start; i < V[ind][bl].size(); i++)
    if (Ok[ind][V[ind][bl][i].second] == 1 &&
        Ok[1 - ind][V[1 - ind][bl][i].second] == 1)
      ans += min(Val[1][bl], V[1][bl][i].first) +
             min(Val[0][bl], V[0][bl][i].first);
  Update(0, bl);
  Update(1, bl);
  bl = B[y];
  start = P[y];
  ind = 0;
  sort(V[ind][bl].begin(), V[ind][bl].end(), cmp);
  sort(V[1][bl].begin(), V[1][bl].end(), cmp);
  for (int i = 0; i <= start; i++)
    if (Ok[ind][V[ind][bl][i].second] == 1 &&
        Ok[1 - ind][V[1 - ind][bl][i].second] == 1)
      ans += min(Val[1][bl], V[1][bl][i].first) +
             min(Val[0][bl], V[0][bl][i].first);
  Update(0, bl);
  Update(1, bl);
  for (int i = B[x] + 1; i < B[y]; i++) ans += Query(0, i) + Query(1, i);
  return ans;
}
int main() {
  precalcB();
  int Q;
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++) {
    int type, x, y, val;
    scanf("%d", &type);
    if (type == 1) {
      scanf("%d%d%d", &x, &y, &val);
      --y;
      Update(x, y, val);
    } else {
      scanf("%d%d", &x, &y);
      --y;
      printf("%I64d\n", Query2(x, y));
    }
  }
  return 0;
}
