#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool inrange(T a, T l, T r) {
  if (l > r) swap(l, r);
  return (a >= l and a <= r);
}
template <typename T, typename U>
inline bool exist(T val, U &any) {
  return (any.find(val) != any.end());
}
template <typename T>
inline void inp(T &any) {
  cin >> any;
}
template <typename T, typename... U>
inline void inp(T &a, U &...b) {
  cin >> a;
  inp(b...);
}
template <typename T>
inline istream &operator>>(istream &in, vector<T> &a) {
  for (auto &x : a) in >> x;
  return in;
}
template <typename T, typename U>
inline istream &operator>>(istream &in, pair<T, U> &a) {
  in >> a.first >> a.second;
  return in;
}
void solve(long long int &T) {
  long long int n, k, a, b;
  inp(n, k, a, b);
  11;
  long long int ans = (n - 1) * a, cost = 0;
  long long int x = n;
  while (k != 1 and x != 1) {
    if (x < k) {
      cost += (x - 1) * a;
      break;
    }
    cost += (x % k) * a;
    x -= (x % k);
    cost += min(b, a * (x - x / k));
    x /= k;
  }
  if (k != 1) ans = min(ans, cost);
  std::cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  for (long long int i = (1); i < (t + 1); i++) {
    cerr << "Case #" << i << "\n";
    solve(i);
  }
  return 0;
}
