#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int main() {
  long long int n, k, a, b;
  cin >> n >> k >> a >> b;
  if (k == 1) {
    cout << (n - 1) * a;
    return 0;
  }
  long long int ans = 0;
  while (n != 1) {
    if (n < k) {
      ans += (n - 1) * a;
      break;
    }
    ans += (n % k) * a;
    n = n - n % k;
    long long int x = n / k;
    long long int c1 = (n - x) * a;
    long long int c2 = b;
    ans += min(c1, c2);
    n = x;
  }
  cout << ans << endl;
}
