#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, a, b, mn = 0;
  cin >> n >> k >> a >> b;
  long long g = (n - 1) * a;
  if (k == 1) {
    cout << (n - 1) * a << endl;
    return 0;
  }
  while (n != 1) {
    if (n % k == 0) {
      n /= k;
      mn += b;
    } else {
      if (n % k != n) {
        mn += a * (n % k);
        n -= (n % k);
      } else {
        mn += a * (n % k);
        n -= ((n % k));
        mn -= a;
        n += 1;
      }
    }
    g = min(g, mn + ((n - 1) * a));
  }
  cout << g << endl;
  return 0;
}
