#include<stdio.h>
int max(int a,int b)
{
	if(a>b)return a;
	else return b;
}
int min(int a,int b)
{
	if(a>b)return b;
	else return a;
}
int main()
{
	int flag=0;
	int x1,x2,x3,x4,x5,x6,y1,y2,y3,y4,y5,y6;
	scanf("%d%d%d%d%d%d%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4,&x5,&y5,&x6,&y6);
	for(int i=x1+1;i<=x2;i++)
	{
		flag=0;
		if(x4>=i&&x3<i&&x6>=i&&x5<i)
		{
			if(max(y4,y6)>=y2&&min(y5,y3)<=y1)
			{
				if(max(y4,y6)==y4)
				{
					if(y6>=y3)flag=1;
					else
					{
						if(y3<=y1)flag=1;
						else if(y6>=y2)flag=1;
					}
				}
				else if(max(y4,y6)==y6)
				{
					if(y4>=y5)flag=1;
					else
					{
						if(y5<=y1)flag=1;
						else if(y4>=y2)flag=1;
					}
				}
			}
		}
		else if(x4>=i&&x3<i)
		{
			if(y4>=y2&&y3<=y1)flag=1;
		}
		else if(x6>=i&&x5<i)
		{
			if(y6>=y2&&y5<=y1)flag=1;
		}
		if(flag!=1)
		{
			flag=-1;
			break;
		}
	}
	if(flag==-1)printf("YES\n");
	else printf("NO\n");
	return 0;
}

#include <stdio.h>
#include <string.h>

typedef struct{
    int x;
    int y;
} point;

typedef struct{
    point BL;
    point TR;
} square;

int inside (point w1, point w2, point b1, point b2){
    if (w1.x >= b1.x && w1.y >= b1.y && w2.x <= b2.x && w2.y <= b2.y){
        return 1;
    }
    else {
        return 0;
    }
}

int main(){
    square w1, b1, b2;
    square left, right, top, bottom;
    scanf("%d %d %d %d", &w1.BL.x, &w1.BL.y, &w1.TR.x, &w1.TR.y);
    scanf("%d %d %d %d", &b1.BL.x, &b1.BL.y, &b1.TR.x, &b1.TR.y);
    scanf("%d %d %d %d", &b2.BL.x, &b2.BL.y, &b2.TR.x, &b2.TR.y);

    left = (b1.BL.x<b2.BL.x)?b1:b2;
    right = (b1.BL.x<b2.BL.x)?b2:b1;
    top = (b1.TR.y<b2.TR.y)?b2:b1;
    bottom = (b1.TR.y<b2.TR.y)?b1:b2;

    if (w1.BL.x>=b1.BL.x && w1.TR.x<=b1.TR.x
     && w1.BL.y>=b1.BL.y && w1.TR.y<=b1.TR.y ||
     w1.BL.x>=b2.BL.x && w1.TR.x<=b2.TR.x
     && w1.BL.y>=b2.BL.y && w1.TR.y<=b2.TR.y){
        printf("NO\n");
    } else if (left.TR.x>=right.BL.x && w1.BL.y>=b1.BL.y && w1.BL.y>=b2.BL.y
     && w1.TR.y<=b1.TR.y && w1.TR.y<=b2.TR.y
     && w1.BL.x>=left.BL.x && w1.TR.x<=right.TR.x
     ) {
        printf("NO\n");
    } else if (top.BL.y<=bottom.TR.y && w1.BL.x>=b1.BL.x && w1.BL.x>=b2.BL.x
     && w1.TR.x<=b1.TR.x && w1.TR.x<=b2.TR.x
     && w1.BL.y>=bottom.BL.y && w1.TR.y<=top.TR.y
     ) {
        printf("NO\n");
    } else {
        printf("YES\n");
    }

    return 0;
}

#include <stdio.h>
#include <stdlib.h>

#define UL 0
#define UR 1
#define BL 2
#define BR 3
#define h 1
//printf("here! line: %d ", __LINE__); fflush(stdout)
typedef unsigned long long	ult;

typedef struct	s_po
{
	int x, y;
}				t_po;

typedef struct	s_sq
{
	int surface, width, height;
	t_po corner[4];
}				t_sq;

t_sq	make_square(int x1, int y1, int x2, int y2);
int		c_inshape(t_po p, t_sq s);

void	check_periphery(t_sq s1, t_sq s2, t_sq s3)
{
	t_sq s = make_square(s2.corner[UL].x - 1, s2.corner[UL].y - 1, s2.corner[BR].x + 1, s2.corner[BR].y + 1);
	t_po c1, c2;
	t_po inc[4];
	inc[UL].x = 1;
	inc[UL].y = 0;
	inc[UR].x = 0;
	inc[UR].y = 1;
	inc[BR].x = -1;
	inc[BR].y = 0;
	inc[BL].x = 0;
	inc[BL].y = -1;
	int i = -1;
	h;
	//printf("\n");
	while (++i < 4)
	{
		c1 = s.corner[i];
		c2 = s.corner[i == UL ? UR : (i == UR ? BR : (i == BR ? BL : UL))];
		while (c1.x != c2.x || c1.y != c2.y)
		{
			if (c_inshape(c1, s1) && !c_inshape(c1, s3))
			{
				printf("YES\n");
				exit(0);
			}
			c1.x += inc[i].x;
			c1.y += inc[i].y;
			//printf("\rc1.x = %d c2.x = %d c1.y = %d c2.y = %d", c1.x, c2.x, c1.y, c2.y);
		}
	}
	h;
}

int		c_inshape(t_po p, t_sq s)
{
	if (p.x >= s.corner[UL].x && p.x <= s.corner[BR].x &&
		p.y >= s.corner[UL].y && p.y <= s.corner[BR].y)
		return (1);
	return (0);
}

t_sq	make_square(int x1, int y1, int x2, int y2)
{
	t_sq ret;

	ret.corner[UL].x = x1;
	ret.corner[UL].y = y1;
	ret.corner[UR].x = x2;
	ret.corner[UR].y = y1;
	ret.corner[BR].x = x2;
	ret.corner[BR].y = y2;
	ret.corner[BL].x = x1;
	ret.corner[BL].y = y2;
	ret.height = y2 - y1;
	ret.width = x2 - x1;
	ret.surface = ret.height * ret.width;
	return (ret);
}

int		main()
{
	int x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6;
	scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
	scanf(" %d %d %d %d", &x3, &y3, &x4, &y4);
	scanf(" %d %d %d %d", &x5, &y5, &x6, &y6);
	t_sq s1, s2, s3;
	t_po p;
	s1 = make_square(x1 * 2, y1 * 2, x2 * 2, y2 * 2);
	s2 = make_square(x3 * 2, y3 * 2, x4 * 2, y4 * 2);
	s3 = make_square(x5 * 2, y5 * 2, x6 * 2, y6 * 2);
	h;
	// if (s3.surface + s2.surface < s1.surface)
	// {
	// 	printf("YES\n");
	// 	return 0;
	// }
	// else
	// {
	// 	h;
		// if ((c_inshape(s1.corner[UL], s2) || c_inshape(s1.corner[UL], s3)) &&
		// 	(c_inshape(s1.corner[UR], s2) || c_inshape(s1.corner[UR], s3)) &&
		// 	(c_inshape(s1.corner[BL], s2) || c_inshape(s1.corner[BL], s3)) &&
		// 	(c_inshape(s1.corner[BR], s2) || c_inshape(s1.corner[BR], s3)))
		// {
			t_sq s = make_square(s1.corner[UL].x, s1.corner[UL].y, s1.corner[BR].x, s1.corner[BR].y);
			t_po c1, c2;
			t_po inc[4];
			inc[UL].x = 1;
			inc[UL].y = 0;
			inc[UR].x = 0;
			inc[UR].y = 1;
			inc[BR].x = -1;
			inc[BR].y = 0;
			inc[BL].x = 0;
			inc[BL].y = -1;
			int i = -1;
			h;
			//printf("\n");
			//printf("s.corner[UL] = (%d, %d), s.corner[BR] = (%d, %d)\n", s.corner[UL].x, s.corner[UL].y, s.corner[BR].x, s.corner[BR].y);
			while (++i < 4)
			{
				c1 = s.corner[i];
				c2 = s.corner[i == UL ? UR : (i == UR ? BR : (i == BR ? BL : UL))];
				while (c1.x != c2.x || c1.y != c2.y)
				{
					//printf("checking point (%d, %d)\n", c1.x, c1.y);
					if (!c_inshape(c1, s2) && !c_inshape(c1, s3))
					{
						printf("YES\n");
						return (0);
					}
					c1.x += inc[i].x;
					c1.y += inc[i].y;
					//printf("\rc1.x = %d c2.x = %d c1.y = %d c2.y = %d", c1.x, c2.x, c1.y, c2.y);
				}
			}
		// }
		// else
		// {
		// 	printf("YES\n");
		// 	return 0;
		// }
	// }
	printf("NO\n");
}

#include<stdio.h>

long long int fun(int x1,int y1,int X1,int Y1,int x2,int y2,int X2,int Y2)
{
	long long int A=0;
	if(y2<Y1 && y1<Y2 && x2<X1 && x1<X2)
	{
		if(y2<y1) y2=y1;
		if(Y1<Y2) Y2=Y1;
		if(x2<x1) x2=x1;
		if(X1<X2) X2=X1;
		A=(long long int)(X2-x2)*(Y2-y2);
	}
	return A;
}

int main()
{
	int x1,y1,X1,Y1,x2,y2,X2,Y2,x3,y3,X3,Y3;
	scanf("%d%d%d%d%d%d%d%d%d%d%d%d",&x1,&y1,&X1,&Y1,&x2,&y2,&X2,&Y2,&x3,&y3,&X3,&Y3);
	if(y2<y1) y2=y1;
	if(Y1<Y2) Y2=Y1;
	if(x2<x1) x2=x1;
	if(X1<X2) X2=X1;
	if(y3<y1) y3=y1;
	if(Y1<Y3) Y3=Y1;
	if(x3<x1) x3=x1;
	if(X1<X3) X3=X1;
	long long int A1=fun(x1,y1,X1,Y1,x2,y2,X2,Y2);
	long long int A2=fun(x1,y1,X1,Y1,x3,y3,X3,Y3);
	long long int A3=fun(x2,y2,X2,Y2,x3,y3,X3,Y3);
	long long int A=(long long int)(X1-x1)*(Y1-y1);
	A=A-A1-A2+A3;
//	printf("%lld\n%lld\n%lld\n%lld\n",A,A1,A2,A3);
	if(A>0) printf("YES\n");
	else printf("NO\n");
	return 0;
}

#include <stdio.h>
double wXF, wYF, wXS, wYS;
double aXF, aYF, aXS, aYS;
double bXF, bYF, bXS, bYS;
double sX[6];
int xC = 0;
double sY[6];
int yC = 0;
char C(double dX, double dY, double xA, double yA, double xB, double yB)
{
    char mark = 0;
    if (dX >= xA && dX <= xB)
    {
        if (dY >= yA && dY <= yB)
        {
            mark = 1;
        }
    }
    return mark;
}
char cE(double dX, double dY)
{
    char mark = 0;
    if (C(dX, dY, aXF, aYF, aXS, aYS) == 0 && C(dX, dY, bXF, bYF, bXS, bYS) == 0)
    {
        if (C(dX, dY, wXF, wYF, wXS, wYS))
        {
            mark = 1;
        }
    }
    return mark;
}
int main()
{
    int i;
    int a, b;
    scanf("%lf %lf %lf %lf", &wXF, &wYF, &wXS, &wYS);
    sX[xC] = wXF;
    xC++;
    sY[yC] = wYF;
    yC++;
    sX[xC] = wXS;
    xC++;
    sY[yC] = wYS;
    yC++;
    scanf("%lf %lf %lf %lf", &aXF, &aYF, &aXS, &aYS);
    sX[xC] = aXF;
    xC++;
    sY[yC] = aYF;
    yC++;
    sX[xC] = aXS;
    xC++;
    sY[yC] = aYS;
    yC++;
    scanf("%lf %lf %lf %lf", &bXF, &bYF, &bXS, &bYS);
    sX[xC] = bXF;
    xC++;
    sY[yC] = bYF;
    yC++;
    sX[xC] = bXS;
    xC++;
    sY[yC] = bYS;
    yC++;
    for (a = 0; a < xC; a++)
    {
        for (b = 0; b < yC; b++)
        {
            if (cE(sX[a] - 0.5, sY[b]))
            {
                printf("YES");
                break;
            }
            else if (cE(sX[a] + 0.5, sY[b]))
            {
                printf("YES");
                break;
            }
            else if (cE(sX[a], sY[b] - 0.5))
            {
                printf("YES");
                break;
            }
            else if (cE(sX[a], sY[b] + 0.5))
            {
                printf("YES");
                break;
            }
        }
        if (b < yC)
        {
            break;
        }
    }
    if (a == xC)
    {
        printf("NO");
    }
    return 0;
}

#include<stdio.h>
struct mystuct{
	int x1,y1,x2,y2;
};
int main(void)
{
	struct mystuct input1,input2,input3;
	scanf("%d %d %d %d",&input1.x1,&input1.y1,&input1.x2,&input1.y2);
	scanf("%d %d %d %d",&input2.x1,&input2.y1,&input2.x2,&input2.y2);
	scanf("%d %d %d %d",&input3.x1,&input3.y1,&input3.x2,&input3.y2);
	getchar();
	if(input2.x1 <= input1.x1 && input2.y1 <= input1.y1 &&
	   input2.x2 >= input1.x2 && input2.y2 >= input1.y2) printf("NO"); //b全覆盖a
	else if(input3.x1 <= input1.x1 && input3.y1 <= input1.y1 &&
	   	 	input3.x2 >= input1.x2 && input3.y2 >= input1.y2) printf("NO"); //c全覆盖a
	else if(input2.y1 <= input1.y1 && input2.y2 >= input1.y2 &&
			input3.y1 <= input1.y1 && input3.y2 >= input1.y2 &&
			input2.x1 <= input1.x1 && input3.x1 <= input2.x2 &&
			input3.x2 >= input1.x2) printf("NO"); //b,c左右覆盖
	else if(input3.y1 <= input1.y1 && input3.y2 >= input1.y2 &&
			input2.y1 <= input1.y1 && input2.y2 >= input1.y2 &&
			input3.x1 <= input1.x1 && input2.x1 <= input3.x2 &&
			input2.x2 >= input1.x2) printf("NO"); //c,b左右覆盖
	else if(input2.x1 <= input1.x1 && input2.x2 >= input1.x2 &&
			input3.x1 <= input1.x1 && input3.x2 >= input1.x2 &&
			input2.y1 <= input1.y1 && input3.y2 >= input1.y2 &&
			input2.y2 >= input3.y1) printf("NO"); //b,c上下覆盖
	else if(input3.x1 <= input1.x1 && input3.x2 >= input1.x2 &&
			input2.x1 <= input1.x1 && input2.x2 >= input1.x2 &&
			input3.y1 <= input1.y1 && input2.y2 >= input1.y2 &&
			input3.y2 >= input2.y1) printf("NO"); //c,b上下覆盖
	else printf("YES"); //还有白色部分露出
	return 0;
}

#include<stdio.h>
int max(int a,int b)
{
	if(a>b)return a;
	else return b;
}
int min(int a,int b)
{
	if(a>b)return b;
	else return a;
}
int main()
{
	int flag=0;
	int x1,x2,x3,x4,x5,x6,y1,y2,y3,y4,y5,y6;
	scanf("%d%d%d%d%d%d%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4,&x5,&y5,&x6,&y6);
	for(int i=x1;i<=x2;i++)
	{
		flag=0;
		if(x4>=i&&x3<i&&x6>=i&&x5<i)
		{
			if(max(y4,y6)>=y2&&min(y5,y3)<=y1)
			{
				if(max(y4,y6)==y4)
				{
					if(y6>=y3)flag=1;
					else
					{
						if(y3<=y1)flag=1;
						else if(y6>=y2)flag=1;
					}
				}
				else if(max(y4,y6)==y6)
				{
					if(y4>=y5)flag=1;
					else
					{
						if(y5<=y1)flag=1;
						else if(y4>=y2)flag=1;
					}
				}
			}
		}
		else if(x4>=i&&x3<i)
		{
			if(y4>=y2&&y3<=y1)flag=1;
		}
		else if(x6>=i&&x5<i)
		{
			if(y6>=y2&&y5<=y1)flag=1;
		}
		if(flag!=1)
		{
			flag=-1;
			break;
		}
	}
	if(flag==-1)printf("YES\n");
	else printf("NO\n");
	return 0;
}

#include <stdio.h>
#include <stdlib.h>

#define UL 0
#define UR 1
#define BL 2
#define BR 3
#define h 1
//printf("here! line: %d ", __LINE__); fflush(stdout)
typedef unsigned long long	ult;

typedef struct	s_po
{
	int x, y;
}				t_po;

typedef struct	s_sq
{
	int surface, width, height;
	t_po corner[4];
}				t_sq;

t_sq	make_square(int x1, int y1, int x2, int y2);
int		c_inshape(t_po p, t_sq s);

void	check_periphery(t_sq s1, t_sq s2, t_sq s3)
{
	t_sq s = make_square(s2.corner[UL].x - 1, s2.corner[UL].y - 1, s2.corner[BR].x + 1, s2.corner[BR].y + 1);
	t_po c1, c2;
	t_po inc[4];
	inc[UL].x = 1;
	inc[UL].y = 0;
	inc[UR].x = 0;
	inc[UR].y = 1;
	inc[BR].x = -1;
	inc[BR].y = 0;
	inc[BL].x = 0;
	inc[BL].y = -1;
	int i = -1;
	h;
	//printf("\n");
	while (++i < 4)
	{
		c1 = s2.corner[i];
		c2 = s2.corner[i == UL ? UR : (i == UR ? BR : (i == BR ? BL : UL))];
		while (c1.x != c2.x || c1.y != c2.y)
		{
			if (c_inshape(c1, s1) && !c_inshape(c1, s3))
			{
				printf("YES\n");
				exit(0);
			}
			c1.x += inc[i].x;
			c1.y += inc[i].y;
			//printf("\rc1.x = %d c2.x = %d c1.y = %d c2.y = %d", c1.x, c2.x, c1.y, c2.y);
		}
	}
	h;
}

int		c_inshape(t_po p, t_sq s)
{
	if (p.x >= s.corner[UL].x && p.x <= s.corner[BR].x &&
		p.y >= s.corner[UL].y && p.y <= s.corner[BR].y)
		return (1);
	return (0);
}

t_sq	make_square(int x1, int y1, int x2, int y2)
{
	t_sq ret;

	ret.corner[UL].x = x1;
	ret.corner[UL].y = y1;
	ret.corner[UR].x = x2;
	ret.corner[UR].y = y1;
	ret.corner[BR].x = x2;
	ret.corner[BR].y = y2;
	ret.corner[BL].x = x1;
	ret.corner[BL].y = y2;
	ret.height = y2 - y1;
	ret.width = x2 - x1;
	ret.surface = ret.height * ret.width;
	return (ret);
}

int		main()
{
	int x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6;
	scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
	scanf(" %d %d %d %d", &x3, &y3, &x4, &y4);
	scanf(" %d %d %d %d", &x5, &y5, &x6, &y6);
	t_sq s1, s2, s3;
	t_po p;
	s1 = make_square(x1, y1, x2, y2);
	s2 = make_square(x3, y3, x4, y4);
	s3 = make_square(x5, y5, x6, y6);
	h;
	if (s3.surface + s2.surface < s1.surface)
	{
		printf("YES\n");
		return 0;
	}
	else
	{
		h;
		if ((c_inshape(s1.corner[UL], s2) || c_inshape(s1.corner[UL], s3)) &&
			(c_inshape(s1.corner[UR], s2) || c_inshape(s1.corner[UR], s3)) &&
			(c_inshape(s1.corner[BL], s2) || c_inshape(s1.corner[BL], s3)) &&
			(c_inshape(s1.corner[BR], s2) || c_inshape(s1.corner[BR], s3)))
		{
			check_periphery(s1, s2, s3);
		}
		else
		{
			printf("YES\n");
			return 0;
		}
	}
	printf("NO\n");
}

#include <stdio.h>
#include <stdlib.h>

#define UL 0
#define UR 1
#define BL 2
#define BR 3
#define h 1
//printf("here! line: %d ", __LINE__); fflush(stdout)
typedef unsigned long long	ult;

typedef struct	s_po
{
	int x, y;
}				t_po;

typedef struct	s_sq
{
	int surface, width, height;
	t_po corner[4];
}				t_sq;

t_sq	make_square(int x1, int y1, int x2, int y2);
int		c_inshape(t_po p, t_sq s);

void	check_periphery(t_sq s1, t_sq s2, t_sq s3)
{
	t_sq s = make_square(s2.corner[UL].x - 1, s2.corner[UL].y - 1, s2.corner[BR].x + 1, s2.corner[BR].y + 1);
	t_po c1, c2;
	t_po inc[4];
	inc[UL].x = 1;
	inc[UL].y = 0;
	inc[UR].x = 0;
	inc[UR].y = 1;
	inc[BR].x = -1;
	inc[BR].y = 0;
	inc[BL].x = 0;
	inc[BL].y = -1;
	int i = -1;
	h;
	//printf("\n");
	while (++i < 4)
	{
		c1 = s.corner[i];
		c2 = s.corner[i == UL ? UR : (i == UR ? BR : (i == BR ? BL : UL))];
		while (c1.x != c2.x || c1.y != c2.y)
		{
			if (c_inshape(c1, s1) && !c_inshape(c1, s3))
			{
				printf("YES\n");
				exit(0);
			}
			c1.x += inc[i].x;
			c1.y += inc[i].y;
			//printf("\rc1.x = %d c2.x = %d c1.y = %d c2.y = %d", c1.x, c2.x, c1.y, c2.y);
		}
	}
	h;
}

int		c_inshape(t_po p, t_sq s)
{
	if (p.x >= s.corner[UL].x && p.x <= s.corner[BR].x &&
		p.y >= s.corner[UL].y && p.y <= s.corner[BR].y)
		return (1);
	return (0);
}

t_sq	make_square(int x1, int y1, int x2, int y2)
{
	t_sq ret;

	ret.corner[UL].x = x1;
	ret.corner[UL].y = y1;
	ret.corner[UR].x = x2;
	ret.corner[UR].y = y1;
	ret.corner[BR].x = x2;
	ret.corner[BR].y = y2;
	ret.corner[BL].x = x1;
	ret.corner[BL].y = y2;
	ret.height = y2 - y1;
	ret.width = x2 - x1;
	ret.surface = ret.height * ret.width;
	return (ret);
}

int		main()
{
	int x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6;
	scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
	scanf(" %d %d %d %d", &x3, &y3, &x4, &y4);
	scanf(" %d %d %d %d", &x5, &y5, &x6, &y6);
	t_sq s1, s2, s3;
	t_po p;
	s1 = make_square(x1, y1, x2, y2);
	s2 = make_square(x3, y3, x4, y4);
	s3 = make_square(x5, y5, x6, y6);
	h;
	if (s3.surface + s2.surface < s1.surface)
	{
		printf("YES\n");
		return 0;
	}
	else
	{
		h;
		if ((c_inshape(s1.corner[UL], s2) || c_inshape(s1.corner[UL], s3)) &&
			(c_inshape(s1.corner[UR], s2) || c_inshape(s1.corner[UR], s3)) &&
			(c_inshape(s1.corner[BL], s2) || c_inshape(s1.corner[BL], s3)) &&
			(c_inshape(s1.corner[BR], s2) || c_inshape(s1.corner[BR], s3)))
		{
			check_periphery(s1, s2, s3);
		}
		else
		{
			printf("YES\n");
			return 0;
		}
	}
	printf("NO\n");
}

#include <stdio.h>
#include <stdlib.h>

#define UL 0
#define UR 1
#define BL 2
#define BR 3
#define h 1
//printf("here! line: %d ", __LINE__); fflush(stdout)
typedef unsigned long long	ult;

typedef struct	s_po
{
	int x, y;
}				t_po;

typedef struct	s_sq
{
	int surface, width, height;
	t_po corner[4];
}				t_sq;

t_sq	make_square(int x1, int y1, int x2, int y2);
int		c_inshape(t_po p, t_sq s);

void	check_periphery(t_sq s1, t_sq s2, t_sq s3)
{
	t_sq s = make_square(s2.corner[UL].x - 1, s2.corner[UL].y - 1, s2.corner[BR].x + 1, s2.corner[BR].y + 1);
	t_po c1, c2;
	t_po inc[4];
	inc[UL].x = 1;
	inc[UL].y = 0;
	inc[UR].x = 0;
	inc[UR].y = 1;
	inc[BR].x = -1;
	inc[BR].y = 0;
	inc[BL].x = 0;
	inc[BL].y = -1;
	int i = -1;
	h;
	//printf("\n");
	while (++i < 4)
	{
		c1 = s.corner[i];
		c2 = s.corner[i == UL ? UR : (i == UR ? BR : (i == BR ? BL : UL))];
		while (c1.x != c2.x || c1.y != c2.y)
		{
			if (c_inshape(c1, s1) && !c_inshape(c1, s3))
			{
				printf("YES\n");
				exit(0);
			}
			c1.x += inc[i].x;
			c1.y += inc[i].y;
			//printf("\rc1.x = %d c2.x = %d c1.y = %d c2.y = %d", c1.x, c2.x, c1.y, c2.y);
		}
	}
	h;
}

int		c_inshape(t_po p, t_sq s)
{
	if (p.x >= s.corner[UL].x && p.x <= s.corner[BR].x &&
		p.y >= s.corner[UL].y && p.y <= s.corner[BR].y)
		return (1);
	return (0);
}

t_sq	make_square(int x1, int y1, int x2, int y2)
{
	t_sq ret;

	ret.corner[UL].x = x1;
	ret.corner[UL].y = y1;
	ret.corner[UR].x = x2;
	ret.corner[UR].y = y1;
	ret.corner[BR].x = x2;
	ret.corner[BR].y = y2;
	ret.corner[BL].x = x1;
	ret.corner[BL].y = y2;
	ret.height = y2 - y1;
	ret.width = x2 - x1;
	ret.surface = ret.height * ret.width;
	return (ret);
}

int		main()
{
	int x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6;
	scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
	scanf(" %d %d %d %d", &x3, &y3, &x4, &y4);
	scanf(" %d %d %d %d", &x5, &y5, &x6, &y6);
	t_sq s1, s2, s3;
	t_po p;
	s1 = make_square(x1, y1, x2, y2);
	s2 = make_square(x3, y3, x4, y4);
	s3 = make_square(x5, y5, x6, y6);
	h;
	if (s3.surface + s2.surface < s1.surface)
	{
		printf("YES\n");
		return 0;
	}
	else
	{
		h;
		if ((c_inshape(s1.corner[UL], s2) || c_inshape(s1.corner[UL], s3)) &&
			(c_inshape(s1.corner[UR], s2) || c_inshape(s1.corner[UR], s3)) &&
			(c_inshape(s1.corner[BL], s2) || c_inshape(s1.corner[BL], s3)) &&
			(c_inshape(s1.corner[BR], s2) || c_inshape(s1.corner[BR], s3)))
		{
			t_sq s = make_square(s1.corner[UL].x, s1.corner[UL].y, s1.corner[BR].x, s1.corner[BR].y);
			t_po c1, c2;
			t_po inc[4];
			inc[UL].x = 1;
			inc[UL].y = 0;
			inc[UR].x = 0;
			inc[UR].y = 1;
			inc[BR].x = -1;
			inc[BR].y = 0;
			inc[BL].x = 0;
			inc[BL].y = -1;
			int i = -1;
			h;
			//printf("\n");
			//printf("s.corner[UL] = (%d, %d), s.corner[BR] = (%d, %d)\n", s.corner[UL].x, s.corner[UL].y, s.corner[BR].x, s.corner[BR].y);
			while (++i < 4)
			{
				c1 = s.corner[i];
				c2 = s.corner[i == UL ? UR : (i == UR ? BR : (i == BR ? BL : UL))];
				while (c1.x != c2.x || c1.y != c2.y)
				{
					//printf("checking point (%d, %d)\n", c1.x, c1.y);
					if (!c_inshape(c1, s2) && !c_inshape(c1, s3))
					{
						printf("YES\n");
						return (0);
					}
					c1.x += inc[i].x;
					c1.y += inc[i].y;
					//printf("\rc1.x = %d c2.x = %d c1.y = %d c2.y = %d", c1.x, c2.x, c1.y, c2.y);
				}
			}
		}
		else
		{
			printf("YES\n");
			return 0;
		}
	}
	printf("NO\n");
}

#include<stdio.h>

long long int fun(int x1,int y1,int X1,int Y1,int x2,int y2,int X2,int Y2)
{
	long long int A=0;
	if(y2<Y1 && y1<Y2 && x2<X1 && x1<X2)
	{
		if(y2<y1) y2=y1;
		if(Y1<Y2) Y2=Y1;
		if(x2<x1) x2=x1;
		if(X1<X2) X2=X1;
		A=(long long int)(X2-x2)*(Y2-y1);
	}
	return A;
}

int main()
{
	int x1,y1,X1,Y1,x2,y2,X2,Y2,x3,y3,X3,Y3;
	scanf("%d%d%d%d%d%d%d%d%d%d%d%d",&x1,&y1,&X1,&Y1,&x2,&y2,&X2,&Y2,&x3,&y3,&X3,&Y3);
	if(y2<y1) y2=y1;
	if(Y1<Y2) Y2=Y1;
	if(x2<x1) x2=x1;
	if(X1<X2) X2=X1;
	if(y3<y1) y3=y1;
	if(Y1<Y3) Y3=Y1;
	if(x3<x1) x3=x1;
	if(X1<X3) X3=X1;
	long long int A1=fun(x1,y1,X1,Y1,x2,y2,X2,Y2);
	long long int A2=fun(x1,y1,X1,Y1,x3,y3,X3,Y3);
	long long int A3=fun(x2,y2,X2,Y2,x3,y3,X3,Y3);
	long long int A=(long long int)(X1-x1)*(Y1-y1);
	A=A-A1-A2+A3;
//	printf("%lld\n%lld\n%lld\n%lld\n",A,A1,A2,A3);
	if(A>0) printf("YES\n");
	else printf("NO\n");
	return 0;
}

#include <stdio.h>
int wXF, wYF, wXS, wYS;
int aXF, aYF, aXS, aYS;
int bXF, bYF, bXS, bYS;
int sX[6];
int xC = 0;
int dX[6];
int sY[6];
int yC = 0;
int dY[6];
char cB(int dX, int dY, int xA, int yA, int xB, int yB)
{
    char mark = 0;
    if (dX > xA && dX < xB)
    {
        if (dY > yA && dY < yB)
        {
            mark = 1;
        }
    }
    return mark;
}
char cW(int dX, int dY, int xA, int yA, int xB, int yB)
{
    char mark = 0;
    if (dX >= xA && dX <= xB)
    {
        if (dY >= yA && dY <= yB)
        {
            mark = 1;
        }
    }
    return mark;
}
char cE(int dX, int dY)
{
    char mark = 0;
    if (cB(dX, dY, aXF, aYF, aXS, aYS) == 0 && cB(dX, dY, bXF, bYF, bXS, bYS) == 0)
    {
        if (cW(dX, dY, wXF, wYF, wXS, wYS))
        {
            mark = 1;
        }
    }
    return mark;
}
void mS(int s[], int d[], int o, int t)
{
    int i, j, k;
    int c = (o + t) / 2;
    if (o < c)
    {
        mS(d, s, o, c);
    }
    if (c + 1 < t)
    {
        mS(d, s, c + 1, t);
    }
    i = o;
    j = c + 1;
    k = o;
    while (i <= c && j <= t)
    {
        if (s[i] < s[j])
        {
            d[k] = s[i];
            i++;
        }
        else
        {
            d[k] = s[j];
            j++;
        }
        k++;
    }
    while (i <= c)
    {
        d[k] = s[i];
        i++;
        k++;
    }
    while (j <= t)
    {
        d[k] = s[j];
        j++;
        k++;
    }
}
int main()
{
    int i;
    int a, b;
    scanf("%d %d %d %d", &wXF, &wYF, &wXS, &wYS);
    sX[xC] = wXF;
    xC++;
    sY[yC] = wYF;
    yC++;
    sX[xC] = wXS;
    xC++;
    sY[yC] = wYS;
    yC++;
    scanf("%d %d %d %d", &aXF, &aYF, &aXS, &aYS);
    sX[xC] = aXF;
    xC++;
    sY[yC] = aYF;
    yC++;
    sX[xC] = aXS;
    xC++;
    sY[yC] = aYS;
    yC++;
    scanf("%d %d %d %d", &bXF, &bYF, &bXS, &bYS);
    sX[xC] = bXF;
    xC++;
    sY[yC] = bYF;
    yC++;
    sX[xC] = bXS;
    xC++;
    sY[yC] = bYS;
    yC++;
    for (i = 0; i < 6; i++)
    {
        dX[i] = sX[i];
    }
    for (i = 0; i < 6; i++)
    {
        dY[i] = sY[i];
    }
    mS(sX, dX, 0, 5);
    mS(sY, dY, 0, 5);
    sX[0] = dX[0];
    xC = 1;
    for (i = 1; i < 6; i++)
    {
        if (dX[i] > sX[xC - 1])
        {
            sX[xC] = dX[i];
            xC++;
        }
    }
    sY[0] = dY[0];
    yC = 1;
    for (i = 1; i < 6; i++)
    {
        if (dY[i] > sY[yC - 1])
        {
            sY[yC] = dY[i];
            yC++;
        }
    }
    for (a = 0; a < xC - 1; a++)
    {
        for (b = 0; b < yC - 1; b++)
        {
            if (cE(sX[a], sY[b]))
            {
                if (cE(sX[a + 1], sY[b]) && cE(sX[a], sY[b + 1]))
                {
                    printf("YES");
                    break;
                }
            }
        }
        if (b < yC - 1)
        {
            break;
        }
    }
    if (a == xC - 1)
    {
        printf("NO");
    }
    return 0;
}

#include <stdio.h>
int wXF, wYF, wXS, wYS;
int aXF, aYF, aXS, aYS;
int bXF, bYF, bXS, bYS;
int sX[6];
int xC = 0;
int dX[6];
int sY[6];
int yC = 0;
int dY[6];
char cB(int dX, int dY, int xA, int yA, int xB, int yB)
{
    char mark = 0;
    if (dX > xA && dX < xB)
    {
        if (dY > yA && dY < yB)
        {
            mark = 1;
        }
    }
    return mark;
}
char cW(int dX, int dY, int xA, int yA, int xB, int yB)
{
    char mark = 0;
    if (dX >= xA && dX <= xB)
    {
        if (dY >= yA && dY <= yB)
        {
            mark = 1;
        }
    }
    return mark;
}
char cE(int dX, int dY)
{
    char mark = 0;
    if (cB(dX, dY, aXF, aYF, aXS, aYS) == 0 && cB(dX, dY, bXF, bYF, bXS, bYS) == 0)
    {
        if (cW(dX, dY, wXF, wYF, wXS, wYS))
        {
            mark = 1;
        }
    }
    return mark;
}
void mS(int s[], int d[], int o, int t)
{
    int i, j, k;
    int c = (o + t) / 2;
    if (o < c)
    {
        mS(d, s, o, c);
    }
    if (c + 1 < t)
    {
        mS(d, s, c + 1, t);
    }
    i = o;
    j = c + 1;
    k = o;
    while (i <= c && j <= t)
    {
        if (s[i] < s[j])
        {
            d[k] = s[i];
            i++;
        }
        else
        {
            d[k] = s[j];
            j++;
        }
        k++;
    }
    while (i <= c)
    {
        d[k] = s[i];
        i++;
        k++;
    }
    while (j <= t)
    {
        d[k] = s[j];
        j++;
        k++;
    }
}
int main()
{
    int i;
    int a, b;
    scanf("%d %d %d %d", &wXF, &wYF, &wXS, &wYS);
    sX[xC] = wXF;
    xC++;
    sY[yC] = wYF;
    yC++;
    sX[xC] = wXS;
    xC++;
    sY[yC] = wYS;
    yC++;
    scanf("%d %d %d %d", &aXF, &aYF, &aXS, &aYS);
    sX[xC] = aXF;
    xC++;
    sY[yC] = aYF;
    yC++;
    sX[xC] = aXS;
    xC++;
    sY[yC] = aYS;
    yC++;
    scanf("%d %d %d %d", &bXF, &bYF, &bXS, &bYS);
    sX[xC] = bXF;
    xC++;
    sY[yC] = bYF;
    yC++;
    sX[xC] = bXS;
    xC++;
    sY[yC] = bYS;
    yC++;
    for (i = 0; i < 6; i++)
    {
        dX[i] = sX[i];
    }
    for (i = 0; i < 6; i++)
    {
        dY[i] = sY[i];
    }
    mS(sX, dX, 0, 5);
    mS(sY, dY, 0, 5);
    sX[0] = dX[0];
    xC = 1;
    for (i = 1; i < 6; i++)
    {
        if (dX[i] > sX[xC - 1])
        {
            sX[xC] = dX[i];
            xC++;
        }
    }
    sY[0] = dY[0];
    yC = 1;
    for (i = 1; i < 6; i++)
    {
        if (dY[i] > sY[yC - 1])
        {
            sY[yC] = dY[i];
            yC++;
        }
    }
    if (xC > 2 || yC > 2)
    {
        for (a = 0; a < xC - 1; a++)
        {
            for (b = 0; b < yC - 1; b++)
            {
                if (cE(sX[a], sY[b]))
                {
                    if (cE(sX[a + 1], sY[b]) && cE(sX[a], sY[b + 1]))
                    {
                        printf("YES");
                        break;
                    }
                }
            }
            if (b < yC - 1)
            {
                break;
            }
        }
        if (a == xC - 1)
        {
            printf("NO");
        }
    }
    else
    {
        printf("NO");
    }
    return 0;
}

#include <stdio.h>
int sX[6];
int xC = 0;
int dX[6];
int sY[6];
int yC = 0;
int dY[6];
char cB(int dX, int dY, int xA, int yA, int xB, int yB)
{
    char mark = 0;
    if (dX > xA && dX < xB)
    {
        if (dY > yA && dY < yB)
        {
            mark = 1;
        }
    }
    return mark;
}
char cW(int dX, int dY, int xA, int yA, int xB, int yB)
{
    char mark = 0;
    if (dX >= xA && dX <= xB)
    {
        if (dY >= yA && dY <= yB)
        {
            mark = 1;
        }
    }
    return mark;
}
void mS(int s[], int d[], int o, int t)
{
    int i, j, k;
    int c = (o + t) / 2;
    if (o < c)
    {
        mS(d, s, o, c);
    }
    if (c + 1 < t)
    {
        mS(d, s, c + 1, t);
    }
    i = o;
    j = c + 1;
    k = o;
    while (i <= c && j <= t)
    {
        if (s[i] < s[j])
        {
            d[k] = s[i];
            i++;
        }
        else
        {
            d[k] = s[j];
            j++;
        }
        k++;
    }
    while (i <= c)
    {
        d[k] = s[i];
        i++;
        k++;
    }
    while (j <= t)
    {
        d[k] = s[j];
        j++;
        k++;
    }
}
int main()
{
    int i;
    int a, b;
    int wXF, wYF, wXS, wYS;
    int aXF, aYF, aXS, aYS;
    int bXF, bYF, bXS, bYS;
    scanf("%d %d %d %d", &wXF, &wYF, &wXS, &wYS);
    sX[xC] = wXF;
    xC++;
    sY[yC] = wYF;
    yC++;
    sX[xC] = wXS;
    xC++;
    sY[yC] = wYS;
    yC++;
    scanf("%d %d %d %d", &aXF, &aYF, &aXS, &aYS);
    sX[xC] = aXF;
    xC++;
    sY[yC] = aYF;
    yC++;
    sX[xC] = aXS;
    xC++;
    sY[yC] = aYS;
    yC++;
    scanf("%d %d %d %d", &bXF, &bYF, &bXS, &bYS);
    sX[xC] = bXF;
    xC++;
    sY[yC] = bYF;
    yC++;
    sX[xC] = bXS;
    xC++;
    sY[yC] = bYS;
    yC++;
    for (i = 0; i < 6; i++)
    {
        dX[i] = sX[i];
    }
    for (i = 0; i < 6; i++)
    {
        dY[i] = sY[i];
    }
    mS(sX, dX, 0, 5);
    mS(sY, dY, 0, 5);
    sX[0] = dX[0];
    xC = 1;
    for (i = 1; i < 6; i++)
    {
        if (dX[i] > sX[xC - 1])
        {
            sX[xC] = dX[i];
            xC++;
        }
    }
    sY[0] = dY[0];
    yC = 1;
    for (i = 1; i < 6; i++)
    {
        if (dY[i] > sY[yC - 1])
        {
            sY[yC] = dY[i];
            yC++;
        }
    }
    for (a = 0; a < xC - 1; a++)
    {
        for (b = 0; b < yC; b++)
        {
            if (cB(sX[a], sY[b], aXF, aYF, aXS, aYS) == 0 && cB(sX[a], sY[b], bXF, bYF, bXS, bYS) == 0)
            {
                if (cW(sX[a], sY[b], wXF, wYF, wXS, wYS))
                {
                    if (cB(sX[a + 1], sY[b], aXF, aYF, aXS, aYS) == 0 && cB(sX[a + 1], sY[b], bXF, bYF, bXS, bYS) == 0)
                    {
                        if (cW(sX[a + 1], sY[b], wXF, wYF, wXS, wYS))
                        {
                            printf("YES");
                            break;
                        }
                    }
                }
            }
        }
        if (b < yC)
        {
            break;
        }
    }
    if (a == xC - 1)
    {
        printf("NO");
    }
    return 0;
}

#include<stdio.h>
struct mystuct{
	int x1,y1,x2,y2;
};
int main(void)
{
	struct mystuct input1,input2,input3;
	scanf("%d %d %d %d",&input1.x1,&input1.y1,&input1.x2,&input1.y2);
	scanf("%d %d %d %d",&input2.x1,&input2.y1,&input2.x2,&input2.y2);
	scanf("%d %d %d %d",&input3.x1,&input3.y1,&input3.x2,&input3.y2);
	getchar();
	if(input2.x1 <= input1.x1 && input2.y1 <= input1.y1 &&
	   input2.x2 >= input1.x2 && input2.y2 >= input1.y2) printf("NO"); //b全覆盖a
	else if(input3.x1 <= input1.x1 && input3.y1 <= input1.y1 &&
	   	 	input3.x2 >= input1.x2 && input3.y2 >= input1.y2) printf("NO"); //c全覆盖a
	else if(input2.y1 <= input1.y1 && input2.y2 >= input1.y2 &&
			input3.y1 <= input1.y1 && input3.y2 >= input1.y2 &&
			input2.x1 <= input1.x1 && input3.x1 <= input2.x2 &&
			input3.x2 >= input1.x2) printf("NO"); //b,c左右覆盖
	else if(input3.y1 <= input1.y1 && input3.y2 >= input1.y2 &&
			input2.y1 <= input1.y1 && input2.y2 >= input1.y2 &&
			input3.x1 <= input1.x1 && input2.x1 <= input3.x2 &&
			input2.x2 >= input1.x2) printf("NO"); //c,b左右覆盖
	else if(input2.x1 <= input1.x1 && input2.x2 >= input1.x2 &&
			input3.x1 <= input1.x1 && input3.x2 >= input1.x2 &&
			input2.y1 >= input1.y2 && input3.y1 >= input2.y1 &&
			input3.y2 >= input1.y2 && input2.y2 >= input1.y2) printf("NO"); //b,c上下覆盖
	else if(input3.x1 <= input1.x1 && input3.x2 >= input1.x2 &&
			input2.x1 <= input1.x1 && input2.x2 >= input1.x2 &&
			input3.y1 >= input1.y2 && input2.y1 >= input3.y1 &&
			input2.y2 >= input1.y2 && input3.y2 >= input1.y2) printf("NO"); //c,b上下覆盖
	else printf("YES"); //还有白色部分露出
	return 0;
}

#include <stdio.h>
#include <string.h>

typedef struct{
    int x;
    int y;
} point;

typedef struct{
    point BL;
    point TR;
} square;

int inside (point w1, point w2, point b1, point b2){
    if (w1.x >= b1.x && w1.y >= b1.y && w2.x <= b2.x && w2.y <= b2.y){
        return 1;
    }
    else {
        return 0;
    }
}

int main(){
    square w1, b1, b2;
    square left, right, top, bottom;
    scanf("%d %d %d %d", &w1.BL.x, &w1.BL.y, &w1.TR.x, &w1.TR.y);
    scanf("%d %d %d %d", &b1.BL.x, &b1.BL.y, &b1.TR.x, &b1.TR.y);
    scanf("%d %d %d %d", &b2.BL.x, &b2.BL.y, &b2.TR.x, &b2.TR.y);

    left = (b1.BL.x<b2.BL.x)?b1:b2;
    right = (b1.BL.x<b2.BL.x)?b2:b1;
    top = (b1.TR.y<b2.TR.y)?b2:b1;
    bottom = (b1.TR.y<b2.TR.y)?b1:b2;

    if (w1.BL.x>=b1.BL.x && w1.TR.x<=b1.TR.x
     && w1.BL.y>=b1.BL.y && w1.TR.y<=b1.TR.y ||
     w1.BL.x>=b2.BL.x && w1.TR.x<=b2.TR.x
     && w1.BL.y>=b2.BL.y && w1.TR.y<=b2.TR.y){
        printf("NO\n");
    } else if (left.TR.x==right.BL.x && w1.BL.y>=b1.BL.y && w1.BL.y>=b2.BL.y
     && w1.TR.y<=b1.TR.y && w1.TR.y<=b2.TR.y
     && w1.BL.x>=left.BL.x && w1.TR.x<=right.TR.x
     ) {
        printf("NO\n");
    } else if (top.BL.y==bottom.TR.y && w1.BL.x>=b1.BL.x && w1.BL.x>=b2.BL.x
     && w1.TR.x<=b1.TR.x && w1.TR.x<=b2.TR.x
     && w1.BL.y>=bottom.BL.y && w1.TR.y<=top.TR.y
     ) {
        printf("NO\n");
    } else {
        printf("YES\n");
    }

    return 0;
}

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stddef.h>
#include <ctype.h>

int x1, x2, x3, x4, x5, x6, y1, y2, y3, y4, y5, y6;

void swap(int *a, int *b)
{
    int t = *a;
    *a = *b;
    *b = t;
}

char inside(int x, int y, int x1, int y1, int x2, int y2)
{
    if (x >= x1 && x <= x2 && y >= y1 && y <= y2)
        return 1;
    return 0;
}

int main()
{
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    scanf("%d%d%d%d", &x3, &y3, &x4, &y4);
    scanf("%d%d%d%d", &x5, &y5, &x6, &y6);

    if (!(inside(x1, y1, x3, y3, x4, y4) || inside(x1, y1, x5, y5, x6, y6))) {
        printf("YES");
        return 0;
    }
    if (!(inside(x2, y2, x3, y3, x4, y4) || inside(x2, y2, x5, y5, x6, y6))) {
        printf("YES");
        return 0;
    }
    if (!(inside(x1, y2, x3, y3, x4, y4) || inside(x1, y2, x5, y5, x6, y6))) {
        printf("YES");
        return 0;
    }
    if (!(inside(x2, y1, x3, y3, x4, y4) || inside(x2, y1, x5, y5, x6, y6))) {
        printf("YES");
        return 0;
    }

    if (x5 < x3) {
        swap(&x3, &x5);
        swap(&x4, &x6);
        swap(&y3, &y5);
        swap(&y4, &y6);
    }
    if (x4 + 1 <= x5 && x4 + 1 >= x1 && x4 + 1 <= x2) {
        printf("YES");
        return 0;
    }

    if (y6 > y4) {
        swap(&x3, &x5);
        swap(&x4, &x6);
        swap(&y3, &y5);
        swap(&y4, &y6);
    }
    if (y3 - 1 >= y6 && y3 - 1 <= y2 && y3 - 1 >= y1) {
        printf("YES");
        return 0;
    }

    printf("NO");

    return 0;
}

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stddef.h>
#include <ctype.h>

int x1, x2, x3, x4, x5, x6, y1, y2, y3, y4, y5, y6;

void swap(int *a, int *b)
{
    int t = *a;
    *a = *b;
    *b = t;
}

char inside(int x, int y, int x1, int y1, int x2, int y2)
{
    if (x >= x1 && x <= x2 && y >= y1 && y <= y2)
        return 1;
    return 0;
}

int main(int argc, char *argv[])
{
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    scanf("%d%d%d%d", &x3, &y3, &x4, &y4);
    scanf("%d%d%d%d", &x5, &y5, &x6, &y6);

    if (!(inside(x1, y1, x3, y3, x4, y4) || inside(x1, y1, x5, y5, x6, y6))) {
        printf("YES\n");
        return 0;
    }
    if (!(inside(x2, y2, x3, y3, x4, y4) || inside(x2, y2, x5, y5, x6, y6))) {
        printf("YES\n");
        return 0;
    }
    if (!(inside(x1, y2, x3, y3, x4, y4) || inside(x1, y2, x5, y5, x6, y6))) {
        printf("YES\n");
        return 0;
    }
    if (!(inside(x2, y1, x3, y3, x4, y4) || inside(x2, y1, x5, y5, x6, y6))) {
        printf("YES\n");
        return 0;
    }

    if (x5 < x3) {
        swap(&x3, &x5);
        swap(&x4, &x6);
        swap(&y3, &y5);
        swap(&y4, &y6);
    }
    if ((x4 + 1 <= x5 || x4 + 1 >= x6) && x4 + 1 >= x1 && x4 + 1 <= x2) {
        printf("YES\n");
        return 0;
    }

    if (y6 > y4) {
        swap(&x3, &x5);
        swap(&x4, &x6);
        swap(&y3, &y5);
        swap(&y4, &y6);
    }
    if ((y3 - 1 >= y6 || y3 - 1 >= y5) && y3 - 1 <= y2 && y3 - 1 >= y1) {
        printf("YES\n");
        return 0;
    }

    printf("NO\n");

    return 0;
}

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stddef.h>
#include <ctype.h>

int x1, x2, x3, x4, x5, x6, y1, y2, y3, y4, y5, y6;

void swap(int *a, int *b)
{
    int t = *a;
    *a = *b;
    *b = t;
}

char inside(int x, int y, int x1, int y1, int x2, int y2)
{
    if (x >= x1 && x <= x2 && y >= y1 && y <= y2)
        return 1;
    return 0;
}

int main(int argc, char *argv[])
{
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    scanf("%d%d%d%d", &x3, &y3, &x4, &y4);
    scanf("%d%d%d%d", &x5, &y5, &x6, &y6);

    if (!(inside(x1, y1, x3, y3, x4, y4) || inside(x1, y1, x5, y5, x6, y6))) {
        printf("YES\n");
        return 0;
    }
    if (!(inside(x2, y2, x3, y3, x4, y4) || inside(x2, y2, x5, y5, x6, y6))) {
        printf("YES\n");
        return 0;
    }
    if (!(inside(x1, y2, x3, y3, x4, y4) || inside(x1, y2, x5, y5, x6, y6))) {
        printf("YES\n");
        return 0;
    }
    if (!(inside(x2, y1, x3, y3, x4, y4) || inside(x2, y1, x5, y5, x6, y6))) {
        printf("YES\n");
        return 0;
    }

    if (x5 < x3) {
        swap(&x3, &x5);
        swap(&x4, &x6);
        swap(&y3, &y5);
        swap(&y4, &y6);
    }
    if (x4 + 1 <= x5 && x4 + 1 > x1 && x4 + 1 < x2) {
        printf("YES\n");
        return 0;
    }

    if (y6 > y4) {
        swap(&x3, &x5);
        swap(&x4, &x6);
        swap(&y3, &y5);
        swap(&y4, &y6);
    }
    if (y3 - 1 >= y6 && y3 - 1 < y2 && y3 - 1 > y1) {
        printf("YES\n");
        return 0;
    }

    printf("NO\n");

    return 0;
}


// Cola

#include <stdio.h>
#include <string.h>

#define ll long long

int count[20000];

void deal(int n, int a, int b, int c)
{
    int i, j;
    ll ans = 0;
    memset(count, 0, sizeof(count));
    for (i = 0; i <= b; i++)
    {
        if (i > n)
        {
            break;
        }
        for (j = 0; j <= c; j++)
        {
            if (i + 2 * j > n)
            {
                break;
            }
            count[i + 2 * j]++;
        }
    }
    for (i = 0; i <= a; i += 2)
    {
        if (n - i / 2 < 0)
        {
            break;
        }
        ans += count[n - i / 2];
    }
    printf("%lld\n", ans);
}

int main(int argc, char **argv)
{
    int a, b, c, n;
    while (scanf("%d%d%d%d", &n, &a, &b, &c) == 4)
    {
        deal(n, a, b, c);
    }
    return 0;
}

#include <memory.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

typedef long long ll;

int main ()
{
    int n, a, b, c; scanf ("%d%d%d%d", &n, &a, &b, &c);
    n <<= 1;
    int ans = 0;
    for (int ta = 0; ta <= a; ta++)
    {
        for (int tb = 0; tb <= b; tb++)
        {
            int cnt = ta + (tb << 1);
            if (cnt > n) continue;
            if ((n - cnt) % 4) continue;
            int tc = (n - cnt) / 4;
            if (tc <= c)
                ans++;
        }
    }
    printf ("%d\n", ans);

    return 0;
}

#include <stdio.h>
int main()
{
    int n, a, b, c;
    scanf("%d %d %d %d", &n, &a, &b, &c);
    int cnt = 0;
    for(int i = 0; i <= a/2; i++)
    {
        for(int j = 0; j <= c; j++)
        {
            int val = n-i-j*2;
            if(val >= 0 && val <= b)
                cnt++;
        }
    }
    printf("%d\n", cnt);
    return 0;
}

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main ()
{
	int N, A, B, C;
	scanf("%d %d %d %d",&N,&A,&B,&C);
	N *= 2;
	int res = 0;
	int x, y;
	int rem;
	for (x = 0; x <= B; x++)
	{
		for (y = 0; y <= C; y++)
		{
			rem = N - 2 * x - 4 * y;
			if ((rem >= 0) && (rem <= A)) res++;
		}
	}
	printf("%d\n",res);
	return 0;
}

#include <stdio.h>

int main(void) {
    int n, a, b, c, i, j, ans = 0;
    scanf("%d %d %d %d", &n, &a, &b, &c);

    for (i = 0; i <= c; i++) {
        for (j = 0; j <= b; j++) {
            int k = 2*n - 4*i - 2*j;
            if (0 <= k && k <= a) ans++;
        }
    }
    printf("%d\n", ans);
    return 0;
}

// Cola

#include <stdio.h>
#include <string.h>

#define ll long long

int count[20000];

void deal(int n, int a, int b, int c)
{
    int i, j;
    ll ans = 0;
    memset(count, 0, sizeof(count));
    for (i = 0; i <= b; i++)
    {
/*      if (i > n)
        {
            break;
        }*/
        for (j = 0; j <= c; j++)
        {
/*          if (i + 2 * j > n)
            {
                break;
            }*/
            count[i + 2 * j]++;
        }
    }
    for (i = 0; i <= a; i += 2)
    {
        if (n - i / 2 < 0)
        {
            break;
        }
        ans += count[n - i / 2];
    }
    printf("%lld\n", ans);
}

int main(int argc, char **argv)
{
    int a, b, c, n;
    while (scanf("%d%d%d%d", &n, &a, &b, &c) == 4)
    {
        deal(n, a, b, c);
    }
    return 0;
}

#include <stdio.h>
int main()
{
    int n, a, b, c, i, j, res, N, rem;
    while(scanf("%d%d%d%d", &n, &a, &b, &c)==4)
    {
        res=0;
        rem=0;
        N=2*n;
        for(i=0; i<=b; i++)
        {
            for(j=0; j<=c; j++)
            {
                rem=N-2*i-4*j;
                if(rem>=0 && rem<=a)
                    res++;
            }
        }
        printf("%d\n", res);
    }
    return 0;
}

#include<stdio.h>
int main()
{

    int n,a,b,c,sum;
    scanf("%d%d%d%d",&n,&a,&b,&c);
    int count =0;
    int i,j;
    for(i=0;i<=a;i++)
    {
        if(i%2)
            continue;
        for(j=0;j<=b;j++)
        {
            sum=0;
            sum=(n)-(int)(i*0.5)-(j*1);
           if(sum<0)
            continue;
            if((sum%2 ==0)&&((sum/2)<=c))
                count++;
        }
    }
    printf("%d",count);
    return 0;
}

#include<stdio.h>
int main()

{
    int n,a,b,c,i,count=0,j,k;
    scanf("%d%d%d%d",&n,&a,&b,&c);
    if(2*c>n)c=n/2;
    if(b>n)b=n;
    if(c/2>n)c=2*n;
    for(i=c;i>=0;i--)
    {
        if(2*i==n){count++;
        continue;
        }
        for(j=b;j>=0;j--)
        {
            if(2*i+j==n)
            {
                count++;
                continue;
            }
            k=2*n-4*i-2*j;
            if(0<=k &&k<=a)count++;
        }

    }printf("%d",count);
    return 0;
}

// Cola

#include <stdio.h>
#include <string.h>

#define ll long long

int count[20000];

void deal(int n, int a, int b, int c)
{
    int i, j;
    ll ans = 0;
    memset(count, 0, sizeof(count));
    for (i = 0; i <= b; i++)
    {
        for (j = 0; j <= c; j++)
        {
            count[i + 2 * j]++;
        }
    }
    for (i = 0; i <= a; i += 2)
    {
        ans += count[n - i / 2];
    }
    printf("%lld\n", ans);
}

int main(int argc, char **argv)
{
    int a, b, c, n;
    while (scanf("%d%d%d%d", &n, &a, &b, &c) == 4)
    {
        deal(n, a, b, c);
    }
    return 0;
}

#include<stdio.h>
int main()
{

    int n,a,b,c,sum;
    scanf("%d%d%d%d",&n,&a,&b,&c);
    int count =0;
    int i,j;
    for(i=0;i<=a;i++)
    {
        if(i%2)
            continue;
        for(j=0;j<=b;j++)
        {
            sum=0;
            sum=(n)-(int)(i*0.5)-(j*1);
            if((sum%2 ==0)&&((sum/2)<=c))
                count++;
        }
    }
    printf("%d",count);
    return 0;
}


#include<stdio.h>

int main()
{
	long long int m,n,a,b,l,d;

	while(scanf("%lld%lld%lld%lld",&m,&n,&a,&b)!=EOF)
	{
		if(m%n==0)
		{
			printf("0\n");
		}
		else
		{
			l=(n-(m%n))*a;
			d=(m%n)*b;

			if(l<d)
			{
				printf("%lld\n",l);
			}
			else
			{
				printf("%lld\n",d);
			}
		}

	}

	return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    long long  n,m,a,b,x1,x2;
    scanf("%lld",&n);
    scanf("%lld",&m);
    scanf("%lld",&a);
    scanf("%lld",&b);
    x1=n%m;
    x2=m-x1;
    if(a*x2 > x1*b)
        printf("%lld",x1*b);
    else
        printf("%lld",x2*a);
    return 0;
}

#include<stdio.h>
#include<math.h>

int main()
{

        long long int n,m,a,b,result,result2,temp,temp2,nn,mm;

        scanf("%lld%lld%lld%lld",&n,&m,&a,&b);
        temp=n;nn=n;temp2=m,mm=m;
        if(n%m==0)
            {printf("0\n");}
        else
        {
            nn=n%m;
            result2=nn*b;
            result=(m-nn)*a;
            if(result2>result)
                printf("%lld\n",result);
            else
                printf("%lld\n",result2);
        }
}

#include<stdio.h>
int main()
{
	long long n, m, a, b ;
	scanf("%I64d %I64d %I64d %I64d", &n, &m, &a, &b);
	if (n >= m) {
		long long x, y;
		x = n % m;
		y = n / m;
		if (b*x >= ((y + 1)* m-n)*a) printf("%I64d", ((y + 1)*m-n)*a);
		else printf("%I64d", b*x);
	}
	else if (n < m) {
		if (b*n >= (m - n)*a) printf("%I64d", (m-n)*a);
		else printf("%I64d", b*n);
	}
}

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
#include<time.h>

int main()
{
    long long int n,m,a,b,r,i,j;
    scanf("%I64d %I64d %I64d %I64d",&n,&m,&a,&b);
    if(n%m==0)
        printf("0");
    else if(n%m!=0)
    {
     r=n%m;
      i=r*b;
      j=(m-r)*a ;
      if(i<j)
        printf("%I64d",i);
      else printf("%I64d",j);
    }
}

#include <stdio.h>
int main(){
    long long m,n;
    int a,b;
    scanf("%lld %lld %d %d",&m,&n,&a,&b);
    // tim 2 so gan n nhat
    if (m % n != 0){
        long long f1,f2;
        // find f1
        long long temp1 = m, temp2 = m;
        f1 = temp1/n* n;
        // find f2
        f2 = f1 + n;
       // printf("(%lld %lld)",f1,f2);
        if ( (m-f1)*b < (f2-m)*a )
        printf("%lld",(m-f1)*b);
        else printf("%lld",(f2-m)*a);

    }else printf("0");
    return 0;
}

#include<stdio.h>
int main()
{
	long long n,m,a,b,c,d;
	while(scanf("%I64d%I64d%I64d%I64d",&m,&n,&a,&b)!=EOF)
	{
		if(m%n==0)
		{
			printf("0");
			printf("\n");
		}
		else
		{
			c=m%n*b;//拆除
				if(m>n)
				{
					d=(n-m%n)*a;
					if(c>d)
					{
						printf("%I64d\n",d);
					}
					else
					{
						printf("%I64d\n",c);
					}

				 }
				 else//m<n
				 {
				 	d=(n-m)*a;//重建
				 	if(c>d)
					{
						printf("%I64d\n",d);
					}
					else
					{
						printf("%I64d\n",c);
					}
				 }

		}
	}
	return 0;
}

#include<stdio.h>
int main()
{
	long long int n,m,a,b,x,y;
	scanf("%lld%lld%lld%lld",&n,&m,&a,&b);
	x=n%m;
	if(x==0)
	printf("0\n");
	else if((m-x)*a>x*b)
		printf("%lld\n",x*b);
	else
		printf("%lld\n",(m-x)*a);
	return 0;
}

#include <stdio.h>

int main()
{
    long long int a, b, c, n, m, x, y, z, cost1, cost2;

    scanf("%lld %lld %lld %lld", &n , &m, &a, &b);

    if(n % m == 0)
    {
        printf("0\n");
        return 0;
    }
    c = n / m;
    x = ((c+1)*m) - n;
    y = n - (c*m) ;
    //printf("%d\n", y);

    cost1 = x*a;
    cost2 = y*b;

    if(cost1<cost2)
        z = cost1;
    else
        z = cost2;

    printf("%lld\n", z);

    return 0;
}

#include <stdio.h>

int main(){

	long long n,m,a,b;
	scanf("%lld %lld %lld %lld",&n,&m,&a,&b);
	printf("%lld\n",((n%m)*b<((m-(n%m))%m)*a)?(n%m)*b:((m-(n%m))%m)*a);

	return 0;
}

/* Coached by rainboy */
#include <stdio.h>

long long min(long long a, long long b) {
	return a < b ? a : b;
}

int main() {
	long long n, m;
	int a, b;

	scanf("%lld%lld%d%d", &n, &m, &a, &b);
	printf("%lld\n", n % m == 0 ? 0 : min(n % m * b, (m - n % m) * a));
	return 0;
}

#include <stdio.h>
#include <inttypes.h>

long long int mod(long long int x, long long int y){
	return(x-(y*(x/y)));
}

int main(void){

	long long int n, m, a, b;
	scanf("%I64d%I64d%I64d%I64d", &n, &m, &a, &b);

	long long int division = mod(n, m);

	if(division!=0){
		if((m-division)*a < division*b){
			printf("%I64d\n", (m-division)*a);
		}else{
			printf("%I64d\n", division*b);
		}
	}else{
		printf("0\n");
	}

	return 0;
}

#include<stdio.h>
#define ll long long
#include<math.h>

int main()
{
	ll n,m,a,b;

	scanf("%lld%lld%lld%lld",&n,&m,&a,&b);

	ll r1,r2,c1,c2;

	if(n%m==0)
	{
		printf("0\n");
	}

	else if(n>m)
	{
		r1=n%m;
		r2=m-r1;

	        	c1=r2*a;
	        	c2=r1*b;

		       if(c1<c2)
		       printf("%lld\n",c1);

		       else
		       printf("%lld\n",c2);
	}

	else if(m>n)
	{
		r1=m-n;
		r2=n;

		c1=r1*a;
		c2=r2*b;

		        if(c1<c2)
		       printf("%lld\n",c1);

		       else
		       printf("%lld\n",c2);
	}
	return 0;

}

#include<stdio.h>

int main()
{
  long long int n,m,a,b,acost,bcost,t;
  scanf("%lld%lld%lld%lld",&n,&m,&a,&b);
  if(n%m==0)
   return printf("0\n"),0;
  else
  {
      t=n%m;
      acost=(m-t)*a;
      bcost=t*b;

      if(bcost<acost)
        return printf("%lld\n",bcost),0;
  }
    printf("%lld\n",acost);
}

#include<stdio.h>
int main()
{
    long long int n,m,a,b,i,j;
    scanf("%lld%lld%lld%lld",&n,&m,&a,&b);
    if(n%m!=0)
    {
       if(n<m)
       {
           i=n*b;
           j=(m-n)*a;
           if(i<j)
           {
               printf("%lld\n",i);
           }
           else
           {
               printf("%lld\n",j);
           }
       }
       else if(n>m)
       {
           i=(n%m)*b;
           j=(m-(n%m))*a;
           if(i<j)
           {
               printf("%lld\n",i);
           }
           else
           {
               printf("%lld\n",j);
           }

       }
    }
    else
    {
        i=0;
        printf("%lld\n",i);
    }
    return 0;
}

#include <stdio.h>

int main()
{
	long long m,n ;
	int a,b ;
	scanf("%lld%lld%d%d",&m,&n,&a,&b) ;
	int i ;
	long long cost1,cost2 ;
	if(m==n || m%n==0)
		cost1 = cost2 = 0 ;
	else if(m<n)
	{
		cost1 = (n-m)*a ;
		cost2 = m*b ;
	}
	else
	{
		long long t = m/n ;
		cost1 = a*((t+1)*n-m) ;
		cost2 = b*(m-t*n) ;
	}
	printf("%lld\n",cost1>=cost2?cost2:cost1) ;
	return 0 ;
}

#include<stdio.h>
int main()
{
    long long n,m,a,b,ans,c1,c2,yu;
    scanf("%I64d %I64d %I64d %I64d",&n,&m,&a,&b);
    yu=n%m;
    if(yu==0)
        printf("0\n");
    else
    {
        c1=yu*b;
        c2=(m-yu)*a;
        if(c1>c2)
            printf("%I64d\n",c2);
        else
            printf("%I64d\n",c1);
    }
    return 0;
}

#include<stdio.h>
main()
{
    long long int n,m;int a,b;
    scanf("%I64d%I64d%d%d",&n,&m,&a,&b);
    if(n%m!=0)
    {
        if((m-n%m)*a<(n%m)*b)printf("%I64d",(m-n%m)*a);
        else printf("%I64d",(n%m)*b);
        return 0;

    }
    printf("0");
    return 0;
}

main()
{long long int i,j,k,p,l,n,m,a,b;
scanf("%lld%lld%lld%lld",&n,&m,&a,&b);
k=n%m;
j=m-k;
i=j*a;
p=b*k;
//printf("%d %d %d %d\n",k,j,i,p);
if (i>p)printf("%lld",p);
else if (p>=i) {printf("%lld",i);}
}

#include<stdio.h>
#include<math.h>
#define Min(a,b) a<b ? a : b
int main()
{
    long long int n, m, a, b, x, y;
    scanf("%lld%lld%lld%lld",&n,&m,&a,&b);

    y = n%m;
    x = m-(n%m);
    x *= a;
    y *= b;
    printf("%lld\n",Min(x,y));
    return 0;
}

#include<stdio.h>
main()
{
   long long int n,m,a,b,p,q,cntd=0,cntb=0,i,j,k,d=0,b1=0,g=0,e=0;
    scanf("%lld%lld%lld%lld",&n,&m,&a,&b);
    p=n;q=n;
    cntd=p%m;
    d=cntd*b;
    if(q%m==0)cntb=0;
    else
    {
        q=q+m;
        g=q/m;
        cntb=g*m-n;
    }
    b1=cntb*a;
    e=n*b;
  if(e<d && e<b1)printf("%lld\n",e);
   else
   {  if(b1<d)printf("%lld\n",b1);

    else printf("%lld\n",d);

    }

    return 0;

}

#include<stdio.h>
int main()
{
    long long n,m,s,d,r,t;
    int a,b;
    scanf("%lld %lld %d %d",&n,&m,&a,&b);
    if(n%m==0)
    {
        printf("%d",0);
    }
    else
    {
        r=n%m;
        s=r*b;
        t=(m-r);
        d=t*a;
        if(s<=d)
        {
            printf("%lld",s);
        }
        else
        {
            printf("%lld",d);
        }
    }
    return 0;
}

#include<stdio.h>
#include<stdlib.h>
#define min(x,y) x<y?x:y
int main()
{
    long long m,n,a,b,ccost,dcost;
    scanf("%lld%lld%lld%lld",&n,&m,&a,&b);
    if(n==m) printf("0");
    else if(n>m)
    {
        long long dr=n%m,cr=((n/m)+1)*m-n;
        printf("%lld",min(cr*a,dr*b));
    }
    else
    {
       long long diff=m-n;
       printf("%lld",min(diff*a,n*b));
    }

    return 0;
}

#include<stdio.h>
int main()
{
    long long int i, j, a, b, n, m, sum = 0, sum1 = 0;
    scanf("%lld %lld %lld %lld", &n, &m, &a, &b);
    if(n % m != 0)
    {
        if(n < m)
            {
                sum = n*b;
                sum1 = (m - n)*a;
                if(sum1 > sum)
                    printf("%lld\n", sum);
                else
                    printf("%lld\n", sum1);
            }
        else
            {
                sum = a*(m - n%m);
                sum1 = b*(n%m);
                if(sum1 > sum)
                    printf("%lld\n", sum);
                else
                    printf("%lld\n", sum1);
            }

    }
    else
        printf("%lld\n", sum);

}

#include<stdio.h>
int main()
{
    long long int n,m,rem=0,cost1=0,cost2=0;
    int a,b;
    scanf("%lld %lld %d %d",&n,&m,&a,&b);
    rem=n%m;
    if(rem==0)
    {
        printf("0");
        return 0;
    }
    if((rem>0)&&(n>m))
    {
        cost1=rem*b;
        cost2=(m-rem)*a;
        cost1<cost2?printf("%lld",cost1):printf("%lld",cost2);
        return 0;
    }
    if((rem>0)&&(m>n))
    {
        cost1=n*b;
        cost2=(m-n)*a;
        cost1<cost2?printf("%lld",cost1):printf("%lld",cost2);
        return 0;
    }
}

#include<stdio.h>
#define I64 long long int
int main()
{
    I64 n,m,a,b,p,q,k,k_;
    scanf("%I64d%I64d%I64d%I64d",&n,&m,&a,&b);
    if(n%m==0){
        printf("0");
        return 0;
    }
    if(n>m)
    {
        p=n%m;q=m-p;
        k=q*a;
        k_=p*b;
        k<k_?printf("%I64d",k):printf("%I64d",k_);
    }
    else
    {
        p=m-n;
        k=p*a;
        k_=n*b;
        k<k_?printf("%I64d",k):printf("%I64d",k_);
    }
}

#include<stdio.h>
int main(){
    int a,b;
    long long n,m;
    long long v1,v2;
    scanf("%lld%lld%d%d",&n,&m,&a,&b);
    v1=n%m;
    v2=m-v1;
    printf("%lld",(v2*a<v1*b)?(v2*a):(v1*b));
    return 0;
}

#include<stdio.h>
#define min(x,y) x<y?x:y
int main()
{
long long int n,m,a,b,x,y;
scanf("%I64d %I64d %I64d %I64d",&n,&m,&a,&b);
x=(m-(n%m))*a;
y=(n%m)*b;
printf("%I64d",min(x,y));
return 0;
}

#include<stdio.h>
int main()
{
    long long int n, m, a, b, x, y;
    scanf("%lld%lld%lld%lld", &n, &m, &a, &b);
    if(n%m==0)
    {
        printf("0\n");
    }
    else
    {
        x= (n%m)*b;
        y= (m-(n%m))*a;
        if(x<y)
        {
            printf("%lld", x);
        }
        else
            printf("%lld", y);
    }
    return 0;
}

#include<stdio.h>
long long int n,m,y,r,s;
int a,b;
int main()
{
    scanf("%lld %lld %d %d",&n,&m,&a,&b);
    if(n%m==0)
     s=0;
    else
     {
        r=a*(m-(n%m));
        y=b*(n%m);
        if(r>y)
        s=y;
        else
        s=r;
     }
 printf("%lld",s);
}

#include <stdio.h>
long long min(long long a,long long b) {return (a<b)?a:b;}
int main()
{
    long long n,m;
    int a,b;
    scanf("%lld%lld%d%d",&n,&m,&a,&b);
    long long r=n%m;
    printf("%lld\n",min(r*b,(m-r)*a));
    return 0;
}

#include<stdio.h>
int main()
{
    long long int n,m,a,b,p,q;
    scanf("%lld %lld %lld %lld",&n,&m,&a,&b);
    if(n%m==0)
    {
        printf("0");
    }
    else
    {
        p=n%m;
        q=m-p;
        if((p*b)>=(q*a))
        {
            printf("%lld",(q*a));
        }
        else
        {
            printf("%lld",(p*b));
        }
    }
}

#include<stdio.h>
int main(){
    long long int n,m,a,b;
    scanf("%I64d%I64d%I64d%I64d",&n,&m,&a,&b);
    if(n%m==0) printf("0");
    else{
        long long int d;
        d=n%m;
        if(d*b<((((n/m)+1)*m)-n)*a)
            printf("%I64d",d*b);
        else
            printf("%I64d",((((n/m)+1)*m)-n)*a);
    }
}

#include<stdio.h>
#define min(a,b) a<b?a:b
int main()
{
    long long n,m,a,b,ta,tb;
    scanf("%lld%lld%lld%lld",&n,&m,&a,&b);
    ta=n%m;
    tb=m-ta;
    ta*=b;
    tb*=a;
    printf("%lld\n",min(ta,tb));
    return 0;
}

#include <stdio.h>

int main(void) {
	long long n,m,a,b,c,d,e,k,l;
	scanf("%lld%lld%lld%lld",&n,&m,&a,&b);
	c=n%m;
	if(c==0)
	{
	  printf("0");
	}
	else
	{
	  d=m-c;
	  k=d*a;
	  l=c*b;
	  if(k>l)
	  {
	      printf("%lld",l);
	  }
	  else
	  {
	      printf("%lld",k);
	  }
	}
	return 0;
}

#include<stdio.h>

int main(void)
{
	long long n, m, a, b;
	long long min;

	scanf("%I64d %I64d %I64d %I64d", &n, &m, &a, &b);

	min = (n % m) * b < (m - (n % m)) * a ? (n % m) * b : (m - (n % m)) * a;

	printf("%I64d", min);
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    long long int a,b,n,m,x,y;
    scanf("%lld %lld %lld %lld",&a,&b,&n,&m);
    x=a%b;
    y=b-a%b;
    if(a%b==0) printf("0\n");
    else
    {
        if(x*m>=y*n) printf("%lld\n",y*n);
        else printf("%lld\n",m*x);
    }
    return 0;
}

#include<stdio.h>
int main(){
  long long int n,m;
  int a,b;
  scanf("%lld%lld%d%d",&n,&m,&a,&b);
  if(n%m==0)
  printf("0\n");
  else if(n%m!=0)
  {
    long long int temp1=n/m;
    long long int temp2=temp1+1;
    long long int ans1=(n-(temp1*m))*b;
    long long int ans2=((temp2*m)-n)*a;
    if(ans1<ans2)
    printf("%lld\n",ans1);
    else
    printf("%lld\n",ans2);
  }
}

#include<stdio.h>
int main()
{
    long long unsigned int n,m,a,b,p=0,q=0;
    scanf("%lld%lld%lld%lld",&n,&m,&a,&b);

    p = (n%m)*b;
    q = (m-(n%m))*a;

    if(p>q)
        printf("%lld\n",q);
    else
        printf("%lld\n",p);

    return 0;
}

#include<stdio.h>
int main()
{
    int a,b;
    long long int n,m,p,q,t;
    scanf("%lld %lld",&n,&m);
    scanf("%d %d",&a,&b);
    if(n%m==0)
    {
        printf("0");
    }
    else{
        if(n<m){
            p=b*n;
            q=(m-n)*a;
            if(p<q){
                printf("%lld",p);
            }
            else{
                printf("%lld",q);
            }
        }
        else{
            p=(n%m)*b;
            t=(n/m);
            t=t+1;
            q=((t*m)-n)*a;
            if(p<q)
            {
                printf("%lld",p);
            }
            else{
                printf("%lld",q);
            }
        }
    }
}

#include<stdio.h>
long long int min (long long int a, long long int b)
{
    if(a<b)
    return a;
    else
    return b;
}
int main()
{
    long long int n,m,a,b;
    scanf("%lld %lld %lld %lld",&n,&m,&a,&b);
    if(n%m==0)
    printf("0");
    else
    {
        long long int rem=n%m;
        long long int des=rem*b;
        long long int build = (((n/m + 1)*m)-n)*a;
        printf("%lld",min(des,build));
    }

}

#include<stdio.h>
int main(){
    long long int n,m,d;
    int a,b,i;
    scanf("%lld %lld %d %d",&n,&m,&a,&b);
    long long int sum_a=0, sum_b=0;

    if(n%m==0)
        printf("0");
    else{
        d=n%m;
        sum_a= (m-d)*a;
        sum_b= d*b;
        if(sum_a<sum_b)
            printf("%lld",sum_a);
        else
            printf("%lld",sum_b);
    }
}

#include <stdio.h>
#include <string.h>
int main()
{
    long long int n,m,a,b,c,d;
    scanf("%lld%lld%lld%lld",&n,&m,&a,&b);
    if(n>m)
    {
        if(n%m==0)
        printf("0");
        else
        {
        		c=a*(m-(n%m));
        		d=b*(n%m);
        		if(c<d)
        			printf("%lld",c);
        		else
        			printf("%lld",d);
        }
    }
    else
    {
        c=((m-n)*a);
        d=(n*b);
        if(c<d)
        printf("%lld",c);
        else
        printf("%lld",d);
    }
    return 0;
}

#include<stdio.h>
#include<stdlib.h>
long long fun(long long ,long long ,long long ,long long );
long long fun(long long n,long long m,long long a,long long b)
{
    long long t=n%m;
    if(t==0)
    {
        return 0;
    }
    long long s1=b*t;
    long long s2=(m-t)*a;
    return (s1<s2)?s1:s2;
}
int main()
{
    long long n,m,a,b;
    scanf("%lld%lld%lld%lld",&n,&m,&a,&b);
    printf("%lld\n",fun(n,m,a,b));
    return 0;
}

#include<stdio.h>
#include<math.h>
int main(){
    long long int n, m;
    int a, b;
    scanf("%I64d%I64d%d%d", &n, &m, &a, &b);
    if(n % m ==0)
        printf("0");
    else{
        /**Hallar el m�ltiplo m�s cercano a m, por encima y por
        debajo de n:
            dividir n entre m y tomar el resultado, por exceso y por defecto
            multiplicar dichos resultados por m y ya tenemos los m�ltiplos buscados*/
        long long int ex, de;
        ex = n/m + 1;
        de = n/m;
        ex = ex * m;
        de = de * m;
        if(de == 0)
            de = n * b;
        else{
            de = fabs(de - n);
            de = de * b;
        }
        ex = fabs(ex - n);
        ex = ex * a;
        if(ex > de)
            printf("%I64d", de);
        else
            printf("%I64d", ex);
    }
    return 0;
}

#include <stdio.h>

int
main ()
{
	unsigned long long int n, m, a, b;

	scanf ("%I64u %I64u %I64u %I64u", &n, &m, &a, &b);

	unsigned long long int destroy = n % m;
	unsigned long long int build = m - destroy;

	build *= a;
	destroy *= b;

	printf ("%I64u\n", build < destroy ? build : destroy);

	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

long long int min(long long int a,long long int b)
{
	if(a>b)
		return b;
	return a;
}

int main()
{
	long long int n,m,a,b,ans=0,p,q;
	scanf("%lld%lld%lld%lld",&n,&m,&a,&b);
	p = n%m;
	q = m-p;
	ans = min(p*b,q*a);
	printf("%lld\n",ans );
	return 0;
}

#include <stdio.h>

int main() {
  long long a, b,c,d,e,f,g,h,i;
  scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
  if (a% b == 0) {
    printf("0\n");
    return 0;
  } else if (a> b) {
    e = (a/ b+ 1) * b- a;
    f = a % b;
    g=e*c;
    h=f*d;
    if(g<h)
    {
    	printf("%lld\n",g);
    	return 0;
    }
    else
    {
    	printf("%lld\n",h);
    	return 0;
    }
  }
   else {
    e = b - a;
    f= a;
    g=e*c;
    h=f*d;
    if(h<g)
    {
    	printf("%lld\n",h);
    	return 0;
    }
    else
    {
    	printf("%lld\n",g);
    	return 0;
    }

  }
  return 0;
}

#include<stdio.h>
int main()
{
    long long int n,m,a,b,i,k,x,y;
    scanf("%lld %lld %lld %lld",&n,&m,&a,&b);
    if(n%m==0)
    {
        printf("0\n");
    }
    else
    {
        k=n%m;
        x=k*b;
        y=(m-k)*a;
        if(x<=y)
        {
            printf("%lld\n",x);
        }
        else
        {
            printf("%lld\n",y);
        }
    }
    return 0;
}

#include<stdio.h>

int main()
{
	long long n,m;
	int a,b;
	long long anc,sum;
	int i;
	scanf("%I64d%I64d%d%d",&n,&m,&a,&b);

		anc=sum=0;
	      	if(n%m==0 )
		{
			printf("0\n");

		}
		else
		{

			anc=b*(n%m);

			sum=(m-n%m)*a;

				if(anc<sum)
				{
					printf("%I64d\n",anc);

				}
				else
				{
					printf("%I64d\n",sum);

				}

		return 0;

	}
	return 0;
}

#include<stdlib.h>
#include<stdio.h>

int main()
{
short int a=0,b=0;
unsigned long long int n=0,m=0,modnm=0;
scanf("%llu %llu %hd %hd",&n,&m,&a,&b);
modnm=n%m;
if (b*modnm>a*(m-modnm))
{
printf("%llu",a*(m-modnm));
}else
{
printf("%llu",b*modnm);
}
return 0;
}

#include<stdio.h>
#define ll long long
int main()
{
	ll n,m,a,b,x1,x2,res1,res2;
	scanf("%I64d%I64d%I64d%I64d",&n,&m,&a,&b);
	x1=n%m;
	x2=m-x1;
	res1=x1*b;
	res2=x2*a;
	if(res1<res2)
		printf("%I64d",res1);
	else
		printf("%I64d",res2);
	return 0;
}

#include <stdio.h>

long long min(long long a, long long b)
{
    return a < b? a: b;
}

int main()
{
    long long n, m, a, b;
    scanf("%lld%lld%lld%lld", &n, &m, &a, &b);
    long long demolish = n % m, build = m - demolish;
    printf("%lld\n", min(demolish*b, build*a));
    return 0;
}

#include <stdio.h>

int main()
{
    long long int n, m, a, b, x, y, c1, c2, div;
    scanf("%lli %lli %lli %lli", &n, &m, &a, &b);

    if(n%m==0)
    {
        printf("0\n");
    }
    else
    {
        div=n/m;
        x=n-(div*m);
        c2=b*x;
        //printf("div %lli\n", div);
        //printf("c2 %lli\n", c2);

        div++;
        y=(div*m)-n;
        c1=a*y;
        //printf("c1 %lli\n", c1);

        if(c1>c2)
        {
            printf("%lli\n", c2);
        }
        else
        {
            printf("%lli\n", c1);
        }
    }
}

#include<stdio.h>
int main()
{
long long int n,m,a,b,minimum_burles,bulit_boxes,destroyed_boxes;
scanf("%I64d %I64d %I64d %I64d",&n,&m,&a,&b);
bulit_boxes=(m-n%m)*a;
destroyed_boxes=(n%m)*b;
if(bulit_boxes<destroyed_boxes) minimum_burles=bulit_boxes;
else minimum_burles=destroyed_boxes;
printf("%I64d",minimum_burles);
return 0;
}

//Bismillahir rahmanir rahim

#include <stdio.h>

int main(void) {
	// your code goes here
	long long  m,n,a,b,rem,ans;
	scanf("%lld %lld %lld %lld",&m,&n,&a,&b);
	rem = m % n ;
	long long int ans1 = rem*b;
	long long int ans2 = (n-rem)*a;
	if(ans1>ans2)   ans=ans2;
	else ans=ans1;
	printf("%lld",ans);
	return 0;
}

#include<stdio.h>
#include<math.h>
int main()
{
    double n,m,a,b,c,f,p,q;
    scanf("%lf %lf %lf %lf", &n,&m,&a,&b);
    c=ceil(n/m);
    f=floor(n/m);
    p=(c*m-n)*a;
    q=(n-f*m)*b;
    printf("%.0lf",p>q?q:p);
    return 0;
}

#include <stdio.h>
#define ll long long

ll min(ll a, ll b)
{
	return a >= b ? b : a;
}

int main()
{
	ll n, m, a, b, x, ans;
	scanf("%lld %lld %lld %lld", &n, &m, &a, &b);
	x = n / m;
	ans = min(((x + 1) * m - n) * a, (n - x * m) * b);
	printf("%lld\n", ans);
	return 0;
}

#include<stdio.h>
#include<math.h>

int main()
{

    long long int m,n,a,b,p,q;
    scanf("%I64d %I64d %I64d %I64d",&n,&m,&a,&b);
    if( n%m==0){
        printf("0");
    }
    else if(n>m && n%m!=0){
        p=(n%m)*b;
        q=(m*(ceil(n/(m*1.0)))-n)*a;
        if(p>q){
            printf("%I64d",q);
        }
        else
            printf("%I64d",p);
    }
    else if(n<m){
        p=(m-n)*a;
        q=(n)*b;
        if(p>q){
            printf("%I64d",q);
        }
        else
            printf("%I64d",p);
    }

}

#include<stdio.h>
int main()
{
    long long int n,m,a,b,build,dem;
    scanf("%lld %lld %lld %lld",&n,&m,&a,&b);
    build = m*a -(n%m)*a;
    dem = (n%m)*b;
    build<=dem? printf("%lld",build):printf("%lld",dem);
    return 0;
}

#include <stdio.h>
#define ll long long
int main(){
	ll n, m;
	int a, b;
	scanf("%I64d%I64d%d%d",&n,&m,&a,&b);
	if (n%m == 0) printf("0");
	else{
		ll costa = a*(m-n%m);
		ll costb = b*(n%m);
		printf("%I64d",costa<costb? costa:costb);
	}

	return 0;
}

#include<stdio.h>
int main()
{
	long long n,m,y1,y11,y2,y22,x;
	int a,b;
	scanf("%lld%lld",&n,&m);
	scanf("%d%d",&a,&b);
	if(n%m==0)
	printf("0\n");
	else
	{
		x=n/m;
		y1=n-m*x;
		y11=y1*b;
        y2=m*(x+1)-n;
        y22=y2*a;
        if(y11<y22)
        printf("%lld\n",y11);
        else
        printf("%lld\n",y22);

	}
	return 0;
}

#include <stdio.h>

long long nzv(long long n, long long m) {
	long long x = n / m;
	if(n == m * x) return m * x;
	return m * (x+1);
}

int main() {
	long long n, m, a, b;
	scanf("%lld%lld%lld%lld", &n, &m, &a, &b);
	long long demolish = n % m * b;
	long long build = (nzv(n, m) - n) * a;

	if(build < demolish) printf("%lld", build);
	else printf("%lld", demolish);
	return 0;
}

#include <stdio.h>

int main(){

	long long n,m,a,b;
	scanf("%lld %lld %lld %lld",&n,&m,&a,&b);
	printf("%lld\n",((n%m)*b<((m-(n%m))%m)*a)?(n%m)*b:((m-(n%m))%m)*a);

	return 0;
}

#include<stdio.h>
#include<stdlib.h>

int main()
{
	long long int n, m, a, b;
	scanf("%lld%lld%lld%lld", &n, &m, &a, &b);
	long long int mod = n%m;
	if(mod==0)
	{
		printf("0\n");
	}
	else
	{
		long long int dem = b*mod;
		long long int cons = a*(m-mod);
		if(dem<cons)
		{
			printf("%lld\n", dem);
		}
		else
		{
			printf("%lld\n", cons);
		}
	}
	return 0;
}

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define ll long long
int main(void)
{
    ll n,m,a,b;
    ll c1,c2,t;
    scanf("%lld%lld%lld%lld",&n,&m,&a,&b);

    if(n%m==0) printf("0");
    else
    {
        if(n>m)
        {
            c1=(n%m)*b;
            c2=(ceil(n*1./m)*m-n)*a;
            t=(c1>=c2)?c2:c1;
            printf("%lld",t);
        }
        else
        {
            c1=(m-n)*a;
            c2=n*b;
            t=(c1>=c2)?c2:c1;
            printf("%lld",t);
        }
    }

    return 0;
}

#include<stdio.h>
int main()
{
    long long int n,m,a,b,ans1,ans2,i,p;
    scanf("%I64d%I64d%I64d%I64d",&n,&m,&a,&b);
    if(n%m==0)
    {

        printf("");
    }
    if(n<m)
    {
        ans1=((m-n)*a);
        ans2=n*b;
    }
    else
    {
        ans1=(n%m)*b;
        ans2=((((n/m)+1)*m)-n)*a;
    }

    if(ans1<ans2)
        printf("%I64d",ans1);
    else
        printf("%I64d",ans2);

    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    long long n, m, a, b;
    scanf("%I64d%I64d%I64d%I64d", &n, &m, &a, &b);

    if((n%m)*b<(m-n%m)*a) printf("%I64d\n", (n%m)*b);
    else printf("%I64d\n", (m-n%m)*a);

    return 0;
}

#include <stdio.h>
int main()
{
    long long int n, m, a, b, c, d;
    scanf("%I64d %I64d %I64d %I64d", &n, &m, &a, &b);
    c=n%m;
    d=m-c;
    if(d*a>c*b)
        printf("%I64d\n", c*b);
    else
        printf("%I64d\n", d*a);

    return 0;
}

#include<stdio.h>
int main()
{
	long long int n,m;
	scanf("%lld %lld",&n,&m);
	int a,b;
	scanf("%d %d",&a,&b);
	long long int c1=0,c2=0;
	c1 = (m-(n%m)) * a;
	c2 = (n%m)*b;
	if (c1<c2)
		printf("%lld\n",c1);
	else
		printf("%lld\n",c2);
	return 0;
}

#include<stdio.h>
int main()
{
    long long int i, j, a, b, n, m, sum = 0;
    scanf("%lld %lld %lld %lld", &n, &m, &a, &b);
    if(n % m != 0)
    {
        if(n < m)
            sum = n*b;
        else
            sum = a*(2*m - n);
    }
    else
        sum = 0;
    printf("%lld\n", sum);
}

#include<stdio.h>

int main()
{
    long long n,m,a,b,p,q,l;
    scanf("%lld%lld%lld%lld",&n,&m,&a,&b);
    if(m>n)
    {
    printf("%lld",n*b);
    }
    else if(n>m)
    {
    l=n/m;
    p=(n-(m*l))*b;
    q=(((l+1)*m)-n)*a;
    if(p>q)
    printf("%lld",q);
    else
    printf("%lld",p);
    }
    else
    printf("%d",0);
    return 0;
}

#include<stdio.h>
#include<math.h>
#define Min(a,b) a<b ? a : b
int main()
{
    int n, m, a, b, d, x, y;
    scanf("%d%d%d%d",&n,&m,&a,&b);
    if(n%m==0)
    {
        printf("0\n");
        return 0;
    }
    d = (m+n-1)/m;
    x = (d*m - n)*a;
    d = Min(n,abs(n-m));
    y = d*b;
    printf("%d\n",Min(x,y));
    return 0;
}

#include <stdio.h>

int main()
{
	long long m,n ;
	int a,b ;
	scanf("%lld%lld%d%d",&m,&n,&a,&b) ;
	int i ;
	int cost1,cost2 ;
	if(m==n || m%n==0)
		cost1 = cost2 = 0 ;
	else if(m>n)
	{
		cost1 = a*(2*n-m) ;
		cost2 = b*(m-n) ;
	}
	else
	{
		cost1 = (n-m)*a ;
		cost2 = m*b ;
	}
	printf("%d\n",cost1>=cost2?cost2:cost1) ;
	return 0 ;
}

#include<stdio.h>
#include<stdlib.h>
#define min(x,y) x<y?x:y
int main()
{
    int m,n,a,b,ccost,dcost;
    scanf("%d%d%d%d",&n,&m,&a,&b);
    if(n==m) printf("0");
    else if(n>m)
    {
        int dr=n%m,cr=((n/m)+1)*m-n;
        printf("%d",min(cr*a,dr*b));
    }
    else
    {
       int diff=m-n;
       printf("%d",min(diff*a,n*b));
    }

    return 0;
}

#include<stdio.h>
int main()
{
    int n,m,a,b,build,dem;
    scanf("%d %d %d %d",&n,&m,&a,&b);
    build = m*a -(n%m)*a;
    dem = (n%m)*b;
    build<=dem? printf("%d",build):printf("%d",dem);
    return 0;
}

#include<stdio.h>
int main()
{
    long long int i, j, a, b, n, m, sum = 0, sum1 = 0;
    scanf("%lld %lld %lld %lld", &n, &m, &a, &b);
    if(n % m != 0)
    {
        if(n < m)
            {
                sum = n*b;
                sum1 = (m - n)*a;
                if(sum1 > sum)
                    printf("%lld\n", sum);
                else
                    printf("%lld\n", sum1);
            }
        else
            {
                sum = a*(2*m - n);
                sum1 = b*(n-m);
                if(sum1 > sum)
                    printf("%lld\n", sum);
                else
                    printf("%lld\n", sum1);
            }

    }
    else
        printf("%lld\n", sum);

}

#include<stdio.h>
#include<string.h>
int main(){
long long int n,m,a,b,c,d;
scanf("%I64d%I64d%I64d%I64d",&n,&m,&a,&b);
if(n%m==0) printf("0");
else{
    c=n%m;
    d=(n/m+1)*m;
    if((d-n)*a>c*b) printf("%d",c*b);
    else printf("%d",a*(d-n));
}
return 0;
}

#include<stdio.h>
#include<math.h>
int main(){
    long long int n, m;
    int a, b;
    scanf("%ld%ld%d%d", &n, &m, &a, &b);
    if(n % m ==0)
        printf("0");
    else{
        /**Hallar el m�ltiplo m�s cercano a m, por encima y por
        debajo de n:
            dividir n entre m y tomar el resultado, por exceso y por defecto
            multiplicar dichos resultados por m y ya tenemos los m�ltiplos buscados*/
        int ex, de;
        ex = n/m + 1;
        de = n/m;
        ex = ex * m;
        de = de * m;
        if(de == 0)
            de = n * b;
        else{
            de = fabs(de - n);
            de = de * b;
        }
        ex = fabs(ex - n);
        ex = ex * a;
        if(ex > de)
            printf("%d", de);
        else
            printf("%d", ex);
    }
    return 0;
}

#include<stdio.h>

int main(void)
{
	long long n, m, a, b;
	long long min;

	scanf("%%I64d %I64d %I64d %I64d", &n, &m, &a, &b);

	min = (n % m) * b < (m - (n % m)) * a ? (n % m) * b : (m - (n % m)) * a;

	printf("%I64d", min);
}

#include<stdio.h>
int main()
{
    int n,m,a,b,i,j;
    scanf("%d%d%d%d",&n,&m,&a,&b);
    if(n%m!=0)
    {
       if(n<m)
       {
           i=n*b;
           j=(m-n)*a;
           if(i<j)
           {
               printf("%d\n",i);
           }
           else
           {
               printf("%d\n",j);
           }
       }
       else if(n>m)
       {
           i=(n%m)*b;
           j=(m-(n%m))*a;
           if(i<j)
           {
               printf("%d\n",i);
           }
           else
           {
               printf("%d\n",j);
           }

       }
    }
    else
    {
        i=0;
        printf("%d\n",i);
    }
    return 0;
}

#include<stdio.h>
#include<math.h>
int main()
{
	int n,m,a,b,res;
	scanf("%d %d %d %d",&n,&m,&a,&b);
	res=n/m;
	if(n % m == 0)
		printf("0");

	else
	{
		if((n-m*res)*b >(m*(res+1)-n)*a)
			printf("%d",(m*(res+1)-n)*a);
		else
			printf("%d",(n-m*res)*b);
	}
}

#include<stdio.h>
int main()
{
    int i, j, a, b, n, m, sum = 0;
    scanf("%d %d %d %d", &n, &m, &a, &b);
    if(n % m != 0)
    {
        if(n < m)
            sum = n*b;
        else
            sum = a*(2*m - n);
    }
    else
        sum = 0;
    printf("%d\n", sum);
}

#include<stdio.h>
int main()
{
    int n,m,a,b,ans,c1,c2,yu;
    scanf("%d %d %d %d",&n,&m,&a,&b);
    yu=n%m;
    if(yu==0)
        printf("0\n");
    else
    {
        c1=yu*b;
        c2=(m-yu)*a;
        if(c1>c2)
            printf("%d\n",c2);
        else
            printf("%d\n",c1);
    }
    return 0;
}

#include<stdio.h>
main()
{
    long int n,m,a,b,p,q,cntd=0,cntb=0,i,j,k,d=0,b1=0,g=0;
    scanf("%ld%ld%ld%ld",&n,&m,&a,&b);
    p=n;q=n;
    cntd=p%m;
    d=cntd*b;
    if(q%m==0)cntb=0;
    else
    {
        q=q+m;
        g=q/m;
        cntb=g*m-n;
    }
    b1=cntb*a;

    if(b1<d)printf("%ld\n",b1);
    else printf("%ld\n",d);
    return 0;

}

#include<stdio.h>
int main()
{
    int c,a,n,m,b,d,e,f;
    scanf("%d%d%d%d",&n,&m,&a,&b);
    c=n%m;
    d=m-n%m;
    b=b*c;
    a=a*d;
    if(a>b)
        printf("%d\n",b);
    else
        printf("%d\n",a);
    return 0;
}

#include<stdio.h>
int main()
{
    int a,b,c,n,m;
    scanf("%d %d %d %d",&n,&m,&a,&b);
    if(n%m==0){
        printf("0\n");
    }
    else{
        if(n<m){
            printf("%d\n",n*b);
        }
        else if(n>m){
            c=(m*2)-n;
            printf("%d\n",c*a);
        }
    }

}

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define ll long long
int main(void)
{
    ll n,m,a,b;
    ll x,y,z;
    ll cost1,cost2;
    scanf("%lld%lld%lld%lld",&n,&m,&a,&b);
    if(n%m==0) printf("0");
    else
    {
        if(n>m)
            x=ceil(n*1./m);
        else
            x=ceil(m*1./n);
        cost1=(x*m-n)*a;
        cost2=(n*b);
        if(cost1>=cost2)
            printf("%lld",cost2);
        else
            printf("%lld",cost1);
    }

    return 0;
}

#include<stdio.h>
int main()
{
    long long int n,m,rem1,rem2,ans1,ans2;
    int a,b;
    scanf("%lld%lld%ld%ld",&n,&m,&a,&b);
    rem1=n%m;
    ans1=rem1*b;
    rem2=m-rem1;
    ans2=rem2*a;
    if(ans1>=ans2)
    {
        printf("%d",ans2);
    }
    else
    {
        printf("%d",ans1);
    }
    return 0;
}

#include<stdio.h>

int main()
{
	int n,m,a,b;
	scanf("%d %d %d %d",&n,&m,&a,&b);

	if(n%m==0)
		{
			printf("%d\n",0);
			return 0;
		}

	int dem,bui;
	bui=(m-n%m)*a;
	dem=(n%m)*b;

	if(bui<dem)
	     printf("%d\n",bui);

	else
		printf("%d\n",dem);

	return 0;

}

#include<stdio.h>
int main()
{
    long int n,m,a,b,c,d;
    scanf("%d%d%d%d",&n,&m,&a,&b);
    if(n>m)
    {
        if(n%m==0)
        printf("0");
        else
        {
        		c=a*(m-(n%m));
        		d=b*(n%m);
        		if(c<d)
        			printf("%d",c);
        		else
        			printf("%d",d);
        }
    }
    else
    {
        c=((m-n)*a);
        d=(n*b);
        if(c<d)
        printf("%d",c);
        else
        printf("%d",d);
    }
    return 0;
}

#include<stdio.h>
int main()
{
    long long int a,b,c,d,x,y,n,m;
    scanf("%lld %lld %lld %lld",&n,&m,&a,&b);
    if(n%m==0){
        printf("0\n");
    }
    else{
        if(n<m){
            x=n*b;
            y=(m-n)*a;
            if(x>y)
            printf("%lld\n",y);
            else
            printf("%lld\n",x);
        }
        else if(n>m){
            c=((m*2)-n)*a;
            d=(n-m)*b;
            if(c>d)
            printf("%lld\n",d);
            else
            printf("%lld\n",c);
        }
    }

}

#include<stdio.h>
int main()
{
    long long n,m,cost1,cost2;
    int a,b;
    scanf("%I64d %I64d %d %d",&n,&m,&a,&b);
    if(n%m==0)
        printf("0");
    else
    {
        if(n>m){
        cost1=((n/m+1)*m-n)*a;
        cost2=(n-(n/m-1)*m)*b;
        }
        else
        {
            cost1=(m-n)*a;
            cost2=n*b;
        }
    if(cost1<=cost2)
        printf("%I64d",cost1);
    else
        printf("%I64d",cost2);
    }
    return 0;
}

//Bismillahir rahmanir rahim

#include <stdio.h>

int main(void) {
	// your code goes here
	int m,n,a,b,rem,ans;
	scanf("%d %d %d %d",&m,&n,&a,&b);
	rem = m % n ;
	int ans1 = rem*b;
	int ans2 = (n-rem)*a;
	if(ans1>ans2)   ans=ans2;
	else ans=ans1;
	printf("%d",ans);
	return 0;
}

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
#include<time.h>

int main()
{
    long long int n,m,a,b,r,i,j;
    scanf("%I64 %I64 %I64 %I64",&n,&m,&a,&b);
    if(n%m==0)
        printf("0");
    else if(n%m!=0)
    {
     r=n%m;
      i=r*b;
      j=(m-r)*a ;
      if(i<j)
        printf("%I64",i);
      else printf("%I64",j);
    }
}

#include<stdio.h>
int main()
{

	int m,n,a,b;
	while(scanf("%d%d%d%d",&m,&n,&a,&b)==4)
	{
		int j,k;
		if(m%n==0)
		printf("0\n");
		else{
			j=((2*n)-m)*a;
			k=(m%n)*b;
			if(j>k)
			j=k;
			printf("%d\n",j);
		}
	}
	return 0;
}

#include<stdio.h>
int main(){
    int n,m,a,b;
    scanf("%d%d%d%d",&n,&m,&a,&b);
    int respuesta = 0;
    int costoA,costoB;
    if( n % m != 0 ){
        costoA = a * ( m - ( n % m ) );
        costoB = b * ( n % m );
        if( costoA < costoB ){
            respuesta = costoA;
        }else{
            respuesta = costoB;
        }
    }
    printf("%d",respuesta);
    return 0;
}

#include<stdio.h>

int main()
{
	long long int m,n,a,b;
	int l,d;

	while(scanf("%l64d%l64d%l64d%l64d",&m,&n,&a,&b)!=EOF)
	{
		if(m%n==0)
		{
			printf("0\n");
		}
		else
		{
			l=(n-(m%n))*a;
			d=(m%n)*b;

			if(l<d)
			{
				printf("%d\n",l);
			}
			else
			{
				printf("%d\n",d);
			}
		}

	}

	return 0;
}

#include<stdio.h>
#include<math.h>
int main()
{
	int n,m;
	long long a,b;
	long long anc,sum;
	int i;
	while(scanf("%d%d%ld%ld",&n,&m,&a,&b)==4)
	{
		anc=sum=0;
	      	if(n%m==0)
		{
			printf("0\n");

		}
		else
		{
			if(n>m)
			{
			anc=b*(n-m);

			sum=(2*m-n)*a;
			}
			else
			if(n<m)
			{
				anc=n*b;
				sum=(m-n)*a;
			}
				if(anc<sum)
				{
					printf("%ld\n",anc);

				}
				else
				{
					printf("%ld\n",sum);

				}

		}

	}
	return 0;
}

#include<stdio.h>
int main(void)
{
	int a,b,m,n,sum1=0,sum2=0,sum=0;
	scanf("%d%d%d%d",&n,&m,&a,&b);
	if(n%m==0)
	{
		printf("0\n");
	}
	if(n%m!=0)
	{
		if(n>m)
		{
			sum1=(m-(n-m))*a;
			sum2=(n-m)*b;
			if(sum1<sum2)
			{
				printf("%d\n",sum1);
			}
			if(sum1==sum2)
			{
				printf("%d\n",sum1);
			}
			if(sum1>sum2)
			{
				printf("%d\n",sum2);
			}
		}
		if(n<m)
		{
			sum1=(m-n)*a;
			sum2=n*b;
			if(sum1<sum2)
			{
				printf("%d\n",sum1);
			}
			if(sum1==sum2)
			{
				printf("%d\n",sum1);
			}
			if(sum1>sum2)
			{
				printf("%d\n",sum2);
			}
		}
	}
}

#include <stdio.h>

int main(void) {
    int n,m,a,b,x,a1,a2;
    scanf("%d %d %d %d",&n,&m,&a,&b);
    if(n%m==0)
    {
        printf("0");
    }
    else
    {
        x=n%m;
        a1=(x)*b;
        a2=(m-x)*a;
        if(a1>a2)
        {
            printf("%d",a2);
        }
        else
        {
            printf("%d",a1);
        }
    }
	return 0;
}

#include<stdio.h>

int main()
{
	long long int m,n;
	int a,b,l,d;

	while(scanf("%lld%lld%d%d",&m,&n,&a,&b)!=EOF)
	{
		if(m%n==0)
		{
			printf("0\n");
		}
		else
		{
			l=(n-m%n)*a;
			d=(m%n)*b;

			if(l<d)
			{
				printf("%lld\n",l);
			}
			else
			{
				printf("%lld\n",d);
			}
		}

	}

	return 0;
}

#include<stdio.h>
int main()
{

    long long int m,n,a,b,p,q;
    scanf("%I64d %I64d %I64d %I64d",&n,&m,&a,&b);
    if( n%m==0){
        printf("0");
    }
    else if(n>m && n%m!=0){
        p=(n-m)*b;
        q=((m*2)-n)*a;
        if(p>q){
            printf("%I64d",q);
        }
        else
            printf("%I64d",p);
    }
    else if(n<m){
        p=(m-n)*a;
        q=(n)*b;
        if(p>q){
            printf("%I64d",q);
        }
        else
            printf("%I64d",p);
    }

}

#include <stdio.h>
int main()
{
    long long int n,m,sum1,sum2;
    int a,b;
    scanf("%lld %lld %d %d",&n,&m,&a,&b);
    if(n%m==0)
        printf("0\n");
    else
    {
        int t;
        t=n%m;
        sum1=t*b;
        sum2=(m-t)*a;
        if(sum1>=sum2)
            printf("%lld\n",sum2);
        else
            printf("%lld\n",sum1);
    }
    return 0;
}

#include<stdio.h>
#define ll long long int
int main()

{
    ll n,m,a,b;
    scanf("%lld %lld %lld %lld",&n,&m,&a,&b);
    if(n%m==0)
        printf("0\n");
    else
    {
        if(n>m)
        {
            if((m-(n%m))*a<(m-(n%m))*b)
                printf("%lld\n",(m-(n%m))*a);
            else
                printf("%lld\n",(m-(n%m))*b);
        }
        else
        {
            if((m-n)*a>n*b)
                printf("%lld\n",n*b);
            else
                printf("%lld\n",(m-n)*b);
        }
    }
    return 0;
}

#include <stdio.h>

int main()
{
	int n,m,a,b,r,s;

	scanf("%d%d%d%d",&n,&m,&a,&b);

	if(n%m == 0)
	{
		printf("0\n");
	}
	else
	{
		s = n % m * b > (m - n % m) * a ?(m - n % m) * a:n % m * b;

		s = s > n * b?n * b:s;

		printf("%d",s);
	}

	return 0;
}

#include <stdio.h>

int main(void) {
	long long int n,m,a,b,c,d,cc,dd;
	scanf("%lld%lld%lld%lld",&n,&m,&a,&b);
	if(n>m)
	{
		d=n%m;
		dd=d*b;
		c=(((n/m)+1)*m)-n;
		cc=c*a;
	}
	else if(m>n)
	{
		dd=n*b;
		cc=(m-n)*a;
	}
	if(dd>cc)printf("%lld\n",cc);
	else if(cc>dd)printf("%lld\n",dd);
	else if (n%m==0)printf("0\n");

	return 0;
}

#include <stdio.h>

int main()
{
    int a , b, n, m, c, x, y, z;
    scanf("%d %d %d %d", &n, &m, &a, &b);

    c = n / m;

    if(n%m == 0)
    {
        printf("0\n");
        return 0;
    }

    x = (((c + 1)*m )- n)*a ;
    y = (n-(c*m))*b;
    if(x < y)
        z = x;
    else
        z = y;
    printf("%d\n", z);

    return 0;

}

//
//
#include <stdio.h>

int main()
{
    long long int n,i,m,a,b;
    scanf("%I64d %I64d %I64d %I64d",&n,&m,&a,&b);
    i=n%m;
    if(i==0)
    printf("0\n");
    else if(a*i<=b*(m-i))
    printf("%I64d\n",a*i);
    else
    printf("%I64d\n",b*(m-i));
	return 0;
}

#include<stdio.h>
#include<math.h>

int main()
{

    long long int m,n,a,b,p,q;
    scanf("%I64d %I64d %I64d %I64d",&n,&m,&a,&b);
    if( n%m==0){
        printf("0");
    }
    else if(n>m && n%m!=0){
        p=(n-m)*b;
        q=(m*(ceil(n/(m*1.0)))-n)*a;
        if(p>q){
            printf("%I64d",q);
        }
        else
            printf("%I64d",p);
    }
    else if(n<m){
        p=(m-n)*a;
        q=(n)*b;
        if(p>q){
            printf("%I64d",q);
        }
        else
            printf("%I64d",p);
    }

}

#include<stdio.h>
int main()
{
    long long int i, j, a, b, n, m, sum = 0;
    scanf("%lld %lld %lld %lld", &n, &m, &a, &b);
    if(n % m != 0)
    {
        if(n < m)
            sum = n*b;
        else
            sum = a*(2*m - n);
    }
    else
        sum = 0;
    printf("%lld\n", sum);
}

#include<stdio.h>
int main(void)
{
	int a,b,m,n,sum1=0,sum2=0,sum=0;
	scanf("%d%d%d%d",&n,&m,&a,&b);
	if(n%m==0)
	{
		printf("0\n");
	}
	if(n%m!=0)
	{
		if(n>m)
		{
			sum1=(m-(n-m))*a;
			sum2=(n-m)*b;
			if(sum1<sum2)
			{
				printf("%d\n",sum1);
			}
			else
			{
				printf("%d\n",sum2);
			}
		}
		if(n<m)
		{
			sum1=(m-n)*a;
			sum2=n*b;
			if(sum1<sum2)
			{
				printf("%d\n",sum1);
			}
			else
			{
				printf("%d\n",sum2);
			}
		}
	}
}

#include<stdio.h>

int main()
{
	long long n,m;
	int a,b;
	long long anc,sum;
	int i;
	scanf("%I64d%I64d%d%d",&n,&m,&a,&b);

		anc=sum=0;
	      	if(n%m==0 )
		{
			printf("0\n");

		}
		else
		{
			if(n>m&& n%m!=0)
			{
			anc=b*(n-m);

			sum=(2*m-n)*a;
			}
			else
			if(n<m && n%m!=0)
			{
				anc=n*b;
				sum=(m-n)*a;
			}
				if(anc<sum)
				{
					printf("%I64d\n",anc);

				}
				else
				{
					printf("%ld\n",sum);

				}

		return 0;

	}
	return 0;
}

#include<stdio.h>
#include<stdlib.h>
#define min(x,y) x<y?x:y
int main()
{
    int m,n,a,b,ccost,dcost;
    scanf("%d%d%d%d",&n,&m,&a,&b);
    if(n==m) printf("0");
    else if(n>m)
    {
        int dr=n%m,cr=((n/m)+1)*m-n;
        printf("%d",min(cr*a,dr*b));
    }
    else
    {
       int diff=m-n;
       printf("%d",min(diff*a,n*b));
    }

    return 0;
}

#include <stdio.h>
int main()
{
	long long int a,b,c,d,e,f,g,h;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	if(a%b==0)
	{
		printf("0\n");
		return 0;
	}
	else
	{
		if(a<b)
		{
			f=b-a;
		}
		else
		{
			e=a/b;
			e=e+1;
			f=(e*b)-a;
		}
			g=f*c;
			h=a*d;
			if(g<h)
			{
				printf("%lld\n",g);
				return 0;
			}
			else
		{
			printf("%lld\n",h);
			return 0;
		}
		}

}

#include<stdio.h>
int main()
{
    int n,m,a,b,c,d;
    scanf("%d%d%d%d",&n,&m,&a,&b);
    if(n>m)
    {
        if(n%m==0)
        printf("0");
        else
        {
        		c=a*(m-(n%m));
        		d=b*(n%m);
        		if(c<d)
        			printf("%d",c);
        		else
        			printf("%d",d);
        }
    }
    else
    {
        c=((m-n)*a);
        d=(n*b);
        if(c<d)
        printf("%d",c);
        else
        printf("%d",d);
    }
    return 0;
}

#include<stdio.h>
int main()
{
	long long n, m, a, b ;
	scanf("%I64d %I64d %I64d %I64d", &n, &m, &a, &b);
	if (n >= m) {
		long long x, y;
		x = n % m;
		y = n / m;
		if (b*x >= ((y + 1)* m-n)*a) printf("%I64d", ((y + 1)*m-n)*a);
		else printf("%I64d", b*x);
	}
	else if (n < m) {
		if (a*n >= (m - n)*b) printf("%I64d", a*n);
		else printf("%I64d", (m - n)*b);
	}
}

#include <stdio.h>

int main(void) {
    int n,m,a,b,x,a1,a2,ans;
    scanf("%d",&n,&m,&a,&b);
    if(n%m==0)
    {
        printf("0\n");
    }
    else
    {
        x=n%m;
        a1=(n-x)*b;
        a2=(n+m-x)*a;
        if(a1>a2)
        {
            printf("%d",a2);
        }
        else
        {
            printf("%d",a1);
        }
    }
	// your code goes here
	return 0;
}

#include<stdio.h>
int main()
{

	long long int m,n,a,b;
	while(scanf("%lld%lld%lld%lld",&m,&n,&a,&b)==4)
	{
		long long j,k;
		if(m%n==0)
		printf("0\n");
		else{
			j=((2*n)-m)*a;
			k=(m%n)*b;
			if(j>k)
			j=k;
			printf("%lld\n",j);
		}
	}
	return 0;
}

#include<stdio.h>

int main()
{
	long long int m,n,a,b;
	int l,d;

	while(scanf("%lld%lld%lld%lld",&m,&n,&a,&b)!=EOF)
	{
		if(m%n==0)
		{
			printf("0\n");
		}
		else
		{
			l=(n-(m%n))*a;
			d=(m%n)*b;

			if(l<d)
			{
				printf("%d\n",l);
			}
			else
			{
				printf("%d\n",d);
			}
		}

	}

	return 0;
}

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
#include<time.h>

int main()
{
    long long int n,m,a,b,r,i,j;
    scanf("%I64 %I64 %I64 %I64",&n,&m,&a,&b);
    if(n%m==0)
        printf("0");
    else if(n%m!=0)
    {
     r=n%m;
      i=r*b;
      j=(m-r)*a ;
      if(i<j)
        printf("%I64",i);
      else printf("%I64",j);
    }
}

#include<stdio.h>
int main()
{
    int n,m,a,b,ans,c1,c2,yu;
    scanf("%d %d %d %d",&n,&m,&a,&b);
    yu=n%m;
    if(yu==0)
        printf("0\n");
    else
    {
        c1=yu*b;
        c2=(m-yu)*a;
        if(c1>c2)
            printf("%d\n",c2);
        else
            printf("%d\n",c1);
    }
    return 0;
}

#include<stdio.h>
#include<math.h>

int main()
{
    long long int n,m,a,b,result,temp;

    scanf("%lld%lld%lld%lld",&n,&m,&a,&b);
    temp=n;
    if(n%m==0)
        {
            printf("0\n");
            return 0;
        }
    else
    {
        if(n>m)
        {
            while(1)
            {
                if(n%m==0) break;

                n++;

            }
        result=(n-temp)*a;
        printf("%%I64d\n",result);
        return 0;
        }

        else if(n<m)
        {
            result=(n)*b;
            printf("%%I64d",result);
            return 0;
        }

    }

}

#include<stdio.h>

int main()
{
	int m,n,a,b,l,d;

	while(scanf("%d%d%d%d",&m,&n,&a,&b)!=EOF)
	{
		if(m%n==0)
		{
			printf("0");
		}
		else
		{
			l=(n-m%n)*a;
			d=(m%n)*b;

			if(l<d)
			{
				printf("%d",l);
			}
			else
			{
				printf("%d",d);
			}
		}

	}

	return 0;
}

#include<stdio.h>

int main()
{
    long long n,m,a,b,p,q,l;
    scanf("%lld%lld%lld%lld",&n,&m,&a,&b);
    if(m>n)
    {
    p=n*b;
    q=(m-n)*b;
    if(p>q)
    printf("%lld",q);
    else
    printf("%lld",p);
    //printf("%lld",n*b);
    }
    else if(n>m)
    {
    l=n/m;
    p=(n-(m*l))*b;
    q=(((l+1)*m)-n)*a;
    if(p>q)
    printf("%lld",q);
    else
    printf("%lld",p);
    }
    else
    printf("%d",0);
    return 0;
}

#include<stdio.h>
#define min(x,y) x<y?x:y
int main()
{
int n,m,a,b,x,y;
scanf("%d %d %d %d",&n,&m,&a,&b);
x=(m-(n%m))*a;
y=(n%m)*b;
printf("%d",min(x,y));
return 0;
}

#include<stdio.h>
int main()
{
	long long int n,m,a,b,c,d,f;

	while(scanf("%lld%lld%lld%lld",&n,&m,&a,&b)==4)
	if(n%m==0)
	{
		printf("0");
	}
	else if(n<m)
	{
		c=b*n;
		d=(m-n)*a;
		if(c>d)
		{
			printf("%d",d);
		}
		else
		{
			printf("%d",c);
		}
	}
	else if(n>m)
	{
		f=n%m;
		c=a*(m-f);//jianli
		d=b*f;
		if(c>d)
		{
			printf("%d",d);
		}
		else
		{
			printf("%d",c);
		}
	}
	return 0;
}

#include<stdio.h>
#include<math.h>
int main()
{
	long long n,m;
	int a,b;
	long long anc,sum;
	int i;
	while(scanf("%ld%ld%d%d",&n,&m,&a,&b)==4)
	{
		anc=sum=0;
	      	if(n%m==0)
		{
			printf("0\n");

		}
		else
		{
			if(n>m)
			{
			anc=b*(n-m);

			sum=(2*m-n)*a;
			}
			else
			if(n<m)
			{
				anc=n*b;
				sum=(m-n)*a;
			}
				if(anc<sum)
				{
					printf("%ld\n",anc);

				}
				else
				{
					printf("%ld\n",sum);

				}

		}

	}
	return 0;
}

#include<stdio.h>
#include<stdlib.h>
#define min(x,y) x<y?x:y
int main()
{
    int m,n,a,b,ccost,dcost;
    scanf("%d%d%d%d",&n,&m,&a,&b);
    if(n==m) printf("0");
    else if(n>m)
    {
        int dr=n%m,cr=((cr/m)+1)*m-n;
        printf("%d",min(cr*a,dr*b));
    }
    else
    {
       int diff=m-n;
       printf("%d",min(diff*a,n*b));
    }

    return 0;
}

#include<stdio.h>
#include<math.h>

int main()
{
	long int n,m;
	int a,b;

	scanf("%ld%ld%d%d",&n,&m,&a,&b);

	long int r1,r2,c1,c2;

	if(n%m==0)
	{
		printf("0\n");
	}

	else
	{
		r1=n%m;
		r2=m-r1;

		if(r1<r2)
		{
	        	c1=r1*b;
	        	c2=r2*a;

		       if(c1<c2)
		       printf("%ld\n",c1);

		       else
		       printf("%ld\n",c2);
	    }

	    else
	    {
	    	    c1=r2*a;
	        	c2=r1*b;

		       if(c1<c2)
		       printf("%ld\n",c1);

		       else
		       printf("%ld\n",c2);
		}
	}
	return 0;

}

#include<stdio.h>
int main()
{
    int n,m,a,b,c,d;
    scanf("%d%d%d%d",&n,&m,&a,&b);
    if(n>m)
    {
        if(n%m==0)
        printf("0");
        else
        {
        		c=a*(m-(n%m));
        		d=b*(n%m);
        		if(c<d)
        			printf("%d",c);
        		else
        			printf("%d",d);
        }
    }
    else
    {
        c=((m-n)*a);
        d=(n*b);
        if(c<d)
        printf("%d",c);
        else
        printf("%d",d);
    }
    return 0;
}

#include<stdio.h>
int main()
{
    int m,n,a,b,ccost,dcost;
    scanf("%d%d%d%d",&n,&m,&a,&b);
    if(n==m) printf("0");
    else if(n>m)
    {
        int cr=n%m;
        printf("%d",cr*a>cr*b?cr*b:cr*a);
    }
    else
    {
        int cr=m%n;
        printf("%d",cr*a>cr*b?cr*b:cr*a);
    }

    return 0;
}

#include<stdio.h>
main()
{
    long int n,m,a,b,p,q,cntd=0,cntb=0,i,j,k,d=0,b1=0,flag=0;
    scanf("%ld%ld%ld%ld",&n,&m,&a,&b);
    p=n;q=n;
    while(1)
    {
        if(q%m!=0)
        {
            q=q-1;cntd++;
        }
        else break;
    }d=cntd*b;
    while(1)
    {  if(b1>d){flag=1;break;}
        if(p%m!=0)
        {
            p=p+1;cntb++;
            b1=cntb*a;
        }
        else break;
    }

    if(flag==0)printf("%ld\n",b1);
    else printf("%ld\n",d);
    return 0;

}

#include<stdio.h>
int main()
{
    long long int a,b,c,n,m;
    scanf("%lld %lld %lld %lld",&n,&m,&a,&b);
    if(n%m==0){
        printf("0\n");
    }
    else{
        if(n<m){
            printf("%lld\n",n*b);
        }
        else if(n>m){
            c=(m*2)-n;
            printf("%lld\n",c*a);
        }
    }

}

#include<stdio.h>

int main()
{
  int n,m,a,b,acost,bcost,t;
  scanf("%d%d%d%d",&n,&m,&a,&b);
  if(n%m==0)
   return printf("0\n"),0;
  else
  {
      t=n%m;
      acost=(m-t)*a;
      bcost=t*b;

      if(bcost<acost)
        return printf("%d\n",bcost),0;
  }
    printf("%d\n",acost);
}

#include<stdio.h>

int main()

{
    int n,m,a,b,c,d;

    scanf("%d %d %d %d",&n,&m,&a,&b);

    d=(n%m)*b;

    c=(((ceil(1.0*n/m))*m)-n)*a;

    (c<d)?printf("%d",c):printf("%d",d);
}

#include <stdio.h>
int main()
{
    long long int n,m,sum1,sum2;
    int a,b;
    scanf("%lld %lld %d %d",&n,&m,&a,&b);
    if(n%m==0)
        printf("0\n");
    else
    {
        int t;
        t=n%m;
        sum1=t*b;
        sum2=(m-t)*a;
        if(sum1>=sum2)
            printf("%lld\n",sum2);
        else
            printf("%lld\n",sum1);
    }
    return 0;
}

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define ll long long
int main(void)
{
    ll n,m,a,b;
    ll c1,c2,t;
    scanf("%lld%lld%lld%lld",&n,&m,&a,&b);

    if(n%m==0) printf("0");
    else
    {
        if(n>m)
        {
            c1=(n-m)*b;
            c2=(ceil(n*1./m)*m-n)*a;
            t=(c1>=c2)?c2:c1;
            printf("%lld",t);
        }
        else
        {
            c1=(m-n)*a;
            c2=n*b;
            t=(c1>=c2)?c2:c1;
            printf("%lld",t);
        }
    }

    return 0;
}

#include <stdio.h>

int main(void) {
    int n,m,a,b,x,a1,a2;
    scanf("%d %d %d %d",&n,&m,&a,&b);
   // printf("%d %d %d %d",n,m,a,b);
    if(n%m==0)
    {
        printf("0\n");
    }
    else
    {
        x=n%m;
        a1=(x)*b;
        a2=(m-x)*a;
        if(a1>a2)
        {
            printf("%d",a2);
        }
        else
        {
            printf("%d",a1);
        }
    }
   // printf("%d",x);
    //printf("%d %d",a1,a2);
	// your code goes here
	return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int min(int a, int b){
    return a<b ? a : b;
}

int main(){

    int i=0;

    int n,m,a,b;
    scanf("%d %d %d %d",&n,&m,&a,&b);

    int p = n%m;
    int q = m-p;

    int ans = min(b*p,a*q);

    printf("%d\n",ans);

    return 0;

}

#include<stdio.h>

int main()
{
	long long n,m;
	int a,b;
	long long anc,sum;
	int i;
	scanf("%ld%ld%d%d",&n,&m,&a,&b);

		anc=sum=0;
	      	if(n%m==0 )
		{
			printf("0\n");

		}
		else
		{
			if(n>m&& n%m!=0)
			{
			anc=b*(n-m);

			sum=(2*m-n)*a;
			}
			else
			if(n<m && n%m!=0)
			{
				anc=n*b;
				sum=(m-n)*a;
			}
				if(anc<sum)
				{
					printf("%ld\n",anc);

				}
				else
				{
					printf("%ld\n",sum);

				}

		return 0;

	}
	return 0;
}

#include<stdio.h>
int main()
{
    long long int a,b,c,d,x,y,n,m;
    scanf("%lld %lld %lld %lld",&n,&m,&a,&b);
    if(n%m==0){
        printf("0\n");
    }
    else{
        if(n<m){
            x=n*b;
            y=(m-n)*a;
            if(x>y)
            printf("%lld\n",y);
            else
            printf("%lld\n",x);
        }
        else if(n>m){
            c=(m*2)-n;
            d=(n-m)*b;
            if(c>d)
            printf("%lld\n",d);
            else
            printf("%lld\n",c);
        }
    }

}

#include<stdio.h>
#define min(x,y) x<y?x:y
int main()
{
int n,m,a,b,x,y;
scanf("%d %d %d %d",&n,&m,&a,&b);
x=(m-(n%m))*a;
y=(n%m)*b;
printf("%d",min(x,y));
return 0;
}

#include <stdio.h>

int main(void) {
	long long n,m,a,b,c,d,cc,dd;
	scanf("%lld%lld%lld%lld",&n,&m,&a,&b);
	if(n>m)
	{
		d=n%m;
		dd=d*b;
		c=(((n/m)+1)*m)-n;
		cc=c*a;
	}
	else if(m>n)
	{
		dd=n*b;
		cc=(m-n)*a;
	}
	if(dd>cc)printf("%d\n",cc);
	else if(cc>dd)printf("%d\n",dd);
	else if (n%m==0)printf("0\n");

	return 0;
}

#include<stdio.h>
#include<math.h>
#define Min(a,b) a<b ? a : b
int main()
{
    int n, m, a, b, d, x, y;
    scanf("%d%d%d%d",&n,&m,&a,&b);
    if(n%m==0)
    {
        printf("0\n");
        return 0;
    }
    d = (m+n-1)/m;
    x = (d*m - n)*a;
    d = Min(n,abs(n-m));
    y = d*b;
    printf("%d\n",Min(x,y));
    return 0;
}

#include <stdio.h>

int main()
{
	int n,m,a,b,r,s;

	scanf("%d%d%d%d",&n,&m,&a,&b);

	if(n%m == 0)
	{
		printf("0\n");
	}
	else
	{
		s = n % m * b > (m - n % m) * a ?(m - n % m) * a:n % m * b;

		printf("%d\n",s);
	}

	return 0;
}

#include<stdio.h>
int main()
{
    int m,n,a,b,ccost,dcost;
    scanf("%d%d%d%d",&n,&m,&a,&b);
    if(n==m) printf("0");
    else if(n>m)
    {
        int cr=n%m;
        printf("%d",cr*a>cr*b?cr*b:cr*a);
    }
    else
    {
        int cr=m%n;
        printf("%d",cr*a>cr*b?cr*b:cr*a);
    }

    return 0;
}

#include<stdio.h>
#include<math.h>

int main()
{
    long long int n,m,a,b,result,temp,tenp2;

    scanf("%lld%lld%lld%lld",&n,&m,&a,&b);
    temp=n;tenp2=m;
    if(n%m==0)
        {
            printf("0\n");
            return 0;
        }
    else
    {
        if(n>m)
        {
            while(1)
            {
                if(n%m==0) break;

                n++;

            }
            printf("%d\n",n/m);
        result=((n-temp)*a);
        printf("%lld\n",result);
        return 0;
        }

        else if(n<m)
        {
            while(1)
            {
                if(n%m==0) break;

                n--;

            }
            result=(temp-n)*b;
            printf("%lld",result);
            return 0;
        }

    }

}