#import <stdio.h>
#define ABS(a) ((a)>0?(a):(-(a)))
#define MIN(a,b) (((a)<(b))?(a):(b))
int main(){
    int n,k;
    scanf("%d %d",&n,&k);
    int s = 0;
    for (int i=0;i<n;i++) {
        int a;
        scanf("%d",&a);
        s += 2*MIN(a,ABS(k-a));
    }
    printf("%d",s);
}
