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