#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
int power(int a, int b) {
  if (b == 0) {
    return 1;
  } else if (b % 2 == 0) {
    return power(a * a, b / 2);
  } else {
    return a * power(a * a, (b - 1) / 2);
  }
}
void solve() {
  long long int n, k, a, b, ans = 0, flag = 0;
  cin >> n >> k >> a >> b;
  long long int x = n;
  if (k == 1) {
    cout << (x - 1) * a;
    return;
  }
  while (x != 1) {
    if (x % k && x > k) {
      ans += (x % k) * (a);
      x = x - (x % k);
    } else if (x < k) {
      ans += (x - 1) * a;
      x = 1;
    } else {
      ans += min((x - (x / k)) * a, b);
      x = x / k;
    }
  }
  cout << ans;
  return;
}
signed main() {
  std::ios_base::sync_with_stdio(false);
  int t = 1;
  while (t--) solve();
  return 0;
  return 0;
}
