#include <bits/stdc++.h>
using namespace std;
long long int hcf(long long int a, long long int b) {
  if (!a)
    return (b);
  else
    return (hcf(b % a, a));
}
long long findGCD(vector<long long> arr, long long n) {
  long long result = arr[0];
  for (long long i = 1; i < n; i++) {
    result = hcf(arr[i], result);
    if (result == 1) {
      return 1;
    }
  }
  return result;
}
long long int lcm(long long int a, long long int b) {
  return ((a * b) / hcf(a, b));
}
bool sortbysec(long int a, long int b) { return (a > b); }
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
vector<long long> primeFactors(long long n) {
  vector<long long> ans;
  while (n % 2 == 0) {
    ans.push_back(2);
    n = n / 2;
  }
  for (long long i = 3; i <= sqrt(n); i = i + 2) {
    while (n % i == 0) {
      ans.push_back(i);
      n = n / i;
    }
  }
  if (n > 2) ans.push_back(n);
  return ans;
}
long long ans(long long n, long long k, long long a, long long b) {
  long long i, c, d;
  if ((n - 1) * a < b) {
    return (n - 1) * a;
  } else {
    if (n % k == 0) {
      c = b;
      d = ((n - ((n / k))) * a);
      return min(c, d) + ans(n / k, k, a, b);
    } else {
      return ((n - ((n / k) * k)) * a) + ans((n / k) * k, k, a, b);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long n, k, a, b, i, c = 0;
  cin >> n >> k >> a >> b;
  if ((n - 1) * a < b || k == 1) {
    cout << ((n - 1) * a);
  } else {
    cout << ans(n, k, a, b);
  }
  return 0;
}
