#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")\n";
}
template <class T>
ostream &operator<<(ostream &os, set<T> V) {
  os << "[";
  for (auto vv : V) os << vv << ", ";
  return os << "\b\b]\n";
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  for (auto vv : V) os << vv << ' ';
  return os << "\n";
}
template <class K, class X>
ostream &operator<<(ostream &os, map<K, X> V) {
  os << "[";
  for (auto vv : V) os << vv << ", ";
  return os << "\b\b]\n";
}
long long int ceildiv(long long int n, long long int f) {
  if (n % f) {
    return n / f + 1;
  } else
    return n / f;
}
int main() {
  long long int n, m, a, b;
  cin >> n >> m >> a >> b;
  long long int construct_price = a * (m - n % m);
  long long int demolish_price = b * (n % m);
  cout << min(construct_price, demolish_price) << endl;
  return 0;
}
