#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, a, b;
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      pq;
  unordered_map<long long, unordered_set<int> > mp;
  auto addtoq = [&pq, &mp](long long c, int s) {
    pair<long long, int> op = make_pair(c, s);
    if (mp.find(op.first) == mp.end() ||
        mp[op.first].find(op.second) == mp[op.first].end()) {
      pq.push(op);
      mp[op.first].insert(op.second);
    }
  };
  cin >> n >> k >> a >> b;
  addtoq(0, n);
  if (k == 1) {
    cout << a * (n - 1);
    goto done;
  }
  while (!pq.empty()) {
    pair<long long, int> p = pq.top();
    pq.pop();
    if (p.second == 0) {
      continue;
    } else if (p.second == 1) {
      cout << p.first;
      goto done;
    } else if (p.second % k == 0) {
      addtoq(p.first + b, p.second / k);
      addtoq(p.first + a * (p.second - p.second / k), p.second / k);
    } else if (p.second > k) {
      addtoq(p.first + a * (p.second - (p.second / k) * k), (p.second / k) * k);
    } else {
      addtoq(p.first + a * (p.second - 1), 1);
    }
  }
done:
  return 0;
}
