#include <bits/stdc++.h>
//file stream
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<sstream>
#include <set>

using namespace std;
#define output freopen("output.txt","w",stdout)
#define input freopen("input.txt","r",stdin)
#define inputfile(x) freopen(x,"r",stdin)
#define outpufile(x) freopen(x,"w",stdout)
//functions
#define pb(x)  push_back(x)
#define pf  printf
#define sc scanf
#define mxe(a,n)   (*max_element(a,a+n))
#define mne(a,n)   (*min_element(a,a+n))
#define SUM(a,n)   (accumulate(a,a+n,0))
#define countbit(x) __builtin_popcount(x)
#define lb  lower_bound // first element which does not compare less than
#define ub  upper_bound //first element which compares greater than
#define bs  binary_search
#define SQ(a)  ((a)*(a))
#define PI (acos(-1.0))
#define mid(l,r)    ((l+r)>>1)


#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
// pair
#define xx first
#define yy second
#define mp(x,y) make_pair(x,y)
//inputs 1 var
#define si1(n) sc("%d",&n)
#define sl1(n) sc("%lld",&n)
#define slu1(n) sc("%llu",&n)
#define sd1(n) sc("%lf",&n)
#define ss1(n) sc("%s",n)
//inputs 2 var
#define si2(n,m) sc("%d %d",&n,&m)
#define sl2(n,m) sc("%lld %lld",&n,&m)
#define slu2(n,m) sc("%llu %llu",&n,&m)
#define sd2(n,m) sc("%lf %lf",&n,&m)
//inputs 3 var
#define si3(n,m,l) sc("%d %d %d",&n,&m,&l)
#define sl3(n,m,l) sc("%lld %lld %lld",&n,&m,&l)
#define slu3(n,m,l) sc("%llu %llu %llu",&n,&m,&l)
#define sd3(n,m,l) sc("%lf %lf %lf",&n,&m,&l)

//output 1 var
#define pi1(n) pf("%d",n)
#define pl1(n) pf("%lld",n)
#define plu1(n) pf("%llu",n)
#define pd1(n,pre) pf("%.*f",pre,n)
#define ps1(n) pf("%s",n)
//output 2 var
#define pi2(n,m) pf("%d %d",n,m)
#define pl2(n,m) pf("%lld %lld",n,m)
#define plu2(n,m) pf("%llu %llu",n,m)
#define pd2(n,m,pre) pf("%.*f %.*f",pre,n,pre,m)
//inputs 3 var less important
#define pi3(n,m,l) pf("%d %d %d",n,m,l)
#define pl3(n,m,l) pf("%lld %lld %lld",n,m,l)
#define plu3(n,m,l) pf("%llu %llu %llu",n,m,l)
//output misc
#define nln putchar(10)
#define sps putchar(' ')
#define pch(c) putchar(c)
#define tcsp(i) pf("Case %d: ",++i)
#define tcnl(i) pf("Case %d:\n",++i)
#define dg()   pf("-----------here\n")

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sc1(n) cin>>n
#define sc2(n,m) cin>>n>>m
#define sc3(n,m,k) cin>>n>>m>>k
#define sc4(n,m,k,l) cin>>n>>m>>k>>l

#define pr1(n) cout<<n
#define pr2(n,m) cout<<n<<" "<<m
#define pr3(n,m,k) cout<<n<<" "<<m<<" "<<k
#define pr4(n,m,k,l) cin<<n<<" "<<m<<" "<<k<<" "<<l
#define NL cout<<endl
#define setPre(x) setprecision(x)
#define fixP cout<<fixed



//loop
#define fr0(i,n) for(i=0;i<n;i++)
#define fr1(i,n) for(i=1;i<=n;i++)
#define FR(i,b,e) for(i=b;i<=e;i++)
#define FRR(i,e,b) for(i=e;i>=b;i--)
//to compile in codeblocks , c++11 flag must be off
//additional, only work if compiled with gcc compiler
#define frf(c, it) for(typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define frr(c, it) for(typeof((c).rbegin()) it = (c).rbegin(); it != (c).rend(); it++)
//memory reset
#define set0(x) memset(x,0,sizeof x)
#define set(x,v) memset(x,v,sizeof x)
#define setn1(x) memset(x,-1,sizeof x)
#define setinf(x) memset(x,125,sizeof x)
//misc
#define SZ(v)   ((int) (v).size())
#define all(v)  (v).begin(), (v).end()
//bit operation single variable
#define On(x,i)  (x|=(1<<(i)))
#define Off(x,i) (x&= ~(1<<(i)))
#define isOn(x,i) (x&(1<<(i)))
#define Toggle(x,i) (x^=(1<<(i)))
#define tmod(x,i)  (x&(~(-1<<i)))

//10000019 10000079 10000103 1000000007 1000000009 1000000021 hash base

template <class _T> void ina(_T a[],int n){int i; fr0(i,n)sc1(a[i]);}
//constant
const double EPS = 1e-9;
const int SIZE=1e6;


///BIT
/*
int __bit[SIZE+100],_n,_lg;
void __inc(int i,int v){for(;i<=_n;i+=(i&-i))__bit[i]+=v;}
int __sum(int i){int s=0;for(;i;i-=(i&-i))s+=__bit[i];return s;}
int __select(int k){int p,i,h=0;for(i=_lg;i>-1;i--){p=1<<i;if(p+h>_n)continue;if(__bit[p+h]<k)h+=p,k-=__bit[h];}return h+1;}
*/
//BIG MOD / mod inverse

template<class _T> _T pow(_T a,_T b,_T m){a%=m;_T ans=1%m;while(b){if(b&1)ans*=a,ans%=m;a*=a;a%=m;b>>=1;}return ans;}
template<class _T> _T pow(_T a,_T b){_T ans=1;while(b){if(b&1)ans*=a;a*=a;b>>=1;}return ans;}
template<class _T>_T add(_T a,_T b,_T m){return a>=m-b?a-(m-b):a+b;}//a,b<m
template<class _T>_T multiply(_T a,_T b,_T m){_T ans=0;if(b>a)swap(a,b);while(b){if(b&1)ans=add(ans,a,m);b>>=1;a=add(a,a,m);}return ans;}//a,b<m
template<class _T>_T bigpow(_T a,_T b,_T m){a%=m;_T ans=1%m;while(b){if(b&1)ans=multiply(ans,a,m);a=multiply(a,a,m);b>>=1;}return ans;}
template<class _T>_T modinvers(_T a,_T m){return m>2000000000LL?bigpow(a,m-2,m):pow(a,m-2,m);}//m is prime

//egcd / mod inverse
template<class _T> _T _egcd(_T a, _T b, _T &x,_T &y){if(!b){x=1,y=0;return a;}_T _g=_egcd(b,a%b,x,y);_T xt=x;x=y,y=xt-(a/b)*y;return _g;}
template<class _T> _T fmodinvers(_T a,_T m){_T x,y;_egcd(a,m,x,y);x%=m;if(x<0)x+=m;return x;} //a,m co-prime
template<class _T> _T _lcm(_T a, _T b){return a*b/__gcd(a,b);}

//direction array

//data type
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<pii ,pii > ppii;
typedef set<int> si;
typedef set<ll> sl;
typedef map<int,int> mii;
typedef map<ll,int> mli;
typedef map<string,int> msi;
typedef long double ld;

ll mod=1000000007;

int main()
{
    int i,j,k,m=0,n,a,b,c,tc,o,ans,q,x,y;
    char com[109];
    si2(n,k);

    fr0(i,n)
    {
        si1(x);

        m+=2*min(x,k-x);
    }
    pi1(m);nln;


    return 0;
}


Measured memory_bytes: 256