Problem:
Discounts of Buckwheat

Aizu is famous for its buckwheat. There are many people who make buckwheat noodles by themselves.

One day, you went shopping to buy buckwheat flour. You can visit three shops, A, B and C. The amount in a bag and its unit price for each shop is determined by the follows table. Note that it is discounted when you buy buckwheat flour in several bags.

Shop A

Shop B

Shop C

Amount in a bag

200g

300g

500g

Unit price for a bag (nominal cost)

380 yen

550 yen

850 yen

Discounted units

per 5 bags

per 4 bags

per 3 bags

Discount rate

reduced by 20 %

reduced by 15 %

reduced by 12 %

For example, when you buy 12 bags of flour at shop A, the price is reduced by 20 % for 10 bags, but not for other 2 bags. So, the total amount shall be (380 × 10) × 0.8 + 380 × 2 = 3,800 yen.

Write a program which reads the amount of flour, and prints the lowest cost to buy them. Note that you should buy the flour of exactly the same amount as the given input.

Input

The input consists of multiple datasets. For each dataset, an integer a (500 ≤ a ≤ 5000, a is divisible by 100) which represents the amount of flour is given in a line.

The input ends with a line including a zero. Your program should not process for the terminal symbol. The number of datasets does not exceed 50.

Output

For each dataset, print an integer which represents the lowest cost.

Sample Input

500
2200
0

Output for the Sample Input

850
3390

Solution in JAVA (judge verdict: Accepted)

import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			int n = stdIn.nextInt();
			if(n == 0) break;
			int ans = sorv(n);
			System.out.println(ans);
		}
		
	}
	
	public static int sorv(int n) {
		int c1 = sa(1,0,0,n - 200);
		int c2 = sb(0,1,0,n - 300);
		int c3 = sc(0,0,1,n - 500);
		
		int ans = c1;
		if (ans > c2) ans = c2;
		if (ans > c3) ans = c3;
		return ans;
	}
	
	public static int sa(int a, int b, int c, int las) {
		if(las < 0) return 999999999;
		if(las == 0 && a % 5 == 0) return 380 - (int)(380 * 5 * 0.2);
		if(las == 0) return 380;
		int c1 = sa(a+1,b,c,las - 200);
		int c2 = sb(a,b+1,c,las - 300);
		int c3 = sc(a,b,c+1,las - 500);
		if(a+1 % 5 == 0) c1 += 380 - (int)(380 * 5 * 0.2);
		int ans = c1;
		if(ans > c2) ans = c2;
		if(ans > c3) ans = c3;
		if(a % 5 == 0) ans += 380 - (int)(380 * 5 * 0.2);
		else ans += 380;
		return ans;
	}
	public static int sb(int a, int b, int c, int las) {
		if(las < 0) return 999999999;
		if(las == 0 && b % 4 == 0) return 550 - (int)(550 * 4 * 0.15);
		if(las == 0) return 550;
		int c1 = sa(a+1,b,c,las - 200);
		int c2 = sb(a,b+1,c,las - 300);
		int c3 = sc(a,b,c+1,las - 500);
		int ans = c1;
		if(ans > c2) ans = c2;
		if(ans > c3) ans = c3;
		if(b % 4 == 0) ans += 550 - (int)(550 * 4 * 0.15);
		else ans += 550;
		return ans;
		
	}
	
	public static int sc(int a, int b, int c, int las) {
		if(las < 0) return 999999999;
		if(las == 0 && c % 3 == 0) return 850 - (int)(850 * 3 * 0.12);
		if(las == 0) return 850;
		int c1 = sa(a+1,b,c,las - 200);
		int c2 = sb(a,b+1,c,las - 300);
		int c3 = sc(a,b,c+1,las - 500);
		int ans = c1;
		if(ans > c2) ans = c2;
		if(ans > c3) ans = c3;
		if(c % 3 == 0) ans += 850 - (int)(850 * 3 * 0.12);
		else ans += 850;
		return ans;
	}
}