#include <stdio.h>
#include <iostream>

int ma[10000][10000];

int main() {
    int m, duzina;
    unsigned int bro = 0, brn = 0;
    long int n, z = 0;
    scanf("%li %d", &n, &m);

    for(long int i = 1; i <= n; i++) {
        scanf("%d", &duzina);
        if(duzina < m - duzina) for(int j = 1; j <= duzina; j++) ma[i][j] = 1;
        else for(int j = m; j <= m - duzina; j--) ma[i][j] = 1;
    }
    for(int i = 1; i <= m; i++) {
        for(long int j = 1; j <= n; j++) {
            if(ma[i][j] == 1) bro++;
            else brn++;
        }
        z += bro * brn;
        bro = 0; brn = 0;
    }
    printf("%li", z);
    return 0;
}