#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long A, B;
long long cost = 0;
long long m;
int main() {
  scanf("%I64d%I64d%I64d%I64d", &n, &k, &A, &B);
  long long costA, costB;
  if (k == 1) {
    cost = (n - 1) * A;
  } else {
    while (n > 1) {
      if (n % k != 0) {
        m = n - n % k;
        if (m < 1) m = 1;
        cost = cost + (long long)(n - m) * A;
        n = m;
      } else {
        m = n / k;
        costA = B;
        costB = (n - m) * A;
        if (costA > costB)
          cost = cost + costB;
        else
          cost = cost + costA;
        n = n / k;
      }
    }
  }
  printf("%I64d\n", cost);
  return 0;
}
