#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
using matrix = vector<vector<long long>>;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m, a, b;
  cin >> n >> m >> a >> b;
  long long mod = n % m;
  long long ans1 = mod * b;
  long long ans2 = (m - mod) * a;
  cout << min(ans1, ans2);
}
