#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, a, b;
  while (~scanf("%lld%lld%lld%lld", &n, &m, &a, &b)) {
    long long x = 0, y = 0;
    if (n > m) {
      x = (n - m * (n / m)) * b;
      y = (((n / m) + 1) * m - n) * a;
    } else if (m > n) {
      x = n * b;
      y = (m - n) * a;
    }
    if (x <= y)
      printf("%lld", x);
    else
      printf("%lld", y);
  }
}
