Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

from itertools import permutations
N, C = map(int, input().split())

D = [None] * C
for i in range(C):
    D[i] = list(map(int, input().split()))

c = [None] * N
for i in range(N):
    c[i] = list(map(int, input().split()))

ans = 10**12

# 塗り分けの順列総数
for p in permutations(range(C),3):
    tmp = 0
    for i in range(N):
        if tmp > ans:
            break
        for j in range(N):
            tmp += D[c[i][j]-1][p[(i+j)%3]]
    ans = min(ans,tmp)

print(ans)

### FIXED CODE ###

from itertools import permutations

N, C = map(int, input().split())

D = [None] * C
for i in range(C):
    D[i] = list(map(int, input().split()))

c = [None] * N
for i in range(N):
    c[i] = list(map(int, input().split()))

# (i+j)%3 = 0,1,2 のそれぞれで初期マスの色をカウント
t = [[0]*C for _ in range(3)]
for i in range(N):
    for j in range(N):
        t[(i+j)%3][c[i][j]-1] += 1

ans = 10**12

# 塗り分けの順列総数
for p in permutations(range(C),3):
    tmp = 0
    for i in range(C):
        tmp += D[i][p[0]] * t[0][i]
        tmp += D[i][p[1]] * t[1][i]
        tmp += D[i][p[2]] * t[2][i]
    ans = min(ans,tmp)

print(ans)
### BUGGY CODE ###

l=[2658,3]
d=[2,4,5]
d_bar=[]
for m in range(10):
    if m not in d:
        d_bar.append(m) 
d_bar.sort()
n=[int(k) for k in str(l[0])]

for i in range(len(n)):
    dig1=0
    dig2=0
    for j in range(l[1]):
        p=dig1+d_bar[j]*10**(l[0]-i)
        if p>l[0]:
            break
        dig1=p
        dig2=dig2+d_bar[j]*l[1]**(l[0]-i)
dig2=dig2+1
r=dig1
q=dig1
R=[]
while q!=0 or q!=1:
    q=q/l[1]
    r=q%l[1]
    R.insert(0,r)
s=0
for t in range(len(R)):
    s=s+R[t]*10**(t)
print(s)




### FIXED CODE ###

l=list(map(int,input().split()))
d=list(map(int,input().split()))
u={i for i in range(10)}
d_bar=u-set(d)
d_bar={str(i) for i in d_bar}
n=l[0]
n_set=set(str(n))
while True:
    if n_set<=d_bar:
        print(n)
        break
    n=n+1
    n_set=set(str(n))
### BUGGY CODE ###

def examA():
    H1, M1, H2, M2, K = LI()
    T = (H2-H1)*60 + (M2-M1)
    ans = T-K
    print(ans)
    return

def examB():
    T = SI()
    ans = ""
    for t in T:
        if t=="?":
            ans += "D"
        else:
            ans += t
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examB()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

### FIXED CODE ###

def examA():
    H1, M1, H2, M2, K = LI()
    T = (H2-H1)*60 + (M2-M1)
    ans = T-K
    print(ans)
    return

def examB():
    T = SI()
    ans = ""
    for t in T:
        if t=="?":
            ans += "D"
        else:
            ans += t
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examB()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""
### BUGGY CODE ###

n = int(input())
value = list(map(int, input().split()))
cost = list(map(int, input().split()))
tmp = 0
for p in range(2**n):
    profit = 0
    for j in range(n):
        if((p >> j) & 1):
            profit += (value[j] - cost[j])
    if profit > tmp:
        tmp = profit
print(tmp)

### FIXED CODE ###

n = int(input())
value = list(map(int, input().split()))
cost = list(map(int, input().split()))
tmp = 0

for i in range(len(value)):
    profit = value[i] - cost[i]
    if profit > 0:
        tmp += profit

print(tmp)
### BUGGY CODE ###

# -*- coding: utf-8 -*-


k, s = map(int, input().split())

ans = 0

if s == 3*k:
    ans = 1
elif s > 3*k:
    ans = 0
else:
    l = k
    while l >= 0:
        t_sum = s - l
        m = k
        if t_sum > 2*k:
            break
        if m < k:
            m = k
        while m >= 0:
            n = s - l - m
            if n > k:
                n = k
            if l + m + n < s:
                break
            while n >= 0:
                if l + m + n == s:
                    ans += 1
                if l + m + n < s:
                    break

                n -=1
            m -= 1
        l -= 1

print(ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Mon Aug  3 13:34:09 2020

@author: ito
"""


# -*- coding: utf-8 -*-

k, s = map(int, input().split())

ans = 0

for x in range(k+1):
    for y in range(k+1):
        
        sat_z = s - x - y
        
        if sat_z >= 0 and sat_z <= k:
            ans += 1
            
print(ans)
### BUGGY CODE ###

from time import time
import random


def main():
    random.seed(0)

    now = time()

    MAX = 26

    # 入力
    d = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for _ in range(d)]

    # 初期解を貪欲法で求める
    t = []
    prev = [0] * MAX
    for day, row in enumerate(s, 1):
        mxi = 1
        mx = 0
        for i, (es, ec) in enumerate(zip(row, c), 1):
            point = es + ec * (day - prev[i - 1])
            if point > mx:
                mx = point
                mxi = i

        prev[mxi - 1] = day
        t.append(mxi)

    # 初期解に対する満足度を計算
    last = [0] * MAX
    score = 0
    for day, e in enumerate(t, 1):
        score += s[day-1][e-1]
        last[e-1] = day

        for ec, elast in zip(c, last):
            score -= ec * (day - elast)

    # 変更を検討する日にちの選ばれやすさ
    d_li = []
    for i in range(1, d + 1):
        ln = max(1, (-(i - d // 2) ** 2 + d ** 2 // 4) // 500)
        d_li += [i] * ln

    d_li = list(range(1, d + 1))
    di_max = len(d_li) - 1

    # 各日にちにおいて変更を検討するコンテストの選ばれやすさ
    sc = []
    for day, row in enumerate(s, 1):
        app = []
        for i, (es, ec) in enumerate(zip(row, c), 1):
            app += [i] * max(1, (es + ec * (d ** 2 // 4 - (day - d // 2) ** 2)) // 20)
        sc.append(app)

    # 時間の許す限り更新を検討する
    while time() - now <= 1.85:
        prev_score = score

        di = random.randint(0, di_max)
        ed = d_li[di]
        qi = random.randint(0, len(sc[ed-1]) - 1)
        eq = sc[ed-1][qi]

        q_old = t[ed-1]
        d_prev = {q_old: 0, eq: 0}

        c_old = c[q_old-1]
        c_new = c[eq-1]

        for day, e in enumerate(t, 1):
            if e in d_prev.keys():
                d_prev[e] = day

            score += c_old * (day - d_prev[q_old])
            score += c_new * (day - d_prev[eq])

        score -= s[ed-1][q_old-1]
        score += s[ed-1][eq-1]

        t[ed-1] = eq

        d_prev = {q_old: 0, eq: 0}

        for day, e in enumerate(t, 1):
            if e in d_prev.keys():
                d_prev[e] = day

            score -= c_old * (day - d_prev[q_old])
            score -= c_new * (day - d_prev[eq])

        if prev_score > score:
            t[ed-1] = q_old
            score = prev_score

    print(*t, sep="\n")


if __name__ == "__main__":
    main()


### FIXED CODE ###

for i in range(365):
    print(i % 26 + 1)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
from collections import defaultdict
INF = float("inf")
MOD = 998244353  # type: int


def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % MOD
    elif y % 2 == 0:
        return power(x, y//2)**2 % MOD
    else:
        return power(x, y//2)**2 * x % MOD


def solve(N: int, a: "List[int]"):

    S = sum(a)
    dp = [defaultdict(int) for _ in range(N)]
    dp2 = [defaultdict(int) for _ in range(N)]
    dp[0][0] = 2
    dp[0][a[0]] = 1
    dp2[0][0] = 1
    dp2[0][a[0]] = 1
    for i in range(1, N):     # i+1番目の数字まで使ったとき
        for key in dp[i-1]:
            dp[i][key] += 2*dp[i-1][key]
            dp[i][key] %= MOD
            dp[i][key+a[i]] += dp[i-1][key]
            dp[i][key+a[i]] %= MOD

        for key in dp2[i-1]:
            dp2[i][key] += dp2[i-1][key]
            dp2[i][key] %= MOD
            dp2[i][key+a[i]] += dp2[i-1][key]
            dp2[i][key+a[i]] %= MOD

    ans = power(3, N) - sum([dp[N-1][i] for i in range(-(-S//2), S+1)])*3
    ans %= MOD
    if S % 2 == 0:              #
        ans += 3*dp2[N-1][-(-S//2)]
        ans %= MOD
    print(ans)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
from collections import defaultdict
INF = float("inf")
MOD = 998244353  # type: int


def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % MOD
    elif y % 2 == 0:
        return power(x, y//2)**2 % MOD
    else:
        return power(x, y//2)**2 * x % MOD


def solve(N: int, a: "List[int]"):

    S = sum(a)
    # dp = [defaultdict(int) for _ in range(N)]
    dp = [[0]*(S+1) for _ in range(N)]
    # dp2 = [defaultdict(int) for _ in range(N)]
    dp2 = [[0]*(S+1) for _ in range(N)]
    dp[0][0] = 2
    dp[0][a[0]] = 1
    dp2[0][0] = 1
    dp2[0][a[0]] = 1
    for i in range(1, N):     # i+1番目の数字まで使ったとき
        # for key in dp[i-1]:
        for key in range(S+1):
            dp[i][key] = 2*dp[i-1][key]+dp[i-1][key-a[i]]
            dp[i][key] %= MOD
            dp2[i][key] = dp2[i-1][key] + dp2[i-1][key-a[i]]
            dp2[i][key] %= MOD

    # ans = power(3, N) - sum([dp[N-1][i] for i in range(-(-S//2), S+1)])*3
    ans = power(3, N) - sum(dp[N-1][-(-S//2):])*3
    ans %= MOD
    if S % 2 == 0:              #
        ans += 3*dp2[N-1][-(-S//2)]
        ans %= MOD
    print(ans)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

S = input()

# 下からi桁(1-indexed)まで使ったときの、13で割ったときあまりがjになるパターン
dp = [[0 for _ in range(13)] for _ in range(len(S)+1)]
dp[0][0] = 1

for i, s in enumerate(S[::-1]):
    r_now = [1, 10, 9, 12, 3, 4][i%6]
    if s == "?":
        for d in range(10):
            for r_before, count in enumerate(dp[i]):
                j = (r_now*d+r_before)%13
                dp[i+1][j] = (dp[i+1][j]+count)%(10**9+7)
    else:
        d = int(s)
        for r_before, count in enumerate(dp[i]):
            j = (r_now*d+r_before)%13
            dp[i+1][j] = (dp[i+1][j]+count)%(10**9+7)
    # for dp_i in dp:
    #     print(dp_i)
    # print("")

print(dp[len(S)][5])

### FIXED CODE ###

S = input()

# 下からi桁(1-indexed)まで使ったときの、13で割ったときあまりがjになるパターン
dp = [[0 for _ in range(13)] for _ in range(len(S)+1)]
dp[0][0] = 1

for i, s in enumerate(S[::-1]):
    r_now = [1, 10, 9, 12, 3, 4][i%6]
    if s == "?":
        for d in range(10):
            for r_before, count in enumerate(dp[i]):
                j = (r_now*d+r_before)%13
                dp[i+1][j] = (dp[i+1][j]+count)%(10**9+7)
    else:
        d = int(s)
        for r_before, count in enumerate(dp[i]):
            j = (r_now*d+r_before)%13
            dp[i+1][j] = (dp[i+1][j]+count)%(10**9+7)
    # for dp_i in dp:
    #     print(dp_i)
    # print("")

print(dp[len(S)][5])
### BUGGY CODE ###

N=int(input())
while True:
    if N%2==1:
        print(2*N)
    else:
        N=N//2


### FIXED CODE ###

from fractions import gcd

N=int(input())

print(int(2 * N / gcd(2, N)))
### BUGGY CODE ###

n,x = map(int, input().split())
def burger(x):
    if x==0:
        return 'P'
    else:
        return 'B'+burger(x-1)+'P'+burger(x-1)+'B'
burger = burger(n)
print(burger[:x].count('P'))

### FIXED CODE ###

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

a,p = [1], [1]
for i in range(n):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)

def f(N,X):
    if N==0:
        return 0 if X<=0 else 1
    elif X<=1+a[N-1]:
        return f(N-1,X-1)
    else:
        return p[N-1]+1+f(N-1,X-2-a[N-1])

print(f(n,x))
### BUGGY CODE ###

def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    S = input()
    _ = int(input())
    K = [int(i) for i in input().split()]

    def solve(k):
        cd = 0
        cm = 0
        cdm = 0
        ans = 0
        for i in range(N):
            if S[i] == 'D':
                cd += 1
            elif S[i] == 'M':
                cm += 1
                cdm += cd
            elif S[i] == 'C':
                ans += cdm
            if k - 1 <= i:
                if S[i-k+1] == 'D':
                    cdm -= cm
                    cd -= 1
                if S[i-k+1] == 'M':
                    cm -= 1
        return ans

    for k in K:
        print(solve(k))


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    S = input()
    _ = int(input())
    K = [int(i) for i in input().split()]

    def solve(k):
        cd = 0
        cm = 0
        cdm = 0
        ans = 0
        for i in range(N):
            if S[i] == 'D':
                cd += 1
            elif S[i] == 'M':
                cm += 1
                cdm += cd
            elif S[i] == 'C':
                ans += cdm
            if k - 1 <= i:
                if S[i-k+1] == 'D':
                    cdm -= cm
                    cd -= 1
                if S[i-k+1] == 'M':
                    cm -= 1
        return ans

    for k in K:
        print(solve(k))


if __name__ == '__main__':
    main()
### BUGGY CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, s: "List[str]"):

    count = 0
    for i in range(len(s) - 1):

        s_from = list(s[i])
        s_from.sort()
        # print(s_from)

        for j in range(i + 1, len(s)):

            s_target = list(s[j])
            s_target.sort()
            # print(s_target)

            if s_target == s_from:
                count += 1
            else:
                pass
    print(count)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, s)


if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, s: "List[str]"):

    result = 0
    str_dict = dict()
    for s_i in s:

        s_i = list(s_i)
        s_i.sort()
        s_i = "".join(s_i)

        if s_i in str_dict:
            result += str_dict[s_i]
            str_dict[s_i] += 1
        else:
            str_dict[s_i] = 1

    print(result)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, s)


if __name__ == "__main__":
    main()
### BUGGY CODE ###

import math
 
h = float(input())
enemies = [h]
 
count = 0
while len(enemies) > 0:
  temp = []
  for enemy in enemies:
    count+=1
    if enemy > 1:
      temp.append(math.floor(enemy / 2))
      temp.append(math.floor(enemy / 2))
  enemies = temp

print(count)

### FIXED CODE ###

import math

h = int(input())

count = 0
while h > 1:
  h = math.floor(h/2)
  count += 1

print(2**count*2-1)
### BUGGY CODE ###

from collections import deque

n = int(input())
e = [list(map(int, input().split())) for _ in range(n-1)]
c = [0 for _ in range(n-1)]

cmap = [[0 for _ in range(n)] for _ in range(n)]
for l in e:
    cmap[l[0]-1][l[1]-1] = cmap[l[1]-1][l[0]-1]=-1
    
d = deque()
d.append(1)
while(d):
    ed = d.popleft() -1
    clist = list()
    usedc = set()
    for i in range(n):
        if cmap[ed][i]:
            clist.append([i, cmap[ed][i]])
            usedc.add(cmap[ed][i])
    for color in clist:
        if color[1] == -1:
            d.append(color[0]+1)
            cn = 1
            while(1):
                if cn in usedc:
                    cn+=1
                else:
                    usedc.add(cn)
                    break

            cmap[ed][color[0]] = cmap[color[0]][ed] = cn

for i in range(n-1):
    c[i] = cmap[e[i][0]-1][e[i][1]-1]

print(max(c))
for num in c:
    print(num)




### FIXED CODE ###

from collections import deque
n = int(input())

ls = [list() for _ in range(n)]
ls2 = [list() for _ in range(n)]
edge = []
for i in range(n-1):
    x,y = map(int,input().split())
    ls[x-1].append(i)
    ls2[y-1].append(i)
    edge.append([x-1,y-1])

d = deque()
color = [0]*(n-1)
d.append(0)
while len(d):
    c = d.pop()
    cl = []
    for i in ls2[c]:
        if color[i]:
            cl.append(color[i])
    idx = 1
    for i in ls[c]:
        while(1):
            if not idx in cl:
                break
            else:
                idx += 1
        color[i] = idx
        cl.append(idx)
        d.append(edge[i][1])

print(max(color))
for i in color:
    print(i)
### BUGGY CODE ###

A,B,C,D,E,F = map(int,input().split(" "))
LOOP_A = int(F / (100*A)) + 1
LOOP_B = int(F / (100*B)) + 1
LOOP_C = int(F / C) + 1
LOOP_D = int(F / D) + 1
ans = []
temp = []
for i in range(LOOP_A):
    Ac = i
    for j in range(LOOP_B):
        Bc = j
        if Ac + Bc >= 1:
            for k in range(LOOP_C):
                W = Ac * A * 100 + Bc * B * 100
                Cc = k
                if W + (Cc * C) <= F:
                    for l in range(LOOP_D):
                        Dc = l
                        S = Cc * C + Dc * D
                        total = W + S 
                        SW = S / W
                        if F >= total and SW <= E/100:
                            ans.append(str(total) + " " + str(S))
                            temp.append(S / total)
print(ans[temp.index(max(temp))])

### FIXED CODE ###

A,B,C,D,E,F = map(int,input().split(" "))
LOOP_A = int(F / (100*A)) + 1
LOOP_B = int(F / (100*B)) + 1
LOOP_C = int((F-100) / C) + 1
LOOP_D = int((F-100) / D) + 1
ans = []
temp = []
for i in range(LOOP_A):
    Ac = i
    for j in range(LOOP_B):
        Bc = j
        W = Ac * A * 100 + Bc * B * 100
        if W >= 100 and W <= F:
            for k in range(LOOP_C):
                Cc = k
                if W + (Cc * C) <= F:
                    for l in range(LOOP_D):
                        Dc = l
                        S = Cc * C + Dc * D
                        total = W + S 
                        SW = S / W
                        #print(Dc)
                        if F >= total and SW <= E/100:
                            ans.append(str(total) + " " + str(S))
                            temp.append(S / total)
print(ans[temp.index(max(temp))])
### BUGGY CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,z,w = LI()
    a = LI()
    m = {}
    def f(z,w,i,t):
        k = (z,w,i,t)
        if k in m:
            return m[k]
        if i >= n:
            m[k] = abs(z-w)
            return m[k]
        if t:
            r = -1
            for j in range(i,n):
                jr = f(a[j],w,j+1,False)
                if r < jr:
                    r = jr
            m[k] = r
        else:
            r = inf
            for j in range(i,n):
                jr = f(z,a[j],j+1,True)
                if r > jr:
                    r = jr
            m[k] = r
        return m[k]

    return f(z,w,-1,True)



print(main())




### FIXED CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,z,w = LI()
    a = LI()
    m = {}
    def f(z,w,i,t):
        if i >= n:
            return abs(z-w)
        if t:
            k = (-1,w,i)
            if k in m:
                return m[k]
            r = -1
            for j in range(i,n):
                jr = f(a[j],w,j+1,False)
                if r < jr:
                    r = jr
            m[k] = r
        else:
            k = (z,-1,i)
            if k in m:
                return m[k]
            r = inf
            for j in range(i,n):
                jr = f(z,a[j],j+1,True)
                if r > jr:
                    r = jr
            m[k] = r
        return m[k]

    return f(z,w,-1,True)



print(main())
### BUGGY CODE ###

n = int(input())
count = 0
a =  list(map(int, input().split()))
while len(a) != 0:
    b = 0
    b = a.count(a[0])
    c = 0
    c = a[0]
    if c > b:
        count += b
    if c < b:
        count += b - c
    while a.count(c) != 0:
        a.remove(c)    
print (count)


### FIXED CODE ###

n = int(input())
a = []
a =  list(map(int, input().split()))
d = {}
c = 0
for x in a:
    d[x] = d.get(x, 0) + 1
for y,z in d.items():
    if y < z:
        c += z-y
    if y > z:
        c += z
print(c)