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