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