#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100 + 5;
int a[MAX_N];
int main() {
  long long n, k, a, b, ans = 0;
  cin >> n >> k >> a >> b;
  if (k == 1) {
    cout << (n - 1) * a << endl;
    return 0;
  }
  while (n > 1) {
    if (n % k == 0) {
      long long tmp = n - n / k;
      if (tmp * a > b)
        ans += b;
      else
        ans += tmp * a;
      n = n / k;
    } else {
      if (n > k) {
        long long tmp = n - n / k * k;
        n -= tmp;
        ans += a * tmp;
      } else {
        ans += a * (n - 1);
        n = 1;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
