#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, a, b, p, c1, c2;
  cin >> n >> m >> a >> b;
  p = n % m;
  c1 = b * p;
  c2 = a * (m - p);
  cout << min(c1, c2);
  return 0;
}
