#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
const int inf = 0x3f3f3f3f;
long long n, k, a, b;
long long ans;
int main() {
  cin >> n >> k >> a >> b;
  if (k == 1)
    ans = (n - 1) * a;
  else {
    while (n > 1) {
      if (n % k == 0) {
        long long m = n / k;
        if ((n - m) * a < b)
          ans += (n - m) * a;
        else
          ans += b;
        n = m;
      } else {
        long long m = n % k;
        n -= m;
        if (n < 1)
          ans += (m - 1) * a;
        else
          ans += m * a;
      }
    }
  }
  cout << ans << endl;
}
