#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long x, k, A, B;
  cin >> x >> k >> A >> B;
  if (k == 1) {
    cout << A * (x - 1) << endl;
    return 0;
  }
  long long cost = 0;
  while (x != 1) {
    long long mod = x % k;
    if (mod != 0) {
      if (mod >= x) {
        cost += A * (x - 1);
        break;
      }
      x -= mod;
      cost += A * mod;
    } else {
      long long next_x = x / k;
      cost += (B < (x - next_x) * A) ? B : (x - next_x) * A;
      x = next_x;
    }
  }
  cout << cost << endl;
  return 0;
}
