#include <bits/stdc++.h>
using namespace std;
void setIO(const string &s) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
}
signed main() {
  setIO("input");
  long long n, k, a, b;
  cin >> n >> k >> a >> b;
  if (k == 1) {
    cout << (n - 1) * a << '\n';
    return 0;
  }
  long long ans = 0;
  while (n > 0) {
    ans += a * (n % k);
    n -= n % k;
    if (n == 0) break;
    long long acost = a * (n - n / k);
    if (acost <= b)
      ans += acost;
    else
      ans += b;
    n /= k;
  }
  ans -= a;
  cout << ans << '\n';
}
