Harryxun/stf_run huggingface dataset:
n, m = map(int, input().split())
a = list(map(int, input().split()))

inf = float("inf")
dp = [-inf for i in range(n+1)]
dp[0] = 0

cost = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

use_cost = []
for i in a:
    use_cost.append(cost[i])

if n < min(use_cost):
    print(0)
    exit()

for i in a:
    for j in range(1, n+1):
        if j - cost[i] >= 0:
            dp[j] = max(dp[j], dp[j-cost[i]]+1)

a.sort(reverse=True)
ans = ""
while n > 0:
    for i in a:
        if dp[n-cost[i]] == dp[n]-1:
            ans += str(i)
            n -= cost[i]
            break
print(ans)


### FIXED CODE ###

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

inf = float("inf")
dp = [-inf for i in range(n+1)]
dp[0] = 0

cost = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

for i in a:
    for j in range(1, n+1):
        if j - cost[i] >= 0:
            dp[j] = max(dp[j], dp[j-cost[i]]+1)

a.sort(reverse=True)
ans = ""
while n > 0:
    for i in a:
        state = True
        if n-cost[i] >= 0 and dp[n-cost[i]] == dp[n]-1:
            ans += str(i)
            n -= cost[i]
            state = False
            break
    if state:
        break

if ans == "":
    print(0)
else:
    print(ans)
n,m=map(int, input().split())
a = [int(input()) for _ in range(m)]
if 1 in a:
    ans = [0,1]
elif 2 in a:
    ans = [1,0]
else:
    ans = [1,2]
if n == 1:
    print(ans[0])
    sys.exit()
elif n == 2:
    print(ans[1])
    sys.exit()
else:
    for i in range(2,n):
        if i+1 not in a:
            ans.append((ans[i-1]+ans[i-2])%1000000007)
        else:
            ans.append(0)
    print(ans[len(ans)-1]%1000000007)
    

### FIXED CODE ###

N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
inf = float("inf")
dp = [0] * (N+1)
for i in A:
	dp[i] = inf
dp[0] = 1
if dp[1] != inf:
	dp[1] = 1
for i in range(2,N+1):
	if dp[i] == inf:
		continue

	a = dp[i-2] if dp[i-2] != inf else 0
	b = dp[i-1] if dp[i-1] != inf else 0

	dp[i] = (a + b) % 1000000007


print(dp[N])
#n=int(input())
#n,m=map(int,input().split())
#a=[int(x) for _ in input().split()]

s=input()
q=int(input())
for i in range(q):
    t=list(map(str,input().split()))
    if t[0]=='1':
        s=s[::-1]
    else:
        if t[1]=='1':
            s=t[2]+s
        else:
            s=s+t[2]
    t.clear
print(s)


### FIXED CODE ###

from collections import deque

s=input()
s=deque(s)
q=int(input())
ans=''
flg=0
for _ in range(q):
	query=list(map(str,input().split()))
	if query[0]=='1':
		flg=1-flg
	else:
		if flg:
			if query[1]=='1':
				s.append(query[2])
			else:
				s.appendleft(query[2])
		else:
			if query[1]=='1':
				s.appendleft(query[2])
			else:
				s.append(query[2])
if flg:
	t=[]
	for i in range(len(s)):
		t.append(s.pop())
	print(''.join(t))
else:
    print(''.join(s))
def solve():
    X = input()
    twoDig = int(X[len(X)-2:])
    rest = int(X[:len(X)-2])

    ans = '1'
    for i in range(rest+1):
        if twoDig == 0:
            break
        for n in range(5, 0, -1):
            if twoDig - n >= 0:
                twoDig -= n
                break
    else:
        ans = '0'
    
    print(ans)

if __name__ == '__main__':
    solve()

### FIXED CODE ###

def solve():
    X = input()

    if int(X) < 100:
        print('0')
        exit(0)

    twoDig = int(X[len(X)-2:])
    rest = int(X[:len(X)-2])

    ans = '1'
    for i in range(rest+1):
        if twoDig == 0:
            break
        for n in range(5, 0, -1):
            if twoDig - n >= 0:
                twoDig -= n
                break
    else:
        ans = '0'
    
    print(ans)

if __name__ == '__main__':
    solve()
import sys

N = int(input())
W = [input() for _ in range(N)]

if len(set(W)) != len(W):
    print('No')
    sys.exit(1)

prev = W[0][-1]
for w in W[1:]:
    print(w[0], prev)
    if prev != w[0]:
        print('No')
        sys.exit(1)
    prev = w[-1]

print('Yes')

### FIXED CODE ###

import sys

N = int(input())
W = [input() for _ in range(N)]

if len(set(W)) != N:
    print('No')
    sys.exit()

prev = W[0][-1]
for w in W[1:]:
    if prev != w[0]:
        print('No')
        sys.exit()
    prev = w[-1]

print('Yes')
N, R = map(int, input().split())
print(R+(100*(10-K)))

### FIXED CODE ###

N, R = map(int, input().split())
if N>10: N=10
print(R+(100*(10-N)))
# N, K = 4, 5
# ARR = [3, 2, 4, 1]

# N, K = 6, 727202214173249351
# ARR = [6, 5, 2, 5, 3, 2]


N,K = map(int,input().split())
ARR = list(map(int,input().split()))
NodeStatus = [False] * N
NodeFirstSteps = [0] * N
L = 0
OrderARR = []


def dfs(pos, arr, step):
    if NodeStatus[pos] == True:
        L = (step - NodeFirstSteps[pos])
        print(OrderARR[K % L] + 1)
        return
    OrderARR.append(pos)
    NodeStatus[pos] = True
    NodeFirstSteps[pos] = step
    dfs(arr[pos] - 1, arr, step + 1)


dfs(0, ARR, 0)


### FIXED CODE ###

# N, K = 4, 5
# ARR = [3, 2, 4, 1]

# N, K = 6, 727202214173249351
# ARR = [6, 5, 2, 5, 3, 2]

import sys
sys.setrecursionlimit(100000000)

N,K = map(int,input().split())
ARR = list(map(int,input().split()))
NodeStatus = [False] * N
NodeFirstSteps = [0] * N
L = 0
STARTLINDEX = 0
OrderARR = []


def dfs(pos, arr, step):
    if NodeStatus[pos] == True:
        L = (step - NodeFirstSteps[pos])
        STARTLINDEX = NodeFirstSteps[pos]
        print(OrderARR[(K - STARTLINDEX) % L + STARTLINDEX] + 1)
        return

    if step == K:
        print(pos+1)
        return

    OrderARR.append(pos)
    NodeStatus[pos] = True
    NodeFirstSteps[pos] = step
    dfs(arr[pos] - 1, arr, step + 1)


dfs(0, ARR, 0)
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    vector<vector<int>> vec(100, vector<int>(100, 0));
    cin >> vec.at(99).at(99);
    num = vec.at(99).at(99);
    cout << num * num * num << endl;
}


### FIXED CODE ###

y = int(input())
print(y*y*y)
def f(n):
  d = 2
  ans = 0
  while n>d:
    d*=5
    n//=d
    ans+=n
  return ans

print(f(int(input()))

### FIXED CODE ###

def f(n):
  ans = 0
  while n>0:
    n//=5
    ans+=n
  return ans

x = int(input())
print(0 if x%2 else f(x//2))
l,r = map(int,input().split(" "))

if r-l > 2019:
    print(0)
else:
    import itertools
    ret = 2020
    for i in itertools.combinations(list(range(l,r+1,1)),2):
        ret = min(ret,(i[0]*i[1])%2019)
       #print(i,ret)

print(ret)


### FIXED CODE ###

import itertools
l,r = map(int,input().split(" "))

if r-l > 2019:
    print(0)
else:
    ret = 2020
    for i in itertools.combinations(range(l,r+1,1),2):
        ret = min(ret,(i[0]*i[1])%2019)
    print(ret)
a,b,c = (int(x) for x in input() . split())

print(a + b + c)

### FIXED CODE ###

s = input()
 
print(s.count("1"))
n = input()

num = 0
for i in range(1, n+1):
    a = input()
    if i % 2 != 0:
        if a % 2 != 0:
            num = num + a

print(num)



### FIXED CODE ###

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

num = 0
for i in range(0, len(a)):
    w = i + 1
    if w % 2 != 0:
        if a[i] % 2 != 0:
            num = num + 1

print(num)
a = input()

if a.islower() == True:
  print('a')
else:
  print('A)

### FIXED CODE ###

a = input()
 
if a.islower() == True:
  print('a')
else:
  print('A')
a,b,c,k=map(int,input().split())
if abs(a-b)>10**18:
  print("unfair)
else:
  if k%2==0:
    print(a-b)
  else:
    print(b-a)

### FIXED CODE ###

a,b,c,k=map(int,input().split())
if abs(a-b)>10**18:
    print("unfair")
else:
    if k%2==0:
        print(a-b)
    else:
        print(b-a)
r,c=list(map(int,input().split()))
l=[]
for i in range(r):
	a=list(map(int,input().split()))
	a.append(sum(a))
	l.append(a)
b=[]
for i in range(c+1):
	c=0
	for j in range(r):
		c+=l[j][i]
	b.append(c)
l.append(b)

for i in l:
	print(" ".join(map(str,i)))

### FIXED CODE ###

while(True):
	a,b=list(map(int,input().split()))
	if a==0 and b==0:
		break
	c=0
	for i in range(1,a+1):
		for j in range(1,i):
			for k in range(1,j):
				if i+j+k==b:
					c+=1
	print(c)
def f(n):
    d = 10
    z = 0
    while d <= n:
        z += (n // d)
	    d = 5 * d
    return z

n = int(input())

if n % 1 == 1: # odd                                                                                                                                    
    print(0)
else: # even                                                                                                                                            
    ans = f(n)
    print(ans)

### FIXED CODE ###

def f(n):
    d, z = 10, 0
    while d <= n:
        z += n // d
        d *= 5
    return z

n = int(input())

ans = 0
if n % 2 == 0: # even                                                                                                                                   
    ans = f(n)
print(ans)
n=int(input())
s=[input() for _ in range(n)]
m=int(input())
t=[input() for _ in range(m)]

dic={}
for i in s:
    if i in dic:
        dic[i]+=1
    else:
        dic[i]=1

for i in t:
    if i in dic:
        dic[i]-=1
print(max(dic.values(),0))

### FIXED CODE ###

n=int(input())
s=[input() for _ in range(n)]
m=int(input())
t=[input() for _ in range(m)]

dic={}
for i in s:
    if i in dic:
        dic[i]+=1
    else:
        dic[i]=1

for i in t:
    if i in dic:
        dic[i]-=1
ma=max(dic.values())
print(max(ma , 0))
a, b, c = map(int, input().split())
if c > (a - b):
	print(c - (a - b)
else:
    print(0)

### FIXED CODE ###

a, b, c = map(int, input().split())
if c > (a - b):
	print(c - (a - b))
else:
    print(0)
from collections import Counter
n=int(input())
*v,=map(int,input().split())
if n==2 and len(set(v))==2:
    print(0)
    exit(0)
elif all(v[i]==v[i+2] for i in range(n-2)) and v[0]!=v[1]:
    print(0)
    exit(0)
odd=v[1::2]
odd_c=Counter(odd).most_common()[0][1]
even=v[::2]
even_c=Counter(even).most_common()[0][1]
cnt=0
if Counter(odd).most_common()[0][0]==Counter(even).most_common()[0][0]:
    if odd_c<even_c:
        odd_c=Counter(odd).most_common()[1][1]
    else:
        even_c=Counter(even).most_common()[1][1]
print(n-even_c-odd_c)

### FIXED CODE ###

from collections import Counter
n=int(input())
*v,=map(int,input().split())
odd=Counter(v[::2]).most_common()
odd.append((0,0))
even=Counter(v[1::2]).most_common()
even.append((0,0))
if odd[0][0]==even[0][0]:
    ans=min(n-odd[0][1]-even[1][1],n-odd[1][1]-even[0][1])
else:
    ans=n-odd[0][1]-even[0][1]
print(ans)
N, Q = map(int, input().split())

g = [[] for _ in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

add = [0]*N

for _ in range(Q):
    p, x = map(int, input().split())
    add[p-1] += x

ans = [0]*N

def func(v, p, val):
    val += add[v]
    ans[v] = val
    for c in g[v]:
        if c==p:
            continue
        func(c, v, val)

func(0, -1, 0)

print(*ans)

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,Q = map(int,readline().split())
ABPX = list(map(int,read().split()))
AB = iter(ABPX[:N+N-2])
PX = iter(ABPX[N+N-2:])

graph = [[] for _ in range(N+1)]
for a,b in zip(AB,AB):
    graph[a].append(b)
    graph[b].append(a)

val = [0] * (N+1)
for p,x in zip(PX,PX):
    val[p] += x

stack = [1]
parent = [0] * (N+1)
while stack:
    x = stack.pop()
    for y in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        stack.append(y)
        val[y] += val[x]

print(' '.join(map(str,val[1:])))
N = int(input())
a = list(map(int,input().split()))
l = sorted(a)
count = 0
for i in range(3):
    if i % 2 == 0:
        count += l[i]
    else:
        count -= l[i]
print(count)

### FIXED CODE ###

N = int(input())
a = list(map(int,input().split()))
l = sorted(a, reverse = True)
count = 0
for i in range(N):
    if i % 2 == 0:
        count += l[i]
    else:
        count -= l[i]
print(count)
from collections import defaultdict


def dfs(p, x):
    counter[p] += x
    if children[p]:
        for c in children[p]:
            dfs(c, x)


children = defaultdict(list)

N, Q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N-1)]
px = [list(map(int, input().split())) for _ in range(Q)]
counter = [0] * N

for i in range(N-1):
    a = ab[i][0] - 1
    b = ab[i][1] - 1
    children[a] += [b]
for i in range(Q):
    p = px[i][0] - 1
    x = px[i][1]
    dfs(p, x)
ans = []
for i in range(N):
    ans.append(counter[i])
print(' '.join(map(str, ans)))


### FIXED CODE ###

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


def dfs(cur, par):
    for child in edge[cur]:
        if child == par:
            continue
        counter[child] += counter[cur]
        dfs(child, cur)


N, Q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N-1)]
px = [list(map(int, input().split())) for _ in range(Q)]
counter = [0] * N

edge = [[] for _ in range(N)]
for i in range(N-1):
    a = ab[i][0] - 1
    b = ab[i][1] - 1
    edge[a].append(b)
    edge[b].append(a)

for i in range(Q):
    p = px[i][0] - 1
    x = px[i][1]
    counter[p] += x


dfs(0, -1)
print(*counter)
from collections import defaultdict

Ss = input()
T =  input()

Tdic = defaultdict(lambda: len(T))

for idx,i in  enumerate(T):
    Tdic[i] = len(T) -(idx+1)
    
Tdic[T[-1]] = len(T)
Tdic["?"] = 1
    
Flag = False
mutchdic = dict()
mutch = 0
head = len(T)-1
          
while(1):
    for i in range(len(T)):

        if T[-(i+1)] == Ss[head-i]:
            mutch += 1
            if i+1 == len(T):
                mutchdic[head] = mutch
                head += len(T)
                mutch = 0
                Flag = True
        elif T[-(i+1)] == "?":
            if i+1 == len(T):
                mutchdic[head] = mutch
                head += 1
                mutch = 0
                Flag = True
        else:
            mutchdic[head] = mutch
            head += Tdic[Ss[head-i]]+1-i
    if head > len(Ss)-1:
        break

if Flag:
    SsL = list(Ss)
    max_head = max(mutchdic.items(), key=lambda x:x[1])[0]
    for i in range(len(T)):
        SsL[max_head-i] = T[-(i+1)]
        SsLstr = "".join(SsL)
        SsLstr=SsLstr.replace("?","a")
        ans = SsLstr
else:
    ans = "UNRESTORABLE"

print(ans)

### FIXED CODE ###

Sd = input()
T  = input()

S_r = Sd[::-1]
T_r = T[::-1]

lenS = len(Sd)
lenT = len(T)

Flag2 = True

if lenS < lenT:
    pass
else:
    for i in range(lenS - lenT + 1):
        for j in range(lenT):
            Flag1 = True
            if S_r[i+j] == "?" or S_r[i+j] == T_r[j]:
                pass
            else:
                Flag1 =False
                break
        if Flag1:
            Flag2 = False
            S_r = S_r.replace(S_r[i:i+lenT],T_r,1)
            S_r = S_r.replace("?","a")
            ans = S_r[::-1]
            break

if Flag2:
    ans = "UNRESTORABLE"
print(ans)
import sys

def f(x):
    p=0
    cnt=0
    for i in range(n-1,-1,-1):
        while p<n and a[i]+a[p]<x:
            p+=1
        cnt+=n-p
    return cnt

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

l,r=a[0]*2,a[n-1]*2

while r-l>0:
    if r-l<=1:
        if f(r)==m: md=r;break 
        else: md=l;break
    md=(r+l)//2
    k=f(md)
    if k==m: break
    elif k>m: l=md
    else: r=md

p=0
cnt=0
ans=0

for q in range(n-1,-1,-1):
    try:
        while (p<n and a[q]+a[p]<=md):
            p+=1
    except:
        p=n

    if p==n: break
    cnt+=n-p
    ans+=a[q]*(n-p)*2


ans+=(m-cnt)*md
print(ans)

### FIXED CODE ###

import sys

def f(x):
    p=0
    cnt=0
    for i in range(n-1,-1,-1):
        while p<n and a[i]+a[p]<x:
            p+=1
        cnt+=n-p
    return cnt

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

l,r=a[0]*2,a[n-1]*2
md=(r+l)//2
while r-l>0:
    if r-l<=1:
        if f(r)==m: md=r;break 
        else: md=l;break
    md=(r+l)//2
    k=f(md)
    if k==m: break
    elif k>m: l=md
    else: r=md

p=0
cnt=0
ans=0

for q in range(n-1,-1,-1):
    try:
        while p<n and a[q]+a[p]<=md:
            p+=1
    except:
        b=1
        while True:
            b+=1

    if p==n: break
    cnt+=n-p
    ans+=a[q]*(n-p)*2


ans+=(m-cnt)*md
print(ans)
a = input()
a = a.split(" ")
i = 0
while 1:
  if int(a[0])=<0:
    break
  else:
    i = i+1
    a[0]=int(a[0])-int(a[1])
    
print(i)
  

### FIXED CODE ###

a = input()
a = a.split(" ")
i = 0
while 1:
  if int(a[0]) <= 0:
    break
  else:
    i = i+1
    a[0]=int(a[0])-int(a[1])
    
print(i)
# -*- coding: utf-8 -*-

import numpy as np

s = input()

x = np.base_repr(int(s), 26)

strings = {
"1": "a",
"2": "b",
"3": "c",
"4": "d",
"5": "e",
"6": "f",
"7": "g",
"8": "h",
"9": "i",
"A": "j",
"B": "k",
"C": "l",
"D": "m",
"E": "n",
"F": "o",
"G": "p",
"H": "q",
"I": "r",
"J": "s",
"K": "t",
"L": "u",
"M": "v",
"N": "w",
"O": "x",
"P": "y",
"Q": "z"
}

r = ''
for i in list(x):
    r += strings[i]

print(r)


### FIXED CODE ###

# -*- coding: utf-8 -*-

n = int(input())

r = ''

def to_moji(x: int):
    if x == 0:
        x = 26
    return chr(96 + x)

def devide(x, moji):
    a = x // 26
    b = x % 26

    if b == 0:
        a -= 1

    if a < 1:
        moji = to_moji(b) + moji
        return moji
    elif 1 <= a and a <= 26:
        moji = to_moji(b) + moji
        moji = to_moji(a) + moji
        return moji
    else:
        moji = to_moji(b) + moji
        return devide(a, moji)

print(devide(n, r))
import math
#from functools import reduce

N, X = map(int, input().split())
xi = map(int, input().split())

dist = [abs(X - x) for x in xi]
print(reduce(math.gcd, dist))

### FIXED CODE ###

from functools import reduce
from fractions import gcd

N, X = map(int, input().split())
xi = map(int, input().split())

dist = [abs(X - x) for x in xi]
print(reduce(gcd, dist))
import math
a=input().split()
n,m=int(a[0]),int(a[1])
f=list(map(int,input().split()))
s=0
fl=0
s=sum(a)
if(s>=n):
  print(s-n)
else:
  print("-1")

### FIXED CODE ###

import math
a=input().split()
n,m=int(a[0]),int(a[1])
f=list(map(int,input().split()))
s=0
fl=0
s=sum(f)
if(n>=s):
  print(n-s)
else:
  print("-1")
A,B = map(int, input().split())
S = list(input())
for i in range(A):
    if not 0 <= int(S[i]) <= 9:
        print("No")
        exit()
if S[A] != "-":
    print("No")
    exit()
for i in range(A+1,B):
    if not 0 <= int(S[i]) <= 9:
        print("No")
        exit()
print("Yes")

### FIXED CODE ###

A,B = map(int,input().split())
S = list(input())
if S[A] == '-' and S.count('-') == 1:
    print("Yes")
else:
    print("No")
from collections import defaultdict

      
def r(i) :
  if i < 2:
    return 1
  else :
    return i*r(i-1)

a = int(input())
b = list(map(int,input().split()))
for i in range(a):
  total = 0
  c = defaultdict(int)
  for j in range(a):
    if j != i:
      c[b[j]] += 1
  for key in c.keys():
    if c[key] > 1:
  #    print(c[key],key)
  #    print("###")
      total += r(c[key]) / (r(2)*r(c[key]-2))
  print(int(total))


### FIXED CODE ###

from collections import defaultdict

def r(i) :
  if i < 2:
    return 1
  else :
    return i*(i-1)/2

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

total = 0
c = defaultdict(int)
for j in range(a):
  c[b[j]] += 1
for key in c.keys():
  if c[key] > 1:
    total += r(c[key])

for j in range(a):
  print(int(total - c[b[j]]+1))
import sys
from fractions import math
from collections import deque

input = sys.stdin.readline

N = int(input())
a = [int(x) for x in input().rstrip("\n").split()]
q = deque(a)

while len(q) > 1:
    x = q.popleft()
    y = q.popleft()
    z =  math.gcd(x, y)
    q.append(z)

ans = q.popleft()
print(ans)

### FIXED CODE ###

import sys
import fractions
from collections import deque

input = sys.stdin.readline

N = int(input())
a = [int(x) for x in input().rstrip("\n").split()]
q = deque(a)

while len(q) > 1:
    x = q.popleft()
    y = q.popleft()
    z =  fractions.gcd(x, y)
    q.append(z)

ans = q.popleft()
print(ans)
N = input()
rN = N[::-1]

res = 0
add = False

for i, n in enumerate(rN):
    p = int(n)
    if add:
        p += 1
        
    if i > 100:
        res += (i-100)*p
        add = False
        continue

    if p == 10:
        continue
    elif p == 5:
        if len(N) >= i+1 and int(rN[i+1]) >= 5:
            add = True
            res += p
        else:
            add = False
            res += p
    elif p < 5:
        add = False
        res += p
    else:
        add = True
        res += 10-p

if add:
    res += 1

print(res)


### FIXED CODE ###

N = input()
rN = N[::-1]

res = 0
add = False

for i, n in enumerate(rN):
    p = int(n)
    if add:
        p += 1
    if p == 10:
        continue
    elif p == 5:
        if len(N) > i+1 and int(rN[i+1]) >= 5:
            add = True
            res += p
        else:
            add = False
            res += p
    elif p < 5:
        add = False
        res += p
    else:
        add = True
        res += 10-p

if add:
    res += 1

print(res)
n, a, b = map(int, input().split())
v = n

if n == a + b:
    print(a)
    exit()

elif a == 0:
    print(0)
    exit()


if n > a + b and n < a + a + b:
    print(a+(n - (a + b)))
    exit()

c = n % (a +b)
if n % (a +b) < a:
    print((a * (n//(a+b))) + (n %(a+b)))
    exit()
else:
    print((a * (n//(a+b))) + a)
    eixt()


### FIXED CODE ###

n, a, b = map(int, input().split())
v = n

if n == a + b:
    print(a)
    exit()

elif a == 0:
    print(0)
    exit()



c = n % (a +b)
if n % (a +b) < a:
    print((a * (n//(a+b))) + (n %(a+b)))
    exit()
else:
    print((a * (n//(a+b))) + a)
    exit()
N = int(input())
h = list(map(int, input().split()))
DP = [10000]*7
DP[0] = 0
DP[1] = abs(h[1]-h[0])
for i in range(N-1):
  DP[i+1] = abs(h[i+1]-h[i])+DP[i]
  if i > 0:
    DP[i+1] = min(abs(h[i+1]-h[i])+DP[i], abs(h[i+1]-h[i-1])+DP[i-1])
print(DP[N-1])

### FIXED CODE ###

N = int(input())
h = list(map(int, input().split()))
DP = [10000]*N
DP[0] = 0
DP[1] = abs(h[1]-h[0])
for i in range(N-1):
  DP[i+1] = abs(h[i+1]-h[i])+DP[i]
  if i > 0:
    DP[i+1] = min(abs(h[i+1]-h[i])+DP[i], abs(h[i+1]-h[i-1])+DP[i-1])
print(DP[N-1])
import math
import numpy as np
import re


def inputs(): return [int(s) for s in input().split()]


def main():
    s = input()
    cnt = 0
    s = s.replace('A', '1').replace('BC', '0')
    arr = re.split('[A-C]', s)
    arr = [list(x) for x in arr]

    flag = True
    while flag:
        flag = False
        for a in arr:

            for i in range(len(a)-1):
                if a[i] > a[i + 1]:
                    a[i], a[i + 1] = a[i+1], a[i]
                    cnt += 1
                    flag = True
    print(cnt)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import math
import numpy as np
import re


def inputs(): return [int(s) for s in input().split()]


def main():
    s = input()
    cnt = 0
    s = s.replace('A', '1').replace('BC', '0')
    arr = re.split('[A-C]', s)
    arr = [list(x) for x in arr]
    flag = True
    while flag:
        flag = False
        for a in arr:
            tmp = 0
            for i in a:
                i = int(i)
                tmp += i
                if i is 0:
                    cnt += tmp

    return cnt


if __name__ == '__main__':
    print(main())
N,X = map(int,input().split())
L = list(map(int,input().split()))

D = [0] * (N + 1)

counter = 0

for i in range(1,len(L)):
	D[i] = D[i - 1] + L[i - 1]
	print(D)
	
	
for i in range(0,len(D)):
	if D[i] <= X:
	counter += 1
	
print(counter)

### FIXED CODE ###

N,X = map(int,input().split())
L = list(map(int,input().split()))

D = [0] * (N + 1)

counter = 0

for i in range(1,len(L)+1):
	D[i] = D[i - 1] + L[i - 1]
	
	
for i in range(0,len(D)):
	if D[i] <= X:
		counter += 1
	
print(counter)
import math
a, b = map(int, input().split())
print(a * b // math.gcd(a, b))

### FIXED CODE ###

a, b = map(int, input().split())
# a, bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
# a, bの最小公倍数
def lcm(a, b):
    return a * b // gcd(a, b)

print(lcm(a, b))
from math import gcd
from functools import reduce
from itertools import product ##for i in z for j in z -> product(z,z)
k=int(input())
z=range(1,k+1)
print(sum(gcd(i,gcd(j,k)) product(z,z,z,z)))


### FIXED CODE ###

k=int(input())
z=range(1,k+1)
import math
from functools import reduce
sum=0
for i in z:
	for j in z:
		for jj in z:
			sum=sum+reduce(math.gcd,[i,j,jj])
print(sum)