/*
	DSL: domain-specific language
	http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_F
	12/5/2017
	TLE: 15/22, doing the query(use loop for (i,j))
	solution: add another ele in node to keep element, look liks add more element is hard to update the 
	Final solution1.0: use the recusive and 
*/
//why long is not enough
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
//#define N 131072 //100000
#define MAXVAL ((long int) ((unsigned long) (1 << 31) - 1))  //*2
typedef long long int ll;
ll min(int a, int b){return a>b?b:a;}
ll max(int a, int b){return a>b?a:b;}
ll query(int search_left,int search_right,int node_id,int node_left,int node_right);
void update(int update_left,int update_right,int new_value,int node_id,int node_left,int node_right);
void update2(int x, int node_id,int node_left, int node_right);
ll data[2*131072+100];      //nodes represent the add of current node(for leaf it means, for interal node: it has children)
ll sum_children[2*131072+100]; //nodes represent the sum of children(leaf are zero);
//BEGIN FROM 0;
int main(){
	int n = 0, q = 0;
	int N = 1;
	int a,b,c;
	//read from the file
	//FILE *fp;
	//fp = fopen("in.txt","r");
	scanf("%d %d",&n,&q);
	
	//how to calculate the beginning index (the last layer of the tree)
	//how many nodes in last layer
	while(N<n) N = N<<1;
	//printf("N%d\n",N);
	for(int i = 0; i<=2*N-2; i++){
		data[i] = 0;
		sum_children[i] = 0;
	}
	
	//printf("count:%d",count);
	
	for(int i = 1; i <=q; i++){
		int temp = 0;
		scanf("%d",&temp);
		if(temp==0){
			scanf("%d %d %d",&a,&b,&c);
			a = a-1;b=b-1;
			update(a,b,c,0,0,N-1);
			/*for(int i = 0 ;i<=2*N-2; i++){
				printf("%d ",sum_children[i]);
			}printf("\n");*/
		}
		else if(temp==1){
			scanf("%d %d",&a,&b);
			a = a-1;b=b-1;
			printf("%lld\n",query(a,b,0,0,N-1));
		}
	}
	return 0;
}


/*
	update the value in the array, no return 
	foramtion: if() return; 
				f();
*/
void update(int update_left,int update_right,int new_value,int node_id,int node_left,int node_right){
    if(update_right < node_left || update_left > node_right)return;
    else if(update_left <= node_left && update_right >= node_right){
        data[node_id] += new_value;//to update the value(if in the right rage or a single point;
    }else{
        sum_children[node_id] += (min(update_right, node_right)-max(update_left,node_left)+1)*new_value; 
        //update with update_left and update_right
        update(update_left,update_right,new_value,2*node_id+1,node_left,(node_left+node_right)/2);
        update(update_left,update_right,new_value,2*node_id+2,(node_left+node_right)/2+1,node_right);
    }
}
ll query(int search_left,int search_right,int node_id,int node_left,int node_right){
    if(search_right < node_left || search_left > node_right){
        return 0;//not in the range
    }else if(search_left <= node_left && search_right >= node_right) {//unfold until left==right
    		return ((node_right-node_left+1)*data[node_id]+sum_children[node_id]);
    	}
    else{
        	//printf("wei");
        	ll sum = (min(search_right, node_right)-max(search_left,node_left)+1)*(data[node_id]);
            ll left = query(search_left,search_right,2*node_id+1,node_left,(node_left+node_right)/2);
            ll right = query(search_left,search_right,2*node_id+2,(node_left+node_right)/2+1,node_right);
            return (sum+left+right);
    }
    
}

Measured memory_bytes: 6852