#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int main() {
  long long n = read(), m = read(), a = read(), b = read();
  long long l = (n / m) * m;
  long long x = 1ll * (n - l) * b;
  long long y = 1ll * (l + m - n) * a;
  if (x > y)
    printf("%lld", y);
  else
    printf("%lld", x);
  return 0;
}
