#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\n";
  else {
    long long x = n % m;
    long long y = m - x;
    cout << min(x * b, y * a) << endl;
    ;
  }
}
