#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, a, b, mod, build, x = 0;
  cin >> n >> m >> a >> b;
  if (n % m == 0)
    cout << x;
  else if (n > m) {
    mod = n % m;
    build = m - mod;
    build *= a;
    mod *= b;
    cout << min(build, mod);
  } else {
    build = m - n;
    build *= a;
    mod = n * b;
    cout << min(build, mod);
  }
  return 0;
}
