import Foundation
func readInts() -> [Int] { readLine()!.split(separator: " ").map { Int($0)! } }

let n = Int(readLine()!)!
let k = Int(readLine()!)!
let xi = readInts()
let ans = xi.map { min($0, k - $0) * 2 }.reduce(0) { $0 + $1 }
print(ans)