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