2 1
1 1
 4 1
2 2 1 1
 10 1
2 6 3 4 2 4 4 3 2 1
 2 1
999152 999153
 8 1000000
1 1 5 1000000 1000000 2 2 2
 9 2
1 6 1 5 5 8 6 8 7
 15 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
 1 4
8
 10 1
6 3 1 3 6 4 1 3 6 4
 10 1
1 2 3 5 6 8 10 11 9 4
 7 2
1 5 5 8 9 8 8
 2 1000000
1 1000000
 8 2
3 13 9 8 3 13 9 14
 1 1
1
 2 1
1 2

2
 2
 4
 1
 2
 4
 15
 1
 7
 2
 4
 1
 5
 1
 1

#include <bits/stdc++.h>
using namespace std;
bool compare(string s1, string s2) { return s1.length() < s2.length(); }
int main() {
  long n, m, a, b;
  cin >> n >> m >> a >> b;
  long temp1 = n - m;
  long temp2 = n % m;
  if (temp1 == 0 || temp2 == 0) {
    cout << 0;
  } else {
    long c = temp2 * b;
    long d = (m - temp2) * a;
    cout << (c > d ? d : c);
  }
  return 0;
}
