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