#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, a, b;
  cin >> n >> k >> a >> b;
  if (k == 1) {
    cout << (n - 1) * a;
    return 0;
  }
  long long ans = 0;
  while (n > 1) {
    long long cst;
    if (n % k == 0) {
      cst = b;
      int z = n - n / k;
      cst = min(cst, z * a);
      n = n / k;
    } else {
      cst = a * min((n % k), n - 1);
      n -= min((n % k), n - 1);
    }
    ans += cst;
  }
  cout << ans;
  return 0;
}
