1214_A. Optimal Currency Exchange_28556
Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has n rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is d rubles, and one euro costs e rubles.

Recall that there exist the following dollar bills: 1, 2, 5, 10, 20, 50, 100, and the following euro bills — 5, 10, 20, 50, 100, 200 (note that, in this problem we do not consider the 500 euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.

Help him — write a program that given integers n, e and d, finds the minimum number of rubles Andrew can get after buying dollar and euro bills.

Input

The first line of the input contains one integer n (1 ≤ n ≤ 10^8) — the initial sum in rubles Andrew has. 

The second line of the input contains one integer d (30 ≤ d ≤ 100) — the price of one dollar in rubles. 

The third line of the input contains integer e (30 ≤ e ≤ 100) — the price of one euro in rubles.

Output

Output one integer — the minimum number of rubles Andrew can have after buying dollar and euro bills optimally.

Examples

Input


100
60
70


Output


40


Input


410
55
70


Output


5


Input


600
60
70


Output


0

Note

In the first example, we can buy just 1 dollar because there is no 1 euro bill.

In the second example, optimal exchange is to buy 5 euro and 1 dollar.

In the third example, optimal exchange is to buy 10 dollars in one bill.

import java.io.*;
import java.util.*;
public class A1214 {
    public static void main(String args[])throws IOException
        {
            Scanner sc=new Scanner(System.in);
            int n=sc.nextInt();
            int d=sc.nextInt();
            int e=sc.nextInt();
            e=e*5;int min=n;
            for(int i=0;i*d <=n;i++)
            {
                int m=(n- i*d)%e;
                min=Math.min(min, m);
            }
            System.out.println(min);
        }

}

410
55
70
 600
60
70
 100
60
70
 8642
70
90
 999
66
74
 1000
60
80
 90852542
95
34
 100000000
31
33
 99999998
60
75
 99
100
100
 10000
68
78
 11750
49
50
 13795
97
31
 150
100
30
 16091
51
96
 50
60
70
 1
30
30
 90
80
89
 130
100
30
 100005
60
70
 169
59
37
 100000
35
35
 100000000
98
99
 99999999
90
100
 1750
45
50
 150
31
30
 59
87
30
 99750
50
51
 898
99
30
 9876543
66
88
 99999
70
75
 1000
63
70
 54321
63
70
 311
31
30
 511
100
31
 39610651
75
98
 12149750
45
50
 420
65
70
 99998
68
78
 30
31
30
 100000000
30
30
 99
97
33
 495
30
31
 420
70
65
 99999989
31
30
 400
30
100
 23456789
66
100
 8642
26
90
 999
82
74
 1000
60
138
 90852542
95
64
 99
100
101
 50
60
128
 1
29
30
 90
145
89
 130
110
30
 169
59
34
 99999999
36
100
 150
31
27
 59
85
30
 9876543
66
44
 30
36
30
 495
60
31
 600
77
70
 100
109
70
 1750
51
30
 1000
126
139
 311
13
26
 99
18
33
 600
16
70
 999
10
111
 100000000
58
33
 99999998
79
75
 10000
135
78
 11750
49
1
 13795
70
31
 16091
51
89
 100005
113
70
 100000
35
3
 100000000
98
85
 1750
51
50
 99750
50
97
 898
99
10
 1000
126
70
 54321
63
115
 311
31
26
 39610651
75
16
 12149750
53
50
 420
65
41
 99998
68
110
 100000000
60
30
 99
12
33
 420
70
119
 99999989
31
49
 400
30
101
 410
24
70
 8642
11
90
 999
82
111
 1000
77
138
 100000000
58
18
 99999998
79
136
 99
101
101
 10000
135
20
 11750
78
1
 13795
70
49
 16091
51
45
 50
50
128
 1
29
33
 90
145
137
 130
010
30
 100005
145
70
 169
59
40
 100000
35
1
 150
42
27
 99750
50
8
 898
99
1
 9876543
25
44
 54321
6
115
 39610651
75
22
 12149750
53
53
 420
65
3
 99998
68
010
 30
51
30
 495
60
53
 420
70
214
 99999989
31
97
 400
30
111
 410
24
127
 100
158
70
 8642
11
150
 1000
77
184
 99
110
101
 10000
135
18
 11750
78
2
 13795
29
49
 16091
33
45
 50
50
124
 1
29
25
 90
145
42
 130
010
13
 100005
145
72
 169
59
42
 100000
35
2

5
 0
 40
 2
 9
 0
 2
 0
 8
 99
 2
 0
 0
 0
 2
 50
 1
 10
 30
 5
 51
 5
 0
 9
 0
 0
 59
 0
 1
 17
 4
 20
 1
 1
 1
 1
 0
 5
 0
 30
 10
 2
 0
 0
 0
 10
 1
 0
 13
 10
 2
 99
 50
 1
 90
 20
 51
 3
 15
 59
 17
 30
 5
 19
 100
 16
 53
 12
 9
 8
 4
 0
 0
 10
 0
 0
 0
 0
 0
 0
 0
 0
 0
 20
 0
 1
 1
 0
 10
 0
 10
 3
 0
 0
 10
 2
 0
 15
 2
 0
 0
 99
 0
 0
 5
 2
 0
 1
 90
 0
 0
 51
 0
 15
 0
 0
 3
 0
 1
 30
 0
 0
 30
 15
 0
 0
 10
 2
 100
 0
 3
 99
 10
 0
 0
 2
 0
 1
 90
 0
 0
 51
 0
