#include <bits/stdc++.h>
#define ll long long int
#define ff first
#define pb push_back
#define ss second
#define debug 0
#define ff first
#define mp make_pair
 
using namespace std;
 
const ll MOD = 1000000007LL;
 
ll fact[1000006];
ll ifact[1000006];
ll power2[1000006];
 
ll ar[200056];
ll br[200056];
ll level[300005];
vector<int> adj[500005];

set<ll>::iterator it;
 
bool vis[500020];
ll sum;
 
bool prime[10000006];
 
vector<int> primes,vec,pec;

map<ll,ll> has,mark;
ll day[300006];
 
 
 
ll powr (ll a, ll  b)
{
    if (b == 0)
        return 1;
    long long int x = powr(a, b/2);
    if (b % 2 == 0)
        return (x*x)%MOD;
    else
        return ((x*x)%MOD*a%MOD)%MOD;
}
 
inline ll inv(ll x) {
  return powr(x, MOD - 2);
}
 
inline ll mulMod(ll a, ll b) {
  return (a%MOD * b%MOD) % MOD;
 
}
 
inline void process() {
  fact[0] = 1;
  power2[0] = 1;
  for(int i = 1; i < 1003; i++) {
    fact[i] = mulMod(fact[i - 1], i);
    power2[i] = mulMod(power2[i - 1], 2);
  }
  ifact[1002] = inv(fact[1002]);
  for(int i = 1002 - 1; i >= 0; i--) {
    ifact[i] = mulMod(ifact[i + 1], i + 1);
  }
}
 
inline ll ncr(ll n, ll r) {
  if(n < r) return 0;
  return mulMod(fact[n], mulMod(ifact[r], ifact[(n - r)]));
}
 
ll solve(ll n, ll k)
{
    ll C[k+1];
    memset(C, 0, sizeof(C));
 
    C[0] = 1; 
 
    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, k); j > 0; j--)
            C[j] = C[j] + C[j-1];
    }
    return C[k];
}
 
void solve1(vector<ll> price, ll n, ll S[])
{
   
   stack<ll> st;
   st.push(0);
 
   S[0] = 1;
 
   for (ll i = 1; i < n; i++)
   {
 
      while (!st.empty() && price[st.top()] <= price[i])
         st.pop();
 
 
      S[i] = (st.empty())? (i + 1) : (i - st.top());
 
      st.push(i);
   }
}
 
void sieve()
{
    memset(prime,true,sizeof(prime));
    prime[0]=prime[1]=false;
    
    for(ll i=2;i*i<=100006;i++)
    {
        if(prime[i])
        {
            for(ll j=i*2;j<=100006;j+=i)
            {
                prime[j]=false;
            }
        }
    }
    
    for(int i=2;i<=100005;i++)
    {
    	if(prime[i])
    	primes.pb(i);
	}
}


int bfs(int s)
{
	vis[s]=1;
	queue<int> q,temp;
	
	vector<int>::iterator it;
	
	q.push(s);
	int siz=1;
	int lev=1;
	level[0]=ar[0];
	
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		siz--;
		
		for(it=adj[u].begin();it!=adj[u].end();++it)
		{
			if(!vis[*it])
			{
				q.push(*it);
				vis[*it]=1;
			}
			
		}
		
		if(siz==0)
		{
			siz=q.size();
			bool flag=0;
			ll val=0;
			while(!q.empty())
			{
				 val^=ar[q.front()];
				temp.push(q.front());
				q.pop();
			}
			
			if(val==0)
			{
				while(!temp.empty())
			{
				q.push(temp.front());
				temp.pop();
			}
			continue;
			}
			
			level[lev]=0;
			
			while(!temp.empty())
			{
				level[lev]^=ar[temp.front()];
				q.push(temp.front());
				temp.pop();
			}
			
			if(siz>0)
			lev++;
		}
	}
	
	return lev-1;
}
 
 
 
 

 
int main() 
{
//	freopen("input4.in","r",stdin);
//	freopen("output4.out","w",stdout);
    ll n,m,t,p,q,s,a,b,c,d,e,f,g,h,res,u,v,i,j,l,k,len,tot,rad,ds,rs,y,r,z,maxm,minm,cycle,val,max1=0,max2=0,num=0,zero,ans=0;
    
    
    string str,ptr="",dup="",dtr="";
    
    
    cin>>n>>k;
    
   for(i=0;i<n;i++)
   cin>>ar[i];
   
   for(i=0;i<n;i++)
   {
   	  p=min(ar[i],k-ar[i]);
   	  ans+=2*p;
   }
    
   cout<<ans;
   
	return 0;
    
}    

Measured memory_bytes: 16640