using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;

namespace Codeforces
{
    class Program
    {
        private static string readString() => Console.ReadLine();
        private static T readValue<T>() => (T)Convert.ChangeType(readString(), typeof(T));
        private static string[] readStrings(char delimiter = ' ') => readString().Split(delimiter);
        private static T[] readValues<T>(char delimiter = ' ') => readStrings(delimiter: delimiter).Select(x => (T)Convert.ChangeType(x, typeof(T))).ToArray();
        private static void write<T>(T s) => Console.WriteLine(s);

        private static int binarySearch<T>(List<T> list, T target) where T : IComparable
        {
            int l = 0, r = list.Count - 1;
            while (l <= r)
            {
                var m = (int)Math.Floor((double)(l + r) / 2);
                if (list[m].CompareTo(target) <= 0)
                    if (m == r || list[m + 1].CompareTo(target) > 0)
                        return m;
                    else
                        l = m + 1;
                else
                    r = m - 1;
            }
            return -1;
        }

        private static int quickSortPartition<T>(List<T> list, int left, int right) where T : IComparable
        {
            T pivot = list[left];
            while (true)
            {
                while (list[left].CompareTo(pivot) < 0)
                    left++;
                while (list[right].CompareTo(pivot) > 0)
                    right--;
                if (left < right)
                {
                    if (list[left].CompareTo(list[right]) == 0)
                        return right;

                    T temp = list[left];
                    list[left] = list[right];
                    list[right] = temp;
                }
                else
                    return right;
            }
        }
        private static void quickSort<T>(List<T> list, int left, int right) where T : IComparable
        {
            if (left < right)
            {
                int pivot = quickSortPartition(list, left, right);
                if (pivot > 1)
                    quickSort(list, left, pivot - 1);
                if (pivot + 1 < right)
                    quickSort(list, pivot + 1, right);
            }
        }
        private static void quickSort<T>(List<T> list) where T : IComparable => quickSort(list, 0, list.Count - 1);

        private static void watermelon()
        {
            var w = readValue<int>();
            write(w >= 4 && w % 2 == 0 ? "YES" : "NO");
        }
        private static void wayTooLongWords()
        {
            var words = new List<string>();

            var n = readValue<int>();
            for (int i = 0; i < n; ++i)
                words.Add(readString());

            foreach (var word in words)
                write(word.Length <= 10 ? word : $"{word.First()}{word.Length - 2}{word.Last()}");
        }
        private static void team()
        {
            int solve = 0;

            var n = readValue<int>();
            for (int i = 0; i < n; ++i)
                if (readValues<int>().Where(x => x == 1).Count() > 1)
                    ++solve;

            write(solve);
        }
        private static void football()
        {
            var positions = readString();
            for (int i = 6; i < positions.Length; ++i)
                if (positions.Substring(i - 6, 6) == (positions[i] == '0' ? "000000" : "111111"))
                {
                    write("YES");
                    return;
                }
            write("NO");
        }
        private static void theatreSquare()
        {
            var sizes = readValues<int>();
            write((long)Math.Ceiling((double)sizes[0] / (double)sizes[2]) * (long)Math.Ceiling((double)sizes[1] / (double)sizes[2]));
        }
        private static void stringTask()
        {
            var Vowels = new HashSet<char> { 'a', 'o', 'y', 'e', 'u', 'i' };
            var sb = new StringBuilder();
            var s = readString().ToLower();
            foreach (var c in s)
                if (!Vowels.Contains(c))
                {
                    sb.Append('.');
                    sb.Append(c);
                }

            write(sb.ToString());
        }
        private static void taxi()
        {
            int taxis = 0;
            var groups = new Dictionary<int, int> { { 1, 0 }, { 2, 0 }, { 3, 0 } };

            readValue<int>();
            var groupSizes = readValues<int>();
            foreach (var size in groupSizes)
                if (size == 4)
                    ++taxis;
                else
                    groups[size] = groups[size] + 1;

            taxis += groups[3];
            groups[1] = groups[1] - Math.Min(groups[1], groups[3]);

            taxis += groups[2] / 2;
            if (groups[2] % 2 == 1)
            {
                ++taxis;
                groups[1] = groups[1] - 2;
            }

            if (groups[1] > 0)
                taxis += (int)Math.Ceiling((double)groups[1] / 4.0);

            write(taxis);
        }
        private static void fancyFence()
        {
            var a = readValue<int>();
            for (double i = 3.0; ; i += 1.0)
            {
                var x = (double)(i - 2.0) * 180.0 / i;
                if (a <= x)
                {
                    write(a < x ? "NO" : "YES");
                    break;
                }
            }
        }
        private static void interestingDrink()
        {
            readString();
            var prices = readValues<int>().OrderBy(x => x).ToList();
            var days = readValue<int>();
            for (int i = 0; i < days; ++i)
                write(binarySearch(prices, readValue<int>()) + 1);
        }
        private static void compilationErrors()
        {
            readString();
            Dictionary<int, int> errors = readValues<int>().GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count()), errors1 = new Dictionary<int, int>();
            foreach (var error in readValues<int>())
            {
                if (errors[error] > 1)
                    errors[error] = errors[error] - 1;
                else
                    errors.Remove(error);

                if (errors1.TryGetValue(error, out var count))
                    errors1[error] = count + 1;
                else
                    errors1.Add(error, 1);
            }
            write(errors.First().Key);

            foreach (var error in readValues<int>())
                if (errors1[error] > 1)
                    errors1[error] = errors1[error] - 1;
                else
                    errors1.Remove(error);
            write(errors1.First().Key);
        }
        private static void doubleCola()
        {
            var idToName = new Dictionary<int, string> { { 0, "Sheldon" }, { 1, "Leonard" }, { 2, "Penny" }, { 3, "Rajesh" }, { 4, "Howard" } };
            int n = readValue<int>(), i = 1;
            for (; n > i * 5; i *= 2)
                n -= i * 5;
            write(idToName[(n - 1) / i]);
        }
        private static void ilyaAndQueries()
        {
            var dic = new Dictionary<int, int>();
            var list = new List<Tuple<int, int>>();

            var s = readString();
            int start = 0, dicStart = 0;
            for (int j = 0; j < s.Length - 1; ++j)
                if (s[j] != s[j + 1])
                {
                    if (start < j)
                    {
                        list.Add(new Tuple<int, int>(start + 1, j + 1));
                        for (; dicStart < j + 1; ++dicStart)
                            dic.Add(dicStart, list.Count - 1);
                    }
                    start = j + 1;
                }
            if (start < s.Length - 1)
            {
                list.Add(new Tuple<int, int>(start + 1, s.Length));
                for (; dicStart < s.Length; ++dicStart)
                    dic.Add(dicStart, list.Count - 1);
            }

            var m = readValue<int>();
            for (int j = 0; j < m; ++j)
            {
                var q = readValues<int>();
                int l = q[0], r = q[1], result = 0;
                if (dic.TryGetValue(l, out var i))
                    for (; i < list.Count && r >= list[i].Item1; ++i)
                        if (l < list[i].Item2)
                            result += Math.Min(r, list[i].Item2) - Math.Max(l, list[i].Item1);
                write(result);
            }
        }
        private static void twoTeamsComposing()
        {
            var n = readValue<int>();
            var skills = readValues<int>().GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count());
        }
        #region Laptop
        private class Laptop
        {
            internal int Price { get; private set; }
            internal int Quality { get; private set; }
            internal Laptop(int[] values)
            {
                Price = values[0];
                Quality = values[1];
            }
        }
        private class Laptop_Comparer_Price : Comparer<Laptop>
        {
            public override int Compare([AllowNull] Laptop x, [AllowNull] Laptop y) => x.Price - y.Price;
        }
        private class Laptop_Comparer_Quality : Comparer<Laptop>
        {
            public override int Compare([AllowNull] Laptop x, [AllowNull] Laptop y) => x.Quality - y.Quality;
        }
        private static void laptops()
        {
            List<Laptop> prices = new List<Laptop>(), qualities = new List<Laptop>();
            var n = readValue<int>();
            for (int i = 0; i < n; ++i)
            {
                var laptop = new Laptop(readValues<int>());
                prices.Add(laptop);
                qualities.Add(laptop);
            }

            for (int i = 0; i < n; ++i)
                if (prices[i] != qualities[i])
                {
                    write("Happy Alex");
                    return;
                }
            write("Poor Alex");
        }
        #endregion
        private static void fence()
        {
            int k = readValues<int>()[1], minI = 0, currentH = 0;
            int[] h = readValues<int>();

            for (int i = 0; i < k; ++i)
                currentH += h[i];
            var minH = currentH;

            for (int i = 1; i < h.Length - k + 1; ++i)
            {
                currentH = currentH - h[i - 1] + h[i + k - 1];
                if (minH > currentH)
                {
                    minH = currentH;
                    minI = i;
                }
            }

            write(minI + 1);
        }
        #region serejaAndSuffixes
        private class SerejaL : IComparable
        {
            internal int L { get; private set; }
            internal int Result;
            internal SerejaL(int l)
            {
                L = l;
            }

            public int CompareTo(object obj) => L - ((SerejaL)obj).L;
        }
        private static void serejaGetLs(int m, out List<SerejaL> listDistinct, out List<SerejaL> listOrdered)
        {
            listDistinct = new List<SerejaL>();
            listOrdered = new List<SerejaL>();
            var dic = new Dictionary<int, SerejaL>();
            for (int i = 0; i < m; ++i)
            {
                var l = readValue<int>() - 1;
                if (!dic.TryGetValue(l, out var item))
                {
                    item = new SerejaL(l);
                    dic.Add(l, item);
                    listDistinct.Add(item);
                }
                listOrdered.Add(item);
            }
            quickSort(listDistinct);
        }
        private static void serejaAndSuffixes()
        {
            var m = readValues<int>()[1];
            var a = readValues<int>();
            serejaGetLs(m, out var listDistinct, out var listOrdered);

            var distinct = new HashSet<int>();
            for (int i = listDistinct.Count - 1, j = a.Length - 1; i >= 0; --i)
            {
                for (; j >= listDistinct[i].L; --j)
                    if (!distinct.Contains(a[j]))
                        distinct.Add(a[j]);

                listDistinct[i].Result = distinct.Count;
            }

            foreach (var item in listOrdered)
                write(item.Result);
        }
        #endregion
        private static void bowWowTimetable()
        {
            string s = readString(), r = "1";
            int i = 1;
            for (; r.Length < s.Length; ++i, r = r + "00") ;
            if (r.Length > s.Length || !s.Substring(1).Contains('1'))
                write(i - 1);
            else
                write(i);
        }
        private static void digits()
        {
            readString();
            var numbers = readValues<int>().GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count());
            if (!numbers.ContainsKey(0))
            {
                write(-1);
                return;
            }
        }
        private static void lifeWithoutZeros()
        {
            long a = readValue<int>(), b = readValue<int>(), c = a + b;
            write(Convert.ToInt64(a.ToString().Replace("0", "")) + Convert.ToInt64(b.ToString().Replace("0", "")) == Convert.ToInt64(c.ToString().Replace("0", "")) ? "YES" : "NO");
        }
        private static void permutation()
        {
            var n = readValue<int>();
            var a = readValues<int>();
            write(n - a.Where(x => x <= n).Distinct().Count());
        }
        private static void hamsterFarm()
        {
            var n = readValues<long>()[0];
            var k = readValues<long>();
            int bestI = 0;
            for (int i = 1; i < k.Length; ++i)
                if (n % k[i] < n % k[bestI])
                    bestI = i;
            write($"{bestI + 1} {n / k[bestI]}");
        }
        private static void shellGame()
        {
            int n = readValue<int>(), x = readValue<int>();
            if (x == 1)
            {
                if (n % 2 == 1)
                    x = 0;
                else
                    x = 2;
                --n;
            }
            for (int i = n % 6; i > 0; --i)
                if (i % 2 == 1)
                {
                    if (x == 0)
                        x = 1;
                    else if (x == 1)
                        x = 0;
                }
                else if (x == 1)
                    x = 2;
                else if (x == 2)
                    x = 1;
            write(x);
        }
        private static void ACM_ICPC()
        {
            int[] a = readValues<int>(), score = new int[2], members = new int[2];
            for (int i1 = 0; i1 < 2; ++i1)
            {
                score[i1] = a[0];
                members[i1] = 1;
                for (int i2 = 0; i2 < 2; ++i2)
                {
                    score[i2] += a[1];
                    members[i2] += 1;
                    for (int i3 = 0; i3 < 2; ++i3)
                    {
                        score[i3] += a[2];
                        members[i3] += 1;
                        for (int i4 = 0; i4 < 2; ++i4)
                            if (members[i4] < 3)
                            {
                                score[i4] += a[3];
                                members[i4] += 1;
                                for (int i5 = 0; i5 < 2; ++i5)
                                    if (members[i5] < 3)
                                    {
                                        score[i5] += a[4];
                                        members[i5] += 1;
                                        for (int i6 = 0; i6 < 2; ++i6)
                                            if (members[i6] < 3)
                                            {
                                                score[i6] += a[5];
                                                members[i6] += 1;
                                                if (score[0] == score[1])
                                                {
                                                    write("YES");
                                                    return;
                                                }
                                                score[i6] -= a[5];
                                                members[i6] -= 1;
                                            }
                                        score[i5] -= a[4];
                                        members[i5] -= 1;
                                    }
                                score[i4] -= a[3];
                                members[i4] -= 1;
                            }
                        score[i3] -= a[2];
                        members[i3] -= 1;
                    }
                    score[i2] -= a[1];
                    members[i2] -= 1;
                }
                score[i1] = 0;
                members[i1] = 0;
            }
            write("NO");
        }
        private static void mex()
        {
            var x = readValues<int>()[1];
            var n = readValues<int>();
            write(x - n.Count(y => y < x) + (n.Contains(x) ? 1 : 0));
        }
        private static void minimumProduct()
        {
            var input = readValues<int>();
            int a = input[0], b = input[1], x = input[2], y = input[3], n = input[4], minA = Math.Min(a - x, n), minB = Math.Min(b - y, n);
            if (a - minA <= b - minB)
            {
                a -= minA;
                n -= minA;
            }
            else
            {
                b -= minB;
                n -= minB;
            }

            if (n > 0)
                if (a > x)
                    a -= Math.Min(a - x, n);
                else if (b > y)
                    b -= Math.Min(b - y, n);

            write((long)a * (long)b);
        }
        private static void shovelsAndSwords()
        {
            var input = readValues<int>();
            int a = input[0], b = input[1], result = 0;
            if (a > b)
            {
                var min = Math.Min(a - b, b);
                a -= min * 2;
                b -= min;
                result += min;
            }
            else if (b > a)
            {
                var min = Math.Min(b - a, a);
                a -= min;
                b -= min * 2;
                result += min;
            }
            int d = Math.Min(a / 3, b / 3);
            a -= d * 3;
            b -= d * 3;
            result += d * 2;
            if (a > 0 && b > 0 && (a > 1 || b > 1))
                ++result;
            write(result);
        }
        private static void matrixGame()
        {
            var input = readValues<int>();
            int n = input[0], m = input[1];
            HashSet<int> claimedRows = new HashSet<int>(), claimedColumns = new HashSet<int>();
            for (int i = 0; i < n; ++i)
            {
                input = readValues<int>();
                for (int j = 0; j < m; ++j)
                    if (input[j] == 1)
                    {
                        if (!claimedRows.Contains(i))
                            claimedRows.Add(i);
                        if (!claimedColumns.Contains(j))
                            claimedColumns.Add(j);
                    }
            }
            write(Math.Min(n - claimedRows.Count, m - claimedColumns.Count) % 2 == 0 ? "Vivek" : "Ashish");
        }
        private static void cinemaLine()
        {
            readString();
            var clerk = new Dictionary<int, int> { { 25, 0 }, { 50, 0 } };
            foreach (var a in readValues<int>())
                switch (a)
                {
                    case 25:
                        clerk[25] += 1;
                        break;
                    case 50:
                        if (clerk[25] > 0)
                        {
                            clerk[25] -= 1;
                            clerk[50] += 1;
                        }
                        else
                        {
                            write("NO");
                            return;
                        }
                        break;
                    default: // 100
                        if (clerk[50] > 0 && clerk[25] > 0)
                        {
                            clerk[25] -= 1;
                            clerk[50] -= 1;
                        }
                        else if (clerk[25] > 2)
                            clerk[25] -= 3;
                        else
                        {
                            write("NO");
                            return;
                        }
                        break;
                }
            write("YES");
        }
        private static void kindAnton()
        {
            readString();
            int[] a = readValues<int>(), b = readValues<int>();
            bool positive1 = false, negative1 = false;
            HashSet<int> positive = new HashSet<int>(), negative = new HashSet<int>();
            for (int i = 0; i < a.Length; ++i)
            {
                int diff = b[i] - a[i];
                if (((diff > 0 && !positive1) || (diff < 0 && !negative1)) && !(diff > 0 ? positive : negative).Any(x => diff % x == 0))
                {
                    write("NO");
                    return;
                }
                if (a[i] > 0)
                {
                    if (!positive1)
                        if (a[i] == 1)
                        {
                            positive1 = true;
                            if (negative1)
                            {
                                write("YES");
                                return;
                            }
                        }
                        else if (!positive.Contains(a[i]))
                            positive.Add(a[i]);
                }
                else if (a[i] < 0 && !negative1)
                    if (a[i] == -1)
                    {
                        negative1 = true;
                        if (positive1)
                        {
                            write("YES");
                            return;
                        }
                    }
                    else if (!negative.Contains(a[i]))
                        negative.Add(a[i]);
            }
            write("YES");
        }
        private static void staircases()
        {
            var input = readValues<int>();
            int n = input[0], mn = input[1];
            if (mn == 0)
            {
                write("YES");
                return;
            }
            var m = readValues<int>().OrderBy(x => x).ToList();
            if (m[0] == 1 || m[m.Count - 1] == n)
            {
                write("NO");
                return;
            }
            for (int i = 0; i < m.Count - 2; ++i)
                if (m[i] == m[i + 1] - 1 && m[i] == m[i + 2] - 2)
                {
                    write("NO");
                    return;
                }
            write("YES");
        }
        private static void blownGarland()
        {
            var colors = new Dictionary<char, int> { { 'R', 0 }, { 'Y', 0 }, { 'B', 0 }, { 'G', 0 } };
            var s = readString();

            var colorPerPosition = new char[4];
            foreach (var color in colors)
                colorPerPosition[s.IndexOf(color.Key) % 4] = color.Key;

            for (int i = 0; i < s.Length; ++i)
                if (s[i] == '!')
                    colors[colorPerPosition[i % 4]] += 1;

            write($"{colors['R']} {colors['B']} {colors['Y']} {colors['G']}");
        }
        private static void mikeAndFax()
        {
            var s = readString();
            int k = readValue<int>();

            if (s.Length % k != 0)
            {
                write("NO");
                return;
            }

            int size = s.Length / k;
            for (int i = 0; i < s.Length; i += size)
                for (int j1 = i + size / 2 - 1, j2 = i + size / 2 + size % 2; j1 >= i; --j1, ++j2)
                    if (s[j1] != s[j2])
                    {
                        write("NO");
                        return;
                    }

            write("YES");
        }
        #region weirdRounding
        private static bool weirdRounding_Recursion(string ns, int kp, int d)
        {
            if (d > 0)
                for (int i = ns[1] == '0' && ns.Length > 2 ? 1 : 0; i < ns.Length; ++i)
                {
                    string nsNew = ns.Remove(i, 1);
                    int n = Convert.ToInt32(nsNew);
                    if (n % kp == 0 || weirdRounding_Recursion(nsNew, kp, d - 1))
                        return true;
                }
            return false;
        }
        private static void weirdRounding()
        {
            var input = readStrings();
            string ns = input[0];
            int n = Convert.ToInt32(ns), k = Convert.ToInt32(input[1]), kp = (int)Math.Pow(10, k);

            if (n < kp)
                write(ns.Length - 1);
            else if (n % kp == 0)
                write(0);
            else
                for (int d = 1; d < ns.Length; ++d)
                    if (weirdRounding_Recursion(ns, kp, d))
                    {
                        write(d);
                        return;
                    }
        }
        #endregion
        private static void wilburArray()
        {
            readString();
            int[] b = readValues<int>();
            long result = Math.Abs(b[0]);
            for (int i = 1; i < b.Length; ++i)
                result += Math.Abs(b[i] - b[i - 1]);
            write(result);
        }
        private static void zuhairStrings()
        {
            int k = readValues<int>()[1];
            var s = readString();
            var result = new Dictionary<char, int>();

            for (int i = 0; i < s.Length - k + 1;)
            {
                int j = i + 1;
                for (; j < i + k && s[i] == s[j]; ++j) ;
                if (j == i + k)
                    if (!result.ContainsKey(s[i]))
                        result.Add(s[i], 1);
                    else
                        result[s[i]] += 1;
                i = j;
            }

            write(result.Count > 0 ? result.Max(x => x.Value) : 0);
        }
        private static void artfulExpedient()
        {
            var n = readValue<int>();
            int[] x = readValues<int>(), y = readValues<int>();
            var numbers = x.Union(y).ToHashSet();
            var resultEven = true;

            for (int i = 0; i < n; ++i)
                for (int j = 0; j < n; ++j)
                    if (numbers.Contains(x[i] ^ y[j]))
                        resultEven = !resultEven;

            write(resultEven ? "Karen" : "Koyomi");
        }
        private static void ebonyIvory()
        {
            var input = readValues<int>();
            int a = input[0], b = input[1], c = input[2];
            if (a < b)
            {
                var t = a;
                a = b;
                b = t;
            }
            for (; c >= 0; c -= a)
                if (c % b == 0)
                {
                    write("Yes");
                    return;
                }
            write("No");
        }
        #region Lala Land Apple Trees
        private class LalaLand_AppleTree : IComparable
        {
            private int coordinate;
            internal int Apples { get; private set; }
            internal LalaLand_AppleTree(int coordinate, int apples)
            {
                this.coordinate = coordinate;
                Apples = apples;
            }
            public int CompareTo(object obj) => coordinate - ((LalaLand_AppleTree)obj).coordinate;
        }
        private static void lalaLandAppleTrees()
        {
            var n = readValue<int>();
            List<LalaLand_AppleTree> right = new List<LalaLand_AppleTree>(), left = new List<LalaLand_AppleTree>();
            for (int i = 0; i < n; ++i)
            {
                var input = readValues<int>();
                if (input[0] > 0)
                    right.Add(new LalaLand_AppleTree(input[0], input[1]));
                else
                    left.Add(new LalaLand_AppleTree(-input[0], input[1]));
            }

            if (Math.Abs(right.Count - left.Count) < 2)
                write(right.Sum(x => x.Apples) + left.Sum(x => x.Apples));
            else
            {
                quickSort(right);
                quickSort(left);
                if (right.Count > left.Count)
                    write(right.GetRange(0, left.Count + 1).Sum(x => x.Apples) + (left.Count > 0 ? left.Sum(x => x.Apples) : 0));
                else
                    write((right.Count > 0 ? right.Sum(x => x.Apples) : 0) + left.GetRange(0, right.Count + 1).Sum(x => x.Apples));
            }
        }
        #endregion
        private static void lanterns()
        {
            int l = readValues<int>()[1], d = 0;
            var a = readValues<int>().Distinct().ToList();
            quickSort(a);
            for (int i = 0; i < a.Count - 1; ++i)
            {
                var diff = a[i + 1] - a[i];
                if (diff > d)
                    d = diff;
            }
            if (a[0] > 0 && a[a.Count - 1] < l)
                write(Math.Max(Math.Max(a[0] - 0, l - a[a.Count - 1]), d / 2.0));
            else if (a[0] > 0)
                write(Math.Max(a[0] - 0, d / 2.0));
            else if (a[a.Count - 1] < l)
                write(Math.Max(l - a[a.Count - 1], d / 2.0));
            else
                write((double)d / 2.0);
        }
        private static void cheapTravel()
        {
            var input = readValues<int>();
            int n = input[0], m = input[1], a = input[2], b = input[3];
            if (b >= a * m)
                write(n * a);
            else
                write((n / m) * b + ((n % m) * a < b ? (n % m) * a : b));
        }

        static void Main(string[] args)
        {
            //var t = readValue<int>();
            //for (int i = 0; i < t; ++i)
            cheapTravel();
        }
    }
}


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

namespace ConsoleApplication24
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = Convert.ToInt32(Console.ReadLine());
            int b = Convert.ToInt32(Console.ReadLine());
            int c = Convert.ToInt32(Console.ReadLine());
            b = b / 2;
            c = c / 4;
            int x = Math.Min(a, b);
            x = Math.Min(x, c);
            Console.WriteLine(x*7);

        }
    }
}


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

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

            {
                int z = 0;
                int a = int.Parse(Console.ReadLine());
                int b = int.Parse(Console.ReadLine());
                int c = int.Parse(Console.ReadLine());
                while (a != 0 && b >= 2 && c >= 4)
                {
                    a--;
                    b = b - 2;
                    c = c - 4;
                    z += 7;
                }
                Console.WriteLine(z);

            }
        }
    }
}


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

namespace G4
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] Steps = new int[10];
            Steps[0] = 1;
            for (int i = 1; i < 10; i++)
            {
                Steps[i] = Steps[i - 1] * 10;
            }

            int n = int.Parse(Console.ReadLine());
            int[] a = new int[n];
            string[] sin = Console.ReadLine().Split(' ');
            for (int i = 0; i < n;i++)
            {
                a[i] = int.Parse(sin[i]);
            }

            Array.Sort(a);

            int count = 0;

            if (a[0] != 0)
            {
                count++;
            }

            for (int i = 1; i < n; i++)
            {
                if (a[i] != a[i-1])
                {
                    count++;
                }
            }

            Console.Write(count);
        }
    }
}


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

namespace CF
{
    public static class FromConsole
    {
        public static T To<T>(this string input) where T : IConvertible
        {
            return (T)Convert.ChangeType(input, typeof(T));
        }

        public static T[] ToArrayOf<T>(this string input, char? delimiter = null) where T : IConvertible
        {
            IEnumerable<string> sequence = delimiter == null ? input.Select(x => x.ToString()) : input.Split(delimiter.Value);

            return sequence.Select(x => x.ToString().To<T>()).ToArray();
        }

        public static T[] ToArrayOf<T>(int count) where T : IConvertible
        {
            T[] output = new T[count];

            for (int i = 0; i < count; i++)
            {
                output[i] = Console.ReadLine().To<T>();
            }

            return output;
        }

        public static T[] ToArrayOf<T>(T value, int count)
        {
            return Enumerable.Repeat(value, count).ToArray();
        }

        public static T[][] ToMatrixOf<T>(int n, char? delimiter = null) where T : IConvertible
        {
            T[][] output = new T[n][];

            for (int i = 0; i < n; i++)
            {
                output[i] = Console.ReadLine().ToArrayOf<T>(delimiter);
            }

            return output;
        }

        public static T[][] ToMatrixOf<T>(T value, int n, int m)
        {
            T[][] output = new T[n][];

            for (int i = 0; i < n; i++)
            {
                output[i] = ToArrayOf(value, m);
            }

            return output;
        }

        public static Tuple<int, int> IndexOf<T>(this T[][] input, params T[] targets)
        {
            for (int i = 0; i < input.Length; i++)
            {
                for (int j = 0; j < input[0].Length; j++)
                {
                    if (targets.Any(x => x.Equals(input[i][j])))
                    {
                        return new Tuple<int, int>(i, j);
                    }
                }
            }

            return new Tuple<int, int>(-1, -1);
        }

        public static void AddToList<T, U>(this Dictionary<T, List<U>> input, T k, U v)
        {
            if (input.ContainsKey(k))
            {
                input[k].Add(v);
            }
            else
            {
                input.Add(k, new List<U>() { v });
            }
        }

        public static void AddAndIncrement<T>(this Dictionary<T, int> input, T k)
        {
            if (input.ContainsKey(k))
            {
                input[k]++;
            }
            else
            {
                input.Add(k, 1);
            }
        }

        public static string ToBinary(this long input)
        {
            return Convert.ToString(input, 2);
        }

        public static long ToDecimal(this string input)
        {
            return Convert.ToInt32(input, 2);
        }

        public static long Binomial(long n, long k)
        {
            long r = 1;
            long d;
            if (k > n) return 0;
            for (d = 1; d <= k; d++)
            {
                r *= n--;
                r /= d;
            }
            return r;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            int n = Console.ReadLine().To<int>();
            int[] scores = Console.ReadLine().ToArrayOf<int>(' ');

            Console.WriteLine(scores.Where(x => x > 0).Distinct().Count());
            //Console.ReadKey();
        }
    }
}


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

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = double.Parse(Console.ReadLine()) - 1;
            var k = Math.Floor(Math.Log(n / 5 + 1, 2));
            var geomSumm = -5*(1 - Math.Pow(2,k));
            var nModGeomSumm = n - geomSumm;
            var need = (int)nModGeomSumm / (int)Math.Pow(2,k);
            switch (need)
            {
                case 0:
                    Console.WriteLine("Sheldon");
                    break;
                case 1:
                    Console.WriteLine("Leonard");
                    break;
                case 2:
                    Console.WriteLine("Penny");
                    break;
                case 3:
                    Console.WriteLine("Rajesh");
                    break;
                case 4:
                    Console.WriteLine("Howard");
                    break;
            }
        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            double a = 0;
            double b = 0;
            string c = "";
            bool d = true;
            double i = 1;
            double n = double.Parse(Console.ReadLine());
            while( d == true)
            {
                a += i * 5;
                if (a >= n)
                {
                    b = (n - (a-i*5));
                    if (b / i <= 1 && b / i > 0)
                        c = "Sheldon";
                    else if (b / i <= 2 && b / i > 1)
                        c = "Leonard";
                    else if (b / i <= 3 && b / i > 2)
                        c = "Penny";
                    else if (b / i <= 4 && b / i > 3)
                        c = "Rajesh";
                    else if (b / i <= 5 && b / i > 4)
                        c = "Howard";
                    d = false;
                }
                i = i*2;
            }

            Console.WriteLine(c);

            Console.ReadLine();
        }
    }
}


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

namespace Problem379A {
    class Program {
        static void Main(string[] args) {
            string[] input = Console.ReadLine().Split(' ');
            int candles = Convert.ToInt32(input[0]);
            int newCandleRequirement = Convert.ToInt32(input[1]);

            int hours = 0;
            int newCandles = 0;
            int oldCandles = 0;

            while (candles != 0) {
                hours += candles;

                newCandles = candles / newCandleRequirement;
                oldCandles += (candles - newCandles*newCandleRequirement);

                candles = newCandles;
                if (oldCandles >= newCandleRequirement) {
                    candles++;
                    oldCandles -= newCandleRequirement;
                }
            }

            Console.WriteLine(hours);
        }
    }
}


using System;
using System.Collections.Generic;

namespace Main
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			string[] map = Console.ReadLine ().Split (' ');
			int a = Convert.ToInt32 (map[0]);
			int b = Convert.ToInt32 (map[1]);

			int t = 0;
			int p = 0;

			while (a > 0) {
				t++;
				p++;
				a--;
				if (p % b == 0){
					a++;
					p = 0;
				}
			}

			Console.WriteLine (t);
		}
	}
}


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

namespace MakeCalendar
{
    public static class MainClass
    {

        static int ReadIntLine()
        {
            return int.Parse(Console.ReadLine());
        }

        static void ReadInt(ref int a)
        {
            a = ReadIntArrayLine()[0];
        }

        static void ReadInts(ref int a, ref int b)
        {
            var x = ReadIntArrayLine();
            a = x[0]; b = x[1];
        }

        static void ReadInts(ref int a, ref int b, ref int c)
        {
            var x = ReadIntArrayLine();
            a = x[0]; b = x[1]; c = x[2];
        }

        static void ReadInts(ref int a, ref int b, ref int c, ref int d)
        {
            var x = ReadIntArrayLine();
            a = x[0]; b = x[1]; c = x[2]; d = x[3];
        }

        static int[] ReadIntArrayLine()
        {
            char[] sep = { ' ' };
            return Console.ReadLine().Split(sep, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToArray();
        }

        static void PrintLn(object obj)
        {
            Console.WriteLine(obj.ToString());
        }

        public static string Reverse(string s)
        {
            char[] charArray = s.ToCharArray();
            Array.Reverse(charArray);
            return new string(charArray);
        }

        public static void PrintLnCollection<T>(IEnumerable<T> col)
        {
            PrintLn(string.Join(" ", col));
        }

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

        public static string MySubstring(this string str, int start, int finish)
        {
            return str.Substring(start, finish - start + 1);
        }

        public static bool IsInRange(this int a, int lb, int ub)
        {
            return (a >= lb) && (a <= ub);
        }

        //----------------------------------------------------------------------------

        static Mat mult(Mat m1, Mat m2, int p)
        {
            var res = new Mat();

            res.a = (m1.a * m2.a + m1.b * m2.c)%p;
            res.b = (m1.a * m2.b + m1.b * m2.d)%p;
            res.c = (m1.c * m2.a + m1.d * m2.c)%p;
            res.d = (m1.c * m2.b + m1.d * m2.d)%p;

            return res;
        }

        static Mat pow(Mat m, int n, int p)
        {
            if (n == 0)
                return new Mat() {a=1,c=0,d=1,b=0 };

            var temp = pow(m, n / 2,p);
            if (n % 2 == 0)
                return mult(temp, temp,p);
            else
                return mult(m, mult(temp, temp,p),p);
        }

        static void Main(string[] args)
        {
            int x = 0, y = 0;
            int n = 0;

            ReadInts(ref x, ref y);
            n = ReadIntLine();

            decimal ans;
            if (n==1)
                ans =  x;
            else if (n==2)
                ans = y;
            else
            {
                var m = new Mat(){a=1,b=-1,c=1,d=0};
                var t = pow(m, n - 2, 1000000007);
                ans = (y * t.a + x * t.b) % 1000000007;
            }

            if (ans < 0) ans += 1000000007;
            PrintLn(ans);

        }

    }

    class Mat
    {
        public decimal a;
        public decimal b;
        public decimal c;
        public decimal d;
    }
}


#define TRACE
#undef DEBUG
/*
Author: w1ld [dog] inbox [dot] ru

 */
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Diagnostics;
using static System.Math;

public class Solver
{
    public void Solve()
    {
        // f3 = f2 - f1
        // f4 = f3 - f2
        // f5 = f4 - f3
        // ...
        // fn = f{n-1} - f{n-2}
        // fn = f{n-2} - f{n-3} - (f{n-3} - f{n-4})
        // fn = f{n-2} - 2*f{n-3} + f{n-4}
        // fn = f{n-3} - fn-4 - 2*(f{n-4} - fn-5) + f{n-5} - f(n-6)
        // fn = f{n-3} - fn-4 - 2*(f{n-4} - fn-5) + f{n-5} - f(n-6)
        //
        // f1
        // f2
        // f3 = f2 - f1
        // f4 = -f1
        // f5 = -f2
        // f6 = -f2 + f1
        // f7 = f1
        // f8 = f2
        // f9 = f2 - f1
        // ...
        //
        // n%6
        // 1 = f1
        // 2 = f2
        // ...
        //
        //

        const long MOD = (int)(1e9 + 7);

        long x = ReadInt();
        long y = ReadInt();
        int n = ReadInt();
        Action<long> MWrite = (a) => Write((a%MOD) < 0 ? (a%MOD)+MOD : a%MOD);
        switch (n % 6)
        {
            case 1:
                MWrite(x);
                break;
            case 2:
                MWrite(y);
                break;
            case 3:
                MWrite(y - x);
                break;
            case 4:
                MWrite(-x);
                break;
            case 5:
                MWrite(-y);
                break;
            case 0:
                MWrite(-y + x);
                break;
            default:
                throw new Exception();
        }
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
        Debug.Listeners.Clear();
        Debug.Listeners.Add(new ConsoleTraceListener());
        Trace.Listeners.Clear();
        Trace.Listeners.Add(new ConsoleTraceListener());

        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        new Solver().Solve();
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array)writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }
    #endregion
}


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

namespace N4
{
    class Program
    {
        static void Main(string[] args)
        {
            string n, s;
            int pos = 0;
            byte count;

            s = "4";

         //   Console.Write("Введите число из последовательности: ");
            n = Console.ReadLine();

            for (int i = 1; i < n.Length; i++)
            {
                pos += (int)Math.Pow(2, i);
                s += "4";
            }

            count = (byte)s.Length;

            while (true)
            {
                pos++;

                if (int.Parse(n) == int.Parse(s)) break;

                if (s[count - 1] == '4')
                {
                    s = s.Remove(count - 1);
                    s += "7";
                }
                else
                {
                    for (int i = count - 1; i >= 0; i--)
                    {
                        if (s[i] == '4')
                        {
                            s = s.Remove(i);
                            s += "7";

                            while (s.Length < count)
                                s += "4";

                            break;
                        }
                    }
                }

            }

         //   Console.Write("Номер числа {0} - {1}.", n, pos);
            Console.Write(pos);
         //   Console.ReadLine();

        }
    }
}


using System;
 class Program
    {
        static void Main(string[] args)
        {
            double result = 0;
            char[] input = Console.ReadLine().ToCharArray();
            result += Math.Pow(2D, input.Length);
            {
                double pow = 1D, crr = pow;
                for (int i = input.Length - 1; i >= 0; --i, pow*=2D)
                {
                    crr = ((input[i] == '4') ? '0' : '1') - 48D;
                    result += crr * pow;
                }
            }
            Console.WriteLine(--result);
        }
    }


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

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

        {
            string[,] lines = new string[8, 8];
            string input;

            for (int i = 0; i < 8; i++)
            {
                input = Console.ReadLine();
                for (int j = 0; j < 8; j++)
                {
                    lines[i, j] = input[j] + "";
                }
            }

            int white = 0;
            int black = 0;

            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    switch (lines[i, j])
                    {
                        case "Q":
                            white += 9;
                            break;
                        case "R":
                            white += 5;
                            break;
                        case "B":
                            white += 3;
                            break;
                        case "N":
                            white += 3;
                            break;
                        case "P":
                            white += 1;
                            break;
                        case "q":
                            black += 9;
                            break;
                        case "r":
                            black += 5;
                            break;
                        case "b":
                            black += 3;
                            break;
                        case "n":
                            black += 3;
                            break;
                        case "p":
                            black += 1;
                            break;

                    }

                }
            }

            if (black > white)
            {
                Console.WriteLine("Black");
            }
            else if (black == white)
            {
                Console.WriteLine("Draw");
            }
            else
            {
                Console.WriteLine("White");

            }

        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[,] k = new string[8, 8];
            string g;
            int black = 0, white = 0;
            for (int i = 0; i < 8; i++)
            {
                g = Console.ReadLine();
                for (int j = 0; j < 8; j++)
                {
                    k[i, j] = g[j].ToString();
                }
            }
                for (int i = 0; i < 8; i++)
                {
                    for (int j = 0; j < 8; j++)
                    {

                        switch (k[i,j])
                        {
                            case "Q":
                                {
                                    white += 9;
                                    break;
                                }
                            case "R":
                                {
                                    white += 5;
                                    break;
                                }
                            case "B":
                                {
                                    white += 3;
                                    break;
                                }
                            case "N":
                                {
                                    white += 3;
                                    break;
                                }
                            case "P":
                                {
                                    white += 1;
                                    break;
                                }
                            case "q":
                                {
                                    black += 9;
                                    break;
                                }
                            case "r":
                                {
                                    black += 5;
                                    break;
                                }
                            case "b":
                                {
                                    black += 3;
                                    break;
                                }
                            case "n":
                                {
                                    black += 3;
                                    break;
                                }
                            case "p":
                                {
                                    black += 1;
                                    break;
                                }
                        }
                    }

                }
            if (white > black)
            {
                Console.Write("White");
            }
            else if (black > white)
            {
                Console.Write("Black");
            }
            else
            {
                Console.Write("Draw");
            }
        }
    }
}


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

namespace ConsoleApp2
{
    class Program
    {
        class element
        {
            public int index;
            public int count;
        }
        static int f(List<int> Even, List<int> Odd, ref int CountEven, ref int CountOdd, int count)
        {
            int i = 0;
            int c = 0;
            while (i < Even.Count && Even[i] <= CountEven)
            {
                CountEven -= Even[i]; i++;
                c++;
            }
            count += (Even.Count - c) * 2;
            i = 0; c = 0;
            while (i < Odd.Count && Odd[i] <= CountOdd)
            {
                CountOdd -= Odd[i]; i++;
                c++;
            }
            count += (Odd.Count - c) * 2;
            return count;
        }
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            if(n==1)
            {
                Console.WriteLine(0);
                return;
            }
            string[] str = Console.ReadLine().Split();
            int[] a = new int[n];
            int count = 0;
            int CountOdd = (n + 1) / 2, CountEven = n / 2;
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(str[i]);
                if (a[i] != 0)
                {
                    if (a[i] % 2 == 1)
                        CountOdd--;
                    else
                        CountEven--;
                }
            }
            int FirstEven = -1, FirstOdd = -1, LastEven = -1, LastOdd = -1;
            int CountZero = 0;
            List<int> Even = new List<int>();
            List<int> Odd = new List<int>();
            for (int i = -1; i < n - 1; i++)
            {
                if (a[i + 1] == 0)
                {
                    int first = i;
                    CountZero = 0;
                    for (++i; i < n && a[i] == 0; i++)
                        CountZero++;
                    if (first == -1 && i == n)
                    {
                        Console.WriteLine(1);
                        return;
                    }
                    if (first == -1)
                    {
                        if (a[i] % 2 == 0)
                            FirstEven = CountZero;
                        else
                            FirstOdd = CountZero;
                        i--;
                        continue;
                    }
                    if (i == n)
                    {
                        if (a[first] % 2 == 0)
                            LastEven = CountZero;
                        else
                            LastOdd = CountZero;
                        i--;
                        continue;
                    }
                    if (a[first] % 2 == a[i] % 2)
                    {

                        if (a[first] % 2 == 0)
                            Even.Add(CountZero);
                        else
                            Odd.Add(CountZero);
                    }
                    else
                        count++;
                    i--;
                }
                else
                {
                    if (i >= 0 && i + 1 < n)
                    {
                        if (a[i] % 2 != a[i + 1] % 2)
                            count++;
                    }
                }
            }
            Even.Sort();
            Odd.Sort();
            count = f(Even, Odd, ref CountEven, ref CountOdd, count);

            if (FirstEven != -1)
            {
                if (CountEven >= FirstEven)
                    CountEven -= FirstEven;
                else
                    count++;
            }
            if (FirstOdd != -1)
            {
                if (CountOdd >= FirstOdd)
                    CountOdd -= FirstOdd;
                else
                    count++;
            }
            if (LastEven != -1)
            {
                if (CountEven >= LastEven)
                    CountEven -= LastEven;
                else
                    count++;
            }
            if (LastOdd != -1)
            {
                if (CountOdd >= LastOdd)
                    CountOdd -= LastOdd;
                else
                    count++;
            }

            Console.WriteLine(count);
        }
    }
}


using System;
using System.Linq;

class C
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var p = Read();

		var even = n / 2;
		var odd = (n + 1) / 2;
		var max = 1 << 20;

		var dp = new int[n + 1, even + 1, 2];
		for (int i = 0; i <= n; i++)
			for (int j = 0; j <= even; j++)
				for (int k = 0; k < 2; k++)
					dp[i, j, k] = max;
		dp[0, 0, 0] = 0;
		dp[0, 0, 1] = 0;

		for (int i = 1; i <= n; i++)
		{
			var v = p[i - 1];
			var e_max = Math.Min(i, even);
			var e_min = Math.Max(i - odd, 0);

			for (int j = e_min; j <= e_max; j++)
			{
				if ((v == 0 || v % 2 == 0) && j > 0)
					dp[i, j, 0] = Math.Min(dp[i - 1, j - 1, 0], dp[i - 1, j - 1, 1] + 1);
				if (v == 0 || v % 2 == 1)
					dp[i, j, 1] = Math.Min(dp[i - 1, j, 0] + 1, dp[i - 1, j, 1]);
			}
		}
		Console.WriteLine(Math.Min(dp[n, even, 0], dp[n, even, 1]));
	}
}


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

namespace G.GangUp
{
    internal static class Program
    {
        public static void Main(string[] args)
        {
            var nmkcd = Console.ReadLine().Split();
            var n = int.Parse(nmkcd[0]);
            var m = int.Parse(nmkcd[1]);
            var k = int.Parse(nmkcd[2]);
            var c = int.Parse(nmkcd[3]);
            var d = int.Parse(nmkcd[4]);

            var solver = new Solver(n, m, k, c, d);
            solver.Init();

            var memberHomes = Console.ReadLine().Split().GroupBy(int.Parse);
            foreach (var memberHome in memberHomes)
                solver.AddMemberHome(memberHome.Key - 1, memberHome.Count());

            for (var i = 0; i < m; i++)
            {
                var xy = Console.ReadLine().Split();
                var x = int.Parse(xy[0]) - 1;
                var y = int.Parse(xy[1]) - 1;

                solver.AddEdge(x, y);
                solver.AddEdge(y, x);
            }

            for (var i = 0; i < k; i++)
                solver.IncreaseFlow();

            Console.WriteLine(solver.TotalCost);
        }
    }

    internal sealed class Solver
    {
        private static readonly Edge FakeEdge = new Edge();

        private readonly int _n, _m, _k, _c, _d;
        private readonly int _maxTime;
        private readonly Node _start, _sink;
        private readonly Node[,] _nodes;
        private readonly List<Edge>[] _nodeEdges;

        private readonly int[] _bestCosts;
        private readonly Edge[] _bestMoves;
        private readonly bool[] _isInQueue;
        private readonly Queue<Node> _bestPathSearchQueue;

        public Solver(int n, int m, int k, int c, int d)
        {
            _n = n;
            _m = m;
            _k = k;
            _c = c;
            _d = d;

            _maxTime = k + m;
            _nodes = new Node[n, _maxTime];

            _start = new Node() {Id = _nodes.Length};
            _sink = new Node() {Id = _nodes.Length + 1};

            var allNodesCount = _nodes.Length + 2;

            _nodeEdges = new List<Edge>[allNodesCount];
            _bestCosts = new int[allNodesCount];
            _bestMoves = new Edge[allNodesCount];
            _isInQueue = new bool[allNodesCount];
            _bestPathSearchQueue = new Queue<Node>(allNodesCount);

            for (var i = 0; i < allNodesCount; i++)
                _nodeEdges[i] = new List<Edge>();
        }

        public int TotalCost { get; private set; }

        public void Init()
        {
            var nodeId = 0;
            for (var node = 0; node < _n; node++)
                for (var time = 0; time < _maxTime; time++)
                    _nodes[node, time] = new Node() { Id = nodeId++ };

            for (var time = 0; time < _maxTime; time++)
                AddEdgePair(_nodes[0, time], _sink, time * _c, _k);

            for (var node = 0; node < _n; node++)
            {
                var from = _nodes[node, 0];
                for (var time = 1; time < _maxTime; time++)
                {
                    var to = _nodes[node, time];
                    AddEdgePair(from, to, 0, _k);
                    from = to;
                }
            }

            _isInQueue[_sink.Id] = true;
        }

        public void AddMemberHome(int home, int count)
        {
            _nodeEdges[_start.Id].Add(new Edge()
            {
                From = _start,
                To = _nodes[home, 0],
                Cost = 0,
                ResidualCapacity = count,
                Paired = FakeEdge,
            });
        }

        public void AddEdge(int from, int to)
        {
            for (var time = 0; time < _maxTime - 1; time++)
            {
                var nodeFrom = _nodes[from, time];
                var nodeTo = _nodes[to, time + 1];

                for (int people = 0, cost = 1; people < _k; people++, cost += 2)
                    AddEdgePair(nodeFrom, nodeTo, cost * _d, 1);
            }
        }

        public void IncreaseFlow()
        {
            FindBestPath();
            CommitBestPath();
            TotalCost += _bestCosts[_sink.Id];
        }

        private void FindBestPath()
        {
            for (var i = 0; i < _bestCosts.Length; i++)
                _bestCosts[i] = int.MaxValue;

            _bestCosts[_start.Id] = 0;
            _bestPathSearchQueue.Enqueue(_start);

            while (_bestPathSearchQueue.Count > 0)
            {
                var node = _bestPathSearchQueue.Dequeue();
                var costToNode = _bestCosts[node.Id];

                foreach (var edge in _nodeEdges[node.Id])
                {
                    if (edge.ResidualCapacity == 0)
                        continue;

                    var possibleCost = costToNode + edge.Cost;
                    if (possibleCost >= _bestCosts[edge.To.Id])
                        continue;

                    _bestCosts[edge.To.Id] = possibleCost;
                    _bestMoves[edge.To.Id] = edge;
                    if (_isInQueue[edge.To.Id])
                        continue;

                    _isInQueue[edge.To.Id] = true;
                    _bestPathSearchQueue.Enqueue(edge.To);
                }

                _isInQueue[node.Id] = false;
            }
        }

        private void CommitBestPath()
        {
            var cur = _bestMoves[_sink.Id];
            while (cur != null)
            {
                cur.ResidualCapacity--;
                cur.Paired.ResidualCapacity++;
                cur = _bestMoves[cur.From.Id];
            }
        }

        private void AddEdgePair(Node from, Node to, int cost, int capacity)
        {
            var forwardEdge = new Edge()
            {
                From = from,
                To = to,
                Cost = cost,
                ResidualCapacity = capacity,
            };

            var reverseEdge = new Edge()
            {
                From = to,
                To = from,
                Cost = -cost,
                ResidualCapacity = 0,
            };

            forwardEdge.Paired = reverseEdge;
            reverseEdge.Paired = forwardEdge;

            _nodeEdges[from.Id].Add(forwardEdge);
            _nodeEdges[to.Id].Add(reverseEdge);
        }
    }

    internal struct Node
    {
        public int Id { get; set; }
        public override string ToString() => Id.ToString();
    }

    internal sealed class Edge
    {
        public Node From { get; set; }
        public Node To { get; set; }
        public int Cost { get; set; }
        public int ResidualCapacity { get; set; }
        public Edge Paired { get; set; }
    }
}


using System;
using System.Linq;

class Program
{
    private static void Main()
    {
        int result = 0;
        var knw = ConsoleReadLineAsArrayOfIntegers();
        int k = knw[0];
        int n = knw[1];
        int w = knw[2];

        int totalPrice = 0;
        for(int i = 0; i < w; i++)
        {
            totalPrice += k * (i + 1);
        }
        if (totalPrice <= n){
            Console.WriteLine("0");
            return;
        }
        result = totalPrice - n;
        Console.WriteLine("" + result);
    }

    private static int[] ConsoleReadLineAsArrayOfIntegers()
    {
        return Console.ReadLine().Split(' ').Select(n => Convert.ToInt32(n)).ToArray();
    }

    private static int ConsoleReadLineAsInteger()
    {
        return Convert.ToInt32(Console.ReadLine());
    }

    private static void ConsoleWriteLine(string line)
    {
        Console.WriteLine(line);
    }
}


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

namespace problem
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] tokens = Console.ReadLine().Split();
            int k = int.Parse(tokens[0]);
            long n = int.Parse(tokens[1]);
            int w = int.Parse(tokens[2]);
            long totaldollar = 0;

            for(int i=1;i<=w;i++)
            {
                totaldollar += i * k;
            }
            long borrow=0;
            if (totaldollar > n)
                borrow = totaldollar - n;
            else
                borrow = 0;
            Console.WriteLine(borrow);

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var text = Console.ReadLine().ToLower().Select(c=>(int)c).ToList();
            var total = 0;
            for (int i = 0; i < 26; i++)
            {
                if (text.Contains(97 + i))
                {
                    total++;
                }
            }
            Console.WriteLine(total == 26 ? "YES" : "NO");
        }
    }
}


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

    class Program
    {
        static void Main(string[] args)
        {
            Dictionary<Char, int> result = new Dictionary<char, int>();
            int n = 0;
            string readLine = Console.ReadLine();
            if (int.TryParse(readLine, out n))
            {
                string word = Console.ReadLine();
                word = word.ToLower();
                for(int i=0; i < n; i++)
                {
                    int value;
                    if (result.TryGetValue(word[i], out value))
                    {
                        result[word[i]] = value + 1;
                    }
                    else
                    {
                        result.Add(word[i], 1);
                    }
                }

                if (result.Count >= 26)
                {
                    Console.WriteLine("YES");
                }
                else
                    Console.WriteLine("NO");
            }

        }
    }


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

namespace CodeForces
{
	public class Program
	{
		public static void Main(string[] args)
		{
			string k1 = Console.ReadLine();
			string[] p1 = k1.Split(null);
			int n = int.Parse(p1[0]);
			int q = int.Parse(p1[1]);

			string[] a = new string[q];
			char[] b = new char[q];

			for (int i = 0; i < q; i++)
			{
				string k = Console.ReadLine();
				string[] p = k.Split(null);
				a[i] = p[0];
				b[i] = p[1].ToCharArray()[0];
			}

			int oper = n - 1;
			int[] start = new int[6];
			start[0] = 1;
			for (int i = 0; i < oper; i++)
			{
				int[] next = new int[6];

				for (int j = 0; j < 6; j++)
				{
					if (start[j] != 0)
					{
						for (int k = 0; k < b.Length; k++)
						{
							if (b[k] - 'a' == j)
							{
								next[a[k].ToCharArray()[0] - 'a'] += start[j];
							}
						}
					}
				}
				start = next;
			}
			Console.Write(start.Sum());
		}

	}
}


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

namespace Codeforces
{
    class Program
    {

        static void Main(string[] args)
        {
            //#if DEBUG
            StreamReader reader = new StreamReader(Console.OpenStandardInput(32768), Encoding.ASCII, false, 32768);
            StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(32768), Encoding.ASCII, 32768);
            //#else
            //            StreamReader streamReader = new StreamReader(Console.OpenStandardInput(32768), Encoding.ASCII, false, 32768);
            //            StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(32768), Encoding.ASCII, 32768);
            //#endif
            InputReader input = new InputReader(reader);

            int n = input.NextInt();
            int q = input.NextInt();
            Dictionary<string, List<string>> dic = new Dictionary<string, List<string>>();
            while (q-- > 0)
            {
                string s1 = input.Next();
                string s2 = input.Next();

                if (!dic.ContainsKey(s2))
                {
                    dic.Add(s2, new List<string>());
                }
                dic[s2].Add(s1.Substring(0, 1));
            }
            List<string> list = new List<string>();
            list.Add("a");
            for (int i = 1; i < n; i++)
            {
                List<string> L = new List<string>();
                bool find = false;
                foreach (string s in list)
                {
                    if (dic.ContainsKey(s))
                    {
                        find = true;
                        L.AddRange(dic[s]);
                    }
                }
                if (!find)
                {
                    writer.WriteLine(0);
                    writer.Close();
                    return;
                }
                list = new List<string>(L);
            }
            writer.WriteLine(list.Count);

#if DEBUG
                Console.BackgroundColor = ConsoleColor.White;
                Console.ForegroundColor = ConsoleColor.Black;
#endif
            writer.Close();
            reader.Close();
        }

        private static string Rev(string p)
        {
            string s = "";
            for (int i = p.Length - 1; i >= 0; i--)
            {
                s += p[i];
            }
            return s;
        }
    }

    // this class is copy
    class InputReader
    {
        private char[] _inbuf;
        private int _lenbuf = 0, _ptrbuf = 0;
        private StreamReader _reader;

        public InputReader(StreamReader reader)
        {
            _reader = reader;
            _inbuf = new char[1024];
            _lenbuf = 0;
            _ptrbuf = 0;
        }

        private int ReadByte()
        {
            if (_lenbuf == -1)
                throw new Exception();
            if (_ptrbuf >= _lenbuf)
            {
                _ptrbuf = 0;
                try
                {
                    _lenbuf = _reader.Read(_inbuf, 0, 1024);
                }
                catch (IOException e)
                {
                    throw e;
                }
                if (_lenbuf <= 0)
                    return -1;
            }
            return _inbuf[_ptrbuf++];
        }

        private bool IsSpaceChar(int c)
        {
            return !(c >= 33 && c <= 126);
        }

        private int Skip()
        {
            int b;
            while ((b = ReadByte()) != -1 && IsSpaceChar(b)) ;
            return b;
        }

        public int NextInt()
        {
            return int.Parse(this.Next());
        }

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

        public string Next()
        {
            var b = Skip();
            var sb = new StringBuilder();
            while (!(IsSpaceChar(b)))
            {
                sb.Append((char)b);
                b = ReadByte();
            }
            return sb.ToString();
        }

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


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

namespace Round_277
{
    class Program
    {
        static void Main(string[] args)
        {
            FunctionCalc fc = new FunctionCalc();
            fc.Test();
        }

    }
    class FunctionCalc
    {
        long Sum(long a1,long an,long n)
        {
            return (a1 + an) * n / 2;
        }
        long Calc(long n)
        {
            if (n == 1) return -1;
            if (n == 2) return 1;
            if(n%2==0)
            {
                return Sum(2, n, n / 2) - Sum(1, n - 1, n / 2);
            }
            else
            {
                return Sum(2, n - 1, (n - 1) / 2) - Sum(1, n, (n + 1) / 2);
            }
        }
        long Calc2(long n)
        {
            long sum = 0;
            for(long i=1;i<=n;i++)
            {
                if (i % 2 == 0) sum += i;
                else sum -= i;
            }
            return sum;
        }
        long Calc3(long n)
        {
            if (n % 2 == 0) return n / 2;
            else return -(n + 1) / 2;
        }
        public void Test()
        {
            long n = long.Parse(Console.ReadLine());
            Console.WriteLine(Calc3(n));
        }
    }
}


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

namespace A.Подсчёт_функции
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());

            Console.WriteLine(fun(n));
            Console.ReadLine();
        }

        static long fun(long n)
        {
            if (n % 2 == 0)
                return n / 2;
            else
                return -n / 2 - 1;
        }
    }
}


using System;
class HelloWorld {
  static void Main(string [] args) {
      string s = Console.ReadLine();
      string str = Console.ReadLine();
     string s1 = s.ToLower();
     string str1=str.ToLower();
        var res = String.Compare(s1,str1);
        if (res>0)
        {

            Console.WriteLine('1');
        }
        else if (res<0)
        {
            Console.WriteLine("-1");
        }
        else
        {
            Console.WriteLine('0');
        }
}
  }


using System;

namespace Strings
{
    class Program {
        static void Main(string[] args){
            string firstWord = Console.ReadLine();
            string secondWord = Console.ReadLine();

            firstWord = firstWord.ToLower();
            secondWord = secondWord.ToLower();

            int charCompareResult = 0;
            for (int i = 0; i< firstWord.Length; i++){
                charCompareResult = firstWord[i] - secondWord[i];
                if (charCompareResult != 0){
                    Console.Write(Math.Sign(charCompareResult));
                    break;
                }
            }
            if (charCompareResult == 0){
                Console.Write(0);
            }

        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        internal static void MyMain()
        {
            int[] ints = RInts();
            var all = ints.GroupBy(a => a).Select(a => a.Count()).OrderBy(a => a).Reverse().ToList();
            if (all[0] >= 4)
            {
                if ((all.Count >= 2 && all[1] >= 2) || all[0] == 6)
                {
                    WLine("Elephant");
                    return;
                }
                else if (all[1] == 1 && all[0] == 5 || (all[0] == 4 && all[1] == 1 && all[2] >= 1))
                {
                    WLine("Bear");
                    return;
                }
                else {
                    WLine("Elien");
                    return;
                }
            }
            else {
                WLine("Alien");
            }

        }

        class Dragon
        {
            public int lvl { get; set; }
            public int exp { get; set; }
        }

        static void Main()
        {
#if !HOME
            MyMain();
#else
            Secret.Run();
#endif
        }

        #region Utils
        static string RLine()
        {
            return Console.ReadLine();
        }

        static int RInt()
        {
            var str = Console.ReadLine();
            return Convert.ToInt32(str);
        }
        static int[] RInts()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), s => Convert.ToInt32(s));
        }
        static void RInts(out int a, out int b)
        {
            var ints = RInts();
            a = ints[0];
            b = ints[1];
        }
        static void RLongs(out long a, out long b)
        {
            var ints = Array.ConvertAll(Console.ReadLine().Split(' '), s => Convert.ToInt64(s));
            a = ints[0];
            b = ints[1];
        }
        public static void WLine<T>(T s)
        {
            Console.WriteLine(s);
        }
        #endregion
    }
}


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

class Solver
{
    void Solve()
    {
        var a = sc.IntArray(6);
        var h = new int[10];
        foreach (var x in a)
            h[x]++;
        for (int i = 1; i < 10; i++)
        {
            if (h[i] == 4)
            {

                for (int j = 1; j < 10; j++)
                {
                    if (i == j)
                        continue;
                    if (h[j] == 2)
                    {
                        Printer.PrintLine(Elephant=>1);
                        return;
                    }

                }
                Printer.PrintLine(Bear=>1);
                return;
            }
            if (h[i] == 5)
            {
                Printer.PrintLine(Bear=>1);
                return;
            }
            if (h[i] == 6)
            {
                Printer.PrintLine(Elephant=>1);
                return;
            }

        }
        Printer.PrintLine(Alien => 1);
    }
    static void Main()
    {
#if DEBUG
        var oStream = new System.IO.FileStream("debug.txt", System.IO.FileMode.Create, System.IO.FileAccess.Write);
        var iStream = new System.IO.FileStream("input.txt", System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
        Console.SetIn(new System.IO.StreamReader(iStream));
        System.Diagnostics.Debug.AutoFlush = true;
        System.Diagnostics.Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(new System.IO.StreamWriter(oStream, System.Text.Encoding.UTF8)));
        try
        {
#endif
            var solver = new Solver();
            solver.Solve();
#if DEBUG
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            Console.WriteLine(ex.StackTrace);
        }
        Console.ReadKey(true);
#endif
    }
    _Scanner sc = new _Scanner(Console.In);

}
static public class Printer
{
    static readonly private System.IO.TextWriter writer;
    static readonly private System.Globalization.CultureInfo info;
    static string Separator { get; set; }
    static Printer()
    {
        writer = Console.Out;
        info = System.Globalization.CultureInfo.InvariantCulture;
        Separator = " ";
    }

    static public void Print(int num) { writer.Write(num.ToString(info)); }
    static public void Print(int num, string format) { writer.Write(num.ToString(format, info)); }
    static public void Print(long num) { writer.Write(num.ToString(info)); }
    static public void Print(long num, string format) { writer.Write(num.ToString(format, info)); }
    static public void Print(double num) { writer.Write(num.ToString(info)); }
    static public void Print(double num, string format) { writer.Write(num.ToString(format, info)); }
    static public void Print(string str) { writer.Write(str); }
    static public void Print(string format, params object[] arg) { writer.Write(format, arg); }
    static public void Print(IEnumerable<char> sources) { writer.Write(sources.AsString()); }
    static public void Print(System.Linq.Expressions.Expression<Func<string, object>> expression)
    {
        var p = expression.Parameters[0];
        writer.WriteLine(p.Name);

    }

    static public void Print(params object[] arg)
    {
        var res = new System.Text.StringBuilder();
        foreach (var x in arg)
        {
            res.AppendFormat(info, "{0}", x);
            if (!string.IsNullOrEmpty(Separator))
                res.Append(Separator);
        }
        writer.Write(res.ToString(0, res.Length - Separator.Length));
    }
    static public void Print<T>(IEnumerable<T> sources)
    {
        var res = new System.Text.StringBuilder();
        foreach (var x in sources)
        {
            res.AppendFormat(info, "{0}", x);
            if (string.IsNullOrEmpty(Separator))
                res.Append(Separator);
        }
        writer.Write(res.ToString(0, res.Length - Separator.Length));

    }
    static public void PrintLine(int num) { writer.WriteLine(num.ToString(info)); }
    static public void PrintLine(int num, string format) { writer.WriteLine(num.ToString(format, info)); }
    static public void PrintLine(long num) { writer.WriteLine(num.ToString(info)); }
    static public void PrintLine(long num, string format) { writer.WriteLine(num.ToString(format, info)); }
    static public void PrintLine(double num) { writer.WriteLine(num.ToString(info)); }
    static public void PrintLine(double num, string format) { writer.WriteLine(num.ToString(format, info)); }
    static public void PrintLine(string str) { writer.WriteLine(str); }
    static public void PrintLine(string format, params object[] arg) { writer.WriteLine(format, arg); }
    static public void PrintLine(IEnumerable<char> sources) { writer.WriteLine(sources.AsString()); }
    static public void PrintLine(System.Linq.Expressions.Expression<Func<string, object>> expression)
    {
        var p = expression.Parameters[0];
        writer.WriteLine(p.Name);

    }
    static public void PrintLine(params object[] arg)
    {
        var res = new System.Text.StringBuilder();
        foreach (var x in arg)
        {
            res.AppendFormat(info, "{0}", x);
            if (!string.IsNullOrEmpty(Separator))
                res.Append(Separator);
        }
        writer.WriteLine(res.ToString(0, res.Length - Separator.Length));
    }
    static public void PrintLine<T>(IEnumerable<T> sources)
    {
        var res = new System.Text.StringBuilder();
        foreach (var x in sources)
        {
            res.AppendFormat(info, "{0}", x);
            if (!string.IsNullOrEmpty(Separator))
                res.Append(Separator);
        }
        writer.WriteLine(res.ToString(0, res.Length - Separator.Length));
    }
}
public class _Scanner
{
    readonly private System.Globalization.CultureInfo info;
    readonly System.IO.TextReader reader;
    string[] buffer = new string[0];
    int position;

    public char[] Separator { get; set; }
    public _Scanner(System.IO.TextReader reader, string separator = null, System.Globalization.CultureInfo info = null)
    {
        if (reader == null)
            throw new ArgumentNullException("reader");
        this.reader = reader;
        if (string.IsNullOrEmpty(separator))
            separator = " ";
        this.Separator = separator.ToCharArray();
        this.info = info ?? System.Globalization.CultureInfo.InvariantCulture;
    }
    public string Scan()
    {
        if (this.position < this.buffer.Length)
            return this.buffer[this.position++];
        this.buffer = this.reader.ReadLine().Split(this.Separator, StringSplitOptions.RemoveEmptyEntries);
        this.position = 0;
        return this.buffer[this.position++];
    }

    public string[] ScanToEndLine()
    {
        if (this.position >= this.buffer.Length)
            return this.reader.ReadLine().Split(this.Separator, StringSplitOptions.RemoveEmptyEntries);
        var size = this.buffer.Length - this.position;
        var ar = new string[size];
        Array.Copy(this.buffer, position, ar, 0, size);
        return ar;

    }

    public string ScanLine()
    {
        if (this.position >= this.buffer.Length)
            return this.reader.ReadLine();
        else
        {
            var sb = new System.Text.StringBuilder();
            for (; this.position < buffer.Length; this.position++)
            {
                sb.Append(this.buffer[this.position]);
                sb.Append(' ');
            }
            return sb.ToString();
        }
    }
    public string[] ScanArray(int length)
    {
        var ar = new string[length];
        for (int i = 0; i < length; i++)
        {
            ar[i] = this.Scan();
        }
        return ar;
    }

    public int Integer()
    {
        return int.Parse(this.Scan(), info);
    }
    public long Long()
    {
        return long.Parse(this.Scan(), info);
    }
    public double Double()
    {
        return double.Parse(this.Scan(), info);
    }
    public double Double(string str)
    {
        return double.Parse(str, info);
    }

    public int[] IntArray(int length)
    {
        var a = new int[length];
        for (int i = 0; i < length; i++)
            a[i] = this.Integer();
        return a;
    }
    public long[] LongArray(int length)
    {
        var a = new long[length];
        for (int i = 0; i < length; i++)
            a[i] = this.Long();
        return a;
    }
    public double[] DoubleArray(int length)
    {
        var a = new double[length];
        for (int i = 0; i < length; i++)
            a[i] = this.Double();
        return a;
    }

}
static public partial class EnumerableEx
{
    static public string AsString(this IEnumerable<char> source)
    {
        return new string(source.ToArray());
    }
    static public T[] EnumerateArray<T>(this int count, Func<int, T> selector)
    {
        var ret = new T[count];
        for (int i = 0; i < count; i++)
            ret[i] = selector(i);
        return ret;
    }
}
//*/


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)
        {
            var a = int.Parse(Console.ReadLine());
            for (int i = a; i < 1112; i++)
            {
                var s = SummDigits(i);
                if (s%4 == 0)
                {
                    Console.WriteLine(i);
                    return;
                }
            }
        }

        static int SummDigits(int n)
        {
            var s = 0;
            while (n > 0)
            {
                s += n%10;
                n /= 10;
            }

            return s;
        }
    }
}


using System;
namespace Codeforces
{

    public class Program
    {
        public static void Main()
        {
           int a = int.Parse(Console.ReadLine());
           while((Sum(a) % 4) != 0) a++;
           Console.WriteLine(a);
        }

        static public int Sum(int a)
        {
        	int sum=0;
        	while(a>0)
        	{
        		sum+=a%10;
        		a/=10;
        	}
        	return sum;
        }
    }
}


using System;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] pokemons = { "vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon" };
            string input = Console.ReadLine();

            for (int i = 0; i < pokemons.Length; i++)
                if (pokemons[i].Length == input.Length)
                    for (int j = 0; j < input.Length; j++)
                        if (input[j] == '.' || pokemons[i][j] == input[j])
                            if ( j == input.Length - 1)
                            {Console.WriteLine(pokemons[i]); return;}
                            else continue;
                        else break;
        }
    }
}


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

namespace ConsoleApplication1
{
    public class Program
    {
        public static void Main()
        {
            int length;
            string input;
            string[] pokemon = { "jolteon", "flareon", "umbreon", "leafeon", "glaceon", "sylveon" };
            int[] SimilarityFactor = { 0, 0, 0, 0, 0, 0 };

            length = Convert.ToInt32(Console.ReadLine());
            input = Console.ReadLine();

            if (length == 6)
                Console.WriteLine("espeon");
            else if (length == 8)
                Console.WriteLine("vaporeon");
            else
            {
                for (int i = 0; i < 4; ++i)
                {
                    if (input[i] == '.')
                        goto Next;
                    for (int j = 0; j < 6; ++j)
                        if (input[i] == pokemon[j][i])
                            ++SimilarityFactor[j];
                Next: ;
                }
                Console.WriteLine(pokemon[Array.IndexOf(SimilarityFactor, SimilarityFactor.Max())]);
            }
        }
    }
}


using System;
public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("25");
        }
    }


using System;
class Codeforces_630A
{
    static void Main()
    {
        string n = Console.ReadLine();
        Console.Write(25);
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Web;
using System.Net;
using System.Collections;

namespace ConsoleApplication1 {
    class Program {
        static void Main( string[] args ) {
            int n = ReadInt();
            int sumx = 0;
            int sumy = 0;
            bool flag = false;

            for ( int i = 0; i < n; i++ ) {
                int x = ReadInt();
                int y = ReadInt();
                sumx += x;
                sumy += y;
                if ( x % 2 != y % 2 )
                    flag = true;
            }

            if ( sumx % 2 == 0 && sumy % 2 == 0)
                Console.Write(0);
            else if ( flag && n > 1 && ((sumx + sumy) % 2 == 0))
                Console.Write(1);
            else
                Console.Write(-1);
        }

        static int _current = -1;
        static string[] _words = null;
        static int ReadInt() {
            if ( _current == -1 ) {
                _words = Console.ReadLine().Split(new char[] { ' ', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                _current = 0;
            }

            int value = int.Parse(_words[_current].Replace('.', ','));
            if ( _current == _words.Length - 1 )
                _current = -1;
            else
                _current++;

            return value;
        }
    }
}


using System;

namespace Task_8
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			int bones = 0;
			string str;
		//	Console.WriteLine("Введите количество костей домино:");
			bones = int.Parse(Console.ReadLine());
			int result = -1;
			int sum_x = 0, sum_y = 0;
			int[,] array = new int[2, bones];
		//	Console.WriteLine("Введите попарно через пробел верхние и нижние значения костей");
			for (int i = 0; i < bones; i++)
			{
			//	Console.Write("Введите " + (i + 1) + " элемент ");
				str = Console.ReadLine();
				String[] str_mas = str.Split(' ');
				array[0, i] = int.Parse(str_mas[0]);
				array[1, i] = int.Parse(str_mas[1]);
			}
			//просуммируем каждую сторону доминошек
			for (int i = 0; i < bones; i++)
			{
				sum_x += array[0, i];
				sum_y += array[1, i];
			}
			//задача будет иметь решение. когда сумма каждой стороны нечетная. Смена чет/нечет сумм сторон возножна только при
			//развороте кости на которой одно число четное, другое-нечетное.
			if (sum_x % 2 ==0 && sum_y % 2 == 0)
			{
				//задача изначально решена.
				result = 0;
			}
			if ((sum_x % 2) != (sum_y % 2))
			{
				//задача не имеет решения, поскольку одна из сторон четная, а другая-нет. При развороте кости с четным и нечетным числом,
				//етность общиих сумм по сторонам инвертируется.
				result = -1;
			}
			//единственным решением может быть тот случай, когда суммы по обеим сторонам нечетные, и присутствует кость с чет/нечет числамми.
			if (sum_x % 2 == 1 && sum_y % 2 == 1)
			{
				for (int i = 0; i < bones; i++)
				{
					if (array[0, i] % 2 != array[1, i] % 2)
					{
						result = 1;
			//			Console.WriteLine("Нужно перевернуть " + (i+1) + " кость");
						break;
					}
					else
						result = -1;
				}
			}
			Console.WriteLine(result);
			//str = Console.ReadLine();
			//String[] str_mas = str.Split(' ');
		}
	}
}


#define LOCALa

using System;
using System.Collections.Generic;
using System.Dynamic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Xml.Serialization;

namespace Algorytmy
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split(' ');
            int V = int.Parse(l[0]);
            int N = int.Parse(l[1]);

            for (int i = 0; i < N; i++)
                if (V % 10 == 0)
                    V /= 10;
                else
                    V--;
            Console.WriteLine(V);
        }
    }
    /*class Program1
    {
        public Program1()
        {
#if LOCAL
            CIN.ReadInputFile("input1");
#endif
            //int V = CIN.Get();
            //int N = CIN.Get();
            var l = Console.ReadLine().Split(' ');
            int V = int.Parse(l[0]);
            int N = int.Parse(l[1]);

            for (int i = 0; i < N; i++)
                if (V % 10 == 0)
                    V /= 10;
                else
                    V--;
            Console.WriteLine(V);
        }
    }*/
#if LOCAL
    //get imput data
    class CIN
    {
        static Queue<string> data = new Queue<string>();
        public static void ReadInputFile(string path)
        {
            try
            {
                foreach (var line in File.ReadAllLines(path))
                    foreach (var word in line.Split())
                        data.Enqueue(word);
            }
            catch
            {

            }
        }
        static void ReadLine()
        {
            foreach (var word in Console.ReadLine().Split())
                data.Enqueue(word);
        }
        public static int Get()
        {
            return GetInt();
        }
        public static int GetInt()
        {
            if (data.Count == 0) ReadLine();
            return int.Parse(data.Dequeue());
        }
        public static float GetFloat()
        {
            if (data.Count == 0) ReadLine();
            return float.Parse(data.Dequeue());
        }
        public static double GetDouble()
        {
            if (data.Count == 0) ReadLine();
            return double.Parse(data.Dequeue());
        }
        public static string GetString()
        {
            if (data.Count == 0) ReadLine();
            return data.Dequeue();
        }
    }

    //fill array with value
    class MEM
    {
        public static void Set(ref int[] array, int value)
        {
            Set(ref array, value, array.Length);
        }
        public static void Set(ref int[] array, int value, int size)
        {
            for (int i = 0; i < size; ++i)
                array[i] = value;
        }
        public static void Set(ref int[,] array, int value)
        {
            for (int i = 0; i < array.GetLength(0); ++i)
                for (int j = 0; j < array.GetLength(1); ++j)
                    array[i, j] = value;
        }
    }
    #endif
}