#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const long double EPS = 1e-12;
long long n, k, a, b, x;
long long ans;
long long t1, t2, t3;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k >> a >> b;
  x = n;
  if (k == 1) {
    cout << (x - 1) * a;
    return 0;
  }
  while (x != 1) {
    t1 = (x - 1) * a;
    t2 = (x % k) * a + b;
    t3 = (x % k) * a + (x - (x % k) - (x / k)) * a;
    if ((t1 <= t2)) {
      if (t1 <= t3) {
        x = 1;
        ans += t1;
      } else {
        x = x / k;
        ans += t3;
      }
    } else {
      if (t2 <= t3) {
        x = x - (x % k);
        x = x / k;
        ans += t2;
      } else {
        x = x / k;
        ans += t3;
      }
    }
  }
  cout << ans;
  return 0;
}
