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

import queue
H, W = map(int, input().split())
S= [input() for i in range(H)]

ans=-1

def dfs(start,goal):
    distance=[[-1]*H for j in range(W)]
    li_x=[1,-1,0,0]
    li_y=[0,0,1,-1]
    q = queue.Queue()
    q.put(start)
    distance[start[0]][start[1]]=0

    while not q.empty():
        hoge=q.get()
        x=hoge[0]
        y=hoge[1]
        dis=distance[x][y]

        for i in range(4):
            x1=x+li_x[i]
            y1=y+li_y[i]
            if (0 <=x1 < W and 0 <= y1 < H):
                if distance[x1][y1] == -1:
                    if S[y1][x1]=='.':
                        q.put([x1,y1])
                        distance[x1][y1]=dis+1

    return distance[goal[0]][goal[1]]

done=[]
for sx in range(W):
    for gx in range(W):
        for sy in range(H):
            for gy in range(H):
                if S[sy][sx]=='.' and S[gy][gx]=='.':
                    if [gx,gy,sx,sy] not in done:
                        re=dfs([sx,sy],[gx,gy])
                        done.append([sx,sy,gx,gy])
                        if re > ans:
                            ans=re

print(ans)


### FIXED CODE ###

import queue
from itertools import product

H, W = map(int, input().split())
S= [input() for i in range(H)]

ans=-1

def bfs(start):
    distance=[[-1]*H for j in range(W)]
    li_x=[1,-1,0,0]
    li_y=[0,0,1,-1]
    q = queue.Queue()
    q.put(start)
    distance[start[0]][start[1]]=0

    while not q.empty():
        hoge=q.get()
        x=hoge[0]
        y=hoge[1]
        dis=distance[x][y]

        for i in range(4):
            x1=x+li_x[i]
            y1=y+li_y[i]
            if (0 <=x1 < W and 0 <= y1 < H):
                if distance[x1][y1] == -1:
                    if S[y1][x1]=='.':
                        q.put([x1,y1])
                        distance[x1][y1]=dis+1
    m=[]
    for i in range(W):
        m.extend(distance[i])
    return max(m)

for sx,sy in product(range(W),range(H)):

                if S[sy][sx]=='.':
                    re=bfs([sx,sy])
                    if re > ans:
                        ans=re

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

#!/usr/bin/env python3
import sys


def solve(s: str, K: int):
    sl = set()

    for i in range(len(s)):
        for j in range(i,len(s)):
            sl.add(s[i:j+1])

    sl = list(sorted(sl))   
    # print(sl)
    print(sl[K-1])

    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    K = int(next(tokens))  # type: int
    solve(s, K)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(s: str, K: int):
    sl = set()

    for i in range(len(s)):
        for j in range(i,min(i+K,len(s))):
            sl.add(s[i:j+1])

    sl = list(sorted(sl))   
    # print(sl)
    print(sl[K-1])

    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    K = int(next(tokens))  # type: int
    solve(s, K)

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

n = int(input())
ans = ""
a = list(map(int,input().split()))
for i in range(n):
    b = a.index(i+1)
    ans += str(b+1)
    if i != n-1:
        ans += " "
print(ans)

### FIXED CODE ###

n = int(input())
b = ""
ans = [0 for i in range(n)]
a = list(map(int,input().split()))
for i in range(n):
    ans[a[i]-1] = i+1
for i in range(n):
    b += str(ans[i])
    if i != n-1:
        b += " "
print(b)
### BUGGY CODE ###

#
# agc012 a
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2
5 2 8 5 1 5"""
        output = """10"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """10
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000"""
        output = """10000000000"""
        self.assertIO(input, output)


def resolve():
    N = int(input())
    a = list(map(int, input().split()))
    a.sort()
    ans = 0
    for i in range(N):
        a.pop(0)
        a.pop()
        ans += a.pop()
    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()


### FIXED CODE ###

#
# agc012 a
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2
5 2 8 5 1 5"""
        output = """10"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """10
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000"""
        output = """10000000000"""
        self.assertIO(input, output)


def resolve():
    N = int(input())
    a = list(map(int, input().split()))
    a.sort()
    ans = 0
    for i in range(N):
        a.pop()
        ans += a.pop()
    print(ans)


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

import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

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

def divisor(N):
	divisor_list = []
	n = int((N ** 0.5) // 1)
	for i in range(1, n):
		if N % i == 0:
			divisor_list.append(i)
			divisor_list.append(int(N // i))
	#平方数かどうかで場合分け
	if n ** 2 == N:
		divisor_list.append(n)
	else:
		if N % n == 0:
			divisor_list.append(n)
			divisor_list.append(int(N // n))

	return sorted(divisor_list)

#処理内容
def main():
	N = int(input())
	A = getlist()
	DD = defaultdict(int)
	for i in range(N):
		DD[A[i]] += 1

	ans = N
	for i in range(N):
		DD[A[i]] -= 1
		div = divisor(A[i])
		for j in div:
			if DD[j] >= 1:
				ans -= 1
				break
		DD[A[i]] += 1

	print(ans)

if __name__ == '__main__':
	main()

### FIXED CODE ###

import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

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

num = 10 ** 6 + 1 #適当に値を入れる
L = [0 for i in range(num)]
ans = 0
N = int(input())
A = getlist()
for i in range(N):
	L[A[i]] += 1

for i in range(num):
	if L[i] >= 1:
		if L[i] == 1:
			ans += 1
		c = 2
		while i * c <= num - 1:
			L[i * c] = 0; c += 1

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

INF=10**18
H,W=map(int,input().split())
A=[list(map(int,input().split())) for i in range(H)]
for i in range(H):
    B=list(map(int,input().split()))
    for j in range(W):
        A[i][j]=abs(A[i][j]-B[j])

dp=[[[False]*(80*H*W-1) for i in range(W)] for i in range(H)]
dp[0][0][A[0][0]]=True
for i in range(H):
    for j in range(W):
        for x,y in [(0,1),(1,0)]:
            nx,ny=i+x,j+y
            if nx>=H or ny>=W:
                continue
            for x in range(81):
                if dp[i][j][x]:
                    if x+A[nx][ny]<=80:
                        dp[nx][ny][x+A[nx][ny]]=True
                        dp[nx][ny][abs(x-A[nx][ny])]=True
for x in range(81):
    if dp[i][j][x]:
        print(x)
        exit()

### FIXED CODE ###

H,W=map(int,input().split())
A=[list(map(int,input().split())) for i in range(H)]
for i in range(H):
    B=list(map(int,input().split()))
    for j in range(W):
        A[i][j]=abs(A[i][j]-B[j])
D=80*(H+W)+1
D2=D*2
dp=[[0]*W for i in range(H)]
dp[0][0]|=1<<(D+A[0][0])
dp[0][0]|=1<<(D-A[0][0])
for i in range(H):
    for j in range(W):
        if i:
            dp[i][j]|=dp[i-1][j]<<A[i][j]
            dp[i][j]|=dp[i-1][j]>>A[i][j]
        if j:
            dp[i][j]|=dp[i][j-1]<<A[i][j]
            dp[i][j]|=dp[i][j-1]>>A[i][j]
res=dp[-1][-1]
ans=10**18
for i in range(D2):
    if res>>i&1:
        ans=min(ans,abs(D-i))
print(ans)
### BUGGY CODE ###

import sys
from collections import deque, defaultdict
import copy
import bisect
#input=sys.stdin.readline
sys.setrecursionlimit(10 ** 9)


N, Q = list(map(int, input().split()))
STX=[]
D=[]
for i in range(N):
    S, T, X = list(map(int, input().split()))
    bisect.insort(STX, (X, S, T))
for i in range(Q):
    D.append(int(input()))

skip = [-1 for i in range(Q)]

dist = [10000000000000 for i in range(Q)]

for (X, S, T) in STX:
    s = S - X
    t = T - X - 1
    a = bisect.bisect_left(D, s)
    b = bisect.bisect_right(D, t)
    #print(D)
    j = a
    while j < b:
        if skip[j] == -1:
            skip[j] = b
            dist[j] = X
            j+=1
        else:
            j=skip[j]



for i in range(Q):
    if dist[i] > 100000000000:
        print(-1)
    else:
        print(dist[i])

### FIXED CODE ###

import sys
from collections import deque, defaultdict
import copy
import bisect
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 9)


N, Q = list(map(int, input().split()))
STX=[]
D=[]
for i in range(N):
    S, T, X = list(map(int, input().split()))
    STX.append((X, S, T))
STX = sorted(STX, key=lambda x: x[0])

for i in range(Q):
    D.append(int(input()))

skip = [-1]*Q

dist = [-1]*Q

for X, S, T in STX:
    s = S - X
    t = T - X - 1
    a = bisect.bisect_left(D, s)
    b = bisect.bisect_right(D, t)
    #print(D)
    j = a
    while j < b:
        if skip[j] == -1:
            skip[j] = b
            dist[j] = X
            j+=1
        else:
            j=skip[j]


for i in range(Q):
    print(dist[i])
### BUGGY CODE ###

# -*- coding: utf-8 -*-
H, W = map(int, input().split())
map = [list(input()) for i in range(H)]
queue = list()
for x in range(H):
    for y in range(W):
        if map[x][y]=="#":
            queue.append([x, y])
count = -1
while queue:
    next_queue = list()
    for x, y in queue:
        for nx, ny in [[x-1, y], [x+1, y], [x, y-1], [x, y+1]]:
            if 0<=nx<H and 0<=ny<W:
                if map[nx][ny]==".":
                    map[nx][ny] = "#"
                    next_queue.append([nx, ny])
    queue = next_queue
    count += 1
print(count)


### FIXED CODE ###

# -*- coding: utf-8 -*-
from collections import deque
H, W = map(int, input().split())
map = [list(input()) for i in range(H)]
checked = list()
queue = deque()
for x in range(H):
    checked.append(list())
    for y in range(W):
        if map[x][y]=="#":
            checked[x].append(True)
            queue.append((x, y, 0))
        else:
            checked[x].append(False)
neighbors = [(1,0), (0,1), (-1,0), (0,-1)]
while queue:
    x, y, res = queue.popleft()
    for dx, dy in neighbors:
        nx, ny = x+dx, y+dy
        if 0<=nx<H and 0<=ny<W:
            if not checked[nx][ny]:
                queue.append((nx, ny, res+1))
                checked[nx][ny] = True
print(res)
### BUGGY CODE ###

"""Coloring Edges on Tree
https://atcoder.jp/contests/abc146/tasks/abc146_d
"""
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 5 + 1)

class Node:
    def __init__(self, num):
        self.num = num
        self.edge = set()
        self.edge_color = set()


def dfs(node, p):
    used_color = node.edge_color
    for e in node.edge:
        if e != p:
            # 子のノードを取得
            child = tree[e]
            child_used_color = child.edge_color

            # このnodeと子のノードでまだ使っていない色を特定
            unused_colors = colors - (used_color | child_used_color)
            if len(unused_colors) == 0:
                color_num = max(colors) + 1
                colors.add(color_num)
            else:
                color_num = min(unused_colors)

            # このノードと、子のノードに使用ずみの色をマーク
            node.edge_color.add(color_num)
            child.edge_color.add(color_num)

            # 答えを記録
            ans['{a} {b}'.format(a=node.num, b=child.num)] = color_num
            ans['{a} {b}'.format(a=child.num, b=node.num)] = color_num

            # 掘る
            dfs(child, node.num)


N = int(input())
ans = {}
colors = {1}

# treeの初期化
tree = [Node(i) for i in range(0, N + 1)]
edges = []
for i in range(N - 1):
    inp = input()
    edges.append(inp.rstrip('\n'))
    a, b = map(int, inp.split())
    tree[a].edge.add(b)
    tree[b].edge.add(a)

dfs(tree[1], -1)

# print("edges:{}".format(edges))
print(len(colors))
# print(ans)
for edge in edges:
    # print(edge)
    print(str(ans.get(edge)))


### FIXED CODE ###

"""Coloring Edges on Tree
https://atcoder.jp/contests/abc146/tasks/abc146_d
"""
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 5 + 1)

class Node:
    def __init__(self, num):
        self.num = num
        self.edge = set()
        self.edge_color = set()


def dfs(node, c = -1 , p = -1):
    k = 1    
    for e in node.edge:
        if e == p:
            continue
        if k == c:
            k += 1
        # 子のノードを取得
        child = tree[e]

        # 答えを記録
        if a < b:
            ans['{0} {1}'.format(node.num, child.num)] = k
        else:
            ans['{0} {1}'.format(child.num, node.num)] = k
        k += 1

        # 掘る
        dfs(child,k - 1, node.num)


N = int(input())
ans = {}
# colors = {1}

# treeの初期化
tree = [Node(i) for i in range(0, N + 1)]
edges = []
for i in range(N - 1):
    a, b = map(int, input().split())
    tree[a].edge.add(b)
    tree[b].edge.add(a)
    if a < b:
        edges.append('{0} {1}'.format(a, b))
    else:
        edges.append('{0} {1}'.format(b, a))

dfs(tree[1], -1)

# print("edges:{}".format(edges))
# print(max(c))
# print(ans)
count = 0
for node in tree:
    count = max(count, len(node.edge))
print(count)
for edge in edges:
    # print(edge)
    print(str(ans.get(edge)))
### BUGGY CODE ###

n, k, q = map(int, input().split())
A = []
for _ in range(q):
    a = int(input())
    A.append(a)

p = [k]*n
for i in range(len(A)):
    ele = A[i]-1
    for j in range(len(p)):
        if j != ele:
            p[j] = p[j]-1
    
for l in range(len(p)):
    if p[l] > 0:
        print('Yes')
    elif p[l] <= 0:
        print('No')

### FIXED CODE ###

n, k, q = map(int, input().split())
A = []
for _ in range(q):
    a = int(input())
    A.append(a)
    
p = [k-q]*n
for i in range(len(A)):
    val = A[i]-1
    p[val] += 1

for l in range(len(p)):
    if p[l] > 0:
        print('Yes')
    elif p[l] <= 0:
        print('No')
### BUGGY CODE ###

N, K = map(int, input().split())
P = list(map(int,input().split()))
for i in range(N-K+1):
  sum_ = 0
  p = P[i:i+K]
  sum_ = (sum(p)+K)/2

  if i == 0:
    ans = sum_
  else:
    if sum_ > ans:
      ans = sum_
    else:
      continue
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

N, K = map(int, input().split())
P = list(map(int,input().split()))
out_ = 0
p = P[0:K]
base = sum(p)
if N == K:
  answer = (sum(p)+K)/2
else:
  for i in range(N-K):
    out_ += P[i+K]-P[i]
    if i == 0:
      ans = out_
    else:
      if out_ > ans:
        ans = out_
      else:
        continue
  answer = (base+ans+K)/2
print(answer)
### BUGGY CODE ###

N,M=map(int,input().split())
list1=[[]for i in range(N)]
list2=[]
for i in range(M):
    A=input()
    A=A.rstrip().split()
    P=int(A[0])
    Y=int(A[1])
    list1[P-1].append(Y)
    list2.append([P,Y])
#print(list1)
for j in range(N):
    list1[j].sort()
#print(list1)
for k in range(M):
    ansP="0"*(6-len(str(list2[k][0])))+str(list2[k][0])
    ansY="0"*(6-len(str(list1[list2[k][0]-1].index(list2[k][1])+1)))+str(list1[list2[k][0]-1].index(list2[k][1])+1)
    ans=ansP+ansY
    print(ans)

### FIXED CODE ###

import bisect
N,M=map(int,input().split())
A=[[]for i in range(N)]
L=[]

for i in range(M):
    P,Y=map(int,input().split())
    A[P-1].append(Y)
    L.append([P-1,Y])
#print(A)
#print(L)

for j in range(N):
    A[j].sort()
#print(A)

for k in range(len(L)):
    ans1=str((L[k][0]+1)+1000000)
    ans1=ans1[1:]
    ans2=bisect.bisect_left(A[L[k][0]],L[k][1])
    ans2=str(ans2+1+1000000)
    ans2=ans2[1:]
    print(ans1+ans2)
### BUGGY CODE ###

def main():
    s = input()
    q = int(input())
    for _ in range(q):
        query = input().split()
        if query[0] == "1":
            s = s[::-1]
        else:
            if query[1] == '1':
                s = query[2] + s
            else:
                s = s + query[2]
    print(s)


if __name__ == "__main__":
    main()


### FIXED CODE ###

from collections import deque


def main():
    s = deque(list(input()))
    q = int(input())
    rev = False
    for _ in range(q):
        query = input().split()
        if query[0] == "1":
            if not rev:
                rev = True
            else:
                rev = False
        else:
            if query[1] == '1':
                pass
                if rev:
                    s.append(query[2])
                else:
                    s.appendleft(query[2])
            else:
                if rev:
                    s.appendleft(query[2])
                else:
                    s.append(query[2])
    if rev:
        s.reverse()
    print(*s, sep="")


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

N = int(input())
A = list(map(int,input().split()))
for i in range(1,N+1):
  print(str(A.index(i)+1) + ' ', end = '')

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
D = [0]*N
for i in range(N):
  a = A[i]
  D[a-1] = i+1
d = str(D[0])
for i in range(1,N):
  d += ' '+str(D[i])
print(d)
### BUGGY CODE ###

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
cnt = 0
m = [0] * n
for i in range(0, n):
    for j in range(cnt):
        if m[j] < a[i]:
            m[j] = a[i]
            break
    else:
        m[cnt] = a[i]
        cnt += 1
print(cnt)

### FIXED CODE ###

import bisect
import collections
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
m = collections.deque([])
for i in range(0, n):
    j = bisect.bisect_left(m, a[i])
    if j == 0:
        m.appendleft(a[i])
    else:
        m[j - 1] = a[i]
print(len(m))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
import numpy as np

n= int(input())
A = [int(a) for a in input().split()]

A = np.array(A)
Ones = np.array([1]*(n-1))

for i in range(n-1):
    A = A -Ones
    print(n-1 -len(np.nonzero(A)[0]))
print("0")


### FIXED CODE ###

import sys
input = sys.stdin.readline

n = int(input())
A = [int(a) for a in input().split()]

sub_list = [0] *n

for a in A:
  sub_list[a-1] +=1

for i in range(n):
  print(sub_list[i])
### BUGGY CODE ###

A,B,C,D=map(int,input().split())
sum=0
for i in range(A,B+1):
    #if(i%C!=0 and i%D!=0):
    if(i%C!=0):
        if(i%D!=0):
            sum+=1

print(sum)


### FIXED CODE ###

import fractions

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

sum1=(A-1)//C
sum2=B//C
sum3=sum2-sum1
sum1=(A-1)//D
sum2=B//D
sum4=sum2-sum1
num=(C*D)//fractions.gcd(C,D)
sum1=(A-1)//num
sum2=B//num
sum5=sum2-sum1
sum=sum3+sum4-sum5
sum=B-A+1-sum


print(sum)
### BUGGY CODE ###

[N,L] = [int(x) for x in input().split()]
A = {}
B = [0]*N
ANS = {}
count = 0
for i,x in enumerate(input().split()):
    i = int(i)
    x = int(x)
    B[i] = x
    if x in A : A[x] += [i]
    else : A[x] = [i]
for i in A:
    j=1
    while j < len(A[i]) - 1:
        if A[i][j+1]-A[i][j-1] < L :
            del A[i][j]
            continue
        j += 1
for i in sorted(A) :
    for j in A[i] :
        for k in range(L) :
            if j + k not in ANS :
                ANS[j+k] = i
                count += 1
    if count > N * 0.997 : break
        
for i in range(L):
    if i not in ANS : ANS[i] = min(B[:i+1])
for i in range(L,N):
    if i not in ANS : ANS[i] = min(B[i+1-L:i+1])
for i in range(L-1,N-1) : print(ANS[i], end=" ")
print(ANS[N-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,A,B=map(int, input().split())
C=0

#for i in range(N):
while N>=0:
	for j in range(A):
		if N==0:
			break
		C+=1
		N-=1
	for k in range(B):
		N=N-1
print(C)

### FIXED CODE ###

N,A,B=map(int, input().split())
ans=N//(A+B)*A
i=N%(A+B)
ans+=min(i,A)
print(ans)
### BUGGY CODE ###

def II(): return int(input())
def LI(): return [int(i) for i in input().split()]

N, K = LI()
H = LI()

cost = [0] * N
cost[0] = 0
for n in range(1, N):
  MIN = min(
  	[ cost[n-k]+abs(H[n-k]-H[n]) for k in range(1, min(n+1, K+1)) ]
  )
  cost[n] = MIN

print(cost[-1])

### FIXED CODE ###

#  def II(): return int(input())
#def LI(): return [int(i) for i in input().split()]

#N, K = LI()
#H = LI()

#cost = [0] * N
#cost[0] = 0
#for n in range(1, N):
#  cost[n] = min([ cost[n-k]+abs(H[n-k]-H[n]) for k in range(1, min(n+1, K+1)) ])

#print(cost[-1])

def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    a = [0] * n
    a[0] = 0
    for i in range(1, n):
        a[i] = min([a[j] + abs(h[i] - h[j]) for j in range(max(0, i - k), i)])
    print(a[-1])
 
if __name__ == '__main__':
    main()