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