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

namespace AlgoTraining.Codeforces._8VCVentureCup2016
{

    class FastScanner : StreamReader
    {
        private string[] _line;
        private int _iterator;

        public FastScanner(Stream stream) : base(stream)
        {
            _line = null;
            _iterator = 0;
        }
        public int NextInt()
        {
            if (_line == null || _iterator >= _line.Length)
            {
                _line = base.ReadLine().Split(' ');
                _iterator = 0;
            }
            if (_line.Count() == 0) throw new IndexOutOfRangeException("Input string is empty");
            return Convert.ToInt32(_line[_iterator++]);
        }
        public long NextLong()
        {
            if (_line == null || _iterator >= _line.Length)
            {
                _line = base.ReadLine().Split(' ');
                _iterator = 0;
            }
            if (_line.Count() == 0) throw new IndexOutOfRangeException("Input string is empty");
            return Convert.ToInt64(_line[_iterator++]);
        }
    }
    class XorEquationC
    {
        public static void Main(string[] args)
        {
            using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
            using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
            {
                long s = fs.NextLong(), x = fs.NextLong();
                if ((s - x) % 2 != 0)
                {
                    writer.WriteLine(0);
                    return;
                }
                long and = (s - x) / 2;
                string xorStr = Convert.ToString(x, 2), andStr = Convert.ToString(and, 2);
                int onesNum = 0;
                foreach (char c in xorStr)
                {
                    if (c == '1') onesNum++;
                }
                writer.WriteLine(Math.Pow(2, onesNum) - (and == 0 ? 2 : 0));
            }
        }
    }
}


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

namespace AlgoTraining.Codeforces._8VCVentureCup2016
{

    class FastScanner : StreamReader
    {
        private string[] _line;
        private int _iterator;

        public FastScanner(Stream stream) : base(stream)
        {
            _line = null;
            _iterator = 0;
        }
        public int NextInt()
        {
            if (_line == null || _iterator >= _line.Length)
            {
                _line = base.ReadLine().Split(' ');
                _iterator = 0;
            }
            if (_line.Count() == 0) throw new IndexOutOfRangeException("Input string is empty");
            return Convert.ToInt32(_line[_iterator++]);
        }
        public long NextLong()
        {
            if (_line == null || _iterator >= _line.Length)
            {
                _line = base.ReadLine().Split(' ');
                _iterator = 0;
            }
            if (_line.Count() == 0) throw new IndexOutOfRangeException("Input string is empty");
            return Convert.ToInt64(_line[_iterator++]);
        }
    }
    class XorEquationC
    {
        public static void Main(string[] args)
        {
            using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
            using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
            {
                long s = fs.NextLong(), x = fs.NextLong();
                if (s < x || (s - x) % 2 != 0)
                {
                    writer.WriteLine(0);
                    return;
                }
                long and = (s - x) / 2;
                string xorStr = Convert.ToString(x, 2), andStr = Convert.ToString(and, 2);
                int onesNum = 0;
                foreach (char c in xorStr)
                {
                    if (c == '1') onesNum++;
                }
                int p = xorStr.Length - 1;
                for (int i = andStr.Length - 1; i >= 0; i--, p--)
                {
                    if (andStr[i] == '1' && xorStr[p] == '1')
                    {
                        writer.WriteLine(0);
                        return;
                    }
                }
                writer.WriteLine(Math.Pow(2, onesNum) - (and == 0 ? 2 : 0));
            }
        }
    }
}


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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public void Solve()
    {
        long n = ReadLong();
        long m = ReadLong();

        var dp = new long[2];
        dp[0] = 1;
        long p = 1;
        for (int i = 0; p <= n; i++, p <<= 1)
        {
            var ndp = new long[2];
            if ((m >> i & 1) == 1)
            {
                if ((n >> i & 1) == 1)
                {
                    ndp[0] = 2 * dp[0];
                }
                else
                {
                    ndp[1] = 2 * dp[1];
                }
            }
            else
            {
                if ((n >> i & 1) == 1)
                {
                    ndp[0] = dp[1];
                    ndp[1] = dp[1];
                }
                else
                {
                    ndp[0] = dp[0];
                    ndp[1] = dp[0];
                }
            }
            dp = ndp;
        }

        if (n == m)
            dp[0] -= 2;
        Write(dp[0]);
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
            new Solver().Solve();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
#if DEBUG
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

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


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

namespace contest
{

    class contest
    {

        static void Main(string[] args)
        {

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

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

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

            long n = long.Parse(Console.ReadLine());

            long count = 0;

            bool first = true;
            long tmp = n;
            while (tmp>1)
            {
                count++;
                tmp = (tmp + 1) / 2 ;
                if(first)
                {
                    tmp += (n % 2);
                    first = false;
                }

            }

            Console.WriteLine(count);

            //Console.WriteLine(ans.ToString(System.Globalization.CultureInfo.InvariantCulture));

        }

    }

}


using System;
using System.Collections.Generic;
using System.Collections;
using System.Globalization;
using System.IO;
using System.Linq;
//Гавно код недорешенный
public class Source
{
    public void Program()
    {
    }
    long fib(int x)
    {
        long f1 = 1, f2 = 1, cur = 1;
        for (int i = 3; i <= 1000000; i++)
        {
            f1 = f2;
            f2 = cur;
            cur = f1 + f2;
            if (cur < 0)
                break;
            if (cur >= x)
                return i;
        }
        return -1;
    }
    void Read()
    {
        int x = ri();
        if(x==2)
        {
            writeLine(1);
            return;
        }
        if (x == 3)
        {
            writeLine(2);
            return;
        }
        writeLine(fib(x)-3);
    }

    #region hide it
    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
            reader = new StreamReader(Console.OpenStandardInput());
            writer = new StreamWriter(Console.OpenStandardOutput());
            //reader = new StreamReader("input.txt");
            //writer = new StreamWriter("output.txt");
#endif
        var source = new Source();
        source.Read();
        source.Program();

        /* try
         {
             new Source().Program();
         }
         catch (Exception ex)
         {
 #if DEBUG
             Console.WriteLine(ex);
 #else
             throw;
 #endif
         }*/
        reader.Close();
        writer.Close();
    }

    #endregion

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

    #region Methods
    #region DSU
    public void MakeSet(int[] poi)
    {
        for (int i = 0; i < poi.Length; i++)
        {
            poi[i] = i;
        }
    }
    public int Find(int x, int[] poi)
    {
        if (poi[x] == x) return x;
        return poi[x] = Find(poi[x], poi);
    }
    Random rand = new Random();
    public void Unite(int x, int y, int[] poi)
    {
        y = Find(y, poi);
        x = Find(x, poi);
        if (rand.Next() % 2 == 0)
            Swap(ref x, ref y);
        poi[x] = y;
    }
    #endregion

    class Deque<T>
    {
        T[] array;
        int start, length;
        public Deque()
        {
            start = 0; length = 0; array = new T[1];
        }
        public T this[int index] { get { return array[(start + index) % array.Length]; } set { array[(start + index) % array.Length] = value; } }
        int last { get { return (start + length) % array.Length; } }
        /// <summary>
        /// ÃÆÃ¢â¬ËÃâÃÂÃÆÃ¢â¬ËÃÂ¢Ã¢âÂ¬Ã
        /// </summary>
        public T PeekFirst()
        {
            return array[start];
        }
        public int Count { get { return length; } }
        /// <summary>
        /// ÃÆÃÂÃâÃÂºÃÆÃÂÃâÃÂ¾ÃÆÃÂÃâÃÂ½ÃÆÃÂÃâÃÂµÃÆÃ¢â¬ËÃÂ¢Ã¢âÂ¬  ÃÆÃÂÃâÃÂ±ÃÆÃÂÃâÃÂµÃÆÃÂÃâÃÂ· ÃÆÃ¢â¬ËÃâ Ã¢â¬â¢ÃÆÃÂÃâÃÂ´ÃÆÃÂÃâÃÂ°ÃÆÃÂÃâÃÂ»ÃÆÃÂÃâÃÂµÃÆÃÂÃâÃÂ½ÃÆÃÂÃâÃÂ¸ÃÆÃ¢â¬ËÃâÃÂ
        /// </summary>
        public T PeekLsat()
        {
            return array[last];
        }
        public T PopLast()
        {
            if (length == 0)
                throw new IndexOutOfRangeException("OutOfRange");
            length--;
            return array[last];
        }
        public T PopFirst()
        {
            if (length == 0)
                throw new IndexOutOfRangeException("OutOfRange");
            length--;
            if (start >= array.Length - 1) start = 0; else start++;
            return array[start - 1 < 0 ? array.Length - 1 : start - 1];
        }
        public void AddFirst(T value)
        {
            IncreaseAndInspection();
            if (start <= 0) start = array.Length - 1; else start--;
            array[start] = value;
            length++;
        }
        public void AddLast(T value)
        {
            IncreaseAndInspection();
            array[last] = value;
            length++;
        }
        bool overflow { get { return length == array.Length; } }
        void IncreaseAndInspection()
        {
            if (overflow)
                increase();

        }
        void increase()
        {
            T[] array2 = new T[array.Length * 2];
            for (int i = 0; i < array.Length; i++)
            {
                int pos = (start + i) % array.Length;
                array2[i] = array[pos];
            }
            array = array2;
            start = 0;
            array2 = null;
        }
        public void Clear()
        {
            start = 0; length = 0; array = new T[1];
        }
    }
    class Heap<T>
    {
        Comparison<T> ic;
        List<T> storage = new List<T>();
        public Heap(Comparison<T> ic)
        {
            this.ic = ic;
        }
        public void Add(T element)
        {
            storage.Add(element);
            int pos = storage.Count - 1;
            while (pos != 0 && ic(storage[((int)(pos - 1) >> 1)], element) > 0)
            {
                Swap(storage, pos, ((int)(pos - 1) / 2));
                pos = ((int)(pos - 1) / 2);
            }
        }
        public T Pop()
        {
            T t = storage[0];
            Swap(storage, 0, storage.Count - 1);
            int pos = 0;
            storage.RemoveAt(storage.Count - 1);
            if (Count > 0)
                while (true)
                {
                    T my = storage[pos];
                    if (pos * 2 + 1 >= Count)
                        break;
                    T left = storage[pos * 2 + 1];
                    if (pos * 2 + 2 >= Count)
                    {
                        if (ic(left, my) < 0)
                        {
                            Swap(storage, pos, pos * 2 + 1);
                            pos = pos * 2 + 1;
                        }
                        break;
                    }
                    T right = storage[pos * 2 + 2];
                    if (ic(left, my) < 0 || ic(right, my) < 0)
                    {
                        if (ic(left, right) < 0)
                        {
                            Swap(storage, pos, pos * 2 + 1);
                            pos = pos * 2 + 1;
                        }
                        else
                        {

                            Swap(storage, pos, pos * 2 + 2);
                            pos = pos * 2 + 2;
                        }
                    }
                    else break;
                }
            return t;
        }

        public void Clear()
        {
            storage.Clear();
        }
        /// <summary>
        /// ÃÆÃÂÃâÃÂ±ÃÆÃÂÃâÃÂµÃÆÃÂÃâÃÂ· ÃÆÃ¢â¬ËÃâ Ã¢â¬â¢ÃÆÃÂÃâÃÂ´ÃÆÃÂÃâÃÂ°ÃÆÃÂÃâÃÂ»ÃÆÃÂÃâÃÂµÃÆÃÂÃâÃÂ½ÃÆÃÂÃâÃÂ¸ÃÆÃ¢â¬ËÃâÃÂ
        /// </summary>
        /// <returns></returns>
        public T Peek()
        {
            return storage[0];
        }
        public int Count
        {
            get { return storage.Count; }
        }
        //void RemoveLast, Size, peeklast, add
    }
    static void Swap<T>(ref T lhs, ref T rhs)
    {
        T temp;
        temp = lhs;
        lhs = rhs;
        rhs = temp;
    }
    static void Swap<T>(T[] a, int l, int r)
    {
        T temp;
        temp = a[l];
        a[l] = a[r];
        a[r] = temp;
    }
    static void Swap<T>(List<T> a, int l, int r)
    {
        T temp;
        temp = a[l];
        a[l] = a[r];
        a[r] = temp;
    }

    bool outregion(long y, long x, long n, long m)
    {
        if (x < 0 || x >= m || y < 0 || y >= n)
            return true;
        return false;
    }
    static void initlist<T>(ref List<T>[] list, int n)
    {
        list = new List<T>[n];
        for (int i = 0; i < n; i++)
            list[i] = new List<T>();
    }
    static void newarray<T>(ref T[][] array, int n, int m)
    {
        array = new T[n][];
        for (int i = 0; i < n; i++)
            array[i] = new T[m];
    }
    static void newarray<T>(ref T[] array, int n)
    {
        array = new T[n];
    }
    static void fill<T>(T[] array, T value)
    {
        for (int i = 0; i < array.Length; i++)
            array[i] = value;
    }
    static void fill<T>(T[][] array, T value)
    {
        for (int i = 0; i < array.Length; i++)
            for (int j = 0; j < array[i].Length; j++)
                array[i][j] = value;
    }
    public bool NextPermutation<T>(T[] b, Comparison<T> ic)
    {
        for (int j = b.Length - 2; j >= 0; j--)
        {
            if (ic(b[j], b[j + 1]) < 0)
            {
                for (int l = b.Length - 1; l >= 0; l--)
                {
                    if (ic(b[l], b[j]) > 0)
                    {
                        Swap(b, j, l);
                        Array.Reverse(b, j + 1, b.Length - (j + 1));
                        return true;
                    }
                }
            }
        }
        return false;
    }
    int[,] step8 = new int[,]
    {
        {-1,0 },
        {1,0 },
        {0,-1 },
        {0,1 },
        {1,1 },
        {-1,1 },
        {-1,-1 },
        {1,-1 },
    };
    int[,] step4 = new int[,]
    {
        {-1,0 },
        {1,0 },
        {0,-1 },
        {0,1 },
    };
    struct Vector2
    {
        public double x;
        public double y;
        public Vector2(double x, double y)
        {
            this.x = x;
            this.y = y;
        }
        public double Dist(Vector2 to)
        {
            return Math.Sqrt(Math.Abs(Math.Pow(to.x - x, 2)) + Math.Abs(Math.Pow(to.y - y, 2)));
        }
        public static bool operator ==(Vector2 left, Vector2 right) { return left.x == right.x && left.y == right.y; }
        public static bool operator !=(Vector2 left, Vector2 right) { return left.x != right.x || left.y != right.y; }
    }
    #endregion
    #endregion

 }


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

class Program
{
    static void Main(string[] args)
    {
        long n = RL();
        Console.Write(1 + Solve(n - 2, 0));
    }

    private static long Solve(long x1, long x2)
    {
        if (x1 == 0) return 0;
        if (x1 == 1) return 1;

        if (x2 == 0)
        {
            x1--;
            return 1 + Solve(x1 / 2, x1 % 2);
        }

        if (x2 == 1)
        {
            x1--;
            x1--;
            return 1 + Solve(1 + (x1 / 2), x1 % 2);
        }

        return 0;
    }

    private const int Mod = 1000000000 + 7;

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

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

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

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

        return g;
    }

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

        return matrix;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        return s.ToArray();
    }

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

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

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

        return s;
    }

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

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

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

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

        return s.ToArray();
    }

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

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

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

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

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

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

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

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

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

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


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

namespace Hack
{

    class Program
    {
      static int Gcd (int a , int b)
        {
            if (b == 0) return a;
            return Gcd(b, a % b);
        }
        static int Lcm (int a , int b)
        {
            return (a * b) / Gcd(a, b);
        }

        static void Main(string[] args)
        {
            // Console.ForegroundColor = ConsoleColor.Green;
            string[] s = Console.ReadLine().Split(' ');
            int x = int.Parse(s[0]), y = int.Parse(s[1]), a = int.Parse(s[2]), b = int.Parse(s[3]);
            int k = Lcm(x, y);
            int count = 0;
            for (; a <= b; a++)
            {
                if (a % k == 0)
                    count++;
            }
            Console.WriteLine(count);
            //  Console.ResetColor();
        }

    }
}


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

namespace FixedPoints
{
    class TheWall
    {
        static void Main(string[] args)
        {
            int ou = 0;
            int[] num = new int[4];
            string input = Console.ReadLine();
            string[] inarr = input.Split(' ');

            for (int x = 0; x < 4; x++)
            {
                num[x] = int.Parse(inarr[x]);
            }

            if (num[0] <= num[3] && num[1] <= num[3])
            {
                int multi = num[0] * num[1];
                int max = 0, min = 0;

                if (num[0] > num[1])
                {
                    max = num[0];
                    min = num[1];
                }
                else if (num[1] > num[0])
                {
                    max = num[1];
                    min = num[0];
                }
                else
                {
                    max = num[0];
                    min = num[0];
                }

                int counter = 1;
                int lcm = max;
                while (lcm % min != 0 && min != max)
                {
                    lcm = max * counter;
                    counter++;
                }

                int temp = lcm;
                counter = 2;
                while (temp <= num[3])
                {
                    if (temp >= num[2])
                        ou++;
                    temp = lcm * counter;
                    counter++;
                }
            }
            Console.WriteLine(ou);
        }
    }
}


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

namespace FixedPoints
{
    class TheWall
    {
        static void Main(string[] args)
        {
            int output = 0;
            int[] num = new int[4];
            string input = Console.ReadLine();
            string[] inarr = input.Split(' ');

            for (int x = 0; x < 4; x++)
            {
                num[x] = int.Parse(inarr[x]);
            }

            if (num[0] <= num[3] && num[1] <= num[3])
            {
                int multi = num[0] * num[1];
                int max = 0, min = 0;

                if (num[0] > num[1])
                {
                    max = num[0];
                    min = num[1];
                }
                else if (num[1] > num[0])
                {
                    max = num[1];
                    min = num[0];
                }

                int counter = 1;
                int lcm = min;
                while (lcm % min != 0 || lcm == min)
                {
                    lcm = max * counter;
                    counter++;
                }
                int temp = lcm;
                int ou = 0;
                counter = 2;
                while (temp <= num[3])
                {
                    if (temp >= num[2])
                        ou++;
                    temp = lcm * counter;
                    counter++;
                }

                Console.WriteLine(ou);
            }
        }
    }
}


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

namespace Op
{
    class Program
    {
        public static int Main(string[] args)
        {
            string[] line =Console.ReadLine().Split();
            long x,y,a,b,ans=0;
            x=long.Parse(line[0]);
            y=long.Parse(line[1]);
            a=long.Parse(line[2]);
            b=long.Parse(line[3]);
            for(long i=a;i<=b;i++){
                if (i%x==0&&i%y==0) {ans++; }
            }
            Console.WriteLine(ans);
            //Console.ReadKey();
            return 0;
        }
    }
    }


using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        var _ = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int x = _[0], y = _[1], a = _[2], b = _[3];
        var ans = new HashSet<int>();
        int c = 0;
        for (int i = (int)Math.Ceiling(a / (double)x) * x, j = (int)Math.Ceiling(a / (double)y) * y;
            i <= b || j <= b; i += x, j += y)
        {
            if (!ans.Contains(i))
            {
                ans.Add(i);
            }
            else
            {
                c++;
            }
            if (!ans.Contains(j))
            {
                ans.Add(j);
            }
            else
            {
                c++;
            }
        }
        Console.WriteLine(c);
    }
}


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

namespace _340A_The_Wall
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int x = int.Parse(str[0]);
            int y = int.Parse(str[1]);
            long a = long.Parse(str[2]);
            long b = long.Parse(str[3]);
            List<long> lijst_x_y = new List<long>();
            int divisor = GCD(x, y);
            long brick = divisor;

            while (brick < a)
                brick += divisor;

            while (brick >= a && brick <= b)
            {
                if (brick % x == 0 && brick % y == 0)
                {
                    lijst_x_y.Add(brick);
                }

                brick += divisor;
            }

            Console.WriteLine(lijst_x_y.Count());

        }

        static int GCD(int x, int y)
        {
            if (x == 1 || y == 1)
                return 1;
            else if (x % 2 == 0 && y % 2 == 0)
                return 2 * GCD(x / 2, y / 2);
            else if (x % 2 == 0)
                return GCD(x / 2, y);
            else if (y % 2 == 0)
                return GCD(x, y / 2);
            else
                return GCD((int)Math.Abs(x - y), (int)Math.Min(x, y));
        }
    }
}


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

namespace _340A_The_Wall
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int x = int.Parse(str[0]);
            int y = int.Parse(str[1]);
            long a = long.Parse(str[2]);
            long b = long.Parse(str[3]);
            int counter = 0;
            int Colour = x * y / Stein_GCD(x, y);
            long brick = Colour;

            while (brick < a)
                brick += Colour;

            while (brick >= a && brick <= b)
            {
                counter++;
                brick += Colour;
            }

            Console.WriteLine(counter);
        }

        static int Euclid_GCD(int a, int b)
        {
            if (a == 0)
                return b;
            else
            {
                while (a != 0 && b != 0)
                {
                    while (a >= b)
                        a -= b;
                    while (b >= a && a != 0)
                        b -= a;
                }

                return Math.Max(a, b);
            }
        }

        static int Stein_GCD(int a, int b)
        {
            if (a == 0)
                return b;
            else if (b == 0)
                return a;
            else
            {
                if (a % 2 == 0 && b % 2 == 0)
                    return 2 * Stein_GCD(a / 2, b / 2);
                else if (a % 2 == 0)
                    return Stein_GCD(a / 2, b);
                else if (b % 2 == 0)
                    return Stein_GCD(a, b / 2);
                else
                    return Stein_GCD((int)Math.Abs(a - b), Math.Min(a, b));
            }
        }
    }
}


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

class Program
{
    static char[] SPACE = new[] { ' ' };

    static void Main(string[] args)
    {
#if DEBUG
        using (var input = new StreamReader("input.txt"))
        using (var output = new StreamWriter("output.txt"))
        {
            Console.SetIn(input);
            Console.SetOut(output);

            int n = 0;
            do
            {
                Console.WriteLine();
                Console.WriteLine("Sample {0}", ++n);
                Prog();
            } while (Console.ReadLine() == string.Empty);
        }
#else
            Prog();
#endif
    }

    static int __ptr = 0;
    static string[] __input;
    static int NextInt()
    {
        return int.Parse(__input[__ptr++]);
    }
    static long NextLong()
    {
        return long.Parse(__input[__ptr++]);
    }
    static void ReadTokens(int n)
    {
        __ptr = 0;
        __input = Console.ReadLine().Split(SPACE, n);
    }

    //

    static void Prog()
    {
        ReadTokens(1);
        int n = NextInt();
        var s = Console.ReadLine();

        int FS = 0, SF = 0;
        for (int i = 0; i < n - 1; i++)
        {
            if (s[i] == 'F' && s[i + 1] == 'S') SF++;
            else if (s[i] == 'S' && s[i + 1] == 'F') SF++;
        }

        Console.WriteLine(SF > FS ? "YES" : "NO");
    }
}


using System;

namespace example
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            String str = Console.ReadLine();
            int countF = 0;
            int countS = 0;
            for(int i=0;i<str.Length-2;i++)
            {
                if(str[i]=='F'&&str[i+1]=='S')
                {
                    countF++;
                }
                else if(str[i]=='S'&&str[i+1]=='F')
                {
                    countS++;
                }
            }

            if(countF<countS)
            Console.WriteLine("YES");
            else
            Console.WriteLine("NO");
        }
    }
}


using System.Linq;
using System;

namespace cs
{
    class Program
    {
        static void Main(string[] args)
        {
          int n = Convert.ToInt32(Console.ReadLine());
          if(n % 2 == 0) {
            Console.WriteLine("Mahmoud")
          } else {
            Console.WriteLine("Ehab");
          }
        }
    }
}


using System;
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write(int.Parse(Console.ReadLine()) % 2 == 0?"Mahmoud": "Ehab");
        }
    }
}


using System;

namespace AllTasksApplication
{
    class Program
    {
        static int Mahmood = 2;
        static int Ehab = 3;

        static int failed(int dig, int plr)
        {

            if (plr == Mahmood)
            {
                for (int i = plr; i <= dig; i+=2)
                {
                    if (dig % i == 0)
                    {
                        return failed(dig/i,Ehab);
                    }
                }
                return plr;
            }
            else
            {
                for (int i = plr;i<=dig;i+=2)
                {
                    if (dig % i == 0)
                    {
                        return failed(dig/i,Mahmood);
                    }
                }
                return plr;
            }
        }

        static void Main(string[] args)
        {
            //mahmood - true - четный - 2
            //ehab - false - нечетный - 3
            int dig = int.Parse(Console.ReadLine());
            if (failed(dig, Mahmood) == Mahmood)
            {
                Console.WriteLine("Ehab");
            }
            else
            {
                Console.WriteLine("Mahmood");
            }

        }
    }
}


using System;

namespace CF959a
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}


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

namespace SortingProblems
{
    class Program
    {
        static void Main(string[] args)
        {
            int x1 = Convert.ToInt32(Console.ReadLine());
             int x2 = Convert.ToInt32(Console.ReadLine());
              int x3 = Convert.ToInt32(Console.ReadLine());
            List<int> list = new List<int>{x1,x2,x3};
            var sorted  = SortMerge(list);
            Console.WriteLine(Friend(sorted));
        }

        static int Friend(List<int> list)
        {
            return list.Last() - list.First();
        }
        static List<int> SortMerge(List<int> list)
        {
            if (list.Count <= 1) return list;
            List<int> left = new List<int>();
            List<int> right = new List<int>();

            for (int i = 0; i < list.Count / 2; i++)
            {
                left.Add(list[i]);
            }

            for (int i = list.Count / 2; i < list.Count; i++)
            {
                right.Add(list[i]);
            }

            left = SortMerge(left);
            right = SortMerge(right);
            return Merge(left, right);
        }

        static List<int> Merge(List<int> left, List<int> right)
        {
            List<int> merged = new List<int>();
            while (left.Count > 0 || right.Count > 0)
            {
                if (left.Count > 0 && right.Count > 0)
                {
                    if (left.First() <= right.First())
                    {
                        merged.Add(left.First());
                        left.Remove(left.First());
                    }
                    else
                    {
                        merged.Add(right.First());
                        right.Remove(right.First());
                    }
                }
                else if (left.Count > 0)
                {
                    merged.Add(left.First());
                    left.Remove(left.First());
                }
                else if (right.Count > 0)
                {
                    merged.Add(right.First());
                    right.Remove(right.First());
                }
            }
            return merged;
        }

    }
}


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

namespace SortingProblems
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> list = new List<int>();
            int length = Convert.ToInt32(Console.ReadLine());
            for (int i = 0; i < length; i++)
            {
                list.Add(Convert.ToInt32(Console.ReadLine()));
            }
            list.Sort();
            Console.WriteLine(Friend(list));

        }
}  }


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

namespace SortingAlgorithms
{
    class Program
    {
        static void Main(string[] args)
        {
            FriendMeeting();
        }
        public void FriendMeeting()
        {
            int count;
            int[] arr = Array.ConvertAll(Console.ReadLine().Split(' '), arrTemp => Convert.ToInt32(arrTemp));
            for (int i = 1; i < arr.Length; i++)
            {
                int next = arr[i];
                int j = i - 1;
                while (j >= 0 && arr[j] > next)
                {
                    arr[j + 1] = arr[j];
                    --j;
                }

                arr[j + 1] = next;
            }

            count = (arr[2] - arr[1]) + (arr[1] - arr[0]);
            Console.WriteLine(count);
        }

    }
}


using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int a;
            String b;
            a =int.Parse(b);
            Console.WriteLine(a);
            if ((a>2) && ((a - 2) % 2 == 0))
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
        }
    }
}


static void Main(string[] args)
        {
            int w = Int32.Parse(Console.ReadLine());
            if (w % 2 == 0) Console.WriteLine("YES");
            else Console.WriteLine("NO");
            Console.ReadKey();

        }


using System;

class Program
{
    static void Main(string[] args)
    {
        int w = Convert.ToInt32(Console.ReadLine());
        string a = "NO";
        if((w % 2 == 0)and(w!=2))
        {
            a = "YES";
        }
        Console.WriteLine(a);
    }
}


namespace check1
{
    class Program
    {
        static void Main(string[] args)
        {
            int i;
            Console.Write("Enter a Number : ");
            i = int.Parse(Console.ReadLine());
            if (i % 2 == 0 && i > 2)
            {
                Console.Write("YES");
                Console.Read();
            }
            else
            {
                Console.Write("NO");
                Console.Read();
            }
        }
    }
}


bool main()
{
	int w = Console.ReadLine();
	return w%2==0;
}


using System;

namespace CodeForces {
    public class Problem4A {
        public static void Main(string[] args) {
            int.TryParse(Console.ReadLine(), int a);
            Console.WriteLine(a % 2 == 0 ? "YES" : "NO");
        }
    }
}


int w;

            if (w % 2 == 0)
                Console.Write("YES");
            else Console.Write("NO");


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

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

	internal class Task
	{
		private int[] a;
		private int[] b;
		private int[] c;
		private int[] d;

		public void Solve(InputReader sr, TextWriter sw)
		{
			var input = sr.ReadArray(Int32.Parse);
			var n = input[0];
			var m = input[1];
			var cTesto = input[2];
			var dTesto = input[3];
			a = new int[m];
			b = new int[m];
			c = new int[m];
			d = new int[m];
			for (var i = 0; i < m; i++) {
				input = sr.ReadArray(Int32.Parse);
				a[i] = input[0];
				b[i] = input[1];
				c[i] = input[2];
				d[i] = input[3];
			}
			var dp = new int[n + 1, m + 1];
			for (var i = 1; i <= n; i++) {
				for (var j = 1; j <= m; j++) {
					for (var k = 1; k <= a[j - 1] / b[j - 1]; k++) {
						if (i - c[j - 1] * k >= 0) {
							dp[i, j] = Math.Max(dp[i, j], dp[i - c[j - 1] * k, j - 1] + k * d[j - 1]);
						}
					}
				}
			}
			var max = 0;
			for (var i = 0; i <= n; i++) {
				for (var j = 1; j <= m; j++) {
					max = Math.Max(dp[i, j] + ((n - i) / cTesto) * dTesto, max);
				}
			}
			sw.WriteLine(max);
		}
	}
}

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

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

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

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

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

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

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

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

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

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

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


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

namespace Buns
{
    class BunWithoutFiling
    {
        public int AllPastry { get; set; } //всего теста
        public int KindsFiling { get; set; } // видов начинки
        public int WithoutFiling { get; set; } // тесто на булки без начинки
        public int CostWithoutFiling { get; set; } // цена за булку без начинки

        public static int Calculation(BunWithoutFiling bunWF, List<Bun> buns)
        {
            int summa = 0;
            for (int i = 0; i < buns.Count; i++)
            {
                while (buns[i].NeedFiling <= buns[i].RemainFiling)
                {
                    summa = summa + buns[i].Cost;
                    buns[i].RemainFiling -= buns[i].NeedFiling;
                    bunWF.AllPastry -= buns[i].NeedPastry;
                    if (bunWF.AllPastry < buns[i].NeedPastry)
                    {
                        break;
                    }
                }
            }

            while (bunWF.AllPastry >= bunWF.WithoutFiling)
            {
                summa = summa + bunWF.CostWithoutFiling;
                bunWF.AllPastry -= bunWF.WithoutFiling;
            }

            return summa;
        }

    }

    class Bun
    {
        public int RemainFiling { get; set; } //осталось начинки для i-того вида булок
        public int NeedFiling { get; set; }// нужно начинки ан 1 булку
        public int NeedPastry { get; set; } // нужно теста на 1 булку
        public int Cost { get; set; } // цена за 1 булку
    }

    class Program
    {
        static void Main(string[] args)
        {
            string firstStr = Console.ReadLine();
            var first = firstStr.Split(' ');
            BunWithoutFiling bunWithout = new BunWithoutFiling
            {
                AllPastry = Convert.ToInt32(first[0]),
                KindsFiling = Convert.ToInt32(first[1]),
                WithoutFiling = Convert.ToInt32(first[2]),
                CostWithoutFiling = Convert.ToInt32(first[3])
            };

            List<Bun> bunsColl = new List<Bun>();
            for (int i = 0; i < bunWithout.KindsFiling; i++)
            {
                string str = Console.ReadLine();
                var str2 = str.Split(' ');

                bunsColl.Add(new Bun
                {
                    RemainFiling = Convert.ToInt32(str2[0]),
                    NeedFiling = Convert.ToInt32(str2[1]),
                    NeedPastry = Convert.ToInt32(str2[2]),
                    Cost = Convert.ToInt32(str2[3])
                });
            }

            Console.WriteLine( BunWithoutFiling.Calculation(bunWithout, bunsColl).ToString());
        }
    }
}


using System;
using System.Collections.Generic;

namespace A
{
    struct vec
    {
        public int x, y;
        public vec(int x, int y) { this.x = x; this.y = y; }
        public static vec operator +(vec a, vec b) { return new vec(a.x + b.x, a.y + b.y); }
        public static vec operator -(vec a, vec b) { return new vec(a.x - b.x, a.y - b.y); }
        public static bool operator ==(vec a, vec b) { return a.x == b.x && a.y == b.y; }
        public static bool operator !=(vec a, vec b) { return a.x != b.x || a.y != b.y; }
        public static vec FromConsole()
        {
            string[] s = Console.ReadLine().Split(new char[] { ' ' });
            return new vec(Convert.ToInt32(s[0]), Convert.ToInt32(s[1]));
        }
    }

    class Program
    {
        static bool IsReachable(vec target, string operate)
        {
            vec[] path = new vec[operate.Length + 1];
            for (int i = 0, n = operate.Length; i < n; ++i)
            {
                switch (operate[i])
                {
                    case 'U': path[i + 1] = path[i] + new vec(0, 1); break;
                    case 'D': path[i + 1] = path[i] + new vec(0, -1); break;
                    case 'L': path[i + 1] = path[i] + new vec(-1, 0); break;
                    case 'R': path[i + 1] = path[i] + new vec(1, 0); break;
                }
                if (path[i + 1] == target)
                    return true;
            }

            vec mod = path[operate.Length];
            if (mod.x != 0 || mod.y != 0)
            {
                for (int i = 0, n = operate.Length; i < n; ++i)
                {
                    vec diff = target - path[i];
                    if (mod.x == 0 && mod.y != 0)
                    {
                        if (diff.x == 0 && diff.y % mod.y == 0 && diff.y / mod.y >= 0)
                            return true;
                    }
                    else if (mod.x != 0 && mod.y == 0)
                    {
                        if (diff.x % mod.x == 0 && diff.y == 0 && diff.x / mod.x >= 0)
                            return true;
                    }
                    else
                    {
                        if (diff.x % mod.x == 0 && diff.y % mod.y == 0 && diff.x / mod.x == diff.y / mod.y && diff.x / mod.x >= 0)
                            return true;
                    }
                }
            }
            return false;
        }

        static void Main(string[] args)
        {
            vec target = vec.FromConsole();
            string operate = Console.ReadLine();
            Console.WriteLine(IsReachable(target, operate) ? "Yes" : "No");
        }
    }
}


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

namespace Issue_327A
{
    class Program
    {
        public static void Main(string[] args) {
            var numbers_count = IO.Read();
            var groups = ReadGroups(numbers_count);

            Console.WriteLine(CountOnes(groups));
        }

        private static int CountOnes(List<Pair> groups) {
            var isZerosGroupsFirst = groups[0].Value == 0;

            if (groups.Count == 1) {
                if (isZerosGroupsFirst)
                    return groups[0].Count;
                else
                    return groups[0].Count - 1;
            }

            var index = isZerosGroupsFirst ? 0 : 1;
            var max_zeros = 0;

            int end_index;
            int max_index_start = 0;
            int max_index_end = 0;

            while (index < groups.Count) {
                if (IsGroupGoal(groups, index)) {
                    var zeros = groups[index].Count + groups[index + 2].Count;
                    var ones  = groups[index + 1].Count;
                    var buff = zeros - ones;
                    end_index = index + 2;

                    // check if A + C + E is still more than lost of ones in [... A, B, C, D, E ...]
                    for (int i = index + 3; i < groups.Count; i += 2) {
                        // if no goal -> just stop
                        if (groups.Count <= (i + 1) && groups[i].Count > (buff + groups[i + 1].Count))
                            break;

                        zeros += groups[i + 1].Count;
                        buff +=  groups[i + 1].Count - groups[i].Count;
                        end_index = i + 1;
                    }

                    if (zeros > max_zeros) {
                        max_zeros = zeros;
                        max_index_start = index;
                        max_index_end = end_index;
                    }

                    index = end_index + 1;
                } else {
                    if (groups[index].Count > max_zeros) {
                        max_index_start = max_index_end = index;
                        max_zeros = groups[index].Count;
                    }

                    index++;
                }
            }

            var amount = 0;

            for (int i = 0; i < max_index_start; ++i) {
                if (groups[i].Value == 1)
                    amount += groups[i].Count;
            }

            for (int i = max_index_start; i <= max_index_end; i += 2) {
                amount += groups[i].Count;
            }

            for (int i = max_index_end + 1; i < groups.Count; ++i) {
                if (groups[i].Value == 1)
                    amount += groups[i].Count;
            }

            return amount;
        }

        // checks that inveted count of two nearest groups of zeroz more then lost ones
        private static bool IsGroupGoal(List<Pair> groups, int index) {
            return (groups.Count > index + 2) &&
                // if A + C group of zeros > B group of 1 in [... A, B, C ...]
                (groups[index].Count + groups[index + 2].Count) > (groups[index + 1].Count);
        }

        private static List<Pair> ReadGroups(int numbers_count) {
            var value  = IO.Read();
            var groups = new List<Pair>();
            var group  = new Pair {
                Value  = value,
                Count  = 1
            };

            for (int i = 1; i < numbers_count; ++i) {
                value = IO.Read();

                if (value == group.Value) {
                    group.Count++;
                } else {
                    groups.Add(group);
                    group = new Pair {
                        Value = value,
                        Count = 1
                    };
                }
            }

            // add last group
            groups.Add(group);

            return groups;
        }
    }

    public struct Pair {
        public int Value;
        public int Count;
    }

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

        public static StreamReader Reader { get; set; }

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

            int result = 0;
            int digit;
            int cache1;
            int 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;
        }
    }
}


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

public class App1
{
    public static void Main()
    {
        Func<string> read = ()=>Console.ReadLine();
        Action<object> write = _=>Console.WriteLine(_.ToString());

        var n=read().ToInt();
        var a=read().ToIntA();
        Func<int,int,int> f=(x,y)=>util.RangeN(x,y).Rd(0,(s,v)=>s+(1-a[v])*2-1);
        var l=
            from i in util.RangeN(0,n-2)
            from j in util.RangeN(i+1,n-1)
            select f(i,j);
        var d=l.Max();
        write(a.Count(v=>v==1)+d);
    }
}

static class Exts
{
    public static int ToInt(this string s)
    {
        return int.Parse(s);
    }

    public static int[] ToIntA(this string s)
    {
        return s.Split(" ").Select(ToInt).ToArray();
    }

    public static long ToLong(this string s)
    {
        return long.Parse(s);
    }

    public static string[] Split(this string s,string sp)
    {
        return s.Split(new[]{sp},StringSplitOptions.RemoveEmptyEntries);
    }

    public static string ToStr(this IEnumerable<char> a)
    {
        return new string((a is char[])?(char[])a:a.ToArray());
    }
}

static class FuncExts
{
    public static T Rd<T>(this IEnumerable<T> l,T df,Func<T,T,T> f)
    {
        return Fold(l,df,f);
    }

    public static U Fold<T,U>(this IEnumerable<T> l,U df,Func<U,T,U> f)
    {
        foreach(var i in l)
        {
            df=f(df,i);
        }
        return df;
    }
}

static class util
{
    public static IEnumerable<int> RangeN(int from,int to)
    {
        while(from<=to)
        {
            yield return from;
            from++;
        }
    }
}


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

namespace COJ
{
    class Program
    {
        /*
         * Author: Luismo
         * Idea: BinarySearch + DFS
         *
         * */

        static void Main(string[] args)
        {
            TextReader tr = Console.In;
           // Console.SetIn(new StreamReader(@"d:\lmo.in"));

            SolveSingleProblem();

            Console.SetIn(tr);
            Console.ReadLine();

            //string[] data = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        }

        static List<Interval> intervals;
        static void SolveSingleProblem()
        {
            int n = int.Parse(Console.ReadLine());
            int[] arr = new int[n];
            string[] data = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            int firstZ = -1;
            int totalOnes = 0;

            for (int i = 0; i < data.Length; i++)
            {
                arr[i] = int.Parse(data[i]);

                if (arr[i] == 0)
                {
                    if(firstZ==-1)
                        firstZ = i;
                }
                else totalOnes++;
            }
            //
            int zeroes = 0, ones = 0, max =0, cnt=0;
            for (int i = firstZ; i < arr.Length; i++)
            {
                if (arr[i] == 0)
                    zeroes++;
                else ones++;

                if (zeroes - ones > max)
                {
                    max = zeroes - ones;
                    cnt = zeroes - ones + totalOnes - ones;
                }
            }

            Console.WriteLine(cnt);

        }

    }

}


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

namespace COJ
{
    class Program
    {
        /*
         * Author: Luismo
         * Idea: BinarySearch + DFS
         *
         * */

        static void Main(string[] args)
        {
            TextReader tr = Console.In;
           // Console.SetIn(new StreamReader(@"d:\lmo.in"));

            SolveSingleProblem();

            Console.SetIn(tr);
            Console.ReadLine();

            //string[] data = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        }

        static void SolveSingleProblem()
        {
            int n = int.Parse(Console.ReadLine());
            int[] arr = new int[n];
            string[] data = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            int firstZ = -1;
            int totalOnes = 0;

            for (int i = 0; i < data.Length; i++)
            {
                arr[i] = int.Parse(data[i]);

                if (arr[i] == 0)
                {
                    if(firstZ==-1)
                        firstZ = i;
                }
                else totalOnes++;
            }
            //
            int zeroes = 0, ones = 0, max =0, cnt=0;
            for (int i = firstZ; i < arr.Length; i++)
            {
                if (arr[i] == 0)
                    zeroes++;
                else ones++;

                if (zeroes - ones > max)
                {
                    max = zeroes - ones;
                    cnt = zeroes - ones + totalOnes - ones;
                }
            }

            Console.WriteLine(cnt);

        }

    }

}


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

namespace TC1
{
    class Program
    {
        static string[] input = File.ReadAllLines("input.txt");
        static string[] line1 = input[1].Split(' '), line2 = input[2].Split(' ');
        static string result = "";
        static void Main(string[] args)
        {
            int i = 0;
            bool ret = false;
            while (true)
            {
                string q = i.ToString();
                foreach (string l in line1)
                {
                    if (q.IndexOf(l) > -1)
                    {
                        foreach (string z in line2)
                        {
                            if (q.IndexOf(z) > -1)
                            {
                                result = q;
                                ret = true;
                            }
                        }
                    }
                }
                if (ret) break;
                i++;
            }
            StreamWriter sw = new StreamWriter("output.txt");
            sw.Write(result);
            sw.Close();
        }
    }
}


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

namespace ConsoleApplication3
{

    class Program
    {

        static void Main(string[] args)
        {

            int L1, L2;

            string temp;

            //Console.WriteLine("Please enter the len of list number 1");

            //temp = Console.ReadLine();

            //L1 = Convert.ToInt32(temp);

            //Console.WriteLine("Please enter the len of list number 2");

            //temp = Console.ReadLine();

            //L2 = Convert.ToInt32(temp);

            string[] sListx = System.Console.ReadLine().Split();

            //Console.WriteLine("Please enter the list of number 1");

            string[] sList1 = System.Console.ReadLine().Split();

            //Console.WriteLine("Please enter the list of number 2");

            string[] sList2 = System.Console.ReadLine().Split();

            int z = 0;

            int[] pretty_numbers = new int[(sList1.Length * sList2.Length) * 2];

            for (int i = 0; i < sList1.Length; i++)
            {
                for (int j = 0; j < sList2.Length; j++)
                {
                    if (sList1[i] != sList2[j])
                    {
                        temp = sList1[i] + sList2[j];
                    }
                    else
                    {
                        temp = sList1[i];
                    }

                    pretty_numbers[j + i + z] = Convert.ToInt32(temp);
                }
                z = z + sList1.Length-1;
            }

            z = z + sList1.Length;

            for (int i = 0; i < sList2.Length; i++)
            {
                for (int j = 0; j < sList1.Length; j++)
                {
                    if (sList1[i] != sList2[j])
                    {
                        temp = sList2[i] + sList1[j];
                    }
                    else
                    {
                        temp = sList2[i];
                    }

                    pretty_numbers[j + i + z] = Convert.ToInt32(temp);
                }
                z = z + sList2.Length - 1;
            }

            int maxValue = pretty_numbers.Min();

            System.Console.WriteLine(maxValue);

        }

    }

}


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

namespace ConsoleApplication3
{

    class Program

    {

        static void Main(string[] args)

        {

            int L1, L2;

            string temp;

            //Console.WriteLine("Please enter the len of list number 1");

            //temp = Console.ReadLine();

            //L1 = Convert.ToInt32(temp);

            //Console.WriteLine("Please enter the len of list number 2");

            //temp = Console.ReadLine();

            //L2 = Convert.ToInt32(temp);

            string[] sListx = System.Console.ReadLine().Split();

            //Console.WriteLine("Please enter the list of number 1");

            string[] sList1 = System.Console.ReadLine().Split();

            //Console.WriteLine("Please enter the list of number 2");

            string[] sList2 = System.Console.ReadLine().Split();

            int z = 0;

            int[] pretty_numbers = new int[(sList1.Length*sList2.Length )*2];

            for (int i = 0; i < sList1.Length; i++)

            {
                for (int j=0;j<sList2.Length;j++)
                {
                    temp = sList1[i] + sList2[j];
                    pretty_numbers[j + i+z] = Convert.ToInt32(temp);
                }
                z = z + sList1.Length;
            }

            z = z + sList1.Length;

            for (int i = 0; i < sList2.Length; i++)
            {
                for (int j = 0; j < sList1.Length; j++)
                {
                    temp = sList2[i] + sList1[j];
                    pretty_numbers[j + i + z] = Convert.ToInt32(temp);
                }
                z = z + 1;
            }

            int maxValue = pretty_numbers.Min();

            System.Console.WriteLine(maxValue);

        }

    }

}


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

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var commandsArray = Console.ReadLine().ToCharArray();
            long count = 0;
            for (int i = 0; i < n; i++)
            {
                var lastResult = new Point();
                lastResult.DoCommand(commandsArray[i]);
                for (int g = i + 1; g < n; g++)
                {
                    lastResult.DoCommand(commandsArray[g]);
                    if (lastResult.InStartPlace())
                        count++;
                }
            }
            Console.WriteLine(count);
        }

        public class Point
        {
            public int x, y;

            public void DoCommand(char command)
            {
                switch (command)
                {
                    case 'U': { y++;break; }
                    case 'D': { y--;break; }
                    case 'L': { x--;break; }
                    case 'R': { x++;break; }
                }
            }

            public bool InStartPlace()
            {
                return x == 0 && y == 0;
            }
        }
    }


using System;
using System.Linq;
using System.Collections.Generic;
//using System.Numerics;
using Debug = System.Diagnostics.Debug;
using SB = System.Text.StringBuilder;
using Number = System.Int64;
namespace Program {
    public class Solver {
        public void Solve() {
            var n = ri;
            var a = new List<int>();
            for (int i = 15; i >= 0; i--)
                if ((n >> i & 1) == 1) {
                    a.Add(i + 1);
                }
            Console.WriteLine(a.AsJoinedString());

        }
        const long INF = 1L << 60;
        int[] dx = { -1, 0, 1, 0 };
        int[] dy = { 0, 1, 0, -1 };

        int ri { get { return sc.Integer(); } }
        long rl { get { return sc.Long(); } }
        double rd { get { return sc.Double(); } }
        string rs { get { return sc.Scan(); } }
        public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());

        static T[] Enumerate<T>(int n, Func<int, T> f) {
            var a = new T[n];
            for (int i = 0; i < n; ++i) a[i] = f(i);
            return a;
        }

        static public void Swap<T>(ref T a, ref T b) {
            var tmp = a;
            a = b;
            b = tmp;
        }
    }
}

#region main

static class Ex {
    static public string AsString(this IEnumerable<char> ie) {
        return new string(ie.ToArray());
    }

    static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") {
        return string.Join(st, ie.Select(x => x.ToString()).ToArray());
        //return string.Join(st, ie);
    }

    static public void Main() {
        Console.SetOut(new Program.IO.Printer(Console.OpenStandardOutput()) { AutoFlush = false });
        var solver = new Program.Solver();
        solver.Solve();
        Console.Out.Flush();
    }
}

#endregion
#region Ex

namespace Program.IO {
    using System.IO;
    using System.Text;
    using System.Globalization;

    public class Printer: StreamWriter {
        public override IFormatProvider FormatProvider {
            get { return CultureInfo.InvariantCulture; }
        }
        public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
    }

    public class StreamScanner {
        public StreamScanner(Stream stream) {
            str = stream;
        }

        public readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream {
            get { return isEof; }
        }

        private byte read() {
            if (isEof) return 0;
            if (ptr >= len) {
                ptr = 0;
                if ((len = str.Read(buf, 0, 1024)) <= 0) {
                    isEof = true;
                    return 0;
                }
            }
            return buf[ptr++];
        }

        public char Char() {
            byte b = 0;
            do b = read(); while ((b < 33 || 126 < b) && !isEof);
            return (char)b;
        }

        public string Scan() {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b);
            return sb.ToString();
        }

        public string ScanLine() {
            var sb = new StringBuilder();
            for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b);
            return sb.ToString();
        }

        public long Long() {
            return isEof ? long.MinValue : long.Parse(Scan());
        }

        public int Integer() {
            return isEof ? int.MinValue : int.Parse(Scan());
        }

        public double Double() {
            return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture);
        }
    }
}

#endregion


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

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            int k = int.Parse(Console.ReadLine());

            int[] somearr = new int[1];

            somearr[0] = 1;

            int current = 0;

            for (int i = 0; i < k; i++)
            {
                Array.Resize(ref somearr, somearr.Length + 1);
                current++;

                while (somearr.Length > 1 && somearr[current] == somearr[current - 1])
                {
                    somearr[current - 1] += 1;
                    current--;
                    Array.Resize(ref somearr, somearr.Length - 1);
                }
            }
            foreach (int i in somearr)
                Console.Write(i + " ");

        }
    }
}


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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public void Solve()
    {
        int n = ReadInt();
        var s = new Stack<int>();
        for (int i = 0; i < n; i++)
        {
            int x = 1;
            while (s.Count > 0 && s.Peek() == x)
            {
                s.Pop();
                x++;
            }
            s.Push(x);
        }

        Write(s.Count);
        WriteArray(s.Reverse());
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
            new Solver().Solve();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
#if DEBUG
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

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


using System;
using System.Text;

namespace WunderFund
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var nBits = Convert.ToString(int.Parse(Console.ReadLine()), toBase: 2);

			Console.WriteLine(nBits);
            var lengths = new StringBuilder();
            for (var i = 0; i < nBits.Length; ++i)
                if (nBits[i] == '1')
                   lengths.Append((nBits.Length - i) + " ");

            Console.WriteLine(lengths.ToString());
        }
    }
}


//Rextester.Program.Main is the entry point for your code. Don't change it.
//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5

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

namespace Rextester
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //input BITCH
            int n=int.Parse(Console.ReadLine());

            //Logic BITCH
            int ans=0;
            while(n>0){
                int pow=(int)(Math.Log(n,2));
                ans+=1+pow;
                n-=(int)Math.Pow(2,pow);
            }
            Console.WriteLine(ans);
        }
    }
}


using System;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            string answ = "";
            string result = "";
            int count = Int32.Parse(Console.ReadLine());
            if (count == 0) { Console.WriteLine("0"); return; }
            int num = 4096*2*2*2;

            while (num != 0)
            {
                int param = count / num;
                if (param > 0) { result += "1"; count = count % num; } else { result += "0";  }
                num = num / 2;
            }
            for(var i = 0; i < result.Length; i++)
            {
                if (result[i] == '1') { answ += (result.Length - i) + " "; }

            }

            Console.WriteLine(answ);
            Console.Read();
        }
    }
}


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

namespace cforce135bb
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] tmp = Console.ReadLine().Split(' ');
            long p = long.Parse(tmp[0]), d = long.Parse(tmp[1]), i=p, n=p, k, f;
            int count = 1;
            while (i>=p-d)
            {
                f = (long)Math.Pow(10, count);
                k=(long)((i + 1) % f);
                if (k == 0)
                {
                    count++;
                    n = i;
                }
                i -= (long)Math.Pow(10, count - 1);
            }
            Console.WriteLine(n);
            Console.ReadLine();
        }
    }
}


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

namespace CF {
    class Program {

        static void Main(string[] args) {

#if DEBUG
            TextReader reader = new StreamReader("../../input.txt");
            TextWriter writer = Console.Out;
#else
			TextReader reader = Console.In;
            TextWriter writer = Console.Out;
#endif

            var p = reader.Read<long>();
            var d = reader.Read<long>();

            var q = p;

            var best = p;
            var dropped = 0L;
            var power = 1L;
            while (q >= 10) {
                var lastDigit = q % 10;
                dropped += (lastDigit + 1) * power;
                power *= 10;
                if (dropped > d) break;
                q /= 10;
                if (lastDigit != 9) {
                    best = p - dropped;
                    q = best / power;
                }

            }

            // 2348699999999999
            Console.WriteLine(best);

#if DEBUG
            Console.ReadKey();
#endif
        }

    }

    class Pair<T1, T2> {
        public Pair(T1 first, T2 second) {
            First = first;
            Second = second;
        }
        public T1 First { get; set; }
        public T2 Second { get; set; }
        public override string ToString() {
            return "{" + First + " " + Second + "}";
        }
    }

    static class ReaderExtensions {

        public static string ReadToken(this TextReader reader) {
            int val;
            var builder = new StringBuilder();
            while (true) {
                val = reader.Read();
                if (val == ' ' || val == -1) {
                    if (builder.Length == 0) continue;
                    break;
                }
                if (val == 13) {
                    reader.Read();
                    if (builder.Length == 0) continue;
                    break;
                }
                builder.Append((char)val);
            }
            return builder.ToString();
        }

        public static T Read<T>(this TextReader reader) {
            return (T)Convert.ChangeType(reader.ReadToken(), typeof(T));
        }

        public static T[] ReadArr<T>(this TextReader reader) {
            return reader.ReadLine()
                .Split(' ').Select(str =>
                    (T)Convert.ChangeType(str, typeof(T))
                ).ToArray();
        }

    }

    static class LinqExtensions {
        /// <summary>Value / Index</summary>
        public static IEnumerable<Pair<T, int>> SelectIndexes<T>(this IEnumerable<T> collection) {
            return collection.Select((v, i) => new Pair<T, int>(v, i));
        }
        public static IEnumerable<T> SelectValues<T>(this IEnumerable<Pair<T, int>> collection) {
            return collection.Select(p => p.First);
        }
    }

}


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

namespace OlimpBlya
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int s=0, k=1;
            for(int i=1;i<=n;i++)
            {
                k *= 2;
                s += k;
            }
            Console.WriteLine(s);

        }
    }
}


using System;

class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        long r = (long)Math.Pow(2, n) + 2;
        Console.WriteLine(r.ToString().Replace(',','.'));
        Console.ReadLine();
    }
}


using System;
using System.Linq;

namespace Codeforces
{
    internal static class Program
    {
        private static void Main()
        {
            var n = long.Parse(Console.ReadLine());

            var max = Math.Pow(10, n) - 1.0;

            var count = 0;

            for (var i = 7; i < max; i++)
            {
                var cs = i.ToString().ToCharArray();
                if (cs.All(x => x == '7' || x == '8'))
                {
                    count++;
                }
            }

            Console.WriteLine(count);
        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine()), res = 0, j=1;
            for (int i = 0; i < n; i++)
            {
                j = j * 2;
                res = res + j;
            }
            Console.Write(res);
        }
    }
}


using System;

namespace LuckyNumbers
{
    class Program
    {
        static void Main(string[] args)
        {
            sbyte n = Convert.ToSByte(Console.ReadLine());

            int output = 2,say7 = 0,say8 = 0;

            if (n == 1) { Console.WriteLine(output); return; }

            for (string i = "77"; !i.Equals( Math.Pow(10,n).ToString()); )
            {

                for (int j = 0; j < i.Length; j++)
                {
                    if (i[j] == '7') say7++;
                    else if (i[j] == '8') say8++;
                    else break;

                }
                if (i.Length == (say7 + say8)) output++;

                i = i.Substring(0, i.Length - 2) + (Convert.ToInt32(i.Substring(i.Length-2,2)) + 1) ;
                say7 = 0;
                say8 = 0;
            }
            Console.WriteLine(output);
        }
    }
}


using System;

namespace LuckyNumbers
{
    class Program
    {
        static void Main(string[] args)
        {
            sbyte n = Convert.ToSByte(Console.ReadLine());
            int output = 0;

            for (int i = n; i > 0; i--)
            {
                output += Convert.ToInt32( Math.Pow(2,i) );
            }
            Console.WriteLine(output);
        }

    }
}


using System;
class Program{
    public static void Main(string[] args){
        int n = int.Parse(Console.ReadLine());
        int res = 2;
        for(int i = 2; i <= n; i++)
            res += Math.Pow(2,i);
        Console.WriteLine(res);
    }
}


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

namespace ConsoleApp1
{
    internal class Program
    {

        public static void Main(string[] args)
        {
            //2010200
            string x = Console.ReadLine();
            string k = string.Empty;
            for (int i = x.Count()-1; i >= 0; i--)
                k+= x[i];
            int res = 0;
            for(int i = 0; i < x.Length; i++)
            {
                if(isPal(k))
                {
                    res++;
                    break;0
                }
                else
                {
                    k += "0";
                }
            }

            if(res > 0)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
        }

        public static bool isPal(string k)
        {
            var st = string.Empty;
            for (int i = k.Count() - 1; i >= 0; i--)
                st += k[i];
            if (st == k)
            {
                return true;
            }
            else
                return false;
        }

    }
}


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

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

            int k;
            string s = Console.ReadLine();
            string[] tmp = s.Split(' ');
            k = int.Parse(tmp[0]);
            string a = k.ToString();

            int kolnul=0;
            for (int i =0;i<a.Length;i++)
            {
                int del = k  - (k/10)*10;
                if (del == 0)
                {
                    kolnul++;
                    k = k/10;
                }
                else break;
            }
            char[] b = new char[a.Length+kolnul];

            if (kolnul > 0)
            {
                for (int i = 0; i < kolnul; i++)
                {
                    b[i] = '0';
                }
                for (int i = 0; i < a.Length; i++)
                {
                    int l = i+kolnul;
                    b[l] = a[i];
                }
                string m1 = new string(b);

                char[] z = new char[a.Length + kolnul];

                for (int i = 0; i < a.Length + kolnul; i++)
                {
                    int l = a.Length +kolnul- i-1;
                    z[l] = m1[i];
                }
                string m2 = new string(z);

                if (m2 == m1) Console.WriteLine("YES");
                else Console.WriteLine("No");
                Console.ReadLine();

            }

            for (int i = 0; i < a.Length; i++)
            {
                int l = a.Length - i-1;
                b[l] = a[i];
            }
            string m = new string(b);

            if (a == m) Console.WriteLine("YES");
            else Console.WriteLine("No");

        }

    }
}


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

namespace ProgrammingContest
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Console.ReadLine();
            var answer = true;
            int j = n.Length;
            int c = 0;
            if (n.Equals("0"))
            {
                c++;
            }
            else
            {

                while (j >= 0 && (n[j - 1]).ToString().Equals("0"))
                {
                    c++;
                    j--;
                }
            }

            var p = new String('0', c) + n ;

            for (int i = 0; i < p.Length / 2; i++)
            {
                if (p[i] - p[p.Length - i - 1] != 0)
                {
                    answer = false;
                    break;
                }
            }

            Console.WriteLine(answer);
        }
    }
}


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

namespace Codeforces12
{
    class Program
    {
        static void Main(string[] args)
        {
            int nameLength = Convert.ToInt32(Console.ReadLine());
            string fileName = Console.ReadLine();
            ColichestvoX(fileName);
        }
        public void ColichestvoX(string fileName)
        {
            //количество стоящих подряд символов х
            int x = 0;
            //количесвто символов для удаления
            int count = 0;

            for (int i = 0; i < fileName.Length; i++)
            {
                if (fileName[i] == 'x')
                {
                    x++;
                }
                else
                {
                    x = 0;
                }

                if(x > 2)
                {
                    count++;
                }
            }

            Console.WriteLine(count);
        }

    }
}


using System;
class Program
    {
        static void Main(string[] args)
        {
            string input = Console.In.ReadToEnd().Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)[1];
            int result = 0;
            for(int i = 0, xes=0; i<input.Length; )
            {
                if (input[i] == 'x')
                {
                    if (xes > 1) result++;
                    else xes++;
                }
                else xes = 0;
            }
            Console.WriteLine(result);
        }
    }


using System;
using System.Linq;

namespace CodeForces
{
    class Program
    {
        static void Main(string[] args)
        {
            Solve();
        }

        static void Solve()
        {
            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            int count = 0;
            int result = 0;
            for(int i = 0; i < n; i++)
            {
                if (s[i] == 'x') count++;
                else if(count >= 3)
                {
                    result += count - 2;
                    count = 0;
                }
            }
            if (count >= 3) result += count - 2;
            Console.WriteLine(result);
        }
    }
}


using System;

namespace B831
{
    class Program
    {
        static void Main(string[] args)
        {
            var fl= Console.ReadLine();
            var sl = Console.ReadLine();
            var txt = Console.ReadLine();
            var ans = new char[txt.Length];
            var index = new int[2,txt.Length];
            for (int i = 0; i < txt.Length; i++)
            {
                if (txt[i] >= 'a' && txt[i] <= 'z' || txt[i] >= 'A' && txt[i] <= 'Z')
                {
                    for (int j = 0; j < fl.Length; j++)
                    {
                        if (txt[i].ToString().ToLower().Equals(fl[j].ToString()))
                        {
                            index[0, i] = j;
                            if (txt[i] <= 'Z')
                                index[1, i] = 1;
                        }
                    }

                }
                else
                {
                    ans[i] = txt[i];
                    index[0, i] = -1;
                }
            }

            for (int i = 0; i < txt.Length; i++)
            {
                if (index[1, i] == 1 && index[0,i] != -1)
                    ans[i] = Convert.ToChar(sl[index[0, i]].ToString().ToUpper());
                else if(index[0, i] != -1)
                    ans[i] = sl[index[0, i]];
            }

            Console.WriteLine(ans);
        }
    }
}