def main():

    N = int(eval(input()))

    K = int(eval(input()))

    X = [int(i) for i in input().split()]

    ans = 0

    for x in X:

        ans += 2 * min(x, K - x)

    print(ans)





if __name__ == '__main__':

    main()

def main():

    N = int(eval(input()))

    K = int(eval(input()))

    X = [int(i) for i in input().split()]

    ans = 0

    for x in X:

        ans += min(x, K-x)*2

    print(ans)





if __name__ == '__main__':

    main()

def main():
    N = int(eval(input()))
    K = int(eval(input()))
    X = [int(i) for i in input().split()]
    ans = 0
    for x in X:
        ans += 2 * min(x, K - x)
    print(ans)


if __name__ == "__main__":
    main()

def main():
    N = int(eval(input()))
    K = int(eval(input()))
    X = [int(i) for i in input().split()]
    ans = 0
    for x in X:
        ans += min(x, K - x) * 2
    print(ans)


if __name__ == "__main__":
    main()

-        ans += 2 * min(x, K - x) +        ans += min(x, K - x) * 2