#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long int n, m, a, b;
  cin >> n >> m >> a >> b;
  long long int r = n % m;
  long long int d = n / m;
  long long int p1 = r * b;
  long long int p2 = ((d + 1) * m - n) * a;
  if (p1 > p2) {
    cout << p2;
  } else {
    cout << p1;
  }
  return 0;
}
