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$ ($K \to K+1$)
  2. Cost $B$ and gain $K\times 2$ ($K \to K\times 2$)
  3. Cost $C$ and gain $K-1$ ($K \to K-1$)

Find the minimun cost to get $N$.

输入格式

There are multiple test cases in this problem.$(T\leq 10^5+5)$

In each test case,there is only one line contains four integers $N(1\leq N\leq 10^9)$, $A(0\leq A\leq 10^9)$, $B(0\leq B\leq 10^9)$, $C(0\leq C\leq 10^9)$.

输出格式

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