#include<cstdio>
int min(int x,int y) {return x>y?y:x;}
int main()
{
	int n,k,x,ans=0;
	scanf("%d%d",&n,&k);
	while(n--)
	{
		scanf("%d",&x);
		ans+=min(x,k-x);
	}
	printf("%d\n",ans*2);
    return 0;
}