#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
  std::ios::sync_with_stdio(false);
  long long n, m;
  int a, b;
  cin >> n >> m >> a >> b;
  long long k = n / m;
  cout << min((n - m * k) * b, (m * (k + 1) - n) * a) << endl;
  return 0;
}
