Harryxun/stf_run huggingface dataset:
import numpy as np
N, X, Y = map(int, input().split())
dist = [0] * (N + 1)
cnt = [0] * (N + 1)

INF = 10**10 + 9

# d = [[INF] * N for _ in range(N)]
d = []
for i in range(N)
    
d = [j - i for i in range(N) for j in range(i, N)]
d = []
for i in range(N):
    tmp = [j - i for j in range(i, N)]
    d.append(tmp)
# d[i][j] = j - i
# d[j][i] = j - i
print('d', d)
exit()
d[X - 1][Y - 1] = 1
d[Y - 1][X - 1] = 1


def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d


d = warshall_floyd(d)
count = np.bincount(np.array(d).flatten(), minlength=N)
count = count[1:] // 2
print(*count, sep='\n')


### FIXED CODE ###

N, X, Y = map(int, input().split())


def f(i, j):
    v1 = j - i
    v2 = abs(X - i) + 1 + abs(j - Y)
    v3 = abs(Y - i) + 1 + abs(j - X)
    return min(v1, v2, v3)


D = [0] * N
for i in range(1, N):
    for j in range(i + 1, N + 1):
        d = f(i, j)
        D[d] += 1

for d in D[1:]:
    print(d)
a=input().split(' ')
X=int(a[0])
N=int(a[1])

if N!=0:
  Ls=input().split(' ')
  L=[]
  for i in range(N):
    L.append(int(Ls[i]))
  for i in range (N):
    if X-i in L and X+i in L:
      pass
    elif X-i not in L:
      s=X-i
      break
    elif X-i in L and X+i not in L:
      s=X+i
      break
else:
  s=X


print(s)

### FIXED CODE ###

a=input().split(' ')
X=int(a[0])
N=int(a[1])

if N!=0:
  Ls=input().split(' ')
  L=[]
  for i in range(N):
    L.append(int(Ls[i]))
  for i in range (N+1):
    if X-i in L and X+i in L:
      pass
    elif X-i not in L:
      s=X-i
      break
    elif X-i in L and X+i not in L:
      s=X+i
      break
else:
  s=X


print(s)
s=input()

x='10'
y='01'

def hoge(s):
    if x in s or y in s:
        for i in range(len(s)-1):
            if s[i]+s[i+1]==x or s[i]+s[i+1]==y:
                s=s[:i]+s[i+2:]
                
                return hoge(s)+2
    else:
        return 0

print(hoge(s))

### FIXED CODE ###

s=input()

x=s.count('1')
y=s.count('0')

a=max(x,y)
b=min(x,y)

print(len(s)-(a-b))
a, b = map(int, input().split())
num = -1

for i in range(100000):
    if a == math.floor(i*0.08):
        if b == math.floor(i*0.1):
            num = i
            break
print(num)

### FIXED CODE ###

a, b = map(int, input().split())
import math
num = -1

for i in range(100000):
    if a == math.floor(i*0.08):
        if b == math.floor(i*0.1):
            num = i
            break
print(int(num))
n,a,b = map(int,input().split())
t = 1
ans = 0
while t <=n:
  a = str(t)
  b = list(map(int,a))
  s = sum(b)
  if a <= s <= b:
    ans += s
print(ans)

### FIXED CODE ###

n,a,b = map(int,input().split())
t = 1
ans = 0
while t <=n:
  s = sum(list(map(int, str(t))))
  if a <= s <= b:
    ans += t
  t += 1
print(ans)
N=[for x in input()]
if '9' in N:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

N=[x for x in input()]
if '9' in N:
  print('Yes')
else:
  print('No')
n = int(input())
a = [input()) for i in range(n)]

c0, c1, c2, c3 = 0, 0, 0, 0

for output in a:
    if output == 'AC':
        c0 += 1
    elif output == 'WA':
        c1 += 1
    elif output == 'TLE':
        c2 += 1
    elif output == 'RE':
        c3 += 1
        
        
print('AC x {}'.format(c0))
print('WA x {}'.format(c1))
print('TLE x {}'.format(c2))
print('RE x {}'.format(c3))

### FIXED CODE ###

n = int(input())
a = [input() for i in range(n)]

c0, c1, c2, c3 = 0, 0, 0, 0

for output in a:
    if output == 'AC':
        c0 += 1
    elif output == 'WA':
        c1 += 1
    elif output == 'TLE':
        c2 += 1
    elif output == 'RE':
        c3 += 1
        
        
print('AC x {}'.format(c0))
print('WA x {}'.format(c1))
print('TLE x {}'.format(c2))
print('RE x {}'.format(c3))
N = int(input())
L = list(map(int, input().split()))
 
L_sorted= L.sort()
 
target_num = N/2
if L_sorted[target_num-1] = L_sorted[target_num]:
	print(0)
else:
  	print(L_sorted[target_num]-L_sorted[target_num-1]-1)


### FIXED CODE ###

n=int(input())
l=list(map(int,input().split()))

l.sort()
print(l[int(n/2)]-l[int(n/2)-1])
s = list(input())

ans = ''
for x in s:
    if x == '1' or x == '0':
        ans += x
    elif ans:
        ans[-1].remove
print(ans)

### FIXED CODE ###

s = input()

ans = ''
for i in s:
    if i != 'B':
        ans += i
    else:
        ans = ans[:-1]
print(ans)
a=[]
b=1000
n,t=map(int,input().split(" "))
for _ in range(n):
    a.append(tuple(map(int,input().split(" "))))
for i in range(n):
    if t>=a[i][1]:
        if b>a[i][0]:
            b=a[i][0]
if b !=1000:
    print(b)
if b==1000
    print("TLE")

### FIXED CODE ###

a=[]
b=1001
n,t=map(int,input().split(" "))
for _ in range(n):
    a.append(tuple(map(int,input().split(" "))))
for i in range(n):
    if t>=a[i][1]:
        if b>a[i][0]:
            b=a[i][0]
if b !=1001:
    print(b)
else:
    print("TLE")
import collections

S = input()
N = len(S)
l = []
for i in range(N):
    l.append(int(''.join(S[i:N]))%2019)

c = collections.Counter(l)

values, counts = zip(*c.most_common())
counts = list(counts)

try:
    ans = counts.pop(list(values).index(0))
except:
    ans = 0

for i in range(len(counts)):
    if counts[i] != 1:
        ans += counts[i] * (counts[i]-1) // 2

print(ans)




### FIXED CODE ###

S, W = map(int, input().split())

if W >= S:
    print('unsafe')
else:
    print('safe')
N = int(input())
A = list(map(int,input().split()))

if i in A:
    num = 1
    c = len(A)
    while(len(A) > num):
        if A[num-1] == num:
            num += 1
        else:
            del A[num-1]
    print(c - len(A))
else:
    print(-1)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))

if 1 in A:
    num = 1
    c = 0
    d = len(A)
    for i in range(N):
        if A[i] == num:
            num += 1
            c += 1 
    print(d - c)
else:
    print(-1)
a,b = map(int,input().sprit())
if a < 10 and b< 10:
  print(a*b)
else:
  print(-1)

### FIXED CODE ###

from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue
from heapq import heappop, heappush
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

a,b = inpl()
if a < 10 and b < 10:
    print(a*b)
else:
    print(-1)
import fractions
N = int(input())
A = list(map(int, input().split()))
A.sort()

ans = 0
counter = 0
for i in range(N):
  ans += abs(A[i])
  if(A[i] < 0):
    counter = counter + 1
    
if(counter%2 == 1):
  if(abs(A[counter - 1]) >= A[counter]):
    ans -= A[counter]*2
  else:
    ans -= A[counter-1]*2
  
print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
Amin = 10**9
ans = 0
counter = 0
for i in range(N):
  if(A[i] < 0):
    counter = counter + 1
  a = abs(A[i])
  ans += a
  Amin = min(a, Amin)
    
if(counter%2 == 1):
    ans -= 2*Amin
  
print(ans)
n,m=map(int,input().split())
X=list(map(int,input().split()))

if m==1 :
    print(0)
    exit()

X.sort()
D=[]
for i in range(1,m):
    D.append(X[i]-X[i-1])

D.sort(reverse=True)
d=0
for i in range(n-1):
    d += D[i]    

ans = sum(D)-d
print(ans)


### FIXED CODE ###

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

if m==1 :
    print(0)
    exit()

X.sort()
D=[]
for i in range(1,m):
    D.append(X[i]-X[i-1])

D.sort(reverse=True)
d=0
if i>1:
    for i in range(min(n-1,m-1)):
        d += D[i]    

ans = sum(D)-d
print(ans)
# -*- coding: utf-8 -*-
import numpy as np
from copy import deepcopy
s = input()
cnt = 0
mod_13_cnt = np.array([0]*13)
hatena = [0,1,2,3,4,5,6,7,8,9]
#定数部分を評価
s_teisu = int(s.replace("?","0")) %13
mod_13_cnt[s_teisu]+=1
fn = lambda x : x %(10**9+7)
for i,s_i in enumerate(s[::-1]):
     mod_13_cnt = np.array(list(map(fn,mod_13_cnt)))
     ph = np.array([0]*13)
     if s_i!="?":
         continue
     for j in hatena:
         add_v = j*10**i%13
         ph += np.roll(mod_13_cnt,add_v)
     mod_13_cnt = ph
print(mod_13_cnt[5]%(10**9+7))

### FIXED CODE ###

# -*- coding: utf-8 -*-
s = input()
s = s[::-1]
MOD = 10**9+7
mod13_map = [[i for i in range(13)]]
ma = mod13_map.append
for i in range(1,10**5):
    next_digit = list(map(lambda x:x*10%13,mod13_map[i-1]))
    ma(next_digit)

ret = [1] + [0] * 12 #13で割ってi余る数の合計
for i,v in enumerate(s):
    if v!="?":
        #mod13_map[i][v]だけ、右にシフト
        ret *= 2
        sft = mod13_map[i][int(v)]
        ret = ret[13-sft:26-sft]
    else:
        temp_ret = [0] * 13
        for j in range(10):
            #?がjの場合
            for k,l in enumerate(ret):
                temp_ret[(k+mod13_map[i][j])%13]+=l
        temp_ret = list(map(lambda x:x%MOD,temp_ret))
        ret = temp_ret
print(ret[5]%MOD)
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# N**2の解法
N, M, Q = lr()
graph = np.array([[0] * (N+1) for _ in range(N+1)])  # 1-indexed
for i in range(M):
    l, r = lr()
    graph[l][r] += 1

for i in range(M):
    graph[i] = graph[i].cumsum()

graph = np.cumsum(graph, axis=0)
for _ in range(Q):
    p, q = lr()
    answer = graph[q][q] - graph[q][p-1] - graph[p-1][q] + graph[p-1][p-1]
    print(answer)

# 30

### FIXED CODE ###

import numpy as np

N, M, Q = map(int, input().split())
data = [[0] * (N+1) for _ in range(N+1)]

for i in range(M):
    l, r = map(int, input().split())
    data[l][r] += 1

data = np.array(data)
np.cumsum(data, axis=0, out=data)
np.cumsum(data, axis=1, out=data)
data = data.tolist()
#print(data)
for i in range(Q):
    p, q = map(int, input().split())
    p -= 1
    x = data[q][q]
    x -= data[p][q] + data[q][p]
    x += data[p][p]
    print(x)
n = int(input())
a = map(int,input().split())
f = {}
count = 0
for i in a:
  count=+1
  f[count] = i
inv_map = {v: k for k, v in f.items()}
print inv_map[i] for i in range(n)
  

### FIXED CODE ###

n = int(input())
a = map(int,input().split())
f = {}
count = 1
for i in a:
  f[count] = i
  count+=1
inv_map = {v: k for k, v in f.items()}
[print(inv_map[i],end=' ') for i in range(1,n+1)]
s = np.array(list(input()))
t = np.array(list(input()))
num = 0
for i in set(t):
  if np.sum(s==i) == np.sum(t==i):
    num += 1
    continue
  if len(set(s[t==i])) == 1:
    num += 1
    continue
if num == len(set(t)):
  print("Yes")
else:
  print("No")

### FIXED CODE ###

from collections import Counter
s = input()
t = input()

sc = Counter(s)
tc = Counter(t)

if sorted(sc.values()) == sorted(tc.values()):
  print("Yes")
else:
  print("No")
from bisect import bisect_right
from sys import setrecursionlimit

setrecursionlimit(10**8)
n = int(input())
A = list(map(int, input().split()))
gr = []
for i in range(n):
    gr.append([])
for i in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    gr[a].append(b)
    gr[b].append(a)
ans = [0] * n
dp = [10 ** 10 for i in range(n)]
dp[0] = -10 ** 10
kek = 1
used = {0}


def dfs(v):
    global kek
    j = bisect_right(dp, A[v] - 1)
    old = -1
    if dp[j - 1] < A[v] < dp[j]:
        old = dp[j]
        dp[j] = A[v]
        if kek == j:
            for h in range(kek + 1, n + 1):
                if dp[h] == 10 ** 10:
                    kek = h
                    break
    ans[v] = kek - 1
    for u in gr[v]:
        if u not in used:
            used.add(u)
            dfs(u)
    dp[j] = old
    if kek > j and old == 10 ** 10:
        kek = j


dfs(0)
print(*ans)

### FIXED CODE ###

from bisect import bisect_right
from sys import setrecursionlimit

setrecursionlimit(10**8)
n = int(input())
A = list(map(int, input().split()))
gr = []
for i in range(n):
    gr.append([])
for i in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    gr[a].append(b)
    gr[b].append(a)
ans = [0] * n
dp = [10 ** 10 for i in range(1 + n)]
dp[0] = -10 ** 10
kek = 1
used = {0}


def dfs(v):
    global kek
    j = bisect_right(dp, A[v] - 1)
    old = dp[j]
    if dp[j - 1] < A[v] < dp[j]:
        old = dp[j]
        dp[j] = A[v]
        if kek == j:
            for h in range(kek + 1, 1 + n):
                if dp[h] == 10 ** 10:
                    kek = h
                    break
            if kek == j:
                kek = n + 1
    ans[v] = kek - 1
    for u in gr[v]:
        if u not in used:
            used.add(u)
            dfs(u)
    dp[j] = old
    if kek > j and old == 10 ** 10:
        kek = j


dfs(0)
print(*ans)
n=int(input())

for i in range(1,3501):
    for j in range(1,3501):
        if n*i*j%(4*i*j-n*i-n*j)==0:
            w=int(n*i*j/(4*i*j-n*i-n*j))
            print(i,j,w)
            break
        else:
            continue

### FIXED CODE ###

n=int(input())

for i in range(1,3501):
    for j in range(i,3501):
        if (4*i*j-n*i-n*j)>0 and n*i*j%(4*i*j-n*i-n*j)==0:
            w=n*i*j//(4*i*j-n*i-n*j)
            print(i,j,w)
            quit()
        else:
            continue
import sys
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
prog=0
a_idx=0
b_idx=0

while a_idx<n:
    if a[a_idx]+prog>k:
        break
    prog+=a[a_idx]
    a_idx+=1

if a_idx==n:
    while b_idx<m:
        if b[b_idx]+prog>k:
            break
        prog+=b[b_idx]
        b_idx+=1

mx=a_idx+b_idx

if mx==n+m:
    print(mx)
    sys.exit()

for i in range(a_idx):
    while b[b_idx]+prog<=k:
        prog+=b[b_idx]
        b_idx+=1
    if a_idx+b_idx>mx:
        mx=a_idx+b_idx
    a_idx-=1
    prog-=a[a_idx]

print(mx)

### FIXED CODE ###

import sys
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
prog=0
a_idx=0
b_idx=0

while a_idx<n:
    if a[a_idx]+prog>k:
        break
    prog+=a[a_idx]
    a_idx+=1

if a_idx==n:
    while b_idx<m:
        if b[b_idx]+prog>k:
            break
        prog+=b[b_idx]
        b_idx+=1

mx=a_idx+b_idx

if mx==n+m:
    print(mx)
    sys.exit()

for i in range(a_idx+1):
    while b_idx<m and b[b_idx]+prog<=k:
        prog+=b[b_idx]
        b_idx+=1
    if a_idx+b_idx>mx:
        mx=a_idx+b_idx
    if b_idx==m:
        break
    if a_idx==0:
        break
    a_idx-=1
    prog-=a[a_idx]

print(mx)
S = str(input())
Q = int(input())
querry = [list(map(str, input().split())) for i in range(Q)]
for i in range(Q):
    if querry[i][0] == '1':
        S = S[::-1]
        A_S = A_S[::-1]
        S_A = S_A[::-1]
    elif querry[i][0] == '2':
        if querry[i][1] == '1':
            A_S += querry[i][2] 
        elif querry[i][1] == '2':
            S_A += querry[i][2]

print(A_S + S + S_A)

### FIXED CODE ###

from collections import deque
S = deque(input())
Q = int(input())
querry = [list(map(str, input().split())) for i in range(Q)]
reverse = False
for i in range(Q):
    if querry[i][0] == '1':
        reverse = not reverse
    elif querry[i][0] == '2':
        if querry[i][1] == '1':
            if reverse:
                S.append(querry[i][2])
            else:
                S.appendleft(querry[i][2])
        elif querry[i][1] == '2':
            if reverse:
                S.appendleft(querry[i][2])
            else:
                S.append(querry[i][2])

ans=list(S)

if reverse:
    print("".join(reversed(ans)))
else:
    print("".join(ans))
S = input()

if S == ABC:
    print('ARC')
else:
    print('ABC')

### FIXED CODE ###

s = input()
print('ARC' if s == 'ABC' else 'ABC')
n=input().split()
m=int(n[0])
c=int(n[1])
d=int(n[2])
n.sort()
print(m[0],c[1],d[2])


### FIXED CODE ###

n=list(map(int, input().split()))
n.sort()
print(n[0],n[1],n[2])
N,M=map(int, input().split())
A=list(map(int, input().split()))
inf = float('inf')

number = [6,2,5,5,4,5,6,3,7,6]


dp = [-1*inf]*(N+1)
dp[0] = 0
for i in range(1,N+1):
  dp_new = 0
  for j in A:
    if i - number[j] >= 0:
      if dp[i-number[j]] +1 > dp_new:
        dp[i] = dp[i-number[j]] +1
        dp_new = dp[i]

A.sort(reverse=True)
ans = ""
while N > 0:
  for j in A:
    if dp[N] == dp[N-number[j]] + 1:
      ans += str(j)
      N -= number[j]
      break

print(int(ans))

### FIXED CODE ###

N,M=map(int, input().split())
A=list(map(int, input().split()))
inf = float('inf')

number = [6,2,5,5,4,5,6,3,7,6]


dp = [-1*inf]*(N+1)
dp[0] = 0
for i in range(1,N+1):
  dp_new = 0
  for j in A:
    if i - number[j] >= 0:
      if dp[i-number[j]] +1 > dp_new:
        dp[i] = dp[i-number[j]] +1
        dp_new = dp[i]

A.sort(reverse=True)
ans = ""
while N > 0:
  for j in A:
    if N - number[j] >= 0:
      if dp[N] == dp[N-number[j]] + 1:
        ans += str(j)
        N -= number[j]
        break

print(int(ans))
n = int(input())
p = input().split(" ")
a = 0
for i in range(len(n)):
    pf = p[i]
    ps = p[i+1]
    pt = p[i+2]
    il = [int(pf),int(ps),int(pt)]
    max_p = max(il)
    il.remove(max_p)
    if int(ps) = max(il):
        a += 1
print(a)

### FIXED CODE ###

n = int(input())
p = input().split(" ")
a = 0
for i in range(len(p)):
    try:
        pf = p[i]
        ps = p[i+1]
        pt = p[i+2]
        il = [int(pf),int(ps),int(pt)]
        max_p = max(il)
        il.remove(max_p)
        if int(ps) == max(il):
            a += 1
    except:
        pass
print(a)
N = input()
sum = 0
for i in N:
  x,u = stdin.readline().rstrip().split()
  if u == 'JPY':
    sum += int(x)
  else:
  	sum += float(x)*38000
print(sum)

### FIXED CODE ###

N = int(input())
sum = 0
for i in range (N):
  X = input().split()
  if X[1] == 'JPY':
    sum += float(X[0])
  else:
  	sum += float(X[0])*380000
print(sum)
import math
val = int(input())
res = 0
current = 1
while True:
    rest = val - current
    plus = math.floor(rest / current)
        
    if math.floor(val / plus) == val % plus:
        res += plus
    if current * current + current >= val:
        break
    current += 1
print(str(res))

### FIXED CODE ###

import math
val = int(input())
res = 0
current = 1
while True:
    rest = val - current
    plus = math.floor(rest / current)
    if plus == 0:
        break

    if math.floor(val / plus) == val % plus:
        res += plus
    if current * current + current >= val:
        break
    current += 1
print(str(res))
import math
n = int(input())
k = int(input())

i = 1

while i <= k:
  print(int(math.factorial(n-k+i)/(math.factorial(n-k))*(math.factorial(i))))
  i += 1
  
  

### FIXED CODE ###

import math
 
def combination_count(n,k):
    if k > n or k < 0:
        return 0
    if n == 0 or k == 0:
        return 1
    
    s = math.factorial(n)
    t = math.factorial(k)
    u = math.factorial(n-k)
    
    return s//(t*u)
    
n,k = map(int,input().split())
 
mod = 10**9 + 7
 
for i in range(1,k+1):
    x = combination_count(n-k+1,i) * combination_count(k-1, i-1)
    print(x%mod)
str = input()
n = len(str)

ls = []

for i in range(n):
  ls.append(str[i])


for i in range(len(ls)):
  if (ls[i] == ls[i+1]) or (len(ls) == 1):
    break
  if (ls[i] == 0 and ls[i + 1] == 1) or (ls[i] == 1 and ls[i + 1] == 0):
    del ls[i]
    del ls[i]

nokori = len(ls)
print(n - nokori)
  


### FIXED CODE ###

str = input()

count1 = str.count('1')
count0 = str.count('0')
print(2 * min(count1, count0))
# C - Welcome to AtCoder
# https://atcoder.jp/contests/abc151/tasks/abc151_c

n,m = map(int,input().split())
submits = [list(input().split()) for i in range(0,m)]

ac = 0
wa = 0

AC = "AC"
WA = "WA"

tmp_wa = 0
tmp_ac = 0


for i in range(len(submits)):
    # ACなら正解数をカウントアップ
    if submits[i][1] == AC:
        # 同じ問題に正解してないかチェック
        if submits[i][0] == tmp_ac:
            continue
        ac += 1
        # WAの数をカウント
        wa += tmp_wa
        # WAを初期化
        tmp_wa = 0
        tmp_ac = submits[i][0]
    else:
        # WAならwa+1
        tmp_wa += 1

print(f"{ac} {wa}")

### FIXED CODE ###

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

ac = [False] * N
wa = [0] * N
for _ in range(M):
    p, S = input().split()
    p = int(p) - 1
    if S == 'AC':
        ac[p] = True
    else:
        if not ac[p]:
            wa[p] += 1

a = 0
b = 0
for i in range(N):
    if ac[i]:
        a += 1
        b += wa[i]
print(*[a, b])
s = list(int,input().split())
s[3] = 8
print(s)

### FIXED CODE ###

s = input()
print(s[:3]+'8'+s[4:])
h,w = map(int,input().split())

for _ in range(h):
  	c = input()
    print(c)
    print(c)
    


### FIXED CODE ###

H, W = map(int, input().split())
for _ in range(H):
    s = input()
    print(s)
    print(s)
N,K,X,Y=[input() for _ in range(4)];print(K*X+max(N-K,0)*Y)

### FIXED CODE ###

N,K,X,Y=[int(input()) for _ in range(4)];print(min(N,K)*X+max(N-K,0)*Y)
def check(x, y, flag):
	farm[x][y] = "$"
	if farm[x + 1][y] == flag : check(x + 1, y, flag)
	if farm[x - 1][y] == flag : check(x - 1, y, flag)
	if farm[x][y + 1] == flag : check(x, y + 1, flag)
	if farm[x][y - 1] == flag : check(x, y - 1, flag)
	return 1

while True:
	h,w = map(int, raw_input().split())
	if h == 0 and w == 0 : break

	farm = []
	farm.append(list("$" * (w + 2)))
	for i in range(0, h):
		farm.append(list("$" + raw_input() + "$"))
	farm.append(list("$" * (w + 2)))
	
	count = 0
	for i in range(0, h):
		for j in range(0, w):
			if farm[i + 1][j + 1] != "$":
				count += check(i + 1, j + 1, farm[i + 1][j + 1])
				
	print count

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)

def check(x, y, flag):
	farm[x][y] = "$"
	if farm[x + 1][y] == flag : check(x + 1, y, flag)
	if farm[x - 1][y] == flag : check(x - 1, y, flag)
	if farm[x][y + 1] == flag : check(x, y + 1, flag)
	if farm[x][y - 1] == flag : check(x, y - 1, flag)
	return 1

while True:
	h,w = map(int, raw_input().split())
	if h == 0 and w == 0 : break

	farm = []
	farm.append(list("$" * (w + 2)))
	for i in range(0, h):
		farm.append(list("$" + raw_input() + "$"))
	farm.append(list("$" * (w + 2)))
	
	count = 0
	for i in range(0, h):
		for j in range(0, w):
			if farm[i + 1][j + 1] != "$":
				count += check(i + 1, j + 1, farm[i + 1][j + 1])
				
	print count
n,m=(int(x) for x in input().split())
k=m+1
s=[0]*k
c=[0]*k
answer=0
for i in range(m):
    s[i+1],c[i+1]=(int(x) for x in input().split())


a=[-1]*10

for i in range(m):
    if a[s[i+1]]==-1:
        a[s[i+1]]=c[i+1]
    elif not a[s[i+1]]==c[i+1]:
        answer=-1
if a[1]==0 and not n=1:
    answer=-1
if a[1]==-1 and not n=1:
    a[1]=1
if a[1]==-1 and n=1:
    a[1]=0
for i in range(10):
    if a[i]==-1:
        a[i]=0

if answer==0:
    for i in range(n):
        d=n-i-1
        answer+=10**d*a[i+1]
print(answer)


### FIXED CODE ###

n,m=(int(x) for x in input().split())
k=m+1
s=[0]*k
c=[0]*k
answer=0
for i in range(m):
    s[i+1],c[i+1]=(int(x) for x in input().split())


a=[-1]*10

for i in range(m):
    if a[s[i+1]]==-1:
        a[s[i+1]]=c[i+1]
    elif not a[s[i+1]]==c[i+1]:
        answer=-1
if a[1]==0 and not n==1:
    answer=-1
if a[1]==-1 and not n==1:
    a[1]=1
if a[1]==-1 and n==1:
    a[1]=0
for i in range(10):
    if a[i]==-1:
        a[i]=0

if answer==0:
    for i in range(n):
        d=n-i-1
        answer+=10**d*a[i+1]
print(answer)
a, b = list(map(int, input().split()))

min = b - (a - 1)
max = b + (a - 1)

output = ''
for i in range(min, (max+1)):
  output += f'{i} '

output.rstrip()

print(output)

### FIXED CODE ###

a, b = list(map(int, input().split()))

min = b - (a - 1)
max = b + (a - 1)

output = ''
for i in range(min, (max+1)):
  hoge = str(i) + ' '
  output += hoge

output.rstrip()

print(output)