#include<iostream>
#include<vector>
#include<queue>
using namespace std;
using ll = long long;

int main(){
    ll n, a, b, c;
    cin >> n >> a >> b >> c;

    vector<vector<pair<int,ll>>> graph(n * 2 + 1);

    // グラフの構築
    // 操作1
    for(int i = 1; i < n * 2; i++){
        graph[i].emplace_back(i + 1, a);
    }

    // 操作2
    for(int i = 1; i < n * 2; i++){
        ll nwb = b, next = i % n, up = (n <= i);
        while(nwb <= n * a){
            graph[i].emplace_back(n * up + next, nwb);
            nwb *= b;
            next *= i;
            if(next >= n) up = 1;
            next %= n;
        }
    }

    // 操作3
    ll next = 1, up = 0;
    for(int i = 1; i < n * 2; i++){
        next *= i;
        if(next >= n) up = 1;
        next %= n;
        graph[i].emplace_back(up * n + next, c);
    }

    
    vector<ll> cost(n * 2 + 1, 1e18);

    cost[1] = 0;
    priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> que;
    que.push({0, 1});

    while(que.size()){
        auto[c, p] = que.top();
        que.pop();
        if(c != cost[p]) continue;
        for(auto edge : graph[p]){
            if(cost[edge.first] > cost[p] + edge.second){
                cost[edge.first] = cost[p] + edge.second;
                que.push({cost[edge.first], edge.first});
            }
        }
    }

    cout << min(cost[n], cost[n * 2]) << endl;
}