#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
long long n, a, b, k;
map<long long, long long> dp;
long long fn(long long x) {
  if (x < k) return (x - 1) * a;
  if (!dp[x]) {
    if (x % k == 0)
      dp[x] = fn(x / k) + min(b, a * (x - x / k));
    else
      dp[x] = fn(x - x % k) + a * (x % k);
  }
  return dp[x];
}
int main() {
  cin >> n >> k >> a >> b;
  if (k == 1) {
    cout << (n - 1) * a;
    return 0;
  }
  cout << fn(n);
  return 0;
}
