#include <bits/stdc++.h>
using namespace std;
long long n, k, a, b, ans;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k >> a >> b;
  if (k == 1) {
    cout << (n - 1) * a;
    return 0;
  }
  while (n > 1) {
    if (n % k != 0 && n < k) {
      ans += (n - 1) * a;
      n = 1;
    } else if (n % k != 0) {
      ans += (n % k) * a;
      n -= (n % k);
    } else {
      long long temp, temp2, val;
      val = n / k;
      temp = (n - val) * a;
      ans += min(temp, b);
      n = val;
    }
  }
  cout << ans;
  return 0;
}
