#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define NUM 100005

struct Info{

	ll range_sum,
	   uniformity,
	   minimum,
	   second_minimum,
	   num_minimum,
	   base_value;
};

ll N = 1;
Info info[8*NUM];

void init(ll first_N){
	while(N < first_N)N *= 2;
}

void updateInfo(int node_id){

	int left_child = 2*node_id+1;
	int right_child = 2*node_id+2;

	info[node_id].range_sum = info[left_child].range_sum+info[right_child].range_sum;

	if(info[left_child].minimum < info[right_child].minimum){

		info[node_id].minimum = info[left_child].minimum;
		info[node_id].num_minimum = info[left_child].num_minimum;
		info[node_id].second_minimum = min(info[left_child].second_minimum,info[right_child].minimum);

	}else if(info[left_child].minimum > info[right_child].minimum){

		info[node_id].minimum = info[right_child].minimum;
		info[node_id].num_minimum = info[right_child].num_minimum;
		info[node_id].second_minimum = min(info[right_child].second_minimum,info[left_child].minimum);

	}else{ //info[left_child].minimum == info[right_child].minimum

		info[node_id].minimum = info[left_child].minimum;
		info[node_id].num_minimum = info[left_child].num_minimum+info[right_child].num_minimum;
		info[node_id].second_minimum = min(info[left_child].second_minimum,info[right_child].second_minimum);
	}
}

void first_add(int loc,ll value){
	loc += N-1;

	info[loc].range_sum = value;
	info[loc].minimum = value;

	if(N == 1)return;

	int parent = (loc-1)/2;

	while(true){
		updateInfo(parent);

		if(parent == 0)break;
		else{
			parent = (parent-1)/2;
		}
	}
}


void evaluate(ll node_id,ll node_left,ll node_right){

	ll left_child = 2*node_id+1;
	ll right_child = 2*node_id+2;

	if(info[node_id].uniformity != 0){

		info[node_id].minimum += info[node_id].uniformity;
		if(info[node_id].second_minimum != HUGE_NUM){

			info[node_id].second_minimum += info[node_id].uniformity;
		}

		info[node_id].range_sum += (node_right-node_left)*info[node_id].uniformity;

		if(node_id <= N-2){

			info[left_child].uniformity += info[node_id].uniformity;
			info[right_child].uniformity += info[node_id].uniformity;

			if(info[left_child].base_value != -1){

				info[left_child].base_value += info[node_id].uniformity;
			}
			if(info[right_child].base_value != -1){

				info[right_child].base_value += info[node_id].uniformity;
			}
		}

		info[node_id].uniformity = 0;
	}

	if(info[node_id].base_value != -1){

		if(info[node_id].base_value >= info[node_id].second_minimum){

			info[left_child].base_value = max(info[left_child].base_value,info[node_id].base_value);
			info[right_child].base_value = max(info[right_child].base_value,info[node_id].base_value);

			if(node_id < N-1){
				evaluate(left_child,node_left,(node_left+node_right)/2);
				evaluate(right_child,(node_left+node_right)/2,node_right);

				updateInfo(node_id);
			}

		}else if(info[node_id].base_value > info[node_id].minimum){

			info[node_id].range_sum += (info[node_id].base_value-info[node_id].minimum)*info[node_id].num_minimum;
			info[node_id].minimum = info[node_id].base_value;

			if(node_id < N-1){

				info[left_child].base_value = max(info[left_child].base_value,info[node_id].base_value);
				info[right_child].base_value = max(info[right_child].base_value,info[node_id].base_value);
			}
		}
		info[node_id].base_value = -1;
	}
}


void changeMax(ll left,ll right,ll value,ll node_id,ll node_left,ll node_right){

	evaluate(node_id,node_left,node_right);

	if(right <= node_left || left >= node_right){
		return;
	}
	else if(left <= node_left && right >= node_right){

		info[node_id].base_value = value;
		evaluate(node_id,node_left,node_right);

	}else{

		changeMax(left,right,value,2*node_id+1,node_left,(node_left+node_right)/2);
		changeMax(left,right,value, 2*node_id+2,(node_left+node_right)/2,node_right);
		updateInfo(node_id);
	}
}

void add(ll left,ll right,ll value,ll node_id,ll node_left,ll node_right){

	evaluate(node_id,node_left,node_right);

	if(right <= node_left || left >= node_right){
		return;
	}
	else if(left <= node_left && right >= node_right){

		info[node_id].uniformity += value;
		evaluate(node_id,node_left,node_right);

	}else{

		add(left,right,value,2*node_id+1,node_left,(node_left+node_right)/2);
		add(left,right,value, 2*node_id+2,(node_left+node_right)/2,node_right);
		updateInfo(node_id);
	}

}

ll getSum(ll left,ll right,ll node_id,ll node_left,ll node_right){

	evaluate(node_id,node_left,node_right);

	if(right <= node_left || left >= node_right){
		return 0;

	}else if(left <= node_left && right >= node_right){

		return info[node_id].range_sum;

	}else{

		ll ret = 0;

		ret += getSum(left,right,2*node_id+1,node_left,(node_left+node_right)/2);
		ret += getSum(left,right,2*node_id+2,(node_left+node_right)/2,node_right);

		return ret;
	}
}



int main(){

	ll first_N;
	scanf("%lld",&first_N);

	init(first_N);

	for(ll i = 0; i <= 2*N-2; i++){
		info[i].range_sum = 0;
		info[i].uniformity = 0;
		info[i].minimum = HUGE_NUM;
		info[i].num_minimum = 1;
		info[i].second_minimum = HUGE_NUM;
		info[i].base_value = -1;
	}

	ll tmp;
	for(int i = 0; i < first_N; i++){

		scanf("%lld",&tmp);
		first_add(i,tmp);
	}

	int num_query;
	scanf("%d",&num_query);

	int command,left,right;
	ll value,pre,current;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d %d %d %lld",&command,&left,&right,&value);
		left--;
		right--;

		if(command == 1){ //加算命令

			add(left,right+1,value,0,0,N);

		}else{

			pre = getSum(0,N,0,0,N);
			add(left,right+1,-value,0,0,N);
			changeMax(left,right+1,0,0,0,N);
			current = getSum(0,N,0,0,N);

			printf("%lld\n",pre-current);
		}
	}

	return 0;
}



Measured memory_bytes: 15492