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