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