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