#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, c, d, e, f, sum1, sum2, max;
  cin >> a >> b >> c >> d;
  if (a % b == 0)
    cout << "0" << endl;
  else {
    sum1 = min((b - (a % b)) * c, (a % b) * d);
    cout << sum1 << endl;
  }
}
