#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k, A, B;
  cin >> n >> k >> A >> B;
  long long ans = 0;
  while (n != 1) {
    if (k == 1) {
      ans += (n - 1) * A;
      n = 1;
    } else if (n % k == 0 && k != 1) {
      long long tmp = n / k;
      ans += min(B, A * (n - tmp));
      n = n / k;
    } else {
      long long c = n / k * k;
      if (c < 1) c = 1;
      ans += A * (n - c);
      n = c;
    }
  }
  cout << ans << endl;
  return 0;
}
