#include <bits/stdc++.h>
using namespace std;
const int infty = (int)((1LL << 31) - 1);
struct segment_tree {
  public:
    int n, N;
    vector<long long> tr, lz;
    segment_tree (vector<int> v) {
      n = v.size();
      N = 1;
      while (N < n) N <<= 1;
      tr.resize(2 * N);
      lz.resize(2 * N, 0);
      for (int i = 0; i < n; i++) tr[N + i] = v[i];
      for (int i = N - 1; i >= 1; i--) tr[i] = tr[2 * i] + tr[2 * i + 1];
    }
    inline void pg (int k, int L, int R) {
      if (lz[k]) {
        if (k < N) {
          lz[2 * k] += lz[k] >> 1;
          lz[2 * k + 1] += lz[k] >> 1;
        }
        tr[k] += lz[k];
        lz[k] = 0;
      }
    }
    void add (int l, int r, int x, int k = 1, int L = 0, int R = -1) {
      if (R == -1) R = N;
      pg(k, L, R);
      if (r <= L || R <= l) {
        return;
      } else if (l <= L && R <= r) {
        lz[k] += x * (R - L);
        pg(k, L, R);
      } else {
        int C = (L + R) / 2;
        add(l, r, x, 2 * k, L, C);
        add(l, r, x, 2 * k + 1, C, R);
        tr[k] = tr[2 * k] + tr[2 * k + 1];
      }
    }
    long long getSum (int l, int r, int k = 1, int L = 0, int R = -1) {
      if (R == -1) R = N;
      pg(k, L, R);
      if (r <= L || R <= l) {
        return 0;
      } else if (l <= L && R <= r) {
        return tr[k];
      } else {
        int C = (L + R) / 2;
        return getSum(l, r, 2 * k, L, C) + getSum(l, r, 2 * k + 1, C, R);
      }
    }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  segment_tree sgt(vector<int>(n, 0));
  while (q--) {
    int c;
    cin >> c;
    if (c == 0) {
      int s, t, x;
      cin >> s >> t >> x;
      sgt.add(--s, t, x);
    } else {
      int s, t;
      cin >> s >> t;
      long long ret = sgt.getSum(--s, t);
      cout << ret << '\n';
    }
  }
  return 0;
}
