#include <iostream>                                                                                                                                                                                         
#include <algorithm>                                                                                                                                                                                        
#include <cstring>                                                                                                                                                                                          
#include <vector>                                                                                                                                                                                           
#include <numeric>                                                                                                                                                                                          
using namespace std;                                                                                                                                                                                        
                                                                                                                                                                                                            
typedef long long ll;                                                                                                                                                                                       
                                                                                                                                                                                                            
int main()                                                                                                                                                                                                  
{                                                                                                                                                                                                           
    ll n, k;                                                                                                                                                                                                
    cin >> n >> k;                                                                                                                                                                                          
                                                                                                                                                                                                            
    ll sum=0;                                                                                                                                                                                               
                                                                                                                                                                                                            
    for (int i=0; i<n; ++i) {                                                                                                                                                                               
        ll xi;                                                                                                                                                                                              
        cin >> xi;                                                                                                                                                                                          
                                                                                                                                                                                                            
        if(xi <= k/2) sum += 2*xi;                                                                                                                                                                          
        else sum += 2*(k-xi);                                                                                                                                                                               
    }                                                                                                                                                                                                       
                                                                                                                                                                                                            
    cout << sum << endl;                                                                                                                                                                                    
}  

Measured memory_bytes: 256