2021 年东华大学金马程序设计联赛

I. A Small Game
PDF 题面可用
你可以在这里下载。

单点时限: 1.0 sec

内存限制: 512 MB

This is a simple question. This is a simple question.This is a simple question.

You are given four integers N,A,B and C.

Now you have a integer K (K=0 initially).

Each time you can choose one of the following operations:

  1. Cost A and gain K+1 (KK+1)
  2. Cost B and gain K×2 (KK×2)
  3. Cost C and gain K1 (KK1)

Find the minimun cost to get N.

输入格式

There are multiple test cases in this problem.(T105+5)

In each test case,there is only one line contains four integers N(1N109), A(0A109), B(0B109), C(0C109).

输出格式

For each test case print one line for the minimun cost to get N.

样例

Input
1 0 0 0
10 1 10 1
10 1 0 10
10 10 0 1
Output
0
10
2
12