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