#include<stdio.h>
#include<stdlib.h>

typedef long long int int64;

typedef struct RSQandRAQ{
  int *add;
  int64 *sum;
  int size;
} segTree;

segTree* newRSQandRAQ(const int n){
  int k=1;
  while(k<n) k*=2;
  segTree *s=(segTree *)malloc(sizeof(segTree));
  s->add=(int *)calloc(2*k,sizeof(int));
  s->sum=(int64 *)calloc(2*k,sizeof(int64));
  s->size=k;
  return s;
}

void add_sub(segTree *s,int k,int l,int r,int x,int y,int v){
  if(y<=l || r<=x) return;
  if(x<=l && r<=y){
    s->add[k]+=v;
    return;
  }
  int m=(l+r)/2;
  add_sub(s,2*k  ,l,m,x,y,v);
  add_sub(s,2*k+1,m,r,x,y,v);
  s->sum[k]=s->sum[2*k]+(int64)(m-l)*s->add[2*k]+s->sum[2*k+1]+(int64)(r-m)*s->add[2*k+1];
  return;
}

void add(segTree *s,int l,int r,int v){
  add_sub(s,1,0,s->size,l,r,v);
}

int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a>b?a:b;}

int64 getSum_sub(segTree *s,int k,int l,int r,int x,int y){
  if(y<=l || r<=x) return 0;
  if(x<=l && r<=y) return s->sum[k]+(int64)(r-l)*s->add[k];
  int m=(l+r)/2;
  return getSum_sub(s,2*k,l,m,x,y)+getSum_sub(s,2*k+1,m,r,x,y)+(int64)(min(y,r)-max(x,l))*s->add[k];
}

int64 getSum(segTree *s,int l,int r){
  return getSum_sub(s,1,0,s->size,l,r);
}

void run(void){
  int n,q;
  scanf("%d%d",&n,&q);
  segTree *s=newRSQandRAQ(n);
  while(q--){
    int c;
    scanf("%d",&c);
    if(c==0){
      int l,r,v;
      scanf("%d%d%d",&l,&r,&v);
      add(s,l-1,r,v);
    } else {
      int l,r;
      scanf("%d%d",&l,&r);
      printf("%lld\n",getSum(s,l-1,r));
    }
  }
}

int main(void){
  run();
  return 0;
}

