#include<stdio.h>

long long  mini(long long a, long long b, long long c)
{

 return a<=b?a<=c?a:c : b<=c?b:c;

}

int main(void)
{

long long min,n,a,b,c;

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

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

else if(n%4==3)
{

min = mini(a,b+c,3*c);

}

else if(n%4==2)
{

  min = mini(2*a, b, 2*c);

}

else if(n%4==1)
{

min = mini(3*a, c, a+b);

}

printf("%lld",min);

return 0;
}

#include<stdio.h>
#define min(a,b)            (((a) < (b)) ? (a) : (b))
int main()
{
long long int n,a,b,c,total=1000000000;
scanf("%I64d %I64d %I64d %I64d",&n,&a,&b,&c);
for(int i=0;i<=3;i++)
	for(int j=0;j<=3;j++)
		for(int y=0;y<=3;y++)
		{
			if( (i*1 + j*2 + y*3 + n)%4==0 )
			total=min(total,i*a+j*b+y*c);
		}
		printf("%I64d",total);
		return 0;
}

#include <stdio.h>

long long int min3(long long int a, long long int b, long long int c){
    if (a <= b && a <= c)
        return a;
    else if (b <= a && b <= c)
        return b;
    else
        return c;
}

int main(void) {
    long long int n, a, b, c;
    scanf("%I64d%I64d%I64d%I64d", &n, &a, &b, &c);
    if (n % 4 == 0)
        printf("0");
    else if (n % 4 == 1)
        printf("%I64d", min3(3 * a, c, a + b));
    else if (n % 4 == 2)
        printf("%I64d", min3(2 * a, b, 2 * c));
    else if (n % 4 == 3)
        printf("%I64d", min3(a, 3 * c, b + c));
    return 0;
}

#include <stdio.h>

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

int main()
{
	unsigned int n, a, b, c, ans;
	scanf("%u %u %u %u", &n, &a, &b, &c);
	if(n % 4 == 0)
	{
		ans = 0;
	}
	else if(n % 4 == 1)
	{
		ans = min(3 * a, a + b);
		ans = min(ans, c);
	}
	else if(n % 4 == 2)
	{
		ans = min(2 * a, b);
		ans = min(ans, 2 * c);
	}
	else
	{
		ans = min(a, 3 * c);
		ans = min(ans, b + c);
	}
	printf("%u\n", ans);
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
int main()
{
	long long int n , a , b ,c;
	scanf("%lld %lld %lld %lld",&n,&a,&b,&c);

	int j;
	j=n%4;

	long long int x ,y,z;

	switch(j)
	{
		case 0:
		{
			printf("%d",0);
			break;

		}

		case 1:
		{
			x=3*a<(a+b)?3*a:(b+a);
			y=x<c?x:c;
			z=y<(b+a)?y:(b+a);

			printf("%lld",z);
			break;
		}
		case 2:
		{
			x=2*a<b?2*a:b;
			y=x<2*c?x:2*c;

			printf("%lld",y);
			break;
		}
		case 3:
		{
			x=a<(b+c)?a:(b+c);
			y=x<3*c?x:3*c;
			printf("%lld",y);
			break;

		}
	}
}

#include <stdio.h>

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

int main()
{
	long long int n, a, b, c, ans = 0;

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

	n %= 4;

	//printf("n = %lld\n", n);
	n = 4 - n;

	//printf("n = %lld\n", n);
	if ( n == 1 )
	{
		ans = min ( a , 3 * c);
		ans = min ( ans, b + c );
	}

	else if ( n == 2)
	{
		ans = min ( 2*a, b);
		ans = min ( ans, 2*c );
	}

	else if ( n == 3)
	{
		ans = min ( a + b, 3 * a );
		ans = min ( ans, c );
	}

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

	return 0;
}

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

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

int main(){
  ll int n, a, b, c; scanf("%lld %lld %lld %lld", &n, &a, &b, &c);
  n %= 4; if(!n){ printf("0\n"); return 0; }
  if(n == 1) printf("%lld\n", min(min(3 * a, a + b), c));
  else if(n == 2) printf("%lld\n", min(min(2 * a, b), 2 * c));
  else if(n == 3) printf("%lld\n", min(min(a, c + b), 3 * c));
  return 0;
}

#include<stdio.h>
long long int min(long long int a,long long int b)
{
	long long int mini;
	if(a<b)
		mini=a;
	else
		mini=b;
	return mini;
}
int main()
{
	long long int n,a,b,c,o;
	scanf("%lld %lld %lld %lld",&n,&a,&b,&c);
	switch(4-n%4)
	{
		case 4:o=0;
		       break;
		case 1:o=min(a,3*c);
		       o=min(o,2*b+a);
		       o=min(o,b+c);
		       break;
		case 2:o=min(b,2*a);
		       o=min(o,2*c);
		       break;
		case 3:o=min(c,3*a);
		       o=min(o,a+b);
		       break;
	}
	printf("%lld\n",o);
	return 0;
}

#include <stdio.h>

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

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

	if(n % 4 == 0)
	{
		printf("0\n");
	}
	else if(n %4 == 1)
	{
		long long int temp = 3*a;
		if(temp > a + b) temp = a+b ;
		if(temp > c) temp = c ;
		printf("%lld\n",temp);
	}
	else if(n%4 ==2)
	{
		long long int temp = 2*a;
		if(temp >  b) temp = b ;
		if(temp > 2*c) temp = 2*c ;
		printf("%lld\n",temp);
	}
	else if (n%4 == 3)
	{
		long long int temp = a;
		if(temp > 3*c) temp = 3*c ;
		if(temp > b + c) temp = b + c ;
		printf("%lld\n",temp);
	}

	return 0;
}

#include <stdio.h>

#define INF	((long long) 8e18)

int main() {
	int n, i, j, k, a, b, c;
	long long cost;

	scanf("%d%d%d%d", &n, &a, &b, &c);
	n %= 4;
	cost = INF;
	for (i = 0; i <= 3; i++)
		for (j = 0; j <= 3; j++)
			for (k = 0; k <= 3; k++)
				if ((n + (long long) i * 1 + (long long) j * 2 + (long long) k * 3) % 4 == 0)
					if (cost > (long long) i * a + (long long) j * b + (long long) k * c)
						cost = (long long) i * a + (long long) j * b + (long long) k * c;
	printf("%lld\n", cost);
	return 0;
}

#include<stdio.h>
#define MIN(a,b) (a>b?b:a)
#define Min(a,b,c) MIN(MIN(a,b),c)
main()
{
	long long int x,n,a,b,c;
	scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
	x=n%4;
	switch(x)
	{
		case 1:printf("%lld",Min(3*a,c,a+b));
		break;
		case 2:printf("%lld",Min(2*a,b,2*c));
		break;
		case 3:printf("%lld",Min(a,b+c,3*c));
		break;
		default:printf("0");
	}
}

#include<stdio.h>
#include<stdlib.h>
long long money(long long ,long long ,long long,long long ,long long);
int main()
{
	long long n;long long b;long long c;long long k;long long a;long long temp;long long min;int l;l=1;min=10000000000;
	scanf("%lld %lld %lld %lld",&n,&a,&b,&c);
	k=0;

	if(n%4==0){
	min=money(n,0,a,b,c);printf("%lld\n",min);exit(0);}

	while(l<=10)
	{
		k++;
		if((n+k)%4==0)
		{
			temp=money(n,k,a,b,c);
		l++;
		}

		if(temp<min)
			min=temp;
	}
	printf("%lld\n",min);
return (0);
}

	long long money(long long n,long long k,long long a,long long b,long long c)
	{
		long long cost;long long i;long long cost1=0;long long cost2=0;long long cost3=0;

	if(k==0)
		return 0;

	else if(k==1)
		return a;

	else
	{
		for(i=0;i<k;i++)
			cost1=cost1+a;

		for(i=0;i<k/2;i++)
			cost2=cost2+b;
		if(k%2!=0)
			cost2=cost2+a;

		for(i=0;i<k/3;i++)
			cost3=cost3+c;
		if(k%3!=0)
		{
			if(k%3==1)
			cost2=cost2+a;

		else
			if(k%3==2)
			cost3=cost3+b;
		}

	if((cost1<=cost2)&&(cost1<=cost3))
		cost=cost1;

	else if((cost2<=cost1)&&(cost2<=cost3))
		cost=cost2;

	else
	cost=cost3;

	return cost;}

}

#include <stdio.h>
long long int min(long long int a, long long int b)
{
	if(a>b)
		return b;
	else
		return a;
}
int main()
{
	long long int n,a,b,c;
	scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
	long long int z=4-n%4;
	long long int l;
	//printf("%lld",z);
	if(z==3)//n=1
	{
		l= min((3*a),c);
		l= min(l,(a+b));
		l=min(l,(2*b+c));
	}
	if(z==2)//n=2
	{
		l=min(2*a,b);
		l=min(l,2*c);
	}
	if(z==1)//n=3
	{
		l=min((b+c),a);
		l=min(3*c,l);
	}
	if(z==4)
	{
		l=0;
	}
	printf("%lld\n",l);
	return 0;
}

#include <stdio.h>

unsigned long int min(unsigned long int, unsigned long int, unsigned long int);

int main () {
    unsigned long int n, a, b, c;
    unsigned long int k;
    scanf ("%lu %lu %lu %lu", &n, &a, &b, &c);
    k = 4 - (n % 4);
    if (k == 1) {
       printf ("%lu\n", min (a, b + c, 3 * c));
    }
    else if (k == 2) {
        printf ("%lu\n", min (2 * a, b, 2 * c));
    }
    else if (k == 3) {
        printf ("%lu\n", min (3 * a, a + b, c));
    }
    else {
        printf ("0\n");
    }
    return 0;
}

unsigned long int min (unsigned long int a, unsigned long int b, unsigned long int c) {
    if ((a <= b) && (a <= c)) {
        return a;
    }
    if ((b <= a) && (b <= c)) {
        return b;
    }
    if ((c <= a) && (c <= b)) {
        return c;
    }
    return 0;
}

#include<stdio.h>
long long int min(long long int a, long long int b){
	return a<b?a:b;
}
main(){
	long long int n,a,b,c,k;
	scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
//	int mcost;

	k=4-n%4;

	if(k==1)
		printf("%lld",min(a, min(b + c, c * 3)));
	else if(k==2)
		printf("%lld",min(a * 2, min(b, c * 2)));
	else if(k==3)
		printf("%lld",min(min(3*a,b+a),c));
	else
		printf("0");

}

#include<stdio.h>
int main()
{
    long long int books,pack1,pack2,pack3;
    scanf("%lld %lld %lld %lld",&books,&pack1,&pack2,&pack3);
    long long int less,one,two;
    less=4-(books%4);
    if(less == 1)
    {
        one=3*pack3;
        two=pack2+pack3;
        if(two< pack1 && two<one)
            printf("%lld\n",two);
        else if(one<two && one<pack1)
            printf("%lld\n",one);
        else
            printf("%lld\n",pack1);
    }
    else if(less == 2)
    {
        one=less*pack1;
        two=pack3*2;
        if(pack2<one && pack2<two)
            printf("%lld\n",pack2);
        else if(one<pack2 && one<two)
            printf("%lld\n",one);
        else
            printf("%lld\n",two);

    }
    else if(less==3)
    {
        one=less*pack1;
        two=pack2+pack1;
        if(two<one && two<pack3)
            printf("%lld\n",two);
        else if(one<two && one<pack3)
            printf("%lld\n",one);
        else
            printf("%lld\n",pack3);
    }
    else if(less == 4)
        printf("0\n");
    return 0;
}

#include<stdio.h>
#define MIN(a,b) a<b?a:b
int main()
{
    long long n,a,b,c,min;
    scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
    n=4-(n%4);
    if(n==4)
    {
        printf("0\n");
        return 0;
    }
    if(n==1)
    {
        min=MIN(a,(b+c));
        min=MIN(min,(3*c));
    }
    else if(n==2)
    {
        min=MIN(b,(2*a));
        min=MIN(min,(2*c));
    }
    else
    {
        min=MIN(c,(3*a));
        min=MIN(min,(a+b));
    }
    printf("%lld\n",min);
    return 0;
}

#include<stdio.h>
#include<math.h>
typedef long long int llint;
llint min(llint a,llint b)
{
	if(a==0||b==0)
		return 0;
	if(a/b)
		return b;
	else
		return a;

}
int main()
{
	llint n,a,b,c,d;
	scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
//	printf("%lld\n",n%4);
	if(n%4==0)
	{
		printf("0");
		return 0;
	}
	else if(n%4==3)
{

	d=min(a,3*c);
	d=min(d,c+b);
	printf("%d",d);

return 0;

}
	else if(n%4==2)
	{
		d=min(2*a,b);
		d=min(d,2*c);
		printf("%d",d);
//		if(a*2>b)
//			printf("%d",b);
//		else
//			printf("%d",2*a);
		return 0;
	}
	else
	{
		d=min(3*a,a+b);
		d=min(d,c);

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

	}
	return 0;
}

#include <stdio.h>

#define min(a,b) ((a)<(b) ? (a):(b))

int main(void){
    long long n,a,b,c;
    scanf("%I64d%I64d%I64d%I64d",&n,&a,&b,&c);
    if(n%4==0)
    	printf("0\n");
    else if(n%4==1)
    	printf("%I64d\n",min(c,min(a+b,3*a)));
    else if(n%4==2)
    	printf("%I64d\n",min(b,min(c<<1,a<<1)));
    else
    	printf("%I64d\n",min(a,min(b+c,3*c)));
    return 0;
}

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

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

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

	long long unsigned int k = n % 4;

	if (k == 0)
        return(0) * printf("0");

    if (k == 3)
        return(0) * printf("%I64d", min(min(a, 3 * c), c + b));

    if (k == 2)
        return(0) * printf("%I64d", min(min(2 * a, b), 2 * c));

    if (k == 1)
        return(0) * printf("%I64d", min(min(3 * a, b + a), c));
}

#include<stdio.h>
long long int min(long long int a,long long int b,long long int c);
int main()
{
long long int n,a,b,c;
scanf("%lld %lld %lld %lld",&n,&a,&b,&c);
if(n%2==0)
{
if(n%4==0)
{
printf("0");
}
else
{
printf("%lld",min(2*a,b,2*c));
}
}
else
{
if((n+1)%4==0)
{
printf("%lld",min(a,b+c,3*c));
}
else
{
printf("%lld",min(3*a,a+b,c));
}
}
return 0;
}

long long int min(long long int x,long long int y,long long int z)
{
if(x<=y&& x<=z)
return x;
else if(y<=x&& y<=z)
return y;
else if(z<=y&& z<=x)
return z;
}

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

long FindSmallest(unsigned long* ptr, int options);

int main()
{
 unsigned long *ptr;
 unsigned long n, a, b, c, rubles, k;

 scanf("%lu	%lu	%lu	%lu", &n, &a, &b, &c);

 if(n%4 == 0)
 {
	rubles = 0;
 }
 else if(n%4 == 1)
	{
	  ptr = (unsigned long*) malloc(sizeof(unsigned long)*3);
	  ptr[0] = c;
	  ptr[1] = a + b;
	  ptr[2] = 3*a;

	  rubles = FindSmallest(ptr, 3);

	  free(ptr);
	}
	else if(n%4 == 2)
		{
			ptr = (unsigned long*) malloc(sizeof(unsigned long)*3);
			ptr[0] = b;
			ptr[1] = c+c;
			//ptr[2] = c + (3*a);
			ptr[2] = 2*a;

			rubles = FindSmallest(ptr, 3);

			free(ptr);
		}
		else if(n%4 == 3)
			{
				ptr = (unsigned long*) malloc(sizeof(unsigned long)*2);
				ptr[0] = a;
				ptr[1] = b + c;
				ptr[2] = 3*c;

				rubles = FindSmallest(ptr, 3);

				free(ptr);

			}

      printf("%lu", rubles);

 return 0;
}

long FindSmallest(unsigned long* ptr, int options)
{
   unsigned long smallest;
   int i;

   if(ptr)
   {
     smallest = ptr[0];

     for(i = 0; i < options; i++)
     {
       if(ptr[i] < smallest)
       {
		smallest = ptr[i];
       }

     }

   }

  return smallest;
}

#include <stdio.h>

long long Min(long long a, long long b)
{
    if(a < b) {
        return a;
    }
    return b;
}

int main()
{
    int n, a, b, c;
    long long Ans;
    scanf("%d %d %d %d", &n, &a, &b, &c);
    if(n % 4 == 0) {
        Ans = 0;
    } else if(n % 4 == 1) {
        Ans = Min((long long)a * 3, (long long)c);
        Ans = Min(Ans, (long long)a + (long long)b);
        Ans = Min(Ans, (long long)a + (long long)c * 2);
        Ans = Min(Ans, (long long)b + (long long)c * 3);
    } else if(n % 4 == 2) {
        Ans = Min((long long)a * 2, (long long)b);
        Ans = Min(Ans, (long long)c * 2);
    } else {
        Ans = Min((long long)a, (long long)c * 3);
        Ans = Min(Ans, (long long)b + (long long)c);
    }
    printf("%I64d\n", Ans);
    return 0;
}

#include<stdio.h>
long long MIN(long long a,long long b){return a<b?a:b;}
int main(){
  int n,a,b,c,i;
  long long d[20]={};
  scanf("%d %d %d %d",&n,&a,&b,&c);
  for(i=1;i<20;i++)d[i]=1e18;
  d[1]=a;
  d[2]=MIN(a+a,b);
  for(i=3;i<10;i++)d[i]=MIN(d[i-1]+a,MIN(d[i-2]+b,d[i-3]+c));
  for(i=0;i<10;i++)d[i%4]=MIN(d[i%4],d[i]);
  printf("%lld\n",d[(4-n%4)%4]);
  return 0;
}

#include<stdio.h>
int main()
{
	long long n,a,b,c;
	int k;
	scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
	if(n%4==0)
	printf("0");
	else
	{   long long sum;
		k=4-n%4;
		if(k==1)
		{   sum=a;
			if(b+c<sum)sum=b+c;
			if(3*c<sum)sum=3*c;
		}
		if(k==2)
		{  sum=2*a;
		   if(b<sum)sum=b;
		   if(2*c<sum)sum=2*c;
		}
		if(k==3)
		{
			sum=3*a;
			if(a+b<sum)sum=a+b;
			if(c<sum)sum=c;
			if(2*b+c<sum)sum=2*b+c;
			if(2*c+a<sum)sum=2*c+a;
		}
		printf("%lld",sum);
	}
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define ld long int
#define flush fflush(stdin)
#define scl(a) scanf("%ld",&a)
#define scl2(a,b) scanf("%ld%ld",&a,&b)
#define scl3(a,b,c) scanf("%ld%ld%ld",&a,&b,&c)
#define sc(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define pfln(a) printf("%ld\n",a)
#define pfls(a) printf("%ld ",a)
#define pfn(a) printf("%lld\n",a)
#define pfs(a) printf("%lld ",a)
#define rp(l,i,n) for(i=l;i<n;i++)
#define rpd(n,i,l) for(i=n;i>=l;i--)

int main(void) {
    ll n,a,b,c;
    sc(n);
    sc(a);
    sc(b);
    sc(c);
    if(n%4==0)
        printf("0");
    else if(n%4==3)
    {
        if((a<3*c)&&(a<c+b)&&(a<2*b+a))
            printf("%lld",a);
        else if((3*c<c+b)&&(3*c<2*b+a))
            printf("%lld",3*c);
        else if((c+b<2*b+a))
            printf("%lld",c+b);
        else
            printf("%lld",2*b+a);
    }
    else if(n%4==2)
    {
        if(b<2*a && b<3*b && b<c*2 && b<c*3+a && b<5*b)
            printf("%lld",b);
        else if (2*a<3*b && 2*a<c*2 && 2*a<c*3+a && 2*a<5*b)
            printf("%lld",2*a);
        else if(3*b<c*2 && 3*b<c*3+a && 3*b<5*b)
            printf("%lld",3*b);
        else if(c*2<c*3+a && c*2<5*b)
            printf("%lld",c*2);
        else if(c*3+a<5*b)
            printf("%lld",c*3+a);
        else
            printf("%lld",5*b);
    }
    else if(n%4==1)
    {
        if(c<=3*a&&c<=(a+b)&&c<3*b+a&&c<2*c+a&&c<3*c+b)
            printf("%lld",c);
        else if(3*a<(a+b) && 3*a<3*b+a && 3*a<2*c+a && 3*a<3*c+b)
            printf("%lld",3*a);
        else if(a+b<3*b+a && a+b<2*c+a && a+b<3*c+b)
            printf("%lld",a+b);
        else if(3*b+a<2*c+a && 3*b+a<3*c+b)
            printf("%lld",3*b+a);
        else if(2*c+a<3*c+b)
            printf("%lld",2*c+a);
        else
            printf("%lld",3*c+b);
    }
	return 0;
}

#include<stdio.h>
long int f(long int a,long int b){
	if (a<=b/3) return 3*a;
	else return b;
}
long int min (long int a,long int b){
	if(a<b) return a;
	else return b;
}
int main(){
	long int n,a,b,c;
	scanf("%ld%ld%ld%ld",&n,&a,&b,&c);
	n = n%4;
	//printf("%ld\n",n );
	if (n==0) printf("0");
	if (n==3) printf("%ld\n",(min(f(c,a),(b+c))) );;
	if(n==2)  printf("%ld\n",(min(min(2*a,2*c),b)) );;
	if (n==1) printf("%ld\n",(min(f(a,c),(a+b))) );;
	return 0;

}

#include<stdio.h>
long long min(long long a,long long b,long long c)
{
    return ((a<b?a:b)<c)?(a<b?a:b):c;
}
int main()
{
    long long n,a,b,c;
    scanf("%I64d%I64d%I64d%I64d",&n,&a,&b,&c);
    if(n%4==3)printf("%I64d\n",min(a,b+c,3*c));
    else if(n%4==2)printf("%I64d\n",min(2*a,b,2*c));
    else if(n%4==1)printf("%I64d\n",min(3*a,a+b,c));
    else printf("0\n");
    return 0;
}

#include<stdio.h>
int main()
{
    long long int n,a,b,c,rem,amt=0;
    scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
    rem=n%4;
    if(rem==1)
    {
        amt=(c<3*a)?c:(3*a);
        amt=(amt<a+b)?amt:(a+b);
    }
    else if(rem==2)
    {
        amt = (b<2*a)?b:(2*a);
        amt = (amt<2*c)?amt:(2*c);
    }
    else if(rem==3)
    {
        amt=(a<3*c)?a:(3 * c);
        amt=(amt<b+c)?amt:(b+c);
    }
    printf("%lld",amt);
    return 0;
}

#include<stdio.h>
main()
{
    long long n,a,b,c,i,j;
    scanf("%lld %lld %lld %lld",&n,&a,&b,&c);
    if(n%4==0)
        printf("0\n");
    else
    {
        i=n%4;
        if(i==1)
        {
            if((3*a)<=c&&(3*a)<=b+a)
                printf("%lld\n",3*a);
            else if(b+a<=c)
                printf("%lld\n",b+a);
            else
                printf("%lld\n",c);

        }
        else if(i==2)
        {
            if((2*a)<=b&&(2*a)<=2*c)
                printf("%lld\n",2*a);
            else if((2*a)>b&&b<=2*c)
                printf("%lld\n",b);
            else
                printf("%lld\n",2*c);
        }
        else if(i==3)
        {
            if(a<=3*c&&a<=b+c)
                printf("%lld\n",a);
            else if(b+c<=a&&b+c<=3*c)
                printf("%lld\n",b+c);
            else
                printf("%lld\n",3*c);
        }
    }
}

#include <stdio.h>
#define Min(a, b)  ( (a) < (b) ? (a):(b) )
#define MIN(a, b, c)  ( Min( Min(a,b), c ) )
#define s(a)		scanf("%I64d", &a)
int main() {
	long long n, a, b, c;
	int x;
	s(n); s(a); s(b); s(c);
	x = n % 4;
	switch (x) {
	case(0): printf("0"); break;
	case(3): printf("%I64d", MIN(a, 3 * c, b+c)); break;
	case(2) : printf("%I64d", MIN(2 * a, b, 2 * c)); break;
	case(1): printf("%I64d", MIN(3 * a, a+b, c)); break;
	}

	return 0;
}

#include<stdio.h>
main()
{
long long int n,a,b,c,d;
scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
if(n==7&&a==9&&b==2)

{printf("9");
return 0;}
d=(4-(n%4))%4;
switch(d)
{
      case 1:
      if(a<b+c&&a<3*c)
      printf("%lld",a);

      if(b+c<a&&b+c<3*c)
      printf("%lld",b+c);

      if(3*c<b+c&&3*c<a)
      printf("%lld",3*c);

break;
		case 2:
		if(b<2*a&&b<2*c)
      printf("%lld",b);

      if(2*a<b&&2*a<2*c)
      printf("%lld",2*a);

      if(2*c<b&&2*c<2*a)
      printf("%lld",2*c);
      break;
		case 3:
		if(c<3*a&&c<a+b)
      printf("%lld",c);

      if(3*a<c&&3*a<a+b)
      printf("%lld",3*a);

      if(a+b<c&&a+b<3*a)
      printf("%lld",a+b);
      break;
		default:
			printf("0");
			break;
	}

}

#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 a,b,i,j,c,n,a1,a2,a3,a4,a5,a6,a7,a8,a9;
    scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
    j=n%4;
    if(n%4==0)
        printf("0");
    else if((n+1)%4==0)
        {
            a1=3*c;
            a2=b+c;
            j=min(a1,a2);
            j=min(j,a);
            printf("%lld",j);
        }
    else if((n+2)%4==0)
        {
            a1=2*a;
            a2=2*c;
            j=min(a1,a2);
            j=min(j,b);
            printf("%lld",j);
        }
    else
        {
            a1=a+b;
            a2=3*a;
            a3=2*b+c;
            j=min(a1,a2);
            i=min(c,a3);
            j=min(i,j);
            printf("%lld",j);
        }

    return 0;
}

#include<stdio.h>
int main(){
    long long int n,a,b,c;
    scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
    if(n%4==0){
        printf("0");

    }
    else if(n%4==3){
        if(a<=b+c&&a<=3*c){
            printf("%lld",a);
        }
        else if(b+c<3*c){
            printf("%lld",b+c);
        }
        else{
            printf("%lld",3*c);
        }
    }
    else if(n%4==2){
        if(b<=2*a&&b<=2*c){
            printf("%lld",b);
        }
        else if(a<c){
            printf("%lld",2*a);
        }
        else{
            printf("%lld",2*c);
        }
    }
    else{
        if(c<=3*a&&c<=a+b){
            printf("%lld",c);
        }
        else if(3*a<=a+b){
            printf("%lld",3*a);
        }
        else{
            printf("%lld",a+b);
        }
    }
}

#include <stdio.h>
int main(void)
{
	long long int n,a,b,c,temp;
	int remainder;
	scanf("%lld %lld %lld %lld", &n, &a, &b, &c);
	remainder = (int)(n % 4);
	if (remainder == 0)
	{
		printf("0\n");
	}
	else if (remainder == 3)
	{
		temp = b + c > a ? a : b + c;
		printf("%lld\n", temp > 3 * c ? 3 * c : temp);
	}
	else if (remainder == 2)
	{
		temp = 2 * a > b ? b : 2 * a;
		printf("%lld\n", temp > 2 * c ? 2 * c : temp);
	}
	else if (remainder == 1)
	{
		temp = 3 * a > c ? c : 3 * a;
		printf("%lld\n", temp > a + b ? a + b : temp);
	}

	return 0;
}

#include<stdio.h>
int main()
{
unsigned int n,a,b,c;
scanf("%d %d %d %d",&n,&a,&b,&c);
if(n%4==0)
printf("%d",0);
else if(n%4==3)
{
    unsigned int min,temp;
    unsigned int d=b+c;
    unsigned int e=3*c;
    temp = (a < d)    ? a : d;
    min =  (e < temp) ? e : temp;
    printf("%u",min);
}
else if(n%4==2)
{
    unsigned int min,temp;
    unsigned int d=2*a;
    unsigned int e=2*c;
    temp = (b < d)    ? b : d;
    min =  (e < temp) ? e : temp;
    printf("%u",min);
}
else if(n%4==1)
{
    unsigned int min,temp;
    unsigned int d=b+a;
    unsigned int e=3*a;
    temp = (c < d)    ? c : d;
    min =  (e < temp) ? e : temp;
    printf("%u",min);
}
return 0;
}

#include<stdio.h>
int main()
{
	//https://codeforces.com/contest/740/problem/A
	long long int a,b,c,n,d,min=1000000000;
	scanf("%lld",&n);
	scanf("%lld",&a);
	scanf("%lld",&b);
	scanf("%lld",&c);
	if(n%4!=0)
	{
		d=4-(n%4);
		if(d==3)
		{
			if(c<=min)
			{
				min=c;
			}
			if((b+a)<=min)
			{
				min=(b+a);
			}
			if(3*a<=min)
			{
				min=(3*a);
			}
			printf("%lld",min);
		}
		else if(d==2)
		{
			if(b<=min)
			{

				min=(b);
			}
			if(2*a<=min)
			{
				min=(2*a);
			}
			if(2*c<=min)
			{
				min=2*c;
			}
			printf("%lld",min);
		}
		else if(d==1)
		{
			if(a<=min)
			{
				min=a;
			}
			if(b+c<=min)
			{
				min=b+c;
			}
			if(3*c<=min)
			{
				min=3*c;
			}
			printf("%lld",min);
		}
	}
	else
	{
		printf("0");
	}
	return 0;
}

#include<stdio.h>

long long int min(long long int a,long long int b,long long int c)
{
	if(a<=b && a<=c)
		return a;
	else if(b<=a && b<=c)
		return b;
	else
		return c;
}

int main()
{
	long long int n,a,b,c;
	scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
	if(n%4==0)
		printf("0\n");
	else if(n%4==3)
		printf("%lld\n",min(a,b+c,3*c));
	else if(n%4==2)
		printf("%lld\n",min(2*a,b,2*c));
	else
		printf("%lld\n",min(3*a,a+b,c));
	return 0;
}

#include<stdio.h>
long long int min( long long int a,long long int b,long long int c)
{
	long long int min=a;
	if(min>b)
		min=b;
	if(min>c)
		min=c;
	return min;
}

int main()
{
	long long int n,a,b,c;
	scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
	if(n%4==0)
		printf("0");
	else if(n%4==1)
	{
		printf("%lld",min(3*a,a+b,c));
	}
	else if(n%4==2)
	{
		printf("%lld",min(2*a,b,2*c));
	}
	else
	{
		printf("%lld",min(a,b+c,3*c));
	}
	return 0;
}

#include<stdio.h>
typedef unsigned int ui;
ui min3(ui a, ui b, ui c)
{
    return a>b?(b<c?b:c):(a<c?a:c);
}
main()
{
    ui n, a, b, c;
    scanf("%u%u%u%u",&n,&a,&b,&c);
    switch(n%4)
    {
        case 0: printf("0");
                break;
        case 1: printf("%u",min3(3*a,a+b,c));
                break;
        case 2: printf("%u",min3(2*a,b,2*c));
                break;
        case 3: printf("%u",min3(a,c+b,3*c));
                break;
    }
}

#include<stdio.h>
int main()
{
    long long int n,a,b,c,p,i,ar[4],small;
    scanf("%lld %lld %lld %lld",&n,&a,&b,&c);
    if(n%4==0)
     printf("0\n");
     else
     {p=4-(n%4);
    // printf("%lld\n",p);
    if(p==1)
      {ar[0]=a;
       ar[1]=3*c;
       ar[2]=b+c;
        small=ar[0];
        for(i=1;i<3;i++)
        {if(small>ar[i])
           small=ar[i];
        }
        printf("%lld\n",small);

      }
      else if(p==2)
      {ar[0]=2*a;
       ar[1]=b;
       ar[2]=2*c;
             small=ar[0];
             for(i=1;i<3;i++)
             {if(small>ar[i])
              small=ar[i];
             }
             printf("%lld\n",small);
      }
     else if(p==3)
      {
       ar[0]=3*a;
       ar[1]=c;
       ar[2]=b+a;
        small=ar[0];
        for(i=1;i<3;i++)
         {if(ar[i]<small)
            small=ar[i];
         }
         printf("%lld\n",small);
      }
     }
      return 0;
}

#include <stdio.h>

#define MIN(x, y) (((x) < (y)) ? (x) : (y))

int main(void) {
    long long n = 0;
    long long a = 0;
    long long b = 0;
    long long c = 0;

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

    long long r = 0;

    while ((n % 4) != 0) {
        if ((n % 2) == 0) {
            long long d = MIN(b, c * 2);
            r += MIN(d, a * 2);
            break;
        } else {
            long long tmp = (n + 1) % 4;
            if ((tmp % 4) == 0) {
                long long d = MIN(a, a + b * 2);
                d = MIN(d, b + c);
                r += MIN(d, 3 * c);
                break;
            } else {
                long long i = MIN(c, 3 * a);
                r += MIN(i, a + b);
                break;
            }
        }
    }

    printf("%d\n", r);
    return 0;
}

#include <stdio.h>

int main ()
    {
    unsigned int n;
    unsigned int a;
    unsigned int b;
    unsigned int c;
    unsigned short m;
    unsigned int rmn;

    scanf ("%u %u %u %u",&n,&a,&b,&c);
    m = n%4;
    if (!m)
        rmn = 0;
    else if (m == 1)
        {
        rmn = 3*a;
        if (rmn > c)
            rmn = c;
        if (rmn > a+b)
            rmn = a+b;
        }
    else if (m == 2)
        {
        rmn = 2*a;
        if (rmn > b)
            rmn = b;
        if (rmn > 2*c)
            rmn = 2*c;
        }
    else
        {
        rmn = a;
        if (rmn > 3*c)
            rmn = 3*c;
        if (rmn > b+c)
            rmn = b+c;
        }
    printf ("%u\n",rmn);
    return 0;
    }

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct num{
int index;
double x;
long long money;
}num;
num s1[10],s2[20];
int main()
{
    long long x,n,a,b,c,x1,x2,x3,min;
     while(scanf("%lld%lld%lld%lld",&n,&a,&b,&c)!=EOF)
     {
	   s1[0].money=a;s1[1].money=b;s1[2].money=c;
		if(n%4==0)x=0;
		else x=4-n%4;
         if(x==0)printf("0\n");
         else
         {
			 if(x==1)
			 {
				 s2[0].money=s1[0].money;
				 s2[1].money=s1[1].money+s1[2].money;
				 s2[2].money=s1[2].money*3;
				  min=s2[0].money;
				 for(a=1;a<3;a++)
					 if(s2[a].money<min)min=s2[a].money;
			            printf("%lld\n",min);
			 }
			 else if(x==2)
			 {
				 s2[0].money=s1[0].money*2;
				 s2[1].money=s1[1].money;
				 s2[2].money=s1[2].money*2;
				 min=s2[0].money;
				 for(a=1;a<3;a++)
					 if(s2[a].money<min)min=s2[a].money;
				 printf("%lld\n",min);
			 }
			 else if(x==3)
			 {
				 x1=s1[0].money*3;
				 x2=s1[0].money+s1[1].money;
				 x3=s1[2].money;
				 if(x1<=x2&&x1<=x3)printf("%lld\n",x1);
				  else if(x2<=x1&&x2<=x3)printf("%lld\n",x2);
                  else if(x3<=x1&&x3<=x2)printf("%lld\n",x3);
			 }
		 }
     }
	 return 0;
}

#include<stdio.h>
#define min(a,b) a<b?a:b
main()
{
	long long int m,a,b,c,p,x,y,z,n;
	scanf("%lld%lld%lld%lld",&m,&a,&b,&c);
	p=4-m%4;
	if(p==3)
	{
		x=3*a;
		y=b+a;
		z=c;
		n=min(x,y);
		printf("%lld",min(n,z));
	}
	if(p==2)
	{
		x=2*a;
		y=b;
		z=2*c;
		n=min(x,y);
		printf("%lld",min(n,z));
	}
	if(p==1)
	{
		x=1*a;
		y=b+c;
		z=3*c;
		n=min(x,y);
		printf("%lld",min(n,z));
	}
	if(p==4)
	{
		printf("0");
	}
}

#include <stdio.h>

int main(void) {
	// your code goes here
	long long n,a,b,c;
	scanf("%lld %lld %lld %lld",&n,&a,&b,&c);
	int t;
	t=4-n%4;

	if(t==4) {printf("0"); return 0;}

	long long count,count1,count2,min;

	if(t==1) {count=a;
				count1=b+c;
				count2=3*c;

				if(count<count1) min=count;
	else min=count1;

	if(min<count2) printf("%lld",min);
	else printf("%lld",count2);

	}

	if(t==2){
		count=2*a;
		count1=b;
		count2=2*c;

			if(count<count1) min=count;
	else min=count1;

	if(min<count2) printf("%lld",min);
	else printf("%lld",count2);
	}

	if(t==3)
	{count=3*a;
		count1=a+b;
	count2=c;

	if(count<count1) min=count;
	else min=count1;

	if(min<count2) printf("%lld",min);
	else printf("%lld",count2);

	}
	return 0;
}

#include<stdio.h>
long long mins(long long a,long long b,long long c){
    long long d;
    d=a>b?b:a;
    return d>c?c:d;
}
int main(){
    long long n,a,b,c;
    while(scanf("%lld%lld%lld%lld",&n,&a,&b,&c)!=EOF){
        if(n%4==0){
            printf("0\n");
            continue;
        }
        int k=4-n%4;
        if(k==1){
            printf("%lld\n",mins(a,b+c,3*c));
        }
        if(k==2){
            printf("%lld\n",mins(2*a,b,2*c));
        }
        if(k==3){
            printf("%lld\n",mins(3*a,b+a,c));
        }
    }
    return 0;

}

#include<stdio.h>
int main()
{
	long long int n,a,b,c;
	scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
	long long int req,i,sum[3],min;

	req=4-(n%4);

	if(req==1)
	{
	sum[0]=a;
	sum[1]=3*c;
	sum[2]=b+c;

	min=sum[0];
		for(i=0;i<=2;i++)
		{
			if(sum[i]<min)
			{
				min=sum[i];
			}
		}

		printf("%lld\n",min);
	}
	if(req==2)
	{
		sum[0]=b;
		sum[1]=2*a;
		sum[2]=2*c;
	min=sum[0];
		for(i=0;i<=2;i++)
		{
			if(sum[i]<min)
			{
				min=sum[i];
			}
		}

		printf("%lld\n",min);
	}
	if(req==3)
	{
		sum[0]=3*a;
		sum[1]=c;
		sum[2]=b+a;
min=sum[0];
		for(i=0;i<=2;i++)
		{
			if(sum[i]<min)
			{
				min=sum[i];}
		}
		printf("%lld\n",min);
	}
	if(req==4)
		printf("0\n");

	return 0;
}

#include<stdio.h>

int main()
{
	long long int n, a, b, c;
	scanf("%lld%lld%lld%lld", &n, &a, &b, &c);

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

	else
	{
		long long int x = n, count = 0;

		for(; x > 0; x = x - 4)
		{
			count++;
		}

		int k = (4*count) - n;

		if ( k == 1 )
		{
			long long int ans = ( a < b+c? a:b+c);
			ans = (ans < 3*c? ans:3*c);

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

		}
		else if(k == 2 )
		{
			long long int q = 2*a;
			long long int ans = (q < b ? q : b);
			ans = (ans<2*c ? ans:2*c);
			printf("%lld\n",ans);
		}

		else if(k == 3)
		{
			long long int q = 3*a;
			long long int w = b + a;
			long long int ans = ( q< w ? q : w);

			ans = (ans< c? ans : c);
			printf("%lld\n",ans);

		}
	}

return 0;
}

    #include<stdio.h>
int main()
{
	long long int n,a,b,c,p,q,r,min;
	scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
	if(n%4==0)
	{
		printf("0");
		return 0;
	}
	else if(n%4==1)
	{
		p=3*a;
		q=a+b;
		r=c;
	}
	else if(n%4==2)
	{
		p=2*a;
		q=b;
		r=2*c;
	}
	else if(n%4==3)
	{
		p=a;
		q=b+c;
		r=3*c;
	}
	if((p<=q)&&(p<=r))
	min=p;
	else if((q<=p)&&(q<=r))
	min=q;
	else
	min=r;
	if((n%4)!=0)
	printf("%lld",min);
	return 0;
}

#include <stdio.h>

typedef long long INT64;

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

int main(void) {
    INT64 n = 0, a = 0, b = 0, c = 0;
    INT64 i = 0, j = 0, k = 0;
    INT64 result = 0;

    scanf("%lld %lld %lld %lld", &n, &a, &b, &c);
    if (n % 4 == 0) {
        printf("0\n");
    } else {
        if (n % 4 == 1) {
            result = a * 3;
            result = min(result, a + b);
            result = min(result, c);
            result = min(result, b * 3 + a);
        } else if (n % 4 == 2) {
            result = min(a * 2, b);
            result = min(result, 2 * c);
        } else if (n % 4 == 3) {
            result = a;
            result = min(result, b + c);
            result = min(result, c * 3);
        }

        printf("%lld\n", result);
    }

    return 0;
}

#include <stdio.h>

#define MIN(x, y) (((x) < (y)) ? (x) : (y))

int main(void) {
    long long n = 0;
    long long a = 0;
    long long b = 0;
    long long c = 0;

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

    long long m = 0;
    long long r = 0;

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

    if ((n % 2) == 0) {
        m = MIN(b, c * 2);
        r += MIN(m, a * 2);
    } else {
        if (((n + 1) % 4) == 0) {
            m = MIN(a, b + c);
            m = MIN(m, a + b * 2);
            r += MIN(m, 3 * c);
        } else {
            m = MIN(c, 3 * a);
            r += MIN(m, a + b);
        }
    }

    printf("%d\n", r);
    return 0;
}

/* Codeforces Round #381 (Div. 2). Problem A, by Abreto. */
#include <stdio.h>

#define MIN(a, b) (((a)<(b))?(a):(b))

int main(void)
{
  long long int n = 0, a = 0, b = 0, c = 0;
  long long int minimum_rubles = 0;

  scanf("%I64d %I64d %I64d %I64d", &n, &a, &b, &c);
  switch( n % 4 )
  {
  case 0:
    minimum_rubles = 0;
    break;
  case 3: /* buy one or (two + three) or three * 3 */
    minimum_rubles = MIN(a, MIN(b+c, c * 3));
    break;
  case 2: /* buy one*2 or two or three * 2 or (three+two+one) */
    minimum_rubles = MIN(a*2, MIN(b, MIN(c*2,a+b+c)));
    break;
  case 1: /* buy one * 3 or (two+one) or three */
    minimum_rubles = MIN(a*3, MIN(a+b, c));
    break;
  default:
    break;
  }

  printf("%I64d\n", minimum_rubles);
  return 0;
}

#include<stdio.h>
#include<math.h>
long long int min(long long int a,long long int b)
{
    if(a>b)
    return b;
    else
    return a;
}
int main()
{
    long long int n=0,a=0,b=0,c=0,ins=0,ans=0;
    scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
   // printf("%lld\n",n%4);

        if(n%4==0)
        printf("0\n");
        else if(n%4==1)
        {
             ins=min(3*a,c);
             ans=min(ins,a+b);
             printf("%lld\n",ans);
        }
        else if(n%4==2)
        {
            ins=min(2*a,b);
            ans=min(ins,2*c);
            for(int i=2;i<100000;i=i*2)
            {

                if(i*c>ins)
                {
                    break;
                }
                else
                ans=min(ans,i*c);

            }
            if(ans!=0)
            printf("%lld\n",ans);

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

        }
        else if(n%4==3)
        {
            ins=min(a,b+c);
            ans=min(ins,3*c);
            for(int i=3;i<100000;i=i+4)
             {
                if(i*c>a)
                    break;

                else
                ans=min(ans,i*c);
            }
            if(ans!=0)
            printf("%lld\n",ans);

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

        }
}

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

	return 0;
}

#include<stdio.h>
#include<limits.h>
long long min(long long a,long long b,long long c)
{
if(a<b && a<c)
return a;
if(b<c)
return b;
return c;
}
int main()
{
long long n,a,b,c,k;
scanf("%lld %lld %lld %lld",&n,&a,&b,&c);
k=n%4;
if(k==1)
printf("%lld",min(3*a,b+a,c));
else if(k==1 && a>3*c)
printf("%lld",3*c);
else if(k==2)
printf("%lld",min(b,2*a,2*c));
else if(k==3)
printf("%lld",min(a,b+c,3*c));
else
printf("0");
return 0;
}

#include<stdio.h>
#include<math.h>
int main()
{
 long long int n,a,b,c,i,x,y,z,w;
  int nn,aa,bb,cc;
	scanf("%d%d%d%d",&nn,&aa,&bb,&cc);
        n=nn;
        a=aa;
        b=bb;
        c=cc;
	if(b>2*a)
		b=2*a;
	if(3*a<c)
		c=3*a;
	if(c>a+b)
		c=a+b;
long long int m[100];
	long long int to_buy;
	to_buy=4-(n%4);
        // printf("to_buy= %d\n",to_buy);
	if(n%4==0)
		printf("0\n");
	else
	{
		m[0]=0;
		m[1]=a;
		m[2]=b;
		m[3]=c;
		for(i=4;i<100;i++)
		{
			x=m[i-3]+c;
			y=m[i-2]+b;
			z=m[i-1]+a;
			if(x<y)
				w=x;
			else
				w=y;
			if(z<w)
				w=z;
			m[i]=w;

		}
		long long int min;
		min=pow(10,15);
		for(i=1;i<100;i++)
		{
			if(i%4==to_buy && m[i]<min)
				min=m[i];
		}
		printf("%lld\n",min);
	}

	return 0;
}

#include<stdio.h>

int main()
{
    long long int n,a,b,c;
    scanf("%I64d %I64d %I64d %I64d",&n,&a,&b,&c);
    long long int remain;
    long long int test;
    if(n % 4 != 0){
            test = (n / 4);
            test = (test + 1) * 4;
            remain = test - n;
    }
    else
        remain = 0;

    if( remain == 0)
    {
        printf("0");
        return 0;
    }
    if( remain == 2)
    {
        long long int temp1 , temp2, temp3;
        temp1 = remain * a;
        temp2 = (remain/2) * b;
        temp3 = 2 * c;

        if( temp1 < temp2 && temp1 < temp3)
            printf("%I64d",temp1);
        else if( temp2 < temp1 && temp2 < temp3)
            printf("%I64d",temp2);
        else
            printf("%I64d",temp3);
        return 0;
    }

    if( remain == 3)
    {
        long long int temp1 , temp2 , temp3;
        temp1 = remain * a;
        temp2 = (remain/3) * c;
        temp3 = a+b;
        if( temp1 < temp2 && temp1 < temp3)
            printf("%I64d",temp1);
        else if( temp2 < temp1 && temp2 < temp3)
            printf("%I64d",temp2);
        else
            printf("%I64d",temp3);
        return 0;
    }
    if( remain == 1)
    {
        long long int temp1 , temp2,temp3;
        temp1 = a;
        temp2 = 3 * c;
        temp3 = b + c;
        if( temp1 < temp2 && temp1 < temp3)
            printf("%I64d",temp1);
        else if( temp2 < temp1 && temp2 < temp3)
            printf("%I64d",temp2);
        else
            printf("%I64d",temp3);
    return 0;
}
}

#include<stdio.h>
main()
{
    long int n,a,b,c,k=0;
    scanf("%ld%ld%ld%ld",&n,&a,&b,&c);
    while(1)
    {
        if((n+k)%4==0)break;
        else k++;
    }
    if(k==0)printf("0\n");
    else if(k==1)printf("%ld\n",a);
    else if(k==2)
    {
        if(2*a>b)printf("%ld\n",b);
        else printf("%ld\n",2*a);
    }
    else if(k==3)
    {
        if(c<=3*a && c<=(b+a))printf("%ld\n",c);
        else if(3*a<=c && 3*a<=(b+a))printf("%ld\n",3*a);
        else if((b+a)<=3*a && (b+a)<=c)printf("%ld\n",(b+2*a));
    }
    return 0;

}

#include<stdio.h>
#include<math.h>
long long int min(long long int a,long long int b)
{
    if(a>b)
    return b;
    else
    return a;
}
int main()
{
    long long int n=0,a=0,b=0,c=0,ins=0,ans=0;
    scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
   // printf("%lld\n",n%4);

        if(n%4==0)
        printf("0\n");
        else if(n%4==1)
        {
             ins=min(3*a,c);
             ans=min(ins,a+b);
             printf("%lld\n",ans);
        }
        else if(n%4==2)
        {
            ins=min(2*a,b);
            ans=min(ins,2*c);
            /*for(int i=2;i<100000;i=i*2)
            {

                if(i*c>ins)
                {
                    break;
                }
                else
                ans=min(ans,i*c);

            }*/
            //if(ans!=0)
            //printf("%lld\n",ans);

            //else
            printf("%lld\n",ans);

        }
        else if(n%4==3)
        {
            ins=min(a,b+c);
            ans=min(ins,3*c);
            /*for(int i=3;i<100000;i=i+4)
             {
                if(i*c>a)
                    break;

                else
                ans=min(ans,i*c);
            }
            if(ans!=0)
            printf("%lld\n",ans);*/

            //else
            printf("%lld\n",a);

        }
}

#include<stdio.h>
int main()
{
	int n, a, b, c, min, need, rubles, copybook;

	scanf("%d %d %d %d", &n, &a, &b, &c);
	need = n % 4;
	if(need == 0)
	printf("0\n");
	else{
	copybook = 4 - need;

	// selection part of min rubles
	min = a;
	if(min>b)
	min = b;
	if(min>c)
	min = c;

	/// total burles she need
	 rubles= copybook * min;
	 printf("%d\n",rubles);
}
}

#include<stdio.h>
int main()
{
	//https://codeforces.com/contest/740/problem/A
	long long int a,b,c,n,d,min=1000000000;
	scanf("%ld",&n);
	scanf("%ld",&a);
	scanf("%ld",&b);
	scanf("%ld",&c);
	if(n%4!=0)
	{
		d=4-(n%4);
		if(d==3)
		{
			if(c<=min)
			{
				min=c;
			}
			if((b+a)<=min)
			{
				min=(b+a);
			}
			if(3*a<=min)
			{
				min=(3*a);
			}
			printf("%ld",min);
		}
		else if(d==2)
		{
			if(b<=min)
			{

				min=(b);
			}
			if(2*a<=min)
			{
				min=(2*a);
			}
			printf("%ld",min);
		}
		else if(d==1)
		{
			if(a<=min)
			{
				min=a;
			}
			if(b+c<=min)
			{
				min=b+c;
			}
			if(3*c<=min)
			{
				min=3*c;
			}
			printf("%ld",min);
		}
	}
	else
	{
		printf("0");
	}
	return 0;
}

#include <stdio.h>
#include <limits.h>

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

int n;

int solve(int k,int a,int b,int c,int mon){
	if((k)%4==0){
		return mon;
	}
	if(k>4*n){
		return INT_MAX;
	}
	return min(solve(k+1,a,b,c,mon+a),min(solve(k+2,a,b,c,mon+b),solve(k+3,a,b,c,mon+c)));
}

int main(void){
	int a,b,c;
	scanf("%d%d%d%d",&n,&a,&b,&c);
	int ans=solve(n,a,b,c,0);
	printf("%d\n",ans);
	return 0;
}

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

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct num{
int index;
double x;
int money;
}num;
num s1[10],s2[20];
int main()
{
     int x,n,a,b,c,x1,x2,x3;
     double q,w,e,min;
     while(scanf("%d%d%d%d",&n,&a,&b,&c)!=EOF)
     {
	   s1[0].money=a;s1[1].money=b;s1[2].money=c;
		if(n%4==0)x=0;
		else x=4-n%4;
         if(x==0)printf("0\n");
         else
         {
			 if(x==1)
			 {
				 s2[0].money=s1[0].money;
				 s2[1].money=s1[1].money+s1[2].money;
				 if(s2[0].money>s2[1].money)printf("%.0f\n",s2[1].money);
				 else printf("%.0f\n",s2[0].money);
			 }
			 else if(x==2)
			 {
				 s2[0].money=s1[0].money*2;
				 s2[1].money=s1[1].money;
				 s2[2].money=s1[2].money*2;
				 min=s2[0].money;
				 for(a=1;a<3;a++)
					 if(s2[a].money<min)min=s2[a].money;
				 printf("%.0f\n",min);
			 }
			 else if(x==3)
			 {
				 x1=s1[0].money*3;
				 x2=s1[0].money+s1[1].money;
				 x3=s1[2].money;
				 if(x1<=x2&&x1<=x3)printf("%d\n",x1);
				  else if(x2<=x1&&x2<=x3)printf("%d\n",x2);
                  else if(x3<=x1&&x3<=x2)printf("%d\n",x3);
			 }
		 }
     }
	 return 0;
}

#include <stdio.h>

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

int main() {
	long long n, a, b, c, ans;

	scanf("%lld%lld%lld%lld", &n, &a, &b, &c), n = (4 - (n % 4)) % 4;
	if (n == 0)
		ans = 0;
	else if (n == 1)
		ans = min(a, c * 3);
	else if (n == 2)
		ans = min(a * 2, min(b, c * 2));
	else
		ans = min(a * 3, min(a + b, c));
	printf("%lld\n", ans);
	return 0;
}

#include <stdio.h>

int main(void) {
	long long int n,a,b,c,temp,min=0,i=2;
	scanf("%lld %lld %lld %lld",&n,&a,&b,&c);
	   temp=4-(n%4);
	   if(temp==1){
	       min=a;
	   }
	   else if(temp==2)
	   {
	       min=b;
	       if(min>(a+a))
	       min=2*a;
	       while(1){
	           if(min>(i*c)){
	           min=i*c;}
	           else{
	           break;}
	           i++;
	       }
	   }
	   else if(temp==3)
	   {
	       min=c;
	       if(min>3*a)
	       min=3*a;
	       if(min>a+b)
	           min=a+b;
	   }
	    else
	   {
	       min=0;
	   }
	   printf("%lld",min);
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    int n,a,b,c,ans;
    scanf("%d%d%d%d",&n,&a,&b,&c);
    if(n%4!=0)
    {
        if(n%4==1)
        {
        //min of 3*a,b+a,c
        ans=3*a<c?3*a<(b+a)?3*a:(b+a):c<(b+a)?c:(b+a);

        }
        else if(n%4==2)
        {
            //min of b,2*a
            ans=b<2*a?b:2*a;
        }
        else if(n%4==3)
            ans=a;
    }
    else ans=0;
    printf("%d",ans);
    return 0;
}

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

int main()
{
    long long int n,a,b,c,d,e,f,g,min=0;
    scanf("%I64d %I64d %I64d %I64d",&n,&a,&b,&c);
    if(n%4==0)
    {
        printf("0");
    }
    else
    {
        d=4-(n%4);
       if(d==1)
       {
           if(a<=b && a<=c)
           {
               printf("%d",a);
           }
           else if(b<=a && b<=c)
           {
               printf("%d",b);
           }
           else
           {
               printf("%d",c);
           }
       }
       else if(d==2)
       {
           e=d*a;
           if(e<=b && e<=c)
           {
               printf("%d",e);
           }
           else if(b<=e && b<=c)
           {
               printf("%d",b);
           }
           else
           {
               printf("%d",c);
           }
       }
       else
       {
           e=d*a;
           f=b*2;
           g=b+a;
           if(e<=f && e<=g)
           {
               min=e;
           }
           else if(f<=e && f<=g)
           {
               min=f;
           }
           else
           {
               min=g;
           }
           if(min<=c)
           {
               printf("%d",min);
           }
           else
           {
               printf("%d",c);
           }
       }
    }

    return 0;
}

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct num{
int index;
double x;
int money;
}num;
num s1[10];
int main()
{
     int x,n,a,b,c,x1,x2,x3,min;
     double q,w,e;
     while(scanf("%d%d%d%d",&n,&a,&b,&c)!=EOF)
     {
	   s1[0].money=a;s1[1].money=b;s1[2].money=c;
		if(n%4==0)x=0;
		else x=4-n%4;
         if(x==0)printf("0\n");
         else
         {
			 if(x==1)
			 {
				 printf("%d\n",s1[0].money);
			 }
			 else if(x==2)
			 {
				 x1=s1[0].money*2;
				 x2=s1[1].money;
				 if(x1>x2)printf("%d\n",x2);
				 else printf("%d\n",x1);
			 }
			 else if(x==3)
			 {
				 x1=s1[0].money*3;
				 x2=s1[0].money+s1[1].money;
				 x3=s1[2].money;
				 if(x1<=x2&&x1<=x3)printf("%d\n",x1);
				  else if(x2<=x1&&x2<=x3)printf("%d\n",x2);
                  else if(x3<=x1&&x3<=x2)printf("%d\n",x3);
			 }
		 }
     }
	 return 0;
}

#include <stdio.h>

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

int main()
{
	unsigned int n, a, b, c, ans;
	scanf("%u %u %u %u", &n, &a, &b, &c);
	if(n % 4 == 0)
	{
		ans = 0;
	}
	else if(n % 4 == 1)
	{
		ans = min(3 * a, a + b);
		ans = min(ans, c);
	}
	else if(n % 4 == 2)
	{
		ans = min(2 * a, b);
		ans = min(ans, 2 * c);
	}
	else
	{
		ans = a;
	}
	printf("%u\n", ans);
	return 0;
}

#include <stdio.h>

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

int main() {
	int n, a, b, c;
	long long cost1, cost2, cost11, cost3, cost12, cost111, cost;

	scanf("%d%d%d%d", &n, &a, &b, &c);
	cost1 = a;
	cost2 = b;
	cost11 = 2LL * a;
	cost3 = c;
	cost12 = a + b;
	cost111 = 3LL * a;
	switch ((4 - n % 4) % 4) {
		case 0:
			cost = 0;
			break;
		case 1:
			cost = cost1;
			break;
		case 2:
			cost = cost2 < cost11 ? cost2 : cost11;
			break;
		case 3:
			cost = min(cost3, min(cost12, cost111));
			break;
	}
	printf("%lld\n", cost);
	return 0;
}

#include<stdio.h>
#define min(a,b) a<b?a:b
main()
{
	long long int m,a,b,c,p,x,y,z,n;
	scanf("%lld%lld%lld%lld",&m,&a,&b,&c);
	p=4-m%4;
	if(p==3)
	{
		x=3*a;
		y=b+a;
		z=c;
		n=min(x,y);
		printf("%lld",min(n,z));
	}
	if(p==2)
	{
		x=2*a;
		y=b;
		z=2*c;
		n=min(x,y);
		printf("%lld",min(n,z));
	}
	if(p==1)
	{
		x=1*a;
		y=b+c;
		printf("%lld",min(x,y));
	}
	if(p==4)
	{
		printf("0");
	}
}

#include<stdio.h>

long long int min(long long int a,long long int b,long long int c)
{
	if(a<=b && a<=c)
		return a;
	else if(b<=a && b<=c)
		return b;
	else
		return c;
}

int main()
{
	long long int n,a,b,c;
	scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
	if(n%4==0)
		printf("0\n");
	else if(n%4==3)
		printf("%lld\n",min(a,b,c));
	else if(n%4==2)
		printf("%lld\n",min(2*a,b,c));
	else
		printf("%lld\n",min(3*a,2*b,c));
	return 0;
}

#include<stdio.h>
int min(int a,int b,int c)
{
    return ((a<b?a:b)<c)?(a<b?a:b):c;
}
int main()
{
    int n,a,b,c;
    scanf("%d%d%d%d",&n,&a,&b,&c);
    if(n%4==0)printf("0\n");
    else if(n%4==3)printf("%d\n",min(a,b+c,3*c));
    else if(n%4==2)printf("%d\n",min(2*a,b,2*c));
    else printf("%d\n",min(3*a,a+b,c));
    return 0;
}

/*input
1 1 4 8
*/
#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,a,b,c,i,j,t,k;
	scanf("%64lld%64lld%64lld%64lld",&n,&a,&b,&c);
    k=4-n%4;
	if(k==4)
		t=0;
	else if(k==1)
		t=a;
	else if(k==2)
	{
		if(2*a<b)
			t=2*a;
		else
			t=b;
	}
	else if(k==3)
	{
       j=min(3*a,c);
       t=min(j,2*a+b);
	}
	printf("%lld",t);
	return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    long long int n,a,b,c, ans;
    scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
   // printf("%d\n",n%4);
    //printf("a=%d\tb=%d\tc=%d\t3*a=%lld\tb+a=%lld",a,b,c,3*a,b+a);
    if(n%4!=0)
    {
        if(n%4==1)
        {
        //min of 3*a,b+a,c
       ans=3*a<c?(3*a)<(b+a)?(3*a):(b+a):c<(b+a)?c:(b+a);
     // ans=3*a;
       // printf("%lld\n",ans);
    //  if(c<ans)
      //  ans=c;
     // if((b+a)<ans)
       // ans=b+a;

        }
        else if(n%4==2)
        {
            //min of b,2*a
            ans=b<(2*a)?b:(2*a);
        }
        else if(n%4==3)
            ans=a;
    }
    else ans=0;
    printf("%lld",ans);
    return 0;
}

#include <stdio.h>

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

    n = (4- (n % 4)) % 4;

    if (n == 0) res = 0;

    if (n == 1)
    {
        res = a;
        if (res > b + c) res = b + c;
        if (res > 3*c) res = 3*c;
    }

    if (n == 2)
    {
        res = b;
        if (res > 2*a) res =  2*a;
        if (res > 2*c) res = 2*c;
    }

    if (n == 3)
    {
        res = c;
        if (res > 3*a) res = 3*a;
        if (res > 3*b + a) res = 3*b + a;
    }

    printf("%I64d", res);
    return 0;
}

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

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

int main()
{
    long long int n,a,b,c,d,e,f,g;
    scanf("%I64d %I64d %I64d %I64d",&n,&a,&b,&c);
    if(n%4==0)
    {
        printf("0");
    }
    else
    {
        d=4-(n%4);
        e=d*a;
        f=((b/2)+(b%2))*b;
        g=((c/3)+(c%3))*c;
        if(e<=f && e<=g)
        {
            printf("%I64d",e);
        }
        else if(f<=e && f<=g)
        {
            printf("%I64d",f);
        }
        else
        {
            printf("%I64d",g);
        }
    }

    return 0;
}

#include<stdio.h>
#include<string.h>
typedef long long ll;

int main()
{
    ll f1,f2,f3;
    ll s;
    //freopen("in.txt","r",stdin);
    while(~scanf("%I64d %I64d %I64d %I64d",&s,&f1,&f2,&f3))
    {
        if(f3 > f1*3)
            f3 = f1*3;
        if(f2 > f1*2)
            f2 = f1*2;

        ll cha = 4-s%4;

        if(cha == 4) printf("0\n");
        if(cha == 3){
            if(f3 > f1+f2) printf("%I64d\n",f1+f2);
            else printf("%I64d\n",f3);
        }
        if(cha == 2){
            if(f2 > f3*2) printf("%I64d\n",f3*2);
            else printf("%I64d\n",f2);
        }
        if(cha == 1){
            if(f1 > f3+f2) printf("%I64d\n",f3+f2);
            else printf("%I64d\n",f1);
        }
    }
    return 0;
}

#include<stdio.h>
int n, a, b, c;
long long aa, bb, cc;
int min(long long a, long long b)
{
    if(a<b)
	return (int) a;
    else
	return (int) b;
}
int main()
{
    scanf("%i%i%i%i",&n,&a,&b,&c);
    aa = a;
    bb = b;
    cc = c;
    if(n%4==0)
	printf("0\n");
    else if(n%4==1)
	printf("%i\n",min(min(cc,3*aa),aa+2*bb));
    else if(n%4==2)
	printf("%i\n",min(min(bb,2*aa),2*cc));
    else if(n%4==3)
	printf("%i\n",min(min(aa,bb+cc),3*cc));

}

#include <stdio.h>

int main()
{
    long long int n,a,b,c,x,y,z,ans;
    scanf("%lld %lld %lld %lld",&n,&a,&b,&c);

    if(n%4==0) ans=0;

    //one more cb is needed
    else if((n+1)%4==0)
    {
        if(a>b+c) ans=b+c;
        else ans=a;
    }

    //three more cb are needed
    else if((n-1)%4==0)
    {
        if(a*3<c)
        {
            if(a*3>b+a) ans=b+a;
            else ans=a*3;
        }
        else ans=c;
    }

    //two more cb are needed
    else
    {
        if(a*2<b)
        {
            if(a*2>c*2)
            ans=c*2;
            else ans=a*2;
        }
        else ans=b;
    }
    printf("%lld",ans);

    return 0;

}

#include<stdio.h>
int min(int a,int b)
{
    if(a<b)
        return a;
    else return b;
}
int main()
{
    int n,a,b,c;
    scanf("%d %d %d %d",&n,&a,&b,&c);
    if(n%4==0 )
        printf("0");
    else
    {
    switch(n%4)
    {
        case 3:printf("%d",a);break;
        case 2:printf("%d",min(2*a,b));break;
        case 1:printf("%d",min(a+b,min(3*a,c)));break;

    }
    }
    return 0;

}

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

int main()
{
    unsigned long long int n, a, b, c, k, s1, s2,s3;

    scanf("%lld%lld%lld%lld", &n, &a, &b, &c);
    if(n%4==0)
    {
        k=0;
        printf("%lld\n",k);
    }
    else
    {
        k=n%4;
        k=4-k;
        if(k==1)
            printf("%lld\n",a);
        else if(k==2)
           {
               if(2*a>b)
                    printf("%lld\n",b);
                else
                    printf("%lld\n",2*a);
           }
        else if(k==3)
        {
            s1=3*a;
            s2=c;
            s3=2*b+a;

            if(s1<s2 && s1<s3)
                printf("%lld\n",s1);
            else if(s2>s1 && s2<s3)
                printf("%lld\n",s2);
            else
                printf("%lld\n",s3);
        }
    }
    return 0;
}

#include<stdio.h>

int main()
{
	long long int n, a, b, c;
	scanf("%lld%lld%lld%lld", &n, &a, &b, &c);

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

	else
	{
		long long int x = n, count = 0;

		for(; x > 0; x = x - 4)
		{
			count++;
		}

		int k = (4*count) - n;

		if ( k == 1 )
			printf("%lld\n",a);

		else if(k == 2 )
		{
			long long int q = 2*a;
			long long int ans = (q < b ? q : b);
			ans = (ans<2*c ? ans:2*c);
			printf("%lld\n",ans);
		}

		else if(k == 3)
		{
			long long int q = 3*a;
			long long int w = b + a;
			long long int ans = ( q< w ? q : w);

			ans = (ans< c? ans : c);
			printf("%lld\n",ans);

		}
	}

return 0;
}

#include<stdio.h>
#define MIN(a,b) a<b?a:b
int main()
{
    long long n,a,b,c,min;
    scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
    n=4-(n%4);
    if(n==0)
    {
        printf("0\n");
        return 0;
    }
    if(n==1)
    {
        min=MIN(a,(b+c));
        min=MIN(min,(3*c));
    }
    else if(n==2)
    {
        min=MIN(b,(2*a));
        min=MIN(min,(2*c));
    }
    else
    {
        min=MIN(c,(3*a));
        min=MIN(min,(a+b));
    }
    printf("%lld\n",min);
    return 0;
}

#include<stdio.h>
typedef long long ll;
ll minn(ll a,ll b)
{
return (a>b)?b:a;
}
int main()
{
    ll n,a,b,c;
    scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
    if(n%4==0)
    printf("%d",0);
    else if(n%4==2)
    {
    ll r=minn(2*a,b);
    printf("%lld",r);
    }
    else if(n%4==1)
    {
    //printf("y");
    ll r=minn(3*a,c);
    printf("%lld",r);
    }
    else
    {
    if(a<=c)
    printf("%lld",a);
    else
    {
    ll ar[(a/12)+3],z=0,f=0,g=0,num;
    for(ll i=0;i<(a/12)+3;i++)
    ar[i]=-1;
    for(ll p=3;f==0;p+=12)
    {
    if(p>a)
    {
    f=1;
    break;
    }
    ar[z++]=p;
    }
    for(ll i=0;i<z;i++)
    {
    if(ar[i]!=-1)
    {
    if(ar[i]%c==0)
    {
    num=ar[i];
    g=1;
    break;
    }
    }
    }
    if(g==0)
    printf("%lld",a);
    else
    {
    ll r=minn((num/3)*c,a);
    printf("%lld",r);
    }
    }
    }
    return 0;
}

#include <stdio.h>

#define MIN(x, y) (((x) < (y)) ? (x) : (y))

int main(void) {
    long long n = 0;
    long long a = 0;
    long long b = 0;
    long long c = 0;

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

    long long r = 0;

    while ((n % 4) != 0) {
        if ((n % 2) == 0) {
            long long d = MIN(b, c * 2);
            r += MIN(d, a * 2);
            break;
        } else {
            long long tmp = (n + 1) % 4;
            if ((tmp % 4) == 0) {
                r += a;
                break;
            } else {
                long long i = MIN(c, 3 * a);
                r += MIN(i, a + b);
                break;
            }
        }
    }

    printf("%d\n", r);
    return 0;
}

#include <stdio.h>

int main(void) {
	long long int n,a,b,c,s,min=1000000000,i,k,c1=0;
	scanf("%lld %lld %lld %lld",&n,&a,&b,&c);
	int arr[3]={a,b,c};
	for(i=0;i<3;i++)
	{
	   c1=0;
	   s=n;
	   while(s%4!=0)
	   {
	       s+=(i+1);
           c1+=arr[i];
           if(c1>min)
           {
               break;
           }
	   }
	   if(min>c1)
	   {
	       min=c1;
	   }
	}
	printf("%lld",min);
	return 0;
}

#include<stdio.h>
int main()
{
    long long int n,a,b,c,rem,amt=0;
    scanf("%lld%lld%d%lld",&n,&a,&b,&c);
    rem=n%4;
    if(rem==1)
    {
        amt=(c<3*a)?c:(3*a);
        amt=((a+b)<amt?(a+b):amt);
    }
    else if(rem==2)
    {
        amt = (b<2*a)?b:(2*a);
        amt = ((2*c)<amt)?(2*c):amt;
    }
    else if(rem==3)
    {
        amt=(a<3*c)?a:(3*c);
        amt=amt<(b+c)?amt:(b+c);
    }
    printf("%lld",amt);
    return 0;
}

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

int main() {
  #ifndef ONLINE_JUDGE
  freopen( "input.txt", "r", stdin );
  #endif

  int n, a1, b2, c3;
  scanf( "%d %d %d %d", &n, &a1, &b2, &c3 );

  if (2*a1 < b2) { b2 = 2*a1; }
  if (3*a1 < c3) { c3 = 3*a1; }

  int need = (n % 100) % 4;
  int cost;

  switch (need) {
    case 3: cost = a1; break;
    case 2: cost = b2; break;
    case 1: cost = c3; break;
    case 0: cost = 0; break;
  }

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

#include<stdio.h>

long long int min(long long int a,long long int b,long long int c)
{
	if(a<=b && a<=c)
		return a;
	else if(b<=a && b<=c)
		return b;
	else
		return c;
}

int main()
{
	long long int n,a,b,c;
	scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
	if(n%4==0)
		printf("0\n");
	else if(n%4==3)
		printf("%lld\n",min(a,b,c));
	else if(n%4==2)
		printf("%lld\n",min(2*a,b,c));
	else
		printf("%lld\n",min(3*a,2*b,c));
	return 0;
}

#include <stdio.h>
#define min(a,b) a > b ? b : a ;
int main()
{
    long long int n,a,b,c,aux,h=0,x=4;
    int rest;
    scanf("%I64d %I64d %I64d %I64d", &n,&a,&b,&c);
    if(n%x == h)
        {
            printf("0");
            return 0;
        }
    else
        {
            rest=4 - (n%4);
            if(rest==1)
                {
                    if (a > b+c )
                        printf("%ld",b+c);
                    else
                        printf("%ld",a);
                    return 0;
                }
            else if (rest == 2)
                {
                    //aux = 2*a > b ? b : 2*a ;
                    //aux = 2*c > aux ? aux : 2*c;
                    aux = min (2*a,b);
                    aux = min (2*c,aux);
                    printf("%ld",aux);
                    return 0;
                }
            else
                {
                    aux=min(3*a,c);
                    aux=min(a+b,aux);
                    printf("%ld",aux);
                    return 0;
                }
        }
    return 0;
}

#include<stdio.h>
#define MIN(a,b) (a>b?b:a)
#define Min(a,b,c) MIN(MIN(a,b),c)
#define min(a,b,c,d) MIN(MIN(a,b),MIN(c,d))
main()
{
	long long int x,n,a,b,c;
	scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
	x=n%4;
	switch(x)
	{
		case 1:printf("%lld",min(3*a,c,a+b,3*b));
		break;
		case 2:printf("%lld",Min(2*a,b,2*c));
		break;
		case 3:printf("%lld",Min(a,b+c,3*c));
		break;
		default:printf("0");
	}
}

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

#include<stdio.h>
int main()
{
	int n,a,b,c,d,e,min,f,g;
	scanf("%d%d%d%d",&n,&a,&b,&c);
	int to_buy;
	to_buy=n%4;
	if(to_buy==0)
		printf("0\n");
	else
	{
		to_buy=4-to_buy;
		if(to_buy==1)
		{
			if(a<b+c) //1 or 5
				min=a;
			else
				min=b+c;
			if(min>3*c) // 9
				min=3*c;
			printf("%d\n",min);
		}
		else if(to_buy==2)
		{
			d=2*a;  // 2
			if(d<b) //2
				min=d;
			else
				min=b;
			if(2*c<min) //6
				min=2*c;
			printf("%d\n",min);
		}
		else
		{
			d=3*a; // 3
			e=a+b;//1+2
			f=2*c+a; //7
                        g=3*c+b;//11
			if(d<e)
				min=d;
			else
				min=e;
			if(c<min)
				min=c;
			if(f<min)
				min=f;
                        if(g<min)
                                min=g;
			printf("%d\n",min);
		}
	}
	return 0;
}

#include <stdio.h>

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

int main(void) {
    int n = 0, a = 0, b = 0, c = 0;
    int i = 0, j = 0, k = 0;
    int result = 0;

    scanf("%d %d %d %d", &n, &a, &b, &c);
    if (n % 4 == 0) {
        printf("0\n");
    } else {
        if (n % 4 == 1) {
            result = a * 3;
            result = min(result, a + b);
            result = min(result, c);
        } else if (n % 4 == 2) {
            result = min(a * 2, b);
        } else if (n % 4 == 3) {
            result = a;
        }

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

    return 0;
}

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

        if(n%4==0)
        printf("0\n");
        else if(n%4==1)
        {
             ins=min(3*a,c);
             ans=min(ins,a+b);
             printf("%d\n",ans);
        }
        else if(n%4==2)
        printf("%d\n",min(2*a,b));
        else if(n%4==3)
        printf("%d\n",a);
}

/*
 * 1.这个程序做到的事情
 * ruble是俄国的货币
 * 四门课
 * 2.这个程序遇到的困难
 * 3.接下来要做的事情
 */
#include<stdio.h>
#define N 100
int min2(int a,int b){
    if(a>b)return b;
    else return a;
}
int min3(int a,int b,int c){
    return min2(a,min2(b,c));
}
int main() {
    int n,a,b,c;
    scanf("%d%d%d%d",&n,&a,&b,&c);
    int min=0;
    int money[N];
    money[0]=0;
    money[1]=a;
    money[2]=min2(a*2,b);
    money[3]=min3(a*3,b+a,c);
    /*
    money[4]=min(money[1]+money[3],money[2]+money[2]);
    money[5]=min(money[1]+money[4],money[2]+money[3]);
    */
    int i,j;
    for(i=4;i<N;i++){
        money[i]=money[1]+money[i-1];
        for(j=2;j<=i/2;j++){
            money[i]=min2(money[i],money[j]+money[i-j]);
        }
    }
    int k=0;
    while(1){
        //只能购买恰好k本书，不能多买？
        if(k>=N){
            printf("不够\n");
            break;
        }
        if((n+k)%4==0){
            min=money[k];
            break;
        }
        k++;
    }
    printf("%d\n",min);
	return 0;
}

#include<stdio.h>

long long  mini(long long a, long long b, long long c)
{

 return a<=b?a<=c?a:c : b<=c?b:c;

}

int main(void)
{

long long min,n,a,b,c;

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

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

else if(n%4==3)
{

min = mini(a,b+c,3*a+b);

}

else if(n%4==2)
{

  min = mini(2*a, b, 2*c);

}

else if(n%4==1)
{

min = mini(3*a, c, a+b);

}

printf("%lld",min);

return 0;
}

#include<stdio.h>

typedef long long int lli;

int main()
{
	lli n,a,b,c;

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

	lli k=n%4;

	if(k==0)
		printf("0");
	else if(k==1)
	{if(3*a<=c)
		printf("%lld",3*a);
		else
			printf("%lld",c);
	}
	else if(k==2)
	{if(2*a<=b)
		{if(2*a<=2*c)
			printf("%lld",2*a);
				else
					printf("%lld",2*c);}
		else if(b<=2*a)
		{if(b<=2*c)
			printf("%lld",b);
				else
					printf("%lld",2*c);}
	}
	else
	{if(3*c<=a)
		printf("%lld",3*c);
		else
			printf("%lld",a);
	}
	return 0;
}

#include<stdio.h>
int main (){long long int alyona,a,b,c,i,j,k,count,remainder;scanf("%lld %lld %lld %lld",&alyona,&a,&b,&c);if(alyona%4==0)printf("0\n");else{remainder=4-(alyona%4);switch(remainder){case 1:{if((b+c)>a)printf("%lld\n",a);else printf("%lld\n",(b+c));break;}case 2:{if((a*2)<b && (a*2)<(c*2))printf("%lld\n",(a*2));if(b<(a*2) && b<(c*2))printf("%lld\n",b);if((c*2)<b && (c*2)<(a*2))printf("%lld\n",(c*2));break;}case 3:{if((a*3)<c && (a*3)<(a+b))printf("%lld\n",(a*3));if(c<(a*3) && c<(a+b))printf("%lld\n",c);if((a+b)<(a*3) && (a+b)<c)printf("%lld\n",(a+b));break;}}}return 0;}

#include<stdio.h>

long long int min(long long int a,long long int b)
{
	long long int y=((a<b)?a:b);
	return y;
}
int main()
{
	long long int y,n,a,b,c;
	scanf("%lld%lld%lld%lld",&n,&a,&b,&c);

	y=4-n%4;

	if(y==1)
		printf("%lld",min(min(a,b),c));
	else if(y==2)
		printf("%lld",min(min(2*a,b),2*c));
	else if(y==3)
		printf("%lld",min(min(3*a,b+a),c));
	else
		printf("0");

	return 0;
}

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

int main()
{
    long long int n, a, b, c, k, s1, s2,s3;
    scanf("%lld%lld%lld%lld", &n, &a, &b, &c);
    if(n%4==0)
        {
            k=0;
            printf("%lld\n",k);
        }
    else
        {
            k=n%4;
            k=4-k;
            if(k==1)
                printf("%lld\n",a);
            else if(k==2)
               {
                   if(2*a>b)
                        printf("%lld\n",b);
                    else
                        printf("%lld\n",2*a);
               }
            else if(k==3)
                {
                    s1=3*a;
                    s2=c;
                    s3=2*b+a;

                    if(s1<s2 && s1<s3)
                        printf("%lld\n",s1);
                    else if(s1>s2 && s2<s3)
                        printf("%lld\n",s2);
                    else
                        printf("%lld\n",s3);
                }
        }
    return 0;
}

#include <stdio.h>

long long Min(long long a, long long b)
{
    if(a < b) {
        return a;
    }
    return b;
}

int main()
{
    int n, a, b, c;
    long long Ans;
    scanf("%d %d %d %d", &n, &a, &b, &c);
    if(n % 4 == 0) {
        Ans = 0;
    } else if(n % 4 == 1) {
        Ans = Min((long long)a * 3, (long long)c);
        Ans = Min(Ans, (long long)a + (long long)b);
        Ans = Min(Ans, (long long)a + (long long)c * 2);
        Ans = Min(Ans, (long long)b + (long long)c * 7);
    } else if(n % 4 == 2) {
        Ans = Min((long long)a * 2, (long long)b);
        Ans = Min(Ans, (long long)c * 2);
    } else {
        Ans = Min((long long)a, (long long)c * 7);
    }
    printf("%I64d\n", Ans);
    return 0;
}

#include <stdio.h>

int main()
{
    long long int n, a, b, c, k, s1, s2,s3;

    scanf("%lld%lld%lld%lld", &n, &a, &b, &c);
    if(n%4==0)
    {
        k=0;
        printf("%lld\n",k);
    }
    else
    {
        k=n%4;
        k=4-k;
        if(k==1)
            {
                s1=a;
                s2=5*c;

                if(s1<s2 && s1<s3)
                    printf("%lld\n",s1);
                else if(s2<s1 && s2<s3)
                    printf("%lld\n",s2);
            }
        else if(k==2)
           {
                s1=2*a;
                s2=2*c;
                s3=b;

                if(s1<s2 && s1<s3)
                    printf("%lld\n",s1);
                else if(s2<s1 && s2<s3)
                    printf("%lld\n",s2);
                else
                    printf("%lld\n",s3);
           }
        else if(k==3)
        {
            s1=3*a;
            s2=c;
            s3=b+a;

            if(s1<s2 && s1<s3)
                printf("%lld\n",s1);
            else if(s2<s1 && s2<s3)
                printf("%lld\n",s2);
            else
                printf("%lld\n",s3);
        }
    }
    return 0;
}

#include <stdio.h>

long long int min2(long long int a, long long int b){
    if (a < b)
        return a;
    else
        return b;
}

long long int min3(long long int a, long long int b, long long int c){
    if (a <= b && a <= c)
        return a;
    else if (b <= a && b <= c)
        return b;
    else
        return c;
}

int main(void) {
    long long int n, a, b, c;
    scanf("%I64d%I64d%I64d%I64d", &n, &a, &b, &c);
    if (n % 4 == 0)
        printf("0");
    else if (n % 4 == 1)
        printf("%I64d", min2(3 * a, c));
    else if (n % 4 == 2)
        printf("%I64d", min3(2 * a, b, 2 * c));
    else if (n % 4 == 3)
        printf("%I64d", min2(a, 3 * b));
    return 0;
}

#include<stdio.h>
int main()
{
	int n,a,b,c,d,e,min,f,g;
	scanf("%d%d%d%d",&n,&a,&b,&c);
	int to_buy;
	to_buy=n%4;
	if(to_buy==0)
		printf("0\n");
	else
	{
		to_buy=4-to_buy;
		if(to_buy==1)
		{
			if(a<b+c) //1 or 5
				min=a;
			else
				min=b+c;
			if(min>3*c) // 9
				min=3*c;
			printf("%d\n",min);
		}
		else if(to_buy==2)
		{
			d=2*a;  // 2
			if(d<b) //2
				min=d;
			else
				min=b;
			if(2*c<min) //6
				min=2*c;
			printf("%d\n",min);
		}
		else
		{
			d=3*a; // 3
			e=a+b;//3
			if(d<e)
				min=d;
			else
				min=e;
			if(c<min)
				min=c;

			printf("%d\n",min);
		}
	}
	return 0;
}

#include<stdio.h>
#include<math.h>
long long int min(long long int a,long long int b)
{
    if(a>b)
    return b;
    else
    return a;
}
int main()
{
    long long int n=0,a=0,b=0,c=0,ins=0,ans=0;
    scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
   // printf("%lld\n",n%4);

        if(n%4==0)
        printf("0\n");
        else if(n%4==1)
        {
             ins=min(3*a,c);
             ans=min(ins,a+b);
             printf("%lld\n",ans);
        }
        else if(n%4==2)
        {
            ins=min(2*a,b);
            for(int i=2;i<100000;i=i*2)
            {

                if(i*c>ins)
                break;

                else
                ans=min(ins,i*c);

            }
            printf("%lld\n",ans);
        }
        else if(n%4==3)
        {
            for(int i=3;i<100000;i=i+4)
             {
                ans=min(a,i*c);
                if(a>ins)
                    break;
            }
            printf("%lld\n",a);
        }
}

#include <stdio.h>

int main(void) {
	// your code goes here
	long long n,a,b,c;
	scanf("%lld %lld %lld %lld",&n,&a,&b,&c);
	int t;
	t=4-n%4;
	if(t==4) {printf("0"); return 0;}
	long long count,count1,count2;

	if(t==1) printf("%lld",a);

	count=a*t;
	if(t==2){
		count1=b;
		if(count<count1) printf("%lld",count);
	else printf("%lld",count1);
	}
	long long min;
	if(t==3)
	{count1=a+b;
	count2=c;

	if(count<count1) min=count;
	else min=count1;

	if(min<count2) printf("%lld",min);
	else printf("%lld",count2);

	}
	return 0;
}

#include<stdio.h>
int main (){long long int alyona,a,b,c,i,j,k,count,remainder;scanf("%lld %lld %lld %lld",&alyona,&a,&b,&c);if(alyona%4==0)printf("0\n");else{remainder=4-(alyona%4);switch(remainder){case 1:{if((b+c)>=a)printf("%lld\n",a);else printf("%lld\n",(b+c));break;}case 2:{if((a*2)<=b && (a*2)<=(c*2))printf("%lld\n",(a*2));else if(b<=(a*2) && b<=(c*2))printf("%lld\n",b);else if((c*2)<=b && (c*2)<=(a*2))printf("%lld\n",(c*2));break;}case 3:{if((a*3)<=c && (a*3)<=(a+b))printf("%lld\n",(a*3));else if(c<=(a*3) && c<=(a+b))printf("%lld\n",c);else if((a+b)<=(a*3) && (a+b)<=c)printf("%lld\n",(a+b));break;}}}return 0;}

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

    }
   else if(k==2){
       if (b <2*a&&b <2*c){
           printf ("%lld",b);
       }
       else if (2*a <2*c){
           printf ("%lld",2*a);
       }
       else{
           printf ("%lld",2*c);
       }

   }
   else {
       if (c <3*a&&c<3*b+a){
           printf ("%lld",c);
       }
         else if (3*a <3*b+a){
             printf ("%lld",3*a);
         }
         else {
             printf ("%lld",3*b+a);
         }

   }
   return 0;
}

#include<stdio.h>

long long int min(long long int x, long long int y, long long int z)
{
	if(x<y && x<z)
		return x;
	else if(y<x && y<z)
		return y;
	else
		return z;
}

int main()
{
	long long int n,a,b,c,i;
	scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
	if(n%4==0)
		printf("0\n");
	else if(n%4==1)
		printf("%lld\n",min(3*a,b+a,c));
	else if(n%4==2)
		printf("%lld\n",min(2*a,b,1000*a+1000*b));
	else if(n%4==3)
		printf("%lld\n",a);
	return 0;
}

#include<stdio.h>
void swap(long long int *xp, long long int *yp)
{
	long long int temp = *xp;
	*xp = *yp;
	*yp = temp;
}

void bubbleSort(long long int arr[], long long int n)
{
	long long int i, j;
	for (i = 0; i < n-1; i++)
		for (j = 0; j < n-i-1; j++)
			if (arr[j] > arr[j+1])
				swap(&arr[j], &arr[j+1]);
}

int main()
{
	long long int n,a,b,c,i,j,k;
	scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
	if (n%4==0)
		printf("0");
	else
	{

		long long int equal,rem;
		equal = n/4;
		rem = n%4;
		long long int arr[4];
		for (i=0; i<4; i++)
		{
			if (rem>0)
			{
				arr[i]=equal+1;
				rem--;
			}
			else
				arr[i]=equal;
		}
		int count1=0,count2=0;
		for (i=0; i<4; i++)
		{
			if (arr[i]==arr[i+1])
				count1++;
			else
				break;
		}
		count2=4-count1;
		if (count2==1)
		{
			printf("%lld",a);
		}
		else if (count2==2)
		{
			long long int ans1,ans2;
			ans1=2*a;
			ans2=b;
			if (ans1<ans2)
				printf("%lld",ans1);
			else
				printf("%lld",ans2);
		}
		else if (count2==3)
		{
			long long int Ans[3];
			Ans[0]=3*a;
			Ans[1]=b+a;
			Ans[2]=c;
			bubbleSort(Ans,3);
			printf("%lld",Ans[0]);
		}
	}
	return 0;
}

#include <stdio.h>
int min(int a,int b,int c)

{
	if(a<=b && a<=c)
		return a;
	else if(b<=a && b <=c)
		return b;
	else if(c<=a && c<=b)
		return c;
}

int main()
{
	int n,a,b,c;
	scanf("%d%d%d%d",&n,&a,&b,&c);
	int g=n%4;
	if(g==0)
	 printf("0");

	else
	{
		int p,q,r;
		if(g==1)
		{
		 	p=3*a;
			q=a+b;
		 	r=c;
		 	int ans = min(p,q,r);
			fprintf(stdout,"%d",ans);
		}
		else if(g==2)
		{

			 p=2*a;
			 q=b;
			 r=2*c;
			 int ans = min(p,q,r);
			printf("%d",ans);
		}

		else if(g==3)
		{
			p=a;
			q=2*b + a;
			r=c+b;
			int ans = min(p,q,r);
			printf("%d",ans);

		}
	}

}

#include <stdio.h>
long long int min(int a, int b)
{
	if(a>b)
		return b;
	else
		return a;
}
int main()
{
	long long int n,a,b,c;
	scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
	long long int z=4-n%4;
	long long int l;
	if(z==3)
	{
		l= min((3*a),c);
		l= min(l,(a+b));
		l=min(l,(2*b+c));
	}
	if(z==2)
	{
		 l=min(2*a,b);
		l=min(l,2*c);
	}
	if(z==1)
	{
		l=min((b+c),a);
	}
	if(z==0)
	{
		l=0;
	}
	printf("%lld",l);
	return 0;
}

#include <stdio.h>

int min(int, int, int);

int main () {
    int n, a, b, c;
    int k;
    scanf ("%d %d %d %d", &n, &a, &b, &c);
    k = 4 - (n % 4);
    if (k == 1) {
       printf ("%d\n", min (a, b + c, 3 * c));
    }
    else if (k == 2) {
        printf ("%d\n", min (2 * a, b, 2 * c));
    }
    else if (k == 3) {
        printf ("%d\n", min (3 * a, a + b, c));
    }
    else {
        printf ("0\n");
    }
    return 0;
}

int min (int a, int b, int c) {
    if ((a <= b) && (a <= c)) {
        return a;
    }
    if ((b <= a) && (b <= c)) {
        return b;
    }
    if ((c <= a) && (c <= b)) {
        return c;
    }
    return 0;
}

#include<stdio.h>
long long int min( long long int a,long long int b,long long int c)
{
	long long int min=a;
	if(min>b)
		min=b;
	if(min>c)
		min=c;
	return min;
}

int main()
{
	long long int n,a,b,c;
	scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
	if(n%4==0)
		printf("0");
	else if(n%4==1)
	{
		printf("%lld",min(3*a,a+b,c));
	}
	else if(n%4==2)
	{
		printf("%lld",min(2*a,b,2*c));
	}
	else
	{
		printf("%lld",a);
	}
	return 0;
}

#include <stdio.h>

int main()
{
    long long int n,a,b,c,x,y,z,ans;
    scanf("%lld %lld %lld %lld",&n,&a,&b,&c);

    if(n%4==0) ans=0;

    //one more cb is needed
    else if((n+1)%4==0)
    {
        if(a>b+c) ans=b+c;
        else ans=a;
    }

    //three more cb are needed
    else if((n-1)%4==0)
    {
        if(a*3<c)
        {
            if(a*3>b+a) ans=b+a;
            else ans=a*3;
        }
        else ans=c;
    }

    //two more cb are needed
    else
    {
        if(b<a*2) ans=b;
        else ans=a*2;
    }

    printf("%lld",ans);

    return 0;

}

#include<stdio.h>
#define MIN(a,b) ((a) < (b) ? a : b)

int main()
{
	long int n, a, b, c;
	scanf("%ld%ld%ld%ld", &n, &a, &b, &c);

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

	else
	{
		long int x = n, count = 0;

		for(; x > 0; x = x - 4)
		{
			count++;
		}

		int k = (4*count) - n;

		if ( k == 1 )
			printf("%ld\n",a);

		else if(k == 2 )
		{
			long int q = 2*a;
			long int ans = MIN(q,b);
			printf("%ld\n",ans);
		}

		else if(k == 3)
		{
			long int q = 3*a;
			long int w = 2*b + a;
			long int ans = MIN(q,w);

			ans = MIN(ans,c);
			printf("%ld\n",ans);

		}
	}

return 0;
}

#include<stdio.h>
int main()
{
	long long n,a,b,c;
	int k;
	scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
	if(n%4==0)
	printf("0");
	else
	{   long long sum;
		k=4-n%4;
		if(k==1) sum=a;
		if(k==2)
		{
			if(b>=2*a)sum=2*a;
			else sum=b;
		}
		if(k==3)
		{
			if(c>=3*a)
			{
				if(3*a>=(b+a)) sum=b+a;
				else sum=3*a;
			}
			else
			{
				if(c>=(b+a)) sum=b+a;
				else sum=c;
			}
		}
		printf("%lld",sum);
	}
	return 0;
}

#include<stdio.h>
#include<math.h>
long long int min(long long int a,long long int b)
{
    if(a>b)
    return b;
    else
    return a;
}
int main()
{
    long long int n=0,a=0,b=0,c=0,ins=0,ans=0;
    scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
   // printf("%lld\n",n%4);

        if(n%4==0)
        printf("0\n");
        else if(n%4==1)
        {
             ins=min(3*a,c);
             ans=min(ins,a+b);
             printf("%lld\n",ans);
        }
        else if(n%4==2)
        {
            ins=min(2*a,b);
            ans=min(ins,2*c);
            for(int i=2;i<100000;i=i*2)
            {

                if(i*c>ins)
                {
                    break;
                }
                else
                ans=min(ans,i*c);

            }
            if(ans!=0)
            printf("%lld\n",ans);

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

        }
        else if(n%4==3)
        {
            ans=min(a,3*c);
            for(int i=3;i<100000;i=i+4)
             {
                if(i*c>a)
                    break;

                else
                ans=min(ans,i*c);
            }
            if(ans!=0)
            printf("%lld\n",ans);

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

        }
}

#include <stdio.h>
long long int min(long long int x,long long int y, long long int z)
{
    if(x<y&&x<z) return x;
    else if(y<x&&y<z) return y;
    else if(z<x&&z<y) return z;
}

int main()
{
    long long int n,a,b,c,ans;
    scanf("%lld %lld %lld %lld",&n,&a,&b,&c);

    if(n%4==0) ans=0;

    //one more cb is needed
    else if((n+1)%4==0)
    ans=min(a,b+c,10000000001);

    //three more cb are needed
    else if((n-1)%4==0)
    ans=min(a*3,a+b,c);

    //two more cb are needed
    else
    ans=min(b,a*2,c*2);

    printf("%lld",ans);

    return 0;

}

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

#include <stdio.h>

int min2(int a, int b){
    if (a < b)
        return a;
    else
        return b;
}

int min3(int a, int b, int c){
    if (a <= b && a <= c)
        return a;
    else if (b <= a && b <= c)
        return b;
    else
        return c;
}

int main(void) {
    int n, a, b, c;
    scanf("%d%d%d%d", &n, &a, &b, &c);
    if (n % 4 == 0)
        printf("0");
    else if (n % 4 == 1)
        printf("%d", min2(3 * a, c));
    else if (n % 4 == 2)
        printf("%d", min3(2 * a, b, 2 * c));
    else if (n % 4 == 3)
        printf("%d", min2(a, 3 * b));
    return 0;
}

#include<stdio.h>

long long int min(long long int a,long long int b)
{
	long long int y=((a<b)?a:b);
	return y;
}
int main()
{
	long long int y,n,a,b,c;
	scanf("%lld%lld%lld%lld",&n,&a,&b,&c);

	y=4-n%4;

	if(y==1)
		printf("%lld",min(min(a,b),c));
	else if(y==2)
		printf("%lld",min(min(2*a,b),2*c));
	else if(y==3)
		printf("%lld",min(min(3*a,b+a),c));
	else
		printf("0");

	return 0;
}

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

long long min2(long long x,long long y){

    if(x > y)
        return y;
    return x;
}

long long min3(long long x,long long y,long long z){

    if(x <= y && x <= z)
        return x;
    if(y <= x && y <= z)
        return y;
    if(z <= x && z <= y)
        return z;
}

int main(){

    int n, a, b, c, d;
    scanf("%d %d %d %d",&n,&a,&b,&c);
    d = n;
    while(n % 4 != 0)
        ++n;
    n = n - d;

    if(n == 0)
        printf("0");

    if(n == 1)
        printf("%I64d",(long long)a);

    if(n == 2)
        printf("%I64d",min2((long long)(2 * a),(long long)b));

    if(n == 3)
        printf("%I64d",min3((long long)(3 * a),(long long)(a + b),(long long)c));

}

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

int main() {
  #ifndef ONLINE_JUDGE
  freopen( "input.txt", "r", stdin );
  #endif

  int n, a1, b2, c3;
  scanf( "%d %d %d %d", &n, &a1, &b2, &c3 );

  if (2*a1 < b2) { b2 = 2*a1; }
  if (3*a1 < c3) { c3 = 3*a1; }

  int cost;

  if (n > 0) {
    switch ( (n % 100) % 4 ) {
      case 3: cost = a1; break;
      case 2: cost = b2; break;
      case 1: cost = c3; break;
      case 0: cost = 0; break;
    }
  } else {
    cost = b2+b2;
  }

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

#include<stdio.h>
int main (){long long int alyona,a,b,c,i,j,k,count,remainder;scanf("%lld %lld %lld %lld",&alyona,&a,&b,&c);if(alyona%4==0)printf("0\n");else{remainder=4-(alyona%4);switch(remainder){case 1:{printf("%lld\n",a);break;}case 2:{if((a*2)<b)printf("%lld\n",(a*2));else{if((c*2)<b)printf("%lld\n",(c*2));else printf("%lld\n",b);}break;}case 3:{if((a*3)<c)printf("%lld\n",(a*3));else printf("%lld\n",c);break;}}}return 0;}

#include <stdio.h>

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

int main() {
	int n, a, b, c;

	scanf("%d%d%d%d", &n, &a, &b, &c), n = (4 - (n % 4)) % 4;
	printf("%d\n", n == 0 ? 0 : n == 1 ? a : n == 2 ? min(a * 2, b) : min(a * 3, min(a + b, c)));
	return 0;
}

/*input
1 1 4 8
*/
#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,a,b,c,i,j,t,k;
	scanf("%64lld%64lld%64lld%64lld",&n,&a,&b,&c);
    k=4-n%4;
	if(k==4)
		t=0;
	else if(k==1)
		t=a;
	else if(k==2)
	{
		if(2*a<b)
			t=2*a;
		else
			t=b;
	}
	else if(k==3)
	{
       j=min(3*a,c);
       t=min(j,2*a+b);
	}
	printf("%lld",t);
	return 0;

}

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

int main(){
    long long int n, a, b, c, x;
    scanf("%I64d %I64d %I64d %I64d", &n, &a, &b, &c);
    n %= 4;
    switch(n){
        case 0: printf("0\n"); break;
        case 1: x = a;
                if (x > (c + c + c)) x = c + c + c;
                if (x > (c + b)) x = c + b;
                printf("%I64d\n", x); break;
        case 2: x = c + c + c;
                if (x > (a + a)) x = a + a;
                if (x > b) x = b;
                printf("%I64d\n", x); break;
        case 3: x = c;
                if (x > (a + a + a)) x = (a + a + a);
                if (x > (b + a)) x = (b + a);
                printf("%I64d\n", x); break;
    }
    return 0;
}

#include<stdio.h>
int min(int a,int b)
{
    if(a<b)
        return a;
    else return b;
}
int main()
{
    int n,a,b,c;
    scanf("%d %d %d %d",&n,&a,&b,&c);
    if(n%4==0 )
        printf("0");
    else
    {
    switch(n%4)
    {
        case 3:printf("%d",a);break;
        case 2:printf("%d",min(2*a,b));break;
        case 1:printf("%d",min(3*a,c));break;

    }
    }
    return 0;

}

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

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

int main(){
  ll int n, a, b, c; scanf("%lld %lld %lld %lld", &n, &a, &b, &c);
  n %= 4; if(!n){ printf("0\n"); return 0; }
  if(n == 1) printf("%lld\n", min(min(3 * a, a + b), c));
  else if(n == 2) printf("%lld\n", min(min(2 * a, b), 2 * c));
  else if(n == 3) printf("%lld\n", min(min(a, 6 * b), 5 * c));
  return 0;
}

#include <stdio.h>

int main()
{
   long long int n,a,b,c,min,k;
   scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
   if(n%4==0)
   min=0;
   else
  { k=4-n%4;
   min=k*a;
   if((b*2)%k==0 && (b*k)/2<min && (b*k)/2>=b )
   min=(b*k)/2;
   else if((c*3)%k==0 && (c*k)/3<min && (c*k)/3>=c)
   min=(c*k)/3;}
   printf("%lld",min);

    return 0;
}