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

N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0 for a in range(N)]

for i in range(1,N):
  dpx = float('inf')
  for j in range(max(0,i-K),i):
    dpx = min(dpx,abs(h[i]-h[j])+dp[j])
    
  dp[i] = dpx


print(dp[-1])

### FIXED CODE ###

def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,N):
        dp[i]= min(abs(h[i]-h[j])+dp[j] for j in range(max(0,i-K),i))
    print(dp[-1])
main()
### BUGGY CODE ###

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

s1=""

for i in s:
    if i=="R":s1+="1"
    elif i=="G":s1+="2"
    elif i=="B":s1+="4"

ans=0

import itertools
for seq in itertools.combinations(range(1,n),2):
    if seq[0]==seq[1]-seq[0]:
        continue
    l1=int(s1,16)
    l2=int(s1,16)*16**seq[0]
    l3=int(s1,16)*16**seq[1]

    tasi=l1+l2+l3

    ans+=hex(tasi).count("7")

print(ans)

### FIXED CODE ###

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

ans=s.count("R")*s.count("G")*s.count("B")

for start in range(n):
    for kousa in range(n):
        if start+2*kousa>n-1:
            break
        if s[start]!=s[start+kousa] and s[start+kousa]!=s[start+2*kousa] and s[start+2*kousa]!=s[start]:
            ans-=1

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

ind = {"A":0,"C":1,"G":2,"T":3}
dic = [[],[],[],[]]
n = int(input())
for i in range(n):
    a = input()
    t=a.split()
    if t[0] == "insert":
        dic[ind[t[1][0]]].append(t[1])
    else:
        if t[1] in dic[ind[t[1][0]]]:
            print("yes")
        else:
            print("no")
    

### FIXED CODE ###

dic=dict()
n = int(input())
for i in range(n):
    a = input()
    t=a.split()
    if t[0] == "insert":
        dic[t[1]] = True
    else:
        if t[1] in dic:
            print("yes")
        else:
            print("no")
### BUGGY CODE ###

import copy
from collections import deque
H, W = map(int, input().split())
M = [list(input()) for _ in range(H)]

black = deque()
for i in range(H):
  for j in range(W):
    if M[i][j] == '#':
      black.append((i, j))

ans = 0
while True:
  ans += 1
  next_black = deque()
  while black:
    bi, bj = black.popleft()
    for i, j in [(bi - 1, bj), (bi + 1, bj), (bi, bj - 1), (bi, bj + 1)]:
      if i >= 0 and i < H and j >= 0 and j < W:
        if M[i][j] == '.':
          M[i][j] = '#'
          next_black.append((i, j))
  if next_black:
     black = copy.copy(next_black)
  else:
     break
print(ans - 1)

### FIXED CODE ###

from collections import deque
import copy
 
def main():
    h, w = map(int, input().split())
    a = [[j == "#" for j in input()] for _ in range(h)]
 
 
    que = deque([(i, j) for i in range(h) for j in range(w) if a[i][j]])
 
    count = 0
    while True:
        count += 1
        nque = deque()
        while que:
            y, x = que.popleft()
            if x > 0 and not a[y][x-1]:
                a[y][x-1] = True
                nque.append((y,x-1))
            if x < w-1 and not a[y][x+1]:
                a[y][x+1] = True
                nque.append((y,x+1))
            if y > 0 and not a[y-1][x]:
                a[y-1][x] = True
                nque.append((y-1,x))
            if y < h-1 and not a[y+1][x]:
                a[y+1][x] = True
                nque.append((y+1,x))
 
        if nque:
            que = copy.copy(nque)
        else:
            break
 
    print(count - 1)

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

A, B, Q = list(map(int, input().split()))
s = [int(input()) for i in range(A)]
t = [int(input()) for i in range(B)]
X = [int(input()) for i in range(Q)]

for x in X:
    s_min = A-1
    for i in range(A):
        if s[i] > x:
            s_min = i-1
            break
    t_min = B-1
    for i in range(B):
        if t[i] > x:
            t_min = i-1
            break

    if s_min == -1:
        if t_min == -1:
            print(max(s[0]-x, t[0]-x))
        elif t_min == B-1:
            print(s[0]-t[t_min]+min(s[0]-x, t[t_min]-x))
        else:
            print(min(t[t_min+1]-x, s[0]-t[t_min]+min(s[0]-x, t[t_min]-x)))
    elif s_min == A-1:
        if t_min == -1:
            print(t[0]-s[s_min] + min(t[0]-x, x-s[s_min]))
        elif t_min == B-1:
            print(max(x-s[s_min], x-t[t_min]))
        else:
            print(min(x-t[t_min], t[t_min+1]-s[s_min] + min(t[t_min+1]-x, x-s[s_min])))
    else:
        if t_min == -1:
            if t[0] < s[s_min+1]:
                print(min(s[s_min + 1] - x, t[0] - s[s_min] + min(t[0] - x, x-s[s_min])))
            else:
                print(t[0]-x)
        elif t_min == B-1:
            print(min(x - s[s_min], s[s_min + 1] - t[t_min] + min(s[s_min + 1] - x, x - t[t_min])))
        else:
            if s[s_min] < t[t_min]:
                if s[s_min+1] < t[t_min+1]:
                    print(min(x-s[s_min], t[t_min+1] - x, s[s_min+1] - t[t_min] + min(x-t[t_min], s[s_min+1]-x)))
                else:
                    print(min(x-s[s_min], s[s_min+1]-x))
            else:
                if s[s_min+1] < t[t_min+1]:
                    print(min(t[t_min+1]-x, x-t[t_min]))
                else:
                    print(min(x-t[t_min], s[s_min+1] - x, t[t_min+1] - s[s_min] + min(x-s[s_min], t[t_min+1]-x)))




### FIXED CODE ###

import bisect
A, B, Q = list(map(int, input().split()))
INF = 10**18
s = [-INF]+[int(input()) for i in range(A)]+[INF]
t = [-INF]+[int(input()) for i in range(B)]+[INF]
X = [int(input()) for i in range(Q)]


for x in X:
    s_min = bisect.bisect_left(s, x)
    t_min = bisect.bisect_left(t, x)

    cost = INF
    for S in [s[s_min-1], s[s_min]]:
        for T in [t[t_min-1], t[t_min]]:
            cost = min(cost, abs(T-S)+abs(T-x), abs(T-S)+abs(S-x))

    print(cost)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
import collections
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
N = int(input())
a = list(int(i) for i in input().split())
ans_list = []
ans = 0
for i in range(N):
	if a[N-1-i] == 1:
		ans += 1
		ans_list.append(N-i)
		chk = make_divisors(N-i)
		for j in range(len(chk)):
			a[chk[j]-1] = (1+a[chk[j]-1])%2
print(ans)
if len(ans_list) != 0:
	print(*ans_list)


### FIXED CODE ###

import sys
input = sys.stdin.readline
import collections
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
N = int(input())
a = list(int(i) for i in input().split())
ans_list = []
ans = 0
for i in range(N):
	if a[N-1-i] == 1:
		ans += 1
		ans_list.append(N-i)
		chk = make_divisors(N-i)
		for j in range(len(chk)):
			a[chk[j]-1] = (1+a[chk[j]-1])%2
print(ans)
if len(ans_list) != 0:
	print(*ans_list)
### BUGGY CODE ###

N, A, B = [int(i) for i in input().split()]
Hn = [int(input()) for _ in range(N)]
dAB = A - B

def check(X):
  base = B * X
  counts = sum([max((h - base + dAB - 1)//dAB, 0) for h in Hn])
  return counts <= X
               
def min_binary_search(check, l=0, r=1000000000000000):
    while r - l > 1:
      mid = (l + r) // 2
      if check(mid):
        r = mid
      else:
        l = mid
    return r
print(min_binary_search(check))

### FIXED CODE ###

N, A, B = [int(i) for i in input().split()]
Hn = [int(input()) for _ in range(N)]
dAB = A - B

def check(X):
  base = B * X
  counts = sum([max((h - base + dAB - 1)//dAB, 0) for h in Hn])
  return counts <= X
               
def min_binary_search(check, l=0, r=100000000000):
    while r - l > 1:
      mid = (l + r) // 2
      if check(mid):
        r = mid
      else:
        l = mid
    return r
print(min_binary_search(check))
### BUGGY CODE ###

numBits = int(input())
bitString = input()

def calculateAndPrintPopcount(n):
  popCount = 0
  while(n > 0):
    n %= bin(n).count('1')
    popCount += 1
  return popCount

count1 = bitString.count('1')
x = int(bitString,2)

for i in range(numBits)  :
  if bitString[i] == '0':
    print(calculateAndPrintPopcount( (x + pow(2,numBits-1-i,(count1+1))) % (count1+1) ) + 1)
  else:
    if (count1-1) == 0:
      print(0)
    else:
      print(calculateAndPrintPopcount( (x - pow(2,numBits-1-i,(count1-1)) ) % (count1-1) ) +1)

### FIXED CODE ###

numBits = int(input())
bitString = input()

def calculateAndPrintPopcount(n):
  popCount = 0
  while(n > 0):
    n %= bin(n).count('1')
    popCount += 1
  return popCount

count1 = bitString.count('1')
x = int(bitString,2)
xPlus = x % (count1 + 1)
if (count1 - 1) == 0:
  xMinus = 0
else:
  xMinus = x % (count1 - 1)

for i in range(numBits)  :
  if bitString[i] == '0':
    print(calculateAndPrintPopcount( (xPlus + pow(2,numBits-1-i,(count1+1))) % (count1+1) ) + 1)
  else:
    if (count1-1) == 0:
      print(0)
    else:
      print(calculateAndPrintPopcount( (xMinus - pow(2,numBits-1-i,(count1-1)) ) % (count1-1) ) +1)
### BUGGY CODE ###

import heapq
def SME(start,end):
    A = []
    if end > N : end = N
    count = 0
    for i,x in enumerate(Whole[start:end]):
        heapq.heappush(A,[x,i])
    for j in range(start,end):
        a = heapq.heappop(A)
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] : continue
                else :
                    ANS[idx] = a[0]
                    count += 1
            except IndexError : continue
        if count > N * 0.97 : break
    for i in range(L):
        if ANS[i] : continue
        else : ANS[i] = min(Whole[:i+1])
    for i in range(L,N):
        if ANS[i] : continue
        else : ANS[i] = min(Whole[i+1-L:i+1])
    return ANS

[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
ANS = [None]*N
ANS = SME(0, N)
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

### FIXED CODE ###

def ascend(a,b):
    mini = min(A[a:a+L])
    ans[a] = mini
    for i in range(a+1,b):
        if A[i+L-1] <= mini : mini = A[i+L-1]
        elif A[i-1] == mini : mini = min(A[i:i+L])
        ans[i] = mini

def descend(a,b):
    mini = min(A[b-1:b+L-1])
    ans[b-1] = mini
    for i in range(b-2,a-1,-1):
        if A[i] <= mini : mini = A[i]
        elif A[i+L] == mini: mini = min(A[i:i+L])
        ans[i] = mini
    
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = [None]*(N-L+1)
count = 0;
if N > 10 ** 4:
    for i in range(100):
        if A[i+1] > A[i] : count += 1
    if count > 80 : descend(0, N-L+1)
    else : ascend(0,N-L+1)
else :
    ascend(0, N-L+1)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
b=[]
if n%2==0:
  for i in range(n):
    if i%2==0:
      b+=[a[i]]
    else:
      b=[a[i]]+b
else:
  for i in range(n):
    if i%2!=0:
      b+=[a[i]]
    else:
      b=[a[i]]+b

ans=''
for i in range(n):
  if i==n-1:
    ans+=str(b[i])
  else:
    ans+=str(b[i])+' '
print(ans)

### FIXED CODE ###

n=int(input())
a=list(input().split())
if n%2==0:
  b=a[-1::-2]+a[0::2]
else:
  b=a[-1::-2]+a[1::2]
ans=''
for i in range(n):
  ans+=b[i]+' '
print(ans[:-1])
### BUGGY CODE ###

from collections import defaultdict
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
G = [[] for _ in range(N+1)]
for _ in range(M):
    A, B = map(int, input().split())
    G[A].append(B)

def dfs(v, o):
    if len(parents[v]) > 1:
        return []

    ancestors.add(v)

    # check c -> ancestor
    for c in G[v]:
        if c in ancestors - {o}:
            ancestors.remove(v)
            return []

    # add to parents
    for c in G[v]:
        parents[c].add(v)

    # check each child
    ret = []
    if any(c == o for c in G[v]):
        ret = [v]
    else:
        for c in G[v]:
            a = dfs(c, o)
            if a:
                ret = [v] + a
                break

    ancestors.remove(v)
    for c in G[v]:
        parents[c].remove(v)
    return ret

for v in range(1, N+1):
    ancestors = set()
    parents = defaultdict(set)
    cand = dfs(v, v)
    if cand:
        print(len(cand))
        print(*cand, sep='\n')
        break
else:
    print(-1)

### FIXED CODE ###

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

N, M = map(int, input().split())
G = [[] for _ in range(N+1)]
for _ in range(M):
    A, B = map(int, input().split())
    G[A].append(B)

def dfs(v, o):
    for c in G[v]:
        if c == o:
            return [v]
    for c in G[v]:
        if visited[c]:
            continue
        visited[c] = True
        ret = dfs(c, o)
        if ret:
            return [v] + ret

for v in range(1, N+1):
    visited = [False] * (N+1)
    cur = dfs(v, v)
    if cur:
        break
else:
    print(-1)
    exit()

while True:
    cur_set = set(cur)
    unused = None
    for i in range(len(cur)):
        u, v = cur[i], cur[(i+1) % len(cur)]
        for c in G[u]:
            if c == v:
                continue
            elif c in cur_set:
                unused = (i, cur.index(c))
                break

    if not unused:
        break
    else:
        t, s = unused
        nxt = []
        i = s
        while i != t:
            nxt.append(cur[i])
            i = (i + 1) % len(cur)
        nxt.append(cur[t])
        cur = nxt

print(len(cur))
print(*cur, sep='\n')
### BUGGY CODE ###

def gen_primes(n: int) -> set:
    if n < 2:
        return set()
    is_prime = [True] * n
    for i in range(3, n, 2):
        if is_prime[i]:
            is_prime[i * i:: 2 * i] = [False] * ((n - i * i - 1) // (2 * i) + 1)
    return {2} | {i for i in range(3, n, 2) if is_prime[i]}

import sys
input = lambda: sys.stdin.readline().rstrip()  
  
q = int(input())
primes = gen_primes(10**5)

for i in range(q):
  l,r = map(int,input().split())
  ans = 0
  for p in primes:
    if (l <= p <= r) and (p+1)//2 in primes:
      ans += 1
  print(ans)

### FIXED CODE ###

from math import ceil,sqrt
from bisect import bisect_right, bisect_left

def trial_division(n):  
  if n == 2:
    return True
  if n < 2 or n % 2 == 0:
    return False
  for i in range(3, int(ceil(sqrt(n))) + 1, 2):
    if n % i == 0:
      return False
  return True

import sys
input = lambda: sys.stdin.readline().rstrip()
q = int(input())

primes = [i for i in range(10**5+10) if trial_division(i)]  
p2017 = []
for i in range(len(primes)-1):
  if trial_division((primes[i]+1)//2):
    p2017.append(primes[i])
    
for i in range(q):
  l,r = map(int,input().split())  
  print(bisect_right(p2017,r) - bisect_left(p2017,l))
### BUGGY CODE ###

h, w = list(map(int, input().split()))
s = [input() for i in range(h)]
visited = [[0 for i in range(w)] for i in range(h)]

ans = 0
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]


def dfs(x, y):
  cur = 1
  if s[y][x]=="#":
    return 0

  for dxt, dyt in zip(dx, dy):
    xx, yy = x, y
    while True:
      nx = xx+dxt
      ny = yy+dyt
      if 0<=ny<h and 0<=nx<w and s[ny][nx]==".":
        cur += 1
      else:
        break
      xx, yy = nx, ny

  return cur


for i in range(h):
  for j in range(w):
    ans = max(ans, dfs(j, i))
print(ans)

### FIXED CODE ###

h, w = list(map(int, input().split()))
s = [input() for i in range(h)]
yoko = [[0 for i in range(w)] for i in range(h)]
tate = [[0 for i in range(w)] for i in range(h)]

ans = 0
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]


for i in range(h):
  cur = 0
  b = 0
  e = 0
  flag = 0
  for j in range(w):
    if s[i][j]=="." and j==w-1:
      cur += 1
      e = j
      for k in range(b, e+1):
        yoko[i][k] = cur
      cur = 0
    elif flag and s[i][j]==".":
      cur += 1
    elif not flag and s[i][j]==".":
      cur = 1
      flag = 1
      b = j
    elif flag and s[i][j]=="#":
      flag = 0
      e = j-1
      for k in range(b, e+1):
        yoko[i][k] = cur
      cur = 0
      b = j+1
    elif s[i][j]=="." and j==w-1:
      cur += 1
      e = j-1
      for k in range(b, e+1):
        yoko[i][k] = cur
      cur = 0
    else:
      b = j+1


for j in range(w):
  cur = 0
  b = 0
  e = 0
  flag = 0
  for i in range(h):
    if s[i][j]=="." and i==h-1:
      cur += 1
      e = i
      for k in range(b, e+1):
        tate[k][j] = cur
      cur = 0
    if flag and s[i][j]==".":
      cur += 1
    elif not flag and s[i][j]==".":
      cur = 1
      flag = 1
      b = i
    elif flag and s[i][j]=="#":
      flag = 0
      e = i-1
      for k in range(b, e+1):
        tate[k][j] = cur
      cur = 0
      b = i+1
    elif s[i][j]=="." and i==h-1:
      cur += 1
      e = i-1
      for k in range(b, e+1):
        tate[k][j] = cur
      cur = 0
    else:
      b = i+1

ans = 0
for i in range(h):
  for j in range(w):
    if yoko[i][j]>0 and tate[i][j]>0:
      ans = max(ans, yoko[i][j]+tate[i][j]-1)
    else:
      ans = max(ans, yoko[i][j]+tate[i][j])
print(ans)
### BUGGY CODE ###

a, b, x = map(int, input().split())
key = 0
count = 0

if a == b:
    if a % x == 0:
        print(1)
        exit()
    else:
        print(0)
        exit()

for i in range(a, b + 1, 1):
    if i % x == 0:
        key = i
        count += 1
        ans = count + (b - key) // x
        print(ans)
        exit()

### FIXED CODE ###

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

big = b // x + 1
small = (a - 1) // x + 1

ans = big - small
if ans < 0:
    ans = 0

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

n,q=map(int,input().split())
s=str(input())
s=list(s)
for i in range(0,q):
  l,r=map(int,input().split())
  temp=s[l-1:r]
  temp="".join(temp)
  temp2=temp.replace("AC","")
  print(int((len(temp)-len(temp2))/2))

### FIXED CODE ###

n,q=map(int,input().split())
s=str(input())
a=[0]*n
s=list(s)
for i in range(1,n):
  temp=0
  if s[i]=="C" and s[i-1]=="A":
    temp=1
  a[i]=a[i-1]+temp
for i in range(0,q):
  l,r=map(int,input().split())
  print(a[r-1]-a[l-1])
### BUGGY CODE ###

import itertools

N, M, _ = map(int, input().split())
R = list(map(int, input().split()))
E = [[10 ** 8 for _ in range(N)] for __ in range(N)]
for _ in range(M):
    A, B, C = map(int, input().split())
    A -= 1
    B -= 1
    E[A][B] = C
    E[B][A] = C

for v in range(N):
    for d in range(N):
        for w in range(N):
            E[v][w] = min(E[v][w], E[v][d] + E[d][w])

res = 10 ** 8
for case in itertools.permutations(range(len(R))):
    tmp = 0
    p = None
    for v in case:
        v -= 1
        if p is None:
            p = v
            continue
        tmp += E[p][v]
        p = v
    res = min(res, tmp)

print(res)

### FIXED CODE ###

import itertools

N, M, r = map(int, input().split())
R = list(map(int, input().split()))
E = [[10 ** 20 if i != j else 0 for i in range(N)] for j in range(N)]
for _ in range(M):
    A, B, C = map(int, input().split())
    A -= 1
    B -= 1
    E[A][B] = C
    E[B][A] = C

for d in range(N):
    for v in range(N):
        for w in range(N):
            E[v][w] = min(E[v][w], E[w][v], E[v][d] + E[d][w])
            E[w][v] = E[v][w]

res = 10 ** 20
for case in itertools.permutations(R):
    tmp = 0
    c = list(case)
    for i in range(r - 1):
        tmp += E[c[i] - 1][c[i + 1] - 1]
    res = min(res, tmp)

print(res)
### BUGGY CODE ###

n, k, l = map(int, input().split())
load = list(range(n + 1))
train = list(range(n + 1))

def find(x, u):
    if u[x] == x :
        return x
    else:
        return find(u[x],u)

for i in range(k):
    p, q = map(int, input().split())
    rp = find(p, load)
    rq = find(q, load)
    if rp != rq:
        root = min(rp, rq)
        load = [root if (x==p)|(x==q)|(x==rq)|(x==rp) else x for x in load]

for i in range(l):
    r, s = map(int, input().split())
    rr = find(r, train)
    rs = find(s, train)
    if rr != rs:
        root = min(rr, rs)
        train = [root if (x==r)|(x==s)|(x==rr)|(x==rs) else x for x in train]

ans = []
for x, y in zip(load, train):
    if x == -1 or y == -1:
        ans.append(1)
    else:
        ans.append(sum([(x == X and y == Y) for X, Y in zip(load,train)]))

print(*ans[1:])

### FIXED CODE ###

n, k, l = map(int, input().split())
load = [-1] * (n + 1)
train = [-1] * (n + 1)

def find_load(x, u = load):
    if u[x] < 0 :
        return x
    else:
        u[x] = find_load(u[x])
        return u[x]

def find_train(x, u = train):
    if u[x] < 0 :
        return x
    else:
        u[x] = find_train(u[x])
        return u[x]

for i in range(k):

    p, q = map(int, input().split())
    p, q = map(find_load, [p, q])
    p, q = sorted((p, q))
    if p != q:
        load[q] = p

load = [i if x < 0 else x for i, x in enumerate(load)]

for i in range(l):
    r, s = map(int, input().split())
    r, s = map(find_train, [r, s])
    r, s = sorted((r, s))
    if r != s:
        train[s] = r
train = [i if x < 0 else x for i, x in enumerate(train)]

keys = []
dic  = {}

for node in range(n):
    key = (find_load(load[node + 1]), find_train(train[node + 1]))
    keys.append(key)
    if key in dic:
        dic[key] += 1
    else:
        dic[key] = 1

ans = [str(dic[key]) for key in keys]
print(" ".join(ans))
### BUGGY CODE ###

def DP():
  H,N = map(int,input().split())
  
  #dpテーブルの設定と初期化
  dp = [0] + [10 ** 9] * H
  
  #各魔法について
  for i in range(N):
    #d,cはそれぞれ魔法ダメージと魔法のコスト
    d,c = map(int,input().split())
    #dpテーブルの各HPについて
    for j in range(H + 1):
      k = max(j - d,0)
      #ダメージjを与える時のコストについて、
      #魔法iを新たに使った場合と、既存の最小コストを比較し更新する
      l = dp[k] + c
      dp[j] = min(dp[j],l)
 
  print(dp[-1])
  
DP()

### FIXED CODE ###

def main():
    h,n,*t=map(int,open(0).read().split())
    d=[0]+[10**18]*h
    for a,b in zip(*[iter(t)]*2):
        for j in range(h+1):
            k=j-a
            if k<0:k=0
            c=d[k]+b
            if c<d[j]:d[j]=c
    print(d[h])
main()
### BUGGY CODE ###

def resolve():
    n, a, b = map(int, input().split())
    lis = []
    while True:
        for i in range(a):
            lis.append("b")
        if len(lis) >= n:
            break
        for j in range(b):
            lis.append("r")
        if len(lis) >= n:
            break
    print(lis[0:n].count("b"))


if __name__ == "__main__":
    resolve()

### FIXED CODE ###

def resolve():
    n,a,b = map(int, input().split())
    if a ==0:
        print(0)
    else:
        ans=0
        tmp = n //(a+b)
        ans += a*tmp
        if n - (a+b)*tmp >a :
            ans +=a
        else:
            ans += n - (a+b)*tmp
        
        print(ans)

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

N = int(input().split()[0])
a_list = list(map(int, input().split()))

mod = 10 ** 9 + 7
total = 0
for i, a in enumerate(a_list):
    for j in range(len(a_list) - (i + 1)):
        total += (a * a_list[i + 1 + j]) % mod
total = total % mod
ans = total
print(ans)

### FIXED CODE ###

#!/usr/bin/env python3

N = int(input().split()[0])
a_list = list(map(int, input().split()))

mod = 10 ** 9 + 7
sum_a = sum(a_list)
total = 0
for i, a in enumerate(a_list):
    total += (a * (sum_a - a)) % mod
    sum_a -= a
total = total % mod
ans = total
print(ans)
### BUGGY CODE ###

n=int(input())
x=[x for x in input().split()]
for i in range(1,n+1):
    print(x.count(str(i)))

### FIXED CODE ###

n=int(input())
x=input().split()
l=[0 for i in range(n)]
for i in range(n-1):
    l[int(x[i])-1]=l[int(x[i])-1]+1
for i in range(n):
    print(l[i])
### BUGGY CODE ###

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

E = [sum(range(1, i+1)) / i for i in p]
ans = 0
for i in range(N - K + 1):
    s = sum(E[i:i+K])
    ans = max([ans, s])
print(ans)

### FIXED CODE ###

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

E = [(i + 1)/2 for i in p]
S = sum(E[0:K])
ans = S
for i in range(1, N - K + 1):
    S += E[i+K-1] - E[i-1]
    if ans < S:
        ans = S
print(ans)
### BUGGY CODE ###

import functools
from operator import mul


n = int(input())

nums = list(map(int, input().split()))

product = functools.reduce(mul, nums, 1)

if product > 1e18:
    product = -1

print(product)


### FIXED CODE ###

n = int(input())

nums = list(map(int, input().split()))

product = 1

for num in nums:
    product *= num

    if product > 1e18:
        product = -1
        break

if 0 in nums:
    product = 0

print(product)