Harryxun/stf_run huggingface dataset:
import heapq

def solve(num_v ,graph_data): # dict -> [[arr]]
    solution = []
    for i in range(num_v):
        solution.append(partial_solve(i, graph_data))
    return solution

def partial_solve(source,graph_data):
    heap = [(0,source)]
    partial_solution = [float("inf") for _ in range(4)]
    while heap:
        dist, target = heapq.heappop(heap)
        if partial_solution[target] > dist:
            if partial_solution[target] != float("inf"):
                return ["negative"]
            partial_solution[target] = dist
            for edge in graph_data[target]:
                heapq.heappush(heap, (dist+edge[1], edge[0]))
    return partial_solution

def print_solution(solution):
    if ["negative"] in solution:
        print("NEGATIVE CYCLE")
    else:
        print_matrix(solution)

def print_matrix(solution):
    for r in solution:
        l = ""
        for c in r:
            l += str_cell(c) + " "
        print(l[:-1])

def str_cell(cell):
    if cell == float("inf"):
        return "INF"
    else:
        return str(cell)

def main():
    l = input().split()
    V = int(l[0])
    E = int(l[1])

    graph = {}
    for i in range(E):
        l = input().split()
        source = int(l[0])
        target = int(l[1])
        dist = int(l[2])
        if source in graph:
            graph[source].append((target, dist))
        else:
            graph[source] = [(target, dist)]

    print_solution(solve(V, graph))

if __name__ == "__main__":
    main()

### FIXED CODE ###

def print_solve(ans):
    if "negative" in ans:
        print("NEGATIVE CYCLE")
    else:
        for l in ans:
            for c in l[:-1]:
                if c == float("inf"):
                    print("INF",end=" ")
                else:
                    print(c,end=" ")
            if l[-1] == float("inf"):
                print("INF")
            else:
                print(l[-1])

def solve(graph_data, num_v):
    ans = []

    for i in range(num_v):
        ans.append(partial_solve(graph_data, i, num_v))

    return ans

def partial_solve(graph_data, source, num_v):
    ans = [0 if i == source else float('inf') for i in range(num_v)]

    i = 0
    while (ans != solver_iteration(graph_data, ans)):
        ans = solver_iteration(graph_data, ans)
        i += 1
        if i >= num_v:
            return "negative"

    return ans

def solver_iteration(graph_data, prev_ans):
    new_ans = prev_ans[0:]

    for i, v in enumerate(new_ans):
        if v == float('inf') or i not in graph_data:
            continue

        for t, w in graph_data[i]:
                new_ans[t] = min(new_ans[t], v + w)

    return new_ans

def main():
    l = input().split()
    V = int(l[0])
    E = int(l[1])

    graph = {}
    for i in range(E):
        l = input().split()
        s = int(l[0])
        t = int(l[1])
        d = int(l[2])

        if s in graph:
            graph[s].append((t,d))
        else:
            graph[s] = [(t,d)]

    print_solve(solve(graph, V))

if __name__ == "__main__":
    main()
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    H, W = map(int, input().split())
    n = int(input())
    A = list(map(int, input().split()))

    grid = [[0 for _ in range(W)] for _ in range(W)]
    h, w = 0, 0
    for i in range(n):
        cnt = A[i]
        while cnt:
            grid[h][w] = i + 1
            cnt -= 1
            if w + 1 < W:
                w += 1
            else:
                h += 1
                w = 0

    for h in range(H):
        print(*grid[h]) if h % 2 == 0 else print(*grid[h][::-1])


if __name__ == '__main__':
    resolve()


### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    H, W = map(int, input().split())
    n = int(input())
    A = list(map(int, input().split()))
    B = []
    for i in range(n):
        for _ in range(A[i]):
            B.append(i + 1)

    res = [[0] * W for _ in range(H)]
    for b in B:
        for h in range(H):
            for w in range(W):
                if res[h][w] == 0:
                    res[h][w] = b
                    break
            else:
                continue
            break

    for i in range(H):
        if i % 2 == 0:
            print(*res[i])
        else:
            print(*res[i][::-1])


if __name__ == '__main__':
    resolve()
from math import gcd

N = int(input().strip())
o = 0
for i in map(int, input().split()):
	o = gcd(o,i)
print(o)


### FIXED CODE ###

def solve():
  def gcd(x, y):
   while(y): 
       x, y = y, x % y 
   return x

  N = int(input().strip())
  o = 0
  for i in map(int, input().split()):
    o = gcd(i,o)
  print(o)

if __name__=="__main__":
  solve()
# -*- coding: utf-8 -*-
A,B,C,D = list(map(int, input().split()))

if A+B+C+D == 7:
    print('A+B+C+D=7')
elif A+B+C-D == 7:
    print('A+B+C-D=7')
elif A+B-C+D == 7:
    print('A+B-C+D=7')
elif A+B-C-D == 7:
    print('A+B-C-D=7')
elif A-B+C+D == 7:
    print('A-B+C+D=7')
elif A-B+C-D == 7:
    print('A-B+C-D=7')
elif A-B-C+D == 7:
    print('A-B-C+D=7')
elif A-B-C-D == 7:
    print('A-B-C-D=7')



### FIXED CODE ###

# -*- coding: utf-8 -*-
A,B,C,D = list(map(int, list(input())))

if A+B+C+D == 7:
    print(str(A)+'+'+str(B)+'+'+str(C)+'+'+str(D)+'=7')
elif A+B+C-D == 7:
    print(str(A)+'+'+str(B)+'+'+str(C)+'-'+str(D)+'=7')
elif A+B-C+D == 7:
    print(str(A)+'+'+str(B)+'-'+str(C)+'+'+str(D)+'=7')
elif A+B-C-D == 7:
    print(str(A)+'+'+str(B)+'-'+str(C)+'-'+str(D)+'=7')
elif A-B+C+D == 7:
    print(str(A)+'-'+str(B)+'+'+str(C)+'+'+str(D)+'=7')
elif A-B+C-D == 7:
    print(str(A)+'-'+str(B)+'+'+str(C)+'-'+str(D)+'=7')
elif A-B-C+D == 7:
    print(str(A)+'-'+str(B)+'-'+str(C)+'+'+str(D)+'=7')
elif A-B-C-D == 7:
    print(str(A)+'-'+str(B)+'-'+str(C)+'-'+str(D)+'=7')
# -*- coding: utf-8 -*-

from decimal import Decimal

a, b = input().split()

print(int(decimal(a)*decimal(b)))


### FIXED CODE ###

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

from decimal import Decimal

a, b = input().split()

print(int(Decimal(a)*Decimal(b)))
a,b=map(int, input().split())

if a==1:
  a=14
else:
  a=a
if b==1:
  b=14
else:
  b=b
  
if a>b:
  print("Alice")
elif a=b:
  print("Draw")
else a<b:
  print("Bob")


### FIXED CODE ###

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

if a==1:
  k=14
else:
  k=a
if b==1:
  m=14
else:
  m=b
  
if k>m:
  print("Alice")
elif k==m:
  print("Draw")
else:
  print("Bob")
i = 0

while True:
 i += 1
 x = input()
 if x == 0:
  break:
 print "case %d: %s" %(i x)

### FIXED CODE ###

 

import sys
for i,ws in enumerate(sys.stdin, 1):
    w = ws[:-1]
    if w =='0': break
    print 'Case %d: %s' % (i, w)
def calc_cost(h):
        if (len(h) == 0):
            return 0
     
        cost = [None] * len(h)
        cost[0] = 0
        for i in range(1, len(h)):
            cost[i] = cost[i-1] + abs(h[i] - h[i-1])
            if i>1:
                cost[i] = min(cost[i], cost[i-2] + abs(h[i] - h[i-2]))
     
        return cost[len(h)-1]
     
    if __name__ == "__main__":
        n = int(input())
        h = list(map(int, input().split(" ")))
        res = calc_cost(h)
        print(res)

### FIXED CODE ###

def calc_cost(h):
    if (len(h) == 0):
        return 0

    cost = [None] * len(h)
    cost[0] = 0
    for i in range(1, len(h)):
        cost[i] = cost[i-1] + abs(h[i] - h[i-1])
        if i>1:
            cost[i] = min(cost[i], cost[i-2] + abs(h[i] - h[i-2]))

    return cost[len(h)-1]

if __name__ == "__main__":
    n = int(input())
    h = list(map(int, input().split(" ")))
    res = calc_cost(h)
    print(res)
import sys
from functools import reduce
def a():
    p = [[int(t) for t in r.split(' ')] for r in sys.stdin.read().split('\n') if r != '']
    A, P = p[0]
    print(int((A*3+P)/2)
a()
import sys
def a():
    p = [[int(t) for t in r.split(' ')] for r in sys.stdin.read().split('\n') if r != '']
    A, P = p[0]
    print(int((A*3+P)/2)
a()


### FIXED CODE ###

import sys
def a():
    p = [[int(t) for t in r.split(' ')] for r in sys.stdin.read().split('\n') if r != '']
    A, P = p[0]
    print(int((A*3+P)/2))
a()
a, b = input(), input()
print(6-a-b)

### FIXED CODE ###

number1 = int(input())
number2 = int(input())
choices = [1,2,3]
choices.remove(number1)
choices.remove(number2)
print(*choices)
N = int(input())
A = [list(map(int, input().split())) for _ in range(2)]
ans = 0
for i in range(N):
  temp = 0
  for j in range(N - i):
    temp += A[i][j]
  temp += A[1][j]
  if ans < temp:
    ans = temp
print(ans)

### FIXED CODE ###

N = int(input())
A = [list(map(int, input().split())) for _ in range(2)]
ans = 0
for i in range(N):
	temp = 0
	for j in range(i+1):
		temp += A[0][j]
	for j in range(i, N): 
		temp += A[1][j]
	ans = max(ans, temp)
print(ans)
N,P = list(map(int,input().split()))
mylist = []
roop  = int((10**12)**(1/N))

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

Primelis = primes(roop)
if N ==1:
    print(P)
else:
    for i in Primelis:
        if P%(i**N)==0:
            mylist.append(i)
            P = P/(i**N)
    ans = 1
    L = len(mylist)
    for i in range(L):
        ans = ans*mylist[i]
    print(ans)


### FIXED CODE ###

N,P = list(map(int,input().split()))
mylist = []
roop  = int((10**12)**(1/N))

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

flag = 0
tmp = 1
if N ==1:
    print(P)
else:
    Primelis = primes(roop)
    for i in Primelis:
        flag = 0
        tmp = 1
        while flag==0:
            if P%(i**N)==0:
                P = P/(i**N)
                tmp = tmp*i
            else:
                mylist.append(tmp)
                flag = 1
    ans = 1
    L = len(mylist)
    for i in range(L):
        ans = ans*mylist[i]
    print(ans)
import numpy as np
[N,K]=[int(x) for x in input().split()]
h=[int(x) for x in input().split()]

dp=[0 for i in range(N)]

for i in range(1,N):
  dp[N-1-i]=dp[N-i]+np.abs(h[N-i-1]-h[N-i])
  for j in range(2,np.min(K+1,i+1)):
    dp[N-i-1]=np.min(dp[N-i-1+j]+np.abs(h[N-i-1]-h[N-1-i+j]),dp[N-i-1])
print(dp[0]) 

### FIXED CODE ###

import numpy as np
import sys
input = sys.stdin.readline
[N,K]=[int(x) for x in input().split()]
h=[int(x) for x in input().split()]
h=np.array(h)
dp=np.zeros(N,dtype=int)
 
for i in range(1,N):
  last=min(K,i)+N-i
  dp[N-i-1]=min(dp[N-i:last]+np.abs(h[N-i:last]-h[N-i-1]))
print(dp[0])
from collections import Counter

N, M, K = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(M)]
CD = [tuple(map(int, input().split())) for _ in range(K)]


class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n))

    def root(self, x):
        if self.parent[x] == x:
            return x
        return self.root(self.parent[x])

    def root_and_depth(self, x, i=0):
        if self.parent[x] == x:
            return x, i
        return self.root(self.parent[x]), i + 1

    def unite(self, x, y):
        rx, ix = self.root_and_depth(x)
        ry, iy = self.root_and_depth(y)
        if rx != ry:
            if ix < iy:
                self.parent[rx] = ry
            else:
                self.parent[ry] = rx


uf = UnionFind(N)

for a, b in AB:
    uf.unite(a - 1, b - 1)

roots = [uf.root(i) for i in range(N)]
counter_roots = Counter(roots)

ans = [counter_roots[roots[i]] - 1 for i in range(N)]

for a, b in AB:
    if roots[a - 1] == roots[b - 1]:
        ans[a - 1] -= 1
        ans[b - 1] -= 1
for a, b in CD:
    if roots[a - 1] == roots[b - 1]:
        ans[a - 1] -= 1
        ans[b - 1] -= 1

print(*ans)


### FIXED CODE ###

from collections import Counter

N, M, K = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(M)]
CD = [tuple(map(int, input().split())) for _ in range(K)]


class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n))
        self.rank = [0] * n

    def root(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        root_x = self.root(x)
        root_y = self.root(y)
        if self.rank[x] > self.rank[y]:
            self.parent[root_y] = root_x
        elif self.rank[x] < self.rank[y]:
            self.parent[root_x] = root_y
        elif root_x != root_y:
            self.parent[root_y] = root_x
            self.rank[x] += 1
        pass


uf = UnionFind(N)

for a, b in AB:
    uf.unite(a - 1, b - 1)

roots = [uf.root(i) for i in range(N)]
counter_roots = Counter(roots)

ans = [counter_roots[roots[i]] - 1 for i in range(N)]

for a, b in AB:
    if roots[a - 1] == roots[b - 1]:
        ans[a - 1] -= 1
        ans[b - 1] -= 1
for a, b in CD:
    if roots[a - 1] == roots[b - 1]:
        ans[a - 1] -= 1
        ans[b - 1] -= 1

print(*ans)
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:
    print("Odd")
else:
    print("Even")
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

d = dict()
for i in range(1, m+1):
    d[i] = []

for i in range(n):
    a = ab[i][0]
    b = ab[i][1]

    d[a].append(b)


ans = 0
l = []
import bisect

for i in range(1, m+1):
    for v in d[i]:
        bisect.insort(l, v)

    # print(l)

    if l != []:
        ans += l[-1]
        l.pop()
print(ans)


### FIXED CODE ###

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

import heapq
import collections

a_all = []
for i in range(n):
    a_all.append(ab[i][0])

key_all = list(set(a_all))
key_all.sort()

d = dict()
for k in key_all:
    d[k] = []

for i in range(n):
    a = ab[i][0]
    b = ab[i][1]
    d[a].append(b)

ans = 0
l = []
for i in range(1, m+1):
    if key_all != []:
        if i == key_all[0]:
            for v in d[i]:
                heapq.heappush(l, -1 * v)

            heapq.heappop(key_all)

    if l != []:
        ans += heapq.heappop(l) * -1

print(ans)
# -*-coding: utf-8 -*-
import numpy as np

N, M = map(int, input().split())
A = list(map(int, input().split()))
np_A = np.array(A)
for i in range(M):
    num = np_A.argmax()
    np_A[num] //= 2

print(sum(np_A))

### FIXED CODE ###

# -*-coding: utf-8 -*-
import heapq
def main():
    N, M = map(int, input().split())
    A = list(map(lambda x: int(x)*(-1), input().split()))
    heapq.heapify(A)

    for _ in range(M):
        tmp_min = heapq.heappop(A)
        heapq.heappush(A, (-1)*(-tmp_min//2))
    
    print(-sum(A))
if __name__ == '__main__':
    main()
a,b,c=map(int,input().split())
if b*c>=d:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

a,b,c=map(int,input().split())
if b*c>=a:
  print("Yes")
else:
  print("No")
n=int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
import math
r=sorted(p)
t=0
l=0
s=0
for i in range(n):
    if p[i]>q[i]:
        l=p
        s=q
        break
    elif q[i]>p[i]:
        l=q
        s=p
        break
else:
    l=p
    s=q
for i in range(n):
    if l[i]>=s[i]:
        t=t+(r.index(l[i])-r.index(s[i])-1)*math.factorial(n-i-1)
    else:
        t=t+(n-r.index(s[i])-1+r.index(l[i])-1)*math.factrial(n-i-1)

print(t)

### FIXED CODE ###

import itertools
n=int(input())
p=tuple(input().split())
q=tuple(input().split())
h=[]
for i in range(n):
    h+=str(i+1)
k=list(itertools.permutations(h))
p2=-1
q2=-1
for i in range(len(k)):
    if p==k[i]:
        p2=i
    if q==k[i]:
        q2=i
    if p2 != -1 and q2 !=-1:
        break
print(abs(p2-q2))
n = int(input())
h = map(int, input().split(" "))
result = 1

for i in range(n):
  viewable = False
  for j in range(i):
    if h[j] > h[i]:
      break
    else if j == i - 1:
      viewable = True
  
  if viewable == True:
    result += 1
    
print("{}".format(result))

### FIXED CODE ###

n = int(input())
h = list(map(int, input().split(" ")))
result = 1

for i in range(n):
  viewable = False
  for j in range(i):
    if h[j] > h[i]:
      break
    elif j == i - 1:
      viewable = True
      
  if viewable == True:
    result += 1

print("{}".format(result))
a,b=int(input())

ans=0

if a=b:
  ans+=2*a
  print(ans)
else:
  ans+=2*max(a,b)-1
  print(ans)

### FIXED CODE ###

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

if a==b:
  print(2*a)
  
else:
  print(2*max(a,b)-1)
N= int(input())
count=0
for i in range(N):
	p,q=list(map(int,input().split(' ')))
    if p==q:
		count+=1
	else:
      	count=0

if count>=3:
  print('Yes')
else:
  print('No')
		


### FIXED CODE ###

N= int(input())
count=0
for i in range(N):
  p,q=map(int,input().split(' '))
  if count<3:
    if p==q:
      count+=1
    else:
      count=0
  else:
    pass

if count>=3:
  print('Yes')
else:
  print('No')
S = list(input())
stack = []
stack.append(S.pop(0))

for s in S:
    if s == "B":
        if len(stack) > 0:
            stack.pop()
    else:
        stack.append(s)

print("".join(stack)

### FIXED CODE ###

S = list(input())
stack = []

for s in S:
    if s == "B":
        if len(stack) > 0:
            stack.pop()
    else:
        stack.append(s)

print("".join(stack))
n=int(input())
l=list(map(int,input().split()))
d={}
d1={}
ans=0
for i in l:
    if i not in d:
        d[i]=1
        d1[i]=1
    else:
        d[i]+=1
        d1[i]*=d[i]
for i in d1.keys():
    x=d1[i]//(d[i]*(d[i]-1))
    d1[i]=d1[i]//(2*x)
    ans+=d1[i]
for i in l:
    if d[i]>2:
        print(ans-d1[i]+(d1[i]*(abs(d[i]-2))//d[i]))
    elif d[i]==2:
        print(ans-1)
    else:
        print(ans)
    


### FIXED CODE ###

n=int(input())
l=list(map(int,input().split()))
d={}
ans=0
for i in l:
    if i not in d:
        d[i]=1
    else:
        d[i]+=1
for i in d.keys():
    x=d[i]*(d[i]-1)//2
    ans+=x
for i in l:
    if d[i]>2:
        print(ans-(d[i]*(d[i]-1)//2)+((d[i]-1)*(d[i]-2)//2))
    elif d[i]==2:
        print(ans-1)
    else:
        print(ans)
from bisect import bisect
n=int(input())
a=sorted(list(map(int,input().split())))
y=set(a)
acc=0
if a[0]==1 and a[1]!=1:acc+=1
dp=[True]*(a[-1]+1)
for i in range(2,a[-1]+1):
  if i in y:
    if dp[i]==True:
      idx=bisect(a,i)
      if a[idx-1]==a[idx-2]:
        dp[i]=False
      else:acc+=1
    dp[2*i::i]=[False]*len(dp[2*i::i])
print(acc)

### FIXED CODE ###

from bisect import bisect
from collections import Counter
n=int(input())
b=sorted(list(map(int,input().split())))
a=Counter(b)
mA=b[-1]
acc=0
dp=[True]*(mA+1)
for i,v in a.items():
  if dp[i]==True and v==1:
    acc+=1
  else:dp[i]=False
  for k in range(mA//i+1):
    dp[k*i]=False
print(acc)
N = int(input())
if N <= 1000:
  print(1000 - N)
elif N <= 2000:
  print(2000 - N)
elif N <= 3000:
  print(3000 - N)
elif N <= 4000:
  print(4000 - N)
elif N <= 5000:
  print(5000 - N)
elif N <= 6000:
  print(6000 - N)
elif N <= 7000
  print(7000 - N)
elif N <= 8000:
  print(8000 - N)
elif N <= 9000:
  print(9000 - N)
else:
  print(10000 - N)

### FIXED CODE ###

N = int(input())
if 0 <= N <= 1000:
  print(1000 - N)
elif 1001 <= N <= 2000:
  print(2000 - N)
elif 2001 <= N <= 3000:
  print(3000 - N)
elif 3001 <= N <= 4000:
  print(4000 - N)
elif 4001 <= N <= 5000:
  print(5000 - N)
elif 5001 <= N <= 6000:
  print(6000 - N)
elif 6001 <=N <= 7000:
  print(7000 - N)
elif 7001 <= N <= 8000:
  print(8000 - N)
elif 8001 <= N <= 9000:
  print(9000 - N)
else:
  print(10000 - N)
a = input()
b = input()

print(int(a) * int(b) + ' ' + int(a) * 2 + int(b) * 2)

### FIXED CODE ###

[a, b] = [int(x) for x in input().split()]
print(a * b ,(a + b) * 2)
sum=0
max=0
for i in range(5):
  x = int(input()）
  y = -(-x//10)
  sum+=y
  max=(y-x, max)
print(sum-max)

### FIXED CODE ###

X=[int(input()) for i in range(5)]
Y=[]
for x in X:
  Y.append(-(-x//10)*10-x)
print(sum(X)+sum(Y)-(max(Y)))
import sys
s = input()
gx,gy = map(int, input().split(' '))
x_d = [0]
y_d = []
cnt = 0
for i in range(len(s)):
    if s[i] == "T":
        cnt += 1
        if cnt % 2 == 0:
            x_d.append(0)
        elif cnt % 2 == 1:
            y_d.append(0)
    if s[i] == "F":
        if cnt % 2 == 0:
            x_d[-1] += 1
        elif cnt % 2 == 1:
            y_d[-1] += 1
gx -= x_d[0]
del x_d[0]
x_d.append(0)
y_d.append(0)
if (sum(x_d)-gx) % 2 or (sum(y_d)-gy) % 2 or sum(x_d) < abs(gx) or sum(y_d) < abs(gy):
    print("No")
    sys.exit()
x_n = (sum(x_d)-gx)//2
y_n = (sum(y_d)-gy)//2
DPx = [[False for i in range(x_n+2)] for j in range(len(x_d))]
DPy = [[False for i in range(y_n+2)] for j in range(len(y_d))]
for x in DPx:
    x[0] = True
for y in DPy:
    y[0] = True
for i in range(len(x_d)-1):
    for j in range(x_n+2):
        if DPx[i][j]:
            DPx[i+1][j] = True
            if j+x_d[i] <= x_n+1:
                DPx[i+1][j+x_d[i]] = True
for i in range(len(y_d)-1):
    for j in range(y_n+2):
        if DPy[i][j]:
            DPy[i+1][j] = True
            if j+y_d[i] <= y_n+1:
                DPy[i+1][j+y_d[i]] = True
if DPx[len(x_d)-1][x_n] and DPy[len(y_d)-1][y_n]:
    print("Yes")
else:
    print("No")
print(x_d,y_d,x_n,y_n)
print(*DPx,"----",*DPy,sep="\n")

### FIXED CODE ###

import sys
s = input()
gx,gy = map(int, input().split(' '))
x_d = [0]
y_d = []
cnt = 0
for i in range(len(s)):
    if s[i] == "T":
        cnt += 1
        if cnt % 2 == 0:
            x_d.append(0)
        elif cnt % 2 == 1:
            y_d.append(0)
    if s[i] == "F":
        if cnt % 2 == 0:
            x_d[-1] += 1
        elif cnt % 2 == 1:
            y_d[-1] += 1
gx -= x_d[0]
x_d[0] = 0
x_d.append(0)
y_d.append(0)
if (sum(x_d)-gx) % 2 or (sum(y_d)-gy) % 2 or sum(x_d) < abs(gx) or sum(y_d) < abs(gy):
    print("No")
    sys.exit()
x_n = (sum(x_d)-gx)//2
y_n = (sum(y_d)-gy)//2
DPx = [[False for i in range(x_n+2)] for j in range(len(x_d))]
DPy = [[False for i in range(y_n+2)] for j in range(len(y_d))]
for x in DPx:
    x[0] = True
for y in DPy:
    y[0] = True
for i in range(len(x_d)-1):
    for j in range(x_n+1):
        if DPx[i][j]:
            DPx[i+1][j] = True
            if j+x_d[i] <= x_n+1:
                DPx[i+1][j+x_d[i]] = True
for i in range(len(y_d)-1):
    for j in range(y_n+1):
        if DPy[i][j]:
            DPy[i+1][j] = True
            if j+y_d[i] <= y_n+1:
                DPy[i+1][j+y_d[i]] = True
if DPx[len(x_d)-1][x_n] and DPy[len(y_d)-1][y_n]:
    print("Yes")
else:
    print("No")
a,b=input().split()
print(a-b if a-b>0 else 0)

### FIXED CODE ###

a,b=map(int,input().split())
print(a-b if a-b>0 else 0)
N=int(input())
l=[]
c=0

for i in range(N):
	a = int(input())
	l.append(a)

for j in range(N):
  	for k in range(j+1,N):
    	for m in range(k+1,N):
      		if l[j]==l[k] or l[k]==l[m] or l[j]==l[m]:
        		continue
      		if (l[j] + l[k] > l[m]) and (l[k] + l[m] > l[j]) and (l[j] + l[m] > l[k]):
        		c += 1

print(c)


### FIXED CODE ###

N = int(input())
L = list(map(int, input().split()))
c = 0
 
for i in range(N):
  for j in range(i+1,N):
    for k in range(j+1,N):
      if L[i]!=L[j] and L[j]!=L[k] and L[k]!=L[i]:
        if L[i] + L[j] + L[k] > 2 * max(L[i],L[j],L[k]):
          c +=1
 
print(c)
N, T = map(int, input().split())

INF = 10001
minimum = INF
for i in range(N):
    c,t = map(int, input())
    if t <= T:
        minimum = min(minimum, c)

if minimum == INF:
    print('TLE')
else
    print(minimum)



### FIXED CODE ###

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

INF = 10001
minimum = INF
for i in range(N):
    c, t = map(int, input().split())
    if t <= T:
        minimum = min(minimum, c)

if minimum == INF:
    print('TLE')
else:
    print(minimum)
N, A, B = map(int, input().split())
ball = ''
cnt = 0

while N > 0:
  if cnt % 2 == 0:	# 青
    i = min(A, N)
    ball = ball + 'b' * i
  else:				# 赤
    i = min(B, N)
    ball = ball + 'r' * i
  N -= i
  cnt += 1

print(ball.count('b'))


### FIXED CODE ###

N, A, B = map(int, input().split())

if N == 0:
  print(0)
  exit()

cnt = N // (A + B)
rem = N % (A + B)

ans = 0

if rem >= A:
  ans = A * (cnt + 1)
else:
  ans = A * cnt + rem

print(ans)