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

int main()
{
  int i, n, s, t, x, w;
  long long *a, *b, z;
  char *p, buf[64];
  buf[63] = 0;
  buf[62] = '\n';
  fgets(buf, 64, stdin);
  for (n=0,p=buf; *p>' '; n=n*10+*(p++)-'0');
  w = pow(2,ceil(log2(n)))+1;
  b = (a = (long long*)calloc(w*2, sizeof(long long)))+w;
  while (fgets(buf, 64, stdin)) {
    for (s=0,p=buf+2; *p>' '; s=s*10+*(p++)-'0');
    for (t=0,p++; *p>' '; t=t*10+*(p++)-'0');
    if (*buf=='0') {
      for (x=0,p++; *p>' '; x=x*10+*(p++)-'0');
      for (i=s; i<w; i+=i&-i) {
	a[i] += -x*(s-1);
	b[i] += x;
      }
      for (i=t+1; i<w; i+=i&-i) {
	a[i] += x*t;
	b[i] += -x;
      }
    } else {
      for (z=0,i=t; i>0; i&=i-1) z += a[i]+b[i]*t;
      for (i=s-1; i>0; i&=i-1)	 z -= a[i]+b[i]*(s-1);
      if (z<10) {
      	putc_unlocked('0'+z, stdout);
	putc_unlocked('\n', stdout);
      } else {
	for (i=62; z>0; buf[--i]='0'+z%10,z/=10);
	fputs(buf+i, stdout);
      }
    }
  }
  return 0;
}

