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