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