#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int n,d;

inline ll calc(int x)
{
	if(x<2 || x>2*n) return 0;
	
	int l = max(x-n, 1), r = min(x-1, n);
	
	return r<l? 0: r-l+1;
}

int main(void)
{
	scanf("%d%d",&n,&d);
	
	ll ans = 0;
	for(int i=2; i<=2*n; ++i)
		ans += calc(i) * calc(i-d);
	
	printf("%lld",ans);
	return 0;
}
#include <bits/stdc++.h>
#define ll long long 
using namespace std;

ll a[300005], b[300005];

int main(){
    
    int n;
    cin >> n;
    ll res = 0;
    for(int i = 0; i < n; i ++ )    cin >> a[i], res += a[i] * a[i] * (n - 1);
    
    for(int i = n - 1; i >= 0; i -- ){
        b[i] = b[i + 1] + a[i];
    }
    ll ans = 0;
    for(int i = 0; i < n; i ++ ){
        ans += b[i + 1] * a[i];
    }
    ans *= 2;
    cout << res - ans << endl;
    return 0;
}