#include <bits/stdc++.h>
int main() {
  long long int cost, n, k, a, b;
  scanf("%I64d %I64d %I64d %I64d", &n, &k, &a, &b);
  if (k == 1) {
    cost = a;
    cost = cost * (n - 1);
  } else {
    cost = n % k;
    cost = cost * a;
    n = n - n % k;
    while (b <= a * (n - n / k) && n > 1 && n % k == 0) {
      cost = cost + b;
      n = n / k;
      if (n % k != 0 && n > k) {
        cost = cost + a * (n % k);
        n = n - n % k;
      }
    }
    cost = cost + a * (n - 1);
  }
  printf("%I64d", cost);
  return 0;
}
