PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#QHD0000079. Bữa tiệc trái cây (Fruit Feast)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Bữa tiệc trái cây (Fruit Feast)

Fruit Feast

Source: USACO

Version: Phuoc Hung OJ Extended

Problem Statement

Bessie has unlimited supplies of two fruits, oranges and lemons. Eating one orange increases her fullness by exactly AA units; eating one lemon increases it by exactly BB units. Her initial fullness is 00, and her fullness may never exceed TT.

She can additionally drink water at most once. Drinking water immediately changes her current fullness ff to ⌊f/2⌋\lfloor f/2\rfloor. She may drink before, between, or after eating fruits, or skip the water entirely.

Find the maximum fullness achievable by any valid sequence of operations. You do not need to print the operations.

Input

A single line contains three integers T,A,BT,A,B.

Output

Print the largest reachable fullness as one integer.

Subtasks

  • Subtask 1 (20 points): 1≤T≤601\le T\le60, 1≤A,B≤T1\le A,B\le T.

  • Subtask 2 (30 points): 1≤T≤500001\le T\le50000, 1≤A,B≤T1\le A,B\le T.

  • Subtask 3 (50 points): 1≤T≤50000001\le T\le5000000, 1≤A,B≤T1\le A,B\le T.

Examples

Example 1

Input

8 5 6

Output

8

Explanation

Eat an orange to reach 55, drink water to reach ⌊5/2⌋=2\lfloor5/2\rfloor=2, then eat a lemon to reach 88.

Example 2

Input

10 6 9

Output

10

Explanation

Eat a lemon to reach 99, drink to reach 44, and then eat an orange to reach 1010.