#include <bits/stdc++.h>
using namespace std;
using namespace std;
const long long mod = 1e9 + 7;
const double eps = 1e-9;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 10;
int main() {
  long long n, m;
  scanf("%lld%lld", &n, &m);
  long long a, b;
  scanf("%lld%lld", &a, &b);
  long long num = n / m * m;
  long long p1 = (n - num) * b;
  long long p2 = (num + m - n) * a;
  long long ans = min(p1, p2);
  printf("%lld\n", ans);
  return 0;
}
