#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const ll MOD = 1e9 + 7;
ll k, A, B;
ll solve(ll n) {
  if (n == 1) return 0;
  if (n < k) return (n - 1) * A;
  ll rem = n % k;
  n = n - rem;
  if ((n - n / k) * A > B) return (rem * A) + B + solve(n / k);
  return (rem * A) + (n - n / k) * A + solve(n / k);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  ll n;
  cin >> n >> k >> A >> B;
  if (k == 1) {
    cout << (n - 1) * A;
    return 0;
  }
  cout << solve(n);
  return 0;
}
