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