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