#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, k, a, b;
  cin >> n >> k >> a >> b;
  unsigned long long ans = 0;
  if (k == 1) {
    cout << (n - 1) * a;
    return 0;
  }
  if (n == 1) {
    cout << 0;
    return 0;
  }
  while (n != 1 && n != 0) {
    if (n % k == 0) {
      ans += min(b, (n - n / k) * a);
      n /= k;
    } else {
      if (n >= k) {
        ans += n % k * a;
        n -= (n % k);
      } else {
        ans += (n - 1) * a;
        n = 1;
      }
    }
  }
  cout << ans;
  return 0;
}
