Harryxun/stf_run huggingface dataset:
n, m = (int(_) for _ in input().split())
e = [[int(i) for i in input().split()] for i in range(m)]

a_dict = {}
for pi,yi in e:
    if(pi not in a_dict):
        a_dict[pi] = [yj]
    else:
        a_dict[pi] +=[yj]

for pi,yi in e:
    print('{0:06d}'.format(pi)+'{0:06d}'.format(a_dict[pi].index(yi)+1))

### FIXED CODE ###

#!/usr/bin/env python3
import sys
import bisect

def solve(N: int, M: int, P: "List[int]", Y: "List[int]"):
    # もとの値
    val = [[] for i in range(N+1)]
    for pi, yi in [[P[i], Y[i]] for i in range(M)]:
        val[pi].append(yi)

    for i in val:
        i.sort()


    a = sorted([[P[i], Y[i]] for i in range(M)], key=lambda x:(x[0],x[1]))

    for p, y in [[P[i], Y[i]] for i in range(M)]:
        c_id = bisect.bisect_left(val[p], y)
        print(str(p).zfill(6)+str(c_id+1).zfill(6))
    
    return


# Generated by 1.1.4 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()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    P = [int()] * (M)  # type: "List[int]" 
    Y = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        P[i] = int(next(tokens))
        Y[i] = int(next(tokens))
    solve(N, M, P, Y)

if __name__ == '__main__':
    main()
a = input()
b = input()
c = input()
if (a + b + c)==(5+7+5):
  print("YES")
else:
  print("NO")

### FIXED CODE ###

a,b,c = list(map(int,input().split()))
if(a + b + c)==17:
  print("YES")
else:
  print("NO")
s = input()
n = len(s)


def dfs(i, f):
    if i == n - 1:
        return sum(list(map(int, f.split("+"))))

	return dfs(i + 1, f + s[i + 1]) + dfs(i + 1, f + "+" + s[i + 1])
    
print(dfs(0, s[0]))

### FIXED CODE ###

s = input()
n = len(s)

def dfs(i, f):
    if i == n - 1:
        return sum(list(map(int, f.split("+"))))

    # 式 f の末尾に "+" を追加するかしないかして次の数字を追加
    # 関数の足し算はメソッドを記憶したまま、各関数に分岐していく
    # → (2:返る関数が2個) ^ (n-1:再帰回数が i=0,1...でn-1回) ＝ 最終的な関数は2^(n-1)個
    return dfs(i + 1, f + s[i + 1]) + dfs(i + 1, f + "+" + s[i + 1])
    
print(dfs(0, s[0]))
a,o,b=map(str,input().split())
if o=='+':
    print(a+b)
else:
    print(a-b)

### FIXED CODE ###

a,o,b=map(str,input().split())
a=int(a)
b=int(b)
if o=='+':
    print(a+b)
else:
    print(a-b)
def main():
    mod = 10**9+7
    k = int(input())
    n = len(input())

    @njit(i8[:](i8, i8), cache=True)
    def num_calc(n, mod):
        fact = np.ones(n+1, dtype=np.int64)
        for i in range(2, n+1):
            fact[i] = fact[i-1]*i % mod
        return fact

    @njit(i8[:](i8, i8), cache=True)
    def num_calc2(k, mod):
        power = np.ones(k+1, dtype=np.int64)
        for i in range(1, k+1):
            power[i] = power[i-1]*25 % mod
        return power

    @njit(i8(i8, i8, i8), cache=True)
    def pow(n, k, mod=10**9+7):
        l, now = np.ones(64, np.int64), 1
        l[0] = n
        for i in range(1, 64):
            l[i] = l[i-1]*l[i-1] % mod
        for i in range(64):
            if k & 1:
                now = now*l[i] % mod
            k >>= 1
        return now

    fact = num_calc(n+k, mod)
    nk = fact[n+k]
    fact = fact[n+k:n-1:-1]*fact[:k+1] % mod
    power = (num_calc2(k, mod)*nk) % mod

    print(sum([pow(i, mod-2, mod)*j for i, j in zip(fact, power)]) % mod)


main()


### FIXED CODE ###

def main():
    mod = 10**9+7
    k = int(input())
    s = input()
    n = len(s)
    fact = [1, 1]
    for i in range(2, 2*(10**6)+1):
        fact.append(fact[-1]*i % mod)

    def nCr(n, r, mod=10**9+7):
        return pow(fact[n-r]*fact[r] % mod, mod-2, mod)*fact[n] % mod

    ans = 0
    for i in range(k+1):
        ans = (ans+nCr(n+k, i)*pow(25, i, mod)) % mod
    print(ans)


main()
N = int(input())
lg = len(N)
cnt = 0
if lg == 6:
    cnt = 90909
elif lg == 5:
    cnt += N - 10000 + 1
    cnt += 909
elif lg == 4:
    cnt = 909
elif lg == 3:
    cnt += N - 100 + 1
    cnt += 9
elif lg == 2:
    cnt = 9
else:
    cnt = N
print(cnt)

### FIXED CODE ###

N = int(input())
result = 0
for i in range(1, N+1):
    if len(str(i)) % 2 == 1:
        result += 1
print(result)
N = int(input())
As = [int(c) for c in input().split()]
counter = 0
w = 0


while w == 0:
    for i in range(N):
        if As[i] % 2 != 0:
            w = 1
        As[i] = int(As[i] / 2)
    counter += 1

print(counter)

### FIXED CODE ###

s = input()
a = [int(c) for c in s]
print(sum(a))
# encoding:utf-8
import sys
 
def main():
	n = int(input())
	vers = [list(map(int, input().split())) for _ in range(n - 1)]
	q, k = list(map(int, input().split()))
	queries = [list(map(int, input().split())) for _ in range(q)]
 
	#n = 10 ** 5
	#vers = [[i + 1, i + 2, 10 ** 9] for i in range(n - 1)]
 
	new_vers = mapping(n, vers)
	dist = calcMinDist(n, new_vers, k, queries)
	calcQueries(dist, queries, k)
	
def mapping(n, vers):
	new_vers = {i :[] for i in range(n)}
	for ver in vers:
		new_vers[ver[0] - 1].append((ver[1], ver[2]))
		new_vers[ver[1] - 1].append((ver[0], ver[2]))
	return new_vers
 
def calcMinDist(n, new_vers, k, queries):
	dist = [- 1 for _ in range(n)]
	flag = [False for _ in range(n)]
	dist[k - 1] = 0
	flag[k - 1] = True
	dfs(new_vers, dist, flag, k)
	return dist
 
def dfs(new_vers, dist, flag, frm):
	flag[frm - 1] = True
	vs = new_vers[frm - 1]
	for v in vs:
		if flag[v[0] - 1] == False:
			dist[v[0] - 1] = dist[frm - 1] + v[1]
			new_ver, dist, flag, _ = dfs(new_vers, dist, flag, v[0])
 
	return [new_vers, dist, flag, frm]
 
def calcQuery(dist, query, k):
	print(dist[query[0] - 1] + dist[query[1] - 1])
 
def calcQueries(dist, queries, k):
	for query in queries:
		calcQuery(dist, query, k)
 
if __name__ == '__main__':
	sys.setrecursionlimit(1000000)
	main()

### FIXED CODE ###

def main():
	n = int(input())
	a = n // 100
	b = n - (n // 10) * 10
	if a == b:
		print("Yes")
	else:
		print("No")
 
if __name__ == '__main__':
	main()
import numpy as np
mod = 10**9 + 7


def solve(now, from_, K, pa, b):
    if from_ == -1:
        can_num = K - 1
    else:
        can_num = K - 2
    if K < pa[now + 1] - pa[now]:
        return 0
    case_num = 1
    for i in range(pa[now], pa[now + 1]):
        if b[i] != from_:
            case_num *= can_num
            can_num -= 1
            case_num %= mod
    for i in range(pa[now], pa[now + 1]):
        if b[i] != from_:
            case_num *= solve(b[i], now, K, pa, b)
            case_num %= mod
    return case_num


def main():
    N, K = map(int, input().split())
    ab = np.array([list(map(int, input().split())) for _ in range(N - 1)], dtype=np.int32)
    ab = ab - 1
    ab = np.hstack((ab, ab[[1, 0]]))
    ab = ab[:, np.argsort(ab[0])]
    pa = np.unique(ab[0], return_index=True)[1]
    pa = np.append(pa, 2 * (N - 1))
    ans = K * solve(0, -1, K, pa, ab[1])
    print(ans % mod)


if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 6)
mod = 10**9 + 7


def solve(now, from_, K, ab):
    if from_ == -1:
        can_num = K - 1
    else:
        can_num = K - 2
    if K < len(ab[now]):
        return 0
    case_num = 1
    for i in ab[now]:
        if i != from_:
            case_num *= can_num
            can_num -= 1
            case_num %= mod
    for i in ab[now]:
        if i != from_:
            case_num *= solve(i, now, K, ab)
            case_num %= mod
    return case_num


def main():
    N, K = map(int, input().split())
    if N == 1:
        print(K)
        exit(0)
    ab = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = map(int, input().split())
        ab[a - 1].append(b - 1)
        ab[b - 1].append(a - 1)
    ans = K * solve(0, -1, K, ab)
    print(ans % mod)


if __name__ == "__main__":
    main()
from itertools import product

N = int(input())

cnt = [0]*10000000

for x in range(1,N):
    flag=0
    for y in range(1,N):
        if flag==1:
            break
        elif x*y>=10**4:
            break
        for z in range(1,N):
            if x*z>=10**4 or y*z>=10**4:
                flag=1
                break
            else:
                cnt[x**2 + y**2 + z**2 + x*y + y*z + z*x -1] += 1



for i in range(N):
    print(cnt[i])


### FIXED CODE ###

from itertools import product

N = int(input())

cnt = [0]*100000000

for x in range(1,N):
    flag=0
    for y in range(1,N):
        if x*y>=10**4:
            flag=1
            break
        for z in range(1,N):
            if flag==1:
                break
            elif x*z>=10**4 or y*z>=10**4:
                # flag=1
                break
            else:
                if x**2 + y**2 + z**2 + x*y + y*z + z*x <=10**4+1:
                    cnt[x**2 + y**2 + z**2 + x*y + y*z + z*x -1] += 1



for i in range(N):
    print(cnt[i])
print("Yes" if (eval(input().replace(" ",*)))%2 else "No")

### FIXED CODE ###

print("Yes" if eval(input().replace(" ","*"))%2 else "No")
n=int(input())
li=[int(k) for k in input().split()]
dp=[0]*(n)
dp[0]=li[0]
dp[1]=abs(li[1]-li[0])
for i in range(2,n):
  dp[i]=min(abs(li[i]-dp[i-1]),abs(li[i]-dp[i-2]))
return dp[n-1] 

### FIXED CODE ###

n=int(input())
li=[int(k) for k in input().split()]
dp=[0]*(n)
dp[0]=0
dp[1]=abs(li[1]-li[0])

for i in range(2,n):
  dp[i]=min(abs(li[i]-li[i-1])+dp[i-1],abs(li[i]-li[i-2])+dp[i-2])
#print(dp)
print(dp[n-1])
A B C D = input()

if A*B>C*D:
    print(A*B)
elif C*D>A*B:
    print(C*D)
elif A*B==C*D:
    print(A*B)

### FIXED CODE ###

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

if A*B>C*D:
    print(A*B)
elif C*D>A*B:
    print(C*D)
elif A*B==C*D:
    print(A*B)
a,b=input().split()
a=int(a)
b=list(b)
b=[b[0],b[2],b[3]]
c=a*b[0]+a*b[1]//10+a*b[2]//100
print(c)

### FIXED CODE ###

a,b=map(int,input().split())
print(a*b)
f = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
n, m = map(int, input().split())
a = list(map(int, input().split()))

memo = [-1]*10100


def dp(i):
    # i本のマッチを使って作れる最大の整数
    if i < 0:
        return - 10 ** 100000
    if not (0 <= i and i < 10100):
        raise RuntimeError
    if memo[i] != -1:
        return memo[i]
    if i == 0:
        return 0
    ret = -10**100000
    for x in a:
        ret = max(ret, 10 * dp(i - f[x]) + x)
    memo[i] = ret
    return ret


print(dp(n))


### FIXED CODE ###

import resource
import sys
sys.setrecursionlimit(20000)
f = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
n, m = map(int, input().split())
a = list(map(int, input().split()))

memo = ["-1"] * 10100


def MAX(x, y):
    if y[0] != '#' and (x == "#" or len(x) < len(y) or (len(x) == len(y) and x < y)):
        return y
    else:
        return x


def dp(i):
    # i本のマッチを使って作れる最大の整数
    if i < 0:
        return "#"

    if memo[i] != "-1":
        return memo[i]

    if i == 0:
        return ""

    ret = "#"
    for x in a:
        ret = MAX(ret, dp(i - f[x]) + str(x))
    memo[i] = ret
    return ret


print(dp(n))
import sys
x = sys.stdin
y = 1000
for i in range(10):
    z = y*i
    if x <= z:
        o = z -x
        break;
    else:
        pass

print(o)  

### FIXED CODE ###

int = int(input())
y = 1000
for i in range(1,11):
    z = y*i
    if int <= z:
        o = z - int
        break;
    else:
        pass

print(o)
a = str(input())
b = {"A":"T","G":"C"}
print(b[a])

### FIXED CODE ###

a = str(input())
b = {"A":"T","G":"C","T":"A","C":"G"}
print(b[a])
n, m = map(int, input().split())
A = [(a, b) for a, b in map(int, input().split())]
C = [(c, d) for c, d in map(int, input().split())]
for i in range(n):
  res = 0
  ans = 1 << 20
  for j in range(m):
    tmp = abs(A[i][0] - C[j][0]) + abs(A[i][1] - C[j][1]) )
    if tmp < ans:
	  ans = tmp
      res = j
  print(j)


### FIXED CODE ###

n, m = map(int, input().split())
A = [tuple(map(int, input().split())) for i in range(n)]
C = [tuple(map(int, input().split())) for j in range(m)]
for i in range(n):
  res = 1 
  ans = abs(A[i][0] - C[0][0]) + abs(A[i][1] - C[0][1])
  for j in range(m):
    tmp = abs(A[i][0] - C[j][0]) + abs(A[i][1] - C[j][1])
    if tmp < ans:
      ans = tmp
      res = j+1
  print(res)
while True:
    n = int(raw_input())
    if n == 0: break
    a = []
    for i in range(n/4):
        a.append(int(raw_input())
    print sum(a)

### FIXED CODE ###

while True:
    n = int(raw_input())
    if n == 0: break
    a = []
    for i in range(n/4):
        a.append(int(raw_input()))
    print sum(a)
w=input()
l=[i+1 for i in range(w)]
n=input()
for _ in range(n):
    a,b=[int(i)-1 for i in input().split(",")]
    t=l[a]
    l[a]=l[b]
    l[b]=t
for i in w:
    print(i)


### FIXED CODE ###

w=int(input())
l=[i+1 for i in range(w)]
n=int(input())
for _ in range(n):
    a,b=[int(i)-1 for i in input().split(",")]
    t=l[a]
    l[a]=l[b]
    l[b]=t
for i in l:
    print(i)
s1, s2, s3 = map(int,input().split())
i = 0
if(s1 == 1):
    i =+ 1
if(s2 == 1):
    i =+ 1
if(s3 == 1):
    i =+ 1
print(i)

### FIXED CODE ###

s = int(input())
i = 0
if(s//100==1):
    i = i + 1
    s = s - 100
if(s//10==1):
    i = i + 1
    s = s-10
if(s==1):
    i = i + 1
print(i)
X = list(map(int,input()))

for i in X:
  if X[i]==0:
    print(i+1)
    

### FIXED CODE ###

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

for i in range(5):
  if X[i]==0:
    print(i+1)
#n,*a=map(int,open(0).read().split())
b=[a[i]for i in range(0,len(a),2)]
c=[a[i]for i in range(1,len(a),2)]
print(max(b)+c[b.index(max(b))])

### FIXED CODE ###

n,*a=map(int,open(0).read().split())
b=[a[i]for i in range(0,len(a),2)]
c=[a[i]for i in range(1,len(a),2)]
print(max(b)+c[b.index(max(b))])
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
a, b = map(int, input().split())
# 出力
if a * b % 2 = 0:
  print('even')
else:
  print('odd')

### FIXED CODE ###

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

if a * b % 2 == 0:
  print("Even")
else:
  print("Odd")
import itertools
N = int(input())
count = 0
for i in range(3, len(str(N)) + 1):
    for j in itertools.product('753', repeat=i):
        if int(''.join(j)) =< N and '3' in str(j) and '5'in str(j) and '7' in str(j):
            count += 1

print(count)


### FIXED CODE ###

import itertools
N = int(input())
count = 0
for i in range(3, len(str(N)) + 1):
    for j in itertools.product('753', repeat=i):
        if int(''.join(j)) <= N and '3' in str(j) and '5'in str(j) and '7' in str(j):
            count += 1

print(count)
N, K = map(int, input().split())
L = list(map(int, input().split()))
dp = [-1 for k in range(K+1)]
dp[0] = 1
def fn(n):
	if dp[n] != -1:
		return dp[n]
	for i in L:
		if fn(n-i) == 1:
			dp[n] = 0
			return 0
	dp[n] = 1
	return 1
for l in range(1, 	K):
	fn(l)
if fn(K) == 0:
	print("First")
else:
	print("Second")

### FIXED CODE ###

N, K = map(int, input().split())
L = list(map(int, input().split()))
dp = [-1 for k in range(K+1)]
# dp[0] = 1
def fn(n):
	if dp[n] != -1:
		return dp[n]
	if n == 0:
		dp[n] = 0
		return dp[n]
	ans = 0
	for i in L:
		if n >= i:
			if fn(n-i) == 0:
				ans = 1
				break
	dp[n] = ans		
	return dp[n]
for l in range(K):
	fn(l)
if fn(K) == 1:
	print("First")
else:
	print("Second")
x1 = input()
x2 = input()
x3 = input()
x4 = input()
x5 = input()

if (x1==0):
  print(1)
if (x2==0):
  print(2)
if (x3==0):
  print(3)
if (x4==0):
  print(4)
if (x5==0):
  print(5)

### FIXED CODE ###

a = input().split()
for i in range(5):
  if (a[i]=='0'):
    print(i+1)
n = int(input())
l = list(map(int,input().split()))
cou = 0
if l[0]==1:
  x = l[0]
  l[0] = l[1]
  l[1]=x
  cou += 1
for i in range(1,n):
  if l[i]==i+1:
    if l[i-1]==i:
      x = l[i-1]
      l[i-1] = l[i]
      l[i] = x
      cou += 1
    else:
      x = l[i]
      l[i] = l[i+1]
      l[i+1] = x
      cou += 1
#  print(l)
print(cou)

### FIXED CODE ###

n = int(input())
l = list(map(int,input().split()))
cou = 0

for i in range(0,n-1):
  if l[i]==i+1:
      l[i],l[i+1] = l[i+1], l[i]
      cou += 1
if l[-1]==n:
  cou += 1
print(cou)
n,x,y = map(int,input().split())

for i in range(1,n):
	ans = 0
	for j in range(1,n-i+1):
		if i+j <= x:
			ans += 1
			continue
		elif j >= y and i+j < n:
			ans += 1
			continue
		else:
			# x-j+1 = jからyまでの距離
			# y-i-j = yからi+j(目的地)までの距離
			#print(abs(x-j)+1+abs(y-i-j))
			if min(abs(x-j)+1+abs(y-i-j),i) == i:
				ans += 1
		num = i-(abs(x-j)+1)
		if num >= 0:
			d1 = y+num
			d2 = y-num
			if i+j < d1 and d1 <= n:
				ans += 1
			if i+j < d2 and d1 != d2:
				ans += 1
		#print(i,j,ans)
	print(ans)


### FIXED CODE ###

s = input()

if s[2] == s[3] and s[4] == s[5]:
	print('Yes')
else:
	print('No')
N,K=map(input().split())
S=input()
S[K-1] = S[K-1].lower()


### FIXED CODE ###

N, K = map(int, input().split())
S = list(input())
S[K-1] = S[K-1].lower()
print("".join(S))
# 問題
# https://atcoder.jp/contests/abc083/tasks/arc088_a

# 方針 greedy
# Xから初めて、2倍2倍していってYに達する手前で止めればよい
# この倍々操作の回数が数列の長さだが、これは簡単に数値計算で求まる
# つまり log_2(X/Y) を整数に丸め込んだやつ
# log2の丸め込み誤差に注意


from math import log2
X, Y = list(map(int, input().split()))

# print(int(log2(Y / X)+1)) #いや、あってるが…
print(len(bin(Y // X)-2))


### FIXED CODE ###

# 問題
# https://atcoder.jp/contests/abc083/tasks/arc088_a

# 方針 greedy
# Xから初めて、2倍2倍していってYに達する手前で止めればよい
# この倍々操作の回数が数列の長さだが、これは簡単に数値計算で求まる
# つまり log_2(X/Y) を整数に丸め込んだやつ
# log2の丸め込み誤差に注意


from math import log2
X, Y = list(map(int, input().split()))

# print(int(log2(Y / X)+1)) #いや、あってるが…
print(len(bin(Y // X))-2)
from math import inf
def rec(n):
    if dp[n-1]!=inf:
        return dp[n-1]
    if n==1:
        dp[n-1]=0
        return dp[n-1]
    if n<1:
        return inf
    if n==2:
        dp[n-1]=abs(a[n-1]-a[n-2])+rec(n-1)
        return dp[n-1]
    else:
        dp[n-1]=min(abs(a[n-1]-a[n-2])+rec(n-1),abs(a[n-1]-a[n-3])+rec(n-2))
        return dp[n-1]
           
n=int(input())
a=[int(i) for i in input().split()]
dp=[inf]*len(a)
print(rec(len(a)))

### FIXED CODE ###

def rec(a):
    dp=[0]*len(a)
    for i in range(len(a)):
        if i==0:
            dp[i]=0
        elif i==1:
            dp[i]=abs(a[i]-a[i-1])
        else:
            dp[i]=min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2])
    return dp[len(a)-1]
n=int(input())
a=[int(i) for i in input().split()]
print(rec(a))
a=input()
s=list(map(int,input().split()))
count=0
counter=0
for i in a:
    counter=0
    for j in range(0,i):
        if s[i]>s[j] and counter==0:
            count+=1
            counter+=1
print(count) 

### FIXED CODE ###

a=int(input())
s=list(map(int,input().split()))
count=0
min=s[0]
for i in range(0,a):
    if min>=s[i]:
        count+=1
        min=s[i]
print(count)
a=input().split(' ')
b=input().split(' ')
c=0
for i in int(a[1]):
    if i != int(a[1])-1:
        if int(b[i+1]) - int(b[i]) > c:
            c = int(b[i+1]) - int(b[i])
    else:
        if int(a[0]) - int(b[-1])+ int(b[0]) > c:
            c = int(a[0]) - int(b[-1])+ int(b[0])
print(int(a[0])-c)


### FIXED CODE ###

a=input().split(' ')
b=input().split(' ')
c=0
for i in range(int(a[1])):
    if i != int(a[1])-1:
        if int(b[i+1]) - int(b[i]) > c:
            c = int(b[i+1]) - int(b[i])
    else:
        if int(a[0]) - int(b[-1])+ int(b[0]) > c:
            c = int(a[0]) - int(b[-1])+ int(b[0])
print(int(a[0])-c)
# coding: utf-8
# Your code here!
n=int(input())
edge=[[] for _ in range(n)]
for _ in range(n-1):
    p,q = [int(i)-1 for i in input().split()]
    edge[p].append(q)
    edge[q].append(p)

    
used = [0]*n
ansb = [0]*n
answ = [0]*n

def dfs(x):
    if used[x]: return (ansb[x], answ[x])
    used[x] = 1
    cb=1; cw=1;
    for e in edge[x]:
        if used[e]: continue
        eb,ew = dfs(e)
        cb*=ew
        cw*=(eb+ew)
    ansb[x]=cb
    answ[x]=cw
    return (cb,cw)

print(sum(dfs(0)))

#print(used)
#print(ansb)
#print(answ)

### FIXED CODE ###

# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**7)
MOD=10**9+7

n=int(input())
edge=[[] for _ in range(n)]
for _ in range(n-1):
    p,q = [int(i)-1 for i in input().split()]
    edge[p].append(q)
    edge[q].append(p)

    
used = [0]*n
ansb = [0]*n
answ = [0]*n

def dfs(x):
    if used[x]: return (ansb[x], answ[x])
    used[x] = 1
    cb=1; cw=1;
    for e in edge[x]:
        if used[e]: continue
        eb,ew = dfs(e)
        cb*=ew
        cb%=MOD
        cw*=(eb+ew)
        cw%=MOD        
    ansb[x]=cb
    answ[x]=cw
    return (cb,cw)

print(sum(dfs(0))%MOD)

#print(used)
#print(ansb)
#print(answ)
X,K,D = map(int, input().split())

X = abs(X)

if X >= K*D:
    print(X - K*D)
else:
    if K%2 == 1:
        X -= D
        k -= 1
    
    x1 = X%(2*D)
    print(min(x1, (2*D-x1)))



### FIXED CODE ###

X,K,D = map(int, input().split())

X = abs(X)

if X >= K*D:
    print(X - K*D)
else:
    if K%2 == 1:
        X -= D
    
    x1 = X%(2*D)
    print(min(x1, (2*D-x1)))
n, k = map(int, input().split())
s = input()
upper = {
    'A': 'a',
    'B': 'b',
    'C': 'c',
}
print(s[:k] + upper[s[k]] + s[k+1:])

### FIXED CODE ###

n, k = map(int, input().split())
s = input()
upper = {
    'A': 'a',
    'B': 'b',
    'C': 'c',
}
print(s[:k-1] + upper[s[k-1]] + s[k:])
from fractions import gcd

n,m=map(int,input().split())
s=input()
t=input()
l=n*m//gcd(n,m)
x=['']*l
ans=l
for i in range(n):
    x[i*(l//n)]=s[i]
for j in range(m):
    if x[j*(l//m)]!='':
        if x[j*(l//m)]!=t[j]:
            ans=-1
            break
print(ans)

### FIXED CODE ###

from fractions import gcd

n,m=map(int,input().split())
s=input()
t=input()
x=gcd(n,m)
l=n*m//gcd(n,m)
for i in range(x):
    if s[i*(n//x)]!=t[i*(m//x)]:
        print(-1)
        exit()
print(l)
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=[i-1 for i in a]+a+[i+1 for i in a]
b=Counter(a).most_max(1)
print(b[0][1])

### FIXED CODE ###

from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=[i-1 for i in a]+a+[i+1 for i in a]
b=Counter(b).most_common(1)
print(b[0][1])
n=int(input())
a=[list(map(int,input().split())) for _ in range(n)]
a.sort(key=lambda x: x[1])
t=0
for i in range(n):
  t+=a[0]
  if t>a[1]:
    print("No")
    break
  elif i==n-1:
    print("Yes")

### FIXED CODE ###

n=int(input())
a=[list(map(int,input().split())) for _ in range(n)]
a.sort(key=lambda x: x[1])
t=0
for i in range(n):
  t+=a[i][0]
  if t>a[i][1]:
    print("No")
    break
  elif i==n-1:
    print("Yes")
s = list(input())
t = [chr(i) for i in range(ord("a"), ord("z") + 1)]
for i in s:
  t.remove(i)
if t:
  print(t[0])
else:
  print("None")


### FIXED CODE ###

s = list(input())
for i in range(ord("a"), ord("z") + 1):
  if chr(i) not in s:
    print(chr(i))
    break
else:
  print("None")
a,b,c = map(int,raw_input())

if a<b<c:
    print "YES"
else:
    print "NO"

### FIXED CODE ###

a,b,c = map(int,raw_input().split())

if a<b<c:
    print "Yes"
else:
    print "No"
n=int(input())

dic=dict()
for i in range(n):
  s=input()
  if s not in dic:
    dic[s]=1
  else:
    dic[s]+=1
a=max(dic)
b=dic[a]
keys = [k for k, v in dic.items() if v == b]
keys.sort()
for i in range(n):
  print(keys[i])


### FIXED CODE ###

n=int(input())

dic=dict()
for i in range(n):
  s=input()
  if s not in dic:
    dic[s]=1
  else:
    dic[s]+=1
a=(max(dic, key=dic.get))
b=dic[a]
keys = [k for k, v in dic.items() if v == b]
keys.sort()

for i in range(len(keys)):
  print(keys[i])
import sys;print"\n".join("%d %d"%(lambda l:(l[0],l[2]/l[0]*l[1]))(lambda f,l:(f(f,l),l[0],l[1]))(lambda f,l:l[1]==0 and l[0] or f(f,[l[1],l[0]%l[1]]),map(int,s.split()))for s in sys.stdin)

### FIXED CODE ###

import sys;print"\n".join("%d %d"%(lambda l:(l[0],l[2]/l[0]*l[1]))((lambda f,l:(f(f,l),l[0],l[1]))(lambda f,l:l[1]==0 and l[0] or f(f,[l[1],l[0]%l[1]]),map(int,s.split())))for s in sys.stdin)
N, A, B = map(int, input().split())
 
tmp1 = N // (A + B)
tmp2 = N % (A + B)
 
print(tmp1 * A + mim(tmp2, A))

### FIXED CODE ###

N, A, B = map(int, input().split())
 
tmp1 = N // (A + B)
tmp2 = N % (A + B)
 
print(tmp1 * A + min(tmp2, A))