#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  int N,K,sum=0,x;
  cin>>N>>K;
  for(int i=0;i<N;i++){
    cin >> x;
    sum += min(x,abs(x-K));
  }
  cout << 2*sum << endl;
}