#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long n, m;
  int a, b;
  while (cin >> n >> m >> a >> b) {
    unsigned long long c = n % m;
    unsigned long long c2 = m - c;
    unsigned long long k = min(b * c, c2 * a);
    cout << k << endl;
  }
  return 0;
}
