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.

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

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

NoteIn 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.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;

namespace Olymp
{
  public class ProblemSolver
  {
    private Tokenizer input;

    public void Solve()
    {
      int n = input.NextInt();
      long a = input.NextInt();
      long b = input.NextInt();
      long c = input.NextInt();
      int k = 4 - n % 4;
      long x;
      if (k == 4)
      {
        x = 0;
      }
      else if (k == 1)
      {
        x = Min(a, 3 * c, b + c);
      }
      else if (k == 2)
      {
        x = Min(2 * a, b, 2 * c, a + b + c);
      }
      else
      {
        x = Min(3 * a, c, 2 * b + c, a + b);
      }
      Console.Write(x);
    }

    private T Min<T>(params T[] a)
    {
      return a.Min();
    }

    public ProblemSolver(TextReader input)
    {
      this.input = new Tokenizer(input);
    }
  }

  #region Service classes

  public class Tokenizer
  {
    private TextReader reader;

    public int NextInt()
    {
      var c = SkipWS();
      if (c == -1)
        throw new EndOfStreamException();
      bool isNegative = false;
      if (c == '-' || c == '+')
      {
        isNegative = c == '-';
        c = this.reader.Read();
        if (c == -1)
          throw new InvalidOperationException();
      }
      if (!char.IsDigit((char)c))
        throw new InvalidOperationException();
      int result = (char)c - '0';
      c = this.reader.Read();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        if (!char.IsDigit((char)c))
          throw new InvalidOperationException();
        result = result * 10 + (char)c - '0';
        c = this.reader.Read();
      }
      if (isNegative)
        result = -result;
      return result;
    }

    public string ReadLine()
    {
      return reader.ReadLine();
    }

    public long NextLong()
    {
      return long.Parse(this.NextToken());
    }

    public double NextDouble()
    {
      return double.Parse(this.NextToken(), CultureInfo.InvariantCulture);
    }

    public int[] ReadIntArray(int n)
    {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = NextInt();
      return a;
    }

    public long[] ReadLongArray(int n)
    {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = NextLong();
      return a;
    }

    public double[] ReadDoubleArray(int n)
    {
      double[] a = new double[n];
      for (int i = 0; i < n; i++)
        a[i] = NextDouble();
      return a;
    }

    public string NextToken()
    {
      var c = SkipWS();
      if (c == -1)
        return null;
      var sb = new StringBuilder();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        sb.Append((char)c);
        c = this.reader.Read();
      }
      return sb.ToString();
    }

    private int SkipWS()
    {
      int c = this.reader.Read();
      if (c == -1)
        return c;
      while (c > 0 && char.IsWhiteSpace((char)c))
        c = this.reader.Read();
      return c;
    }

    public Tokenizer(TextReader reader)
    {
      this.reader = reader;
    }
  }

  class Program
  {
    public static void Main(string[] args)
    {
      var solver = new ProblemSolver(Console.In);
      solver.Solve();
    }
  }

  #endregion
}

using System;

class Program
{
    static Func<string, int> Int = x => Convert.ToInt32(x);
    static Func<string, long> Long = x => Convert.ToInt64(x);
    static void Main(string[] args)
    {
        string[] buf = Console.ReadLine().Split(' ');
        long n = Long(buf[0]);
        long a = Long(buf[1]);
        long b = Long(buf[2]);
        long c = Long(buf[3]);
        if (n % 4 == 0) Console.WriteLine(0);
        else if (n % 4 == 1) Console.WriteLine(Math.Min(Math.Min(3 * a, a + b), c));
        else if (n % 4 == 2) Console.WriteLine(Math.Min(2 * a, Math.Min(2 * c, b)));
        else if (n % 4 == 3) Console.WriteLine(Math.Min(a, Math.Min(b + c, 3 * c)));
    }
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test
{
    class IOHelper : IDisposable
    {
        StreamReader reader;
        StreamWriter writer;

        public IOHelper(string inputFile, string outputFile, Encoding encoding)
        {
            StreamReader iReader;
            StreamWriter oWriter;
            if (inputFile == null)
                iReader = new StreamReader(Console.OpenStandardInput(), encoding);
            else
                iReader = new StreamReader(inputFile, encoding);

            if (outputFile == null)
                oWriter = new StreamWriter(Console.OpenStandardOutput(), encoding);
            else
                oWriter = new StreamWriter(outputFile, false, encoding);

            reader = iReader;
            writer = oWriter;

            curLine = new string[] { };
            curTokenIdx = 0;
        }

        string[] curLine;
        int curTokenIdx;

        char[] whiteSpaces = new char[] { ' ', '\t', '\r', '\n' };

        public string ReadNextToken()
        {
            if (curTokenIdx >= curLine.Length)
            {
                //Read next line
                string line = reader.ReadLine();
                if (line != null)
                    curLine = line.Split(whiteSpaces, StringSplitOptions.RemoveEmptyEntries);
                else
                    curLine = new string[] { };
                curTokenIdx = 0;
            }

            if (curTokenIdx >= curLine.Length)
                return null;

            return curLine[curTokenIdx++];
        }

        public int ReadNextInt()
        {
            return int.Parse(ReadNextToken());
        }

        public double ReadNextDouble()
        {
            var nextToken = ReadNextToken();
            var result = 0.0;
            nextToken = nextToken.Replace(".", System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);
            result = double.Parse(nextToken);
            return result;
        }

        public void Write(string stringToWrite)
        {
            writer.Write(stringToWrite);
        }

        public void WriteLine(string stringToWrite)
        {
            writer.WriteLine(stringToWrite);
        }

        public void WriteLine(double valueToWrite)
        {
            long intPart = (long)valueToWrite;
            double fracPart = valueToWrite - intPart;
            var fracPartStr = fracPart.ToString();
            if (fracPartStr.Length > 1)
                fracPartStr = fracPartStr.Substring(2);
            var strToWrite = string.Format("{0}.{1}", intPart, fracPartStr);
            writer.WriteLine(strToWrite);
        }

        public void Dispose()
        {
            try
            {
                if (reader != null)
                {
                    reader.Dispose();
                }
                if (writer != null)
                {
                    writer.Dispose();
                }
            }
            catch { };
        }

        public void Flush()
        {
            if (writer != null)
            {
                writer.Flush();
            }
        }
    }

    class Program
    {
        protected IOHelper ioHelper;

        int n;
        long a, b, c;

        long result = 0;

        public void Solve()
        {
            n = ioHelper.ReadNextInt();
            a = ioHelper.ReadNextInt();
            b = ioHelper.ReadNextInt();
            c = ioHelper.ReadNextInt();

            if((n%4) == 0)
            {
                result = 0;
            }
            else if((n%4)==1)
            {
                var choice1 = c;

                var choice2 = a + b;

                var choice3 = 3 * a;

                result = Math.Min(Math.Min(choice2, choice3), choice1);
            }
            else if((n%4)==2)
            {
                var choice3 = a + 3 * c;
                var choice1 = 2 * a;
                var choice2 = b;
                var choice4 = 2 * c;

                result = Math.Min(Math.Min(choice1, choice2), Math.Min(choice3, choice4));
            }
            else if((n%4)==3)
            {
                var choice1 = a;
                var choice2 = b + c;
                var choice3 = 3 * c;

                result = Math.Min(Math.Min(choice1, choice2), choice3);
            }

            ioHelper.WriteLine(result.ToString());
            ioHelper.Flush();

            //Console.ReadKey();
        }

        public Program(string inputFile, string outputFile)
        {
            ioHelper = new IOHelper(inputFile, outputFile, Encoding.Default);
            Solve();
            ioHelper.Dispose();
        }

        static void Main(string[] args)
        {
            Program myProgram = new Program(null, null);
        }
    }
}

using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;

namespace TmpSharpProj
{
    class Program
    {
        static void Main()
        {
            Program app = new Program();
            app.Run();
        }

        public void Run()
        {
            long[] ar = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
            long ans = 0;
            switch (ar[0] % 4)
            {
                case 0:
                    ans = 0;
                    break;
                case 1:
                    ans = Math.Min(ar[3], Math.Min(ar[1] + ar[1] + ar[1], ar[2] + ar[1]));
                    break;
                case 2:
                    ans = Math.Min(ar[2], Math.Min(ar[3] + ar[3], ar[1] + ar[1]));
                    break;
                case 3:
                    ans = Math.Min(ar[1], Math.Min(ar[2] + ar[3], ar[3] + ar[3] + ar[3]));
                    break;
            }
            Console.WriteLine(ans);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//using System.Xml.Linq;

namespace CP
{
    class Program
    {
        #region Reusable

        class DescComparer<T> : IComparer<T>
        {
            public int Compare(T x, T y)
            {
                return Comparer<T>.Default.Compare(y, x);
            }
        }
        public class DuplicateKeyComparer<TKey> : IComparer<TKey> where TKey : IComparable
        {
            #region IComparer<TKey> Members

            public int Compare(TKey x, TKey y)
            {
                int result = x.CompareTo(y);

                if (result == 0)
                    return 1;   // Handle equality as beeing greater
                else
                    return result;
            }

            #endregion
        }
        static int[] GetIntArray()
        {
            return Array.ConvertAll(Console.ReadLine().Trim().Split(' '), int.Parse);
        }
        static double[] GetDoubleArray()
        {
            return Array.ConvertAll(Console.ReadLine().Trim().Split(' '), Convert.ToDouble);
        }
        static string[] GetStringArray()
        {
            return Console.ReadLine().Trim().Split(' ');
        }
        static int GetN()
        {
            return Convert.ToInt32(Console.ReadLine().Trim());
        }
        static bool[] GetSieve(int max)
        {
            long sum = 0;
            long n = 2000000;
            bool[] e = new bool[n];//by default they're all false
            for (int i = 2; i < n; i++)
            {
                e[i] = true;//set all numbers to true
            }
            //weed out the non primes by finding mutiples
            for (int j = 2; j < n; j++)
            {
                if (e[j])//is true
                {
                    for (long p = 2; (p * j) < n; p++)
                    {
                        e[p * j] = false;
                    }
                }
            }
            return e;
        }
        static bool IsPrime(int n)
        {
            if (n > 1)
            {
                return Enumerable.Range(2, n / 2).Where(x => n % x == 0).Count() == 0;
            }

            return false;
        }
        static List<int> GetListFromInt(int n)
        {
            List<int> arr = new List<int>();
            while (n > 0)
            {
                arr.Add(n % 10);
                n /= 10;
            }
            arr.Reverse();
            return arr;
        }
        static int GetIntFromArray(int[] arr)
        {
            int op = 0;
            foreach (int i in arr)
            {
                op = (op * 10) + i;
            }
            return op;
        }
        private static int GetMost(List<int> vals, int m)
        {
            int ct = vals.Count;
            int l = vals.Max();
            int h = vals.Sum();

            while (l < h)
            {
                int mp = 1;
                int cl = 0;
                int mid = l + (h - l) / 2;
                for (int i = 0; i < ct; ++i)
                {
                    if (cl + vals[i] <= mid) cl += vals[i];
                    else { ++mp; cl = vals[i]; }
                }
                if (mp <= m) h = mid;
                else l = mid + 1;
            }
            return l;
        }
        private static int GetLeast(List<int> vals, int m)
        {
            int max = -1;
            int ct = vals.Count;
            int h = vals[ct - 1];
            int l = 0;
            //int l = h;
            //for (int i = 1; i < ct; i++)
            //{
            //    int df = vals[i] - vals[i - 1];
            //    if (df < l) l = df;
            //}
            while (l < h)
            {
                int mp = 1;
                int prCwPos = vals[0];
                int mid = l + (h - l) / 2;
                for (int i = 1; i < ct; ++i)
                {
                    int d = vals[i] - prCwPos;
                    if (d >= mid)
                    {
                        mp++;
                        prCwPos = vals[i];
                    }
                }
                if (mp >= m) { l = mid + 1; if (mid > max) max = mid; }
                else h = mid;
            }
            return max;
        }
        static void Print(List<string> op, bool newLine)
        {
            if (newLine)
            {
                foreach (string s in op)
                {
                    Console.WriteLine(s);
                }
            }
            else
            {
                Console.WriteLine(string.Join(" ", op));
            }
        }
        static void Print2DArray(int[,] ar)
        {
            for (int i = 0; i < ar.GetLength(0); i++)
            {
                string op = string.Empty;
                for (int j = 0; j < ar.GetLength(1); j++)
                {
                    if (op == string.Empty) op = ar[i, j].ToString();
                    else op += " " + ar[i, j].ToString();
                }
                Console.WriteLine(op);

            }
        }
        static void Print2DArray(int[][] ar)
        {
            for (int i = 0; i < ar.GetLength(0); i++)
            {
                string op = string.Empty;
                for (int j = 0; j < ar.GetLength(1); j++)
                {
                    if (op == string.Empty) op = ar[i][j].ToString();
                    else op += " " + ar[i][j].ToString();
                }
                Console.WriteLine(op);

            }
        }
        static void Print2DArray(bool[,] ar)
        {
            for (int i = 0; i < ar.GetLength(0); i++)
            {
                string op = string.Empty;
                for (int j = 0; j < ar.GetLength(1); j++)
                {
                    if (op == string.Empty) op = (ar[i, j] ? "1" : "0");
                    else op += " " + (ar[i, j] ? "1" : "0");
                }
                Console.WriteLine(op);

            }
        }
        static int MinDistanceForDijkstra(int[] dist, bool[] sptSet)
        {
            int V = dist.Length;
            // Initialize min value
            int min = Int32.MaxValue, min_index = 0;

            for (int v = 0; v < V; v++)
                if (sptSet[v] == false && dist[v] <= min)
                {
                    min = dist[v];
                    min_index = v;
                }

            return min_index;
        }
        static int[] Dijkstra(int[][] graph, int src)
        {
            int V = graph.Length;
            int[] dist = new int[V];     // The output array.  dist[i] will hold the shortest
            // distance from src to i

            bool[] sptSet = new bool[V]; // sptSet[i] will true if vertex i is included in shortest
            // path tree or shortest distance from src to i is finalized

            // Initialize all distances as INFINITE and stpSet[] as false
            for (int i = 0; i < V; i++)
            {
                dist[i] = Int32.MaxValue;
                sptSet[i] = false;
            }

            // Distance of source vertex from itself is always 0
            dist[src] = 0;

            // Find shortest path for all vertices
            for (int count = 0; count < V - 1; count++)
            {
                // Pick the minimum distance vertex from the set of vertices not
                // yet processed. u is always equal to src in first iteration.
                int u = MinDistanceForDijkstra(dist, sptSet);

                // Mark the picked vertex as processed
                sptSet[u] = true;

                // Update dist value of the adjacent vertices of the picked vertex.
                for (int v = 0; v < V; v++)

                    // Update dist[v] only if is not in sptSet, there is an edge from
                    // u to v, and total weight of path from src to  v through u is
                    // smaller than current value of dist[v]
                    if (!sptSet[v] && (graph[u][v] != 0) && dist[u] != Int32.MaxValue
                                                  && dist[u] + graph[u][v] < dist[v])
                        dist[v] = dist[u] + graph[u][v];
            }
            return dist;

        }
        static int[] Dijkstra2(int[][] graph, int src)
        {
            int V = graph.Length;
            int[] dist = new int[V];     // The output array.  dist[i] will hold the shortest
            // distance from src to i

            bool[] sptSet = new bool[V]; // sptSet[i] will true if vertex i is included in shortest
            // path tree or shortest distance from src to i is finalized

            // Initialize all distances as INFINITE and stpSet[] as false
            for (int i = 0; i < V; i++)
            {
                dist[i] = Int32.MaxValue;
                sptSet[i] = false;
            }

            // Distance of source vertex from itself is always 0
            dist[src] = 0;

            // Find shortest path for all vertices
            for (int count = 0; count < V - 1; count++)
            {
                // Pick the minimum distance vertex from the set of vertices not
                // yet processed. u is always equal to src in first iteration.
                int u = MinDistanceForDijkstra(dist, sptSet);

                // Mark the picked vertex as processed
                sptSet[u] = true;

                // Update dist value of the adjacent vertices of the picked vertex.
                for (int v = 0; v < V; v++)

                    // Update dist[v] only if is not in sptSet, there is an edge from
                    // u to v, and total weight of path from src to  v through u is
                    // smaller than current value of dist[v]
                    if (!sptSet[v] && (graph[u][v] != -1) && dist[u] != Int32.MaxValue
                                                  && dist[u] + graph[u][v] < dist[v])
                        dist[v] = dist[u] + graph[u][v];
            }
            return dist;

        }
        static int LCM(int[] numbers)
        {
            return numbers.Aggregate(LCM);
        }
        static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        static int GCD(int[] numbers)
        {
            return numbers.Aggregate(GCD);
        }
        static int GCD(int a, int b)
        {
            return b == 0 ? a : GCD(b, a % b);
        }

        static int[] or = new int[] { 1, 0, -1, 0 };
        static int[] oc = new int[] { 0, 1, 0, -1 };
        #endregion
        static void Main(string[] args)
        {
            a2();

        }

        private static void a2()
        {
            long[] ips = Array.ConvertAll(Console.ReadLine().Trim().Split(' '), long.Parse);
            long n = ips[0];
            long a = ips[1];
            long b = ips[2];
            long c = ips[3];
            long req = 4 - (n % 4);
            long ct = 0;
            switch (req)
            {
                case 3:
                    ct = new long[]{3 * a, c,a+b}.Min();
                    break;
                case 2:
                    ct = new long[]{2 * a, b,2*c}.Min();
                    break;
                case 1:
                    ct = new long[] { a, b+c, 3 * c }.Min();
                    break;
            }
            Console.WriteLine(ct);
        }

        private static void a1()
        {
            int n = GetN();
            List<int> ips = GetIntArray().ToList();
            int ct=0;
            if (n > 2)
            {
                ips.Sort();
                int s = 0;
                int e = n - 1;
                while (s < n)
                {
                    if (ips[0] == ips[s]) s++;
                    else break;
                }
                while (e >= 0)
                {
                    if (ips[e] == ips[n-1]) e--;
                    else break;
                }
                ct = e - s+1;
                if (ct < 0) ct = 0;
            }
            Console.WriteLine(ct);

        }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace tetradki
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            long n = long.Parse(s[0]);
            long a = long.Parse(s[1]);
            long b = long.Parse(s[2]);
            long c = long.Parse(s[3]);
            long ans=0;

            switch (n%4)
            {
                case 1:
                    ans = Math.Min(3 * a, Math.Min(a + b, c));
                    break;
                case 2:
                    ans = Math.Min(Math.Min(2 * a, b),2*c);
                    break;
                case 3:
                    ans = Math.Min(a,Math.Min(b+c,3*c));
                    break;
            }

            Console.Write(ans);

        }
    }
}

using System;
using System.IO;
using System.Text;

namespace Alyona_and_copybooks
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            long n = Next(), a = Next(), b = Next(), c = Next();

            long amount = 0;
            switch (n%4)
            {
                case 0:
                    break;
                case 1:
                    amount = Math.Min(c, Math.Min(a + a + a, a + b));
                    break;
                case 2:
                    amount = Math.Min(b, Math.Min(a + a, c + c));
                    break;
                case 3:
                    amount = Math.Min(a, Math.Min(b + c, c + c + c));
                    break;
            }

            writer.WriteLine(amount);
            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _740A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            long n = long.Parse(input[0]), a = long.Parse(input[1]), b = long.Parse(input[2]), c = long.Parse(input[3]);
            long result = 0;
            switch (4 - n % 4)
            {
                case 1:
                    result = Math.Min(a, Math.Min(3 * c, b + c));
                    break;

                case 2:
                    result = Math.Min(2 * a, Math.Min(b, 2 * c));
                    break;

                case 3:
                    result = Math.Min(3 * a, Math.Min(a + b, c));
                    break;
            }
            Console.WriteLine(result);
            //Console.ReadLine();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace contest1012
{
    class Program
    {
        static void Main(string[] args)
        {

            var cp = Console.ReadLine().Split(' ').Select(k => long.Parse(k)).ToArray();

            var n = cp[0];
            var a = cp[1];
            var b = cp[2];
            var c = cp[3];
            long counta, countb,countc;

            var h = n% 4;

            if(h == 0)
            {
                Console.WriteLine(0);
                return;
            }
            else if (h == 1)
            {
                countc = c;
                countb = b + a;
                counta = 3 * a;
                if ((countc <= countb) && (countc <= counta))
                {
                    Console.WriteLine(countc);
                }
                else if ((countb <= countc) && (countb <= counta))
                {
                    Console.WriteLine(countb);
                }
                else if ((counta <= countb) && (counta <= countc))
                {
                    Console.WriteLine(counta);
                }
            }
            else if (h == 2)
            {
                countc = 2 * c;
                countb = b;
                counta = 2 * a;
                if ((countc <= countb) && (countc <= counta))
                {
                    Console.WriteLine(countc);
                }
                else if ((countb <= countc) && (countb <= counta))
                {
                    Console.WriteLine(countb);
                }
                else if ((counta <= countb) && (counta <= countc))
                {
                    Console.WriteLine(counta);
                }
            }
            else if (h == 3)
            {
                countc = 3 * c;
                countb = b + c;
                counta = a;
                if ((countc <= countb) && (countc <= counta))
                {
                    Console.WriteLine(countc);
                }
                else if ((countb <= countc) && (countb <= counta))
                {
                    Console.WriteLine(countb);
                }
                else if ((counta <= countb) && (counta <= countc))
                {
                    Console.WriteLine(counta);
                }
            }
        }
    }
}

using System;

namespace CSharp
{
    public class _740A
    {
        public static void Main()
        {
            string[] tokens = Console.ReadLine().Split();

            long n = int.Parse(tokens[0]);
            long a = int.Parse(tokens[1]);
            long b = int.Parse(tokens[2]);
            long c = int.Parse(tokens[3]);

            long min = long.MaxValue;

            for (int ca = 0; ca < 4; ca++)
            {
                for (int cb = 0; cb < 4; cb++)
                {
                    for (int cc = 0; cc < 4; cc++)
                    {
                        if ((n + ca + 2 * cb + 3 * cc) % 4 == 0)
                        {
                            min = Math.Min(min, ca * a + cb * b + cc * c);
                        }
                    }
                }
            }

            Console.WriteLine(min);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            long n, a, b, c;
            string[] num = Console.ReadLine().Split(' ');
            n = int.Parse(num[0]);
            a = int.Parse(num[1]);
            b = int.Parse(num[2]);
            c = int.Parse(num[3]);
            long[] mas = new long[6];

            if (n % 4 == 0) Console.WriteLine(0);

            if (n % 4 == 3)
            {
                mas[0] = a;
                mas[1] = c * 3;
                mas[2] = b + c;
                mas[3] = mas[0];
                for (int i = 0; i < 3; i++)
                {
                    if (mas[3] > mas[i]) mas[3] = mas[i];
                }
                Console.WriteLine(mas[3]);
            }

            if (n % 4 == 2)
            {
                mas[0] = a * 2;
                mas[1] = b;
                mas[2] = c * 2;
                mas[3] = mas[0];
                for (int i = 0; i < 3; i++)
                {
                    if (mas[3] > mas[i]) mas[3] = mas[i];
                }
                Console.WriteLine(mas[3]);
            }

            if (n % 4 == 1)
            {
                mas[0] = a * 3;
                mas[1] = a + b;
                mas[2] = c;
                if (mas[0] > mas[1]) mas[4] = mas[1];
                else mas[4] = mas[0];
                if (mas[4] > mas[2]) Console.WriteLine(mas[2]);
                else Console.WriteLine(mas[4]);
            }

        }
    }
}

using System;

namespace acsv2
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var line = Console.ReadLine().Trim().Split();
            var n = Int64.Parse(line[0]);
            var a = Int64.Parse(line[1]);
            var b = Int64.Parse(line[2]);
            var c = Int64.Parse(line[3]);

            long answer = 0;

            if (n % 4 == 0) {
                answer = 0;
            }
            else if ((n + 1) % 4 == 0) {
                answer = Math.Min(Math.Min(a, b + c), 3 * c);
            }
            else if ((n + 2) % 4 == 0) {
                answer = Math.Min(Math.Min(a * 2, b), c * 2);
            }
            else if ((n + 3) % 4 == 0) {
                answer = Math.Min(Math.Min(a * 3, a + b), c);
            }

            Console.WriteLine(answer);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using static Template;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pi = Pair<int, int>;

class Solver
{
    public void Solve(Scanner sc)
    {
        int n = sc.Next<int>();
        var A = new long[3];
        for (var i = 0; i < 3; i++) A[i] = sc.Next<long>();
        chmin(ref A[0], A[1] + A[2]);
        chmin(ref A[0], A[2] * 3);
        chmin(ref A[1], A[0] * 2);
        chmin(ref A[1], A[2] * 2);
        chmin(ref A[2], A[0] + A[1]);
        chmin(ref A[2], A[0] * 3);
        var o = (4L - n % 4) % 4;if (o == 0) Fail(0);
        WriteLine(A[o - 1]);
    }
}

#region Template
public class Template
{
    static void Main(string[] args)
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver().Solve(new Scanner());
        Console.Out.Flush();
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmin<T>(ref T a, T b) where T : IComparable<T>
    { if (a.CompareTo(b) == 1) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmax<T>(ref T a, T b) where T : IComparable<T>
    { if (a.CompareTo(b) == -1) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(ref T a, ref T b)
    { var t = b; b = a; a = t; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static T[] Create<T>(int n, Func<T> f)
    {
        var rt = new T[n];
        for (var i = 0; i < rt.Length; ++i)
            rt[i] = f();
        return rt;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static T[] Create<T>(int n, Func<int, T> f)
    {
        var rt = new T[n];
        for (var i = 0; i < rt.Length; ++i)
            rt[i] = f(i);
        return rt;
    }
    public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }
}

public class Scanner
{
    public string Str => ReadLine().Trim();
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
    public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
    public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
    public int[] ArrInt1D(int n) => Create(n, () => Int);
    public long[] ArrLong1D(int n) => Create(n, () => Long);
    public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
    public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
    public Pair<T1, T2> PairMake<T1, T2>() => new Pair<T1, T2>(Next<T1>(), Next<T2>());
    public Pair<T1, T2, T3> PairMake<T1, T2, T3>() => new Pair<T1, T2, T3>(Next<T1>(), Next<T2>(), Next<T3>());
    private Queue<string> q = new Queue<string>();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }
    public void Make<T1>(out T1 v1) => v1 = Next<T1>();
    public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); }
    public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); }
    public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); }
    public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); }
    public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); }
}

public class Pair<T1, T2> : IComparable<Pair<T1, T2>>
{
    public T1 v1;
    public T2 v2;
    public Pair() { }
    public Pair(T1 v1, T2 v2)
    { this.v1 = v1; this.v2 = v2; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2> p)
    {
        var c = Comparer<T1>.Default.Compare(v1, p.v1);
        if (c == 0)
            c = Comparer<T2>.Default.Compare(v2, p.v2);
        return c;
    }
    public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
    public void Tie(out T1 a, out T2 b) { a = v1; b = v2; }
}

public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>>
{
    public T3 v3;
    public Pair() : base() { }
    public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2)
    { this.v3 = v3; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2, T3> p)
    {
        var c = base.CompareTo(p);
        if (c == 0)
            c = Comparer<T3>.Default.Compare(v3, p.v3);
        return c;
    }
    public override string ToString() => $"{base.ToString()} {v3.ToString()}";
    public void Tie(out T1 a, out T2 b, out T3 c) { Tie(out a, out b); c = v3; }
}
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            long n, a, b, c;
            var s = Console.ReadLine().Split(' ');
            n = long.Parse(s[0]);
            a = long.Parse(s[1]);
            b = long.Parse(s[2]);
            c = long.Parse(s[3]);
            if (n % 4 == 0)
            {
                Console.WriteLine(0);
                return ;
            }

            if (n % 4 == 1)
            {
                long res = 3 * a;
                if (res > c) res = c;
                if (res > a + b) res = a + b;
                Console.WriteLine(res);
                return ;
            }

            if (n % 4 == 2)
            {
                long res = b;
                if (res > 2 * a) res = 2 * a;
                if (res > 2 * c) res = 2 * c;
                Console.WriteLine(res);
                return ;
            }

            if (n % 4 == 3)
            {
                long res = a;
                if (res > 3 * c) res = 3 * c;
                if (res > b + c) res = b + c;
                Console.WriteLine(res);
                return ;
            }
        }

    }
}

using System;

public class Test
{
	public static void Main()
	{
		string s = Console.ReadLine();
		string[] temp = s.Split(' ');
		int n= Convert.ToInt32(temp[0]);
		long a = Convert.ToInt32(temp[1]);
		long b= Convert.ToInt32(temp[2]);
		long c = Convert.ToInt32(temp[3]);
		int[,] mass = new int[9,3]{{3,0,0},{1,1,0},{0,0,1},{2,0,0},{0,1,0},{0,0,2},{1,0,0},{0,1,1},{0,0,3}};
		long min =99999999999;
		if (n%4==0) min=0;
		else
		for (int i=(n%4-1)*3;i<(n%4)*3;i++)
		{
			long sum=a*mass[i,0]+b*mass[i,1]+c*mass[i,2];
			if (sum<min) min=sum;
		}
		Console.WriteLine(min);
	}
}

/* Date: 26.11.2016 * Time: 21:45 */
//       29.01.2017
// *
// ������������ ����� �� ����� 17
// ������������ ����� �� ����� 21
// ������������ ����� �� ����� 26

/*
�	fflush(stdout) � ����� C++;
�	System.out.flush() � Java;
�	stdout.flush() � Python;
�	flush(output) � Pascal;
*/

using System;
using System.IO;
using System.Globalization;

class Example
{
	public static void Main (string[] args)
	{
# if ( ONLINE_JUDGE )

# else
		StreamReader sr = new StreamReader ("C:\\TRR\\2017\\Task\\07 Codeforces\\021\\A.TXT");
		StreamWriter sw = new StreamWriter ("C:\\TRR\\2017\\Task\\07 Codeforces\\021\\A.OUT");
# endif

		string ss;

# if ( ONLINE_JUDGE )
		ss = Console.ReadLine ();
# else
		ss = sr.ReadLine ();
		sw.WriteLine (ss);
# endif

		string [] s = ss.Split (' ');
		Int64 n = Int64.Parse (s [0]);
		Int64 a = Int64.Parse (s [1]);
		Int64 b = Int64.Parse (s [2]);
		Int64 c = Int64.Parse (s [3]);

		Int64 m = (4 - n % 4) % 4, k = 0;
		switch ( m )
		{
			case 1 :
				if ( a <= b + c && a <= 3 * c )
					k = a;
				else if ( 3 * c < a && 2 * c <= b )
					k = 3 * c;
				else
					k = c + b;
				break;
			case 2 :
				if ( 2 * a <= b && a <= c)
					k = 2 * a;
				else if ( 2 * a >= b && b <= c + c)
					k = b;
				else
					k = c + c;
				break;
			case 3 :
				if ( 3 * a <= c && 2 * a <= b )
					k = 3 * a;
				else if ( c <= 3 * a && c <= a + b )
					k = c;
				else
					k = b + a;
				break;
		}

# if ( ONLINE_JUDGE )
		Console.WriteLine (k);
# else
		sw.WriteLine (k);
# endif

# if ( ! ONLINE_JUDGE )
		sw.Close ();
# endif

	}
}

/*
   long long N, A, B, C;
    cin >> N >> A >> B >> C;
    if (N % 4 == 0) {
        cout << 0 << endl;
    } else
    if (N % 4 == 1) {
        cout << min(min(C, A + B), A * 3) << endl;
    } else
    if (N % 4 == 2) {
        cout << min(min(B, C + C), A + A) << endl;
    } else {
        cout << min(min(A, B + C), C * 3) << endl;
    }

if(n%4==0)cout<<"0\n";
	else if(n%4==1)cout<<min(c,min(a+b,3*a))<<'\n';
	else if(n%4==2)cout<<min(c*2,min(a*2,b))<<'\n';
	else cout<<min(3*c,min(a,b+c))<<'\n';

	lint ret = 1e18;
	for( int i=0; i < 22; i++ )
		for( int j=0; j < 22; j++ )
			for( int k=0; k < 22; k++ )
				if ( (n + i + j + j + k + k + k) % 4 == 0 )
					ret = min(ret, a * i + b * j + c * k);

} */

using System;

namespace CodeForces4
{
	class Program
	{
		static void Main(string[] args)
		{
			string[] Data = Console.ReadLine().Split(' ');
			int[] data = Array.ConvertAll(Data, x => int.Parse(x));
			long one = minimum(data[1], (long)data[2] + data[3], (long)3 * data[3]);
			long two = minimum(data[2], (long)2 * data[1], (long)2 * data[3]);
			long three = minimum((long)3 * data[1], (long)data[1] + data[2], data[3]);
			switch ((4 - data[0]%4)%4)
			{
				case 0:
					Console.WriteLine('0');
					break;
				case 1:
					Console.WriteLine(one);
					break;
				case 2:
					Console.WriteLine(two);
					break;
				case 3:
					Console.WriteLine(three);
					break;
			}
		}

		static long minimum(long x1, long x2, long x3)
		{
			return x1 < x2 ? x1 < x3 ? x1 : x3 : x2 < x3 ? x2 : x3;
		}
	}
}

using System;
using System.Globalization;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace Codeforces
{
    class Program : ProgramBase
    {
        private const long commonMod = 1000000007;

        static void Main(string[] args)
        {
            var p = new Program();
            var x = p.Solve();
            p.Out(x);
        }

        object Solve()
        {
            checked
            {
                var n = ReadLong();
                var a = ReadLong();
                var b = ReadLong();
                var c = ReadLong();
                if (n % 4 == 0)
                    return 0;
                if (n % 4 == 2)
                {
                    return new[] { b, 2 * a, 2 * c }.Min();
                }
                if (n % 4 == 3)
                {
                    return new[] { a, c + b, c + 2 * c }.Min();
                }
                if (n % 4 == 1)
                {
                    return new[] { c, a + b, a + 2 * a }.Min();
                }
                throw new Exception();
            }
        }

        struct Segment
        {
            public Segment(long left, long rigth)
            {
                Left = left;
                Right = rigth;
            }

            public long Left;
            public long Right;
            public long Size() { return Right - Left; }
            public long Ships(long size) { return Size() / size; }
            public List<long> GetPositions(long shipSize) {
                var result = new List<long>();
                for (var i = Left + shipSize - 1; i < Right; i+=shipSize)
                {
                    result.Add(i);
                }
                return result;
            }
        }

        struct Second
        {
            public Second(long count, long mana)
            {
                Mana = mana;
                Count = count;
            }

            public long Mana;
            public long Count;
        }
    }

    abstract class ProgramBase
    {
        bool? prod = null;
        StreamReader f;
        Queue<string> tokens;
        protected string FileName { private get; set; }

        protected string Read()
        {
            if (f == null)
                f = string.IsNullOrEmpty(FileName)
                    ? new StreamReader(Console.OpenStandardInput())
                    : new StreamReader((GetProd() ? "" : "c:\\dev\\") + FileName);
            return f.ReadLine();
        }

        protected string ReadToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return tokens.Dequeue();
        }

        protected long ReadLong() { return long.Parse(ReadToken()); }

        protected long[] ReadLongs()
        {
            var s = Read();
            if (s == "")
                return new long[0];
            var tokens = s.Split(' ');
            var result = new long[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = long.Parse(tokens[i]);
            return result;
        }

        public void Out(object r)
        {
            if (string.IsNullOrEmpty(FileName))
                Console.WriteLine(r);
            else if (GetProd())
                File.WriteAllText(FileName, r.ToString());
            else
                Console.WriteLine(r);
        }

        private bool GetProd()
        {

            if (!prod.HasValue)
                try
                {
                    prod = Environment.MachineName != "RENADEEN-W7";
                }
                catch (Exception)
                {
                    prod = true;
                }
            return prod.Value;
        }
    }

    public static class Huj
    {
        public static T MinBy<T>(this IEnumerable<T> source, Func<T, double> func) where T : class
        {
            T result = null;
            var min = double.MaxValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (min > current)
                {
                    min = current;
                    result = item;
                }
            }
            return result;
        }

        public static T MaxBy<T>(this IEnumerable<T> source, Func<T, double> func, T defaultValue = default(T))
        {
            T result = defaultValue;
            var max = double.MinValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (max < current)
                {
                    max = current;
                    result = item;
                }
            }
            return result;
        }

        public static string JoinStrings(this IEnumerable<string> s, string d) { return string.Join(d, s.ToArray()); }

        public static string JoinStrings(this IEnumerable<int> s, string d) { return s.Select(x => x.ToString()).JoinStrings(d); }
        public static string JoinStrings(this IEnumerable<long> s, string d) { return s.Select(x => x.ToString()).JoinStrings(d); }
    }
}

using System;
using System.Globalization;
using System.IO;
using System.Linq;

namespace CF317
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var sr = new InputReader(Console.In);
            //var sr = new InputReader(new StreamReader("input.txt"));
            var task = new Task();
            using (var sw = Console.Out)
            //using (var sw = new StreamWriter("output.txt"))
            {
                task.Solve(sr, sw);
                //Console.ReadKey();
            }
        }
    }

    internal class Task
    {
        public void Solve(InputReader sr, TextWriter sw)
        {
            var input = sr.ReadArray(Int64.Parse);
            var n = input[0];
            var a = input[1];
            var b = input[2];
            var c = input[3];
            if (n % 4 == 0) {
                sw.WriteLine(0);
                return;
            }
            var firstCount = 0L;
            var min = Int64.MaxValue;
            for (var i = 0; i <= 100; i++) {
                for (var j = 0; j <= 100; j++) {
                    for (var k = 0; k <= 100; k++) {
                        var curr = i + 2*j + 3*k;
                        if ((n + curr) % 4 == 0) {
                            var price = i * a + b * j + c * k;
                            min = Math.Min(price, min);
                        }
                    }
                }
            }

            sw.WriteLine(min);
        }
    }
}

internal class InputReader : IDisposable
{
    private bool isDispose;
    private readonly TextReader sr;

    public InputReader(TextReader stream)
    {
        sr = stream;
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    public string NextString()
    {
        var result = sr.ReadLine();
        return result;
    }

    public int NextInt32()
    {
        return Int32.Parse(NextString());
    }

    public long NextInt64()
    {
        return Int64.Parse(NextString());
    }

    public string[] NextSplitStrings()
    {
        return NextString()
            .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
    {
        return NextSplitStrings()
            .Select(s => func(s, CultureInfo.InvariantCulture))
            .ToArray();
    }

    public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
    {
        return
            str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(s => func(s, CultureInfo.InvariantCulture))
                .ToArray();
    }

    protected void Dispose(bool dispose)
    {
        if (!isDispose)
        {
            if (dispose)
                sr.Close();
            isDispose = true;
        }
    }

    ~InputReader()
    {
        Dispose(false);
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A_Alena_and_sketchbooks
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] inputFirst = Console.ReadLine().Split(' ');
            long n = Int64.Parse(inputFirst[0]);
            long a = Int64.Parse(inputFirst[1]);
            long b = Int64.Parse(inputFirst[2]);
            long c = Int64.Parse(inputFirst[3]);

            n = n % 4;
            long min = 0;
            long case1, case2, case3;
            switch (n)
            {
                case 0: break;
                case 1: case1 = a + a + a;
                    case2 = a + b; min = Math.Min(case1, case2);
                    case3 = c; min = Math.Min(min, case3); break;
                case 2: case1 = a + a;
                    case2 = b; min = Math.Min(case1, case2);
                    case3 = c + c; min = Math.Min(min, case3); break;
                case 3: case1 = a;
                    case2 = b + c; min = Math.Min(case1, case2);
                    case3 = c + c + c; min = Math.Min(min, case3); break;
            }

            Console.WriteLine(min);
        }
    }
}

using System;

namespace ConsoleApplication5
{
    class Program
    {
        //static int poisk (int x,int y,int z)
        //{
        //    int res;
        //    if (x < y || x < z)
        //        res = x;
        //    else
        //    {
        //        if (y < x || y < z)
        //            res = y;
        //        else
        //        {
        //            if (z < x || z < y)
        //                res = z;
        //            else

        //        }
        //    }
        //    return (res);
        //}

        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            var s1 = s.Split(' ');
            long r = 0;
            long n = long.Parse(s1[0]);
            long a = long.Parse(s1[1]);
            long b = long.Parse(s1[2]);
            long c = long.Parse(s1[3]);
            if (n % 4 == 0)
                r = 0;
            else
            {
                if (n % 4 == 1)
                {
                    if (c < 3 * a && c < a + b)
                        r = c;
                    else
                    {
                        if (3 * a < c && 3 * a < a + b)
                            r = 3 * a;
                        else
                            r = a + b;
                    }
                }
                else
                {
                    if (n % 4 == 2)
                    {
                        if (b < 2 * a && b < 2 * c)
                            r = b;
                        else
                        {
                            if (2 * a < b && 2 * a < 2 * c)
                                r = 2 * a;
                            else
                                r = 2 * c;
                        }
                    }
                    else
                    {
                        if (a < 3 * c && a < c + b)
                            r = a;
                        else
                        {
                            if (3 * c < a && 3 * c < c + b)
                                r = 3 * c;
                            else
                                r = c + b;
                        }
                    }
                }
            }
            Console.WriteLine(r);
            Console.ReadLine();
        }
    }
}

using System;

namespace ConsoleApplication5
{
    class Program
    {
        static long poisk(long x, long y, long z)
        {
            if (x < y && x < z)
                return x;
            else
            {
                if (y < x && y < z)
                    return y;
                else
                    return z;
              }
        }

        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            var s1 = s.Split(' ');
            long n = long.Parse(s1[0]);
            long a = long.Parse(s1[1]);
            long b = long.Parse(s1[2]);
            long c = long.Parse(s1[3]);
            if (n % 4 == 0)
                Console.WriteLine (0);
            else
            {
                if (n % 4 == 1)
                    Console.WriteLine(poisk(c, 3 * a, a + b));
                else
                {
                    if (n % 4 == 2)
                        Console.WriteLine(poisk(b, 2 * a, 2 * c));
                    else
                        Console.WriteLine(poisk(a, 3 * c, c + b));
                }
            }
            Console.ReadLine();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                long[] nabc = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
                long n = nabc[0];
                long bir = nabc[1];
                long iki = nabc[2];
                long uc = nabc[3];
                if (n % 4 == 0)
                    Console.WriteLine("0");
                else if (n % 4 == 1)
                    Console.WriteLine(Math.Min(Math.Min(3 * bir, bir + iki), uc));
                else if (n % 4 == 2)
                    Console.WriteLine(Math.Min(Math.Min(2 * bir, iki), 2 * uc));
                else
                    Console.WriteLine(Math.Min(Math.Min(bir, iki + uc), 3 * uc));

                Console.ReadKey();
            }

            catch { }
        }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Round381
{
    class Program
    {
        static int[] inputs;
        static long [] qhd;
        static long maxk = long.MaxValue;
        static void Main(string[] args)
        {
            inputs = readInts();
            qhd = new long[4];
            for (int i = 0; i < 4; i++)
                qhd[i] = maxk;
            Console.WriteLine(getMinRubles(ref inputs[0], 0));
        }

        static int[] readInts()
        {
            return Console.ReadLine().Split(' ').Select(p => Int32.Parse(p)).ToArray();
        }

        static long getMinRubles(ref int left, long rubles)
        {
            if (left%4 == 0)
                return rubles;
            int d = left % 4;
            if (qhd[d] <= rubles)
                return maxk;
            else
                qhd[d] = rubles;
            left += 1;
            long min = getMinRubles(ref left, rubles + inputs[1]);
            left -= 1;
            int imin = left + 1;
            for(int i=2; i<=3; i++)
            {
                left += i;
                long value = getMinRubles(ref left, rubles + inputs[i]);
                left -= i;
                if (value < min)
                {
                    min = value;
                    imin = left + i;
                }
            }
            return min;
        }
    }
}

using System;
using System.Collections.Generic;
using System.IO;

namespace prA {
    class Program {
#if ONLINE_JUDGE
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);
#else
        private static readonly StreamWriter writer = new StreamWriter(@"..\..\output");
        private static readonly StreamReader reader = new StreamReader(@"..\..\input");
#endif

        static void Main(string[] args) {
            ulong n = (ulong) Next();
            ulong a = (ulong) Next();
            ulong b = (ulong) Next();
            ulong c = (ulong) Next();
            ulong[] k = new ulong[13];
            ulong ans = int.MaxValue;
            for (ulong i = 1; i < 13; i++) {
                k[i] = k[i - 1] + a;
                if (i >= 2)
                    k[i] = Math.Min(k[i - 2] + b, k[i]);
                if (i >= 3)
                    k[i] = Math.Min(k[i - 3] + c, k[i]);
                if ((n + i) % 4 == 0)
                    ans = Math.Min(ans, k[i]);
            }
            if (n % 4 == 0)
                writer.Write(0);
            else
                writer.Write(ans);
            writer.Flush();
#if !ONLINE_JUDGE
            writer.Close();
#endif
        }
        private static int Next() {
            int c;
            int res = 0;
            do {
                c = reader.Read();
                if(c == -1)
                    return res;
            } while(c != '-' && (c < '0' || c > '9'));
            int sign = 1;
            if(c == '-') {
                sign = -1;
                c = reader.Read();
            }
            res = c - '0';
            while(true) {
                c = reader.Read();
                if(c < '0' || c > '9')
                    return res * sign;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Alyona_and_copybooks
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            long n = long.Parse(s[0]);
            long a = long.Parse(s[1]);
            long b = long.Parse(s[2]);
            long c = long.Parse(s[3]);
            long am = 0;
            long k = 4 - (n % 4);
            if (k == 1)
            {
                if (Math.Min(c * 3, c+b) > a)
                {
                    am += a;
                }
                else
                    am += Math.Min(c * 3, c + b);
            }
            else if (k == 2)
            {
                if (Math.Min(a * 2, 2*c) > b)
                {
                    am += b;
                }
                else
                    am += Math.Min(a * 2, 2 * c);
            }
            else if (k == 3)
            {
                if (Math.Min(a * 3, b + a) > c)
                {
                    am += c;
                }
                else
                    am += Math.Min(a * 3, b + a);
            }
            Console.WriteLine(am);
            Console.ReadLine();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        static long N, A, B, C;

        static long Solve(long N, long A, long B, long C)
        {
            switch (N % 4)
            {
                case 1:
                    return Math.Min(Math.Min(3L * A, C), A + B);

                case 2:
                    return Math.Min(Math.Min(2L * A, B), 2L * C);

                case 3:
                    return Math.Min(Math.Min(A, 3L * C), 3L * B + C);

                default:
                    return 0;
            }
        }

        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string[] vals = input.Split(' ');
            N = long.Parse(vals[0]);
            A = long.Parse(vals[1]);
            B = long.Parse(vals[2]);
            C = long.Parse(vals[3]);

            //Console.WriteLine(Solve(N, A, B, C));

            long minVal = long.MaxValue;
            for (int i = 0; i <= 10; i++)
            {
                for (int j = 0; j <= 10; j++)
                {
                    for (int k = 0; k <= 10; k++)
                    {
                        if ((N + i + 2 * j + 3 * k) % 4 == 0)
                        {
                            minVal = Math.Min(minVal, A * i + B * j + C * k);
                        }
                    }
                }
            }

            Console.WriteLine(minVal);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Numerics;

namespace contest
{

    class contest
    {

        static void Main(string[] args)
        {

            //int n = int.Parse(Console.ReadLine());
            //var input = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //int n = int.Parse(Console.ReadLine());
            var num = Console.ReadLine().Split().Select(int.Parse).ToArray();

            long n = num[0];
            long a = num[1];
            long b = num[2];
            long c = num[3];

            long ruble = long.MaxValue;
            long res = 4 - (n % 4);

            if (n % 4 == 0)
            {
                Console.WriteLine(0);
            }
            else if (res == 1)
            {
                ruble = Math.Min(ruble, a);
                ruble = Math.Min(ruble, (b + c));
                ruble = Math.Min(ruble, ( c*3));
                Console.WriteLine(ruble);
            }
            else if (res == 2)
            {
                ruble = Math.Min(a * 2, b);
                ruble = Math.Min(c * 2, ruble);
                Console.WriteLine(ruble);
            }
            else
            {
                ruble = Math.Min(a * 3, c);
                ruble = Math.Min(ruble, a + b);
                Console.WriteLine(ruble);
            }

        }

    }

}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Alyona_copybooks
{
    class Program
    {
        static void Main(string[] args)
        {
            long a, b, c, n = 0;

            String all_nums = Console.ReadLine();

            String[] numbers = new String[4];
            //StringBuilder[] numbers = new StringBuilder[4];
            numbers = all_nums.Split(' ');

            n = long.Parse(numbers[0]);
            a = long.Parse(numbers[1]);
            b = long.Parse(numbers[2]);
            c = long.Parse(numbers[3]);

            long copybooks,min=0,money;

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

            min = 4000000000;

            for (int i = 0; i <= 3; i++)
            {
                for (int j = 0; j <= 3; j++)
                {
                    for (int k = 0; k <= 3; k++)
                    {
                        copybooks = n + (i) + (j*2) + (k*3);

                        if(copybooks%4==0)
                        {

                            money = a*(i) + b*(j) + c*(k);
                            if (money < min)
                                min = money;
                        }
                    }
                    }
            }

            Console.WriteLine(min);
            Console.ReadLine();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;

namespace codeforces
{
	class Program
	{
		public const int Osn = 1000000007;

		public class Pair
		{
			public long First;

			public long Second;
		}

		public class PairComparer : IComparer<Pair>
		{
			public int Compare(Pair x, Pair y)
			{
				if (x.First < y.First || (x.First == y.First && x.Second > y.Second))
					return -1;
				return 1;
			}
		}

		public static long GetGcd(long a, long b)
		{
			while (true)
			{
				if (b == 0)
					return a;
				var a1 = a;
				a = b;
				b = a1 % b;

			}
		}

		public static void WriteYesNo(bool x, string yes = "YES", string no = "NO")
		{
			if (x)
				Console.WriteLine(yes);
			else
			{
				Console.WriteLine(no);
			}
		}

		public static string ReadString()
		{
			return Console.ReadLine();
		}

		public static List<int> ReadListOfInts()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(int.Parse).ToList();
		}

		public static List<long> ReadListOfLongs()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(long.Parse).ToList();
		}

		public static int ReadInt()
		{
			var s = Console.ReadLine();
			return int.Parse(s);
		}

		public static long ReadLong()
		{
			var s = Console.ReadLine();
			return long.Parse(s);
		}

		public class Vertex
		{
			public int Was;

			public List<int> Edges;
		}

		public static List<Vertex> Graph = new List<Vertex>();

		public static bool Dfs(int u)
		{
			if (Graph[u].Was == 1) return true;
			if (Graph[u].Was == 2) return false;
			Graph[u].Was = 1;
			foreach (var t in Graph[u].Edges)
			{
				if (Dfs(t)) return true;
			}

			Graph[u].Was = 2;
			return false;
		}

		public static bool IsPrime(int x)
		{
			for (var j = 2; j * j <= x; ++j)
				if (x % j == 0)
					return false;
			return true;
		}

		public class LinkedVertex
		{
			public int Next;

			public int Prev;

			public int Value;
		}

		public static int BinarySearch(List<int> list, int value)
		{
			var l = -1;
			var r = list.Count;
			while (r - l > 1)
			{
				var m = (r + l) / 2;
				if (list[m] >= value)
					r = m;
				else
					l = m;
			}

			return r;
		}

		public static Dictionary<long, long> mp = new Dictionary<long, long>();
		public static long Go(long u, long v, long w)
		{
			long ans = 0;
			while (u != v)
				if (u > v)
				{
					if (!mp.ContainsKey(u))
						mp.Add(u, 0);
					ans += mp[u];
					mp[u] += w;
					u /= 2;
				}
				else
				{
					if (!mp.ContainsKey(v))
						mp.Add(v, 0);
					ans += mp[v];
					mp[v] += w;
					v /= 2;
				}
			return ans;
		}

		private static void Main()
		{
			var l = ReadListOfLongs();
			var n = l[0];
			var a = l[1];
			var b = l[2];
			var c = l[3];
			if (n % 4 == 0)
			{
				Console.WriteLine(0);
			}
			if (n % 4 == 3)
			{
				Console.WriteLine(Math.Min(a, Math.Min(3*c, b + c)));
			}
			if (n % 4 == 2)
			{
				Console.WriteLine(Math.Min(b, Math.Min(2*a, 2*c)));
			}
			if (n % 4 == 1)
			{
				Console.WriteLine(Math.Min(c, Math.Min(3 * a, b + a)));
			}
			/*			var n = ReadLong();
			var a = ReadLong();
			var b = ReadLong();
			var c = ReadLong();
			if (a <= b - c)
			{
				Console.WriteLine(n / a);
			}
			else
			{
				long ans = 0;
				while ((n / b) > 0)
				{
					var k = n / b;
					ans += k;
					n = (n % b) + k * c;
				}
				ans += n / a;
				Console.WriteLine(ans);
			}*/
			Console.ReadLine();
		}
	}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        static int GetNumberInt()
        {
            return Convert.ToInt32(Console.ReadLine());
        }

        static long GetNumberLong()
        {
            return Convert.ToInt64(Console.ReadLine());
        }

        static int[] GetArrayInt()
        {
            string[] @string = Console.ReadLine().Split(' ');
            int[] array = new int[@string.Length];
            for (int i = 0; i < array.Length; i++)
            {
                array[i] = Convert.ToInt32(@string[i]);
            }
            return array;
        }

        static long[] GetArrayLong()
        {
            string[] @string = Console.ReadLine().Split(' ');
            long[] array = new long[@string.Length];
            for (int i = 0; i < array.Length; i++)
            {
                array[i] = Convert.ToInt64(@string[i]);
            }
            return array;
        }

        static void Main(string[] args)
        {
            long[] array = GetArrayLong();
            long n = array[0], a = array[1], b = array[2], c = array[3];
            long k = 4 - n % 4;
            long minMoney = int.MaxValue;
            if (k == 1)
                minMoney = Math.Min(Math.Min(a, c + b), Math.Min(3 * c, a + 2 * b));
            else if (k == 2)
                minMoney = Math.Min(Math.Min(2 * a, b), 2 * c);
            else if (k == 3)
                minMoney = Math.Min(Math.Min(c, b + a), 3 * a);
            else
                minMoney = 0;
            Console.WriteLine(minMoney);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        var dp = RLA(4);
        long n = (4 - (dp[0] % 4)) % 4;
        dp[0] = 0;

        for (int tmp = 0; tmp <= 4; tmp++)
            for (int i = 1; i <= 3; i++)
                for (int j = 1; j <= 3; j++)
                    dp[(i + j) % 4] = Math.Min(dp[(i + j) % 4], dp[i] + dp[j]);

        Console.Write(dp[n]);
    }

    private const int Mod = 1000000000 + 7;

    #region Data Read
    private static char ReadSign()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (ans == '+' || ans == '-' || ans == '?')
                return (char)ans;
        }
    }

    private static long GCD(long a, long b)
    {
        if (a % b == 0) return b;
        return GCD(b, a % b);
    }

    private static List<int>[] ReadGraph(int n, int m)
    {
        List<int>[] g = new List<int>[n];
        for (int i = 0; i < g.Length; i++) g[i] = new List<int>();
        for (int i = 0; i < m; i++)
        {
            int a = RI() - 1;
            int b = RI() - 1;

            g[a].Add(b);
            g[b].Add(a);
        }

        return g;
    }

    private static int[,] ReadGraphAsMatrix(int n, int m)
    {
        int[,] matrix = new int[n + 1, n + 1];
        for (int i = 0; i < m; i++)
        {
            int a = RI();
            int b = RI();
            matrix[a, b] = matrix[b, a] = 1;
        }

        return matrix;
    }

    private static void Sort(ref int a, ref int b)
    {
        if (a > b) Swap(ref a, ref b);
    }

    private static void Swap(ref int a, ref int b)
    {
        int tmp = a;
        a = b;
        b = tmp;
    }

    private const int BufferSize = 1 << 16;
    private static StreamReader consoleReader;
    private static MemoryStream testData;

    private static int RI()
    {
        int ans = 0;
        int mul = 1;
        do
        {
            ans = consoleReader.Read();
            if (ans == -1)
                return 0;
            if (ans == '-') mul = -1;
        } while (ans < '0' || ans > '9');

        ans -= '0';
        while (true)
        {
            int chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans * mul;
            ans = ans * 10 + chr - '0';
        }
    }

    private static ulong RUL()
    {
        ulong ans = 0;
        int chr;
        do
        {
            chr = consoleReader.Read();
            if (chr == -1)
                return 0;
        } while (chr < '0' || chr > '9');

        ans = (uint)(chr - '0');
        while (true)
        {
            chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans;
            ans = ans * 10 + (uint)(chr - '0');
        }
    }

    private static long RL()
    {
        long ans = 0;
        int mul = 1;
        do
        {
            ans = consoleReader.Read();
            if (ans == -1)
                return 0;
            if (ans == '-') mul = -1;
        } while (ans < '0' || ans > '9');

        ans -= '0';
        while (true)
        {
            int chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans * mul;
            ans = ans * 10 + chr - '0';
        }
    }

    private static int[] RIA(int n)
    {
        int[] ans = new int[n];
        for (int i = 0; i < n; i++)
            ans[i] = RI();
        return ans;
    }

    private static long[] RLA(int n)
    {
        long[] ans = new long[n];
        for (int i = 0; i < n; i++)
            ans[i] = RL();
        return ans;
    }

    private static char[] ReadWord()
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));

        List<char> s = new List<char>();
        do
        {
            s.Add((char)ans);
            ans = consoleReader.Read();
        } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));

        return s.ToArray();
    }

    private static char[] ReadString(int n)
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));

        char[] s = new char[n];
        int pos = 0;
        do
        {
            s[pos++] = (char)ans;
            if (pos == n) break;
            ans = consoleReader.Read();
        } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));

        return s;
    }

    private static char[] ReadStringLine()
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (ans == 10 || ans == 13);

        List<char> s = new List<char>();

        do
        {
            s.Add((char)ans);
            ans = consoleReader.Read();
        } while (ans != 10 && ans != 13);

        return s.ToArray();
    }

    private static char ReadLetter()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'))
                return (char)ans;
        }
    }
    private static char ReadNonLetter()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')))
                return (char)ans;
        }
    }

    private static char ReadAnyOf(IEnumerable<char> allowed)
    {
        while (true)
        {
            char ans = (char)consoleReader.Read();
            if (allowed.Contains(ans))
                return ans;
        }
    }

    private static char ReadDigit()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (ans >= '0' && ans <= '9')
                return (char)ans;
        }
    }

    private static int ReadDigitInt()
    {
        return ReadDigit() - (int)'0';
    }

    private static char ReadAnyChar()
    {
        return (char)consoleReader.Read();
    }

    private static string DoubleToString(double x)
    {
        return x.ToString(CultureInfo.InvariantCulture);
    }

    private static double DoubleFromString(string x)
    {
        return double.Parse(x, CultureInfo.InvariantCulture);
    }

    static Program()
    {
        //Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
        consoleReader = new StreamReader(Console.OpenStandardInput(BufferSize), Encoding.ASCII, false, BufferSize);
    }

    private static void PushTestData(StringBuilder sb)
    {
        PushTestData(sb.ToString());
    }
    private static void PushTestData(string data)
    {
#if TOLYAN_TEST
        if (testData == null)
        {
            testData = new MemoryStream();
            consoleReader = new StreamReader(testData);
        }

        var pos = testData.Position;
        var bytes = Encoding.UTF8.GetBytes(data);
        testData.Write(bytes, 0, bytes.Length);
        testData.Flush();
        testData.Position = pos;
#endif
    }
    #endregion
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Olymp
{
  public class ProblemSolver
  {
    private Tokenizer input;

    public void Solve()
    {
      long n = input.NextInt();
      long a = input.NextInt();
      long b = input.NextInt();
      long c = input.NextInt();
      long k = 4 - n % 4;
      long x;
      if (k == 1)
        x = a;
      else if (k == 2)
        x = Min(2 * a, b);
      else if (k == 3)
        x = Min(3 * a, a + b, c);
      else
        x = 0;
      Console.Write(x);
    }

    private T Min<T>(params T[] values)
    {
      return values.Min();
    }

    public ProblemSolver(TextReader input)
    {
      this.input = new Tokenizer(input);
    }
  }

  #region Service classes

  public class Tokenizer
  {
    private TextReader reader;

    public int NextInt()
    {
      var c = SkipWS();
      if (c == -1)
        throw new EndOfStreamException();
      bool isNegative = false;
      if(c == '-' || c == '+')
      {
        isNegative = c == '-';
        c = this.reader.Read();
        if (c == -1)
          throw new InvalidOperationException();
      }
      if (!char.IsDigit((char)c))
        throw new InvalidOperationException();
      int result = (char)c - '0';
      c = this.reader.Read();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        if (!char.IsDigit((char)c))
          throw new InvalidOperationException();
        result = result * 10 + (char)c - '0';
        c = this.reader.Read();
      }
      if (isNegative)
        result = -result;
      return result;
    }

    public string ReadLine()
    {
      return reader.ReadLine();
    }

    public long NextLong()
    {
      return long.Parse(this.NextToken());
    }

    public double NextDouble()
    {
      return double.Parse(this.NextToken(), CultureInfo.InvariantCulture);
    }

    public int[] ReadIntArray(int n)
    {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = NextInt();
      return a;
    }

    public long[] ReadLongArray(int n)
    {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = NextLong();
      return a;
    }

    public double[] ReadDoubleArray(int n)
    {
      double[] a = new double[n];
      for (int i = 0; i < n; i++)
        a[i] = NextDouble();
      return a;
    }

    public string NextToken()
    {
      var c = SkipWS();
      if (c == -1)
        return null;
      var sb = new StringBuilder();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        sb.Append((char)c);
        c = this.reader.Read();
      }
      return sb.ToString();
    }

    private int SkipWS()
    {
      int c = this.reader.Read();
      if (c == -1)
        return c;
      while (c > 0 && char.IsWhiteSpace((char)c))
        c = this.reader.Read();
      return c;
    }

    public Tokenizer(TextReader reader)
    {
      this.reader = reader;
    }
  }

  class Program
  {
    public static void Main(string[] args)
    {
      var solver = new ProblemSolver(Console.In);
      solver.Solve();
    }
  }

  #endregion
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Olymp
{
  public class ProblemSolver
  {
    private Tokenizer input;

    public void Solve()
    {
      int n = input.NextInt();
      int a = input.NextInt();
      int b = input.NextInt();
      int c = input.NextInt();
      int k = 4 - n % 4;
      int x;
      if (k == 1)
        x = a;
      else if (k == 2)
        x = Min(2 * a, b);
      else if (k == 3)
        x = Min(3 * a, a + b, c);
      else
        x = 0;
      Console.Write(x);
    }

    private int Min(params int[] values)
    {
      return values.Min();
    }

    public ProblemSolver(TextReader input)
    {
      this.input = new Tokenizer(input);
    }
  }

  #region Service classes

  public class Tokenizer
  {
    private TextReader reader;

    public int NextInt()
    {
      var c = SkipWS();
      if (c == -1)
        throw new EndOfStreamException();
      bool isNegative = false;
      if(c == '-' || c == '+')
      {
        isNegative = c == '-';
        c = this.reader.Read();
        if (c == -1)
          throw new InvalidOperationException();
      }
      if (!char.IsDigit((char)c))
        throw new InvalidOperationException();
      int result = (char)c - '0';
      c = this.reader.Read();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        if (!char.IsDigit((char)c))
          throw new InvalidOperationException();
        result = result * 10 + (char)c - '0';
        c = this.reader.Read();
      }
      if (isNegative)
        result = -result;
      return result;
    }

    public string ReadLine()
    {
      return reader.ReadLine();
    }

    public long NextLong()
    {
      return long.Parse(this.NextToken());
    }

    public double NextDouble()
    {
      return double.Parse(this.NextToken(), CultureInfo.InvariantCulture);
    }

    public int[] ReadIntArray(int n)
    {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = NextInt();
      return a;
    }

    public long[] ReadLongArray(int n)
    {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = NextLong();
      return a;
    }

    public double[] ReadDoubleArray(int n)
    {
      double[] a = new double[n];
      for (int i = 0; i < n; i++)
        a[i] = NextDouble();
      return a;
    }

    public string NextToken()
    {
      var c = SkipWS();
      if (c == -1)
        return null;
      var sb = new StringBuilder();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        sb.Append((char)c);
        c = this.reader.Read();
      }
      return sb.ToString();
    }

    private int SkipWS()
    {
      int c = this.reader.Read();
      if (c == -1)
        return c;
      while (c > 0 && char.IsWhiteSpace((char)c))
        c = this.reader.Read();
      return c;
    }

    public Tokenizer(TextReader reader)
    {
      this.reader = reader;
    }
  }

  class Program
  {
    public static void Main(string[] args)
    {
      var solver = new ProblemSolver(Console.In);
      solver.Solve();
    }
  }

  #endregion
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;

namespace Olymp
{
  public class ProblemSolver
  {
    private Tokenizer input;

    public void Solve()
    {
      int n = input.NextInt();
      long a = input.NextInt();
      long b = input.NextInt();
      long c = input.NextInt();
      int k = 4 - n % 4;
      long x;
      if (k == 4)
      {
        x = 0;
      }
      else if (k == 1)
      {
        x = Min(a, 3 * c, b + c);
      }
      else if (k == 2)
      {
        x = Min(2 * a, b, 2 * c);
      }
      else
      {
        x = Min(3 * a, c);
      }
      Console.Write(x);
    }

    private T Min<T>(params T[] a)
    {
      return a.Min();
    }

    public ProblemSolver(TextReader input)
    {
      this.input = new Tokenizer(input);
    }
  }

  #region Service classes

  public class Tokenizer
  {
    private TextReader reader;

    public int NextInt()
    {
      var c = SkipWS();
      if (c == -1)
        throw new EndOfStreamException();
      bool isNegative = false;
      if (c == '-' || c == '+')
      {
        isNegative = c == '-';
        c = this.reader.Read();
        if (c == -1)
          throw new InvalidOperationException();
      }
      if (!char.IsDigit((char)c))
        throw new InvalidOperationException();
      int result = (char)c - '0';
      c = this.reader.Read();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        if (!char.IsDigit((char)c))
          throw new InvalidOperationException();
        result = result * 10 + (char)c - '0';
        c = this.reader.Read();
      }
      if (isNegative)
        result = -result;
      return result;
    }

    public string ReadLine()
    {
      return reader.ReadLine();
    }

    public long NextLong()
    {
      return long.Parse(this.NextToken());
    }

    public double NextDouble()
    {
      return double.Parse(this.NextToken(), CultureInfo.InvariantCulture);
    }

    public int[] ReadIntArray(int n)
    {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = NextInt();
      return a;
    }

    public long[] ReadLongArray(int n)
    {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = NextLong();
      return a;
    }

    public double[] ReadDoubleArray(int n)
    {
      double[] a = new double[n];
      for (int i = 0; i < n; i++)
        a[i] = NextDouble();
      return a;
    }

    public string NextToken()
    {
      var c = SkipWS();
      if (c == -1)
        return null;
      var sb = new StringBuilder();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        sb.Append((char)c);
        c = this.reader.Read();
      }
      return sb.ToString();
    }

    private int SkipWS()
    {
      int c = this.reader.Read();
      if (c == -1)
        return c;
      while (c > 0 && char.IsWhiteSpace((char)c))
        c = this.reader.Read();
      return c;
    }

    public Tokenizer(TextReader reader)
    {
      this.reader = reader;
    }
  }

  class Program
  {
    public static void Main(string[] args)
    {
      var solver = new ProblemSolver(Console.In);
      solver.Solve();
    }
  }

  #endregion
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test
{
    class IOHelper : IDisposable
    {
        StreamReader reader;
        StreamWriter writer;

        public IOHelper(string inputFile, string outputFile, Encoding encoding)
        {
            StreamReader iReader;
            StreamWriter oWriter;
            if (inputFile == null)
                iReader = new StreamReader(Console.OpenStandardInput(), encoding);
            else
                iReader = new StreamReader(inputFile, encoding);

            if (outputFile == null)
                oWriter = new StreamWriter(Console.OpenStandardOutput(), encoding);
            else
                oWriter = new StreamWriter(outputFile, false, encoding);

            reader = iReader;
            writer = oWriter;

            curLine = new string[] { };
            curTokenIdx = 0;
        }

        string[] curLine;
        int curTokenIdx;

        char[] whiteSpaces = new char[] { ' ', '\t', '\r', '\n' };

        public string ReadNextToken()
        {
            if (curTokenIdx >= curLine.Length)
            {
                //Read next line
                string line = reader.ReadLine();
                if (line != null)
                    curLine = line.Split(whiteSpaces, StringSplitOptions.RemoveEmptyEntries);
                else
                    curLine = new string[] { };
                curTokenIdx = 0;
            }

            if (curTokenIdx >= curLine.Length)
                return null;

            return curLine[curTokenIdx++];
        }

        public int ReadNextInt()
        {
            return int.Parse(ReadNextToken());
        }

        public double ReadNextDouble()
        {
            var nextToken = ReadNextToken();
            var result = 0.0;
            nextToken = nextToken.Replace(".", System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);
            result = double.Parse(nextToken);
            return result;
        }

        public void Write(string stringToWrite)
        {
            writer.Write(stringToWrite);
        }

        public void WriteLine(string stringToWrite)
        {
            writer.WriteLine(stringToWrite);
        }

        public void WriteLine(double valueToWrite)
        {
            long intPart = (long)valueToWrite;
            double fracPart = valueToWrite - intPart;
            var fracPartStr = fracPart.ToString();
            if (fracPartStr.Length > 1)
                fracPartStr = fracPartStr.Substring(2);
            var strToWrite = string.Format("{0}.{1}", intPart, fracPartStr);
            writer.WriteLine(strToWrite);
        }

        public void Dispose()
        {
            try
            {
                if (reader != null)
                {
                    reader.Dispose();
                }
                if (writer != null)
                {
                    writer.Dispose();
                }
            }
            catch { };
        }

        public void Flush()
        {
            if (writer != null)
            {
                writer.Flush();
            }
        }
    }

    class Program
    {
        protected IOHelper ioHelper;

        int n;
        long a, b, c;

        long result = 0;

        public void Solve()
        {
            n = ioHelper.ReadNextInt();
            a = ioHelper.ReadNextInt();
            b = ioHelper.ReadNextInt();
            c = ioHelper.ReadNextInt();

            if((n%4) == 0)
            {
                result = 0;
            }
            else if((n%4)==1)
            {
                var choice1 = c;

                var choice2 = a + b;

                var choice3 = 3 * a;

                result = Math.Min(Math.Min(choice2, choice3), choice1);
            }
            else if((n%4)==2)
            {
                var choice3 = a + 3 * c;
                var choice1 = 2 * a;
                var choice2 = b;
                var choice4 = 4 * c;

                result = Math.Min(Math.Min(choice1, choice2), Math.Min(choice3, choice4));
            }
            else if((n%4)==3)
            {
                var choice1 = a;
                var choice2 = b + c;
                var choice3 = 3 * c;

                result = Math.Min(Math.Min(choice1, choice2), choice3);
            }

            ioHelper.WriteLine(result.ToString());
            ioHelper.Flush();

            //Console.ReadKey();
        }

        public Program(string inputFile, string outputFile)
        {
            ioHelper = new IOHelper(inputFile, outputFile, Encoding.Default);
            Solve();
            ioHelper.Dispose();
        }

        static void Main(string[] args)
        {
            Program myProgram = new Program(null, null);
        }
    }
}

using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;

namespace TmpSharpProj
{
    class Program
    {
        static void Main()
        {
            Program app = new Program();
            app.Run();
        }

        public void Run()
        {
            long[] ar = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
            long[] c = new long[4] { 2000 * 1000 * 1000, 2000 * 1000 * 1000, 2000 * 1000 * 1000, 2000 * 1000 * 1000 };
            c[0] = 0;
            for (int i = 1; i < 4; i++)
            {
                for (int j = 1; j < 3; j++)
                {
                    if (i - j >= 0)
                    {
                        c[i] = Math.Min(c[i], c[i - j] + ar[j]);
                    }
                }
            }
            Console.WriteLine(c[ar[0] % 4 == 0 ? 0 : 4 - (ar[0] % 4)]);
        }
    }
}

using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;

namespace TmpSharpProj
{
    class Program
    {
        static void Main()
        {
            Program app = new Program();
            app.Run();
        }

        public void Run()
        {
            int[] ar = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            long[] c = Enumerable.Repeat(long.MaxValue, 100).ToArray();
            c[0] = 0;
            for (int i = 1; i < 100; i++)
            {
                for (int j = 1; j < 3; j++)
                {
                    if (i - j >= 0)
                    {
                        c[i] = Math.Min(c[i], c[i - j] + ar[j]);
                    }
                }
            }
            long ans = long.MaxValue;
            for (int i = (ar[0] % 4 == 0 ? 0 : 4 - ar[0] % 4); i < 100; i += 4)
            {
                ans = Math.Min(ans, c[i]);
            }
            Console.WriteLine(ans);
        }
    }
}

using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;

namespace TmpSharpProj
{
    class Program
    {
        static void Main()
        {
            Program app = new Program();
            app.Run();
        }

        public void Run()
        {
            int[] ar = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            int[] c = new int[4] { 2000 * 1000 * 1000, 2000 * 1000 * 1000, 2000 * 1000 * 1000, 2000 * 1000 * 1000 };
            c[0] = 0;
            for (int i = 1; i < 4; i++)
            {
                for (int j = 1; j < 3; j++)
                {
                    if (i - j >= 0)
                    {
                        c[i] = Math.Min(c[i], c[i - j] + ar[j]);
                    }
                }
            }
            Console.WriteLine(c[ar[0] % 4 == 0 ? 0 : 4 - (ar[0] % 4)]);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace tetradki
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(); ;
            long n = long.Parse(s[0]);
            long a = long.Parse(s[1]);
            long b = long.Parse(s[2]);
            long c = long.Parse(s[3]);
            long ans=0;

            switch (n%4)
            {
                case 1:
                    ans = Math.Min(3 * a, Math.Min(a + b, c));
                    break;
                case 2:
                    ans = Math.Min(2 * a, b);
                    break;
                case 3:
                    ans = a;
                    break;
            }

            Console.Write(ans);

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace tetradki
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(); ;
            int n = int.Parse(s[0]);
            int a = int.Parse(s[1]);
            int b = int.Parse(s[2]);
            int c = int.Parse(s[3]);
            int ans=0;

            switch (n%4)
            {
                case 1:
                    ans = Math.Min(3 * a, Math.Min(a + b, c));
                    break;
                case 2:
                    ans = Math.Min(2 * a, b);
                    break;
                case 3:
                    ans = a;
                    break;
            }

            Console.Write(ans);

        }
    }
}

using System;
using System.IO;
using System.Text;

namespace Alyona_and_copybooks
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            long n = Next(), a = Next(), b = Next(), c = Next();

            long amount = 0;
            switch (n%4)
            {
                case 0:
                    break;
                case 1:
                    amount = Math.Min(c, Math.Min(a + a + a, a + b));
                    break;
                case 2:
                    amount = Math.Min(b, Math.Min(a + a, c + c));
                    break;
                case 3:
                    amount = Math.Min(a, b + c);
                    break;
            }

            writer.WriteLine(amount);
            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

using System;
using System.IO;
using System.Text;

namespace Alyona_and_mex
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int n = Next();
            int m = Next();

            int min = n + 1;
            for (int i = 0; i < m; i++)
            {
                int l = Next();
                int r = Next();
                min = Math.Min(min, r - l + 1);
            }

            writer.WriteLine(min);
            for (int i = 0; i < n; i++)
            {
                writer.Write(i%min);
                writer.Write(' ');
            }
            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

using System;
using System.IO;
using System.Text;

namespace Alyona_and_copybooks
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int n = Next(), a = Next(), b = Next(), c = Next();

            int amount = 0;
            switch (n%4)
            {
                case 0:
                    break;
                case 1:
                    amount = Math.Min(c, Math.Min(a + a + a, a + b));
                    break;
                case 2:
                    amount = Math.Min(b, Math.Min(a + a, c + c));
                    break;
                case 3:
                    amount = Math.Min(a, b + c);
                    break;
            }

            writer.WriteLine(amount);
            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _740A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            long n = long.Parse(input[0]), a = long.Parse(input[1]), b = long.Parse(input[2]), c = long.Parse(input[3]);
            long result = 0;
            switch (4 - n % 4)
            {
                case 1:
                    result = Math.Min(a, Math.Min(3 * c, b + c));
                    break;

                case 2:
                    result = Math.Min(2 * a, Math.Min(b, 2 * c));
                    break;

                case 3:
                    result = Math.Min(3 * a, c);
                    break;
            }
            Console.WriteLine(result);
            //Console.ReadLine();
        }
    }
}

using System;

namespace CodeForces4
{
	class Program
	{
		static void Main(string[] args)
		{
			string[] Data = Console.ReadLine().Split(' ');
			int[] data = Array.ConvertAll(Data, x => int.Parse(x));
			long one = minimum(data[1], data[2] + data[3], 3 * data[3]);
			long two = minimum(data[2], 2 * data[1], 2 * data[3]);
			long three = minimum(3 * data[1], data[1] + data[2], data[3]);
			switch ((4 - data[0]%4)%4)
			{
				case 0:
					Console.WriteLine('0');
					break;
				case 1:
					Console.WriteLine(one);
					break;
				case 2:
					Console.WriteLine(two);
					break;
				case 3:
					Console.WriteLine(three);
					break;
			}
		}

		static long minimum(long x1, long x2, long x3)
		{
			return x1 < x2 ? x1 < x3 ? x1 : x3 : x2 < x3 ? x2 : x3;
		}
	}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace contest1012
{
    class Program
    {
        static void Main(string[] args)
        {

            var cp = Console.ReadLine().Split(' ').Select(k => int.Parse(k)).ToArray();

            var n = cp[0];
            var a = cp[1];
            var b = cp[2];
            var c = cp[3];

            var h = 0;

            if (n < 4)
                h = 4 - n;
            else
                h = n % 4;

            if (h == 1)
            {
                Console.WriteLine(a);
                return;
            }
            else if (h == 2)
            {
                Console.WriteLine(b);
                return;
            }
            else if (h == 3)
            {
                Console.WriteLine(c);
                return;
            }

            var cbooks = h % 3;
            if (cbooks == 0)
            {
                Console.WriteLine((h / 3) * c);
                return;
            }
            else
            {
              var bbooks  = cbooks % 2;
              if (bbooks == 0)
              {
                  Console.WriteLine(((h / 3) * c) + ((cbooks / 2) * b));
                  return;
              }
              else
              {
                  Console.WriteLine(((h / 3) * c) + ((cbooks) * a));
                  return;
              }

            }

        }
    }
}
;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace contest1012
{
    class Program
    {
        static void Main(string[] args)
        {

            var cp = Console.ReadLine().Split(' ').Select(k => long.Parse(k)).ToArray();

            var n = cp[0];
            var a = cp[1];
            var b = cp[2];
            var c = cp[3];
            long counta, countb,countc;

            var h = 0;

            if(h == 0)
            {
                Console.WriteLine(0);
                return;
            }
            else if (h == 1)
            {
                countc = c;
                countb = b + a;
                counta = 3 * a;
                if ((countc <= countb) && (countc <= counta))
                {
                    Console.WriteLine(countc);
                }
                else if ((countb <= countc) && (countb <= counta))
                {
                    Console.WriteLine(countb);
                }
                else if ((counta <= countb) && (counta <= countc))
                {
                    Console.WriteLine(counta);
                }
            }
            else if (h == 2)
            {
                countc = 2 * c;
                countb = b;
                counta = 2 * a;
                if ((countc <= countb) && (countc <= counta))
                {
                    Console.WriteLine(countc);
                }
                else if ((countb <= countc) && (countb <= counta))
                {
                    Console.WriteLine(countb);
                }
                else if ((counta <= countb) && (counta <= countc))
                {
                    Console.WriteLine(counta);
                }
            }
            else if (h == 3)
            {
                countc = 3 * c;
                countb = b + c;
                counta = a;
                if ((countc <= countb) && (countc <= counta))
                {
                    Console.WriteLine(countc);
                }
                else if ((countb <= countc) && (countb <= counta))
                {
                    Console.WriteLine(countb);
                }
                else if ((counta <= countb) && (counta <= countc))
                {
                    Console.WriteLine(counta);
                }
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, a, b, c;
            string[] num = Console.ReadLine().Split(' ');
            n = int.Parse(num[0]);
            a = int.Parse(num[1]);
            b = int.Parse(num[2]);
            c = int.Parse(num[3]);
            int[] mas = new int[6];

            if (n % 4 == 0) Console.WriteLine(0);

            if (n % 4 == 3)
            {
                mas[0] = a;
                mas[1] = c * 3;
                mas[3] = mas[0];
                for (int i = 0; i < 1; i++)
                {
                    if (mas[3] > mas[i]) mas[3] = mas[i];
                }
                Console.WriteLine(mas[3]);
            }

            if (n % 4 == 2)
            {
                mas[0] = a * 2;
                mas[1] = b;
                mas[2] = c * 2;
                mas[3] = mas[0];
                for (int i = 0; i < 2; i++)
                {
                    if (mas[3] > mas[i]) mas[3] = mas[i];
                }
                Console.WriteLine(mas[3]);
            }

            if (n % 4 == 1)
            {
                mas[0] = a * 3;
                mas[1] = a + b;
                mas[2] = c;
                if (mas[0] > mas[1]) mas[4] = mas[1];
                else mas[4] = mas[0];
                if (mas[4] > mas[2]) Console.WriteLine(mas[2]);
                else Console.WriteLine(mas[4]);
            }

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            long n, a, b, c;
            string[] num = Console.ReadLine().Split(' ');
            n = int.Parse(num[0]);
            a = int.Parse(num[1]);
            b = int.Parse(num[2]);
            c = int.Parse(num[3]);
            long[] mas = new long[6];

            if (n % 4 == 0) Console.WriteLine(0);

            if (n % 4 == 3)
            {
                mas[0] = a;
                mas[1] = c * 3;
                mas[3] = mas[0];
                for (int i = 0; i < 1; i++)
                {
                    if (mas[3] > mas[i]) mas[3] = mas[i];
                }
                Console.WriteLine(mas[3]);
            }

            if (n % 4 == 2)
            {
                mas[0] = a * 2;
                mas[1] = b;
                mas[2] = c * 2;
                mas[3] = mas[0];
                for (int i = 0; i < 2; i++)
                {
                    if (mas[3] > mas[i]) mas[3] = mas[i];
                }
                Console.WriteLine(mas[3]);
            }

            if (n % 4 == 1)
            {
                mas[0] = a * 3;
                mas[1] = a + b;
                mas[2] = c;
                if (mas[0] > mas[1]) mas[4] = mas[1];
                else mas[4] = mas[0];
                if (mas[4] > mas[2]) Console.WriteLine(mas[2]);
                else Console.WriteLine(mas[4]);
            }

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, a, b, c;
            string[] num = Console.ReadLine().Split(' ');
            n = int.Parse(num[0]);
            a = int.Parse(num[1]);
            b = int.Parse(num[2]);
            c = int.Parse(num[3]);
            int[] mas = new int[6];

            if (n % 4 == 0) Console.WriteLine(0);

            if (n % 4 == 3) Console.WriteLine(a);

            if (n % 4 == 2)
            {
                mas[0] = a * 2;
                mas[1] = b;
                if (mas[0] > mas[1]) Console.WriteLine(mas[1]);
                else Console.WriteLine(mas[0]);
            }

            if (n % 4 == 1)
            {
                mas[0] = a * 3;
                mas[1] = a + b;
                mas[2] = c;
                if (mas[0] > mas[1]) mas[4] = mas[1];
                else mas[4] = mas[0];
                if (mas[4] > mas[2]) Console.WriteLine(mas[2]);
                else Console.WriteLine(mas[4]);
            }

        }
    }
}

using System;

namespace acsv2
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var line = Console.ReadLine().Trim().Split();
            var n = Int64.Parse(line[0]);
            var a = Int64.Parse(line[1]);
            var b = Int64.Parse(line[2]);
            var c = Int64.Parse(line[3]);

            long answer = 0;

            if (n % 4 == 0) {
                answer = 0;
            }
            else if ((n + 1) % 4 == 0) {
                answer = Math.Min(Math.Min(a, b + c), c);
            }
            else if ((n + 2) % 4 == 0) {
                answer = Math.Min(Math.Min(a * 2, b), c * 2);
            }
            else if ((n + 3) % 4 == 0) {
                answer = Math.Min(Math.Min(a * 3, a + b), c);
            }

            Console.WriteLine(answer);
        }
    }
}

using System;

namespace acs
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var line = Console.ReadLine().Trim().Split();
            var n = Int64.Parse(line[0]);
            var a = Int64.Parse(line[1]);
            var b = Int64.Parse(line[2]);
            var c = Int64.Parse(line[3]);

            var r = n / 4 + (n % 4 == 0 ? 0 : 1);
            var k = r * 4 - n;

            if (k == 0) {
                Console.WriteLine(0);
            }
            else {
                var c_abc = k / 3;
                var b_abc = (k - c_abc) / 2;
                var a_abc = k - c_abc - b_abc;
                var answer_abc = a * a_abc + b * b_abc + c * c_abc;

                var a_a = k;
                var answer_a = a_a * a;

                var answer = Math.Min(answer_abc, answer_a);

                var b_b = k / 2;
                if (k % 2 == 0) {
                    answer = Math.Min(answer, b_b * b);
                }

                var c_c = k / 3;
                if (k % 3 == 0) {
                    answer = Math.Min(answer, c_c * c);
                }

                var b_ab = k / 2;
                var a_ab = k - b_ab;
                answer = Math.Min(answer, a_ab * a + b_ab * b);

                var c_ac = k / 3;
                var a_ac = k - c_ac;
                answer = Math.Min(answer, a_ac * a + c_ac * c);

                var c_bc = k / 3;
                var b_bc = (k - c_bc) / 2;
                if ((k - c_bc) % 2 == 0) {
                    answer = Math.Min(answer, b_bc * b + c_bc * c);
                }

                Console.WriteLine(answer);
            }
        }
    }
}

using System;

namespace acs
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var line = Console.ReadLine().Trim().Split();
            var n = Int64.Parse(line[0]);
            var a = Int64.Parse(line[1]);
            var b = Int64.Parse(line[2]);
            var c = Int64.Parse(line[3]);

            var r = n / 4 + (n % 4 == 0 ? 0 : 1);
            var k = r * 4 - n;

            if (k == 0) {
                Console.WriteLine(0);
            }
            else {
                var c_abc = k / 3;
                var b_abc = (k - c_abc) / 2;
                var a_abc = k - c_abc * 3 - b_abc * 2;
                var answer_abc = a * a_abc + b * b_abc + c * c_abc;

                var answer_a = k * a;

                var answer = Math.Min(answer_abc, answer_a);

                if (k % 2 == 0) {
                    answer = Math.Min(answer, (k / 2) * b);
                }

                if (k % 3 == 0) {
                    answer = Math.Min(answer, (k / 3) * c);
                }

                var b_ab = k / 2;
                var a_ab = k - b_ab * 2;
                answer = Math.Min(answer, a_ab * a + b_ab * b);

                var c_ac = k / 3;
                var a_ac = k - c_ac * 3;
                answer = Math.Min(answer, a_ac * a + c_ac * c);

                var c_bc = k / 3;
                var b_bc = (k - c_bc * 3) / 2;
                if ((k - c_bc * 3) % 2 == 0) {
                    answer = Math.Min(answer, b_bc * b + c_bc * c);
                }

                Console.WriteLine(answer);
            }
        }
    }
}

using System;

namespace acsv2
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var line = Console.ReadLine().Trim().Split();
            var n = Int64.Parse(line[0]);
            var a = Int64.Parse(line[1]);
            var b = Int64.Parse(line[2]);
            var c = Int64.Parse(line[3]);

            long answer = 0;

            if (n % 4 == 0) {
                answer = 0;
            }
            else if ((n + 1) % 4 == 0) {
                answer = a;
            }
            else if ((n + 2) % 4 == 0) {
                answer = Math.Min(a * 2, b);
            }
            else if ((n + 3) % 4 == 0) {
                answer = Math.Min(Math.Min(a * 3, a + b), c);
            }

            Console.WriteLine(answer);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using static Template;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pi = Pair<int, int>;

class Solver
{
    public void Solve(Scanner sc)
    {
        int n = sc.Next<int>();
        var A = new long[3];
        for (var i = 0; i < 3; i++) A[i] = sc.Next<long>();
        var o = (4L - n % 4) % 4;if (o == 0) Fail(0);
        var min = o * A[0];
        if (o == 1) Fail(Min(min,A[2]*3));
        if (o == 2) Fail(Min(min, Min(A[1],A[2]*2)));
        if (o == 3) WriteLine(Min(min, A[2]));
    }
}

#region Template
public class Template
{
    static void Main(string[] args)
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver().Solve(new Scanner());
        Console.Out.Flush();
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmin<T>(ref T a, T b) where T : IComparable<T>
    { if (a.CompareTo(b) == 1) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmax<T>(ref T a, T b) where T : IComparable<T>
    { if (a.CompareTo(b) == -1) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(ref T a, ref T b)
    { var t = b; b = a; a = t; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static T[] Create<T>(int n, Func<T> f)
    {
        var rt = new T[n];
        for (var i = 0; i < rt.Length; ++i)
            rt[i] = f();
        return rt;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static T[] Create<T>(int n, Func<int, T> f)
    {
        var rt = new T[n];
        for (var i = 0; i < rt.Length; ++i)
            rt[i] = f(i);
        return rt;
    }
    public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }
}

public class Scanner
{
    public string Str => ReadLine().Trim();
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
    public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
    public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
    public int[] ArrInt1D(int n) => Create(n, () => Int);
    public long[] ArrLong1D(int n) => Create(n, () => Long);
    public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
    public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
    public Pair<T1, T2> PairMake<T1, T2>() => new Pair<T1, T2>(Next<T1>(), Next<T2>());
    public Pair<T1, T2, T3> PairMake<T1, T2, T3>() => new Pair<T1, T2, T3>(Next<T1>(), Next<T2>(), Next<T3>());
    private Queue<string> q = new Queue<string>();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }
    public void Make<T1>(out T1 v1) => v1 = Next<T1>();
    public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); }
    public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); }
    public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); }
    public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); }
    public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); }
}

public class Pair<T1, T2> : IComparable<Pair<T1, T2>>
{
    public T1 v1;
    public T2 v2;
    public Pair() { }
    public Pair(T1 v1, T2 v2)
    { this.v1 = v1; this.v2 = v2; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2> p)
    {
        var c = Comparer<T1>.Default.Compare(v1, p.v1);
        if (c == 0)
            c = Comparer<T2>.Default.Compare(v2, p.v2);
        return c;
    }
    public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
    public void Tie(out T1 a, out T2 b) { a = v1; b = v2; }
}

public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>>
{
    public T3 v3;
    public Pair() : base() { }
    public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2)
    { this.v3 = v3; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2, T3> p)
    {
        var c = base.CompareTo(p);
        if (c == 0)
            c = Comparer<T3>.Default.Compare(v3, p.v3);
        return c;
    }
    public override string ToString() => $"{base.ToString()} {v3.ToString()}";
    public void Tie(out T1 a, out T2 b, out T3 c) { Tie(out a, out b); c = v3; }
}
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using static Template;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pi = Pair<int, int>;

class Solver
{
    public void Solve(Scanner sc)
    {
        int n = sc.Next<int>();
        var A = new int[3];
        for (var i = 0; i < 3; i++) A[i] = sc.Next<int>();
        var o = (4L - n % 4) % 4;if (o == 0) Fail(0);
        var min = o * A[0];
        if (o == 1) Fail(min);
        if (o == 2) Fail(Min(min, A[1]));
        if (o == 3) WriteLine(Min(min, A[2]));
    }
}

#region Template
public class Template
{
    static void Main(string[] args)
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver().Solve(new Scanner());
        Console.Out.Flush();
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmin<T>(ref T a, T b) where T : IComparable<T>
    { if (a.CompareTo(b) == 1) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmax<T>(ref T a, T b) where T : IComparable<T>
    { if (a.CompareTo(b) == -1) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(ref T a, ref T b)
    { var t = b; b = a; a = t; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static T[] Create<T>(int n, Func<T> f)
    {
        var rt = new T[n];
        for (var i = 0; i < rt.Length; ++i)
            rt[i] = f();
        return rt;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static T[] Create<T>(int n, Func<int, T> f)
    {
        var rt = new T[n];
        for (var i = 0; i < rt.Length; ++i)
            rt[i] = f(i);
        return rt;
    }
    public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }
}

public class Scanner
{
    public string Str => ReadLine().Trim();
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
    public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
    public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
    public int[] ArrInt1D(int n) => Create(n, () => Int);
    public long[] ArrLong1D(int n) => Create(n, () => Long);
    public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
    public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
    public Pair<T1, T2> PairMake<T1, T2>() => new Pair<T1, T2>(Next<T1>(), Next<T2>());
    public Pair<T1, T2, T3> PairMake<T1, T2, T3>() => new Pair<T1, T2, T3>(Next<T1>(), Next<T2>(), Next<T3>());
    private Queue<string> q = new Queue<string>();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }
    public void Make<T1>(out T1 v1) => v1 = Next<T1>();
    public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); }
    public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); }
    public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); }
    public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); }
    public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); }
}

public class Pair<T1, T2> : IComparable<Pair<T1, T2>>
{
    public T1 v1;
    public T2 v2;
    public Pair() { }
    public Pair(T1 v1, T2 v2)
    { this.v1 = v1; this.v2 = v2; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2> p)
    {
        var c = Comparer<T1>.Default.Compare(v1, p.v1);
        if (c == 0)
            c = Comparer<T2>.Default.Compare(v2, p.v2);
        return c;
    }
    public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
    public void Tie(out T1 a, out T2 b) { a = v1; b = v2; }
}

public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>>
{
    public T3 v3;
    public Pair() : base() { }
    public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2)
    { this.v3 = v3; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2, T3> p)
    {
        var c = base.CompareTo(p);
        if (c == 0)
            c = Comparer<T3>.Default.Compare(v3, p.v3);
        return c;
    }
    public override string ToString() => $"{base.ToString()} {v3.ToString()}";
    public void Tie(out T1 a, out T2 b, out T3 c) { Tie(out a, out b); c = v3; }
}
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, a, b, c;
            var s = Console.ReadLine().Split(' ');
            n = int.Parse(s[0]);
            a = int.Parse(s[1]);
            b = int.Parse(s[2]);
            c = int.Parse(s[3]);
            if (n % 4 == 0)
            {
                Console.WriteLine(0);
                return ;
            }

            if (n % 4 == 1)
            {
                int res = 3 * a;
                if (res > c) res = c;
                if (res > a + b) res = a + b;
                Console.WriteLine(res);
                return ;
            }

            if (n % 4 == 2)
            {
                int res = b;
                if (res > 2 * a) res = 2 * a;
                if (res > 2 * c) res = 2 * c;
                Console.WriteLine(res);
                return ;
            }

            if (n % 4 == 3)
            {
                int res = a;
                if (res > 3 * c) res = 3 * c;
                if (res > b + c) res = b + c;
                Console.WriteLine(res);
                return ;
            }
        }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, a, b, c;
            n = Console.Read();
            a = Console.Read();
            b = Console.Read();
            c = Console.Read();
            if (n % 4 == 0)
            {
                Console.WriteLine(0);
            }

            if (n % 4 == 1)
            {
                int res = 3 * a;
                if (res > c) res = c;
                if (res > a + b) res = a + b;
                Console.WriteLine(res);
            }

            if (n % 4 == 2)
            {
                int res = b;
                if (res > 2 * a) res = 2 * a;
                if (res > 2 * c) res = 2 * c;
                Console.WriteLine(res);
            }

            if (n % 4 == 3)
            {
                int res = a;
                if (res > 3 * c) res = 3 * c;
                if (res > b + c) res = b + c;
                Console.WriteLine(res);
            }
        }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, a, b, c;
            n = Console.Read();
            a = Console.Read();
            b = Console.Read();
            c = Console.Read();
            if (n % 4 == 0)
            {
                Console.WriteLine(0);
            }

            if (n % 4 == 1)
            {
                int res = 3 * a;
                if (res > c) res = c;
                if (res > a + b) res = a + b;
                Console.WriteLine(res);
            }

            if (n % 4 == 2)
            {
                int res = b;
                if (res > 2 * a) res = 2 * a;
                if (res > 2 * c) res = 2 * c;
                Console.WriteLine(res);
            }

            if (n % 4 == 3)
            {
                int res = a;
                if (res > 3 * c) res = 3 * c;
                if (res > b + c) res = b + c;
                Console.WriteLine(res);
            }

            Console.ReadLine();
        }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, a, b, c;
            n = Console.Read();
            a = Console.Read();
            b = Console.Read();
            c = Console.Read();
            if (n % 4 == 0)
            {
                Console.WriteLine(0);
                return ;
            }

            if (n % 4 == 1)
            {
                int res = 3 * a;
                if (res > c) res = c;
                if (res > a + b) res = a + b;
                Console.WriteLine(res);
                return ;
            }

            if (n % 4 == 2)
            {
                int res = b;
                if (res > 2 * a) res = 2 * a;
                if (res > 2 * c) res = 2 * c;
                Console.WriteLine(res);
                return ;
            }

            if (n % 4 == 3)
            {
                int res = a;
                if (res > 3 * c) res = 3 * c;
                if (res > b + c) res = b + c;
                Console.WriteLine(res);
                return ;
            }
        }

    }
}

using System;

public class Test
{
	public static void Main()
	{
		string s = Console.ReadLine();
		string[] temp = s.Split(' ');
		int n= Convert.ToInt32(temp[0]);
		int a = Convert.ToInt32(temp[1]);
		int b= Convert.ToInt32(temp[2]);
		int c = Convert.ToInt32(temp[3]);
		int[,] mass = new int[9,3]{{3,0,0},{1,1,0},{0,0,1},{2,0,0},{0,1,0},{0,0,2},{1,0,0},{0,1,1},{0,0,3}};
		long min =99999999999;
		if (n%4==0) min=0;
		else
		for (int i=(n%4-1);i<(n%4-1)+3;i++)
		{
			long sum=a*mass[i,0]+b*mass[i,1]+c*mass[i,2];
			if (sum<min) min=sum;
		}
		Console.WriteLine(min);
	}
}

/* Date: 26.11.2016 * Time: 21:45 */
//       29.01.2017
// *
// ������������ ����� �� ����� 17
// ������������ ����� �� ����� 21

/*
�	fflush(stdout) � ����� C++;
�	System.out.flush() � Java;
�	stdout.flush() � Python;
�	flush(output) � Pascal;
*/

using System;
using System.IO;
using System.Globalization;

class Example
{
	public static void Main (string[] args)
	{
# if ( ONLINE_JUDGE )

# else
		StreamReader sr = new StreamReader ("C:\\TRR\\2017\\Task\\07 Codeforces\\021\\A.TXT");
		StreamWriter sw = new StreamWriter ("C:\\TRR\\2017\\Task\\07 Codeforces\\021\\A.OUT");
# endif

		string ss;

# if ( ONLINE_JUDGE )
		ss = Console.ReadLine ();
# else
		ss = sr.ReadLine ();
		sw.WriteLine (ss);
# endif

		string [] s = ss.Split (' ');
		Int64 n = Int64.Parse (s [0]);
		Int64 a = Int64.Parse (s [1]);
		Int64 b = Int64.Parse (s [2]);
		Int64 c = Int64.Parse (s [3]);

		Int64 m = (4 - n % 4) % 4, k = 0;
		switch ( m )
		{
			case 1 :
				if ( a <= b + c )
					k = a;
				else if ( 3 * c < a )
					k = 3 * c;
				else
					k = a + b;
				break;
			case 2 :
				if ( 2 * a <= b && 2 * a <= c + c)
					k = 2 * a;
				else if ( a >= b && b <= c + c)
					k = b;
				else
					k = c + c;
				break;
			case 3 :
				if ( 3 * a <= c && 2 * a <= b )
					k = 3 * a;
				else if ( c <= 3 * a && c <= a + b )
					k = c;
				else
					k = b + a;
				break;
		}

# if ( ONLINE_JUDGE )
		Console.WriteLine (k);
# else
		sw.WriteLine (k);
# endif

# if ( ! ONLINE_JUDGE )
		sw.Close ();
# endif

	}
}

/*
   long long N, A, B, C;
    cin >> N >> A >> B >> C;
    if (N % 4 == 0) {
        cout << 0 << endl;
    } else
    if (N % 4 == 1) {
        cout << min(min(C, A + B), A * 3) << endl;
    } else
    if (N % 4 == 2) {
        cout << min(min(B, C + C), A + A) << endl;
    } else {
        cout << min(min(A, B + C), C * 3) << endl;
    }

if(n%4==0)cout<<"0\n";
	else if(n%4==1)cout<<min(c,min(a+b,3*a))<<'\n';
	else if(n%4==2)cout<<min(c*2,min(a*2,b))<<'\n';
	else cout<<min(3*c,min(a,b+c))<<'\n';
 */

/* Date: 26.11.2016 * Time: 21:45 */
// *
// ������������ ����� �� ����� 7

/*
�	fflush(stdout) � ����� C++;
�	System.out.flush() � Java;
�	stdout.flush() � Python;
�	flush(output) � Pascal;
*/

using System;
using System.IO;
using System.Globalization;

class Example
{
	public static void Main (string[] args)
	{
# if ( ONLINE_JUDGE )

# else
		StreamReader sr = new StreamReader ("C:\\TRR\\2016\\Task\\07 Codeforces\\021\\A.TXT");
		StreamWriter sw = new StreamWriter ("C:\\TRR\\2016\\Task\\07 Codeforces\\021\\A.OUT");
# endif

		string ss;

# if ( ONLINE_JUDGE )
		ss = Console.ReadLine ();
# else
		ss = sr.ReadLine ();
		sw.WriteLine (ss);
# endif

		string [] s = ss.Split (' ');
		Int64 n = Int64.Parse (s [0]);
		Int64 a = Int64.Parse (s [1]);
		Int64 b = Int64.Parse (s [2]);
		Int64 c = Int64.Parse (s [3]);

		Int64 m = ((4 - n % 4) % 4), k = 0;
		switch ( m )
		{
			case 1 :
				if ( a <= c && a <= b )
					k = a;
				else if ( b <= a && b <= c )
					k = b;
				else
					k = c;
				break;
			case 2 :
				if ( 2*a <= b )
					k = 2 * a;
				else
					k = b;
				break;
			case 3 :
				if ( 3*a <= c && 2*a <= b )
					k = 3 * a;
				else if ( c <= 3*a && c <= a + b )
					k = c;
				else
					k = b + a;
				break;
		}

# if ( ONLINE_JUDGE )
		Console.WriteLine (k);
# else
		sw.WriteLine (k);
# endif

# if ( ! ONLINE_JUDGE )
		sw.Close ();
# endif

	}
}

/* Date: 26.11.2016 * Time: 21:45 */
//       29.01.2017
// *

/*
�	fflush(stdout) � ����� C++;
�	System.out.flush() � Java;
�	stdout.flush() � Python;
�	flush(output) � Pascal;
*/

using System;
using System.IO;
using System.Globalization;

class Example
{
	public static void Main (string[] args)
	{
# if ( ONLINE_JUDGE )

# else
		StreamReader sr = new StreamReader ("C:\\TRR\\2017\\Task\\07 Codeforces\\021\\A.TXT");
		StreamWriter sw = new StreamWriter ("C:\\TRR\\2017\\Task\\07 Codeforces\\021\\A.OUT");
# endif

		string ss;

# if ( ONLINE_JUDGE )
		ss = Console.ReadLine ();
# else
		ss = sr.ReadLine ();
		sw.WriteLine (ss);
# endif

		string [] s = ss.Split (' ');
		Int64 n = Int64.Parse (s [0]);
		Int64 a = Int64.Parse (s [1]);
		Int64 b = Int64.Parse (s [2]);
		Int64 c = Int64.Parse (s [3]);

		Int64 m = (4 - n % 4) % 4, k = 0;
		switch ( m )
		{
			case 1 :
				if ( a <= b + c )
					k = a;
				else
					k = a + b;
				break;
			case 2 :
				if ( 2 * a <= b && 2 * a <= c + c)
					k = 2 * a;
				else if ( a >= b && b <= c + c)
					k = b;
				else
					k = c + c;
				break;
			case 3 :
				if ( 3 * a <= c && 2 * a <= b )
					k = 3 * a;
				else if ( c <= 3 * a && c <= 2 + b )
					k = c;
				else
					k = b + a;
				break;
		}

# if ( ONLINE_JUDGE )
		Console.WriteLine (k);
# else
		sw.WriteLine (k);
# endif

# if ( ! ONLINE_JUDGE )
		sw.Close ();
# endif

	}
}

/*
   long long N, A, B, C;
    cin >> N >> A >> B >> C;
    if (N % 4 == 0) {
        cout << 0 << endl;
    } else
    if (N % 4 == 1) {
        cout << min(min(C, A + B), A * 3) << endl;
    } else
    if (N % 4 == 2) {
        cout << min(min(B, C + C), A + A) << endl;
    } else {
        cout << min(min(A, B + C), C * 3) << endl;
    }

if(n%4==0)cout<<"0\n";
	else if(n%4==1)cout<<min(c,min(a+b,3*a))<<'\n';
	else if(n%4==2)cout<<min(c*2,min(a*2,b))<<'\n';
	else cout<<min(3*c,min(a,b+c))<<'\n';
 */

/* Date: 26.11.2016 * Time: 21:45 */
//       29.01.2017
// *
// ������������ ����� �� ����� 17
// ������������ ����� �� ����� 21
// ������������ ����� �� ����� 26

/*
�	fflush(stdout) � ����� C++;
�	System.out.flush() � Java;
�	stdout.flush() � Python;
�	flush(output) � Pascal;
*/

using System;
using System.IO;
using System.Globalization;

class Example
{
	public static void Main (string[] args)
	{
# if ( ONLINE_JUDGE )

# else
		StreamReader sr = new StreamReader ("C:\\TRR\\2017\\Task\\07 Codeforces\\021\\A.TXT");
		StreamWriter sw = new StreamWriter ("C:\\TRR\\2017\\Task\\07 Codeforces\\021\\A.OUT");
# endif

		string ss;

# if ( ONLINE_JUDGE )
		ss = Console.ReadLine ();
# else
		ss = sr.ReadLine ();
		sw.WriteLine (ss);
# endif

		string [] s = ss.Split (' ');
		Int64 n = Int64.Parse (s [0]);
		Int64 a = Int64.Parse (s [1]);
		Int64 b = Int64.Parse (s [2]);
		Int64 c = Int64.Parse (s [3]);

		Int64 m = (4 - n % 4) % 4, k = 0;
		switch ( m )
		{
			case 1 :
				if ( a <= b + c && a <= 3 * c )
					k = a;
				else if ( 3 * c < a && 2 * c <= b )
					k = 3 * c;
				else
					k = a + b;
				break;
			case 2 :
				if ( 2 * a <= b && a <= c)
					k = 2 * a;
				else if ( 2 * a >= b && b <= c + c)
					k = b;
				else
					k = c + c;
				break;
			case 3 :
				if ( 3 * a <= c && 2 * a <= b )
					k = 3 * a;
				else if ( c <= 3 * a && c <= a + b )
					k = c;
				else
					k = b + a;
				break;
		}

# if ( ONLINE_JUDGE )
		Console.WriteLine (k);
# else
		sw.WriteLine (k);
# endif

# if ( ! ONLINE_JUDGE )
		sw.Close ();
# endif

	}
}

/*
   long long N, A, B, C;
    cin >> N >> A >> B >> C;
    if (N % 4 == 0) {
        cout << 0 << endl;
    } else
    if (N % 4 == 1) {
        cout << min(min(C, A + B), A * 3) << endl;
    } else
    if (N % 4 == 2) {
        cout << min(min(B, C + C), A + A) << endl;
    } else {
        cout << min(min(A, B + C), C * 3) << endl;
    }

if(n%4==0)cout<<"0\n";
	else if(n%4==1)cout<<min(c,min(a+b,3*a))<<'\n';
	else if(n%4==2)cout<<min(c*2,min(a*2,b))<<'\n';
	else cout<<min(3*c,min(a,b+c))<<'\n';

	lint ret = 1e18;
	for( int i=0; i < 22; i++ )
		for( int j=0; j < 22; j++ )
			for( int k=0; k < 22; k++ )
				if ( (n + i + j + j + k + k + k) % 4 == 0 )
					ret = min(ret, a * i + b * j + c * k);

} */

/* Date: 26.11.2016 * Time: 21:45 */
//       29.01.2017
// *
// ������������ ����� �� ����� 17

/*
�	fflush(stdout) � ����� C++;
�	System.out.flush() � Java;
�	stdout.flush() � Python;
�	flush(output) � Pascal;
*/

using System;
using System.IO;
using System.Globalization;

class Example
{
	public static void Main (string[] args)
	{
# if ( ONLINE_JUDGE )

# else
		StreamReader sr = new StreamReader ("C:\\TRR\\2017\\Task\\07 Codeforces\\021\\A.TXT");
		StreamWriter sw = new StreamWriter ("C:\\TRR\\2017\\Task\\07 Codeforces\\021\\A.OUT");
# endif

		string ss;

# if ( ONLINE_JUDGE )
		ss = Console.ReadLine ();
# else
		ss = sr.ReadLine ();
		sw.WriteLine (ss);
# endif

		string [] s = ss.Split (' ');
		Int64 n = Int64.Parse (s [0]);
		Int64 a = Int64.Parse (s [1]);
		Int64 b = Int64.Parse (s [2]);
		Int64 c = Int64.Parse (s [3]);

		Int64 m = (4 - n % 4) % 4, k = 0;
		switch ( m )
		{
			case 1 :
				if ( a <= b + c )
					k = a;
				else
					k = a + b;
				break;
			case 2 :
				if ( 2 * a <= b && 2 * a <= c + c)
					k = 2 * a;
				else if ( a >= b && b <= c + c)
					k = b;
				else
					k = c + c;
				break;
			case 3 :
				if ( 3 * a <= c && 2 * a <= b )
					k = 3 * a;
				else if ( c <= 3 * a && c <= a + b )
					k = c;
				else
					k = b + a;
				break;
		}

# if ( ONLINE_JUDGE )
		Console.WriteLine (k);
# else
		sw.WriteLine (k);
# endif

# if ( ! ONLINE_JUDGE )
		sw.Close ();
# endif

	}
}

/*
   long long N, A, B, C;
    cin >> N >> A >> B >> C;
    if (N % 4 == 0) {
        cout << 0 << endl;
    } else
    if (N % 4 == 1) {
        cout << min(min(C, A + B), A * 3) << endl;
    } else
    if (N % 4 == 2) {
        cout << min(min(B, C + C), A + A) << endl;
    } else {
        cout << min(min(A, B + C), C * 3) << endl;
    }

if(n%4==0)cout<<"0\n";
	else if(n%4==1)cout<<min(c,min(a+b,3*a))<<'\n';
	else if(n%4==2)cout<<min(c*2,min(a*2,b))<<'\n';
	else cout<<min(3*c,min(a,b+c))<<'\n';
 */

/* Date: 26.11.2016 * Time: 21:45 */
// *

/*
�	fflush(stdout) � ����� C++;
�	System.out.flush() � Java;
�	stdout.flush() � Python;
�	flush(output) � Pascal;
*/

using System;
using System.IO;
using System.Globalization;

class Example
{
	public static void Main (string[] args)
	{
# if ( ONLINE_JUDGE )

# else
		StreamReader sr = new StreamReader ("C:\\TRR\\2016\\Task\\07 Codeforces\\021\\A.TXT");
		StreamWriter sw = new StreamWriter ("C:\\TRR\\2016\\Task\\07 Codeforces\\021\\A.OUT");
# endif

		string ss;

# if ( ONLINE_JUDGE )
		ss = Console.ReadLine ();
# else
		ss = sr.ReadLine ();
		sw.WriteLine (ss);
# endif

		string [] s = ss.Split (' ');
		Int64 n = Int64.Parse (s [0]);
		Int64 a = Int64.Parse (s [1]);
		Int64 b = Int64.Parse (s [2]);
		Int64 c = Int64.Parse (s [3]);

		Int64 m = ((4 - n % 4) % 4), k = 0;
		switch ( m )
		{
			case 1 :
				if ( a <= c && a <= b )
					k = a;
				else if ( b <= a && b <= c )
					k = b;
				else
					k = c;
				break;
			case 2 :
				if ( 2*a <= b )
					k = 2 * a;
				else
					k = b;
				break;
			case 3 :
				if ( 3*a <= c && 3*a <= 2*b )
					k = 3 * a;
				else if ( c <= 3*a && c <= a + b )
					k = c;
				else
					k = b + a;
				break;
		}

# if ( ONLINE_JUDGE )
		Console.WriteLine (k);
# else
		sw.WriteLine (k);
# endif

# if ( ! ONLINE_JUDGE )
		sw.Close ();
# endif

	}
}

using System;

namespace CodeForces4
{
	class Program
	{
		static void Main(string[] args)
		{
			string[] Data = Console.ReadLine().Split(' ');
			int[] data = Array.ConvertAll(Data, x => int.Parse(x));
			int one = minimum(data[1], data[2] + data[3], 3 * data[3]);
			int two = minimum(data[2], 2 * data[1], 2 * data[3]);
			int three = minimum(3 * data[1], data[1] + data[2], data[3]);
			switch ((4 - data[0]%4)%4)
			{
				case 0:
					Console.WriteLine('0');
					break;
				case 1:
					Console.WriteLine(one);
					break;
				case 2:
					Console.WriteLine(two);
					break;
				case 3:
					Console.WriteLine(three);
					break;
			}
		}

		static int minimum(int x1, int x2, int x3)
		{
			return x1 < x2 ? x1 < x3 ? x1 : x3 : x2 < x3 ? x2 : x3;
		}
	}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A_Alena_and_sketchbooks
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] inputFirst = Console.ReadLine().Split(' ');
            int n = Int32.Parse(inputFirst[0]);
            int a = Int32.Parse(inputFirst[1]);
            int b = Int32.Parse(inputFirst[2]);
            int c = Int32.Parse(inputFirst[3]);

            n = n % 4;
            int min = 0;
            int case1, case2, case3;
            switch (n)
            {
                case 0: break;
                case 1: case1 = a + a + a;
                    case2 = a + b; min = Math.Min(case1, case2);
                    case3 = c; min = Math.Min(min, case3); break;
                case 2: case1 = a + a;
                    case2 = b; min = Math.Min(case1, case2);
                    case3 = c + c; min = Math.Min(min, case3); break;
                case 3: case1 = a;
                    case2 = b + c; min = Math.Min(case1, case2);
                    case3 = c + c + c; min = Math.Min(min, case3); break;
            }

            Console.WriteLine(min);
        }
    }
}

using System;

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            var s1 = s.Split(' ');
            long r =0;
            long n = long.Parse(s1[0]);
            long a = long.Parse(s1[1]);
            long b = long.Parse(s1[2]);
            long c = long.Parse(s1[3]);
            if (n % 4 == 0)
                r = 0;
            else
            {
                if (n % 4 == 1)
                {
                    if (c < 3 * a || c < a + b)
                        r = c;
                    else
                    {
                        if (3 * a < c || 3 * a < a + b)
                            r = 3 * a;
                        else
                            r = a + b;
                    }
                }
                else
                {
                    if (n % 4 == 2)
                    {
                        if (b < 2 * a || b < 2 * c)
                            r = b;
                        else
                        {
                            if (2 * a < b || 2 * a < 2 * c)
                                r = 2 * a;
                            else
                                r = 2 * c;
                        }
                    }
                    else
                    {
                        if (a < 3 * c || a < c + b)
                            r = a;
                        else
                        {
                            if (3 * c < a || 3 * c < c + b)
                                r = 3 * c;
                            else
                                r = c + b;
                        }
                    }
                }
            }
                Console.WriteLine(r);
            Console.ReadLine();
        }
    }
}

using System;

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            var s1 = s.Split(' ');
            long r =0;
            long n = long.Parse(s1[0]);
            long a = long.Parse(s1[1]);
            long b = long.Parse(s1[2]);
            long c = long.Parse(s1[3]);
            if (n % 4 == 0)
                r = 0;
            else
            {
                if (n % 4 == 1)
                {
                    if (c <= 3 * a || c <= a + b)
                        r = c;
                    else
                    {
                        if (3 * a <= c || 3 * a <= a + b)
                            r = 3 * a;
                        else
                            r = a + b;
                    }
                }
                else
                {
                    if (n % 4 == 2)
                    {
                        if (b <= 2 * a)
                            r = b;
                        else
                            r = 2 * a;
                    }
                    else
                    {
                        if (a <= 3 * c)
                            r = a;
                        else
                            r = 3 * c;
                    }
                }
            }
                Console.WriteLine(r);
            Console.ReadLine();
        }
    }
}

using System;

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            var s1 = s.Split(' ');
            long r =0;
            long n = long.Parse(s1[0]);
            long a = long.Parse(s1[1]);
            long b = long.Parse(s1[2]);
            long c = long.Parse(s1[3]);
            if (n % 4 == 0)
                r = 0;
            else
            {
                if (n % 4 == 1)
                {
                    if (c < 3 * a || c < a + b)
                        r = c;
                    else
                    {
                        if (3 * a < c || 3 * a < a + b)
                            r = 3 * a;
                        else
                            r = a + b;
                    }
                }
                else
                {
                    if (n % 4 == 2)
                    {
                        if (b < 2 * a)
                            r = b;
                        else
                            r = 2 * a;
                    }
                    else
                    {
                        if (a < 3 * c)
                            r = a;
                        else
                            r = 3 * c;
                    }
                }
            }
                Console.WriteLine(r);
            Console.ReadLine();
        }
    }
}

using System;
using System.Collections.Generic;
using System.IO;

namespace prA {
    class Program {
#if ONLINE_JUDGE
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);
#else
        private static readonly StreamWriter writer = new StreamWriter(@"..\..\output");
        private static readonly StreamReader reader = new StreamReader(@"..\..\input");
#endif

        static void Main(string[] args) {
            int n = Next();
            int a = Next();
            int b = Next();
            int c = Next();
            int i = n % 4;
            if (i == 0)
                writer.Write(0);
            else {
                i = 4 - i;
                int ans = int.MaxValue;
                if (i == 3) {
                    ans = Math.Min(c, Math.Min(3 * a, b + a));
                }else if (i == 2) {
                    ans = Math.Min(b, 2 * a);
                }
                else
                    ans = a;
                writer.Write(ans);
            }

            writer.Flush();
#if !ONLINE_JUDGE
            writer.Close();
#endif
        }
        private static int Next() {
            int c;
            int res = 0;
            do {
                c = reader.Read();
                if(c == -1)
                    return res;
            } while(c != '-' && (c < '0' || c > '9'));
            int sign = 1;
            if(c == '-') {
                sign = -1;
                c = reader.Read();
            }
            res = c - '0';
            while(true) {
                c = reader.Read();
                if(c < '0' || c > '9')
                    return res * sign;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Alyona_and_copybooks
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int n = int.Parse(s[0]);
            int a = int.Parse(s[1]);
            int b = int.Parse(s[2]);
            int c = int.Parse(s[3]);
            int am = 0;
            int k = 4 - (n % 4);
            if (k == 1)
            {
                am += b;
            }
            else if (k == 2)
            {
                am += Math.Min(a * 2, b);
            }
            else if (k == 3)
            {
                if (Math.Min(a * 3, b + a) > c)
                {
                    am += c;
                }
                else
                    am += Math.Min(a * 3, b + a);
            }
            Console.WriteLine(am);
            Console.ReadLine();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Alyona_and_copybooks
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int n = int.Parse(s[0]);
            int a = int.Parse(s[1]);
            int b = int.Parse(s[2]);
            int c = int.Parse(s[3]);
            int am = 0;
            int k = 4 - (n % 4);
            if (k == 1)
            {
                if (Math.Min(c * 3, c+b) > a)
                {
                    am += a;
                }
                else
                    am += Math.Min(c * 3, c + b);
            }
            else if (k == 2)
            {
                if (Math.Min(a * 2, 2*c) > b)
                {
                    am += b;
                }
                else
                    am += Math.Min(a * 2, 2 * c);
            }
            else if (k == 3)
            {
                if (Math.Min(a * 3, b + a) > c)
                {
                    am += c;
                }
                else
                    am += Math.Min(a * 3, b + a);
            }
            Console.WriteLine(am);
            Console.ReadLine();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        static int N, A, B, C;

        static long Solve(int N, int A, int B, int C)
        {
            switch (N % 4)
            {
                case 1:
                    return Math.Min(3L * A, C);

                case 2:
                    return Math.Min(Math.Min(2L * A, B), 2L * C);

                case 3:
                    return Math.Min(A, 3L * C);

                default:
                    return 0;
            }
        }

        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string[] vals = input.Split(' ');
            N = int.Parse(vals[0]);
            A = int.Parse(vals[1]);
            B = int.Parse(vals[2]);
            C = int.Parse(vals[3]);

            Console.WriteLine((int)Solve(N, A, B, C));

            //for (int i = 1; i <= 10; i++)
            //{
            //    for (int j = 1; j <= 10; j++)
            //    {
            //        for (int k = 1; k <= 10; k++)
            //        {
            //            for (int h = 1; h <= 10; h++)
            //            {
            //                Console.WriteLine(string.Format("({0}, {1}, {2}, {3}) -> {4}", i, j, k, h, Solve(i, j, k, h)));
            //            }
            //        }
            //    }
            //}
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        static long N, A, B, C;

        static long Solve(long N, long A, long B, long C)
        {
            switch (N % 4)
            {
                case 1:
                    return Math.Min(Math.Min(3L * A, C), A + B);

                case 2:
                    return Math.Min(Math.Min(2L * A, B), 2L * C);

                case 3:
                    return Math.Min(Math.Min(A, 3L * C), 3L * B + C);

                default:
                    return 0;
            }
        }

        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string[] vals = input.Split(' ');
            N = long.Parse(vals[0]);
            A = long.Parse(vals[1]);
            B = long.Parse(vals[2]);
            C = long.Parse(vals[3]);

            Console.WriteLine(Solve(N, A, B, C));

            //for (int i = 1; i <= 10; i++)
            //{
            //    for (int j = 1; j <= 10; j++)
            //    {
            //        for (int k = 1; k <= 10; k++)
            //        {
            //            for (int h = 1; h <= 10; h++)
            //            {
            //                Console.WriteLine(string.Format("({0}, {1}, {2}, {3}) -> {4}", i, j, k, h, Solve(i, j, k, h)));
            //            }
            //        }
            //    }
            //}

            /*long minVal = long.MaxValue;
            for (int i = 0; i < 1000; i++)
            {
                if (((N + i) % 4) == 0)
                {
                    minVal = Math.Min(minVal, A * i);
                }

                if (((N + 2 * i) % 4) == 0)
                {
                    minVal = Math.Min(minVal, B * i);
                }

                if (((N + 3 * i) % 4) == 0)
                {
                    minVal = Math.Min(minVal, C * i);
                }
            }

            Console.WriteLine(minVal);*/
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        static int N, A, B, C;

        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string[] vals = input.Split(' ');
            N = int.Parse(vals[0]);
            A = int.Parse(vals[1]);
            B = int.Parse(vals[2]);
            C = int.Parse(vals[3]);

            long minVal = long.MaxValue;
            if (N % 4 == 0)
            {
                minVal = 0;
            }
            else
            {
                minVal = (4L - (N % 4)) * A;
                if (N % 4 == 2)
                {
                    minVal = Math.Min(minVal, B);
                    minVal = Math.Min(minVal, 2L * C);
                }

                if (N % 4 == 1)
                {
                    minVal = Math.Min(minVal, C);
                }

                if (N % 4 == 3)
                {
                    minVal = Math.Min(minVal, 3L * C);
                }
            }

            Console.WriteLine(minVal);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        static int N, A, B, C;

        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string[] vals = input.Split(' ');
            N = int.Parse(vals[0]);
            A = int.Parse(vals[1]);
            B = int.Parse(vals[2]);
            C = int.Parse(vals[3]);

            long minVal = int.MaxValue;
            if (N % 4 == 0)
            {
                minVal = 0;
            }
            else
            {
                minVal = (4L - (N % 4)) * A;
                if (N % 4 == 2)
                {
                    minVal = Math.Min(minVal, B);
                }

                if (N % 4 == 1)
                {
                    minVal = Math.Min(minVal, C);
                }

                if (N % 4 == 3)
                {
                    minVal = Math.Min(minVal, 3L * C);
                }
            }

            Console.WriteLine(minVal);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        static int N, A, B, C;

        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string[] vals = input.Split(' ');
            N = int.Parse(vals[0]);
            A = int.Parse(vals[1]);
            B = int.Parse(vals[2]);
            C = int.Parse(vals[3]);

            long minVal = int.MaxValue;
            if (N % 4 == 0)
            {
                minVal = 0;
            }
            else
            {
                minVal = (4L - (N % 4)) * A;
                if (N % 4 == 2)
                {
                    minVal = Math.Min(minVal, B);
                    minVal = Math.Min(minVal, 2L * C);
                }

                if (N % 4 == 1)
                {
                    minVal = Math.Min(minVal, C);
                }

                if (N % 4 == 3)
                {
                    minVal = Math.Min(minVal, 3L * C);
                }
            }

            Console.WriteLine(minVal);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        static long N, A, B, C;

        static long Solve(int N, int A, int B, int C)
        {
            switch (N % 4)
            {
                case 1:
                    return Math.Min(3L * A, C);

                case 2:
                    return Math.Min(Math.Min(2L * A, B), 2L * C);

                case 3:
                    return Math.Min(A, 3L * C);

                default:
                    return 0;
            }
        }

        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string[] vals = input.Split(' ');
            N = long.Parse(vals[0]);
            A = long.Parse(vals[1]);
            B = long.Parse(vals[2]);
            C = long.Parse(vals[3]);

            //Console.WriteLine((int)Solve(N, A, B, C));

            //for (int i = 1; i <= 10; i++)
            //{
            //    for (int j = 1; j <= 10; j++)
            //    {
            //        for (int k = 1; k <= 10; k++)
            //        {
            //            for (int h = 1; h <= 10; h++)
            //            {
            //                Console.WriteLine(string.Format("({0}, {1}, {2}, {3}) -> {4}", i, j, k, h, Solve(i, j, k, h)));
            //            }
            //        }
            //    }
            //}

            long minVal = long.MaxValue;
            for (int i = 0; i < 1000; i++)
            {
                if (((N + i) % 4) == 0)
                {
                    minVal = Math.Min(minVal, A * i);
                }

                if (((N + 2 * i) % 4) == 0)
                {
                    minVal = Math.Min(minVal, B * i);
                }

                if (((N + 3 * i) % 4) == 0)
                {
                    minVal = Math.Min(minVal, C * i);
                }
            }

            Console.WriteLine(minVal);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Numerics;

namespace contest
{

    class contest
    {

        static void Main(string[] args)
        {

            //int n = int.Parse(Console.ReadLine());
            //var input = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //int n = int.Parse(Console.ReadLine());
            var num = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long n = num[0];
            long a = num[1];
            long b = num[2];
            long c = num[3];

            long ruble = long.MaxValue;
            long res = 4 - (n % 4);

            for (int i=1; i<=3; i++)
            {
                long tmp = n + i;

                if(i==1)
                {

                    ruble = Math.Min(num[i]*res, ruble);
                }

                if(i==3 && tmp%4==0)
                {
                    ruble = Math.Min(num[1]+num[2] , ruble);
                }
                if(tmp%4==0)
                {
                    ruble = Math.Min(num[i],ruble);
                }
            }

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

            Console.WriteLine(ruble);

        }

    }

}

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Numerics;

namespace contest
{

    class contest
    {

        static void Main(string[] args)
        {

            //int n = int.Parse(Console.ReadLine());
            //var input = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //int n = int.Parse(Console.ReadLine());
            var num = Console.ReadLine().Split().Select(int.Parse).ToArray();

            long n = num[0];
            long a = num[1];
            long b = num[2];
            long c = num[3];

            long ruble = long.MaxValue;
            long res = 4 - (n % 4);

            if (n % 4 == 0)
            {
                Console.WriteLine(0);
            }
            else if (res == 1)
            {
                ruble = Math.Min(ruble, a);
                ruble = Math.Min(ruble, (b + c));
                ruble = Math.Min(ruble, ( c*7));
                Console.WriteLine(ruble);
            }
            else if (res == 2)
            {
                ruble = Math.Min(a * 2, b);
                ruble = Math.Min(c * 2, ruble);
                Console.WriteLine(ruble);
            }
            else
            {
                ruble = Math.Min(a * 3, c);
                ruble = Math.Min(ruble, a + b);
                Console.WriteLine(ruble);
            }

        }

    }

}

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Numerics;

namespace contest
{

    class contest
    {

        static void Main(string[] args)
        {

            //int n = int.Parse(Console.ReadLine());
            //var input = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //int n = int.Parse(Console.ReadLine());
            var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int n = num[0];
            int a = num[1];
            int b = num[2];
            int c = num[3];

            long ruble = int.MaxValue;

            for(int i=1; i<=3; i++)
            {
                int tmp = n + i;

                if(i==1)
                {
                    int res = 4-(n % 4);
                    ruble = Math.Min(num[i]*res, ruble);
                }
                if(tmp%4==0)
                {
                    ruble = Math.Min(num[i],ruble);
                }
            }

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

            Console.WriteLine(ruble);

        }

    }

}

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Numerics;

namespace contest
{

    class contest
    {

        static void Main(string[] args)
        {

            //int n = int.Parse(Console.ReadLine());
            //var input = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //int n = int.Parse(Console.ReadLine());
            var num = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long n = num[0];
            long a = num[1];
            long b = num[2];
            long c = num[3];

            long ruble = long.MaxValue;

            for(int i=1; i<=3; i++)
            {
                long tmp = n + i;

                if(i==1)
                {
                    long res = 4-(n % 4);
                    ruble = Math.Min(num[i]*res, ruble);
                }
                if(tmp%4==0)
                {
                    ruble = Math.Min(num[i],ruble);
                }
            }

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

            Console.WriteLine(ruble);

        }

    }

}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//using System.

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {

            long a, b, c, n = 0;

            String all_nums = Console.ReadLine();

            String[] numbers = new String[4];
            //StringBuilder[] numbers = new StringBuilder[4];
            numbers=all_nums.Split(' ');

            n = long.Parse(numbers[0]);
            a = long.Parse(numbers[1]);
            b = long.Parse(numbers[2]);
            c = long.Parse(numbers[3]);

            long to_buy = -1;

             if (n < 4)
                 to_buy = 4 - n;

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

            if (to_buy == 0 || to_buy % 4==0)
                Console.WriteLine(0);

            if(to_buy==1)
                Console.WriteLine(a);

            if(to_buy==2)
            {
                long x =checked(2 * a);
                long y = b;
                if (x > y)
                    Console.WriteLine(y);
                else
                    Console.WriteLine(x);
            }

            if(to_buy==3)
            {
              //  BigInteger number = BigInteger.Multiply(Int64.MaxValue, 3);
                long x =checked(3 * a);
                long y =checked(a + b);
                long z = c;
                long h =checked(b + (2 * a));

                long min = x;

                if(y<min)
                    min=y;
                if(z<min)
                    min=z;

                if(h<min)
                    min=h;

                Console.WriteLine(min.ToString());

            }

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {

            BigInteger a, b, c, n = 0;

            String all_nums = Console.ReadLine();

            String[] numbers = new String[4];
            //StringBuilder[] numbers = new StringBuilder[4];
            numbers=all_nums.Split(' ');

            n = BigInteger.Parse(numbers[0]);
            a = BigInteger.Parse(numbers[1]);
            b = BigInteger.Parse(numbers[2]);
            c = BigInteger.Parse(numbers[3]);

            BigInteger to_buy = -1;

             if (n < 4)
                 to_buy = 4 - n;

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

            if (to_buy == 0 || to_buy % 4==0)
                Console.WriteLine(0);

            if(to_buy==1)
                Console.WriteLine(a);

            if(to_buy==2)
            {
                BigInteger x = BigInteger.Multiply(a,2);
                BigInteger y = b;
                if (x > y)
                    Console.WriteLine(y);
                else
                    Console.WriteLine(x);
            }

            if(to_buy==3)
            {
                BigInteger x = BigInteger.Multiply(a, 3);
                BigInteger y = BigInteger.Add(a, b);
                //long x =checked(3 * a);
               // long y =checked(a + b);
                BigInteger z = c;
                BigInteger h = BigInteger.Add(b, BigInteger.Multiply(a, 2));

                BigInteger min = x;

                if(y<min)
                    min=y;
                if(z<min)
                    min=z;

                if(h<min)
                    min=h;

                Console.WriteLine(min.ToString());

            }

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {

            long a, b, c, n = 0;

            String all_nums = Console.ReadLine();

            String[] numbers = new String[4];
            //StringBuilder[] numbers = new StringBuilder[4];
            numbers=all_nums.Split(' ');

            n = long.Parse(numbers[0]);
            a = long.Parse(numbers[1]);
            b = long.Parse(numbers[2]);
            c = long.Parse(numbers[3]);

            long to_buy = -1;

             if (n < 4)
                 to_buy = 4 - n;

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

            if (to_buy == 0 || to_buy % 4==0)
                Console.WriteLine(0);

            if(to_buy==1)
                Console.WriteLine(a);

            if(to_buy==2)
            {
                long x = 2 * a;
                long y = b;
                if (x > y)
                    Console.WriteLine(y);
                else
                    Console.WriteLine(x);
            }

            if(to_buy==3)
            {

                long x = 3 * a;
                long y = a + b;
                long z = c;
                long h = b + (2 * a);

                long min = x;

                if(y<min)
                    min=y;
                if(z<min)
                    min=z;

                if(h<min)
                    min=h;

                Console.WriteLine(min.ToString());

            }

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {

            int a, b, c,n = 0;

            string all_nums = Console.ReadLine();

            String[] numbers = new String[4];
            numbers=all_nums.Split(' ');

             n = int.Parse(numbers[0]);
             a = int.Parse(numbers[1]);
             b = int.Parse(numbers[2]);
             c = int.Parse(numbers[3]);

             int to_buy = -1;

             if (n < 4)
                 to_buy = 4 - n;

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

            if (to_buy == 0 || to_buy % 4==0)
                Console.WriteLine(0);

            if(to_buy==1)
                Console.WriteLine(a);

            if(to_buy==2)
            {
                int x = 2 * a;
                int y = b;
                if (x > y)
                    Console.WriteLine(y);
                else
                    Console.WriteLine(x);
            }

            if(to_buy==3)
            {

                int x = 3*a;
                int y=a+b;
                int z=c;
                int h=b+(2*a);

                int min=x;

                if(y<min)
                    min=y;
                if(z<min)
                    min=z;

                if(h<min)
                    min=h;

                Console.WriteLine(min.ToString());

            }

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {

            long a, b, c, n = 0;

            String all_nums = Console.ReadLine();

            String[] numbers = new String[4];
            //StringBuilder[] numbers = new StringBuilder[4];
            numbers=all_nums.Split(' ');

            n = long.Parse(numbers[0]);
            a = long.Parse(numbers[1]);
            b = long.Parse(numbers[2]);
            c = long.Parse(numbers[3]);

            long to_buy = -1;

             if (n < 4)
                 to_buy = 4 - n;

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

            if (to_buy == 0 || to_buy % 4==0)
                Console.WriteLine(0);

            if(to_buy==1)
                Console.WriteLine(a);

            if(to_buy==2)
            {
                long x =checked(2 * a);
                long y = b;
                if (x > y)
                    Console.WriteLine(y);
                else
                    Console.WriteLine(x);
            }

            if(to_buy==3)
            {
                BigInteger x = BigInteger.Multiply(a, 3);
                BigInteger y = BigInteger.Add(a, b);
                //long x =checked(3 * a);
               // long y =checked(a + b);
                BigInteger z = c;
                BigInteger h = BigInteger.Add(b, BigInteger.Multiply(a, 2));

                BigInteger min = x;

                if(y<min)
                    min=y;
                if(z<min)
                    min=z;

                if(h<min)
                    min=h;

                Console.WriteLine(min.ToString());

            }

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {

            Double a, b, c, n = 0;

            string all_nums = Console.ReadLine();

            String[] numbers = new String[4];
            numbers=all_nums.Split(' ');

             n = Double.Parse(numbers[0]);
             a = Double.Parse(numbers[1]);
             b = Double.Parse(numbers[2]);
             c = Double.Parse(numbers[3]);

             Double to_buy = -1;

             if (n < 4)
                 to_buy = 4 - n;

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

            if (to_buy == 0 || to_buy % 4==0)
                Console.WriteLine(0);

            if(to_buy==1)
                Console.WriteLine(a);

            if(to_buy==2)
            {
                Double x = 2 * a;
                Double y = b;
                if (x > y)
                    Console.WriteLine(y);
                else
                    Console.WriteLine(x);
            }

            if(to_buy==3)
            {

                Double x = 3 * a;
                Double y = a + b;
                Double z = c;
                Double h = b + (2 * a);

                Double min = x;

                if(y<min)
                    min=y;
                if(z<min)
                    min=z;

                if(h<min)
                    min=h;

                Console.WriteLine(min.ToString());

            }

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;

namespace codeforces
{
	class Program
	{
		public const int Osn = 1000000007;

		public class Pair
		{
			public long First;

			public long Second;
		}

		public class PairComparer : IComparer<Pair>
		{
			public int Compare(Pair x, Pair y)
			{
				if (x.First < y.First || (x.First == y.First && x.Second > y.Second))
					return -1;
				return 1;
			}
		}

		public static long GetGcd(long a, long b)
		{
			while (true)
			{
				if (b == 0)
					return a;
				var a1 = a;
				a = b;
				b = a1 % b;

			}
		}

		public static void WriteYesNo(bool x, string yes = "YES", string no = "NO")
		{
			if (x)
				Console.WriteLine(yes);
			else
			{
				Console.WriteLine(no);
			}
		}

		public static string ReadString()
		{
			return Console.ReadLine();
		}

		public static List<int> ReadListOfInts()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(int.Parse).ToList();
		}

		public static List<long> ReadListOfLongs()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(long.Parse).ToList();
		}

		public static int ReadInt()
		{
			var s = Console.ReadLine();
			return int.Parse(s);
		}

		public static long ReadLong()
		{
			var s = Console.ReadLine();
			return long.Parse(s);
		}

		public class Vertex
		{
			public int Was;

			public List<int> Edges;
		}

		public static List<Vertex> Graph = new List<Vertex>();

		public static bool Dfs(int u)
		{
			if (Graph[u].Was == 1) return true;
			if (Graph[u].Was == 2) return false;
			Graph[u].Was = 1;
			foreach (var t in Graph[u].Edges)
			{
				if (Dfs(t)) return true;
			}

			Graph[u].Was = 2;
			return false;
		}

		public static bool IsPrime(int x)
		{
			for (var j = 2; j * j <= x; ++j)
				if (x % j == 0)
					return false;
			return true;
		}

		public class LinkedVertex
		{
			public int Next;

			public int Prev;

			public int Value;
		}

		public static int BinarySearch(List<int> list, int value)
		{
			var l = -1;
			var r = list.Count;
			while (r - l > 1)
			{
				var m = (r + l) / 2;
				if (list[m] >= value)
					r = m;
				else
					l = m;
			}

			return r;
		}

		public static Dictionary<long, long> mp = new Dictionary<long, long>();
		public static long Go(long u, long v, long w)
		{
			long ans = 0;
			while (u != v)
				if (u > v)
				{
					if (!mp.ContainsKey(u))
						mp.Add(u, 0);
					ans += mp[u];
					mp[u] += w;
					u /= 2;
				}
				else
				{
					if (!mp.ContainsKey(v))
						mp.Add(v, 0);
					ans += mp[v];
					mp[v] += w;
					v /= 2;
				}
			return ans;
		}

		private static void Main()
		{
			var l = ReadListOfLongs();
			var n = l[0];
			var a = l[1];
			var b = l[2];
			var c = l[3];
			if (n % 4 == 0)
			{
				Console.WriteLine(0);
			}
			if (n % 4 == 3)
			{
				Console.WriteLine(Math.Min(a, Math.Min(3*c, 3*b + c)));
			}
			if (n % 4 == 2)
			{
				Console.WriteLine(Math.Min(b, Math.Min(2*a, 2*c)));
			}
			if (n % 4 == 1)
			{
				Console.WriteLine(Math.Min(c, Math.Min(3 * a, b + a)));
			}
			/*			var n = ReadLong();
			var a = ReadLong();
			var b = ReadLong();
			var c = ReadLong();
			if (a <= b - c)
			{
				Console.WriteLine(n / a);
			}
			else
			{
				long ans = 0;
				while ((n / b) > 0)
				{
					var k = n / b;
					ans += k;
					n = (n % b) + k * c;
				}
				ans += n / a;
				Console.WriteLine(ans);
			}*/
			Console.ReadLine();
		}
	}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        static int GetNumberInt()
        {
            return Convert.ToInt32(Console.ReadLine());
        }

        static long GetNumberLong()
        {
            return Convert.ToInt64(Console.ReadLine());
        }

        static int[] GetArrayInt()
        {
            string[] @string = Console.ReadLine().Split(' ');
            int[] array = new int[@string.Length];
            for (int i = 0; i < array.Length; i++)
            {
                array[i] = Convert.ToInt32(@string[i]);
            }
            return array;
        }

        static long[] GetArrayLong()
        {
            string[] @string = Console.ReadLine().Split(' ');
            long[] array = new long[@string.Length];
            for (int i = 0; i < array.Length; i++)
            {
                array[i] = Convert.ToInt64(@string[i]);
            }
            return array;
        }

        static void Main(string[] args)
        {
            long[] array = GetArrayLong();
            long n = array[0], a = array[1], b = array[2], c = array[3];
            long k = 4 - n % 4;
            long minMoney = int.MaxValue;
            if (k == 1)
                minMoney = Math.Min(a, 3 * c);
            else if (k == 2)
                minMoney = Math.Min(Math.Min(2 * a, b), 2 * c);
            else if (k == 3)
                minMoney = Math.Min(c, 3 * a);
            else
                minMoney = 0;
            Console.WriteLine(minMoney);
        }
    }
}