Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for a rubles, a pack of two copybooks for b rubles, and a pack of three copybooks for c rubles. Alyona already has n copybooks.

What is the minimum amount of rubles she should pay to buy such number of copybooks k that n + k is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase.

Input

The only line contains 4 integers n, a, b, c (1 ≤ n, a, b, c ≤ 109).

Output

Print the minimum amount of rubles she should pay to buy such number of copybooks k that n + k is divisible by 4.

Examples

Input

1 1 3 4


Output

3


Input

6 2 1 1


Output

1


Input

4 4 4 4


Output

0


Input

999999999 1000000000 1000000000 1000000000


Output

1000000000

Note

In the first example Alyona can buy 3 packs of 1 copybook for 3a = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally. 

In the second example Alyuna can buy a pack of 2 copybooks for b = 1 ruble. She will have 8 copybooks in total.

In the third example Alyona can split the copybooks she already has between the 4 subject equally, so she doesn't need to buy anything.

In the fourth example Alyona should buy one pack of one copybook.
import java.awt.Point;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.util.Comparator;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Easy {
    static long mod = (long) (1e9 + 7);
    static int[] dx = {1,-1,0,0};
    static int[] dy = {0,0,1,-1};
    static int[] ddx = {1,-1,0,0,1,-1,1,-1};
    static int[] ddy = {0,0,1,-1,1,-1,-1,1};

    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long temp = n % 4;
        if (temp == 0) {
            out.println(0);
        } else if (temp == 1) {
            out.println(Math.min(3 * a, Math.min(c, a + b)));
        } else if (temp == 2) {
            out.println(Math.min(2 * a, Math.min(b, 2 * c)));
        } else {
            out.println(Math.min(3 * c, Math.min(a, b + c)));
        }
        out.close();
    }


    public static class Node {
        ArrayList<Integer> edges;


        public Node() {
            edges = new ArrayList<>();
        }
    }

    public static class STree {
        long[] tree;
        long[] base;

        public STree(long[] base) {
            this.base = base;
            tree = new long[2 * base.length];
            for (int i = base.length; i < tree.length; i++) {
                tree[i] = base[i - base.length];
            }
            for (int i = base.length - 1; i > 0; i--) {
                tree[i] = tree[2*i] + tree[2*i ^ 1];
            }
        }

        public long get(int index) {
            return tree[index + base.length];
        }

        public void modify(int index, long val) {
            index += base.length;
            tree[index] = val;
            while (index > 1) {
                tree[index/2] = tree[index] + tree[index ^ 1];
                index/=2;
            }
        }


        public long query(int start, int end) {
            long ans = 0;
            start += base.length;
            end += base.length + 1;
            while (start < end) {
                if ((start & 1) == 1) {
                    ans += tree[start++];
                }
                if ((end & 1) == 1) {
                    ans += tree[--end];
                }
                start>>=1;
            end>>=1;
            }
            return ans;
        }

        public void print() {
            out.println();
            for (int i = base.length; i < tree.length; i++) {
                out.print(tree[i] + " ");
            }
            out.println();
        }
    }

    public static PrintWriter out;
    /*
    int n      = sc.nextInt();        // read input as integer
    long k     = sc.nextLong();       // read input as long
    double d   = sc.nextDouble();     // read input as double
    String str = sc.next();           // read input as String
    String s   = sc.nextLine();       // read whole line as String
    out.println(result);              // print via PrintWriter
     */
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
}