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

// (づ*ω*)づﾐ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    private long[] pows = new[]
    {
        1, 11, 111, 1111, 11111, 111111, 1111111, 11111111, 111111111, 1111111111, 11111111111, 111111111111, 1111111111111,
        11111111111111, 111111111111111, 1111111111111111
    };

    int Fun(long t)
    {
        if (t < 10)
            return (int)(t > 6 ? 13 - t : t);

        int k = 0;
        while (pows[k] <= t)
            k++;

        int tp = (int)((pows[k] - t) / pows[k - 1]);
        int ret = Fun(pows[k] - t - tp * pows[k - 1]) + k + 1 + tp * k;

        tp = (int)(t / pows[k - 1]);
        ret = Math.Min(ret, Fun(t - tp * pows[k - 1]) + tp * k);

        return ret;
    }

    public object Solve()
    {
        return Fun(ReadLong());
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;

    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = Console.In;
        writer = new StreamWriter(Console.OpenStandardOutput());
#endif
        try
        {
            object result = new Solver().Solve();
            if (result != null)
                writer.WriteLine(result);
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        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));
    }

    #endregion
}


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

namespace DivisaoConquista
{
    public static class Operacao
    {
        static public long[] Vetor; //vetor auxiliar

        static public long Calcula(long n, int i)
        {
            long m = n / Vetor[i]; //auxiliar para dividir o número {aplicação da técnica}
            n = n % Vetor[i]; //atualização de n para o resto da divisão

            if (n == 0) //Se chegar ao fim
                return m * i; //auxiliar * 'posição' atual
            else //retorna o produto do auxiliar pelo menor valor entre a qtd de 1 para o número e a posição anterior e para a
                return m * i + Math.Min(Calcula(n, i - 1), i + Calcula(Vetor[i] - n, i - 1));
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            /*O Prof. Vasechkin quer representar o inteiro positivo n como uma soma de adendos,
             * onde cada adendo é um número inteiro contendo apenas 1 s.
             * Por exemplo, ele pode representar 121 como 121 = 111 + 11 + -1.
             * Encontrar o menor número de dígitos 1 em tal soma.
             */
            Rodar();
        }

        static void Rodar()
        {
            long n;
            long[] vetor = new long[17];

            for (int i = 1; i < vetor.Length; i++)
            {
                vetor[i] = vetor[i - 1] * 10 + 1;
            }

            Operacao.Vetor = vetor;
            n = long.Parse(Console.ReadLine());
            Console.Write(Operacao.Calcula(n, 16));
        }
    }
}


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

namespace One_Basic
{
    public static class Operacao
    {
        static public long[] Vetor;

        static public long dfs(long n, int i)
        {
            long m = n / Vetor[i];
            n = n % Vetor[i];
            if (n == 0)
                return m * i;
            else
                return m * i + Math.Min(dfs(n, i - 1), i + dfs(Vetor[i] - n, i - 1));
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Rodar();
        }

        static void Rodar()
        {
            long n;
            long[] vetor = new long[17];

            for (int i = 1; i < vetor.Length; i++)
            {
                vetor[i] = vetor[i - 1] * 10 + 1;
            }

            Operacao.Vetor = vetor;
            n = long.Parse(Console.ReadLine());
            Console.Write(Operacao.dfs(n, 16));
        }
    }
}


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

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

        private static readonly StreamWriter writer =
            new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            long n = long.Parse(reader.ReadLine());

            var nn = new List<long>();
            nn.Add(1);
            nn.Add(1);
            for (int i = 1;; i++)
            {
                long next = nn[i]*10 + 1;
                nn.Add(next);
                if (next > n)
                    break;
            }

            int min = int.MaxValue;

            find(n, nn.Count - 1, nn, 0, ref min);

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

        private static void find(long n, int index, List<long> nn, int sum, ref int min)
        {
            if (n == 0)
            {
                if (min > sum)
                    min = sum;
            }
            if (index <= 0)
                return;

            for (int i = -10; i < 11; i++)
            {
                if (n == nn[index]*i)
                {
                    find(n - nn[index]*i, index - 1, nn, sum + index*Math.Abs(i), ref min);
                    break;
                }
            }

            for (int i = -10; i < 11; i++)
            {
                if (n < nn[index] * i)
                {
                    find(n - nn[index] * i, index - 1, nn, sum + index * Math.Abs(i), ref min);
                    break;
                }
            }

            for (int i = 10; i > -11; i--)
            {
                if (n > nn[index] * i)
                {
                    find(n - nn[index] * i, index - 1, nn, sum + index * Math.Abs(i), ref min);
                    break;
                }
            }
        }
    }
}


using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		string[] str = Console.ReadLine().Split();
		int[]A = new int[N];
		for(var i=0;i<N;i++){
			A[i] = int.Parse(str[i]);
		}
		long ans = 0;
		for(var i=1;i<N;i++){
			if(A[i-1]==1 && A[i]==2){
			    if(i>=2 && A[i-2]==3){
			        ans +=2;
			    } else {
    				ans += 3;
			    }
			} else if(A[i-1]==1 && A[i]==3){
				ans += 4;
			} else if(A[i-1]==2 && A[i]==1){
				ans += 3;
			} else if(A[i-1]==2 && A[i]==3){
				ans = -1;
				break;
			} else if(A[i-1]==3 && A[i]==1){
				ans += 4;
			} else if(A[i-1]==3 && A[i]==2){
				ans = -1;
				break;
			}
		}
		if(ans == -1){
			Console.WriteLine("Infinite");
		} else {
			Console.WriteLine("Finite");
			Console.WriteLine(ans);
		}
	}
}


using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
class Problem
{
    static void Main()
    {
        //--------------------------------input--------------------------------//

        int n = Convert.ToInt32( Console.ReadLine() );
        var a = Array.ConvertAll( Console.ReadLine().Split(), Convert.ToInt32 );

        //--------------------------------solve--------------------------------//

        string s = String.Join( "", a );
        if(s.Contains( "23" ) || s.Contains( "32" ) || s.Contains( "11" ) || s.Contains( "22" ) || s.Contains( "33" ))
            Console.WriteLine( "Infinite" );
        else
        {
            Console.WriteLine( "Finite" );
            int kq = 0;
            for(int i = 0 ; i < n - 1 ; i++)
            {
                if(a[i] + a[i + 1] == 3)
                    kq += 3;
                if(a[i] + a[i + 1] == 4)
                    kq += 4;
            }
            for(int i = 0 ; i < n - 2 ; i++)
                if(a[i] == 3 && a[i + 1] == 1 && a[i + 2] == 2)
                    kq--;
            Console.WriteLine( kq );
        }

    }

}


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

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

        private static void Main(string[] args)
        {
            int w = Next();
            int b = Next();

            nn = new double[w + 1,b + 1];
            for (int i = 1; i <= w; i++)
            {
                nn[i, 0] = 1;
            }

            for (int j = 1; j <= b; j++)
            {
                for (int i = 1; i <= w; i++)
                {
                    nn[i, j] = 1.0*i/(i + j) +
                               1.0*j/(i + j)*
                               (1.0*(j - 1)/(i + j - 1)*
                                ((j - 3 < 0 ? 0 : nn[i, j - 3]*(j - 2)/(i + j - 2)) + (j - 2 < 0 ? 0 : nn[i - 1, j - 2]*i/(i + j - 2))));
                }
            }

            writer.WriteLine(nn[w, b].ToString("#0.000000000", CultureInfo.InvariantCulture));
            writer.Flush();
        }

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


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

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

        private static void Main(string[] args)
        {
            int w = Next();
            int b = Next();

            nn = new double[w + 1,b + 1];
            for (int i = 1; i <= w; i++)
            {
                nn[i, 0] = 1;
            }

            for (int j = 1; j <= b; j++)
            {
                for (int i = 1; i <= w; i++)
                {
                    nn[i, j] = 1.0*i/(i + j) +
                               1.0*j/(i + j)*
                               (1.0*(j - 1)/(i + j - 1)*
                                ((j - 2 < 0 ? 0 : gnn(i, j - 3)*(j - 2)/(i + j - 2)) + (j - 2 < 0 ? 0 : gnn(i - 1, j - 2)*(i)/(i + j - 2))));
                }
            }

            writer.WriteLine(nn[w, b].ToString("#0.000000000", CultureInfo.InvariantCulture));
            writer.Flush();
        }

        private static double gnn(int i, int j)
        {
            if (j < 0)
                return 0;
            return nn[i, j];
        }

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


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

namespace ReadWriteTemplate
{
    public static class Solver
    {
        private static void SolveCase()
        {
            long n = ReadLong() - 1;

            long ans = 0;
            for (int i = 0; i < 60; i++)
            {
                long a = (1L << i);
                long b = (1L << (i + 1));
                ans += a * ((n + b - a) / b);
            }

            Writer.WriteLine(ans);
        }

        public static void Solve()
        {
            SolveCase();

            /*var sw = Stopwatch.StartNew();

            int T = ReadInt();
            for (int i = 0; i < T; i++)
            {
                Writer.Write("Case #{0}: ", i + 1);
                SolveCase();
                Writer.Flush();
                Console.WriteLine($"Task {i + 1} completed");
            }

            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds);*/
        }

        public class Point
        {
            public Point(int x, int y)
            {
                X = x;
                Y = y;
            }

            public int X;

            public int Y;

            public double Length => Math.Sqrt(X * X + Y * Y);

            protected bool Equals(Point other)
            {
                return X == other.X && Y == other.Y;
            }

            public override bool Equals(object obj)
            {
                if (ReferenceEquals(null, obj))
                {
                    return false;
                }
                if (ReferenceEquals(this, obj))
                {
                    return true;
                }
                /*if (obj.GetType() != this.GetType())
                {
                    return false;
                }*/
                return Equals((Point) obj);
            }

            public override int GetHashCode()
            {
                unchecked
                {
                    return (X * 397) ^ Y;
                }
            }

            public int Dist2(Point p)
            {
                return (p.X - X) * (p.X - X) + (p.Y - Y) * (p.Y - Y);
            }

            public static Point operator +(Point a, Point b)
            {
                return new Point(a.X + b.X, a.Y + b.Y);
            }

            public static Point operator -(Point a, Point b)
            {
                return new Point(a.X - b.X, a.Y - b.Y);
            }

            public override string ToString()
            {
                return $"{nameof(X)}: {X}, {nameof(Y)}: {Y}";
            }
        }

        public static class Standard
        {
            public static long Power(long x, long p, long mod)
            {
                long result = 1;
                while (p > 0)
                {
                    if ((p & 1) == 0)
                    {
                        x = (x * x) % mod;
                        p >>= 1;
                    }
                    else
                    {
                        result = (result * x) % mod;
                        p--;
                    }
                }
                return result;
            }

            public static long Gcd(long a, long b)
            {
                return b == 0 ? a : Gcd(b, a % b);
            }

            public static List<int> GetPrimes(int n)
            {
                bool[] isPrime = Enumerable.Repeat(true, n + 1).ToArray();
                isPrime[0] = false;
                isPrime[1] = false;
                for (int i = 2; i <= n; i++)
                {
                    if (isPrime[i])
                    {
                        for (int j = i + i; j <= n; j += i)
                        {
                            isPrime[j] = false;
                        }
                    }
                }
                List<int> primes = new List<int>();
                for (int i = 0; i <= n; i++)
                {
                    if (isPrime[i])
                    {
                        primes.Add(i);
                    }
                }
                return primes;
            }

            public static CompressionResult<T> Compress<T>(IEnumerable<T> values)
            {
                int d = 0;
                var dictionary = new Dictionary<T, int>();
                foreach (T value in values.OrderByWithShuffle(x => x))
                {
                    if (!dictionary.ContainsKey(value))
                    {
                        // todo: increase before or after?
                        d++;
                        dictionary[value] = d;
                    }
                }
                return new CompressionResult<T>(dictionary, d);
            }

            public class CompressionResult<T>
            {
                public CompressionResult(Dictionary<T, int> dictionary, int maxValue)
                {
                    Dictionary = dictionary;
                    MaxValue = maxValue;
                }

                public Dictionary<T, int> Dictionary { get; }

                public int MaxValue { get; }
            }
        }

        public static void Main()
        {
            //Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

#if DEBUG
            //Reader = Console.In; Writer = Console.Out;
            Reader = File.OpenText("input.txt"); Writer = File.CreateText("output.txt");
#else
            Reader = Console.In; Writer = Console.Out;
#endif

            Solve();

            Reader.Close();
            Writer.Close();
        }

        public static IOrderedEnumerable<TSource> OrderByWithShuffle<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
        {
            return source.Shuffle().OrderBy(keySelector);
        }

        public static T[] Shuffle<T>(this IEnumerable<T> source)
        {
            T[] result = source.ToArray();
            Random rnd = new Random();
            for (int i = result.Length - 1; i >= 1; i--)
            {
                int k = rnd.Next(i + 1);
                T tmp = result[k];
                result[k] = result[i];
                result[i] = tmp;
            }
            return result;
        }

        #region Read/Write

        private static TextReader Reader;

        private static TextWriter Writer;

        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 string ReadLine()
        {
            return Reader.ReadLine();
        }

        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 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));
        }

        #endregion
    }
}


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

namespace ConsoleApplication1.BFS
{
    class NewYearFireworks
    {
        class Node
        {
            public int Level { get; set; }
            public int Direction { get; set; }
            public int X { get; set; }
            public int Y { get; set; }
        }

        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var t = new int[N];
            var s = Console.ReadLine().Split(' ').ToArray();
            for (var i = 0; i < N; i++)
            {
                t[i] = int.Parse(s[i]);
            }

            var directions = new int[][] {
                new int []{0,1},
                new int []{1,1},
                new int []{1,0},
                new int []{1,-1},
                new int []{0,-1},
                new int []{-1,-1},
                new int []{-1,0},
                new int []{-1,1}
            };

            var visited = new bool[600, 600];

            var q = new Queue<Node>();
            q.Enqueue(new Node()
            {
                Level = 0,
                Direction = 0,
                X = 300,
                Y = 300
            });
            visited[300, 300] = true;
            var res = 1;
            for (var k = 0; k < N; k++)
            {
                var used = new bool[600, 600, 8];
                var queue = new Queue<Node>();
                while (q.Count > 0)
                {
                    var current = q.Dequeue();

                    for (var i = 1; i < t[k]; i++)
                    {
                        if (!visited[current.Y + i * directions[current.Direction][0], current.X + i * directions[current.Direction][1]])
                        {
                            res++;
                            visited[current.Y + i * directions[current.Direction][0], current.X + i * directions[current.Direction][1]] = true;
                        }
                    }
                    current.Y += (t[current.Level] - 1) * directions[current.Direction][0];
                    current.X += (t[current.Level] - 1) * directions[current.Direction][1];

                    if (current.Level == N - 1)
                    {
                        continue;
                    }
                    var direction = (current.Direction + 1) % 8;
                    if (!used[current.Y + directions[direction][0], current.X + directions[direction][1], direction])
                    {
                        used[current.Y + directions[direction][0], current.X + directions[direction][1], direction] = true;
                        queue.Enqueue(new Node()
                        {
                            Direction = direction,
                            Level = current.Level + 1,
                            Y = current.Y + directions[direction][0],
                            X = current.X + directions[direction][1]
                        });
                    }
                    if (!visited[current.Y + directions[direction][0], current.X + directions[direction][1]])
                    {
                        visited[current.Y + directions[direction][0], current.X + directions[direction][1]] = true;
                        res++;
                    }

                    direction = (current.Direction - 1) % 8;
                    if (direction < 0)
                    {
                        direction = 8 + direction;
                    }
                    if (!used[current.Y + directions[direction][0], current.X + directions[direction][1], direction])
                    {
                        used[current.Y + directions[direction][0], current.X + directions[direction][1], direction] = true;
                        queue.Enqueue(new Node()
                        {
                            Direction = direction,
                            Level = current.Level + 1,
                            Y = current.Y + directions[direction][0],
                            X = current.X + directions[direction][1]
                        });
                    }
                    if (!visited[current.Y + directions[direction][0], current.X + directions[direction][1]])
                    {
                        visited[current.Y + directions[direction][0], current.X + directions[direction][1]] = true;
                        res++;
                    }

                }
                q = queue;
            }

            Console.WriteLine(res);
        }
    }
}


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

namespace AlgoTraining.Codeforces.GoodBye2016
{
    public class FastScanner : StreamReader
    {
        private string[] _line;
        private int _iterator;

        public FastScanner(Stream stream) : base(stream)
        {
            _line = null;
            _iterator = 0;
        }
        public string NextToken()
        {
            if (_line == null || _iterator >= _line.Length)
            {
                _line = base.ReadLine().Split(' ');
                _iterator = 0;
            }
            if (_line.Count() == 0) throw new IndexOutOfRangeException("Input string is empty");
            return _line[_iterator++];
        }
        public int NextInt()
        {
            return Convert.ToInt32(NextToken());
        }
        public long NextLong()
        {
            return Convert.ToInt64(NextToken());
        }
        public float NextFloat()
        {
            return float.Parse(NextToken());
        }
        public double NextDouble()
        {
            return Convert.ToDouble(NextToken());
        }
    }
    class NewYearAndFireworksD
    {
        private static int n;
        private static int[] t;
        private static bool[, , ,] dp = new bool[301, 301, 8, 30];
        private static int[][] dir = new int[][]
        {
            new int[] { 0, 1 },
            new int[] { -1, 1 },
            new int[] { -1, 0 },
            new int[] { -1, -1 },
            new int[] { 0, -1 },
            new int[] { 1, -1 },
            new int[] { 1, 0 },
            new int[] { 1, 1 }
        };
        private static bool[,] grid = new bool[301, 301];

        public static void Main(string[] args)
        {
            using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
            using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
            {
                n = fs.NextInt();
                t = Array.ConvertAll(fs.ReadLine().Split(), Convert.ToInt32);
                Fire(151, 150, 2, 0);
                int count = 0;
                for (int i = 0; i < 301; i++)
                {
                    for (int j = 0; j < 301; j++)
                    {
                        if (grid[i, j]) count++;
                    }
                }
                writer.WriteLine(count);
            }
        }
        public static void Fire(int i, int j, int direction, int iteration)
        {
            if (iteration == n || dp[i, j, direction, iteration]) return;
            dp[i, j, direction, iteration] = true;
            int di = dir[direction][0], dj = dir[direction][1];
            int lifeTime = t[iteration];
            while (lifeTime-- > 0)
            {
                i += di;
                j += dj;
                grid[i, j] = true;
            }
            Fire(i, j, direction == 0 ? 7 : direction - 1, iteration + 1);
            Fire(i, j, direction == 7 ? 0 : direction + 1, iteration + 1);
        }
    }
}


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

using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>;
using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>;

class Program
{
    static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    static Scan sc = new Scan();
//    static Scan sc = new ScanCHK();
    const int M = 1000000007;
    const double eps = 1e-9;
    static readonly int[] dd = { 0, 1, 0, -1, 0 };
    static readonly int[] dx = { 0, 1, 1, 1, 0, -1, -1, -1 };
    static readonly int[] dy = { 1, 1, 0, -1, -1, -1, 0, 1 };
    static int n;
    static int[] t;
    static bool[][] fw;
    static bool[][][][] vis;
    static void Main()
    {
        n = sc.Int;
        t = sc.IntArr;
        int lim = (n + 1) * 10;
        int m = (n + 1) * 5;
        fw = new bool[lim][];
        vis = new bool[n][][][];
        for (int i = 0; i < lim; i++)
        {
            fw[i] = new bool[lim];
        }
        for (int i = 0; i < n; i++)
        {
            vis[i] = new bool[lim][][];
            for (int j = 0; j < lim; j++)
            {
                vis[i][j] = new bool[lim][];
                for (int k = 0; k < lim; k++)
                {
                    vis[i][j][k] = new bool[8];
                }
            }
        }
        dfs(0, m, m, 0);
        int ans = 0;
        foreach (var i in fw)
        {
            foreach (var j in i)
            {
                if (j) ++ans;
            }
        }
        Prt(ans);
        sw.Flush();
    }
    static void dfs(int dep, int x, int y, int d)
    {
        if (dep == n || vis[dep][x][y][d]) return;

        vis[dep][x][y][d] = true;

        for (int i = 0; i < t[dep]; i++)
        {
            x += dx[d];
            y += dy[d];
            fw[x][y] = true;
        }
        dfs(dep + 1, x, y, (d + 1) % 8);
        dfs(dep + 1, x, y, (d + 7) % 8);
    }

    static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; }
    static T Max<T>(params T[] a) => a.Max();
    static T Min<T>(params T[] a) => a.Min();
    static void DBG<T>(params T[] a) => Console.WriteLine(string.Join(" ", a));
    static void DBG(params object[] a) => Console.WriteLine(string.Join(" ", a));
    static void Prt<T>(params T[] a) => sw.WriteLine(string.Join(" ", a));
    static void Prt(params object[] a) => sw.WriteLine(string.Join(" ", a));
}
static class ex
{
    public static string con<T>(this IEnumerable<T> a) => a.con(" ");
    public static string con<T>(this IEnumerable<T> a, string s) => string.Join(s, a);
    public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; }
    public static T[] copy<T>(this IList<T> a)
    {
        var ret = new T[a.Count];
        for (int i = 0; i < a.Count; i++) ret[i] = a[i];
        return ret;
    }
}
static class Operator<T>
{
    static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x");
    static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y");
    public static readonly Func<T, T, T> Add = Lambda(Expression.Add);
    public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract);
    public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply);
    public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide);
    public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus);
    public static readonly Func<T, T> Negate = Lambda(Expression.Negate);
    public static Func<T, T, T> Lambda(Binary op) => Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile();
    public static Func<T, T> Lambda(Unary op) => Expression.Lambda<Func<T, T>>(op(x), x).Compile();
}

class ScanCHK : Scan
{
    public new string Str { get { var s = Console.ReadLine(); if (s != s.Trim()) throw new Exception(); return s; } }
}
class Scan
{
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public string Str => Console.ReadLine().Trim();
    public int[] IntArr => StrArr.Select(int.Parse).ToArray();
    public long[] LongArr => StrArr.Select(long.Parse).ToArray();
    public double[] DoubleArr => StrArr.Select(double.Parse).ToArray();
    public string[] StrArr => Str.Split();
    bool eq<T, U>() => typeof(T).Equals(typeof(U));
    T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
    T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                       : eq<T, long>() ? ct<T, long>(long.Parse(s))
                       : eq<T, double>() ? ct<T, double>(double.Parse(s))
                       : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s);
    public void Multi<T>(out T a) => a = cv<T>(Str);
    public void Multi<T, U>(out T a, out U b)
    { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); }
    public void Multi<T, U, V>(out T a, out U b, out V c)
    { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); }
    public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d)
    { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); }
    public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e)
    { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); }
}
class mymath
{
    public static long Mod = 1000000007;
    public static bool isprime(long a)
    {
        if (a < 2) return false;
        for (long i = 2; i * i <= a; i++) if (a % i == 0) return false;
        return true;
    }
    public static bool[] sieve(int n)
    {
        var p = new bool[n + 1];
        for (int i = 2; i <= n; i++) p[i] = true;
        for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false;
        return p;
    }
    public static List<int> getprimes(int n)
    {
        var prs = new List<int>();
        var p = sieve(n);
        for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i);
        return prs;
    }
    public static long[][] E(int n)
    {
        var ret = new long[n][];
        for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; }
        return ret;
    }
    public static long[][] pow(long[][] A, long n)
    {
        if (n == 0) return E(A.Length);
        var t = pow(A, n / 2);
        if ((n & 1) == 0) return mul(t, t);
        return mul(mul(t, t), A);
    }
    public static double dot(double[] x, double[] y)
    {
        int n = x.Length;
        double ret = 0;
        for (int i = 0; i < n; i++) ret += x[i] * y[i];
        return ret;
    }
    public static long dot(long[] x, long[] y)
    {
        int n = x.Length;
        long ret = 0;
        for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod;
        return ret;
    }
    public static T[][] trans<T>(T[][] A)
    {
        int n = A[0].Length, m = A.Length;
        var ret = new T[n][];
        for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; }
        return ret;
    }
    public static double[] mul(double[][] A, double[] x)
    {
        int n = A.Length;
        var ret = new double[n];
        for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]);
        return ret;
    }
    public static long[] mul(long[][] A, long[] x)
    {
        int n = A.Length;
        var ret = new long[n];
        for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]);
        return ret;
    }
    public static long[][] mul(long[][] A, long[][] B)
    {
        int n = A.Length;
        var Bt = trans(B);
        var ret = new long[n][];
        for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]);
        return ret;
    }
    public static long[] add(long[] x, long[] y)
    {
        int n = x.Length;
        var ret = new long[n];
        for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod;
        return ret;
    }
    public static long[][] add(long[][] A, long[][] B)
    {
        int n = A.Length;
        var ret = new long[n][];
        for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]);
        return ret;
    }
    public static long pow(long a, long b)
    {
        if (a >= Mod) return pow(a % Mod, b);
        if (a == 0) return 0;
        if (b == 0) return 1;
        var t = pow(a, b / 2);
        if ((b & 1) == 0) return t * t % Mod;
        return t * t % Mod * a % Mod;
    }
    public static long inv(long a) => pow(a, Mod - 2);
    public static long gcd(long a, long b)
    {
        while (b > 0) { var t = a % b; a = b; b = t; }
        return a;
    }
    // a x + b y = gcd(a, b)
    public static long extgcd(long a, long b, out long x, out long y)
    {
        long g = a; x = 1; y = 0;
        if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; }
        return g;
    }
    public static long lcm(long a, long b) => a / gcd(a, b) * b;
    public static long comb(int n, int r)
    {
        if (n < 0 || r < 0 || r > n) return 0;
        if (n - r < r) r = n - r;
        if (r == 0) return 1;
        if (r == 1) return n;
        int[] numer = new int[r], denom = new int[r];
        for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; }
        for (int p = 2; p <= r; p++)
        {
            int piv = denom[p - 1];
            if (piv > 1)
            {
                int ofst = (n - r) % p;
                for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; }
            }
        }
        long ret = 1;
        for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod;
        return ret;
    }
}


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

namespace contest
{

    class contest
    {

        static void Main(string[] args)
        {

            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //int n = num[0];
            //int m = num[1];

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

            //int n = int.Parse(Console.ReadLine());

            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //for (int i = 0; i < n; i++)
            //{
            //    input[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //}

            //int n = int.Parse(Console.ReadLine());
            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //int n = num[0];
            //int m = num[1];

            //int n = int.Parse(Console.ReadLine());
            //var arr = new int[n][];//Console.ReadLine().Split().Select(int.Parse).ToArray();
            //for(int i =0; i< n; i++)
            //{
            //    arr[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //}

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

            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //var tastes = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //int n = int.Parse(Console.ReadLine());
            //var arr = new int[n][];
            //for(int i =0; i< n; i++)
            //{
            //    arr[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //}

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

            int count = 0;

            var map = new bool[301,301];
            var set = new HashSet<Tuple<int, int, int, int>>();

            var next = new List<Tuple<int, int, int>>();
            for(int i =0; i< n; i++)
            {
                int cur = num[i];
                if(i==0)
                {
                    int x = 150;
                    int y = 150;

                    for(int j=0; j<cur; j++)
                    {
                        map[y - j, x] = true;
                        count++;
                    }
                    next.Add(Tuple.Create(y-(cur-1), x, 1));

                }
                else
                {
                    var memo = new List<Tuple<int, int, int>>();
                    for(int m=0; m<next.Count(); m++)
                    {
                        var tmp = next[m];
                        int y = tmp.Item1;
                        int x = tmp.Item2;
                        int dir = tmp.Item3;

                        if (set.Contains(Tuple.Create(i, y, x, dir))) continue;
                        set.Add(Tuple.Create(i, y, x, dir));
                        if (dir == 1)
                        {
                            map = five(cur, y, x,ref map, ref count);
                            map = eight(cur, y, x,ref map, ref count);
                            memo.Add(Tuple.Create(y-(cur),x+(cur),5));
                            memo.Add(Tuple.Create(y - (cur), x - (cur), 8));
                        }
                        else if (dir == 2)
                        {
                            map = five(cur, y, x,ref map, ref count);
                            map = six(cur, y, x,ref map, ref count);
                            memo.Add(Tuple.Create(y - (cur), x + (cur), 5));
                            memo.Add(Tuple.Create(y + (cur), x + (cur), 6));
                        }
                        else if (dir == 3)
                        {
                            map = six(cur, y, x,ref map, ref count);
                            map = seven(cur, y, x,ref map, ref count);
                            memo.Add(Tuple.Create(y + (cur), x + (cur), 6));
                            memo.Add(Tuple.Create(y + (cur), x - (cur), 7));
                        }
                        else if (dir == 4)
                        {
                            map = seven(cur, y, x,ref map, ref count);
                            map = eight(cur, y, x,ref map, ref count);
                            memo.Add(Tuple.Create(y + (cur), x - (cur), 7));
                            memo.Add(Tuple.Create(y - (cur), x - (cur), 8));
                        }
                        else if (dir == 5)
                        {
                            map = one(cur, y, x,ref map, ref count);
                            map = two(cur, y, x,ref map, ref count);
                            memo.Add(Tuple.Create(y - (cur), x , 1));
                            memo.Add(Tuple.Create(y , x + (cur), 2));
                        }
                        else if (dir == 6)
                        {
                            map = two(cur, y, x,ref map, ref count);
                            map = three(cur, y, x,ref map, ref count);
                            memo.Add(Tuple.Create(y, x + (cur), 2));
                            memo.Add(Tuple.Create(y + (cur), x , 3));
                        }
                        else if (dir == 7)
                        {
                            map = three(cur, y, x,ref map, ref count);
                            map = four(cur, y, x,ref map, ref count);
                            memo.Add(Tuple.Create(y + (cur), x, 3));
                            memo.Add(Tuple.Create(y , x - (cur), 4));
                        }
                        else if (dir == 8)
                        {
                            map = four(cur, y, x,ref map, ref count);
                            map = one(cur, y, x,ref map, ref count);
                            memo.Add(Tuple.Create(y, x - (cur), 4));
                            memo.Add(Tuple.Create(y - (cur), x, 1));
                        }

                    }
                    next = new List<Tuple<int, int, int>>(memo);
                }
            }

            //for (int i = 0; i < 301; i++)
            //{
            //    for (int j = 0; j < 301; j++)
            //    {
            //        if (map[i, j])
            //        {
            //            count++;
            //        }
            //    }
            //}

            Console.WriteLine(count);

            //Console.WriteLine();

        }

        public static bool[,] one(int cur,int y, int x,ref bool[,] map, ref int count)
        {
            for(int i = 1; i<=cur; i++)
            {
                if(!map[y-i,x])
                {
                    map[y - i, x] = true;
                    count++;
                }
            }
            return map;
        }

        public static bool[,] two(int cur, int y, int x,ref bool[,] map, ref int count)
        {
            for (int i = 1; i <= cur; i++)
            {
                if (!map[y, x+i])
                {
                    map[y , x+i] = true;
                    count++;
                }
            }
            return map;
        }

        public static bool[,] three(int cur, int y, int x,ref bool[,] map, ref int count)
        {
            for (int i = 1; i <= cur; i++)
            {
                if (!map[y + i, x])
                {
                    map[y + i, x] = true;
                    count++;
                }
            }
            return map;
        }

        public static bool[,] four(int cur, int y, int x,ref bool[,] map, ref int count)
        {
            for (int i = 1; i <= cur; i++)
            {
                if (!map[y , x-i])
                {
                    map[y , x-i] = true;
                    count++;
                }
            }
            return map;
        }

        public static bool[,] five(int cur, int y, int x,ref bool[,] map, ref int count)
        {
            for (int i = 1; i <= cur; i++)
            {
                if (!map[y - i, x+i])
                {
                    map[y - i, x+i] = true;
                    count++;
                }
            }
            return map;
        }

        public static bool[,] six(int cur, int y, int x,ref bool[,] map, ref int count)
        {
            for (int i = 1; i <= cur; i++)
            {
                if (!map[y + i, x+i])
                {
                    map[y + i, x+i] = true;
                    count++;
                }
            }
            return map;
        }

        public static bool[,] seven(int cur, int y, int x,ref bool[,] map, ref int count)
        {
            for (int i = 1; i <= cur; i++)
            {
                if (!map[y + i, x-i])
                {
                    map[y + i, x-i] = true;
                    count++;
                }
            }
            return map;
        }

        public static bool[,] eight(int cur, int y, int x,ref bool[,] map, ref int count)
        {
            for (int i = 1; i <= cur; i++)
            {
                if (!map[y - i, x-i])
                {
                    map[y - i, x-i] = true;
                    count++;
                }
            }
            return map;
        }

    }

    class Segment
    {
        //public int[] arr;
        public Tuple<int, int, int, int, int>[] arr;
        int n;

        public Segment(int n)
        {
            this.n = n * 2;
            //arr = Enumerable.Range(0, n*2).ToArray();
            //arr = new int[this.n];
            arr = new Tuple<int, int, int, int, int>[this.n];
            for (int i = 0; i < this.n; i++)
            {
                arr[i] = Tuple.Create(0,0,0,0,0);
            }

        }

        public void update(int i, int x)
        {
            i = (n / 2) + i - 1;
            //arr[i] = 1;
            if (x == 2) arr[i] = Tuple.Create(1, 0, 0, 0, 0);
            else if (x == 0) arr[i] = Tuple.Create( 0,1, 0, 0, 0);
            else if (x == 1) arr[i] = Tuple.Create(0,0,1,0,0);
            else if (x == 6) arr[i] = Tuple.Create( 0, 0, 0,1, 0);
            else if (x == 7) arr[i] = Tuple.Create( 0, 0, 0, 0,1);

            while (i > 0)
            {
                i = (i - 1) / 2;
                //arr[i] = Math.Max(arr[i*2+1], arr[i*2+2]);
                //if (arr[i * 2 + 1] > arr[i * 2 + 2])
                //{
                //    arr[i] = arr[i*2+1];
                //}
                //else
                //{
                //    arr[i] = arr[i*2+2];
                //}
                //arr[i] = arr[i * 2 + 1] + arr[i * 2 + 2];
                arr[i] = Tuple.Create(arr[i*2+1].Item1+ arr[i*2+2].Item1,
                    arr[i * 2 + 1].Item2 + arr[i * 2 + 2].Item2,
                    arr[i * 2 + 1].Item3 + arr[i * 2 + 2].Item3,
                    arr[i * 2 + 1].Item4 + arr[i * 2 + 2].Item4,
                    arr[i * 2 + 1].Item5 + arr[i * 2 + 2].Item5);
            }

        }

        //call : query(a,b, 0, 0, n)
        public Tuple<int,int,int,int,int> query(int a, int b, int k, int l, int r)
        {
            if (r <= a || b <= l) return Tuple.Create(0,0,0,0,0);
            if (a <= l && r <= b) return arr[k];
            else
            {

                var vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
                var vr = query(a, b, k * 2 + 2, (l + r) / 2, r);

                //if (vl.Item4 > vr.Item4)
                //{
                //    return vl;
                //}
                ////else if (vl.Item4 == vr.Item4)
                ////{
                ////    if (countA >= countB) return vr;
                ////    else return vl;
                ////}
                //else return vr;

                return Tuple.Create(vl.Item1 + vr.Item1,
   vl.Item2 + vr.Item2,
   vl.Item3 + vr.Item3,
  vl.Item4 + vr.Item4,
   vl.Item5 + vr.Item5);

                //return Math.Max(vl, vr);
                //return vl
                int countA = 0;
                int countB = 0;
                if (vl.Item1 == 0) countA++;
                if (vl.Item2 == 0) countA++;
                if (vl.Item3 == 0) countA++;
                if (vl.Item4 == 0) countA++;
                if (vl.Item5 == 0) countA++;

                if (vr.Item1 == 0) countB++;
                if (vr.Item2 == 0) countB++;
                if (vr.Item3 == 0) countB++;
                if (vr.Item4 == 0) countB++;
                if (vr.Item5 == 0) countB++;

                if((vl.Item1==0 && vr.Item1>0))
                {
                    return vr;
                }
                else if ((vl.Item1 > 0 && vr.Item1 == 0))
                {
                    return vl;
                }
                else if ((vl.Item2 == 0 && vr.Item2 > 0))
                {
                    return vr;
                }
                else if ((vl.Item2 > 0 && vr.Item2 == 0))
                {
                    return vl;
                }
                else if ((vl.Item3 == 0 && vr.Item3 > 0))
                {
                    return vr;
                }
                else if ((vl.Item3 > 0 && vr.Item3 == 0))
                {
                    return vl;
                }
                else if ((vl.Item4 == 0 && vr.Item4 > 0))
                {
                    return vr;
                }
                else if ((vl.Item4 > 0 && vr.Item4 == 0))
                {
                    return vl;
                }
                else if ((vl.Item5 == 0 && vr.Item5 > 0))
                {
                    return vr;
                }
                else if ((vl.Item5 > 0 && vr.Item5 == 0))
                {
                    return vl;
                }

                if (vl.Item4 > vr.Item4)
                {
                    return vl;
                }
                else if (vl.Item4 == vr.Item4)
                {
                    if (countA >= countB) return vr;
                    else return vl;
                }
                else return vr;

                //if (countA <= countB) return vl;
                //else return vr;
            }
        }

    }

    class UnionFind
    {
        public int[] path;

        public UnionFind(int n)
        {
            path = new int[n];

            for (int i = 0; i < n; i++)
            {
                path[i] = i;
            }

        }

        private int root(int i)
        {
            while (i != path[i])
            {
                path[i] = path[path[i]];
                i = path[i];
            }
            return i;
        }

        public bool find(int p, int q)
        {
            return root(p) == root(q);
        }

        public void unite(int p, int q)
        {
            int i = root(p);
            int j = root(q);
            path[i] = j;
        }

    }
}


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

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

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

            var nn = new int[n];
            for (int i = 0; i < n; i++)
            {
                nn[i] = Next();
            }

            var dx = new[] {0, 1, 1, 1, 0, -1, -1, -1};
            var dy = new[] {1, 1, 0, -1, -1, -1, 0, 1};
            var move = new[,]
                           {
                               {7, 1}, {0, 2}, {1, 3}, {2, 4}, {3, 5}, {4, 6}, {5, 7}, {6, 0}
                           };

            var pole = new int[400,400];

            var q = new Queue<Tuple<int, int, int>>();
            q.Enqueue(new Tuple<int, int, int>(200, 200, 0));

            for (int i = 0; i < n; i++)
            {
                var next = new Queue<Tuple<int, int, int>>();
                var f = new bool[400,400,8];

                while (q.Count > 0)
                {
                    Tuple<int, int, int> point = q.Dequeue();
                    int x = point.Item1;
                    int y = point.Item2;
                    for (int j = 0; j < nn[i]; j++)
                    {
                        x = x + dx[point.Item3];
                        y = y + dy[point.Item3];
                        pole[x, y] = 1;
                    }

                    for (int j = 0; j < 2; j++)
                    {
                        int dir = move[point.Item3, j];
                        if (!f[x, y, dir])
                        {
                            f[x, y, dir] = true;
                            next.Enqueue(new Tuple<int, int, int>(x, y, dir));
                        }
                    }
                }

                q = next;
            }

            int count = 0;
            for (int i = 0; i < 400; i++)
            {
                for (int j = 0; j < 400; j++)
                {
                    count += pole[i, j];
                }
            }
            writer.WriteLine(count);
            writer.Flush();
        }

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


using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
//using System.Numerics;
//using Point = System.Numerics.Complex;
//using Number = System.Int64;
namespace Program
{
    public class Solver
    {

        public void Solve()
        {
            var n = sc.Integer();
            var a = sc.Integer(n);
            int[] dx = { 0, 1, 1, 1, 0, -1, -1, -1 };
            int[] dy = { 1, 1, 0, -1, -1, -1, 0, 1 };
            var otaku = new bool[400, 400];
            var dp = new int[400, 400];
            const int X = 200;
            dp[X, X] = 1;
            foreach (var x in a)
            {
                var next = new int[400, 400];
                for (int i = 0; i < 400; i++)
                    for (int j = 0; j < 400; j++)
                    {
                        if (dp[i, j] == 0) continue;
                        for (int d = 0; d < 8; d++)
                        {
                            if ((dp[i, j] >> d & 1) == 0) continue;
                            for (int v = 1; v <= x; v++)
                                otaku[i + dx[d] * v, j + dy[d] * v] = true;
                            next[i + dx[d] * x, j + dy[d] * x] |= 1 << ((d + 1) % 8);
                            next[i + dx[d] * x, j + dy[d] * x] |= 1 << ((d + 7) % 8);
                        }
                    }

                dp = next;
            }
            IO.Printer.Out.WriteLine(otaku.Cast<bool>().Count(x => x));

        }

        public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());
        static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; }
        static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
    }
}

#region main
static class Ex
{
    //static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); }
    //static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); }
    static public void Main()
    {
        var solver = new Program.Solver();
        solver.Solve();
        Program.IO.Printer.Out.Flush();
    }
}
#endregion
#region Ex
namespace Program.IO
{
    using System.IO;
    using System.Text;
    using System.Globalization;
    public class Printer: StreamWriter
    {
        static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; }
        public static Printer Out { get; set; }
        public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
        public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
        public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) { }
        public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); }
        public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); }
    }
    public class StreamScanner
    {
        public StreamScanner(Stream stream) { str = stream; }
        public readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        private byte read()
        {
            if (isEof) return 0;
            if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } }
            return buf[ptr++];
        }
        public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; }

        public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        public string ScanLine()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b != '\n'; b = (char)read())
                if (b == 0) break;
                else if (b != '\r') sb.Append(b);
            return sb.ToString();
        }
        public long Long()
        {
            if (isEof) return long.MinValue;
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != 0 && b != '-' && (b < '0' || '9' < b));
            if (b == 0) return long.MinValue;
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
        public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; }
        private T[] enumerate<T>(int n, Func<T> f)
        {
            var a = new T[n];
            for (int i = 0; i < n; ++i) a[i] = f();
            return a;
        }

        public char[] Char(int n) { return enumerate(n, Char); }
        public string[] Scan(int n) { return enumerate(n, Scan); }
        public double[] Double(int n) { return enumerate(n, Double); }
        public int[] Integer(int n) { return enumerate(n, Integer); }
        public long[] Long(int n) { return enumerate(n, Long); }
    }
}
#endregion


using System;

class B869 {
    public static void Main() {
        var line = Console.ReadLine().Split();
        var a = long.Parse(line[0]);
        var b = long.Parse(line[1]);
        if (10L <= b - a) Console.WriteLine(0);
        else {
            long answer = 1;
            for (long i = a + 1; i <= b; ++i)
                answer = answer * (i % 10) % 10;
            Console.WriteLine(answer);
        }
    }
}


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

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

            long a, b, ans = 1, helper_1;
            var token = Console.ReadLine().Split().Select(long.Parse);
            long[] token_1 = new long[2];
            token_1 = token.ToArray();

            // token_1 = token.ToArray();
            a = token_1[0];
            b = token_1[1]; ;
            long rezalt = b % 10;
            if (a == b) ans = 1;
            else if (b - a == 1) ans = b % 10;
            else if (b % 10 == 0) ans = 0;
            else
            {
                helper_1 = b % 10 - 1;
                ans = b % 10;

                long counter = b - a - 1;
                while (counter-- != 0)
                {

                    ans = ans * helper_1;
                    if (helper_1 == 0)
                    {
                        ans = 0;
                        break;
                    }
                    helper_1--;

                }
                //for (; ; counter--)
                //{
                //    ans = ans * helper_1 ;
                //    helper_1--;
                //}
            }

            Console.Write(ans % 10);

            token = null;
            token_1 = null;
         //   Console.ReadKey();
        }
    }
}


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

namespace ProgrammingContest.Codeforces.Round46
{
    class B
    {
        static int calc(int[] xs, int m, int[] ys, int n, int b)
        {
            int res = 0, c = 0, i = 0;
            for (int r = 1; i < Math.Max(m, n) || c != 0; i++, r*=b)
            {
                int x = xs[i] + ys[i] + c;
                res += x % b * r;
                c = x / b;
            }
            return i;
        }

        public static void Main()
        {
            Scanner scanner = Scanner.FromConsole();
            int a = scanner.NextInt(), b = scanner.NextInt();
            int[] xs = new int[15], ys = new int[15];
            int m = 0, n = 0;
            for (; a > 0; a /= 10) xs[m++] = a % 10;
            for (; b > 0; b /= 10) ys[n++] = b % 10;
            for (int i = 2; i <= 16; i++)
            {
                bool ok = true;
                for (int j = 0; j < Math.Max(m, n); j++)
                    if (xs[j] >= i || ys[j] >= i)
                        ok = false;
                if (ok)
                {
                    Console.WriteLine(calc(xs, m, ys, n, i));
                    break;
                }
            }
        }

        #region Scanner
        public class Scanner : IDisposable
        {
            const int MAX_BUFFER_SIZE = 1024 * 1024 * 16;
            const string DELIMITER = " \r\n\t";

            System.IO.TextReader stream;
            int pos = 0, len = 0;
            bool endStream = false;
            int BufferSize = MAX_BUFFER_SIZE;
            char[] buffer = new char[MAX_BUFFER_SIZE];

            public enum Option { Buffering, NoBuffering }

            public Scanner(System.IO.TextReader stream, Option bufferingOption)
            {
                this.stream = stream;
                if (bufferingOption == Option.NoBuffering) BufferSize = 1;
            }

            void ReadBuffer()
            {
                pos = 0;
                len = stream.ReadBlock(buffer, 0, BufferSize);
                endStream = len == 0;
            }

            void SkipDelimiter()
            {
                while (!endStream && IsDelimiter(Peek())) NextChar();
            }

            static bool IsDelimiter(char c)
            {
                return DELIMITER.Contains(c);
            }

            bool Continue(char c)
            {
                return !endStream && !IsDelimiter(c);
            }

            char Peek()
            {
                if (pos >= len) ReadBuffer();
                return buffer[pos];
            }

            public char NextChar()
            {
                if (pos >= len) ReadBuffer();
                return buffer[pos++];
            }

            public string NextString()
            {
                SkipDelimiter();
                StringBuilder res = new StringBuilder();
                for (char c = NextChar(); Continue(c); c = NextChar()) res.Append(c);
                return res.ToString();
            }

            public int NextInt()
            {
                SkipDelimiter();
                int res = 0;
                char c = NextChar();
                int sign = 1;
                if (c == '-') { sign = -1; c = NextChar(); }
                for (; Continue(c); c = NextChar())
                    res = res * 10 + (c - '0');
                return sign * res;
            }

            public long NextLong()
            {
                SkipDelimiter();
                long res = 0;
                char c = NextChar();
                long sign = 1;
                if (c == '-') { sign = -1; c = NextChar(); }
                for (; Continue(c); c = NextChar())
                    res = res * 10 + (c - '0');
                return sign * res;
            }

            public double NextDouble()
            {
                return double.Parse(NextString());
            }

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

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

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

            public string[] NextStrings(int n)
            {
                string[] res = new string[n];
                for (int i = 0; i < n; i++) res[i] = NextString();
                return res;
            }

            public static Scanner FromString(string s)
            {
                return new Scanner(new System.IO.StreamReader(new System.IO.MemoryStream(Encoding.ASCII.GetBytes(s))), Option.Buffering);
            }

            public static Scanner FromFile(string path)
            {
                return new Scanner(new System.IO.StreamReader(path), Option.Buffering);
            }

            public static Scanner FromConsole()
            {
                return new Scanner(Console.In, Option.Buffering);
            }

            public void Dispose()
            {
                stream.Close();
            }
        }
        #endregion
    }
}


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

namespace Task49B
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] tm = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int a = tm[0], b = tm[1];
            int BDa = FindBiggestDigit(a);
            int BDb = FindBiggestDigit(b);
            int BD = Math.Max(BDa, BDb);
            int nbase = BD + 1;

            Console.WriteLine(SumInBase(a,b,nbase).Length);
           // Console.ReadKey();
        }

        private static int FindBiggestDigit(int a)
        {
            int ans = 0, helper;
            while (a > 0)
            {
                helper = a % 10;
                if (ans < helper)
                    ans = helper;
                a /= 10;
            }

            return ans;
        }

        private static string SumInBase(int a, int b, int nbase)
        {
            string ans = "";
            if (a < b)
            {
                int temp = a;
                a = b;
                b = temp;
            }

            int leftOver = 0;
            while (b > 0)
            {
                int lastDigitA = a % 10;
                int lastDigitB = b % 10;

                int helper = lastDigitA + lastDigitB + leftOver;

                if (helper >= nbase)
                {
                    helper = ConvertToBase(helper, nbase);
                    ans = (helper % 10).ToString() + ans;
                    leftOver = helper / 10;
                }
                else {
                    ans = helper.ToString() + ans;
                    leftOver = 0;
                }

                a /= 10;
                b /= 10;

            }

            while (a > 0)
            {
                int lastDigitA = a % 10;
                int helper = lastDigitA + leftOver;
                if(helper >= nbase)
                {
                    helper = ConvertToBase(helper, nbase);
                    ans = (helper % 10).ToString() + ans;
                    leftOver = helper / 10;
                }
                else
                {
                  ans = helper.ToString() + ans;
                  leftOver = 0;
                }

                a /= 10;
            }

            if (leftOver != 0)
                ans = leftOver.ToString() + ans;

            return ans;
        }

        private static int ConvertToBase(int num, int nbase)
        {
            int ans = 0;
            List<int> lefts = new List<int>();

            while (num > 0)
            {
                lefts.Add(num % nbase);
                num /= nbase;
            }

            for (int i = lefts.Count - 1; i >= 0; i--)
                ans = ans * 10 + lefts[i];

            return ans;
        }
    }
}


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

namespace Olymp
{
  public class ProblemSolver
  {
    public void Solve()
    {
      int n = int.Parse(Console.ReadLine());
      string s = Console.ReadLine();
      var count = new Dictionary<char, int> { {'B', 0}, {'G', 0}, {'R', 0} };
      foreach (var c in s)
        count[c]++;
      int b = count['B'];
      int g = count['G'];
      int r = count['R'];
      string ans = "";
      if(b > 0 && g > 0 && r > 0 ||
         b > 1 && g > 1 && r == 0 ||
         b > 1 && g == 0 && r > 1 ||
         b == 0 && g > 1 && r > 1)
        ans = "BGR";
      else if(b > 1 && g == 1 && r == 0 ||
              b > 1 && r == 1 && g == 0)
        ans = "GR";
      else if(g > 1 && b == 1 && r == 0 ||
              g > 1 && r == 1 && b == 0)
        ans = "BR";
      else if(r > 1 && b == 1 && g == 0 ||
              r > 1 && g == 1 && b == 0)
        ans = "BG";
      else if (b == 1 && g == 1 && r == 0 || b == 0 && g == 0 && r > 0)
        ans = "R";
      else if (b == 1 && g == 0 && r == 1 || b == 0 && g > 0 && r == 0)
        ans = "G";
      else if (b == 0 && g == 1 && r == 1 || b > 0 && g == 0 && r == 0)
        ans = "B";
      Console.WriteLine(ans);
    }
  }

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


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

class Program
{
    public static char GetItem(int[] data)
    {
        while (data[0] + data[1] + data[2] > 1)
        {
            if (data[0] == Math.Min(Math.Min(data[0], data[1]), data[2]))
            {
                int delta = 1;// Math.Min(data[1], data[2]);
                data[0] += delta;
                data[1] -= delta;
                data[2] -= delta;
            }
            else if (data[1] == Math.Min(Math.Min(data[0], data[1]), data[2]))
            {
                int delta = 1;// Math.Min(data[0], data[2]);
                data[1] += delta;
                data[0] -= delta;
                data[2] -= delta;
            }
            else
            {
                int delta = 1;// Math.Min(data[0], data[1]);
                data[2] += delta;
                data[0] -= delta;
                data[1] -= delta;
            }
        }
        if (data[0] == 1)
            return 'R';
        else if (data[1] == 1)
            return 'G';
        else
            return 'B';
    }

    public static void Main()
    {
        int[] data = new int[3];
        int n = int.Parse(Console.ReadLine());
        string card = Console.ReadLine();
        foreach (var item in card)
        {
            if (item == 'R')
                ++data[0];
            else if (item == 'G')
                ++data[1];
            else
                ++data[2];
        }
        string res = "";
        if (data[0] == 0 && data[1] == 0 || data[1] == 0 && data[2] == 0 || data[0] == 0 && data[2] == 0)
        {
            if (data[0] == 0 && data[1] == 0)
                Console.WriteLine("B");
            else if (data[0] == 0 && data[2] == 0)
                Console.WriteLine("G");
            else
                Console.WriteLine("R");
        }
        else if (data[0] == 0 || data[1] == 0 || data[2] == 0)
        {
            if (data[0] == 0)
            {
                res += "R";
                if (data[1] == 1 && data[2] > 1)
                    res +="G";
                else if (data[1] > 1 && data[2] == 1)
                    res += "B";
                else if (data[1] > 1 && data[2] > 1)
                    res += "GB";
            }
            else if (data[1] == 0)
            {
                res += "G";
                if (data[0] == 1 && data[2] > 1)
                    res +="R";
                else if (data[0] > 1 && data[2] == 1)
                    res += "B";
                else if (data[0] > 1 && data[2] > 1)
                    res +="RB";
            }
            else
            {
                res += "B";
                if (data[1] == 1 && data[0] > 1)
                    res += "G";
                else if (data[1] > 1 && data[0] == 1)
                    res +="R";
                else if (data[1] > 1 && data[0] > 1)
                    res += "GR";
            }
            char[] arr = res.ToCharArray().OrderBy(x => x).ToArray();
            foreach (var item in arr)
                Console.Write(item);
        }
        else
        {
            Console.WriteLine("BGR");
        }
    }
}


using System;

namespace AllProblems
{
    class _328B_SheldonAndIcePieces
    {
        public static void Run()
        {
            var t = ReadArray(Console.ReadLine().Trim());
            var s = ReadArray(Console.ReadLine().Trim());

            var min = int.MaxValue;
            for (var i = 0; i < 10; i++)
            {
                if(t[i] == 0) continue;
                if (s[i] == 0)
                {
                    Console.WriteLine(0);
                    return;
                }
                var q = s[i]/t[i];
                if (q < min) min = q;
            }
            Console.WriteLine(min);
            Console.ReadLine();
        }

        static int[] ReadArray(string t)
        {
            var n = new int[10];
            foreach (var s in t)
            {
                switch (s)
                {
                    case '5':
                        n[2]++;
                        break;
                    case '9':
                        n[6]++;
                        break;
                    default:
                        n[s - 48]++;
                        break;
                }
            }

            return n;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            _328B_SheldonAndIcePieces.Run();
        }
    }
}


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

namespace Graph
{
    class Program
    {
        static void Main(string[] args)
        {
            string num = Console.ReadLine();
            string str = Console.ReadLine();

            int res = 0;
            bool done = false;
            int n = str.Length;
            for (int i = 0; i < n; i++)
            {
                //res = i;
                //Console.WriteLine(i + " " + str + " " + done + " " + n);
                if(str.Length == 0 ){
                    Console.WriteLine(res);
                    return;
                }

                if (!done)
                {

                    for (int j = 0; j < num.Length; j++)
                    {
                        if (num[j] == '9' || num[j] == '6')
                        {
                            if (str.IndexOf('9') != -1)
                            {
                                str = str.Remove(str.IndexOf('9'), 1);
                            }
                            else
                            {
                                if (str.IndexOf('6') != -1)
                                {
                                    str = str.Remove(str.IndexOf('6'), 1);
                                }
                                else
                                {
                                    //Console.WriteLine("Нет девятки и шестерки");
                                    done = true;
                                    Console.WriteLine(res);
                                    return;
                                }
                            }
                        }
                        else
                        {
                            if (num[j] == '5' || num[j] == '2')
                            {
                                if (str.IndexOf('5') != -1)
                                {
                                    str = str.Remove(str.IndexOf('5'), 1);
                                }
                                else
                                {
                                    if (str.IndexOf('2') != -1)
                                    {
                                        str = str.Remove(str.IndexOf('2'), 1);
                                    }
                                    else
                                    {
                                        //Console.WriteLine("Нет двойки и пятерки");
                                        done = true;
                                        Console.WriteLine(res);
                                        return;
                                    }
                                }
                            }
                            else {
                                if (str.IndexOf(num[j]) != -1)
                                {
                                    str = str.Remove(str.IndexOf(num[j]), 1);
                                }
                                else {
                                    //Console.WriteLine("Нет " + num[j]);
                                    done = true;
                                    Console.WriteLine(res);
                                    return;
                                    //break;
                                }

                            }
                        }
                    }

                    res++;
                }
            }

            Console.WriteLine(res);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using CompLib.Util;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        string s = sc.Next();

        // n文字 sがある

        // s_iに隣接する文字がs_iより1つ小さいならs_iを消せる

        // 消せる 最大

        var ar = s.ToCharArray();

        for (char c = 'z'; c >= 'b'; c--)
        {
            var stack = new Stack<char>();
            foreach (char ch in ar)
            {
                if (ch == c && stack.Count > 0 && stack.Peek() == c - 1)
                {
                    continue;
                }
                else if (ch == c - 1)
                {
                    while (stack.Count > 0 && stack.Peek() == c)
                    {
                        stack.Pop();
                    }
                    stack.Push(ch);
                }
                else
                {
                    stack.Push(ch);
                }
            }

            ar = new char[stack.Count];
            for (int i = ar.Length - 1; i >= 0; i--)
            {
                ar[i] = stack.Pop();
            }
        }

        Console.WriteLine(n - ar.Length);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


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

class Program
{
    static void test123()
    {

        string str = Console.ReadLine();
        var str1 = str.Split(' ');

        UInt64 n = Convert.ToUInt64(str1[0]);
        UInt64 m = Convert.ToUInt64(str1[1]);
        UInt64 a = Convert.ToUInt64(str1[2]);

        UInt64 a1 = n / a + (UInt64) (n % a > 0 ? 1 : 0);
        UInt64 a2 = m / a + (UInt64) (m % a > 0 ? 1 : 0);

        Console.WriteLine(a1 * a2);

    }

    static (char, List<int>) MaxSymbolLowerThan(string str, int maxValue)
    {
        int maxFindedValue = 0;
        int indexOfMax = 0;
        List<int> indexes = new List<int>();

        for (int i = 0; i < str.Length; i++)
        {
            if (str[i] > maxFindedValue && (int) str[i] < maxValue) // проверить как он кастуется к инту
            {
                indexes.Clear();
                indexes.Add(i);
                maxFindedValue = (int) (str[i]); //Char.GetNumericValue
            }
            else if (maxFindedValue == str[i])
            {
                indexes.Add(i);
            }
        }

        return ((char)maxFindedValue, indexes);
    }

    static void test3234234()
    {
        int n = Convert.ToInt32(Console.ReadLine());

        int steps = 0;

        string str = Console.ReadLine();

        //int count = 0;

        int indexOfMax = 0; // нужен ли ?

        List<int> indexesOfMax;

        char maxSymbol = ' ';
        (maxSymbol, indexesOfMax) = MaxSymbolLowerThan(str, 9999);

        //var indexesOfMaxBuffer = indexesOfMax.GetRange(0, n);
        //int[] indexEsOfMaxValue = str.Where(s=>s==maxSymbol).Select()

        int minValue = str.Min();

        bool ValueWasFinded = false;
        bool LastSymbol = false;
        int countOfIndexes = 123;
        //while (true)
        //{
        //if (n == 1) // лучше через n
        //{
        //    Console.WriteLine(steps);
        //    return;
        //}

        //if (LastSymbol && minValue == (int) maxSymbol) // еще один флаг ?  проверка недоделана !!!
        //{
        //    Console.WriteLine(steps);
        //    return;
        //}

        int j = 0; // индекс в IndexesOfMax
        while (true)
        {
            if (countOfIndexes == 0)
            {
                Console.WriteLine(steps);
                return;
            }

            if (j < indexesOfMax.Count && indexesOfMax[j] != 0 && str[indexesOfMax[j] - 1] == (int) str[indexesOfMax[j]] - 1 )
            {
                ValueWasFinded = true;
                str = str.Remove(indexesOfMax[j], 1);
                steps++;
                n--;
                indexesOfMax.RemoveAt(j);
                for (var z = j ; z < indexesOfMax.Count; z++)
                    indexesOfMax[z]--;

            }

            else if (j < indexesOfMax.Count && indexesOfMax[j] != n - 1 && str[indexesOfMax[j] + 1] == (int) (str[indexesOfMax[j]]) - 1)
            {
                ValueWasFinded = true;
                str = str.Remove(indexesOfMax[j], 1);

                steps++;
                n--;
                indexesOfMax.RemoveAt(j);
                for (var z = j ; z<indexesOfMax.Count; z++)
                    indexesOfMax[z]--;

            }

            else
            {
                if (j >= indexesOfMax.Count - 1)
                {
                    if (!ValueWasFinded)
                    {
                        (maxSymbol, indexesOfMax) = MaxSymbolLowerThan(str, (int) maxSymbol);
                        countOfIndexes = indexesOfMax.Count;
                    }
                    else
                        ValueWasFinded = false;
                    j = 0;
                }
                else
                    j++;
            }
        }
    }

    static void Main(string[] args)
    {

        test3234234();
    }
}


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

class Solver
{
    public void Solve(Scanner sc)
    {
        int N, K;long M;
        sc.Make(out N, out K, out M);
        var T = sc.ArrInt;
        Array.Sort(T);
        var res = 0L;
        for(int i = 0; i <= N; i++)
        {
            var sum = 0L;
            for (int j = 0; j < K; j++)
                sum += i * T[j];
            if (sum > M) break;
            var rest = N - i;
            var max = i * (K+1L);
            for(int j = 0; j < K; j++)
            {
                if (rest * T[j] <= M - sum) { sum += rest * T[j];max += rest;continue; }
                max += (M - sum) / T[j];break;
            }
            chmax(ref res, max);
        }
        Console.WriteLine(res);
    }
}

#region Template
public static class Template
{
    static void Main(string[] args)
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver().Solve(new Scanner());
        Console.Out.Flush();
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) > 0) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; }
    public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; }
    public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; }
    public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid());
    public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; }
    public static int MaxElement<T>(this IList<T> A, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; }
    public static T PopBack<T>(this List<T> A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; }
    public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }
}
public class Scanner
{
    public string Str => Console.ReadLine().Trim();
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
    public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
    public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
    public int[] ArrInt1D(int n) => Create(n, () => Int);
    public long[] ArrLong1D(int n) => Create(n, () => Long);
    public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
    public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
    private Queue<string> q = new Queue<string>();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }
    public void Make<T1>(out T1 v1) => v1 = Next<T1>();
    public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); }
    public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); }
    public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); }
    public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); }
    public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); }
    public void Make<T1, T2, T3, T4, T5, T6, T7>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6, out T7 v7) { Make(out v1, out v2, out v3, out v4, out v5, out v6); v7 = Next<T7>(); }
    //public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, v2); }
    //public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, out T3 v3); return (v1, v2, v3); }
    //public (T1, T2, T3, T4) Make<T1, T2, T3, T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, v3, v4); }
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>>
{
    public T1 v1;
    public T2 v2;
    public Pair() { }
    public Pair(T1 v1, T2 v2)
    { this.v1 = v1; this.v2 = v2; }

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

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

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