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