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