#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long k, a, b;
  cin >> k >> a >> b;
  long long sum1 = (n - 1) * a;
  long long sum = 0;
  if (k == 1) {
    cout << sum1 << endl;
    return (0);
  }
  long long ans = sum1;
  while (n > 1) {
    if (n % k == 0) {
      sum += b;
      n = n / k;
      ans = min(ans, sum + (n - 1 >= 0 ? (n - 1) * a : 0));
    } else {
      ans = min(ans, sum + (n - 1 >= 0 ? (n - 1) * a : 0));
      sum += (n < k ? (n % k - 1) * a : (n % k) * a);
      n = n - (n % k);
    }
  }
  cout << ans << endl;
}
