#include <iostream>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <deque>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <climits>
#include <numeric>
#include <bitset>
#include <random>
#include <tuple>
#include <initializer_list>
#include <fstream>
#include <cctype>
#include <string>
#include <cfloat>
#include <array>



class Group {
	struct Range {
		int from, until;
		bool covered_by(const Range that) const {
			return that.from <= this->from && this->until <= that.until;
		}
		bool has_intersection(const Range that) const {
			return that.from < this->until && this->from < that.until;
		}
		int length() const {
			return until - from;
		}
	};
	std::vector<int> _sum_value, _min_value, _min_count, _min_second, _add_for_all;
	std::vector<Range> area;
	std::vector<bool> is_valid;
	bool is_leaf(const int node) const {
		return (node << 1) >= _sum_value.size() || length(node) == 1;
	}
	int right(const int node) const {
		return (node << 1) + 1;
	}
	int left(const int node) const {
		return node << 1;
	}
	bool covered_by(const int node, const Range range) const {
		return area[node].covered_by(range);
	}
	bool has_intersection(const int node, const Range range) const {
		return area[node].has_intersection(range);
	}
	void add_leaf(const int node, const Range range, const int value) {
		if (covered_by(node, range)) {
			_sum_value[node] += value;
			_min_value[node] += value;
		}
	}
	void add(const int node, const Range range, const int value) {
		if (value == 0) return;
		if (is_leaf(node)) return add_leaf(node, range, value);
		if (covered_by(node, range)) {
			_add_for_all[node] += value;
		}
		else if (has_intersection(node, range)) {
			apply_min(node);
			add(left(node), range, value);
			add(right(node), range, value);
			renew_parameter(node);
		}
	}
	void change_min_leaf(const int node, const Range range, const int lower_limit) {
		if (covered_by(node, range) && _sum_value[node] < lower_limit) _sum_value[node] = _min_value[node] = lower_limit;
		else return;
	}
	void change_min(const int node, const Range range, const int lower_limit) {
		if (is_leaf(node)) return change_min_leaf(node, range, lower_limit);
		if (lower_limit <= min(node)) return;
		if (covered_by(node, range) && lower_limit < min_second(node)) {
			_sum_value[node] += (lower_limit - min(node)) * min_count(node);
			_min_value[node] = lower_limit - _add_for_all[node];
		}
		else if (has_intersection(node, range)) {
			change_min(left(node), range, lower_limit - _add_for_all[node]);
			change_min(right(node), range, lower_limit - _add_for_all[node]);
			renew_parameter(node);
		}
	}
	int min(const int node) const {
		return _min_value[node] + _add_for_all[node];
	}
	int min_count(const int node) const {
		return _min_count[node];
	}
	int min_second(const int node) const {
		return _min_second[node] + _add_for_all[node];
	}
	int length(const int node) const {
		return area[node].length();
	}
	int sum_all(const int node) const {
		return _sum_value[node] + _add_for_all[node] * length(node);
	}
	int sum_leaf(const int node, const Range range) {
		if (covered_by(node, range)) return _sum_value[node];
		else return 0;
	}
	int sum(const int node, const Range range) {
		if (is_leaf(node)) return sum_leaf(node, range);
		if (covered_by(node, range)) {
			return sum_all(node);
		}
		else if (has_intersection(node, range)) {
			apply_change(node);
			renew_parameter(node);
			return sum(left(node), range) + sum(right(node), range);
		}
		else return 0;
	}
	void apply_change(const int node) {
		apply_min(node);
		if (_add_for_all[node] != 0) {
			add(left(node), area[node], _add_for_all[node]);
			add(right(node), area[node], _add_for_all[node]);
			_add_for_all[node] = 0;
		}
	}
	void apply_min(const int node) {
		change_min(left(node), area[node], _min_value[node]);
		change_min(right(node), area[node], _min_value[node]);
	}
	void renew_parameter(const int node) {
		_min_value[node] = std::min(min(left(node)), min(right(node)));
		_min_count[node] = 0;
		_min_second[node] = INT_MAX >> 1;
		if (_min_value[node] == min(left(node))) {
			_min_count[node] += min_count(left(node));
			_min_second[node] = std::min(_min_second[node], min_second(left(node)));
		}
		else _min_second[node] = std::min(_min_second[node], min(left(node)));
		if (_min_value[node] == min(right(node))) {
			_min_count[node] += min_count(right(node));
			_min_second[node] = std::min(_min_second[node], min_second(right(node)));
		}
		else _min_second[node] = std::min(_min_second[node], min(right(node)));
		_sum_value[node] = sum_all(left(node)) + sum_all(right(node));
	}
	void initialize(const int node) {
		if ((node << 1) >= _sum_value.size()) return;
		initialize(node << 1); initialize((node << 1) + 1);
		if (is_valid[node << 1] || is_valid[(node << 1) + 1]) {
			is_valid[node] = true;
			area[node] = area[node << 1];
			if (is_valid[(node << 1) + 1]) area[node].until = area[(node << 1) + 1].until;
			if (area[node].length() == 1) {
				_sum_value[node] = _min_value[node] = _sum_value[node << 1];
				_min_count[node] = 1;
				_min_second[node] = INT_MAX >> 1;
			}
			else {
				renew_parameter(node);
			}
		}
	}
public:
	Group(const std::vector<int>& initial) {
		int len = 1;
		while (len < initial.size()) len <<= 1;
		len;
		_sum_value = _min_value = _min_count = _min_second = _add_for_all = std::vector<int>(len << 1, 0);
		area = std::vector<Range>(len << 1);
		is_valid = std::vector<bool>(len << 1, false);
		for (auto i = 0; i < initial.size(); ++i) {
			_sum_value[i + len] = _min_value[i + len] = initial[i];
			_min_count[i + len] = 1;
			_min_second[i + len] = INT_MAX >> 1;
			area[i + len] = Range{ i, i + 1 };
			is_valid[i + len] = true;
		}
		initialize(1);
	}
	void add(int from, int until, int value) {
		add(1, Range{ from, until }, value);
	}
	int emerge(int from, int until, int max) {
		const auto current = sum_all(1);
		add(1, Range{ from, until }, -max);
		change_min(1, Range{ from, until }, 0);
		return current - sum_all(1);
	}
};
int main() {
	int n; std::cin >> n;
	std::vector<int> initial(n); for (auto& c : initial) std::cin >> c;
	Group g(initial);
	int m; std::cin >> m;
	for (auto i = 0; i < m; ++i) {
		int t, a, b, d; std::cin >> t >> a >> b >> d;
		switch (t) {
		case 1: g.add(a - 1, b, d); break;
		case 2: std::cout << g.emerge(a - 1, b, d) << std::endl; break;
		default: throw 0;
		}
	}
}


Measured memory_bytes: 10588