#include <bits/stdc++.h>
using namespace std;
const double pi = 3.1415926535897932384626433832795;
const double eps = 1e-12;
const int INF = 1 << 30;
const long long LINF = 1LL << 62;
const int BUFFER_SZ = 1 << 20;
const int MOD = 1000 * 1000 * 1000 + 7;
char BUFFER[BUFFER_SZ];
int gi() {
  int x;
  scanf("%d", &x);
  return x;
}
long long gll() {
  long long x;
  scanf("%lld", &x);
  return x;
}
vector<int> gvi(int n) {
  vector<int> a;
  while (n-- > 0) a.push_back(gi());
  return a;
}
string gs() {
  scanf("%s", BUFFER);
  return string(BUFFER);
}
template <class T>
void print(vector<T> &x, string format) {
  format += "%c";
  for (int i = 0; i < x.size(); ++i)
    printf(format.c_str(), x[i], i + 1 == x.size() ? '\n' : ' ');
}
void solve() {
  int n = gi();
  int k = gi();
  int A = gi();
  int B = gi();
  long long res = 0;
  if (k == 1) {
    res = 1ll * (n - 1) * A;
  } else
    while (n > 1) {
      if (n % k == 0) {
        int v = n / k;
        if (1ll * (n - v) * A < B) {
          res += 1ll * (n - v) * A;
        } else {
          res += B;
        }
        n = v;
      } else {
        int r = n % k;
        if (n - r == 0) {
          res += 1ll * (n - 1) * A;
          n = 1;
        } else {
          res += 1ll * r * A;
          n -= r;
        }
      };
    }
  printf("%lld\n", res);
}
int main() {
  solve();
  return 0;
}
