Harryxun/stf_run huggingface dataset:
import math

def main():
  N, K = list(map(int, input().split()))
  A = list(map(int, input().split()))
  
  if K == 0:
    C = 0
  else:
    C = int(math.log2(K + 1))
  
  Lt = [0 for i in range(44)]
  for i in A:
    t = i
    for j in range(len(Lt)):
      if t % 2 == 1:
        t -= 1
        Lt[j] += 1
      if t == 0:
        break
      t /= 2
  
  L = [Lt for i in range(C + 1)]
  
  x = pow(2, C)
  T = [K for i in range(C + 1)]
  for i in range(C, -1, -1):
    for j in range(C + 1):
      if T[j] >= x:
        if j != i and L[j][i] <= N / 2:
          L[j][i] = N - L[j][i]
          T[j] -= x
    x //= 2
  
  Ans = [0 for i in range(C + 1)]
  x = 1
  for i in range(44):
    for j in range(C + 1):
      Ans[j] += L[j][i] * x
    x *= 2
  
  print(max(Ans))
  
main()

### FIXED CODE ###

import math
def main():
  N, K = list(map(int, input().split()))
  A = list(map(int, input().split()))
 
  if K == 0:
    C = 0
  else:
    C = int(math.log2(K + 1))
  L = [[0 for i in range(44)] for j in range(C + 1)]
 
  for i in A:
    for j in range(len(L[0])):
      if i % 2 == 1:
        i -= 1
        L[0][j] += 1
      if i == 0:
        break
      i /= 2
  for i in range(1, C + 1):
    for j in range(44):
      L[i][j] = L[0][j]
 
  x = pow(2, C)
  T = [K for i in range(C + 1)]
  for i in range(C, -1, -1):
    for j in range(C + 1):
      if T[j] >= x:
        if j != i and L[j][i] <= N / 2:
          L[j][i] = N - L[j][i]
          T[j] -= x
    x //= 2
 
  Ans = [0 for i in range(C + 1)]
  x = 1
  for i in range(44):
    for j in range(C + 1):
      Ans[j] += L[j][i] * x
    x *= 2
 
  print(max(Ans))

main()
#!/usr/bin/python

import math
import sys

pi =3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450
2841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881
7488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272
4891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609
1736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185
950244594553469083026425223082

r = int(raw_input())

area = r * r * pi
length = 2 * r * pi

print str(area) + " " + str(length) + "\n"

sys.exit()

### FIXED CODE ###

import math
n = input()
S = '%.6f' % (float(n)**2 * math.pi)
L = '%.6f' % (float(n) * 2 * math.pi)
print "{} {}".format(S,L)
n = int(input())
lis = list(map(int,input().split()))

ans = "Yes"
m = 0
for i in range(n):
	if m - lis[i] > 1:
		ans = "No"
		break
	else:
		m = max(m,lis[i])
print(ans)

### FIXED CODE ###

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

p=[]
q=[]

for i in range(m):
    l,r=map(int,input().split())
    p.append(l)
    q.append(r)

p1=max(p)
q1=min(q)

if q1>=p1:
    print(q1-p1+1)
else:
    print(0)
from collections import defaultdict
from fractions import Fraction

N = int(input())
X = [tuple(map(int, input().split())) for _ in range(N)]

MOD = 1000000007
d_plus = defaultdict(int)  # + or ∞
d_minus = defaultdict(int)  # - or 0
ans = 1

for i, (a, b) in enumerate(X):
    if a == 0 and b == 0:
        continue
    elif a == 0:
        d_minus[0] += 1
    elif b == 0:
        d_plus[float('inf')] += 1
    elif a * b > 0:
        d_plus[Fraction(a, b)] += 1
    else:
        d_minus[Fraction(a, b)] += 1

for m in d_minus:
    d_plus[-1 / m] += 0
for p in d_plus:
    ans = ans * (pow(2, d_plus[p], MOD) + pow(2, d_minus[-1 / p], MOD) - 1)
    ans %= MOD
print((ans - 1) % MOD)


### FIXED CODE ###

from collections import defaultdict
from math import gcd

N = int(input())

MOD = 1000000007
d_plus = defaultdict(int)  # + or ∞
d_minus = defaultdict(int)  # - or 0
ans = 1
ans_00 = 0
for i in range(N):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        ans_00 += 1
    elif a == 0:
        d_minus[0] += 1
    elif b == 0:
        d_plus[float('inf')] += 1
    else:
        g = gcd(a, b)
        if (a > 0) ^ (b > 0):
            d_plus[(abs(a // g), abs(b // g))] += 1
        else:
            d_minus[(abs(a // g), -abs(b // g))] += 1


def pair(p):
    if p == 0:
        return float('inf')
    elif p == float('inf'):
        return 0
    else:
        a, b = -p[1], p[0]
        if a < 0:
            a, b = -a, -b
        return a, b


for m in d_minus:
    d_plus[pair(m)]
for p in d_plus:
    ans *= (pow(2, d_plus[p], MOD) + pow(2, d_minus[pair(p)], MOD) - 1)
    ans %= MOD
print((ans - 1 + ans_00) % MOD)
#coding: utf-8
 
N, K = map(int, input().split())
A = list(map(int, input().split()))
 
if(N==K):
    ans = 1
 
print(ans)

### FIXED CODE ###

#coding: utf-8

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

for i in range(N):
    if(A[i] == 1):
        one = i
        #print('1は',one + 1,'番目')

ans = []

for i in range(K):
    start = one - (K - 1) + i
    end = one + i

    before = start
    after = N - (end+1)

    before_num = before//(K-1)
    if(before%(K-1) != 0):
        before_num += 1

    after_num = after//(K-1)
    if(after%(K-1) != 0):
        after_num += 1

    answer = before_num + after_num + 1
    ans.append(answer)

print(min(ans))
import numpy as np
N = int(input())
ans = np.sum(np.arange(N))
print(ans)


### FIXED CODE ###

N = int(input())
print(N * (N - 1) // 2)
N = int(input())
a = list(map(int, input().split()))
print(N)

### FIXED CODE ###

a, b, c = map(int, input().split())
sums = [a+b,b+c,c+a]
print(min(sums))
def zeroPadding(num):
    return "%06d"%num

class Row:
    def __init__(self, i, pref_id, year):
        self.i = i
        self.pref_id = pref_id
        self.year = year
        self.city_id = -1
        
    def __str__(self):
        return "{i: %d, pref_id: %d, year: %d, city_id: %d}"%(self.i, self.pref_id, self.year, self.city_id)
        
    def set_city_id(self, city_id):
        self.city_id = city_id
            
    def get_sort_key(self):
        return zeroPadding(self.pref_id ) + zeroPadding(self.year ) 
            
    def get_str(self):
        return zeroPadding(self.pref_id ) + zeroPadding(self.city_id)

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

row_list = []

for i in range(M):
    d = list(map(int,input().split())) 
    row_list.append(Row(i, d[0], d[1]))

row_list = sorted(row_list, key=lambda x: x.get_sort_key())

now_pref_id = -1a
cnt = 1

result = []
for i, row in enumerate(row_list):
    if row.pref_id != now_pref_id:
        now_pref_id = row.pref_id
        cnt = 1
    
    row.set_city_id(cnt)
    row_list[i] = row
    cnt += 1

[print(x.get_str()) for x in sorted(row_list, key=lambda x: x.i)]

### FIXED CODE ###

def zeroPadding(num):
    return "%06d"%num

def zeroPadding10(num):
    return "%010d"%num

class Row:
    def __init__(self, i, pref_id, year):
        self.i = i
        self.pref_id = pref_id
        self.year = year
        self.city_id = -1
        
    def __str__(self):
        return "{i: %d, pref_id: %d, year: %d, city_id: %d}"%(self.i, self.pref_id, self.year, self.city_id)
        
    def set_city_id(self, city_id):
        self.city_id = city_id
            
    def get_sort_key(self):
        return zeroPadding(self.pref_id ) + zeroPadding10(self.year) 
            
    def get_str(self):
        return zeroPadding(self.pref_id ) + zeroPadding(self.city_id)

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

row_list = []

for i in range(M):
    d = list(map(int,input().split())) 
    row_list.append(Row(i, d[0], d[1]))

row_list = sorted(row_list, key=lambda x: x.get_sort_key())

now_pref_id = -1
cnt = 1

result = []
for i, row in enumerate(row_list):
    if row.pref_id != now_pref_id:
        now_pref_id = row.pref_id
        cnt = 1
    
    row.set_city_id(cnt)
    row_list[i] = row
    cnt += 1

[print(x.get_str()) for x in sorted(row_list, key=lambda x: x.i)]
a,b,c=map(int,input().split())
if b-c==c=b:
  print('YES')
else:
  print('NO')

### FIXED CODE ###

a,b,c=map(int,input().split())
if b-a==c-b:
  print('YES')
else:
  print('NO')
S=input()
if S[2]=S[3],S[4]=S[5]:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

S=input()
if S[2]==S[3] and S[4]==S[5]:
  print("Yes")
else:
  print("No")
import sys
sys.setrecursionlimit(10000)

def resolve():
    N = int(input())
    hs = list(map(int, input().split(" ")))
    dps = [None] * N

    def rec(dest):
        if dest == 0:
            dps[dest] = 0
        if dest == 1:
            dps[dest] = abs(hs[1]-hs[0])

        if dps[dest] is None:
            dps[dest] = min(rec(dest-1)+abs(hs[dest]-hs[dest-1]), rec(dest-2)+abs(hs[dest]-hs[dest-2]))
        
        return dps[dest]

    print(rec(N-1))

if __name__ == '__main__':
    resolve()

### FIXED CODE ###

def resolve():
    N = int(input())
    hs = list(map(int, input().split(" ")))
    dps = [0] * N

    dps[0] = 0
    dps[1] = abs(hs[1] - hs[0])
    for i in range(2, N):
        dps[i] = min(dps[i-1]+abs(hs[i]-hs[i-1]), dps[i-2]+abs(hs[i]-hs[i-2]))
    
    print(dps[-1])

if __name__ == '__main__':
    resolve()
N,Q=map(int,input().split()) 
S=sinput()
t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

### FIXED CODE ###

N,Q=map(int,input().split()) 
S=input()
t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])
a, b, c = input.split()
num = a + b + c
num = int(num)
if num % 4 == 0:
  print("YES")
else:
  print("NO)

### FIXED CODE ###

a, b, c = input().split()
num = a + b + c
num = int(num)
if num % 4 == 0:
  print("YES")
else:
  print("NO")
#C - Energy Drink Collector(ABC121)
N,M=map(int, input().split())
L={}
for i in range(N):
    A,B=map(int, input().split())
    L[A]=B
X=sorted(L.keys())
i=0
ans=0
while True:
    if M>=L[X[i]]:
        M-=L[X[i]]
        ans+=X[i]*L[X[i]]
        i+=1
        if M==0:
            break
    else:
        ans+=X[i]*M
        break
print(ans)

### FIXED CODE ###

#C - Energy Drink Collector(ABC121)
N,M=map(int, input().split())
X=[]
for i in range(N):
    a,b=map(int, input().split())
    X.append([a,b])
X.sort()
ans=0
i=0
while M>0:
    if M>=X[i][1]:
        ans+=X[i][1]*X[i][0]
        M-=X[i][1]
        i+=1
    else:
        ans+=X[i][0]*M
        break
print(ans)
def main():
    N, Q = list(map(int, input().split()))
    nodes = [None] * N
    ans = [0] * N

    for i in range(N-1):
        a, b = list(map(int, input().split()))

        if nodes[a-1] is None:
            nodes[a-1] = []

        nodes[a-1].append(b-1)

    # print()
    # print(nodes)

    for i in range(Q):
        p, x = list(map(int, input().split()))
        li = nodes[p-1]

        ans[p-1] += x

        if li is None:
            continue

        queue = li.copy()
        while len(queue) != 0:
            # print(queue)
            n = queue.pop(0)
            ans[n] += x

            if nodes[n] is not None:
                for next_n in nodes[n]:
                    queue.append(next_n)
        # print(i, ans)

    print(' '.join(map(str, ans)))


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import queue
input = sys.stdin.readline
N, Q = map(int, input().split())
 
tree = [[] for i in range(N+1)]
values = [0] * (N+1)
visit = [False]*(N+1)
for _ in range(N-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)
 
for _ in range(Q):
    p, x = map(int, input().split())
    values[p] += x
 
 
q = queue.Queue()
q.put(1)
visit[1] = True
while (not q.empty()):
    now = q.get()
    for next in tree[now]:
        if not visit[next]:
            values[next] += values[now]
            visit[next] = True
            q.put(next)
 
values = values[1:]
print(" ".join(map(str, values)))
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
a_list.sort()

import math


def cmb(n, r):
    o = math.factorial(n)
    u = math.factorial(r) * math.factorial(n - r)
    return o / u


max_val = 0
min_val = 0
val = cmb(n - 1, k - 1)
for i in range(n - k + 1):
    if i != 0:
        val = int(val * (n - i - k + 1) / (n - i))
    max_val = (max_val + (((a_list[-(i + 1)]) * val))) % (10 ** 9 + 7)
    min_val = (min_val + ((a_list[i]) * val)) % (10 ** 9 + 7)

print(int((max_val - min_val) % (10 ** 9 + 7)))

### FIXED CODE ###

n, k = map(int, input().split())
a_list = list(map(int, input().split()))
a_list.sort()


mod = 10 ** 9 + 7
f_list = [1]
for i in range(1,n+1):
    f_list.append((f_list[-1] * i) % mod)
def comb(n,r):
    return f_list[n] * (pow(f_list[r], mod-2, mod) * pow(f_list[n-r], mod-2, mod) % mod) % mod


max_val = 0
min_val = 0
for i in range(n - k + 1):
    val = comb(n - i - 1, k - 1)
    max_val = (max_val + (((a_list[-(i + 1)]) * val))) % (10 ** 9 + 7)
    min_val = (min_val + ((a_list[i]) * val)) % (10 ** 9 + 7)

print(int((max_val - min_val) % (10 ** 9 + 7)))
h,a = map(int,input().split())
print(h//a + (1-(h%a==0))


### FIXED CODE ###

h,a = map(int,input().split())
print(h//a+1-int(h%a==0))
''' Hey stalker :) '''
INF = 10**10
def main():
    #print = out.append
    ''' Cook your dish here! '''
    h, n = get_list()
    wepons = dict()
    for _ in range(n):
        a,b = get_list()
        if a in wepons:
            wepons[a] = min(b, wepons[a])
        else: wepons[a] = b

    dp = [-1]*(h+1)
    dp[0] = 0
    #print(wepons)
    def calc(n):
        if n<0: return 0
        if dp[n]!=-1: return dp[n]
        #print(n)
        cst = INF
        for wepon in wepons:
            #print(n-wepon)
            cst = min(cst, calc(n-wepon) + wepons[wepon])
        dp[n] = cst
        #print(n, cst)
        return cst
    print(calc(h))


''' Pythonista fLite 1.1 '''
import sys
#from collections import defaultdict, Counter
#from bisect import bisect_left, bisect_right
#from functools import reduce
#import math
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
main()
#[main() for _ in range(int(input()))]
print(*out, sep='\n')


### FIXED CODE ###

''' Hey stalker :) '''
INF = 10**10
def main():
    #print = out.append
    ''' Cook your dish here! '''
    h, n = get_list()
    wepons = dict()
    for _ in range(n):
        a,b = get_list()
        if a in wepons:
            wepons[a] = min(b, wepons[a])
        else: wepons[a] = b
    dp = [0]*(h+1)
    for i in range(1, h+1):
        ans = INF
        for wp in wepons:
            if wp>i: ans = min(ans, wepons[wp])
            else: ans = min(ans, wepons[wp] + dp[i-wp])
        dp[i] = ans
    print(dp[-1])

''' Pythonista fLite 1.1 '''
import sys
#from collections import defaultdict, Counter
#from bisect import bisect_left, bisect_right
#from functools import reduce
#import math
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
main()
#[main() for _ in range(int(input()))]
print(*out, sep='\n')
def dot(a, b):
    return (a.real*b.real - a.imag*b.imag)
def cross(a, b):
    return (a.real*b.imag - a.imag*b.real)

EPS = 10**(-7)

def isIntersectedLS(a1, a2, b1, b2):
    return ((cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1)) < EPS and
            (cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1)) < EPS)

def main():
    while 1:
        try:
            x,y = [[0. for i in xrange(3)] for j in xrange(2)]
            a = []
            z = [0. for i in xrange(2)]
            x[0],y[0],x[1],y[1],x[2],y[2],z[0],z[1] = map(float, raw_input().split())
            for i in xrange(3):
                a.append((x[i]+(y[i])*1j))
            c = (sum(x)/3)+(sum(y)/3)*1j
            p = z[0]+z[1]*1j
                
            for i in xrange(3):
                #print a, c, p
                if isIntersectedLS(a[i-1], a[i], c, p) is True:
                    print "NO"
                    break
            else:
                print "YES"
                
        except EOFError:
            break

if __name__ == '__main__':
    main()

### FIXED CODE ###

def dot(a, b):
    return (a.real*b.real - a.imag*b.imag)
def cross(a, b):
    return (a.real*b.imag - a.imag*b.real)

EPS = 10**(-7)

def isIntersectedLS(a1, a2, b1, b2):
    return ((cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1)) < EPS and
            (cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1)) < EPS)

while 1:
    try:
        x,y = [[0. for i in xrange(3)] for j in xrange(2)]
        a = []
        z = [0. for i in xrange(2)]
        line = raw_input().split()
        if line == []: break
        x[0],y[0],x[1],y[1],x[2],y[2],z[0],z[1] = map(float, line)
        for i in xrange(3):
            a.append((x[i]+(y[i])*1j))
        c = (sum(x)/3)+(sum(y)/3)*1j
        p = z[0]+z[1]*1j
           
        for i in xrange(3):
            #print a, c, p
            if isIntersectedLS(a[i-1], a[i], c, p) is True:
                print "NO"
                break
        else:
            print "YES"
           
    except EOFError:
        break
import numpy


def li():
    return list(map(int, input().split()))


if __name__ == "__main__":
    n = int(input())
    a_list = li()
    b_list = li()
    # i0_list = []
    # for a, b in zip(a_list[:n], b_list):
    #     i0_list.append(min(a, b))
    # i1_list = []
    # for a, b in zip(a_list[1:], b_list):
    #     i1_list.append(min(a, b))
    # i0_cum = numpy.cumsum(i0_list).tolist()
    # tmp = [0]
    # tmp.extend(i0_cum)
    # i0_cum = tmp
    # i1_cum = numpy.cumsum(i1_list[::-1]).tolist()
    # tmp = [0]
    # tmp.extend(i1_cum)
    # i1_cum = tmp[::-1]
    #
    # print(i0_cum)
    # print(i1_cum)
    # max_val = 0
    # for i0, i1 in zip(i0_cum, i1_cum):
    #     if i0 + i1 > max_val:
    #         max_val = i0 + i1
    # print(max_val)

    monster = 0
    for index in range(len(b_list)):
        monster_add = min(a_list[index], b_list[index])
        monster = monster + monster_add
        a_list[index] = a_list[index] - monster_add
        b_list[index] = b_list[index] - monster_add

        monster_add = min(a_list[index + 1], b_list[index])
        monster = monster + monster_add
        a_list[index] = a_list[index + 1] - monster_add
        b_list[index] = b_list[index] - monster_add
    print(monster)

# 尺取り的に全部求められる？
# iの場合とi+1の場合を全て計算して累積和を使えばいけそう


### FIXED CODE ###

def li():
    return list(map(int, input().split()))


if __name__ == "__main__":
    n = int(input())
    a_list = li()
    b_list = li()

    monster = 0
    for index in range(n):
        monster_add = min(a_list[index], b_list[index])
        monster = monster + monster_add
        a_list[index] = a_list[index] - monster_add
        b_list[index] = b_list[index] - monster_add

        monster_add = min(a_list[index + 1], b_list[index])
        monster = monster + monster_add
        a_list[index + 1] = a_list[index + 1] - monster_add
        b_list[index] = b_list[index] - monster_add
    print(monster)
A = int(input())
B = int(input())
C = int(input())
K = int(input())

if K >A+B :
  print(2*A-K+B)
else :
  print(A)

### FIXED CODE ###

A,B,C,K = map(int,input().split())

if K >A+B:
  print(A-1*(K-A-B))
elif A > K :
  print(K)
else :
  print(A)
import sys
input = sys.stdin.readline

X = 0
D = 0

def loop():
    i=1
    a = int(input())
    while i*a+1 <= D:
      	yield 1
        i += 1

def readlines():
    global X, D
    N = int(input())
    D, X = map(int, input().split())
    for _ in range(N):
        yield 1+sum(loop())

def main():
    return sum(readlines()) + X
	
if __name__ == "__main__":
    print(main())


### FIXED CODE ###

import sys
input = sys.stdin.readline

X = 0
D = 0

def loop():
    i=1
    a = int(input())
    while True:
        if i*a+1 <= D:
            yield 1
        else:
            break
        i += 1

def readlines():
    global X, D
    N = int(input())
    D, X = map(int, input().split())
    for _ in range(N):
        yield 1+sum(loop())

def main():
    return sum(readlines()) + X
	
if __name__ == "__main__":
    print(main())
import collections

n,k=int(input())
a=list(map(int,input().split()))

a_counter=collections.Counter(a)
li=a_counter.most_common()[k:]
ans=0
ans+=li[1]
print(ans)


### FIXED CODE ###

import collections

n,k=map(int,input().split())
a=list(map(int,input().split()))

a_counter=collections.Counter(a)
li=a_counter.most_common()[k:]
ans=0
for i in li:
    ans+=i[1]
print(ans)
!/usr/bin/python3
from itertools import product
 
def solve():
	N = int(input())
	S = [0 if i == 'o' else 1 for i in input()]
 
	for i, j in product(range(2), repeat=2):
		pattern = [i, j] + [0] * (N - 2) 
		for k in range(2, N):
			pattern[k] = (pattern[k - 1] + pattern[k - 2] + S[k] ) % 2
		if S[-1] != (pattern[-2] + pattern[-1] + pattern[0]) % 2 : 
			continue
		if S[0] != (pattern[-1] + pattern[0] + pattern[1]) % 2 :
			continue 	
		answer = [ 'S' if pattern[k] == 0 else 'W' for k in range(N)]
		print(''.join(answer))
		return None
	print(-1)
 
if __name__ == '__main__':
	solve()

### FIXED CODE ###

from itertools import product

def solve():
    N = int(input())
    S = [0 if i == 'o' else 1 for i in input()]
    
    for i, j in product(range(2), repeat=2):
        pat = [i, j] + [0]*(N - 2)
        for k in range(2, N):
            pat[k] = (S[k - 1] - (pat[k - 1] + pat[k - 2])) % 2

        if S[-1] != (pat[0] + pat[-1] + pat[-2]) % 2:
            continue
        if S[0] != (pat[1] + pat[0] + pat[-1]) % 2:
            continue

        ans = ['S' if pat[k] == 0 else 'W' for k in range(N)]
        print(''.join(ans))
        return None

    print(-1)

if __name__ == '__main__':
    solve()
n,k,x,y=int(input())
if n <= k:
    print n * x
else:
    print k * x + (n - k) * y

### FIXED CODE ###

n=int(input())
k=int(input())
x=int(input())
y=int(input())
if n <= k:
    print n * x
else:
    print k * x + (n - k) * y
N = list(map(int, input().split()))
if N[0] == N[1] == N[2] or N[1] == N[2] == N[3]:
  print("Yes")
else:
  print("No")
         

### FIXED CODE ###

N = list(input())
if (N[0] == N[1] and N[1] == N[2]) or (N[1] == N[2] and N[2] == N[3]):
  print("Yes")
else:
  print("No")
A,B,C,D = map(int,input().split())
 
Takahashi = A
Aoki = C
 
while Takahashi >= 0 or Aoki >=0:
  Aoki -= B
  if Aoki <= 0:
    print('Yes')
    break
  Takahashi -= D
  if Takahashi <= 0:
    print('No')
    break

### FIXED CODE ###

S,W = map(int,input().split())
 
if S <= W:
  print('unsafe')
else:
  print('safe')