#include <bits/stdc++.h>
using namespace std;

int main(){
    long long n;
    cin >> n;
    long long tsum = 0;
    while(n--){
        long long a, b;
        cin >> a >> b;

        long long  sum1 = ((a-1) * a) / 2;
        long long  sum2 = ( b * (b+1)) / 2;
        long long sum = sum2 - sum1;
        tsum = tsum + sum;
    }
    cout << tsum << endl;
    return 0;
}
#include <iostream>
#include <fstream>
#include <cstdio>
#include <string>
#include <stack>
#include <queue>
#include <random>
#include <deque>
#include <cassert>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <list>
#include <forward_list>
#include <array>
#include <cstring>
#include <cmath>
#include <tuple>
#include <complex>
#include <bitset>
#include <climits>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using pld = pair<ld, ld>;


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    ll N, K;
    cin >> N >> K;

    ll res = 0;
    for (ll cur_sum = 2 - min(0ll, K); cur_sum <= 2 * N - max(0ll, K); ++cur_sum)
    {
        res += (abs(cur_sum - 2 * max(1ll, cur_sum - N)) + 1) * (abs(cur_sum + K - 2 * max(1ll, cur_sum + K - N)) + 1);
    }

    cout << res;
}
