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