//=======================^========================================================^=======================\\
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * *
*/
//=======================^========================================================^=======================\\
#include<iostream>
#include<math.h>
#include<stdlib.h>
// #include<bits/stdc++.h>
#include<string.h>
#include<ctype.h>
#include<set>
#include<vector>
#include <algorithm>
#include<map>
#define test ll t;cin>>t;while(t--)
#define ll long long int
#define lld long double
#define setfor for(auto it: s1)
#define parthparekh ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define fi(l,r) for(ll i = l; i < r; i++)
#define fj(l,r) for(ll j = l; j < r; j++)
#define fk(l,r) for(ll k = l; k < r; k++)
#define fir(r,l) for(ll i=r;i>=l;i--)
#define fjr(r,l) for(ll j=r;j>=l;j--)
#define pb push_back
#define em emplace_back
#define yy cout<<"YES\n"
#define nn cout<<"NO\n"
using namespace std;
int main()
{
parthparekh;
ll n,m,a,b,ans=0,ans1=0;
cin>>n>>m>>a>>b;
if(n%m==0)
cout<<0<<endl;
else
{
ans=(n%m)*b;
ans1=(m-(n%m))*a;
cout<<min(ans,ans1)<<endl;
}
}
1032. Stream of Characters | 987. Vertical Order Traversal of a Binary Tree |
952. Largest Component Size by Common Factor | 212. Word Search II |
174. Dungeon Game | 127. Word Ladder |
123. Best Time to Buy and Sell Stock III | 85. Maximal Rectangle |
84. Largest Rectangle in Histogram | 60. Permutation Sequence |
42. Trapping Rain Water | 32. Longest Valid Parentheses |
Cutting a material | Bubble Sort |
Number of triangles | AND path in a binary tree |
Factorial equations | Removal of vertices |
Happy segments | Cyclic shifts |
Zoos | Build a graph |
Almost correct bracket sequence | Count of integers |
Differences of the permutations | Doctor's Secret |
Back to School | I am Easy |
Teddy and Tweety | Partitioning binary strings |