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