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