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