#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int MAXN = 3e5 + 10;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) {
  long long c;
  while (a != 0) {
    c = a;
    a = b % a;
    b = c;
  }
  return b;
};
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int main() {
  int n, k, A, B;
  cin >> n >> k >> A >> B;
  long long ans = 0ll;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  if (k == 1) {
    cout << 1ll * A * (n - 1) << endl;
    return 0;
  }
  while (1) {
    int x = n % k;
    if (x == n)
      ans += 1ll * (n - 1) * A, n = 1;
    else
      ans += 1ll * x * A, n -= x;
    if (n == 1) break;
    int y = n / k;
    int z = n - y;
    ans += min(1ll * z * A, 1ll * B);
    n = y;
    if (n == 1) break;
  }
  cout << ans << endl;
}
