#include <bits/stdc++.h>
using namespace std;
void solve();
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  while (t--) solve();
  return 0;
}
void solve() {
  long long n, m, a, b;
  cin >> n >> m >> a >> b;
  long long rem = n % m;
  cout << min(rem * b, (m - rem) * a);
  cout << "\n";
  return;
}
