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