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

namespace CleanCode
{
    class Program
    {
        static void Main(string[] args)
        {
            string x = Console.ReadLine();
            string[] y = x.Split(' ');
            double a = Convert.ToDouble(y[0]);
            double b = Convert.ToDouble(y[1]);
            int i = 0;
            if (1 <= b && b < a && a <= Math.Pow(10, 12))
            {
                while (b <= a)
                {
                    double temp = a - b;
                    a = temp < b ? b : temp;
                    b = b < a ? b : temp;
                    i++;
                    if (b == 0)
                        break;
                }
            }
            Console.WriteLine(i.ToString());
        }
    }
}


using System;
using System.IO;

namespace Issue_527A
{
    class Program
    {
        public static void Main(string[] args) {
            var width = IO.Read();
            var height = IO.Read();

            long count = 0;

            while (width > 0) {
                if (height > width)
                    Swap(ref height, ref width);

                if (width % height == 0) {
                    count += width / height;
                    break;
                }

                width -= height;
                count++;
            }

            Console.WriteLine(count);
        }

        private static void Swap(ref long a, ref long b) {
            var temp = a;
            a = b;
            b = temp;
        }
    }

    public static class IO {
        static IO() {
            Reader = new StreamReader(
                Console.OpenStandardInput(sizeof(long)),
                System.Text.Encoding.ASCII,
                false,
                sizeof(long),
                false);
        }

        public static StreamReader Reader { get; set; }

        public static long Read() {
            const int zeroCode = (int) '0';

            long result = 0;
            int digit;
            long cache1;
            long cache2;

            var isNegative = false;
            var symbol = Reader.Read();

            while (symbol == ' ') {
                symbol = Reader.Read();
            }

            if (symbol == '-') {
                isNegative = true;
                symbol = Reader.Read();
            }

            for ( ;
                (symbol != -1) && (symbol != ' ');
                symbol = Reader.Read()
            ) {
                digit = symbol - zeroCode;

                if (digit < 10 && digit >= 0) {
                    cache1 = result << 1;
                    cache2 = cache1 << 2;
                    result = cache1 + cache2 + digit;
                } else {
                    if (symbol == 13)         // if symbol == \n
                        Reader.Read();          // skip next \r symbol
                    break;
                }
            }

            return isNegative ? ~result + 1 : result;
        }

        public static string Line() {
            return Reader.ReadLine();
        }
    }
}


using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            double a = Convert.ToDouble(input[0]);
            double b = Convert.ToDouble(input[1]);

            double answer = 0;

            while (a != b)
            {
                if (a > b)
                {
                    if (a % b == 0)
                    {
                        answer += a / b;
                        Console.WriteLine(answer);
                        return;
                    }
                    a = a - b;
                }
                else
                {
                    if (b % a == 0)
                    {
                        answer += b / a;
                        Console.WriteLine(answer);
                        return;
                    }
                    b = b - a;
                }

                answer++;
            }

            //answer++; // a == b

            Console.WriteLine(answer);
        }
    }
}


using System;

class A714 {
    public static void Main() {
        var line = Console.ReadLine().Split();
        var l1 = int.Parse(line[0]);
        var r1 = int.Parse(line[1]);
        var l2 = int.Parse(line[2]);
        var r2 = int.Parse(line[3]);
        var k = int.Parse(line[4]);
        var l = Math.Max(l1, l2);
        var r = Math.Min(r1, r2);
        var ans = Math.Max(0, r - l + 1);
        if (l <= k && k <= r) --ans;
        Console.WriteLine(ans);
    }
}


<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{2EAAF829-089B-443C-A985-B1AB48407DE9}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>Task_01</RootNamespace>
    <AssemblyName>Task_01</AssemblyName>
    <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <None Include="App.config" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>


<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{6E9044DB-BA15-4CBE-AC2A-7ABAA7C39024}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>FiljaISonja</RootNamespace>
    <AssemblyName>FiljaISonja</AssemblyName>
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <None Include="App.config" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>


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

namespace CodeforcesB
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            int start = 0;
            int end = 0;

            if (input[0] < input[2])
            {
                start = input[2];
            } else
            {
                start = input[0];
            }

            if (input[1] < input[3])
            {
                end = input[1];
            }
            else
            {
                end = input[3];
            }

            if (end < start)
            {
                Console.WriteLine(0);
            } else
            {
                if (input[4] >= start && input[4] <= end)
                {

                } else
                {
                    end++;
                }
                Console.WriteLine(end - start);
            }
            //Console.ReadLine();
        }
    }
}


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

namespace CodeForces
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            string[] strArray = str.Split(' ');
            long n = long.Parse(strArray[0]);
            long k = long.Parse(strArray[1]) - 1;

            List<int> arr = new List<int>();
            for (int i = 0; i < n; i++)
            {
                if ((i + 1) % 2 == 1)
                    arr.Add(i + 1);
            }
            for (int i = 0; i < n; i++)
            {
                if ((i + 1) % 2 == 0)
                    arr.Add(i + 1);
            }
            Console.WriteLine(arr[(int)k]);

            //Console.ReadKey();
        }
    }
}


using System;
using System.IO;
using System.Collections.Generic;
public class dp_cut_ribbon_189A
    {
        Dictionary<int, int> dp = new Dictionary<int, int>();
        private int max(int a, int b, int c)
        {
            return Math.Max(a, Math.Max(b, c));
        }
        private int rec(int n, int a, int b, int c)
        {
            if (dp.ContainsKey(n))
                return dp[n];
            if (n < 0)
                return -1;
            if (n == 0)
                return 0;
            int x = rec(n - a, a, b, c), y = rec(n - b, a, b, c), z = rec(n - c, a, b, c);
            if (x >= 0 || y >= 0 || z >= 0)
                dp[n] = max(x, y, z) + 1;
            else
                dp[n] = -1;
            return dp[n];
        }
        public int solve(int n, int a, int b, int c)
        {
            return rec(n, a, b, c);
        }
    }
    class main
    {
        private static void print(string s = "")
        {
            Console.Write(s);
        }
        private static void print(int s)
        {
            Console.Write(s);
        }
        private static void printL(string s = "")
        {
            Console.WriteLine(s);
        }
        private static void printL(int s)
        {
            Console.WriteLine(s);
        }
        static void Main(string[] args)
        {
                int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

                dp_cut_ribbon_189A obj = new dp_cut_ribbon_189A();

                printL(obj.solve(input[0],input[1],input[2],input[3]));

        }
    }


public class Test
    {
        public static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int a = int.Parse(input[1]);
            int b = int.Parse(input[2]);
            int c = int.Parse(input[3]);

            int[] div = new int[n + 1];

            div[0] = 0;
            for (int i = Math.Min(a, Math.Min(b, c)); i <= n; ++i)
            {
                if (i >= a)
                    div[i] = div[i - a] + 1;
                if (i >= b)
                    div[i] = Math.Max(div[i], div[i - b] + 1);
                if(i >= c)
                    div[i] = Math.Max(div[i], div[i - c] + 1);
            }

            Console.WriteLine(div[n]);
        }
    }


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

namespace AlgoTraining.Codeforces.C_s
{
    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 Array53
    {
        public static void Main(string[] args)
        {
            using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
            using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
            {
                int n = fs.NextInt();
                long mod = 1000000007;
                if (n == 1)
                {
                    writer.WriteLine(1);
                    return;
                }
                long[,] factor = new long[n, n];
                long[,] initial = new long[1, n];
                for (int i = 0; i < n; i++)
                {
                    initial[0, i] = n - i;
                    for (int j = 0; j <= i; j++)
                    {
                        factor[i, j] = 1;
                    }
                }
                factor = BinPowMatrixMod(factor, n - 1, mod);
                long[,] ans = MatrixProductMod(initial, factor, mod);
                writer.WriteLine((ans[0, 0] * 2 - n) % mod);
            }
        }
        public static long[,] BinPowMatrixMod(long[,] a, long p, long mod) // p >= 1
        {
            if (a.GetLength(0) != a.GetLength(1))
            {
                throw new Exception("Not a square matrix");
            }

            if (p == 1) return a;
            if ((p & 1) == 0)
            {
                long[,] t = BinPowMatrixMod(a, p / 2, mod);
                return MatrixProductMod(t, t, mod);
            }
            else
            {
                return MatrixProductMod(a, BinPowMatrixMod(a, p - 1, mod), mod);
            }
        }
        private static long[,] MatrixProductMod(long[,] matrixA, long[,] matrixB, long mod)
        {
            int aRows = matrixA.GetLength(0); int aCols = matrixA.GetLength(1);
            int bRows = matrixB.GetLength(0); int bCols = matrixB.GetLength(1);
            if (aCols != bRows)
                throw new Exception("Can't multiply because of incompatible sizes");

            long[,] result = new long[aRows, bCols];

            Parallel.For(0, aRows, i =>
            {
                for (int j = 0; j < bCols; ++j) // each col of B
                    for (int k = 0; k < aCols; ++k) // could use k < bRows
                        result[i, j] = (result[i, j] + matrixA[i, k] * matrixB[k, j]) % mod;
            });

            return result;
        }
    }
}


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

namespace AlgoTraining.Codeforces.C_s
{
    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 Array53
    {
        public static void Main(string[] args)
        {
            using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
            using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
            {
                int n = fs.NextInt();
                int mod = 1000000007;
                if (n == 1)
                {
                    writer.WriteLine(1);
                    return;
                }
                long ans = (FactorialMod(2 * n - 1, mod) * 1L * BinPowMod((FactorialMod(n - 1, mod) * 1L * FactorialMod(n, mod)) % mod, mod - 2, mod)) % mod;
                writer.WriteLine(ans * 2 - n);
            }
        }

        public static int FactorialMod(int n, int mod)
        {
            long res = 1;
            while (n > 0)
            {
                for (int i = 2, m = n % mod; i <= m; i++)
                    res = (res * i) % mod;
                if ((n /= mod) % 2 > 0)
                    res = mod - res;
            }
            return (int)res;
        }

        public static long BinPowMod(long a, long p, long mod)
        {
            if (p == 0) return 1;
            if ((p & 1) == 0)
            {
                long t = BinPowMod(a, p / 2, mod);
                return (t * t) % mod;
            }
            else
            {
                return (a % mod * BinPowMod(a, p - 1, mod)) % mod;
            }
        }
    }
}


#if DEBUG
using System.Reflection;
using System.Threading.Tasks;
#endif

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

#if DEBUG
using System.Diagnostics;
#endif

namespace _489с
{
    class Program
    {
        static string _inputFilename = "input.txt";
        static string _outputFilename = "output.txt";
        static bool _useFileInput = false;
        const string _delim = "!";

        static void Main(string[] args)
        {
            StreamWriter file = null;
#if DEBUG
            var testNumber = 0;
            var timer = new Stopwatch();
            foreach (var test in GetTests())
            {

                timer.Start();

                var defaultColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine($"<!-- TEST #{testNumber} -->");
                Console.ForegroundColor = defaultColor;
                Console.SetIn(test);

#else
            if (_useFileInput)
            {
                Console.SetIn(File.OpenText(_inputFilename));
                file = new StreamWriter(_outputFilename);
                Console.SetOut(file);
            }
#endif

            try
            {
#if DEBUG
                Solution(testNumber);
#else
                Solution(0);
#endif
            }
            finally
            {
#if DEBUG
#else
                if (_useFileInput)
                {
                    file.Close();
                }
#endif
            }

#if DEBUG
                timer.Stop();

                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine($"<!-- TEST #{testNumber} FINISHED IN {timer.Elapsed.ToString(@"ss\:fff")}-->");
                Console.ForegroundColor = defaultColor;

                timer.Reset();
                testNumber++;
            }
#endif
        }

        static long mod = 1000 * 1000 * 1000 + 7;

        static void Solution(int testNumber)
        {
            #region SOLUTION
            var d = ReadLongArray();
            var x = d[0];
            var k = d[1];

            if (x == 0)
            {
                Console.WriteLine(0);
                return;
            }

            k++;
            var kp = Pow(2, k);
            kp *= x;
            kp %= mod;

            var next = 1L;
            if (k == 2)
            {
                next = -1;
            }
            else if (k == 1)
            {
                next = 0;
            }
            else if (k > 2)
            {
                //var gp = (1 - Pow(2, k - 2)) / (1 - 2);
                next = -Pow(2, k - 1) + 1;
            }

            var res = kp + next;
            res %= mod;

            Console.WriteLine(res);
            //var n = readInt();
            //var m = readInt();

            //var a = readIntArray();
            //var b = readIntArray();
            #endregion
        }

        static long Pow(long a, long pp)
        {
            var res = 1L;
            while (true)
            {
                if (pp % 2 == 1)
                {
                    res *= a;
                    res %= mod;
                    pp--;
                }
                else
                {
                    pp /= 2;
                    a *= a;

                    a %= mod;
                }

                if (pp == 0)
                {
                    break;
                }
            }

            return res;
        }

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

        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => int.Parse(i)).ToArray();
        }

        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => long.Parse(i)).ToArray();
        }

#if DEBUG
        static IEnumerable<TextReader> GetTests()
        {
            var tests = new List<string>();
            var resName = Assembly.GetCallingAssembly().GetManifestResourceNames()[0];
            using (var resource = new StreamReader(Assembly.GetCallingAssembly().GetManifestResourceStream(resName)))
            {
                while (true)
                {
                    var nextText = new StringBuilder();
                    var endOfFile = false;
                    while (true)
                    {
                        var line = resource.ReadLine();

                        endOfFile = line == null;
                        if (endOfFile)
                        {
                            break;
                        }

                        if (line.StartsWith(_delim, StringComparison.Ordinal))
                        {
                            break;
                        }

                        nextText.AppendLine(line);
                    }

                    yield return new StringReader(nextText.ToString());

                    if (endOfFile)
                    {
                        break;
                    }
                }
            }
        }
#endif
    }
}


#if DEBUG
using System.Reflection;
using System.Threading.Tasks;
#endif

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

#if DEBUG
using System.Diagnostics;
#endif

namespace _489с
{
    class Program
    {
        static string _inputFilename = "input.txt";
        static string _outputFilename = "output.txt";
        static bool _useFileInput = false;
        const string _delim = "!";

        static void Main(string[] args)
        {
            StreamWriter file = null;
#if DEBUG
            var testNumber = 0;
            var timer = new Stopwatch();
            foreach (var test in GetTests())
            {

                timer.Start();

                var defaultColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine($"<!-- TEST #{testNumber} -->");
                Console.ForegroundColor = defaultColor;
                Console.SetIn(test);

#else
            if (_useFileInput)
            {
                Console.SetIn(File.OpenText(_inputFilename));
                file = new StreamWriter(_outputFilename);
                Console.SetOut(file);
            }
#endif

            try
            {
#if DEBUG
                Solution(testNumber);
#else
                Solution(0);
#endif
            }
            finally
            {
#if DEBUG
#else
                if (_useFileInput)
                {
                    file.Close();
                }
#endif
            }

#if DEBUG
                timer.Stop();

                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine($"<!-- TEST #{testNumber} FINISHED IN {timer.Elapsed.ToString(@"ss\:fff")}-->");
                Console.ForegroundColor = defaultColor;

                timer.Reset();
                testNumber++;
            }
#endif
        }

        static long mod = 1000 * 1000 * 1000 + 7;

        static void Solution(int testNumber)
        {
            checked
            {
                #region SOLUTION
                var d = ReadLongArray();
                var x = d[0];
                var k = d[1];

                if (x == 0)
                {
                    Console.WriteLine(0);
                    return;
                }

                k++;
                var kp = Pow(2, k);
                kp *= x;
                kp %= mod;

                var next = 1L;
                if (k == 2)
                {
                    next = -1;
                }
                else if (k == 1)
                {
                    next = 0;
                }
                else if (k > 2)
                {
                    //var gp = (1 - Pow(2, k - 2)) / (1 - 2);
                    next = -Pow(2, k - 1) + 1;
                    next %= mod;
                }

                var res = kp + next;
                if (res < 0)
                {
                    res += mod;
                }
                res %= mod;

                Console.WriteLine(res);
            }
            //var n = readInt();
            //var m = readInt();

            //var a = readIntArray();
            //var b = readIntArray();
            #endregion
        }

        static long Pow(long a, long pp)
        {
            checked
            {
                var res = 1L;
                while (true)
                {
                    if (pp % 2 == 1)
                    {
                        res *= a;
                        res %= mod;
                        pp--;
                    }
                    else
                    {
                        pp /= 2;
                        a *= a;

                        a %= mod;
                    }

                    if (pp == 0)
                    {
                        break;
                    }
                }

                return res;
            }

        }

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

        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => int.Parse(i)).ToArray();
        }

        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => long.Parse(i)).ToArray();
        }

#if DEBUG
        static IEnumerable<TextReader> GetTests()
        {
            var tests = new List<string>();
            var resName = Assembly.GetCallingAssembly().GetManifestResourceNames()[0];
            using (var resource = new StreamReader(Assembly.GetCallingAssembly().GetManifestResourceStream(resName)))
            {
                while (true)
                {
                    var nextText = new StringBuilder();
                    var endOfFile = false;
                    while (true)
                    {
                        var line = resource.ReadLine();

                        endOfFile = line == null;
                        if (endOfFile)
                        {
                            break;
                        }

                        if (line.StartsWith(_delim, StringComparison.Ordinal))
                        {
                            break;
                        }

                        nextText.AppendLine(line);
                    }

                    yield return new StringReader(nextText.ToString());

                    if (endOfFile)
                    {
                        break;
                    }
                }
            }
        }
#endif
    }
}


using System;
using System.Linq;
class DELETEME
{
    static void Main()
    {
        var d = Console.ReadLine().Split().Select(Int32.Parse).ToArray();
        int r = d[1], k = d[0];
        var result = 1;
        while ((result * k - r) % 10 != 0)
            result++;
        Console.WriteLine(result);
    }
}-


using System;
using System.Linq;
class DELETEME
{
    static void Main()
    {
        var d = Console.ReadLine().Split().Select(Int32.Parse).ToArray();
        int r = d[1], k = d[0];
        var result = 1;
        while ((result * k - r) % 10 != 0 || (result * k) % 10 != 0)
            result++;
        Console.WriteLine(result);
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
             Int64 n=Int64.Parse(Console.ReadLine());
             string[]s=Console.ReadLine().Split(' ');
             int[]a=new int[n];
             for(int i=0;i<n;i++)
             a[i]=int.Parse(s[i]);
             bool d=false;
             if(n>0)
             {
             if(a[0]<=15)
             {
                  for(int i=1;i<n;i++)
                  {
                       if(a[i]-a[i-1]>15)
                       {
                            Console.WriteLine(a[i-1]+15);
                            d=true;
                            break;
                       }
                  }
                  if(d==false)
             Console.WriteLine(90);
             }
             else
             Console.WriteLine(15);
             }
             else
             {
                  if(a[0]<=15)
             Console.WriteLine(a[0]+15);
             else
             Cosnole.WriteLine(15);
             }
        }

    }
}


class Program
{
    static void Main(string[] args)
    {
        int mins2 = Console.ReadLine();
        string minsList = Console.ReadLine();
        string[] mins = minsList.Split(' ');
        int[] finalMins = new int[mins.Length];
        for(int i = 0;i<= mins.Length - 1;i++)
         finalMins[i] = (int) mins[i];
        if(finalMins[0] > 15)
            Console.WriteLine(15);
        else
        {
            int result = 0;
            for(int j = 0;j<= finalMins.Length - 1;j++)
            {
                    if(result + 15 >= finalMins[j] && result < 90)
                    {
                        result = finalMins[j];
                    }
                    else
                    {
                        result = result + 15;
                        break;
                    }

            }
            result = result > 90 ? 90 : result;
            Console.WriteLine(90);
        }

    }
}


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

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            long d = 1000000007;
            long p = 1;
            for (int i = 0; i < n; i++)
            {
                p = p << 1;
                p %= d;
            }
            long res = (p * p + p) / 2;
            res %= d;
            Console.WriteLine(res);
        }
    }
}


using System;

namespace GrassPlant
{
    class Matrix
    {
        public long A11
        {
            get;
            set;
        }
        public long A12
        {
            get;
            set;
        }
        public long A21
        {
            get;
            set;
        }
        public long A22
        {
            get;
            set;
        }
    }

    class Program
    {
        private static int p = 1000000007;

        private static int n;

        private static Matrix m = new Matrix{A11 = 3, A12 = 1, A21 = 1, A22 = 3};

        static void Main(string[] args)
        {
            n = Convert.ToInt32(Console.ReadLine());

            long result = Solve();
            Console.Out.WriteLine(result);
        }

        private static long Solve()
        {
            return Power(n).A11;
        }

        static Matrix Power(long power)
        {
            if (power == 0)
            {
                return new Matrix{A11 = 1, A22 = 1, A12 = 0, A21 = 0};
            }
            if (power == 1)
            {
                return m;
            }

            long remainder = power % 2;
            Matrix result = Power(power / 2);
            result = Multiply(result, result);

            if (remainder == 1)
            {
                result = Multiply(result, m);
            }

            return result;
        }

        static Matrix Multiply(Matrix m1, Matrix m2)
        {
            return new Matrix
            {
                A11 = ((m1.A11 * m2.A11) % p + (m1.A12 * m2.A21) % p) % p, A12 = ((m1.A11 * m2.A12) % p + (m1.A12 * m2.A22) % p) % p,
                A21 = ((m1.A21 * m2.A11) % p + (m1.A22 * m2.A21) % p) % p, A22 = ((m1.A21 * m2.A12) % p + (m1.A22 * m2.A22) % p) % p
            };
        }
    }
}


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

namespace D.Polyline
{
    class Program
    {
        static void Main(string[] args)
        {
            long[][] p = new long[3][];
            for (var i = 0; i < 3; ++i)
                p[i] = new long[2];
            for(var i = 0; i < 3; ++i) {
                var nm = Console.ReadLine().Split();
                p[i][0] = long.Parse(nm[0]);
                p[i][1] = long.Parse(nm[1]);
            }
            Console.WriteLine(function(p));
        }
        static long function(long[][] p)
        {
            long[] x = p[0];
            long[] y = p[1];
            long[] z = p[2];
            long _x = x[0];
            long _y = y[0];

            if (x[0] == y[0] && y[0] == z[0])
                return 1;

            if (x[1] == y[1] && y[1] == z[1])
                return 1;
            if (check(x, y, z) || check(x, z, y) || check(y, x, z))
                return 2;
            return 3;

        }
        static bool check(long[] p1, long[] p2, long[] p3)
        {
            if ((p1[0] == p2[0] || p2[0] == p3[0]) && belongX(p1, p2, p3))
                return true;
            if ((p1[1] == p2[1] || p2[1] == p3[1]) && belongY(p1, p2, p3))
                return true;
            return false;
        }
        static bool belongX(long[] p1, long[] p2, long[] p3)
        {
            return Math.Min(p1[0], p3[0]) <= p2[0] && p2[0] <= Math.Max(p1[0], p3[0]);
        }
        static bool belongY(long[] p1, long[] p2, long[] p3)
        {
            return Math.Min(p1[1], p3[1]) <= p2[1] && p2[1] <= Math.Max(p1[1], p3[1]);
        }
    }
}


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

class Program
{
    public class Point
    {
        public int X;
        public int Y;
    }

    public static Point ReadPoint()
    {
        var p = new Point();
        p.X = ReadInt();
        p.Y = ReadInt();

        return p;
    }

    private static int Count(Point a, Point b, Point c)
    {
        if (a.X == b.X && a.X == c.X) return 1;
        if (a.Y == b.Y && a.Y == c.Y) return 1;

        if (a.X == b.X) return 2;
        if (a.Y == b.Y) return 2;

        return 3;
    }

    static void Main(string[] args)
    {
        var a = ReadPoint();
        var b = ReadPoint();
        var c = ReadPoint();

        int[] ans = new int[6];
        ans[0] = Count(a, b, c);
        ans[1] = Count(a, c, b);
        ans[2] = Count(b, a, c);
        ans[3] = Count(b, c, a);
        ans[4] = Count(c, a, b);
        ans[5] = Count(c, b, a);

        Console.WriteLine(ans.Min());
    }

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

        return g;
    }

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

        return matrix;
    }

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

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

    private const int BufferSize = 1 << 16;
    private static readonly StreamReader consoleReader = new StreamReader(Console.OpenStandardInput(BufferSize), Encoding.ASCII, false, BufferSize);

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

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

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

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

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

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

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

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

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

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

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

        return s.ToArray();
    }

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

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

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

        return s;
    }

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

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

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

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


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

namespace _742A__Сложный_экзамен_Arpa_и_наивный_чит_Mehrdad
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] res = { 8, 4, 2, 6 };
            if (n == 0)
                Console.WriteLine(1);
            else
            {
                Console.WriteLine(res[n % 4 - 1]);
            }
        }
    }
}


using System;

public class Program
{
	public static void Main()
	{
		int[] s = { 8, 4, 2, 6};
	    long n = long.Parse(Console.ReadLine());
		n = (n % 4)-1 ;
		Console.WriteLine(s[n]);
	}
}


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

class Solver
{
    Scanner sc = new Scanner();
    //

    public void Solve()
    {
        int n, p, l, r;
        sc.Make(out n, out p, out l, out r);
        if (l == 1 && r == n) Fail(0);
        else if (l == 1) Fail(Abs(r - p) + 1);
        else if (r == n) Fail(Abs(l - p) + 1);
        WriteLine(r - l + Min(r - p, p - l) + 2);
    }
}

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

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

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

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

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

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


using System;
namespace Contest
{
class MainClass{
   public static void Main (string[] args){

            long a,b,k,s=0;
            string[] num = Console.ReadLine().Split(' ');
            a=long.Parse(num[0]);
            b=long.Parse(num[1]);
            while(((a%b)!=0)&&(a>0))
            {
                a-=b;
                s++;
                if(a<b)
                {
                    k=b;
                    b=a;
                    a=k;
                }
            }
            s+=a/b;
          Console.WriteLine(s);
    }
}
}


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

namespace origami
{
    class Program
    {
        private static string _str = string.Empty;
        private static Int64 _a = 0;
        private static Int64 _b = 0;
        private static Int64 _ship = 0;

        private static Int64 Count()
        {
            _str = Console.ReadLine();
            _a = Int64.Parse(_str.Split(' ')[0]);
            _b = Int64.Parse(_str.Split(' ')[1]);

            if (_b == 1)
            {
                _ship = _a;
                return _ship;
            }
            if (_a == _b)
            {
                return _ship = 1;
            }

            if (_a%_b != 0)
            {
                _ship = _a/_b;
                if ((_a - _ship * _b) < _b && (_a - _ship * _b != 1))
                {
                    var r = _a;
                    _a = _b;
                    _b = r - _ship*_a;
                }
                else if ((_a - _ship * _b) > _b && (_a - _ship * _b != 1))
                {
                    _a = _a - _ship*_b;
                }
                else if (_a - _ship * _b == 1)
                {
                    return _ship + _b;
                }
                else
                {
                    return _ship;
                }
            }
            else
            {
                return _ship = _a/_b;
            }
            do
            {
                if ((_a - _b) > _b)
                {
                    _ship += 1;
                    _a = _a - _b;
                }
                else if ((_a - _b) < _b)
                {
                    _ship += 1;
                    var r = _b;
                    _b = (_a - _b);
                    _a = r;
                }
                else if ((_a - _b) == _b)
                {
                    _ship += 2;
                    _a = _a - _b;
                }
                else if ((_a - _b) == 0)
                {
                    _ship += 1;
                }
            } while (_a - _b != 0);

            return _ship;
        }
        static void Main(string[] args)
        {
            Console.WriteLine(Count());
            //Console.ReadKey();
        }
    }
}


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

namespace ConsoleApplication249
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            long a = long.Parse(s[0]);
            long b = long.Parse(s[1]);
            long[] m = { a, b };
            int k = 1;
            while (true)
            {
                if (m[0] == m[1])
                {
                    break;
                }
                Array.Sort(m);
                m[1] -= m[0];
                k++;
            }
            Console.WriteLine(k);
        }
    }
}


using System;
using System.Linq;

namespace tren
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] ab = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            long s = 0, count = 1;
            if (ab[1] == 1) { Console.Write(ab[0]); return; }
            while(true)
            {
                if (ab[0] == ab[1]) break;
                s = Math.Min(ab[0], ab[1]);
                ab[1] = Math.Max(ab[0], ab[1]) - s;
                ab[0] = s;
                count++;
            }
            Console.Write(count);
        }
    }
}


using System;

namespace ConsoleApplication1
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            UInt64 a = Convert.ToUInt64(input[0]);
            UInt64 b = Convert.ToUInt64(input[1]);
            UInt64 s = a*b;
            UInt64 count = 1;
            while (a != 1 || b != 1)
            {
                if (b < a)
                {
                    s = s - (b*b);
                    a = s/b;
                }
                else if (a < b)
                {
                    s = s - (a*a);
                    b = s/a;
                }
                count++;
            }
            Console.WriteLine(count);
        }
    }
}


using System;
using System.Linq;
namespace CodeForces
{
    class Contest
    {

        static void Main()
        {

            string [] s = Console.ReadLine().Split(' ');
            long a = Convert.ToInt64(s[0]);
            long b = Convert.ToInt64(s[1]);
            long ans = 0;
            while (a != b)
            {
                long m = Math.Max(a, b);
                long n = Math.Min(a, b);
                a = m - n;
                b = n;
                ans++;

            }
            ans++;

            Console.WriteLine(ans);
            //Console.ReadKey();

        }
    }
}


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

namespace _527A.Playing_with_Paper
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            string[] tok = line.Split(' ');
            ulong a = ulong.Parse(tok[0]),b=ulong.Parse(tok[1]),suma=0;
            while(a>1&&b>1)
            {
                if (b > a)
                {
                    b -= a;
                    suma++;
                }
                else if (b < a)
                {
                    a -= b;
                    suma++;
                }
                else
                {
                    suma++;
                    a = 0;
                    b = 0;
                }
            }
            if (b == 1)
                suma += a;
            else if (a == 1)
                suma += b;
            Console.WriteLine("{0}", suma);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text;

namespace codeforces
{
	class Program
	{
		public class User
		{
			public int c;

			public int r;
		}

		public class Comparer : IComparer<User>
		{
			public int Compare(User x, User y)
			{
				if (x.c < y.c)
					return -1;
				return 1;
			}
		}

		public static long getGcd(long a, long b)
		{
			if (b == 0)
				return a;
			return getGcd(b, a % b);
		}

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

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

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

		public static int Min(int x, int y)
		{
			return Math.Min(x, y);
		}

		public static int Max(int x, int y)
		{
			return Math.Max(x, y);
		}

		public static int Abs(int x)
		{
			return Math.Abs(x);
		}

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

		public static bool Equal(int x, int y, int x1, int y1)
		{
			return x == x1 && y == y1;
		}

		private static void Main(string[] args)
		{
/*			var input = new StreamReader("input.txt");
			var output = new StreamWriter("output.txt");*/
			var arr = Console.ReadLine().Split(' ').Select(long.Parse).ToList();
			var a = arr[0];
			var b = arr[1];
			var ans = 1;
			while (a != b)
			{
				ans++;
				a = a - b;
				if (a < b)
				{
					a = a + b;
					b = a - b;
					a = a - b;
				}
			}
			Console.WriteLine(ans);
			/*			input.Close();
			output.Close();*/
		}
	}
}


using System;

class Program
{
    public static void Main(string[] args)
    {
        int[] input = ReadArray();
        if(input.Length == 2)
        {
            int a = input[0];
            int b = input[1];
            int count = 0;
            do
            {
                int delta = a - b;
                a = b;
                b = delta;
                count++;
            }
            while(delta > 0)
            Console.WriteLine(count);
        }
    }

    private static int[] ReadIntArray()
    {
        string line;
        while(Console.ReadKey().Key == ConsoleKey.Enter)
        {
            line = Console.ReadLine();
        }
        if(line != null)
        {
            string[] sArray = line.Split(' ');
            int n = stringArray.Length;
            int[] intArray = new int[n];
            for(int i = 0; i < n; i++)
            {
                string s = stringArray[i].Trim();
                intArray[i] = int.Parse(s);
            }
            return intArray;
        }
        return null;
    }
}


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

namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] b = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int[] A = new int[5];
            int[] B = new int[5];

            for (int i = 0; i < 5; i++)
            {
                A[i] = 0; B[i] = 0;
            }

            foreach (int i in a)
            {
                switch (i)
                {
                    case 1: A[0]++; break;
                    case 2: A[1]++; break;
                    case 3: A[2]++; break;
                    case 4: A[3]++; break;
                    case 5: A[4]++; break;
                }
                switch (i)
                {
                    case 1: B[0]++; break;
                    case 2: B[1]++; break;
                    case 3: B[2]++; break;
                    case 4: B[3]++; break;
                    case 5: B[4]++; break;
                }
            }

            int[] arr = new int[5];

            for (int i = 0; i < n; i++)
                arr[i] = Math.Abs(B[i] - A[i]);

            foreach(int x in arr)
            {
                if(x%2!=0)
                {
                    Console.WriteLine(-1);
                    return;
                }
            }

            int Last_Words = 0;
            foreach(int x in A)
            {
                Last_Words += x / 2;
            }
            Console.WriteLine(Last_Words);

            Console.ReadLine();

        }
    }
}


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

public class Program
{
    public static void Main(string[] args)
    {
        var x = int.Parse(Console.ReadLine());
        var timeInput = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

        var time = new DateTime(1, 1, 1, timeInput[0], timeInput[1], 0);

        var answer = 0;
        while (time.Minute.ToString().IndexOf('7') == -1 &&
               time.Hour.ToString().IndexOf('7') == -1)
        {
            time = time.AddMinutes(-x);
            ++answer;
        }

        Console.WriteLine(answer);
    }
}


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 queue = new Queue<Node>();
            queue.Enqueue(new Node()
            {
                Level = 0,
                Direction = 0,
                X = 300,
                Y = 300
            });
            visited[300, 300] = true;
            var res = 1;
            while (queue.Count > 0)
            {
                var current = queue.Dequeue();

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

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

                if(res == 150 * 150)
                {
                    break;
                }
            }

            Console.WriteLine(res);
        }
    }
}


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 queue = new Stack<Node>();
            queue.Push(new Node()
            {
                Level = 0,
                Direction = 0,
                X = 300,
                Y = 300
            });
            visited[300, 300] = true;
            while(queue.Count > 0)
            {
                var current = queue.Pop();

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

                if (current.Level == N - 1)
                {
                    continue;
                }
                var direction = Math.Abs((current.Direction + 1) % 8);
                queue.Push(new Node()
                {
                    Direction = direction,
                    Level = current.Level + 1,
                    X = current.X + directions[direction][0],
                    Y = current.Y + directions[direction][1]
                });
                visited[current.X + directions[direction][0], current.Y + directions[direction][1]] = true;
                direction = (current.Direction - 1) % 8;
                if(direction < 0)
                {
                    direction = 8 + direction;
                }
                queue.Push(new Node()
                {
                    Direction = direction,
                    Level = current.Level + 1,
                    X = current.X + directions[direction][0],
                    Y = current.Y + directions[direction][1]
                });
                visited[current.X + directions[direction][0], current.Y + directions[direction][1]] = true;
            }
            var res = 0;
            for(var i = 0; i < 600; i++)
            {
                for(var j = 0; j < 600; j++)
                {
                    if(visited[i, j]) {
                        res++;
                    }
                }
            }
            Console.WriteLine(res);
        }
    }
}


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 arr = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int count = 0;

            var dp = new bool[501,501];
            var list = new List<Tuple<int,int,int>>();
            for (int i = 0; i < n; i++)
            {
                int cur = arr[i];
                var tmp = new List<Tuple<int,int, int>>();
                if(i==0)
                {
                    for(int j=0; j<cur; j++)
                    {
                        dp[250-j,250] = true;
                    }
                    tmp.Add(Tuple.Create( 250-(cur-1),250, 90));
                }
                else if(i%2==1)
                {
                    for (int j = 0; j < list.Count(); j++)
                    {
                        int y = list[j].Item1;
                        int x = list[j].Item2;
                        int deg = list[j].Item3;
                        ee(x, y, cur, deg, ref tmp, ref dp);
                    }

                }
                else
                {
                    for (int j = 0; j < list.Count(); j++)
                    {
                        int y = list[j].Item1;
                        int x = list[j].Item2;
                        int deg = list[j].Item3;
                        VH(x, y, cur, deg, ref tmp, ref dp);
                    }
                }

                list = new List<Tuple<int, int, int>>(tmp);
            }

            for (int i = 0; i < 501; i++)
            {
                for (int j = 0; j < 501; j++)
                {
                    if (dp[i, j]) count++;
                }
            }

            Console.WriteLine(count);

            //Console.WriteLine();

        }

        public static void VH(int x , int y , int cur,int deg, ref List<Tuple<int,int, int>> tmp, ref bool[,] dp)
        {
            if(deg == 45)
            {
                for (int k = 1; k <= cur; k++)
                {
                    dp[y, x + k] = true;
                }
                tmp.Add(Tuple.Create(y , x + cur, 180));
                for (int k = 1; k <= cur; k++)
                {
                    dp[y - k, x] = true;
                }
                tmp.Add(Tuple.Create(y - cur, x , 90));
            }
            else if(deg == 135)
            {
                for (int k = 1; k <= cur; k++)
                {
                    dp[y, x + k] = true;
                }
                tmp.Add(Tuple.Create(y , x + cur, 180));
                for (int k = 1; k <= cur; k++)
                {
                    dp[y + k, x] = true;
                }
                tmp.Add(Tuple.Create(y + cur, x  , 270));
            }
            else if (deg == 225)
            {
                for (int k = 1; k <= cur; k++)
                {
                    dp[y, x - k] = true;
                }
                tmp.Add(Tuple.Create(y , x - cur, 0));
                for (int k = 1; k <= cur; k++)
                {
                    dp[y + k, x] = true;
                }
                tmp.Add(Tuple.Create(y + cur, x, 270));
            }
            else
            {
                for (int k = 1; k <= cur; k++)
                {
                    dp[y, x - k] = true;
                }
                tmp.Add(Tuple.Create(y , x - cur, 0));
                for (int k = 1; k <= cur; k++)
                {
                    dp[y - k, x] = true;
                }
                tmp.Add(Tuple.Create(y - cur, x , 90));
            }

        }

        public static void ee(int x, int y, int cur, int deg, ref List<Tuple<int, int, int>> tmp, ref bool[,] dp)
        {
            if (deg == 0)
            {
                for (int k = 1; k <= cur; k++)
                {
                    dp[y + k, x - k] = true;
                }
                tmp.Add(Tuple.Create(y + cur, x - cur, 225));
                for (int k = 1; k <= cur; k++)
                {
                    dp[y - k, x - k] = true;
                }
                tmp.Add(Tuple.Create(y - cur, x - cur, 315));
            }
            else if (deg == 90)
            {
                for (int k = 1; k <= cur; k++)
                {
                    dp[y-k, x - k] = true;
                }
                tmp.Add(Tuple.Create(y-cur, x - cur, 315));
                for (int k = 1; k <= cur; k++)
                {
                    dp[y - k, x+k] = true;
                }
                tmp.Add(Tuple.Create(y - cur, x+cur, 45));
            }
            else if (deg == 180)
            {
                for (int k = 1; k <= cur; k++)
                {
                    dp[y-k, x + k] = true;
                }
                tmp.Add(Tuple.Create(y-cur, x + cur, 45));
                for (int k = 1; k <= cur; k++)
                {
                    dp[y + k, x+k] = true;
                }
                tmp.Add(Tuple.Create(y + cur, x+cur, 135));
            }
            else
            {
                for (int k = 1; k <= cur; k++)
                {
                    dp[y + k, x + k] = true;
                }
                tmp.Add(Tuple.Create(y + cur, x + cur, 135));
                for (int k = 1; k <= cur; k++)
                {
                    dp[y + k, x - k] = true;
                }
                tmp.Add(Tuple.Create(y + cur, x - cur, 225));
            }

        }

    }

    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.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 arr = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int count = 0;

            var dp = new bool[501,501];

            dfs(0,250,250,0,ref dp, arr);

            //var list = new List<Tuple<int,int,int>>();
            //for (int i = 0; i < n; i++)
            //{
            //    int cur = arr[i];
            //    var tmp = new List<Tuple<int,int, int>>();
            //    if(i==0)
            //    {
            //        for(int j=0; j<cur; j++)
            //        {
            //            dp[250-j,250] = true;
            //        }
            //        tmp.Add(Tuple.Create( 250-(cur-1),250, 90));
            //    }
            //    else if(i%2==1)
            //    {
            //        for (int j = 0; j < list.Count(); j++)
            //        {
            //            int y = list[j].Item1;
            //            int x = list[j].Item2;
            //            int deg = list[j].Item3;
            //            ee(x, y, cur, deg, ref tmp, ref dp);
            //        }

            //    }
            //    else
            //    {
            //        for (int j = 0; j < list.Count(); j++)
            //        {
            //            int y = list[j].Item1;
            //            int x = list[j].Item2;
            //            int deg = list[j].Item3;
            //            VH(x, y, cur, deg, ref tmp, ref dp);
            //        }
            //    }

            //    list = new List<Tuple<int, int, int>>(tmp);
            //}

            for (int i = 0; i < 501; i++)
            {
                for (int j = 0; j < 501; j++)
                {
                    if (dp[i, j]) count++;
                }
            }

            Console.WriteLine(count);

            //Console.WriteLine();

        }

        public static void dfs(int depth,int y, int x ,int deg,  ref bool[,] dp, int[] arr)
        {
            if (depth == arr.Length) return;
            int cur = arr[depth];

            if(depth == 0)
            {
                for (int j = 0; j < cur; j++)
                {
                    dp[250 - j, 250] = true;
                }
                dfs(depth+1, 250 - (cur - 1), 250, 90 , ref dp, arr);
            }
            else if(depth % 2 == 1)
            {
                if (deg == 0)
                {
                    for (int k = 1; k <= cur; k++)
                    {
                        dp[y + k, x - k] = true;
                    }

                    dfs(depth + 1, y + cur, x - cur, 225, ref dp, arr);
                    for (int k = 1; k <= cur; k++)
                    {
                        dp[y - k, x - k] = true;
                    }

                    dfs(depth + 1, y - cur, x - cur, 315, ref dp, arr);
                }
                else if (deg == 90)
                {
                    for (int k = 1; k <= cur; k++)
                    {
                        dp[y - k, x - k] = true;
                    }

                    dfs(depth + 1, y - cur, x - cur, 315, ref dp, arr);
                    for (int k = 1; k <= cur; k++)
                    {
                        dp[y - k, x + k] = true;
                    }

                    dfs(depth + 1, y - cur, x + cur, 45, ref dp, arr);
                }
                else if (deg == 180)
                {
                    for (int k = 1; k <= cur; k++)
                    {
                        dp[y - k, x + k] = true;
                    }

                    dfs(depth + 1, y - cur, x + cur, 45, ref dp, arr);
                    for (int k = 1; k <= cur; k++)
                    {
                        dp[y + k, x + k] = true;
                    }

                    dfs(depth + 1, y + cur, x + cur, 135, ref dp, arr);
                }
                else
                {
                    for (int k = 1; k <= cur; k++)
                    {
                        dp[y + k, x + k] = true;
                    }

                    dfs(depth + 1, y + cur, x + cur, 135, ref dp, arr);
                    for (int k = 1; k <= cur; k++)
                    {
                        dp[y + k, x - k] = true;
                    }

                    dfs(depth + 1, y + cur, x - cur, 225, ref dp, arr);
                }
            }
            else
            {
                if (deg == 45)
                {
                    for (int k = 1; k <= cur; k++)
                    {
                        dp[y, x + k] = true;
                    }

                    dfs(depth + 1, y, x + cur, 180, ref dp, arr);
                    for (int k = 1; k <= cur; k++)
                    {
                        dp[y - k, x] = true;
                    }

                    dfs(depth + 1, y - cur, x, 90, ref dp, arr);
                }
                else if (deg == 135)
                {
                    for (int k = 1; k <= cur; k++)
                    {
                        dp[y, x + k] = true;
                    }
                    dfs(depth + 1, y, x + cur, 180, ref dp, arr);
                    for (int k = 1; k <= cur; k++)
                    {
                        dp[y + k, x] = true;
                    }

                    dfs(depth + 1, y + cur, x, 270, ref dp, arr);
                }
                else if (deg == 225)
                {
                    for (int k = 1; k <= cur; k++)
                    {
                        dp[y, x - k] = true;
                    }

                    dfs(depth + 1, y, x - cur, 0, ref dp, arr);
                    for (int k = 1; k <= cur; k++)
                    {
                        dp[y + k, x] = true;
                    }
                    dfs(depth + 1, y + cur, x, 270, ref dp, arr);
                }
                else
                {
                    for (int k = 1; k <= cur; k++)
                    {
                        dp[y, x - k] = true;
                    }
                    dfs(depth + 1, y, x - cur, 0, ref dp, arr);
                    for (int k = 1; k <= cur; k++)
                    {
                        dp[y - k, x] = true;
                    }
                    dfs(depth + 1, y - cur, x, 90, ref dp, arr);
                }

            }

        }

        public static void VH(int x , int y , int cur,int deg, ref List<Tuple<int,int, int>> tmp, ref bool[,] dp)
        {
            if(deg == 45)
            {
                for (int k = 1; k <= cur; k++)
                {
                    dp[y, x + k] = true;
                }
                tmp.Add(Tuple.Create(y , x + cur, 180));
                for (int k = 1; k <= cur; k++)
                {
                    dp[y - k, x] = true;
                }
                tmp.Add(Tuple.Create(y - cur, x , 90));
            }
            else if(deg == 135)
            {
                for (int k = 1; k <= cur; k++)
                {
                    dp[y, x + k] = true;
                }
                tmp.Add(Tuple.Create(y , x + cur, 180));
                for (int k = 1; k <= cur; k++)
                {
                    dp[y + k, x] = true;
                }
                tmp.Add(Tuple.Create(y + cur, x  , 270));
            }
            else if (deg == 225)
            {
                for (int k = 1; k <= cur; k++)
                {
                    dp[y, x - k] = true;
                }
                tmp.Add(Tuple.Create(y , x - cur, 0));
                for (int k = 1; k <= cur; k++)
                {
                    dp[y + k, x] = true;
                }
                tmp.Add(Tuple.Create(y + cur, x, 270));
            }
            else
            {
                for (int k = 1; k <= cur; k++)
                {
                    dp[y, x - k] = true;
                }
                tmp.Add(Tuple.Create(y , x - cur, 0));
                for (int k = 1; k <= cur; k++)
                {
                    dp[y - k, x] = true;
                }
                tmp.Add(Tuple.Create(y - cur, x , 90));
            }

        }

        public static void ee(int x, int y, int cur, int deg, ref List<Tuple<int, int, int>> tmp, ref bool[,] dp)
        {
            if (deg == 0)
            {
                for (int k = 1; k <= cur; k++)
                {
                    dp[y + k, x - k] = true;
                }
                tmp.Add(Tuple.Create(y + cur, x - cur, 225));
                for (int k = 1; k <= cur; k++)
                {
                    dp[y - k, x - k] = true;
                }
                tmp.Add(Tuple.Create(y - cur, x - cur, 315));
            }
            else if (deg == 90)
            {
                for (int k = 1; k <= cur; k++)
                {
                    dp[y-k, x - k] = true;
                }
                tmp.Add(Tuple.Create(y-cur, x - cur, 315));
                for (int k = 1; k <= cur; k++)
                {
                    dp[y - k, x+k] = true;
                }
                tmp.Add(Tuple.Create(y - cur, x+cur, 45));
            }
            else if (deg == 180)
            {
                for (int k = 1; k <= cur; k++)
                {
                    dp[y-k, x + k] = true;
                }
                tmp.Add(Tuple.Create(y-cur, x + cur, 45));
                for (int k = 1; k <= cur; k++)
                {
                    dp[y + k, x+k] = true;
                }
                tmp.Add(Tuple.Create(y + cur, x+cur, 135));
            }
            else
            {
                for (int k = 1; k <= cur; k++)
                {
                    dp[y + k, x + k] = true;
                }
                tmp.Add(Tuple.Create(y + cur, x + cur, 135));
                for (int k = 1; k <= cur; k++)
                {
                    dp[y + k, x - k] = true;
                }
                tmp.Add(Tuple.Create(y + cur, x - cur, 225));
            }

        }

    }

    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;
using System.Collections.Generic;
using System.Linq;

namespace Problem{

    public class Solution{

        public void Main(){

            int n = int.Parse(Console.ReadLine());
             if(n == 1){
                 Console.WriteLine(n);
             }else{
                 Console.WriteLine((n*2 - 3)*(n*2 - 3) + 4);
             }
        }
    }
}


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

namespace ConsoleApp33
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int[] mas = new int[n];
            int ans = (n + n - 1) * (n + n - 1);
            mas[1] = 1;
            for (int i = 2; i < n; i++)
            {
                mas[i] = mas[i - 1] + i;
            }
            Console.WriteLine(ans - (mas[mas.Length - 1] * 4));
        }
    }
}


using System;

namespace C
{
	class Program
	{
		static void Main()
		{
			var s = Console.ReadLine();
			var ss = s.Split(' ');
			var r = int.Parse(ss[0]);
			var h = int.Parse(ss[1]);

			Console.WriteLine((h / r) * 2 + (h % r >= (double) r / 2 ? 2 : 1));
		}
	}
}