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

n = int(input())
s = input()

min_cost = n

for i in range(n+1):
    s_left = s[:i]
    s_right = s[i:]
    cost = s_left.count('#') + s_right.count('.')
    if cost < min_cost:
        min_cost = cost

print(min_cost)


### FIXED CODE ###

n = int(input())
s = input()

def calc():
    min_cost = n
    left_cost = 0
    right_cost = s.count('.')

    cost = left_cost + right_cost
    if cost < min_cost:
        min_cost = cost

    for i in range(n):
        if s[i] == '#':
            left_cost += 1
        else:
            right_cost -= 1
        cost = left_cost + right_cost
        if cost < min_cost:
            min_cost = cost

    return(min_cost)

print(calc())
### BUGGY CODE ###

N, M = map(int, input().split())
from collections import defaultdict

graph = defaultdict(list)
for i in range(M):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    graph[u].append(v + N)
    graph[u + N].append(v + 2 * N)
    graph[u + 2 * N].append(v)
S, T = map(int, input().split())
S -= 1
T -= 1
cnt = 4 * 10 ** 5
dist = [float("inf")] * cnt


que = [S]
dist[S] = 0

while len(que) != 0:
    q = que.pop()
    for v in graph[q]:
        if dist[v] > dist[q] + 1:
            dist[v] = dist[q] + 1
            que.append(v)
if dist[T] != float("inf"):
    print(dist[T] // 3)
else:
    print(-1)


### FIXED CODE ###

import heapq


class Dijkstra:

    def __init__(self, rote_map, start_point, goal_point=None):
        self.rote_map = rote_map
        self.start_point = start_point
        self.goal_point = goal_point

    def execute(self):
        num_of_city = 3 * 10 ** 5 + 10
        dist = [float("inf") for _ in range(num_of_city)]
        prev = [float("inf") for _ in range(num_of_city)]

        dist[self.start_point] = 0
        heap_q = []
        heapq.heappush(heap_q, (0, self.start_point))
        route_count = [0 for _ in range(num_of_city)]
        route_count[self.start_point] = 1
        while len(heap_q) != 0:
            prev_cost, src = heapq.heappop(heap_q)

            if dist[src] < prev_cost:
                continue

            for dest, cost in self.rote_map[src].items():
                if cost != float("inf") and dist[dest] > dist[src] + cost:
                    dist[dest] = dist[src] + cost
                    heapq.heappush(heap_q, (dist[dest], dest))
                    prev[dest] = src
                if dist[dest] == dist[src] + cost:
                    route_count[dest] += route_count[src]

        if self.goal_point is not None:
            return self._get_path(self.goal_point, prev)
        else:
            return dist, route_count

    def _get_path(self, goal, prev):
        path = [goal]
        dest = goal

        while prev[dest] != float("inf"):
            path.append(prev[dest])
            dest = prev[dest]

        return list(reversed(path))


N, M = map(int, input().split())
from collections import defaultdict

graph = defaultdict(dict)
for i in range(M):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    graph[u][v + N] = 1
    graph[u + N][v + 2 * N] = 1
    graph[u + 2 * N][v] = 1
S, T = map(int, input().split())
S -= 1
T -= 1
dj = Dijkstra(graph, S)

dist, _ = dj.execute()
if dist[T] % 3 == 0:
    print(dist[T] // 3)
else:
    print(-1)
### BUGGY CODE ###

n= int(input())
l= []
for _ in range(n):
	s= input()
	if s in l:
		continue
	else:
		l.append(s)
print(len(l))

### FIXED CODE ###

n= int(input())
l= set()
for _ in range(n):
	s= input()
	l.add(s)
print(len(l))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline


def DFS(num,parent,point):
    D[num]=point+Q[num]
    for i in M[num]:
        if i!=parent:
            DFS(i,num,D[num])


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

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

Q=[0]*(n+1)
for i in range(q):
    p,x=map(int,input().split())
    Q[p] +=x

D=[0]*(n+1)
DFS(1,0,0)
print(*D[1:])

### FIXED CODE ###

# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

#n = int(input())
n,q = [int(i) for i in readline().split()]

g = [[] for _ in range(n)]
for i in range(n-1):
    a,b = [int(i) for i in readline().split()]
    g[a-1].append(b-1)
    g[b-1].append(a-1)

add = [0]*n
for _ in range(q):
    p,x = [int(i) for i in readline().split()]
    add[p-1] += x

ans = [0]*n
#ans[0] = add[0]

def dfs(v,p,value): #p: parent of v
    value += add[v]
    ans[v] = value
    for c in g[v]:
        if c == p: continue
        dfs(c,v,value)

dfs(0,-1,0)

#print(add)

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

n,k=map(int,input().split())
xy=[list(map(int,input().split())) for _ in range(n)]
x=[xy[i][0] for i in range(n)]
y=[xy[i][1] for i in range(n)]
res = 10**20
for i in range(n):
    xl = xy[i][0]
    for j in range(n):
        xr = xy[j][0]
        if xr<xl:continue
        for p in range(n):
            yl = xy[p][1]
            for q in range(n):
                yr = xy[q][1]
                if yr<yl:continue
                tres = 0
                for sxy in xy:
                    if sxy[0] >= xl and sxy[0] <= xr and sxy[1] >= yl and sxy[1] <= yr:
                        tres += 1
                if tres >= k:
                    res = min(res,(xr-xl)*(yr-yl))
print(res)

### FIXED CODE ###

n,k=map(int,input().split())
xy=[list(map(int,input().split())) for _ in range(n)]
x=[xy[i][0] for i in range(n)]
y=[xy[i][1] for i in range(n)]
res = 10**20
for i in range(n):
    xl = xy[i][0]
    for j in range(n):
        xr = xy[j][0]
        if xr<xl:continue
        for p in range(n):
            yl = xy[p][1]
            for q in range(n):
                yr = xy[q][1]
                if yr<yl:continue
                tres = 0
                for sxy in xy:
                    if sxy[0] >= xl and sxy[0] <= xr and sxy[1] >= yl and sxy[1] <= yr:
                        tres += 1
                if tres >= k:
                    res = min(res,(xr-xl)*(yr-yl))
print(res)
### BUGGY CODE ###

N = int(input())
S=[]
for n in range(N):
    S.append(input())
Slist = []
for s in S:
    lists = list(s)
    listss = sorted(lists)
    Slist.append(listss)
def isAna2(Sl,sl):
    boolcount = True
    for i,Sli in enumerate(Sl):
        if Sli != sl[i]:
            boolcount = False
            break
    return boolcount
count = 0
for i,Sl in enumerate(Slist):
    for sl in Slist[i+1:]:
        if isAna2(Sl,sl) == True:
            count+=1
print(count)

### FIXED CODE ###

N = int(input())
S=[]
for n in range(N):
    S.append(input())
Sdict = {}
for s in S:
    lists = list(s)
    listss = sorted(lists)
    listsss = ''.join(listss)
    if Sdict.get(listsss) == None:
        Sdict[listsss] = 1
    else:
        Sdict[listsss] += 1
count = 0
for value in Sdict.values():
    count += int(value*(value-1)/2)
print(count)
### BUGGY CODE ###

import math

K = int(input())
total = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            total += math.gcd(k, math.gcd(i, j))

print(total)

### FIXED CODE ###

import math

K = int(input())
total = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            total += math.gcd(k, math.gcd(i, j))

print(total)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
import bisect
n = int(input())
a = list(map(int,input().split()))
d = int(input())
graph = [0 for i in range(n+1)]
for i in range(n-1):
  x = bisect.bisect_right(a,a[i]+d)
  if x == i:
    continue
  graph[i+1] = x
group = [0]*(n+1)
row = [[] for i in range(n+1)]
cnt = 0
stack = []
for i in range(1,n+1):
  if group[i] == 0:
    stack.append(i)
    cnt += 1
    while stack:
      x = stack.pop()
      row[cnt].append(x)
      group[x] = cnt
      if x != n:
        stack.append(graph[x])
q = int(input())
for _ in range(q):
  l,r = map(int,input().split())
  if l>r:
    l,r = r,l
  x = group[l]
  yl = bisect.bisect_left(row[x],l)
  yr = bisect.bisect_left(row[x],r)
  print(yr-yl)

### FIXED CODE ###

import bisect
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
d = int(input())
graph = [[0 for i in range(n+1)] for j in range(18)]
for i in range(n):
  x = bisect.bisect_right(a,a[i]+d)
  graph[0][i+1] = x
for j in range(1,18):
  for i in range(n):
    t = graph[j-1][i+1]
    graph[j][i+1] = graph[j-1][t]
q = int(input())
for _ in range(q):
  x,y = map(int,input().split())
  x,y = min(x,y),max(x,y)
  ans = 0
  for j in range(18)[::-1]:
    if graph[j][x] < y:
      ans += 2**j
      x = graph[j][x]
    if j == 0 and x < y:
      ans += 1
  print(ans)
### BUGGY CODE ###

import heapq
n,m=map(int,input().split())
item=list(map(int,input().split()))
for i in range(n):item[i]=item[i]*-1
for i in range(m):
    heapq.heapify(item)
    a=heapq.heappop(item)
    heapq.heappush(item,((-1*a)//2)*-1)

print(sum(item)*-1)

### FIXED CODE ###

import heapq
n,m=map(int,input().split())
item=list(map(lambda x: -int(x),input().split()))
heapq.heapify(item)
for i in range(m):
    a=-heapq.heappop(item)
    a //=2
    heapq.heappush(item,-a)

print(-sum(item))
### BUGGY CODE ###

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

cnt = 0
print(len([i for i in range(N) if all([False if P[i] > P[j] else True for j in range(i)])]))


### FIXED CODE ###

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

cnt = 0
min_value = N + 1
for i in range(N):
    if P[i] <= min_value:
        cnt += 1
        min_value = P[i]
print(cnt)
### BUGGY CODE ###

S = list(input())
n = int(input())
s = []
for i in range(n):
    array = list(map(str,input().split()))
    s.append(array)
for i in range(n):
    if s[i][0] == "1":
        S.reverse()
    else:
        if s[i][1] == "1":
            S.insert(0,s[i][2])
        else:
            S.append(s[i][2])

print("".join(S))

### FIXED CODE ###

x = input()
s = []
n = int(input())
for i in range(n):
    array = list(map(str,input().split()))
    s.append(array)
    
a = ""
b = ""
c = 0
for i in range(n):
    if s[i][0] == "1":
        c += 1
        c = c%2
    else:
        if c == 0:
            if s[i][1] == "1":
                a = s[i][2] + a
            else:
                b = b + s[i][2]
        else:
            if s[i][1] == "1":
                b = b + s[i][2]
            else:
                a = s[i][2] + a
if c == 0:
    print(a + x + b)
else:
    print(''.join(list(reversed(b))) + ''.join(list(reversed(x))) + ''.join(list(reversed(a))))
### BUGGY CODE ###

s = input()
change_s = "" + s
check = True
while check:
    change_s = change_s.replace("01", "")
    change_s = change_s.replace("10", "")
    check = "01" in change_s or "10" in change_s
print(len(s) - len(change_s))

### FIXED CODE ###

s = input()
count_0 = s.count("0")
count_1 = s.count("1")
print(min(count_0, count_1) * 2)
### BUGGY CODE ###

n = int(input())
l = list(map(int, input().split()))
ans = 1
for i in l:
  ans *= i
if ans > 1e18:
  print(-1)
else:
  print(ans)

### FIXED CODE ###

n = int(input())
l = list(map(int, input().split()))
ans = 1
for i in l:
  if i == 0:
    ans = 0

for i in l:
  ans *= i
  if ans > 1e18 or ans == 0:
    break
if ans > 1e18:    
  print(-1)
else:
  print(ans)
### BUGGY CODE ###

a,b,k=map(int,input().split())
S=[]
for i in range(a,b+1):
    S.append(i)
T=sorted(list(set(S[:k]+S[-k:])))

for i in T:
    print(i)

### FIXED CODE ###

a,b,k=map(int,input().split())
S=[]

for i in range(k):
    if a+i>b:
        break
    S.append(a+i)
    
for i in range(k):
    if b-i<a:
        break
    S.append(b-i)
    
S=sorted(list(set(S)))
for i in S:
    print(i)
### BUGGY CODE ###

import math
N = int(input())
A = [int(s) for s in input().split()]
B = [0 for i in range(N)]
idx = []
for i in range(N):
  B[A[i]-1] += 1
  if B[A[i]-1] >= 2 and not A[i]-1 in idx:
    idx.append(A[i]-1)

def nCr (n, r):
  return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))

Cs = []
C = []
Ctot = 0
for j in idx:
  if B[j]-1 >= 2:
    Cs.append(nCr(B[j]-1, 2))
  else:
    Cs.append(0)
  tmp = nCr(B[j], 2)
  C.append(tmp)
  Ctot += tmp
for i in range(N):
  current_idx = A[i]-1
  if current_idx in idx:
    count = Ctot + Cs[idx.index(current_idx)]-C[idx.index(current_idx)]
  else:
    count = Ctot
  print(count)

### FIXED CODE ###

N = int(input())
A = [int(s) for s in input().split()]
B = [0 for i in range(N)]
def nC2(n):
  return n*(n-1)//2
for i in range(N):
  B[A[i]-1] += 1
Ctot = 0
for i in range(N):
  Ctot += nC2(B[i])
for i in range(N):
  current_idx = A[i]-1
  if B[current_idx] == 1:
    count = Ctot
  else:
    count = Ctot + nC2(B[current_idx]-1) - nC2(B[current_idx])
  print(count)
### BUGGY CODE ###

N,P=map(int,input().split())
S=list(input())
S=S[::-1]
Si=[0]*N
cnt=0
sum=0
if P==2 or P==5:
    for i in range(N):
        if int(S[i])%P==0:
            cnt+=N-i

else:
    mod=[(int(k)*10**j)%P for j,k in enumerate(S)]
    for m,n in enumerate(mod):
        sum+=n
        Si[m]=sum%P
    
    cnt+=Si.count(0)
    for i in range(P):
        num_i=Si.count(i)
        cnt+=num_i*(num_i-1)/2
        
print(int(cnt))

### FIXED CODE ###

n, p = map(int, input().split())
 
s = list(input())
ans = 0
if p == 2 or p == 5:
    for i in range(n):
        if int(s[i]) % p == 0:
            ans += i + 1
else:
    d = [0] * (n + 1)
    ten = 1
    for i in range(n - 1, -1, -1):
        a = int(s[i]) * ten % p
        ten *= 10
        ten %= p
        d[i - 1] = (d[i] + a) % p
    cnt = [0] * p
    for i in range(n, -1, -1):
        cnt[d[i]] += 1
    for  i in cnt:
        ans+=i*(i-1)/2

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

import sys
input = sys.stdin.readline
N=int(input())
ans=[]

for _ in range(N):
    A=int(input())
    if((A in ans) == True):
        ans.remove(A)
    else:
        ans.append(A)


print(len(ans))


### FIXED CODE ###

import sys
input = sys.stdin.readline
N=int(input())
ans=dict()
cnt=0

for _ in range(N):
    A=int(input())
    if((A in ans)==False):
        ans[A]=1
    else:
        ans[A]+=1

for value in ans.values():
    if(value%2==1):
        cnt+=1

print(cnt)
### BUGGY CODE ###

N = int(input())
h = [int(x) - 1 for x in input().split()]
a = [int(x) for x in input().split()]

dp = [0] * N
for i,j in zip(h,a):
    if i == 0:
        dp[i] = j
    else:
        dp[i] = max(dp[0:i]) + j
print(max(dp))

### FIXED CODE ###

N = int(input())
h = [int(x) - 1 for x in input().split()]
a = [int(x) for x in input().split()]

l2N = 0
n = N
while n > 1:
    n = -(-n//2)
    l2N += 1
N = 2**l2N

seg = [0] * (2 * 2**l2N - 1)

def update(H, x):
    H += 2**l2N - 1
    seg[H] = x
    while H > 0:
        H = (H - 1) // 2
        seg[H] = max(seg[H*2+1], seg[H*2+2])

def maxSrch(a, b, k, l, r):
    if r <= a or b <= l:
        return 0
    if a <= l and r <= b:
        return seg[k]
    else:
        vl = maxSrch(a, b, k*2+1, l, (l+r)//2)
        vr = maxSrch(a, b, k*2+2, (l+r)//2, r)
        return max(vl, vr)

for H,A in zip(h,a):
    update(H, maxSrch(0,H,0,0,N) + A)
print(seg[0])
### BUGGY CODE ###

def main():
    import sys
    input = sys.stdin.readline
    class BIT:
        def __init__(self,n):
            self.tree = [0]*(n+1)
            self.size = n
        
        def add(self,i,x):
            while i <= self.size:
                self.tree[i] += x
                i += i&-i
        
        def sum(self,i):
            s = 0
            while i > 0:
                s += self.tree[i]
                i -= i&-i
            return s

    N,Q = map(int,input().split())
    bit = BIT(N)
    C = list(map(int,input().split()))
    query = []
    for i in range(Q):
        l,r = map(int,input().split())
        query.append([l,r,i])
    query.sort(key=lambda x: x[1])
    #良い玉のindexを1-indexで管理する
    colorMemo = [0]*(N+1)
    i = 1
    for j in range(Q):
        l,r = query[j][:2]
        #良い玉の情報を更新する
        while i <= r:
            c = C[i-1]
            if colorMemo[c]:
                bit.add(colorMemo[c],-1)
            bit.add(i,1)
            colorMemo[c] = i
            i += 1
        query[j].append(bit.sum(r)-bit.sum(l-1))

    query.sort(key=lambda x: x[2])
    for l,r,i,a in query:
        print(a)
main()

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    class BIT:
        def __init__(self,n):
            self.tree = [0]*(n+1)
            self.size = n
        
        def add(self,i,x):
            while i <= self.size:
                self.tree[i] += x
                i += i&-i
        
        def sum(self,i):
            s = 0
            while i > 0:
                s += self.tree[i]
                i -= i&-i
            return s

    N,Q = map(int,input().split())
    bit = BIT(N)
    C = list(map(int,input().split()))
    query = []
    for i in range(Q):
        l,r = map(int,input().split())
        query.append([l,r,i])
    query.sort(key=lambda x: x[1])
    ans = [0]*Q
    #良い玉のindexを1-indexで管理する
    colorMemo = [0]*(N+1)
    cur = 1
    for q in query:
        l,r,j = q
        #良い玉の情報を更新する
        for i in range(cur,r+1):
            c = C[i-1]
            if colorMemo[c]:
                bit.add(colorMemo[c],-1)
            bit.add(i,1)
            colorMemo[c] = i
        cur = r + 1
        ans[j]=bit.sum(r)-bit.sum(l-1)

    print(*ans, sep="\n")
main()
### BUGGY CODE ###

# coding: utf-8
import re

n = int(input())
s = input()

R = [m.start() for m in re.finditer('R', s)]
G = [m.start() for m in re.finditer('G', s)]
B = [m.start() for m in re.finditer('B', s)]

x=0
for r in R:
    for g in G:
        if r < g:
            gr = g-r
            if r-gr in B:
                x += 1
            if g+gr in B:
                x += 1
            if gr%2 == 0 and r+gr//2 in B:
                x += 1
        else:
            rg = r-g
            if g-rg in B:
                x += 1
            if r+rg in B:
                x += 1
            if rg%2 == 0 and g+rg//2 in B:
                x += 1
                
print(len(R)*len(G)*len(B)-x)

### FIXED CODE ###

# coding: utf-8
import re

n = int(input())
s = input()

R = set([m.start() for m in re.finditer('R', s)])
G = set([m.start() for m in re.finditer('G', s)])
B = set([m.start() for m in re.finditer('B', s)])
#print(R,G,B)
x=0
li=[]
for r in R:
    for g in G:
        
        if r < g:
            gr = g-r
            li.extend([r-gr in B, g+gr in B, (gr%2 == 0 and r+gr//2 in B)])
        
        else:
            rg = r-g
            li.extend([g-rg in B, r+rg in B, (rg%2 == 0 and g+rg//2 in B)])

print(len(R)*len(G)*len(B)-sum(li))
### BUGGY CODE ###

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

aa=[]

for i in range(n):
    aa.append(a[i]-1)
    aa.append(a[i])
    aa.append(a[i]+1)

ans=0
for i in aa:
    if ans < aa.count(i):
        ans = aa.count(i)
print(ans)

### FIXED CODE ###

import collections

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

aa=[]

for i in range(n):
    aa.append(a[i]-1)
    aa.append(a[i])
    aa.append(a[i]+1)
ans_list=collections.Counter(aa)
print(ans_list.most_common()[0][1])
### BUGGY CODE ###

a,b,q=map(int,input().split())
s=sorted([int(input()) for _ in range(a)])
t=sorted([int(input()) for _ in range(b)])
import bisect
for _ in range(q):
    x=int(input())
    ss=[x-s[max(bisect.bisect_left(s,x)-1,0)],x-s[min(bisect.bisect_right(s,x),a-1)]]
    tt=[x-t[max(bisect.bisect_left(t,x)-1,0)],x-t[min(bisect.bisect_right(t,x),b-1)]]
    l=[]
    for i in ss:
        for j in tt:
            if i*j>=0:
                l.append(max(abs(i),abs(j)))
            else:
                l.append(max(abs(i),abs(j))+2*min(abs(i),abs(j)))
    print(min(l))


### FIXED CODE ###

a,b,q=map(int,input().split())
s=[int(input()) for _ in range(a)]
t=[int(input()) for _ in range(b)]
import bisect
for _ in range(q):
    x=int(input())
    sb=bisect.bisect_left(s,x)
    tb=bisect.bisect_left(t,x)
    ss=[x-s[max(sb-1,0)],x-s[min(sb,a-1)]]
    tt=[x-t[max(tb-1,0)],x-t[min(tb,b-1)]]
    l=[]
    for i in ss:
        for j in tt:
            if i*j>=0:
                l.append(max(abs(i),abs(j)))
            else:
                l.append(max(abs(i),abs(j))+2*min(abs(i),abs(j)))
    print(min(l))
### BUGGY CODE ###

n, m, q = map(int, input().split())
aa = [0]*q
bb = [0]*q
cc = [0]*q
dd = [0]*q
for i in range(q):
    aa[i],bb[i],cc[i], dd[i] = list(map(int, input().split()))
    
import itertools
ss = set(itertools.permutations([0]*(n-1)+[1]*(m-1)))
score = 0
for tu in ss:
    tmp = 0
    xx = [1]*n
    j = 0
    for t in tu:
        if t == 0:
            j += 1
            xx[j] = xx[j-1]
        if t == 1:
            xx[j] += 1
    for i in range(q):
        if xx[bb[i]-1] - xx[aa[i]-1] ==cc[i]: 
            tmp += dd[i]
    score = max(score, tmp)
print(score)   

### FIXED CODE ###

import numpy as np
from itertools import combinations_with_replacement
 
n, m, q = map(int, input().split())
 
pt = np.array(list(combinations_with_replacement(range(1,m+1), n)))
score = np.zeros(len(pt))
 
for i in range(q):
    a, b, c, d =map(int, input().split())
    flg = pt[:,b-1] - pt[:,a-1] == c
    score += flg * d
#    print(score)
 
print(int(score.max()))
### BUGGY CODE ###

N, A, B = map(int, input().split())
balls = 0
ans = 0
while balls < N:
    if balls + A <= N:
        balls += A + B
        ans += A
    else:
        ans += N - balls
        balls += A + B
print(ans)

### FIXED CODE ###

N, A, B = map(int, input().split())
k = N // (A + B)
print(A * k + min(A, N - (A + B) * k))