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

import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    r, c, k = ns()

    mat = [[0 for _ in range(c + 1)] for __ in range(r + 1)]
    for _ in range(k):
        x, y, v = ns()
        x, y = x - 1, y - 1
        mat[x][y] = v

    dp = [[[0 for ___ in range(4)] for _ in range(c + 1)] for __ in range(r + 1)]

    for i in range(r):
        for j in range(c):
            for n in range(2, -1, -1):
                dp[i][j][n + 1] = max(dp[i][j][n + 1], dp[i][j][n] + mat[i][j])

            dp[i + 1][j][0] = max(dp[i][j])
            for n in range(4):
                dp[i][j + 1][n] = max(dp[i][j + 1][n], dp[i][j][n])

    print(max(dp[r - 1][c - 1]))


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    r, c, k = ns()

    mat = [[0 for _ in range(c + 1)] for __ in range(r + 1)]
    for _ in range(k):
        x, y, v = ns()
        x, y = x - 1, y - 1
        mat[x][y] = v

    dp = [[0] * 4 for _ in range(c + 1)]

    for i in range(r):
        ndp = [[0] * 4 for _ in range(c + 1)]
        for j in range(c):
            for n in range(2, -1, -1):
                dp[j][n + 1] = max(dp[j][n + 1], dp[j][n] + mat[i][j])

            ndp[j][0] = max(dp[j])
            for n in range(4):
                dp[j + 1][n] = max(dp[j + 1][n], dp[j][n])
        dp = ndp

    print(max(dp[c - 1]))


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

from itertools import product

h, w = map(int, input().split())
maze = [input() for _ in range(h)]


def neighbors(ih, iw):
    for ih1, iw1 in (
        (ih - 1, iw),
        (ih + 1, iw),
        (ih, iw - 1),
        (ih, iw + 1),
    ):
        if 0 <= ih1 < h and 0 <= iw1 < w and maze[ih1][iw1] == '.':
            yield (ih1, iw1)



def len_maze(ih, iw):
    # BFS
    if maze[ih][iw] == '#':
        return 0

    stepped = [[False] * w for _ in range(h)]
    q0 = [(ih, iw)]
    l = -1
    while q0:
        q1 = []
        for ih0, iw0 in q0:
            stepped[ih0][iw0] = True
            for ih1, iw1 in neighbors(ih0, iw0):
                if not stepped[ih1][iw1]:
                    q1.append((ih1, iw1))
        q0 = q1
        l += 1

    return l


answer = max(len_maze(ih, iw) for ih, iw in product(range(h), range(w)))
print(answer)


### FIXED CODE ###

from itertools import product

h, w = map(int, input().split())
maze = [input() for _ in range(h)]


def neighbors(ih, iw):
    for ih1, iw1 in (
        (ih - 1, iw),
        (ih + 1, iw),
        (ih, iw - 1),
        (ih, iw + 1),
    ):
        if 0 <= ih1 < h and 0 <= iw1 < w and maze[ih1][iw1] == '.':
            yield (ih1, iw1)



def len_maze(ih, iw):
    # BFS
    if maze[ih][iw] == '#':
        return 0

    stepped = [[False] * w for _ in range(h)]
    q0 = [(ih, iw)]
    l = -1
    while q0:
        q1 = set()
        for ih0, iw0 in q0:
            stepped[ih0][iw0] = True
            for ih1, iw1 in neighbors(ih0, iw0):
                if not stepped[ih1][iw1]:
                    q1.add((ih1, iw1))
        q0 = list(q1)
        l += 1

    return l


answer = max(len_maze(ih, iw) for ih, iw in product(range(h), range(w)))
print(answer)
### BUGGY CODE ###

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

LR = [map(int, input().split()) for _ in range(K)]
MOD = 998244353
dic = set()
for l, r in LR:
    for i in range(l, r+1):
        dic.add(i)
dic = list(dic)
dic.sort()
dp = [0]*(N+1)
dp[1] = 1

n = len(dic)
cnt = 0
t = []
for i in range(2, N+1):
    tmp = i-1
    while cnt < n:
        if dic[cnt] <= tmp:
            t.append(dic[cnt])
            cnt += 1
        else:
            break
    for s in t:
        dp[i] += dp[i-s]
        dp[i] %= MOD
print(dp[-1])


### FIXED CODE ###

def main():
    N, K = map(int, input().split())

    LR = [list(map(int, input().split())) for _ in range(K)]
    MOD = 998244353

    dp = [0]*(N+1)
    S = [0]*(N+1)
    dp[1] = 1
    S[1] = 1

    for i in range(2, N+1):
        for l, r in LR:
            if i-l < 0:
                continue
            else:
                dp[i] += S[i-l] - S[max(i-r-1, 0)]
        dp[i] %= MOD
        S[i] = S[i-1] + dp[i]
    print(dp[-1]%MOD)

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

N=int(input())

ans=0
for i in range(1,N+1):
    for j in range(1,N):
        if i <j:
            continue
        for k in range(1,N):
            if i <j+k:
                continue
            for l in range(1,N):
                if l**2+j**2+k**2+l*j+j*k+k*l==i:
                    ans+=1
    print(ans)
    ans=0

### FIXED CODE ###

N=int(input())

ans=[0]*N

for i in range(1,int(N**0.5)):
    if i**2 >=N:
        break
    for j in range(1,int(N**0.5)):
            if i**2+j**2+i*j>=N:
                break
            for k in range(1,int(N**0.5)):
                    if i**2+j**2+k**2+i*j+j*k+k*i <=N:
                        ans[i**2+j**2+k**2+i*j+j*k+k*i-1] +=1

for i in range(N):
    print(ans[i])
### BUGGY CODE ###

def solve():
    m, n = map(int, input().split())
    print(m ** n % 1000000007)

solve()

### FIXED CODE ###

d = 1000000007

def pow_rem(x, n):
    if n == 0:
        return x ** n % d
    if n % 2 == 0:
        return pow_rem(x, n // 2) ** 2 % d
    else:
        return ((pow_rem(x , n // 2) ** 2) * x) % d

def solve():
    m, n = map(int, input().split())
    print(pow_rem(m, n))

solve()
### BUGGY CODE ###

n, m = map(int, input().split())
l1 = []
ln = []
for _ in range(m):
    a, b = map(int, input().split())
    if a == 1:
        l1.append(b)
    elif b == 1:
        l1.append(a)
    elif a == n:
        ln.append(b)
    elif b == n:
        ln.append(a)
l1.sort()
ln.sort()
ans = False
for i in l1:
    for j in ln:
        if i == j:
            ans = True
            break
        if i < j:
            break
    if ans:
        break
if ans:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

### FIXED CODE ###

n, m = map(int, input().split())
l1 = []
ln = []
for _ in range(m):
    a, b = map(int, input().split())
    if a == 1:
        l1.append(b)
    elif b == 1:
        l1.append(a)
    elif a == n:
        ln.append(b)
    elif b == n:
        ln.append(a)
l1.sort()
ln.sort()
ans = False
for i in l1:
    low = 0
    high = len(ln) - 1
    while low <= high:
        mid = (low + high)//2
        if ln[mid] == i:
            ans = True
            break
        elif ln[mid] > i:
            high = mid - 1
        else:
            low = mid + 1
    if ans:
        break
if ans:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
### BUGGY CODE ###

S = input()

ans = 0
for i in range(4, len(S)):
    tmp = 0
    for j in range(len(S) - 1, i - 1, -1):
        if tmp > 0:
            tmp -= 1
            continue
        if int(S[j - i: j + 1]) % 2019 == 0:
            ans += 1
            tmp = i - 1

print(ans)


### FIXED CODE ###

S = input()

ans = 0
lists = [0 for i in range(2019)]
lists[0] += 1

num = 0
for i in range(len(S) - 1, -1, -1):
    num += pow(10, len(S) - 1 - i, 2019) * int(S[i])
    lists[num % 2019] += 1

for i in range(2019):
    if lists[i] >= 2:
        ans += (lists[i] * (lists[i] - 1)) // 2

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

import copy
from collections import deque

# input
N, A, B, C = map(int, input().split())
S = []
for _ in range(N):
    S.append(input())

# process
dq = deque()
dq.append((A, B, C, []))

for i, s in enumerate(S):
    l = len(dq)
    for _ in range(l):
        a, b, c, op = list(dq.popleft())
        
        if a < 0 or b < 0 or c < 0:
            continue

        op1 = op
        op2 = copy.copy(op)
        if s == "AB":
            op1.append("A")
            op2.append("B")
            dq.append((a+1, b-1, c, op1))
            dq.append((a-1, b+1, c, op2))
        elif s == "BC":
            op1.append("B")
            op2.append("C")
            dq.append((a, b+1, c-1, op1))
            dq.append((a, b-1, c+1, op2))
        else:
            op1.append("A")
            op2.append("C")
            dq.append((a+1, b, c-1, op1))
            dq.append((a-1, b, c+1, op2))

# output
operation = []
for a, b, c, op in dq:
    if a >= 0 and b >= 0 and c >= 0:
        operation = op
        break

if operation == []:
    print("No")
else:
    print("Yes")
    [print(x) for x in operation]


### FIXED CODE ###

# input
N, A, B, C = map(int, input().split())
S = [input() for _ in range(N)]

# process
V = {"A":A, "B":B, "C":C}
S.append("XX")
op = ""
for i in range(N):
    s0, s1 = S[i]
    if V[s0] + V[s1] == 0:
        break
    
    x, y = s0, s1
    if V[s1] == 0 or (V[s0] != 0 and s1 in S[i+1]):
        x, y = s1, s0

    V[x] += 1
    V[y] -= 1
    op += x

# output
if len(op) != N:
    print("No")
else:
    print("Yes")
    [print(x) for x in op]
### BUGGY CODE ###

R, G, B, N = map(int, input().split())

counter = 0
for r in range((N // R) + 1):
    for g in range(((N - (r * R)) // G) + 1):
        w_b_sum = N - ((R * r) + (G * g))

        if w_b_sum % B == 0 and w_b_sum >= 0 and w_b_sum == N - ((R * r) + (G * g)):
            # print(r, g, (w_b_sum // B))
            counter += 1
print(counter)


### FIXED CODE ###

R, G, B, N = map(int, input().split())

counter = 0
for r in range((N // R) + 1):
    for g in range(((N - (r * R)) // G) + 1):
        w_b_sum = N - ((R * r) + (G * g))

        if w_b_sum % B == 0 and w_b_sum >= 0:
            # print(r, g, (w_b_sum // B))
            counter += 1
print(counter)
### BUGGY CODE ###

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

for i in range(n-1):
    for j in range(i+1,n):
        if a[i]==a[j]:
            print('NO')
            exit()
print('YES')


### FIXED CODE ###

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

if len(a)==len(set(a)):
    print('YES')
else:
    print('NO')
### BUGGY CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
  a[i]=(1+a[i])/2
x=[0]*(n+k-1)
for i in range(n):
  for j in range(i,i+k):
    x[j]+=a[i]
print('{:.10f}'.format(max(x)))

### FIXED CODE ###

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

tmp=sum(p[:k])
ans=tmp
for i in range(n-k):
    tmp=tmp-p[i]+p[i+k]
    if tmp>ans:
        ans=tmp
print((ans+k)/2)
### BUGGY CODE ###

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

count = [[100000] * W for _ in range(W)]

def dfs(h,w,p):
    if h >= H or w >= W:
        return
    else:
        if S[h][w] == ".":
            count[h][w] = min(count[h][w], p)
            dfs(h+1, w, p)
            dfs(h, w+1, p)
        else:
            count[h][w] = min(count[h][w], p+1)
            dfs(h+1, w, p+1)
            dfs(h, w+1, p+1)

dfs(0,0,0)

print(count[H-1][W-1])

### FIXED CODE ###

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

count = [[100000] * W for _ in range(W)]
count[0][0] = 0 if S[0][0] == "." else 1


for i in range(H):
    for j in range(W):
        if i + j == 0:
            continue
        X, Y = 10**6, 10**6
        if i > 0:
            if S[i][j] == "#" and S[i-1][j] == ".":
                X = count[i-1][j] + 1
            else:
                X = count[i-1][j]
        if j > 0:
            if S[i][j] == "#" and S[i][j-1] == ".":
                Y = count[i][j-1] + 1
            else:
                Y = count[i][j-1]
        count[i][j] = min(X, Y)

print(count[H-1][W-1])
### BUGGY CODE ###

import sys

def main():
    _ = int(input())
    A = list(map(int,input().split()))

    M = []
    lenA = len(A)
    for i in range(len(A))[::-1]:
        if i > lenA/2:
            if A[i] == 1:
                M.append(i+1)
        else:
            num = len([x for x in M if x%(i+1)==0]) % 2
            if A[i] != num:
                M.append(i+1)
    
    print(len(M))
    if len(M) > 0:
        print(*M)

if __name__=='__main__':
    main()

### FIXED CODE ###

import sys


def main():
    _ = int(input())
    A = list(map(int,input().split()))

    M = set()
    lenA = len(A)
    for i in range(len(A))[::-1]:
        if i > lenA/2:
            if A[i] == 1:
                M.add(i+1)
        else:
            bai = set([x*(i+1) for x in range(1, int(lenA/(i+1))+1)])
            num = len(M&bai) % 2
            if A[i] != num:
                M.add(i+1)
    
    print(len(M))
    if len(M) > 0:
        print(*M)

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

str_num, a,b,c = 1, 0, 0, 0
for i in input():
    if i == 'A':
        a += str_num
    elif i == 'B':
        b += a
    elif i == 'C':
        c += b
    else:
        str_num, a,b,c = 3*str_num, (3*a+str_num), (a+3*b), (b+3*c)
print(c % (10**9+7))

### FIXED CODE ###

e,a,b,c=1,0,0,0
p=1000000007
for i in input():
  if i == "A":
    a+=e
  elif i == "B":
    b+=a
  elif i == "C":
    c+=b
  else:
    e,a,b,c = (3*e)%p,(e+3*a)%p,(a+3*b)%p,(b+3*c)%p
print(c%1000000007)
### BUGGY CODE ###

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

from collections import defaultdict


def main():
	Ls = []
	cardDic = defaultdict(int)
	Rs = []
	for i in range(M):
		inputs= list(map(int,input().split()))
		Ls.append(inputs[0])
		cardDic[inputs[0]] += 1
		Rs.append(inputs[1])
		cardDic[inputs[1]] += 1

	result = []
	for i in range(1, M + 1):
		Li = Ls[i - 1]
		LiPlusOne = Li + 1
		LiPlus = [j for j in range(Li + 1, Rs[i - 1] + 1)]

		res = set([Li] + LiPlus)

		if len(result) == 0:
			result.extend(list(res))
		result = list(set(result) & res)

	print(len(result))

if __name__ == '__main__':
	main()

### FIXED CODE ###

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


def main():
	Ls = []
	Rs = []
	for i in range(M):
		inputs = list(map(int,input().split()))
		Ls.append(inputs[0])
		Rs.append(inputs[1])

	maxL = max(Ls)
	minR = min(Rs)

	if maxL > minR:
		print(0)
	else:
		print(minR - maxL + 1)

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

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

data =[0]
access = [False]*(n+1)
dis = [0]+[" "]*(n)
q = queue.Queue()
for i in range(n):
    data.append([])

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

    data[l].append((r,d))
    data[r].append((l,-d))

for i in range(1,n+1):
    data[i].sort(reverse=True)

for i in range(1,n+1):
    if data[i]!=[] and not access[i]: 
        q.put(i)
        access[i] = True
        dis[i] = 0
        while not q.empty():
            l = q.get()

            for r,d in data[l]:
                if access[r]:
                    if dis[r] ==dis[l]+d:
                        continue
                    else:
                        print("No")
                        exit(0)
                else:
                    access[r] = True
                    dis[r] = dis[l]+d
                    q.put(r)
print("Yes")


### FIXED CODE ###

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

data =[0]
access = [False]*(n+1)
dis = [0]+[" "]*(n)
q = queue.Queue()
for i in range(n):
    data.append([])

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

    data[l].append((r,d))
    data[r].append((l,-d))

for i in range(1,n+1):
    data[i].sort(reverse=True)

for i in range(1,n+1):
    if data[i]!=[] and not access[i]: 
        q.put(i)
        access[i] = True
        dis[i] = 0
        while not q.empty():
            l = q.get()

            while data[l]:
                r,d = data[l].pop()
                data[r].remove((l,-d))
                if access[r]:
                    if dis[r] ==dis[l]+d:
                        continue
                    else:
                        print("No")
                        exit(0)
                else:
                    access[r] = True
                    dis[r] = dis[l]+d
                    q.put(r)
print("Yes")
### BUGGY CODE ###

N=int(input())
A=input().split()
a=[]
b=0
for i in range(len(A)):
  x=int(A[i])
  a.append(x)
for i in range(N):
  if a[i] in a[i+1:]:
    print("NO")
    b=1
    break
  else:
    pass
if b==0:
  print("YES")

### FIXED CODE ###

import numpy as np
N=int(input())
a=list(map(int, input().split()))
A=np.array(a)
def has_duplicates(seq):
    return len(seq) != len(set(seq))

s=has_duplicates(A)
if s==False:
  print("YES")
elif s==True:
  print("NO")
### BUGGY CODE ###

N=int(input())
S=input()
cntR,cntG,cntB=S.count('R'),S.count('G'),S.count('B')

a=[cntR]*N
b=[cntG]*N
c=[cntB]*N
for i in range(N):
    if i==0:
        if S[i]=='R':
            a[i]-=1
        elif S[i]=='G':
            b[i]-=1
        else:
            c[i]-=1
    else:
        a[i],b[i],c[i]=a[i-1],b[i-1],c[i-1]
        if S[i]=='R':
            a[i]-=1
        elif S[i]=='G':
            b[i]-=1
        else:
            c[i]-=1
ans=0
for i in range(N-2):
    p=0
    t=S[i]
    r=0
    for j in range(i+1,N-1):
        if S[i]!=S[j]:
            t+=S[j]
            k=2*j-i
            if t=='RG' or t=='GR':
                ans+=c[j]
            elif t=='GB' or t=='BG':
                ans+=a[j]
            else:
                ans+=b[j]
            if k<N and S[k] not in t:
                ans-=1
            t=S[i]

print(ans)

### FIXED CODE ###

N=int(input())
S=input()
cntR,cntG,cntB=S.count('R'),S.count('G'),S.count('B')

ans=cntR*cntG*cntB

for i in range(N-2):
    for j in range(i+1,N-1):
        if S[i]!=S[j]:
            k=2*j-i
            if k<N and S[k]!=S[i] and S[k]!=S[j]:
                ans-=1

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

from collections import defaultdict
S=input()
D=defaultdict(int)
D[0]=1
n=0
i=0
a=[0]*len(S)
for s in S[::-1]:
  n+=int(s)*10**i
  a[i]=n%2019
  i+=1


for i in range(len(a)):
  D[a[i]]+=1

ans=sum([i*(i-1)//2 for i in D.values()])
print(ans)     

### FIXED CODE ###

from collections import defaultdict
S=input()
D=defaultdict(int)
D[0]=1
n=0
i=0
a=[0]*len(S)
b=1
for s in S[::-1]:
  n+=int(s)*b
  a[i]=n%2019
  i+=1
  b=(b*10)%2019


for i in range(len(a)):
  D[a[i]]+=1

ans=sum([i*(i-1)//2 for i in D.values()])
print(ans)
### BUGGY CODE ###

k,s = input().split(' ')
k,s = int(k),int(s)


count = 0
for i in range(k+1):
	for j in range(k+1):
		for l in range(k+1):
			x = i+j+l
			if s == x:
				count += 1

print(count)

### FIXED CODE ###

k,s = input().split(' ')
k,s = int(k),int(s)


count = 0
for i in range(k+1):
	for j in range(k+1):
		z = s - (i+j)
		if z <= k and z >= 0:
			count += 1
print(count)
### BUGGY CODE ###

k, s = map(int, input().split())
count = 0
for i in range(k+1):
    for j in range(k+1):
        for l in range(k+1):
            if i + j + l == s:
                count += 1
print(count)

### FIXED CODE ###

k, s = map(int, input().split())
count = 0
for i in range(k+1):
    if (s - i) / 2 > k:
        continue
    for j in range(k+1):
        z = s - i - j
        if 0 <= z <= k:
            count += 1

print(count)
### BUGGY CODE ###

N,K = map(int,input().split())
h = list(map(int,input().split()))
ans = [0]*N
ans[1] = abs(h[1] - h[0])
for i in range(N - 2):
  j = i + 2
  step = min(K , j)
  height = h[j]
  p = [ans[j - s - 1] + abs(h[j-s-1] - height)
       for s in range(step)]
  ans[j] = min(p)
print(ans[N - 1])  

### FIXED CODE ###

N,K = map(int,input().split())
h = list(map(int,input().split()))
ans = [0]*N
ans[1] = abs(h[1] - h[0])
for i in range(N - 2):
  j = i + 2
  step = min(K , j)
  height = h[j]
  p = [ans[j - s - 1] + abs(h[j-s-1] - height)
       for s in range(step)]
  ans[j] = min(p)
print(ans[N - 1])
### BUGGY CODE ###

import heapq
def SME(start,end):

    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 * parameter : 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()]
A = []
parameter = 0.997
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,M = list(map(int,input().split()))

if M < n-1:exit(print('No'))

m = [[0]*n for _ in range(n)]
dp = [0]*n
from collections import deque
que = deque()
for _ in range(M):
  a,b = list(map(int,input().split()))
  a -= 1
  b -= 1
  m[a][b] = 1
  m[b][a] = 1
  if a == 0:
    que.append(b)
    dp[b] = 1
  if b == 0:
    que.append(a)
    dp[a] = 1

while que:
  c = que.popleft()
  for i in range(n):
    if m[c][i] == 1 and dp[i] == 0 :
      dp[i] = c+1
      que.append(i)

for i in range(1,n):
  if dp[i] == 0:exit(print('No'))

print('Yes')
for i in range(1,n):
  print(dp[i])


### FIXED CODE ###

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

m = [[] for _ in range(n)]
dp = [0]*n
from collections import deque
que = deque()
for _ in range(M):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  m[a].append(b)
  m[b].append(a)
  if a == 0:
    que.append(b)
    dp[b] = 1
  if b == 0:
    que.append(a)
    dp[a] = 1

while que:
  c = que.popleft()
  for i in m[c]:
    if dp[i] == 0 :
      dp[i] = c+1
      que.append(i)

#[exit(print('No')) for i in range(1,n)  if dp[i] == 0]

print('Yes')
[print(dp[i]) for i in range(1,n)]
### BUGGY CODE ###

import itertools
n=int(input())
a=list(map(int,input().split()))
ans=0
for a,b in itertools.combinations(a,2):
    ans+=(a*b)%(10**9+7)
    ans%=(10**9+7)
print(ans%(10**9+7))

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=0
cum=[0]
for i in range(n):
    cum.append((cum[i]+a[i])%(10**9+7))
for i in range(n):
    # print(a[i],cum[-1]-cum[i+1])
    ans+=a[i]*(cum[-1]-cum[i+1])%(10**9+7)
    ans%=(10**9+7)
print(ans)
### BUGGY CODE ###

N=int(input())
n_list=list(map(int,input().split()))
ans=1
tho=10**18
for i in range (N):
  ans*=n_list[i]
  if n_list[i]==0:
    print('0')
    quit()
if ans > tho :
  print ('-1')
elif ans <= tho :
  print(ans)

### FIXED CODE ###

N = int(input())
n_list = list(map(int,input().split()))
if 0 in n_list :
  print('0')
else:  
  ans = 1
  tho = 10**18
  for i in range (N):
    ans *= n_list[i]
    if ans > tho :
      print('-1')
      break
  if ans <= tho :
    print(ans)
### BUGGY CODE ###

n,a,b = map(int,input().split())
ans = 0
q = 0
A = 'Blue'
if a == 0:
  print(0)
  exit()
  
for i in range(n):
  if i % 2 == 0:
    ans += a
    q += a
    A = 'Blue'
  if i % 2 != 0:
    q += b
    A = 'Red'
  if q > n:
    break
    
if A == 'Red':
  print(ans)
  
if A == 'Blue':
  print(ans-(q-n))


### FIXED CODE ###

n,a,b = map(int,input().split())
ans = 0
q = n // (a+b)

ans += q*a
q = n - (a+b)*q

if q - a >= 0:
    ans += a
if q - a < 0:
    ans = ans + a +(q-a)
print(ans)