#include <bits/stdc++.h>
using namespace std;
struct __s {
  __s() {
    if (1) {
      ios_base::Init i;
      cin.sync_with_stdio(0);
      cin.tie(0);
    }
  }
  ~__s() {
    if (!1)
      fprintf(stderr, "Execution time: %.3lf s.\n",
              (double)clock() / CLOCKS_PER_SEC);
    long long n;
    cin >> n;
  }
} __S;
int main(void) {
  long long n, k, a, b;
  cin >> n >> k >> a >> b;
  if (k == 1) {
    cout << (n - 1) * a << '\n';
    return 0;
  }
  long long ans = 0;
  while (n != 1) {
    long long x;
    long long res;
    if (n % k == 0) {
      x = n / k;
      long long res1 = b;
      long long res2 = (n - x) * a;
      res = min(res1, res2);
    } else if (n < k) {
      x = 1;
      res = (n - x) * a;
    } else {
      x = n / k * k;
      res = (n - x) * a;
    }
    ans += res;
    n = x;
  }
  cout << ans << '\n';
  return 0;
}
