#include <bits/stdc++.h>
using namespace std;
int zhs(int n) { return n * (n - 1) / 2; }
bool isP(long long n) {
  for (long long i = 2; i <= sqrt(n); ++i)
    if (n % i == 0) return false;
  return true;
}
bool yuanyin6(char c) {
  switch (c) {
    case 'a':
    case 'e':
    case 'i':
    case 'o':
    case 'u':
    case 'y':
      return true;
      break;
    default:
      return false;
      break;
  }
}
bool check(const int a[55][55], int n, int x, int y) {
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      if (a[x][i] + a[j][y] == a[x][y]) return true;
  return false;
}
int work(int n, int p, int m) {
  long long v = 0;
  long long bs = 1;
  int half = 0;
  long long back = n;
  while (n > 0) {
    bs *= 10;
    v = v * 10 + n % 10;
    n /= 10;
  }
  v += back * bs;
  return (v + m) % p;
}
struct a230 {
  int s;
  int b;
  bool operator<(a230 a) { return s < a.s; }
};
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  if (b == 0) return a;
  if (a % b == 0) return b;
  return gcd(b, a % b);
}
long long data[300005] = {0};
long long data2[300005] = {0};
void initFib() {
  data[1] = 1;
  for (int i = 2; data[i - 1] < 1000000000; i++)
    data[i] = data[i - 1] + data[i - 2];
}
void init2048() {
  data[0] = 1;
  for (int i = 1; i < 13; i++) data[i] = data[i - 1] * 2;
}
bool isI(int i) {
  int a[10] = {0};
  while (i > 0) {
    a[i % 10]++;
    i /= 10;
  }
  for (int i = 0; i < 10; i++)
    if (a[i] > 1) return false;
  return true;
}
void init(int num, int len) {
  data[0] = 1;
  for (int i = 1; i < len; ++i) data[i] = num * data[i - 1];
}
void a1251() {
  string s;
  cin >> s;
  int a[26] = {0};
  for (int i = 0; i < s.length(); ++i)
    if (i == s.length() - 1 || s[i] != s[i + 1])
      a[s[i] - 'a'] = 1;
    else
      ++i;
  for (int i = 0; i < 26; ++i)
    if (a[i] == 1) cout << (char)('a' + i);
  cout << endl;
}
void b465() {
  int n;
  cin >> n;
  int p, c;
  cin >> p;
  int sum = 0, seg = 0;
  if (p == 1) {
    sum++;
    seg++;
  }
  for (int i = 1; i < n; ++i) {
    cin >> c;
    if (c == 1) {
      sum++;
      if (p != 1) seg++;
    }
    p = c;
  }
  if (sum == 0)
    cout << 0;
  else
    cout << sum + seg - 1;
}
void a879() {
  int n;
  cin >> n;
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    int s, d;
    cin >> s >> d;
    if (sum < s)
      sum = s;
    else {
      sum = s + ((sum - s) / d + 1) * d;
    }
  }
  cout << sum;
}
void d1256out(int b, int e, int len, int k, int n, string s) {
  for (int i = 0; i < b; ++i) cout << "0";
  if (k > 0 && k < len) {
    for (int i = 0; i < len - k; ++i) cout << "1";
    if (k > 0) cout << "0";
    for (int i = 0; i < k; ++i) cout << "1";
    for (int i = e + 1; i < n; ++i) cout << s[i];
  } else {
    for (int i = 0; i < len; ++i) cout << "1";
    for (int i = e; i < n; ++i) cout << s[i];
  }
  cout << endl;
}
void d1256() {
  long long k, n;
  cin >> n >> k;
  string s;
  cin >> s;
  int b, e = n, len = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == '1') {
      b = i;
      break;
    }
  }
  for (int i = b; i < n; ++i) {
    if (s[i] == '0') {
      e = i;
      break;
    }
    len++;
  }
  if (b + len >= n) {
    d1256out(b, n, len, 0, n, s);
    return;
  }
  while (e < n) {
    while (s[e] == '0' && len <= k) {
      k -= len;
      b++;
      e++;
    }
    while (e < n && s[e] == '1') {
      e++;
      len++;
    }
    if (k < len) break;
  }
  if (k > len || e >= n) k = 0;
  d1256out(b, e, len, k, n, s);
}
struct sb1256 {
  int p, v;
  bool operator<(sb1256 s) { return v < s.v; }
};
void b1256() {
  int n;
  cin >> n;
  int a[200];
  int p;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] == 1) p = i;
  }
  int b = 0;
  int m = 1;
  while (true) {
    if (b != p) {
      for (int i = p; i > b; --i) a[i] = a[i - 1];
      a[b] = m;
    } else
      p++;
    b = p;
    m = a[p];
    if (b >= n - 1) break;
    for (int i = b + 1; i < n; ++i)
      if (a[i] < m) {
        m = a[i];
        p = i;
      }
  }
  for (int i = 0; i < n; ++i) cout << a[i] << " ";
  cout << endl;
}
void c1256() {
  int n, m, d;
  cin >> n >> m >> d;
  int a[1005] = {0};
  int sum = 0;
  for (int i = 0; i < m; ++i) {
    cin >> a[i];
    sum += a[i];
  }
  int empty = n - sum;
  if (empty > (m + 1) * (d - 1))
    cout << "NO";
  else {
    int each = empty / (m + 1);
    int lef = empty % (m + 1);
    cout << "YES" << endl;
    for (int j = 0; j < m; ++j) {
      for (int i = 0; i < each; ++i) cout << 0 << " ";
      if (lef > 0) {
        cout << 0 << " ";
        lef--;
      }
      for (int i = 0; i < a[j]; ++i) cout << j + 1 << " ";
    }
    for (int i = 0; i < each; ++i) cout << 0 << " ";
  }
}
struct sb520 {
  int v, n;
};
void b520() {
  long long n, m;
  cin >> n >> m;
  queue<sb520> q;
  sb520 s;
  s.n = 0;
  s.v = n;
  q.push(s);
  long long mm = m * 3;
  if (n >= m) {
    cout << n - m;
    return;
  }
  data[n] = 1;
  while (!q.empty()) {
    sb520 temp = q.front();
    q.pop();
    if (temp.n >= mm) {
      cout << mm;
      return;
    }
    if (temp.v * 2 == m || temp.v - 1 == m) {
      cout << temp.n + 1;
      return;
    }
    if (temp.v > m)
      mm = min(mm, temp.n + temp.v - m);
    else {
      s.n = temp.n + 1;
      s.v = temp.v * 2;
      if (data[s.v] == 0) {
        data[s.v] = 1;
        q.push(s);
      }
      if (temp.v - 1 > 0) {
        s.v = temp.v - 1;
        if (data[s.v] == 0) {
          data[s.v] = 1;
          q.push(s);
        }
      }
    }
  }
  cout << mm;
  return;
}
int a217() {
  int n;
  cin >> n;
  vector<int> hv[1005], lv[1005];
  int h[1005] = {0}, l[1005] = {0};
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    hv[x].push_back(y);
    lv[y].push_back(x);
  }
  int sum = 0;
  for (int i = 1; i <= 1000; ++i) {
    if (h[i] != 0 || hv[i].size() == 0) continue;
    sum++;
    h[i] = sum;
    queue<int> hq, lq;
    for (int j = 0; j < hv[i].size(); ++j) {
      if (l[hv[i][j]] == 0) {
        l[hv[i][j]] = sum;
        lq.push(hv[i][j]);
      }
    }
    while (!lq.empty()) {
      while (!lq.empty()) {
        int y = lq.front();
        lq.pop();
        for (int j = 0; j < lv[y].size(); ++j) {
          if (h[lv[y][j]] == 0) {
            h[lv[y][j]] = sum;
            hq.push(lv[y][j]);
          }
        }
      }
      while (!hq.empty()) {
        int y = hq.front();
        hq.pop();
        for (int j = 0; j < hv[y].size(); ++j) {
          if (l[hv[y][j]] == 0) {
            l[hv[y][j]] = sum;
            lq.push(hv[y][j]);
          }
        }
      }
    }
  }
  cout << sum - 1;
}
void a1257() {
  int n, x, a, b;
  cin >> n >> x >> a >> b;
  if (a > b) swap(a, b);
  int mov = min(x, a - 1);
  a -= mov;
  x -= mov;
  mov = min(x, n - b);
  b += mov;
  cout << b - a << endl;
}
void a1256() {
  long long a, b, n, s, t1, t2, t3;
  cin >> a >> b >> n >> s;
  t1 = s / n;
  if (t1 > a) t1 = a;
  s -= t1 * n;
  if (b >= s)
    cout << "yes";
  else
    cout << "no";
  cout << endl;
}
void b1257() {
  int x, y;
  cin >> x >> y;
  if (x == 1 && y > 1 || x <= 3 && y > 3)
    cout << "no";
  else
    cout << "yes";
  cout << endl;
}
void a1245() {
  long long x, y;
  cin >> x >> y;
  if (gcd(x, y) == 1)
    cout << "Finite";
  else
    cout << "Infinite";
  cout << endl;
}
void a1155() {
  int n;
  string s;
  cin >> n >> s;
  for (int i = 1; i < s.length(); ++i) {
    if (s[i] < s[i - 1]) {
      cout << "yes" << endl;
      cout << i << " " << i + 1;
      return;
    }
  }
  cout << "no";
}
void a990() {
  long long n, m, a, b;
  cin >> n >> m >> a >> b;
  n %= m;
  cout << min(n * b, (m - n) * a);
  return;
}
int main() {
  a990();
  return 0;
}
