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