#include <bits/stdc++.h>
using namespace std;
long long n, m, a, b;
int main() {
  scanf("%lld %lld %lld %lld", &n, &m, &a, &b);
  long long int mm = n % m;
  unsigned long long ans = min((m - mm) * a, mm * b);
  printf("%llu\n", ans);
  return 0;
}
