Harryxun/stf_run huggingface dataset:
class Node:
    def __init__(self, val):
        self.num = val
        self.nodes = []
        self.distance = []

def set_color(node, color):
    if color_list[node.num] == None:
        color_list[node.num] = color
        if len(node.child) > 0:
            for child, dist in zip(node.nodes, node.distance):
                if child != node:
                    if dist == 0:
                        set_color(child, color)
                    else:
                        set_color(child, not color)

N= int(input())

node_list = [Node(i) for i in range(N)]
color_list = [None for i in range(N)]

for i in range(N-1):
    u, v, w = map(int, input().split())
    x = node_list[u-1]
    y = node_list[v-1]
    w = w % 2
    x.nodes.append(y)
    x.distance.append(w)
    y.nodes.append(x)
    y.distance.append(w)

set_color(node_list[0], True)

for i in color_list:
    if i:
        print(1)
    else:
        print(0)


### FIXED CODE ###

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

class Node:
    def __init__(self):
        self.color = 0
        self.check = False
        self.link = []

def main():
    N = int(input())

    nodes = [Node() for i in range(N)]
    
    for i in range(N-1):
        u, v, w = map(int, input().split())
        nodes[u-1].link.append((nodes[v-1], w&1))
        nodes[v-1].link.append((nodes[u-1], w&1))
    
    q = deque()
    q.append((nodes[0], 1))
    while len(q) > 0:
        node, color = q.popleft()
        node.color = color
        node.check = True
        for nex, weight in node.link:
            if not nex.check:
                if weight == 0:
                    q.append((nex, color))
                else:
                    q.append((nex, -color))
    
    for i in range(N):
        print((nodes[i].color + 1) // 2)

if __name__ == "__main__":
    main()
def ryuka(n):
    if n == 0:
        return 2
    elif n == 1:
        return 1

    return ryuka(n-1) + ryuka(n-2)
print(ryuka(n))

### FIXED CODE ###

n = int(input())
li = [2,1]
for i in range(n+1):
    if i == 0:
        continue
    elif i == 1:
        continue
    else:
        li.append(li[i-2] + li[i-1])
print(li[n])
n = int(input())
N = input()
L = 0
R = 0
num = 0
while N[num] == ')':
    L += 1
    num += 1
num = n-1
while N[num] == '(':
    R += 1
    num -= 1
a = N.count('(')
b = len(N) - a
c = a - b + L -R
if (c) < 0:
    for i in range(abs(c)):
        N = '(' + N
elif (c) > 0:
    for i in range(abs(c)):
        N = N + ')'
print('('*L+N+')'*R)

### FIXED CODE ###

n = int(input())
N = input()
L = 0
R = 0
num = 0
for c in N:
    if c == '(':
        num += 1
    else:
        if num:
            num -= 1
        else:
            L += 1
R = num

print('('*L+N+')'*R)
def gcd(a,b):
  if a%b == 0:
    return b
  return gcd(b,a//b)


N,M = [int(i) for i in input().split()]

S = input()
T = input()

x = N * M // gcd(N,M)
flag = True

#print(S[0 * (N / math.gcd(N,M)) + 1])
for i in range(gcd(N,M)):
  if not(S[i * (N //gcd(N,M))] == T[i * (M // gcd(N,M))]):
    flag = False
#    print(S[i * (N // math.gcd(N,M))]  , T[i * (M // math.gcd(N,M))])
if flag:
  print(x)
else:
  print('-1')

### FIXED CODE ###

def gcd(a,b):
  if a%b == 0:
    return b
  return gcd(b,a%b)


N,M = [int(i) for i in input().split()]

S = input()
T = input()

x = N * M // gcd(N,M)
flag = True

#print(S[0 * (N / math.gcd(N,M)) + 1])
for i in range(gcd(N,M)):
  if not(S[i * (N //gcd(N,M))] == T[i * (M // gcd(N,M))]):
    flag = False
#    print(S[i * (N // math.gcd(N,M))]  , T[i * (M // math.gcd(N,M))])
if flag:
  print(x)
else:
  print('-1')
def abc086_b():
    a, b = map(str, input().split())
    
    inpt = a + b
    
    for i in range(100101):
        if inpt / i == i:
            return "Yes"

    return "No"


if __name__ == '__main__':
    print(abc086_b())

### FIXED CODE ###

def abc086_b():
    a, b = map(str, input().split())

    inpt = a + b

    for i in range(1, 100101):
        if int(inpt) / i == i:
            return "Yes"

    return "No"


if __name__ == '__main__':
    print(abc086_b())
n,m = map(int, input().split())
ls = [tuple(map(int, input().split())) for _ in range(m)]
neighborls = []
for i in range(1,n+1):
    neighbors = []
    for j in range(1, m+1):
        if (i,j) in ls or (j,i) in ls:
            neighbors.append(j)
    neighborls.append(neighbors)

ans = 0

def main():
    visitedls = [1]
    ans = dfs(1, visitedls, ans)

    print(ans)
    
        
def dfs(a, visitedls, ans):
    if len(visitedls) == n:
        ans += 1
        return ans
    for i in range(1,n+1):
        if i not in visitedls and i in neighborls[a-1]:
            visitedls.append(i)
            ans = dfs(i, visitedls, ans)
            visitedls.remove(i)
    return ans


if __name__ == "__main__":
    main()

### FIXED CODE ###

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

ans = 0

def dfs(n, visited):
    global ans
    visited.append(n)
    if len(visited) == N:
        ans += 1
    else:
        for i in l[n-1]:
            if i not in visited:
                dfs(i, visited)
    visited.remove(n)

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

dfs(1, [])
print(ans)
N. K = int(input())


while abs(N-K) > N:
  N = abs(N-K)
  
print(N)

### FIXED CODE ###

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

if N % K == 0:
  print(0)
else:
  q = N // K
  d = N - K*q
  print(min(d,abs(d-K)))
n,k= map(int,input().split())
h = list(map(int,input().split()))
h.sort()
if n<=k:
  print(0)
else:
  a = h[:n-k]
  print(sum(a))

### FIXED CODE ###

H, A = map(int,input().split())

ans = 0

while H>0:
	ans += 1
	H -= A

print(ans)
S = input()
N = int(input())
line = [''] * (N * 2)
rev = False
pos = N
line[pos] = S
leftPos = pos - 1
rightPos = pos + 1

for i in range(N):
    A = input().split()
    if len(A) == 1:
        rev = not rev
    else:
        if A[1] == '1':
            if rev == False:
                pos = leftPos
                leftPos -= 1
            else:
                pos = rightPos
                rightPos += 1
        else:
            if rev == False:
                pos = rightPos
                rightPos += 1
            else:
                pos = leftPos
                leftPos -= 1
        line[pos] = A[2]

ans = line[leftPos+1:rightPos]
ans = "".join(ans)
if rev == False:
    print(ans)
else:
    print(ans[::-1])


### FIXED CODE ###

S = input()
N = int(input())
line = [''] * (N+1) * 2
rev = False
pos = N
line[pos] = S
leftPos = pos - 1
rightPos = pos + 1

for i in range(N):
    A = input().split()
    if len(A) == 1:
        rev = not rev
    else:
        if A[1] == '1':
            if rev == False:
                pos = leftPos
                leftPos -= 1
            else:
                pos = rightPos
                rightPos += 1
        else:
            if rev == False:
                pos = rightPos
                rightPos += 1
            else:
                pos = leftPos
                leftPos -= 1
        line[pos] = A[2]

ans = line[leftPos+1:rightPos]
ans = "".join(ans)
if rev == False:
    print(ans)
else:
    print(ans[::-1])
list = map(int(), input().split())
area = list[0] * list[1]
perimeter = list[0] * 2 + list[1] * 2
print('{0} {1}.format(area, perimeter))



### FIXED CODE ###

l = list(map(int, input().split()))
area = l[0] * l[1]
perimeter = l[0] * 2 + l[1] * 2
print('{0} {1}'.format(area, perimeter))
a, b = map(int, input().split())
ans = 0
for n in range(a, b+1):
    if n[0] == n[4] and n[1] == n[3]:
        ans += 1
print(ans)

### FIXED CODE ###

a, b = map(int, input().split())
ans = 0
for n in range(a, b+1):
    if str(n)[0] == str(n)[4] and str(n)[1] == str(n)[3]:
        ans += 1
print(ans)
n = input()
if n = 1:
    print("Helllo World")
else:
    a, b = map(int, input().split())
    print(a + b)

### FIXED CODE ###

n = int(input())
if n == 1:
    print("Hello World")
else:
    a = int(input())
    b = int(input())
    print(a + b)
S = input()
S_list = list(S)

while len(S_list) >= 5 :
    if S_list[0:5] == ['e', 'r', 'a', 's', 'e']:
        if S_list[5] == 'r':
            del S_list[0:6]
        else:
            del S_list[0:5]
    elif S_list[0:5] == ['d', 'r', 'e', 'a', 'm']:
        if S_list[5:8] == ['e', 'r', 'a']:
            del S_list[0:5]
        elif S_list[5:7] == ['e', 'r'] and S_list[7] != ['a']:
            del S_list[0:7]
        else :
            del S_list[0:5]
    else:
        print('NO')
        break


if len(S_list) == 0:
    print('YES')
elif 0<len(S_list)<5:
    print('NO')

### FIXED CODE ###

S = input()
S_list = list(S)

while len(S_list) >= 5 :
    a = len(S_list)
    if S_list[0:5] == ['e', 'r', 'a', 's', 'e']:
        if a >= 6 :
            if S_list[5] == 'r' :
                del S_list[0:6]
            else:
                del S_list[0:5]
        else:
            del S_list[0:5]
    elif S_list[0:5] == ['d', 'r', 'e', 'a', 'm']:
        if a >= 8 :
            if S_list[5:8] == ['e', 'r', 'a'] :
                del S_list[0:5]
            elif S_list[5:7] == ['e', 'r'] :
                del S_list[0:7]
            else :
                del S_list[0:5]
        elif a >= 7 :
            if S_list[5:7] == ['e', 'r'] :
                del S_list[0:7]
            else:
                del S_list[0:5]
        else :
            del S_list[0:5]
    else:
        print('NO')
        break


if len(S_list) == 0:
    print('YES')
elif 0<len(S_list)<5:
    print('NO')
import math
A,B,C = map(int, input().split())
K = int(input())
K1 = math.ceil(math.log(A,B))
B = B ** K1
K2 = math.ceil(math.log(B,C))
if K1 + K2 -2 <= K:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

import math
A,B,C = map(int, input().split())
K = int(input())
if A > B:
  K1 = math.ceil(math.log(A/B,2))
  B = B * (2 ** K1)
  if A == B:
    B = B * 2
    K1 = K1 + 1
elif A == B:
  B = B * 2
  K1 = 1
else:
  K1 = 0

if B > C:
  K2 = math.ceil(math.log(B/C,2))
  C = C * (2 ** K2)
  if C == B:
    K2 = K2 + 1
elif B == C:
  K2= 1
else:
  K2= 0
  
if K1 + K2 <= K:
  print('Yes')
else:
  print('No')
N,m = input().split()
M = int(m)
L1 = list(map(int,input().split()))
ans=-1
if sum(L1)<=N:
    ans = N - sum(L1)
print(ans)

### FIXED CODE ###

n,m = input().split()
N = int(n)
L1 = list(map(int,input().split()))
ans=-1
if sum(L1)<=N:
    ans = N-sum(L1)
print(ans)
d = int(input())
c = list(map(int,input().split()))
s = []
p = [1]*d
for i in range(d):
    s.append(list(map(int,input().split())))
x = [1]*26
for i in range(d):
    q = 1
    m = -1
    for j in range(26):
        n = s[i][j] + (x[j]+13)(x[j]+14)*c[j]
        x[j] += 1
        if(m < n):
            m = n
            q = j
    x[q] *= 0
    p[i] = q+1
for i in range(d):
    print(p[i])

### FIXED CODE ###

import random as rd
d = int(input())
c = list(map(int,input().split()))
s = []
for i in range(d):
    s.append(list(map(int,input().split())))
for i in range(d):
    print(rd.randint(1,26))
1 3 3


### FIXED CODE ###

n,a,b = (int(i) for i in input().split())
if a >b:
  print(0)
  exit()
elif n == 1 and a!=b:
  print(0)
  exit()
if n<= 2:
  print(1)
else:
  mi = a*(n-1)+b
  ma = a+(n-1)*b
  print(ma-mi+1)
import math
A = [int(input()) for _ in range(5)]
print(sum([math.ceil(i/10)*10 for i in A])  -max([10-i for i in [ (i % 10) for i in A] if i != 0]))



### FIXED CODE ###

import math
A = [int(input()) for _ in range(5)]
print(sum([math.ceil(i/10)*10 for i in A])  -max([10-i for i in [ (i % 10) for i in A] if i != 0] +[0]))
import sys
input = sys.stdin.readline

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

def lcm(a, b):
    return a*b//gcd(a, b)

N, M = map(int, input().split())
a = list(map(int, input().split()))
b = [ai//2 for ai in a]
    
L = 1

for bi in b:
    L = lcm(L, bi)

flag = True

for i in range(N):
    if (L-b[i])%a[i]!=0:
        flag = False
    
if not flag:
    print(0)
    exit()
    
L2 = 1

for ai in a:
    L2 = lcm(L2, ai)

if L>M:
    1/0
    
if L>M:
    print(0)
else:
    print((M-L)//L2+1)

### FIXED CODE ###

import sys
input = sys.stdin.readline

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

def lcm(a, b):
    return a*b//gcd(a, b)

N, M = map(int, input().split())
a = list(map(int, input().split()))
b = [ai//2 for ai in a]
    
L = 1

for bi in b:
    L = lcm(L, bi)

flag = True

for i in range(N):
    if (L-b[i])%a[i]!=0:
        flag = False
    
if not flag:
    print(0)
    exit()
    
L2 = 1

for ai in a:
    L2 = lcm(L2, ai)

if L>M:
    print(0)
else:
    print((M-L)//L2+1)
S = input()
a = (len(S) - 1) / 2
b = (len(S) + 1) / 2
if S[:a] == S[b:]:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

N, M = map(int, input().split())
print(int((N * (N - 1) + M * (M-1)) / 2))
ls = list(map(int, input().split()))
ans = 1
for l in ls:
  ans *= l
  if ans > 1e18:
    print(-1)
    return
print(ans)

### FIXED CODE ###

def main():
  n = int(input())
  ls = list(map(int, input().split()))
  if 0 in ls:
    print(0)
    return
  ans = 1
  for l in ls:
    ans *= l
    if ans > 1000000000000000000:
      print(-1)
      return
  print(ans)
  
main()
N = int(input)

data=[]
for i in range(N):
    S,P = input().split()
    li = [i,S,int(P)]
    data.append(li)
    
data.sort(key=lambda x: x[1])
data.sort(reverse=True, key=lambda x: x[2])
for i in range(N):
    data[i] = data[i]+[i]

data.sort(key=lambda x: x[0])
for i in range(N):
    print(str(data[i][3]))

### FIXED CODE ###

N = int(input())

data=[]
for i in range(N):
    S,P = input().split()
    li = [i+1,S,int(P)]
    data.append(li)
    
data.sort(reverse=True, key=lambda x: x[2])
data.sort(key=lambda x: x[1])
for i in range(N):
    print(str(data[i][0]))
n = int(input())
Mnum = 0
Anum = 0
Rnum = 0
Cnum = 0
Hnum = 0
for i in range(n):
  a = input()
  if a[0] == "M":
    Mnum+=1
  elif a[0] == "A":
    Anum+=1
  elif a[0] == "R":
    Rnum+=1
  elif a[0] == "C":
    Cnum+=1
  elif a[0] == "H":
    Hnum+=1
alist = []
alist.append(Mnum)
alist.append(Anum)
alist.append(Rnum)
alist.append(Cnum)
alist.append(Hnum)
from itertools import combinations
blist =list(combinations(alist,3))
from functools import reduce
sum = 0
for i in range(len(blist)):
  sum+=reduce(mul,blist[i])
print(sum)

### FIXED CODE ###

n = int(input())
Mnum = 0
Anum = 0
Rnum = 0
Cnum = 0
Hnum = 0
for i in range(n):
  a = input()
  if a[0] == "M":
    Mnum+=1
  elif a[0] == "A":
    Anum+=1
  elif a[0] == "R":
    Rnum+=1
  elif a[0] == "C":
    Cnum+=1
  elif a[0] == "H":
    Hnum+=1
alist = []
alist.append(Mnum)
alist.append(Anum)
alist.append(Rnum)
alist.append(Cnum)
alist.append(Hnum)
from itertools import combinations
print(sum([a*b*c for a,b,c in combinations(alist,3)]))
S, W = int(input().split())
if S < W:
    print('unsafe')
else:
    print('safe')

### FIXED CODE ###

s,w=map(int,input().split())
 
if s>w:
	print("safe\n")
else:
	print("unsafe\n")
NH = input().split()
N = int(NH[0])
H = int(NH[1])
a = []
b = []
for v in range(N):
    L = input().split()
    a.append(L[0])
    b.append(L[1])
a = list(map(int, a))
b = list(map(int, b))
a.sort(reverse = True)
b.sort(reverse = True)
c = 0
count = 0
while c < H:
    if a[0] >= b[0] or len(b) == 0:
        c = c + a[0]
        count = count + 1
    else:
        c = c + b.pop(0)
        count = count + 1 
print(count)

### FIXED CODE ###

NH = input().split()
N = int(NH[0])
H = int(NH[1])
a = []
b = []
for v in range(N):
    L = input().split()
    a.append(L[0])
    b.append(L[1])
a = list(map(int, a))
b = list(map(int, b))
a.sort(reverse = True)
b.sort(reverse = True)
c = 0
count = 0
while c < H:
    if len(b) > 0 and a[0] < b[0]:
        c = c + b.pop(0)
        count = count + 1 
    else:
        break
if c < H:
    count = count -(-(H - c)//a[0])
print(count)
a, b, c = map(int, input().split())

print(int(a b c))

### FIXED CODE ###

a, b, c = input().split()
if b == '+':
  print(int(int(a) + int(c)))
else:
  print(int(int(a) - int(c)))
N,K=map(int,input().split())
A=[]
people=list(range(1,N+1,1))
for idx in range(K):
    d=int(input())
    X=list((map(int,input().split())))
    for i in range(len(X)):
        A.append(X[i])
ans =[i for i in people if not i in A]
print(ans[0])

### FIXED CODE ###

N,K=map(int,input().split())
A=[]
people=list(range(1,N+1,1))
for idx in range(K):
    d=int(input())
    X=list((map(int,input().split())))
    for i in range(len(X)):
        A.append(X[i])
ans =[i for i in people if not i in A]
print(len(ans))
n = int(input())
b = 1
a = list(map(int,input().split()))
if 0 in a:
    print(0)
else:
    for i in range(n):
        b *= int(a[i])
    b *= a[n]
    if b > 10**18:
       print(-1)
    else:print(b)    

### FIXED CODE ###

n = int(input())
b = 1
a = list(map(int,input().split()))
if 0 in a:
    print(0)
else:
    for i in range(n):
        b *= a[i]
        if b > 10**18:
            print(-1)
            break
    if b <=10**18:
        print(b)
lucky = input()
a = int (lucky[1])
b = int (lucky[2])
c = int (lucky[3])

if (a == 7) or (b == 7) or (c == 7) :
    print ("Yes")
else :
    print ("No")

### FIXED CODE ###

lucky = input()
a = int (lucky[0])
b = int (lucky[1])
c = int (lucky[2])
 
if (a == 7) or (b == 7) or (c == 7) :
    print ("Yes")
else :
    print ("No")
N = int(input())

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

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

sum_M = []
for i in range(0, N+1):
 if i == 0:
  p1 = max(0, Y[0] - M[0])
  sum_M.append(min(M[0], Y[0]) ) 
 elif i < N:
  sum_M.append(min(M[i], Y[i] + p1) )
  p0 = 
  p1 = min(Y[i], max(0, Y[i] - (M[i] + p1)) )
 else:
  sum_M.append(min(M[i], p1) )
  p1 = max(0, p1 - M[i])  

print(sum(sum_M))


### FIXED CODE ###

N = int(input())

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

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

sum_M = []
for i in range(0, N+1):
 if i == 0:
  p1 = max(0, Y[0] - M[0])
  sum_M.append(min(M[0], Y[0]) ) 
 elif i < N:
  sum_M.append(min(M[i], Y[i] + p1) )
  p1 = min(Y[i], max(0, Y[i] - M[i] + p1) )
 else:
  sum_M.append(min(M[i], p1) )
  p1 = max(0, p1 - M[i])  

print(sum(sum_M))
import sys
input = sys.stdin.readline

def main():
    N, M, P = map(int, input().split())
    g = [[] for _ in range(N+1)]
    g2 = [[] for _ in range(N+1)]
    data0 = [None] * (M+1)
    data1 = [None] * (M+1)
    data2 = [None] * (M+1)
    for i in range(M):
        a, b, c = map(int, input().split())
        data0[i] = a
        data1[i] = b
        data2[i] = c


    for i in range(M):
        g[data1[i]].append(data0[i])
        g2[data0[i]].append(data1[i])








    INF = -100000001
    d = [INF] * (N+1)
    d[1] = 0

    for i in range(N):
        d_N = [d[i] for i in range(1, N+1) if visit[i]]
        for j in range(M):
            d[data1[j]] = max(d[data1[j]], d[data0[j]]+data2[j]-P)
        if i == N-1:
            if d_N != [d[i] for i in range(1, N+1) if visit[i]]:
                ans = -1

            else:
                ans = d[N]

    if ans == -1:
        print(-1)
    else:
        print(max(0, ans))

if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
import queue
input = sys.stdin.readline

def main():
    N, M, P = map(int, input().split())
    g = [[] for _ in range(N+1)]
    g2 = [[] for _ in range(N+1)]
    data = [list(map(int, input().split())) for _ in range(M)]
    for a, b, _ in data:
        g2[b].append(a)
        g[a].append(b)

    visit = [False]*(N+1)
    visit2 = [False]*(N+1)

    q = queue.Queue()
    q.put(1)
    visit[1] = True
    while (not q.empty()):
        now = q.get()
        for next in g[now]:
            if not visit[next]:
                visit[next] = True
                q.put(next)

    q = queue.Queue()
    q.put(N)
    visit2[N] = True
    while (not q.empty()):
        now = q.get()
        for next in g2[now]:
            if not visit2[next]:
                visit2[next] = True
                q.put(next)

    for i in range(1, N+1):
        visit[i] = visit[i] and visit2[i]


    INF = 1000000001
    d = [(-1)*INF for i in range(N+1)]
    d[1] = 0

    for i in range(N):
        d_N = [d[i] for i in range(1, N+1) if visit[i]]
        for j in range(M):
            a = data[j][0]
            b = data[j][1]
            c = data[j][2]
            d[b] = max(d[b], d[a]+c-P)
        if i == N-1:
            if d_N != [d[i] for i in range(1, N+1) if visit[i]]:
                ans = -1

            else:
                ans = d[N]

    if ans == -1:
        print(-1)
    else:
        print(max(0, ans))

if __name__ == "__main__":
    main()
x, y = int(input("Number")), int(input("Number"))
print(x*y)


### FIXED CODE ###

a,b = map(int,input(). split ())
print(a*b)
K, N = map(int, input().split())
A = list(map(int, input().split())
distances = {}
for i in range(1, len(A)):
	distances += (A[i] - A[i - 1]
most = max(distances.keys())
distance += (A[0] + K) - A[-1]                   
output = K - most
print(output)

### FIXED CODE ###

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

distance = []
for i in range(1, N):
	distance.append(A[i] - A[i - 1])
distance.append((A[0] + K - (A[-1])))
most = max(distance)
output = K - most
print(output)
k=int(input())
d=0
for a in range(1,k+1) :
    for b in range(1,k+1):
        i=gcd(a,b)
        for c in range(1,k+1):
            d+=gcd(i,c)
print(d)


### FIXED CODE ###

import math
d=0
k=int(input())
for a in range(1,k+1) :
    for b in range(1,k+1):
        x=math.gcd(a,b)
        for c in range(1,k+1):
            d+=math.gcd(x,c)
print(d)
N, A, B = map(int, input().split())
2 ans = N // (A + B) * A
3 rem = N % (A + B)
4 ans += min(rem, A)
5 print(ans)

### FIXED CODE ###

N, A, B = map(int, input().split())
ans = N // (A + B) * A
rem = N % (A + B)
ans += min(rem, A)
print(ans)
# ABC154
#A Remaining balls
s, t = map(input().split())
a, b = map(int, input().split())
u = input()
if s == u:
    a = a - 1
else:
    b = b -1
print(a, b)


### FIXED CODE ###

# ABC154
#A Remaining balls
s, t = map(str,input().split())
a, b = map(int, input().split())
u = input()
if s == u:
    a = a - 1
else:
    b = b -1
print(a, b)
a = int(input())
n = list(map(int.input().split()))
b = 0
c = 0
flag = 0
for i in n:
    if not int(i) == b+1:
        c +=1
    else:
        b += 1
        flag = 1
if flag == 0:
    c = -1
print(c)

### FIXED CODE ###

a = int(input())
n = input().split()
b = 0
c = 0
flag = 0
for i in n:
    if not int(i) == b+1:
        c +=1
    else:
        b += 1
        flag = 1
if flag == 0:
    c = -1
print(c)