qyliang/CodeNanoFix huggingface dataset:
# Buggy code:
n,m = map(int,input().split())
count = 0
ab = []
for _ in range(m):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])

for i in range(m):
    root = [[] for i in range(n)]
    done = [False]*n
    cd = copy.copy(ab)
    cd.pop(i)
    for j in range(m-1):
        a, b = cd[j]
        root[b-1].append(a-1)
        root[a-1].append(b-1)
        
    stack=[0]
    while len(stack):
        v = stack.pop()
        for k in root[v]:
            if done[k]: continue
            done[k] = True
            stack.append(k)
    if False in done:
        count += 1

print(count)

# Fixed code:
import copy     
n,m = map(int,input().split())
count = 0
ab = []
for _ in range(m):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])

for i in range(m):
    root = [[] for i in range(n)]
    done = [False]*n
    cd = copy.copy(ab)
    cd.pop(i)
    for j in range(m-1):
        a, b = cd[j]
        root[b-1].append(a-1)
        root[a-1].append(b-1)
        
    stack=[0]
    while len(stack):
        v = stack.pop()
        for k in root[v]:
            if done[k]: continue
            done[k] = True
            stack.append(k)
    if False in done:
        count += 1

print(count)
# Buggy code:
from collections import deque
n,m=map(int,input().split())
X=[]
M=[[] for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    X.append([a,b])
    M[a-1].append(b-1)
    M[b-1].append(a-1)
ans=0
for i in range(m):
    se={X[i][0],X[i][1]}
    q=deque([0])
    visited=[0]*n
    while q:
        s=q.popleft()
        if visited[s]==1:
            continue
        visited[s]=1
        for x in M[s]:
            if {s,x}!=se:
                q.append(x)
    if sum(visited)!=n:
        ans+=1
print(ans)

# Fixed code:
from collections import deque
n,m=map(int,input().split())
X=[]
M=[[] for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    X.append([a,b])
    M[a-1].append(b-1)
    M[b-1].append(a-1)
ans=0
for i in range(m):
    a,b=X[i][0],X[i][1]
    M[a-1].remove(b-1)
    M[b-1].remove(a-1)
    q=deque([0])
    visited=[0]*n
    while q:
        s=q.popleft()
        if visited[s]==1:
            continue
        visited[s]=1
        for x in M[s]:
            q.append(x)
    M[a-1].append(b-1)
    M[b-1].append(a-1)
    if sum(visited)!=n:
        ans+=1
print(ans)
# Buggy code:
N, M = map(int, input().split())
E = [[] for i in range(N)]
visited = []
ab = []
for i in range(M):
    a, b = map(int, input().split())
    ab.append([a-1, b-1])
         
def DFS(pos):
    for n_pos in E[pos]:
        if n_pos not in visited:
            visited.append(n_pos)
            DFS(n_pos)
cnt = 0
for i in range(M):
    visited = []
    E = [[] for i in range(N)]
    for j in range(M):
        if j == 1:
            continue
        E[ab[j][0]].append(ab[j][1])
        E[ab[j][1]].append(ab[j][0])
    DFS(0)
    if(len(visited) < N):
        cnt += 1
print(cnt)

# Fixed code:
N, M = map(int, input().split())

E = [[] for i in range(N)]

ab = []
for i in range(M):
    a, b = map(int, input().split())
    ab.append([a-1, b-1])

visited = []


def search(pos):
    for n_pos in E[pos]:
        if n_pos not in visited:
            visited.append(n_pos)
            search(n_pos)

count = 0
for i in range(M):
    visited = []
    E = [[] for i in range(N)]
    for j in range(M):
        if j == i:
            continue
        E[ab[j][0]].append(ab[j][1])
        E[ab[j][1]].append(ab[j][0])
    search(0)
    if len(visited) < N:
        count += 1

print(count)
# Buggy code:
from collections import defaultdict as dd
n,m = map(int, input().split())
dic = dd(list)
l = []
cnt = 0
for _ in range(m):
  a,b = map(int, input().split())
  l.append(a,b)
  dic[a].add(b)
  dic[b].add(a)
def con(x):
  visit.add(x)
  for i in [j for j in dic[x] if j not in visited]:
    con(i)
  return visit == set(range(1,n+1))
for x,y in l:
  dic[x].remove(y)
  dic[y].remove(x)
  visit = set()
  if not con(x):
    cnt += 1
  dic[x].add(y)
  dic[y].add(x)
print(cnt)

# Fixed code:
from collections import defaultdict as dd
n,m = map(int, input().split())
dic = dd(list)
l = []
cnt = 0
for _ in range(m):
  a,b = map(int, input().split())
  l.append((a,b))
  dic[a].append(b)
  dic[b].append(a)
def con(x):
  visit.add(x)
  for i in dic[x]:
    if i in visit:
      continue
    con(i)
  return visit == set(range(1,n+1))
for x,y in l:
  dic[x].remove(y)
  dic[y].remove(x)
  visit = set()
  if not con(x):
    cnt += 1
  dic[x].append(y)
  dic[y].append(x)
print(cnt)
# Buggy code:
import sys
n,m=map(int,input().split())
vertex=[[int(i) for i in l.split()] for l in sys.stdin]
def generate(x):
  root=[i for i in range(1,x+1)]
  size=[0]*x
def find(x):
  if root[x]==x:
    return x
  return find(root[x])
def check(x,y):
  return find(x)==find(y)
def union(x,y):
  x=find(x)
  y=find(y)
  if size[x]>=size[y]:
    root[y]=x
  else:
    root[x]=y
  if size[x]==size[y]:
    size[x]+=1
ans=0
for i in range(m):
  generate(n)
  for j in range(m):
    if j!=i:
      if check(vertex[j][0],vertex[j][1]):
        pass
      else:
        union(vertex[j][0],vertex[j][1])
  for j in range(n-1):
    if check(j,j+1)==0:
      pass
    else:
      ans+=1
      break
print(ans)

# Fixed code:
import sys
n,m=map(int,input().split())
vertex=[[int(i) for i in l.split()] for l in sys.stdin]
def find(x):
  if root[x]==x:
    return x
  root[x]=find(root[x])
  return root[x]
def check(x,y):
  return find(x)==find(y)
def union(x,y):
  x=find(x)
  y=find(y)
  if size[x]>=size[y]:
    root[y]=x
  else:
    root[x]=y
  if size[x]==size[y]:
    size[x]+=1
ans=0
for i in range(m):
  root=[i for i in range(n+1)]
  size=[0]*(n+1)
  for j in range(m):
    if j!=i:
      if check(vertex[j][0],vertex[j][1]):
        pass
      else:
        union(vertex[j][0],vertex[j][1])
  for j in range(1,n):
    if check(j,j+1)==True:
      pass
    else:
      ans+=1
      break
print(ans)
# Buggy code:
import copy

def m():
    N, M = map(int, input().split())
    graph = [[] for _ in range(N+1)]
    E = []
    visited = []
    for i in range(M):
        a, b = map(int, input().split())
        E.append((a,b))

    for m in range(M):
        a, b = E[m]
        graph[a].append(b)
        graph[b].append(a)


    def dfs(v, g):
        if visited[v] == True:
            return
        visited[v] = True
        for i in g[v]:
            dfs(i,g)


    def is_all_visited(v):
        for i in range(1, N):
            if v[i]:
                pass
            else:
                return False
        return True
    ans = 0
    for j in range(M):
        y,z = E[j]
        visited = [False] * (N + 1)
        tmp = copy.deepcopy(graph)
        tmp[y].remove(z)
        tmp[z].remove(y)
        dfs(1,tmp)
        if is_all_visited(visited):
            pass
        else:
            ans +=1

    return ans


print(m())


# Fixed code:
import copy


def m():
    N, M = map(int, input().split())
    graph = [[] for _ in range(N + 1)]
    E = []
    visited = []
    for i in range(M):
        a, b = map(int, input().split())
        E.append((a, b))

    for m in range(M):
        a, b = E[m]
        graph[a].append(b)
        graph[b].append(a)

    def dfs(v, g):
        if visited[v] == True:
            return
        visited[v] = True
        for i in g[v]:
            dfs(i, g)

    def is_all_visited(v):
        for i in range(1, N + 1):
            if v[i]:
                pass
            else:
                return False
        return True

    ans = 0
    for j in range(M):
        y, z = E[j]
        visited = [False] * (N + 1)
        tmp = copy.deepcopy(graph)
        tmp[y].remove(z)
        tmp[z].remove(y)
        dfs(1, tmp)
        if is_all_visited(visited):
            pass
        else:
            ans += 1

    return ans


print(m())
# Buggy code:
from collections import deque
n,m = map(int,input().split())
path = [[] for _ in range(n)]
ab = [[] for _ in range(m)]
for i in ragne(m):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  ab[i] = (a,b)
  path[a].append(b)
  path[b].append(a)
def dfs(a,b):
  que = deque()
  reach = [False]*n
  reach[0] = True
  que.append(0)
  while que:
    p = que.pop()
    for i in path[p]:
      if (p,i)!=(a,b)!=(i,p) and not reach[i]:
        p.append(i)
        reach[i] = True
  return reach != [True] * n
ans = 0
for a,b in ab:
  ans += dfs(a,b)
print(ans)


# Fixed code:
from collections import deque
n,m = map(int,input().split())
path = [[] for _ in range(n)]
ab = [[] for _ in range(m)]
for i in range(m):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  ab[i] = (a,b)
  path[a].append(b)
  path[b].append(a)
def dfs(a,b):
  que = deque()
  reach = [False]*n
  reach[0] = True
  que.append(0)
  while que:
    p = que.pop()
    for i in path[p]:
      if (p,i)!=(a,b)!=(i,p) and not reach[i]:
        que.append(i)
        reach[i] = True
  return reach != [True] * n
ans = 0
for a,b in ab:
  ans += dfs(a,b)
print(ans)
# Buggy code:
N, M = map(int, input().split())
ablist = [list(map(int, input().split())) for _ in range(M)]
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
ans = 0
for i in range(M):
    uf = UnionFind(N)
    for j in range(M):
        if i != j:
            uf.union(*ablist[j])
    if uf.group_count() >= 2:
        ans += 1
print(ans)


# Fixed code:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

N, M = map(int, input().split())
def int_(num):
    return int(num) - 1
ablist = [list(map(int_, input().split())) for _ in range(M)]
ans = 0
for ng in range(M):
    uf = UnionFind(N)
    for i in range(M):
        if i != ng:
            uf.union(*ablist[i])
    if uf.group_count() != 1:
        ans += 1
print(ans)
# Buggy code:
from collections import deque

n, m = map(int, input().split())
e = [list(map(int, input().split())) for _ in range(m)]

res = 0
for i in range(m):
    edge = [[] for _ in range(n)]
    for j in range(m):
        if i == j:
            continue
        a, b = e[j]
        edge[a-1].append(b-1)
        edge[b-1].append(a-1)

    d = deque([0])
    visited = [False] * n
    visit_cnt = 0
    while d:
        node = d.popleft()
        visited[node] = True
        visit_cnt += 1
        for next_node in edge[node]:
            if not visited[next_node]:
                d.append(next_node)
    if visit_cnt < n:
        res += 1

print(res)

# Fixed code:
from collections import deque

n, m = map(int, input().split())
e = [list(map(int, input().split())) for _ in range(m)]

res = 0
for i in range(m):
    edge = [[] for _ in range(n)]
    for j in range(m):
        if i == j:
            continue
        a, b = e[j]
        edge[a-1].append(b-1)
        edge[b-1].append(a-1)
    
    flag = False
    for j in range(n):
        d = deque([j])
        visited = [False] * n
        visit_cnt = 0
        while d:
            node = d.popleft()
            visited[node] = True
            visit_cnt += 1
            for next_node in edge[node]:
                if not visited[next_node]:
                    d.append(next_node)
        if visit_cnt < n:
            flag = True
            break
    
    if flag:
        res += 1

print(res)
# Buggy code:
n, m = map(int, input().split())
edges = [list(map(int, input().split())) for i in range(m)]
count = 0
print(n,m,edges)

for x in edges:
    l = list(range(n))
    print(l)
    for y in edges:
        if y != x:
            l = [l[y[0]-1] if l[i] == l[y[1]-1] else l[i] for i in range(n)]
            print(l)
    if len(set(l)) != 1:
        count += 1

print(count)

# Fixed code:
n, m = map(int, input().split())
edges = [list(map(int, input().split())) for i in range(m)]
count = 0
 
for x in edges:
    l = list(range(n))
    for y in edges:
        if y != x:
            l = [l[y[0]-1] if l[i] == l[y[1]-1] else l[i] for i in range(n)]
    if len(set(l)) != 1:
        count += 1
 
print(count)
# Buggy code:
# https://atcoder.jp/contests/abc075/tasks/abc075_c
class UnionFind():
    def __init__(self, N):
        self._root = [-1 for _ in range(N)]

    def find(self, x):
        if self._root[x] < 0: return x
        self._root[x] == self.find(self._root[x])
        return self._root[x]

    def unite(self, x, y):
        gx = self.find(x)
        gy = self.find(y)
        if gx == gy:
            return False
        if self._root[gx] > self._root[gy]:
            gx, gy = gy, gx
        self._root[gx] += self._root[gy]
        self._root[gy] = gx
        print(self._root)
        return True

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -(self._root[self.find(x)])

    def roots(self):
        return [i for i in self._root if i < 0]


n, m = map(int, input().split())

nodes = []
for _ in range(m):
    a, b = map(int, input().split())
    nodes.append((a,b))

cnt = 0
for i in range(m):
    uf = UnionFind(n)
    for j in range(m):
        if i != j: 
           uf.unite(nodes[j][0]-1, nodes[j][1]-1)
    cnt += (len(uf.roots()) != 1)
print(cnt)

# Fixed code:
# https://atcoder.jp/contests/abc075/tasks/abc075_c
class UnionFind():
    def __init__(self, N):
        self._root = [-1 for _ in range(N)]

    def find(self, x):
        if self._root[x] < 0: return x
        self._root[x] = self.find(self._root[x])
        return self._root[x]

    def unite(self, x, y):
        gx = self.find(x)
        gy = self.find(y)
        if gx == gy: return False
        if self._root[gx] > self._root[gy]:
            gx, gy = gy, gx
        self._root[gx] += self._root[gy]
        self._root[gy] = gx
        return True

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -(self._root[self.find(x)])

    def roots(self):
        return [i for i in self._root if i < 0]


n, m = map(int, input().split())

nodes = []
for _ in range(m):
    a, b = map(int, input().split())
    nodes.append((a, b))

cnt = 0
for i in range(m):
    uf = UnionFind(n)
    for j in range(m):
        if i != j:
          uf.unite(nodes[j][0]-1, nodes[j][1]-1)
    cnt += (len(uf.roots()) != 1)
print(cnt)
# Buggy code:
N=int(input())
K=int(input())
def ans(s):
  n=int(s)
  return 2*min(K-n,n)
x=list(map(int,input().split()))
print(sum(x))



# Fixed code:
N=int(input())
K=int(input())
def ans(s):
  n=int(s)
  return 2*min(K-n,n)
x=list(map(ans,input().split()))
print(sum(x))
# Buggy code:
n=int(input())
k=int(input())
x=list(map(int,input().split()))
ans=0
for i in range(len(x)):
  if abs(x[i]-k)>=x[i]:
    ans=ans+x[i]*2
  else:
    ans=ans+(x[i]-k)*2
print(ans)

# Fixed code:
n=int(input())
k=int(input())
x=list(map(int,input().split()))
ans=0
for i in range(n):
  if abs(x[i]-k)>=x[i]:
    ans=ans+x[i]*2
  else:
    ans=ans+abs(x[i]-k)*2
print(ans)
# Buggy code:
N = int(input())
K = int(input())
X = list(map(int,input().split()))
cnt = 0
for i in range(N):
    cnt += 2*min(K-x,x)
print(cnt)

# Fixed code:
N = int(input())
K = int(input())
X = list(map(int,input().split()))
cnt = 0
for i in range(N):
    x = X[i]
    cnt += 2*min(K-x,x)
print(cnt)
# Buggy code:
def main48():
    n = int(input())
    k = int(input())
    data = input().split()
    x = []
    for i in range(n):
        x.append(int(data[i]))
    result = 0
    for i in range(n):
        if x[i] < k-x[i]:
            result = result + x[i]
        else:
            result = result + k-x[i]
    print(result)

if __name__ == "__main__":
    main48()

# Fixed code:
def main48():
    n = int(input())
    k = int(input())
    data = input().split()
    x = []
    for i in range(n):
        x.append(int(data[i]))
    result = 0
    for i in range(n):
        if x[i] < k-x[i]:
            result = result + x[i] * 2
        else:
            result = result + (k-x[i]) * 2
    print(result)

if __name__ == "__main__":
    main48()
# Buggy code:
N = int(input())
K = int(input())
X = list(map(int, input().split()))
count = 0
for i in X:
    A = i
    B =abs(i - K)
    if A >= B:
        count = count + B
    else:
        count = count + A
print(count)

# Fixed code:
N = int(input())
K = int(input())
X = list(map(int, input().split()))
count = 0
for i in X:
    A = i
    B =abs(i - K)
    if A >= B:
        count = count + 2*B
    else:
        count = count + 2*A
print(count)
# Buggy code:
n=int(input())
k=int(input())
x=list(map(int,input().split()))
ans=0
for i in x:
    ans+=min(abs(x-k),abs(x))*2
print(ans)

# Fixed code:
n = int(input())
k = int(input())
x = list(map(int, input().split()))
ans = 0
for i in x:
  ans += 2*min(i,abs(i-k))
print(ans)
# Buggy code:
n=int(input())
k=int(input())
ans=0
for i in list(map(int,input().split())):
    if 2*i<k:ans+=2*i
    else:ans+=k
print(ans)

# Fixed code:
n=int(input())
k=int(input())
ans=0
for i in list(map(int,input().split())):
    if 2*i<k:ans+=2*i
    else:ans+=2*(k-i)
print(ans)
# Buggy code:
N = int(input())
K = int(input())
X = list(map(int, input().split()))

sum_len = 0
for i in range(len(X)):
    if abs(N-X[i]) < abs(K-X[i]):
        sum_len += abs(N-X[i]) * 2
    else:
        sum_len += abs(K-X[i]) * 2

print(sum_len)

# Fixed code:
N = int(input())
K = int(input())
X = list(map(int, input().split()))

sum_len = 0
for i in range(len(X)):
    if X[i] < abs(K-X[i]):
        sum_len += X[i] * 2
    else:
        sum_len += abs(K-X[i]) * 2

print(sum_len)
# Buggy code:
N = int(input())
K = int(input())
x = list(map(int, input().split()))

sum = 0

for i in range(N):
  if x[i] >= K - x[i]:
    sum += K - x[i]
  
  else:
    sum += x[i]

print(sum)

# Fixed code:
N = int(input())
K = int(input())
x = list(map(int, input().split()))

sum = 0

for i in range(N):
  if x[i] >= K - x[i]:
    sum += 2 * (K - x[i])
  
  else:
    sum += 2 * x[i]

print(sum)
# Buggy code:
#74b
n = int(input())
k = int(input())
x = list(map(int,input().split()))
ans=0

for i in range(n):
    ans+=min(2*x[i],2*k-x[i])

print(ans)

# Fixed code:
#74b
n = int(input())
k = int(input())
x = list(map(int,input().split()))
ans=0
for i in range(n):
    ans+=min(2*x[i],2*(k-x[i]))
print(ans)
# Buggy code:
_,k=int(input()),int(input())
print(sum([min([i,k-i])for i in list(map(int,input().split()))]))


# Fixed code:
_,k=int(input()),int(input())
print(sum([min([i,k-i])*2 for i in list(map(int,input().split()))]))
# Buggy code:
N = int(input())
K = int(input())
a = list(map(int, input().split()))
sum_a = 0

for i in range(N):
    A = a[i]
    B = K-a[i]
    sum_a += min(A,B)
    
    
print(sum_a)

# Fixed code:
N = int(input())
K = int(input())
a = list(map(int, input().split()))
sum_a = 0

for i in range(N):
    A = 2*a[i]
    B = 2*(K-a[i])
    sum_a += min(A,B)
    
    
print(sum_a)
# Buggy code:
N=int(input())
K=int(input())
c=list(map(int, input().split()))
l=[K]*N
sub=[]
res=[]
for i in range(0, N):
	sub.append(l[i]-c[i])
	if (sub[i]<=c[i]):
		res.append(2*sub[i])
	else:
		res.append(2*c[i])

# Fixed code:
N=int(input())
K=int(input())
c=list(map(int, input().split()))
l=[K]*N
sub=[]
res=[]
for i in range(0, N):
	sub.append(l[i]-c[i])
	if (sub[i]<=c[i]):
		res.append(2*sub[i])
	else:
		res.append(2*c[i])
print(sum(res))
# Buggy code:
NUM = int(input())
K = int(input())
POS = list(map(int, input().split()))
a = 0
b = 0
sum = 0
for i in POS:
    a = pow(i, 2)
    b = pow(abs((i - K)), 2)
    sum += min(a, b)
print(sum)



# Fixed code:
NUM = int(input())
K = int(input())
POS = list(map(int, input().split()))
sum = 0
for i in POS:
    a = i * 2
    b = abs(i - K) * 2
    sum += min(a, b)
print(sum)
# Buggy code:
# -*- coding: utf-8 -*-

n = int(input())
k = int(input())
x = list(map(int, input().split())) #x[0->(n-1)]

sum = 0

for i in x:
    if i > k - i:
        sum = sum + i
    else:
        sum = sum + k - i

print(sum)

# Fixed code:
# -*- coding: utf-8 -*-

n = int(input())
k = int(input())
x = list(map(int, input().split())) #x[0->(n-1)]

sum = 0

for i in x:
    if i < k - i:
        sum = sum + i
    else:
        sum = sum + k - i

print(sum*2)
# Buggy code:
N = int(input())
K = int(input())
x = list(map(int,input().split()))
L = 0
for i in range(N):
  if K - x[i] <= x[i]:
    L = L + x[i]
  else:
    L = K -x[i]
print (2 * L)

# Fixed code:
N = int(input())
K = int(input())
x = list(map(int,input().split()))
L = 0
for i in range(N):
  if K - x[i] >= x[i]:
    L += x[i]
  else:
    L += K -x[i]
print (2 * L)
# Buggy code:
N=int(input())
K=int(input()) 
S=list(map(int, input().split()))
total=0
for i in range(A):
    if abs(S[i]-K)<S[i]:
        total+=abs(S[i]-K)*2
    else:
        total+=2*S[i]

# Fixed code:
N=int(input())
K=int(input()) 
S=list(map(int, input().split()))
total=0
for i in range(N):
    if abs(S[i]-K)<S[i]:
        total+=abs(S[i]-K)*2
    else:
        total+=2*S[i]
print(total)
# Buggy code:
from sys import stdin
N = int(stdin.readline().rstrip())
K = int(stdin.readline().rstrip())
X = [int(_) for _ in stdin.readline().rstrip().split()]
ans = 0
for i in x:
    if i < K - i:
        ans += 2 * i
    else:
        ans += 2 * (K - i)
print(route)

# Fixed code:
from sys import stdin
N = int(stdin.readline().rstrip())
K = int(stdin.readline().rstrip())
X = [int(_) for _ in stdin.readline().rstrip().split()]
ans = 0
for i in X:
    if i < K - i:
        ans += 2 * i
    else:
        ans += 2 * (K - i)
print(ans)
# Buggy code:
N = int(input())
K = int(input())
X = [int(x) for x in input().split()]

ans = 0
for x in X:
    ans += min(x, abs(x-K))
print(ans)

# Fixed code:
N = int(input())
K = int(input())
X = [int(x) for x in input().split()]

ans = 0
for x in X:
    ans += min(x, abs(x-K))
ans *= 2
print(ans)
# Buggy code:
N = int(input())
K = int(input())
X = list(map(int, input().split()))
Z = 0
for i in range(N):
  Z += max(X[i]*2, abs(K-X[i])*2)
print(Z)

# Fixed code:
N = int(input())
K = int(input())
X = list(map(int, input().split()))
Z = 0
for i in range(N):
  Z += min(X[i]*2, abs(K-X[i])*2)
print(Z)
# Buggy code:
n=int(input())
k=int(input())
a=list(map(int,input().split()))
ans = 0
for i in a:
    ans+=min(a*2,abs(k-a)*2)
print(ans)

# Fixed code:
n=int(input())
k=int(input())
a=list(map(int,input().split()))
ans = 0
for i in a:
    ans+=min(i*2,abs(k-i)*2)
print(ans)