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