using System;
using System.Collections.Generic;
using System.Linq;
using Solver.Ex;
using Enum = System.Linq.Enumerable;
using Watch = System.Diagnostics.Stopwatch;
using StringBuilder = System.Text.StringBuilder;
using BitVector = System.Collections.Specialized.BitVector32;
namespace Solver
{

    public class Solver
    {
        public void Solve()
        {
            var n = sc.Long();
            var count = 0;
            for (long i = 1; i < n; i++)
            {
                var t = 3 * i * (i + 1) / 2;
                var num = n + i;
                if (t > num)
                    break;
                if (num % 3 != 0)
                    continue;
                count++;
            }
            IO.Printer.Out.PrintLine(count);
        }
        internal IO.StreamScanner sc;
    }

    #region Main and Settings
    static class Program
    {
        static void Main(string[] arg)
        {
#if DEBUG
            var errStream = new System.IO.FileStream(@"..\..\dbg.out", System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite);
            System.Diagnostics.Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(errStream, "debugStream"));
            System.Diagnostics.Debug.AutoFlush = false;
            var sw = new Watch();
            sw.Start();
            try
            {
#endif
                var solver = new Solver();
                solver.sc = new IO.StreamScanner(Console.OpenStandardInput());
                IO.Printer.Out = new IO.Printer(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
                solver.Solve();
                IO.Printer.Out.Flush();
#if DEBUG
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
                Console.Error.WriteLine(ex.StackTrace);
            }
            finally
            {
                sw.Stop();
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Error.WriteLine("Time:{0}ms", sw.ElapsedMilliseconds);
                System.Diagnostics.Debug.Close();
                System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
            }
#endif
        }

    }
    #endregion
}
#region IO Helper
namespace Solver.IO
{
    public class Printer
    {
        static Printer()
        {
            Out = new Printer(Console.Out);
        }
        public static Printer Out { get; set; }
        private readonly System.IO.TextWriter writer;
        private readonly System.Globalization.CultureInfo info;
        public string Separator { get; set; }
        public string NewLine { get { return writer.NewLine; } set { writer.NewLine = value ?? "\n"; } }
        public Printer(System.IO.TextWriter tw = null, System.Globalization.CultureInfo ci = null, string separator = null, string newLine = null)
        {
            writer = tw ?? System.IO.TextWriter.Null;
            info = ci ?? System.Globalization.CultureInfo.InvariantCulture;
            NewLine = newLine;
            Separator = separator ?? " ";
        }
        public void Print(int num) { writer.Write(num.ToString(info)); }
        public void Print(int num, string format) { writer.Write(num.ToString(format, info)); }
        public void Print(long num) { writer.Write(num.ToString(info)); }
        public void Print(long num, string format) { writer.Write(num.ToString(format, info)); }
        public void Print(double num) { writer.Write(num.ToString("F12", info)); }
        public void Print(double num, string format) { writer.Write(num.ToString(format, info)); }
        public void Print(string str) { writer.Write(str); }
        public void Print(string format, params object[] arg) { writer.Write(string.Format(info, format, arg)); }
        public void Print<T>(string format, IEnumerable<T> sources) { writer.Write(format, sources.OfType<object>().ToArray()); }
        public void Print(IEnumerable<char> sources) { writer.Write(sources.AsString()); }
        public void Print<T>(IEnumerable<T> sources)
        {
            var res = new System.Text.StringBuilder();
            foreach (var x in sources)
            {
                res.AppendFormat(info, "{0}", x);
                if (string.IsNullOrEmpty(Separator))
                    res.Append(Separator);
            }
            writer.Write(res.ToString(0, res.Length - Separator.Length));
        }
        public void PrintLine() { writer.WriteLine(); }
        public void PrintLine(int num) { writer.WriteLine(num.ToString(info)); }
        public void PrintLine(int num, string format) { writer.WriteLine(num.ToString(format, info)); }
        public void PrintLine(long num) { writer.WriteLine(num.ToString(info)); }
        public void PrintLine(long num, string format) { writer.WriteLine(num.ToString(format, info)); }
        public void PrintLine(double num) { writer.WriteLine(num.ToString("F12", info)); }
        public void PrintLine(double num, string format) { writer.WriteLine(num.ToString(format, info)); }
        public void PrintLine(string str) { writer.WriteLine(str); }
        public void PrintLine(string format, params object[] arg) { writer.WriteLine(string.Format(info, format, arg)); }
        public void PrintLine<T>(string format, IEnumerable<T> sources) { writer.WriteLine(format, sources.OfType<object>().ToArray()); }
        public void PrintLine<T>(IEnumerable<T> sources)
        {
            var res = new StringBuilder();
            foreach (var x in sources)
            {
                res.AppendFormat(info, "{0}", x);
                if (!string.IsNullOrEmpty(Separator))
                    res.Append(Separator);
            }
            writer.WriteLine(res.ToString(0, res.Length - Separator.Length));
        }
        public void Flush() { writer.Flush(); }
    }
    public class StreamScanner
    {
        public StreamScanner(System.IO.Stream stream)
        {
            iStream = stream;
        }
        private readonly System.IO.Stream iStream;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        private bool eof = false;
        public bool EndOfStream { get { return eof; } }
        private byte readByte()
        {
            if (eof) throw new System.IO.EndOfStreamException();
            if (ptr >= len)
            {
                ptr = 0;
                len = iStream.Read(buf, 0, 1024);
                if (len <= 0)
                {
                    eof = true;
                    return 0;
                }
            }
            return buf[ptr++];
        }
        private bool inSpan(byte c)
        {
            const byte lb = 33, ub = 126;
            return !(c >= lb && c <= ub);
        }
        private byte skip()
        {
            byte b = 0;
            do b = readByte();
            while (!eof && inSpan(b));
            return b;
        }
        public char Char()
        {
            return (char)skip();
        }
        public char[] Char(int n)
        {
            var a = new char[n];
            for (int i = 0; i < n; i++)
                a[i] = (char)skip();
            return a;
        }
        public char[][] Char(int n, int m)
        {
            var a = new char[n][];
            for (int i = 0; i < n; i++)
                a[i] = Char(m);
            return a;
        }
        public string Scan()
        {

            const byte lb = 33, ub = 126;
            if (eof) throw new System.IO.EndOfStreamException();

            do
            {
                while (ptr < len && (buf[ptr] < lb || ub < buf[ptr]))
                {
                    ptr++;
                }
                if (ptr < len)
                    break;
                ptr = 0;
                len = iStream.Read(buf, 0, 1024);
                if (len <= 0)
                {
                    eof = true;
                    return null;
                }
                continue;
            } while (true);

            StringBuilder sb = null;
            do
            {
                var i = ptr;
                while (i < len)
                {
                    if (buf[i] < lb || ub < buf[i])
                    {
                        string s;
                        if (sb != null)
                        {
                            sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr));
                            s = sb.ToString();
                        }
                        else s = new string(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr));
                        ptr = i + 1;
                        return s;
                    }
                    i++;
                }
                i = len - ptr;
                if (sb == null) sb = new StringBuilder(i + 32);
                sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i));
                ptr = 0;
            } while ((len = iStream.Read(buf, 0, 1024)) > 0);
            eof = true;
            return sb.ToString();
        }
        public string[] Scan(int n)
        {
            var a = new string[n];
            for (int i = 0; i < n; i++)
                a[i] = Scan();
            return a;
        }
        public string ScanLine()
        {
            const byte el = 10, cr = 13;
            if (eof) throw new System.IO.EndOfStreamException();
            StringBuilder sb = null;
            do
            {
                var i = ptr;
                while (i < len)
                {
                    if (buf[i] == cr || buf[i] == el)
                    {
                        string s;
                        if (sb != null)
                        {
                            sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr));
                            s = sb.ToString();
                        }
                        else s = new string(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr));
                        if (buf[i] == cr) i++;
                        if (buf[i] == el) i++;
                        ptr = i;
                        return s;
                    }
                    i++;
                }
                i = len - ptr;
                if (sb == null) sb = new StringBuilder(i + 32);
                sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i));
                ptr = 0;
            } while ((len = iStream.Read(buf, 0, 1024)) > 0);
            eof = true;
            return sb.ToString();
        }
        public double Double()
        {
            return double.Parse(Scan(), System.Globalization.CultureInfo.InvariantCulture);
        }
        public double[] Double(int n)
        {
            var a = new double[n];
            for (int i = 0; i < n; i++)
                a[i] = Double();
            return a;
        }
        public int Integer()
        {
            var ret = 0;
            byte b = 0;
            bool isMynus = false;
            const byte zero = 48, nine = 57, mynus = 45;
            do b = readByte();
            while (!eof && !((b >= zero && b <= nine) || b == mynus));

            if (b == mynus)
            {
                isMynus = true;
                b = readByte();
            }
            while (true)
            {
                if (b >= zero && b <= nine)
                {
                    ret = ret * 10 + b - zero;
                }
                else return isMynus ? -ret : ret;
                b = readByte();
            }

        }
        public int[] Integer(int n)
        {
            var a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = Integer();
            return a;
        }
        public long Long()
        {
            long ret = 0;
            byte b = 0;
            bool isMynus = false;
            const byte zero = 48, nine = 57, mynus = 45;
            do b = readByte();
            while (!eof && !((b >= zero && b <= nine) || b == mynus));
            if (b == '-')
            {
                isMynus = true;
                b = readByte();
            }
            while (true)
            {
                if (b >= zero && b <= nine)
                    ret = ret * 10 + (b - zero);
                else return isMynus ? -ret : ret;
                b = readByte();
            }

        }
        public long[] Long(int n)
        {
            var a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = Long();
            return a;
        }
        public void Flush()
        {
            iStream.Flush();
        }

    }

}
#endregion
#region Extension
namespace Solver.Ex
{
    static public partial class EnumerableEx
    {
        static public string AsString(this IEnumerable<char> source)
        {
            return new string(source.ToArray());
        }
        static public string AsJoinedString<T>(this IEnumerable<T> source, string separator = " ")
        {
            return string.Join(separator, source);
        }
        static public T[] Enumerate<T>(this int n, Func<int, T> selector)
        {
            var res = new T[n];
            for (int i = 0; i < n; i++)
                res[i] = selector(i);
            return res;
        }
    }
}
#endregion


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

namespace razmer_monitora
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Int32.Parse(Console.ReadLine());
            int a = (int)Math.Sqrt(n);
            int b = n/a;
            while (a*b!=n)
            {
                a--;
                b = n / a;
            }
            Console.WriteLine(a+" "+b);
        }
    }
}


using System;

public class Program
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		for (int i = (int)Math.Sqrt(n); i > 0; i--)
		{
			if (n % i == 0)
			{
				Console.WriteLine($"{i} {n / i}");
				return;
			}
		}
	}
}


using System;

class Program
{
	static void Main()
	{
		int n = Convert.ToInt32(Console.ReadLine());
		string inp = Console.ReadLine();
		string[] par = inp.Split(' ');
		int i, d, prognoz;

		int[] a = new int[n];

		for (i = 0; i < n; i++)
			a[i] = Convert.ToInt32(par[i]);

		d = (a[n - 1] - a[0]) / (n - 1);

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

		/*if (d == a[1] - a[0])
			prognoz = a[n - 1] + d;
		else
			prognoz = a[n - 1];*/

		prognoz = a[n - 1] + d;

		Console.WriteLine("{0}", prognoz);
	}
}


using System;

namespace E
{
    class Program
    {
        static void Main(string[] args)
        {
            int days = int.Parse(Console.ReadLine());
            var _temp = Console.ReadLine().Split(' ');

            bool _flag = true;
            int zeroDay, secondDay, progress, expectedTemp, currTemp = 0;

            zeroDay = int.Parse(_temp[0]);
            secondDay = int.Parse(_temp[1]);

            progress = secondDay - zeroDay;
            if (days >= 3)
            {
                for (int i = 1; i < days; i++)
                {
                    currTemp = int.Parse(_temp[i]);
                    expectedTemp = int.Parse(_temp[i - 1]) + progress;
                    if(currTemp != expectedTemp)
                    {
                        _flag = false;
                        break;
                    }
                }
                if(_flag)
                {
                    Console.WriteLine(currTemp + progress);

                }
                else
                {
                    Console.WriteLine(_temp[days - 1]);
                }

            }
            else
            {
                expectedTemp = zeroDay + progress * (days - 1);

                if (int.Parse(_temp[days - 1]) == expectedTemp)
                {
                    Console.WriteLine(expectedTemp + progress);

                }
                else
                    Console.WriteLine(_temp[days - 1]);
            }

        }
    }
}


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

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

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

            char[] next = s.ToCharArray();
            string ss;
            for (int i = 1; i < next.Length; i++)
            {
                next[i] = '0';
            }
            if (next[0] < '9')
            {
                next[0]++;
                ss = new string(next);
            }
            else
            {
                next[0] = '0';
                ss = "1" + new string(next);
            }

            writer.WriteLine(long.Parse(ss) - n);
            writer.Flush();
        }
    }
}


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

namespace A808
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            string a1 = a + "";
            int l = a1.Length;
            if (l == 1)
            {
                Console.WriteLine(1);
            }
            else {

                int m =int.Parse(a1[0]+"");
                int k = (int)Math.Pow(10, l - 1);
                Console.WriteLine((m+1)* k-a);
            }

        }
    }
}


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

namespace ReadWriteTemplate
{
    public static class Solver
    {
        private static void SolveCase()
        {
            long n = ReadLong();
            long m = ReadLong();
            long ans = 0;
            for (long i = 1; i <= m; i++)
            {
                for (long j = 1; j <= m; j++)
                {
                    if ((i * i + j * j) % m == 0)
                    {
                        long ci = (n + m - i) / m;
                        long cj = (n + m - j) / m;
                        ans += ci * cj;
                    }
                }
            }
            Writer.WriteLine(ans);
        }

        public static void Solve()
        {
            SolveCase();

            /*var sw = Stopwatch.StartNew();*/

            /*int T = ReadInt();
            for (int i = 0; i < T; i++)
            {
                // Writer.Write("Case #{0}: ", i + 1);
                Precalc();
                SolveCase();
            }*/

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

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

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

            // Solve();
            Thread thread = new Thread(Solve, 64 * 1024 * 1024);
            thread.CurrentCulture = CultureInfo.InvariantCulture;
            thread.Start();
            thread.Join();

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

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

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

        #region Read/Write

        private static TextReader Reader;

        private static TextWriter Writer;

        private static Queue<string> CurrentLineTokens = new Queue<string>();

        private static string[] ReadAndSplitLine()
        {
            return Reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
        }

        public static string ReadToken()
        {
            while (CurrentLineTokens.Count == 0)
                CurrentLineTokens = new Queue<string>(ReadAndSplitLine());
            return CurrentLineTokens.Dequeue();
        }

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

        public static int ReadInt()
        {
            return int.Parse(ReadToken());
        }

        public static long ReadLong()
        {
            return long.Parse(ReadToken());
        }

        public static double ReadDouble()
        {
            return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
        }

        public static int[] ReadIntArray()
        {
            return ReadAndSplitLine().Select(int.Parse).ToArray();
        }

        public static long[] ReadLongArray()
        {
            return ReadAndSplitLine().Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();
        }

        public static int[][] ReadIntMatrix(int numberOfRows)
        {
            int[][] matrix = new int[numberOfRows][];
            for (int i = 0; i < numberOfRows; i++)
                matrix[i] = ReadIntArray();
            return matrix;
        }

        public static string[] ReadLines(int quantity)
        {
            string[] lines = new string[quantity];
            for (int i = 0; i < quantity; i++)
                lines[i] = Reader.ReadLine().Trim();
            return lines;
        }

        public static void WriteArray<T>(IEnumerable<T> array)
        {
            Writer.WriteLine(string.Join(" ", array));
        }

        #endregion
    }
}


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

namespace Lib
{
    public class DivideCandies
    {
        public static void Main()
        {
            Solve(Console.In, Console.Out);
        }

        public static void Solve(TextReader tr, TextWriter tw)
        {
            var tokens = tr.ReadLine().Split();
            var n = long.Parse(tokens[0]);
            var m = long.Parse(tokens[1]);

            var t = new long[m, m];

            var res = 0L;
            for (long i = 0; i < m; i++)
            {
                for (long j = 0; j < m; j++)
                {
                    t[i, j] = ((i+1) * (i+1) + (j+1) * (j+1)) % m;
                    if (t[i, j] == 0)
                        res++;
                }
            }

            var p = n / m;
            res *= p * p;

            var r = n % m;

            var res2 = 0L;
            for (long i = 0; i < r; i++)
            {
                for (long j = 0; j < m; j++)
                {
                    if (t[i, j] == 0)
                        res2++;
                }
            }
            res += res2 * p * 2;

            for (long i = 0; i < r; i++)
            {
                for (long j = 0; j < r; j++)
                {
                    if (t[i, j] == 0)
                        res++;
                }
            }

            tw.WriteLine(res);
        }
    }
}


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

class Solution
{

    static void Main(String[] args)
    {
        Dictionary<int, char> r = new Dictionary<int, char>();
        r[3] ='3';
        r[7] ='7';
        r[4] ='6';
        r[6] ='4';
        r[5] ='9';
        r[9] ='5';
        r[8] ='0';
        r[0] = '8';
        string s = Console.ReadLine();
        string rs = string.Concat(s.Reverse());
        for (int i = 0; i < s.Length ; i++)
        {
            int q = int.Parse(s[i].ToString());
            if(!r.ContainsKey(q))
            {
                Console.WriteLine("NO");
                Console.Read();
                return;
            }
            if(r[q] != rs[i])
            {
                Console.WriteLine("NO");
                Console.Read();
                return;
            }
        }
        Console.WriteLine("YES");
        Console.Read();
    }
}


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

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

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

            for (int i = 0; i < s.Length - i; i++)
            {
                switch (s[s.Length - i - 1])
                {
                    case '1':
                    case '2':
                        writer.WriteLine("No");
                        writer.Flush();
                        return;
                    case '3':
                        if (s[i] != '3')
                        {
                            writer.WriteLine("No");
                            writer.Flush();
                            return;
                        }
                        break;
                    case '4':
                        if (s[i] != '6')
                        {
                            writer.WriteLine("No");
                            writer.Flush();
                            return;
                        }
                        break;
                    case '5':
                        if (s[i] != '9')
                        {
                            writer.WriteLine("No");
                            writer.Flush();
                            return;
                        }
                        break;
                    case '6':
                        if (s[i] != '4')
                        {
                            writer.WriteLine("No");
                            writer.Flush();
                            return;
                        }
                        break;
                    case '7':
                        if (s[i] != '7')
                        {
                            writer.WriteLine("No");
                            writer.Flush();
                            return;
                        }
                        break;
                    case '8':
                        if (s[i] != '0')
                        {
                            writer.WriteLine("No");
                            writer.Flush();
                            return;
                        }
                        break;
                    case '9':
                        if (s[i] != '5')
                        {
                            writer.WriteLine("No");
                            writer.Flush();
                            return;
                        }
                        break;
                    case '0':
                        if (s[i] != '8')
                        {
                            writer.WriteLine("No");
                            writer.Flush();
                            return;
                        }
                        break;
                }
            }

            writer.WriteLine("Yes");
            writer.Flush();
        }
    }
}


using System;

class Program {
    static void Main()  {
        int n = int.Parse(Console.ReadLine());

        int b = n%3 == 2? n/3 + 1 : n/3;
        int a = b/12;
        b %= 12;

        Console.WriteLine(a + " " + b);
    }
}


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

namespace ConsoleApplication254
{
    class Program
    {

        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int a = n/36;
            int b = (n-a*36)/3;
            if ((n - a * 36) % 3 == 2) b++;
            if (b == 12) { a++; b = 0; }
            Console.WriteLine(a+" "+b);

        }
    }
}/*using System;
using System.Collections.Generic;
using System.Text;

namespace chislo
{
    class Program
    {
        static void Main(string[] args)
        {int sch = 0;
            string[] s = Console.ReadLine().Split(' ');
            long n = Convert.ToInt64(s[0]);
            long l1 = Convert.ToInt64(s[1]);
            long r1 = Convert.ToInt64(s[2]);
            List<long> l = new List<long>(); if (n == 0) Console.WriteLine(0);
            else
                if (n == 1)
                {
                    if (l1 <= 2 && r1 >= 2) Console.WriteLine(1);
                    else
                        Console.WriteLine(0);
                }
                else
            {
                for (int i = 0; n > 1; i++)
                {
                    l.Add(n); n /= 2;
                }
                string c = Convert.ToString(l[l.Count - 1] / 2);
                string c1 = Convert.ToString(l[l.Count - 1] % 2);
                string str = (c + c1 + c);
                for (int i = l.Count - 2; i >= 0; i--)
                {
                    c1 = Convert.ToString(l[i] % 2);
                    str += c1 + str;
                }
                Console.WriteLine(str);

                /*for (long i = l1 - 1; i < r1; i++)
                {
                    if (str[i] == '1') sch++;
                }
                 Console.WriteLine(str);
                Console.WriteLine(sch);

            }

        }
    }
}*/


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

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

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

            var r = new StringBuilder();

            while (true)
            {
                if (a > b)
                {
                    if (b != 1)
                        r.Append(a/b);
                    else
                    {
                        r.Append(a/b - 1);
                    }
                    r.Append('A');
                    a %= b;
                }
                else
                {
                    if (a != 1)
                        r.Append(b/a);
                    else
                    {
                        r.Append(b/a - 1);
                    }
                    r.Append('B');
                    b %= a;
                }

                if ((a == 0 || b == 0))
                {
                    if ((a + b) != 1)
                    {
                        writer.WriteLine("Impossible");
                        writer.Flush();
                        return;
                    }
                    break;
                }
            }

            writer.WriteLine(r.ToString());
            writer.Flush();
        }

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


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

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

        private static void Main(string[] args)
        {
            var lucky = new List<long> {4, 7};

            int l = Next();
            int r = Next();

            int first = 0;
            int last = 1;
            long d = 10;
            do
            {
                for (int i = first; i <= last; i++)
                {
                    lucky.Add(d*4 + lucky[i]);
                    lucky.Add(d*7 + lucky[i]);
                }
                d *= 10;
                first = last + 1;
                last = lucky.Count - 1;
            } while (lucky[last] < r);

            long sum = 0;

            lucky.Sort();

            int il = lucky.BinarySearch(l);
            if (il < 0)
                il = ~il;

            int ir = lucky.BinarySearch(r);
            if (ir < 0)
                ir = ~ir;

            if (il == ir)
            {
                sum = lucky[ir]*(r - l + 1);
            }
            else
            {
                sum = lucky[il]*(lucky[il] - l + 1);
                sum += lucky[ir]*(r - lucky[ir - 1]);

                for (int i = il + 1; i < ir; i++)
                {
                    sum += lucky[i]*(lucky[i] - lucky[i - 1]);
                }
            }

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

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


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

namespace ProgrammingContest.Codeforces.Round91 {
    class A {
        static List<long> num = new List<long>();
        static void gen(long x) {
            if (x <= 10000000000L) {
                num.Add(x);
                gen(x * 10 + 4);
                gen(x * 10 + 7);
            }
        }

        //
        static void Main() {
            var xs = Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), int.Parse);
            int a = xs[0],
                b = xs[1];
            gen(0);
            num.Sort();
            long res = 0;
            for (int i = 0; ; i++) {
                if (num[i+1] < a) {
                    continue;
                }
                if (num[i+1] > b) {
                    res += (b - Math.Max(num[i], a-1)) * num[i + 1];
                    break;
                }
                res += (num[i + 1] - Math.Max(num[i], a-1)) * num[i + 1];
            }
            Console.WriteLine(res);
        }
    }
}


using System;
using System.Threading;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using System.Text;
namespace Codeforces
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string s = Console.ReadLine();
            if (Petals(s))
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }

        static bool Petals(string landscape)
        {
            string substring = string.Empty;
            var values = new [] {"ABC", "ACB", "BCA", "BAC", "CAB", "CBA"};
            bool result = false;
            for (int i = 0; i < landscape.Length - 2; i++)
            {
                if (landscape.Substring(i, 3).Contains("ABC") || landscape.Substring(i, 3).Contains("ACB") || landscape.Substring(i, 3).Contains("BCA") || landscape.Substring(i, 3).Contains("BAC") || landscape.Substring(i, 3).Contains("CAB") || landscape.Substring(i, 3).Contains("CBA"))
                {
                    result = true;
                    break;
                }
                else
                    result = false;
            }
            return result;
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using static CF.ReadNext;

namespace CF
{
    public static class Program
    {
        private static void Main()
        {
            var s = Console.ReadLine();
            for (int i = 0; i <= s.Length - 3; i++)
            {
                var substring = string.Concat(s.Substring(i, 3).OrderBy(c=>c));
                if (substring == "ABC")
                {
                    Console.WriteLine("YES");
                    return;
                }
            }
            Console.WriteLine("NO");
        }
    }

    public static class ReadNext
    {
        public static int NextInt()
        {
            var next = ReadUntilSpace();
            return int.Parse(next);
        }

        public static double NextDouble()
        {
            var next = ReadUntilSpace();
            return double.Parse(next);
        }

        public static string NextWord()
        {
            return ReadUntilSpace();
        }

        private static bool IsWhiteSpace(int n)
        {
            return n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1;
        }

        private static string ReadUntilSpace()
        {
            var result = "";

            var n = Console.Read();
            // read whitespace
            while (IsWhiteSpace(n))
            {
                n = Console.Read();
            }

            // read characters
            while (!IsWhiteSpace(n))
            {
                result += (char)n;
                n = Console.Read();
            }

            return result;
        }
    }
}


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

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

            int counter = 0;
            for (int i = 2; i < A; i++)
                counter += sumOfBase(A, i);

            Console.WriteLine("{0}/{1}", counter / gcd(counter, A-2), (A-2) / gcd(counter, A-2));
        }
        private static int gcd(int a, int b)
        {
            return b == 0 ? a : gcd(b, a % b);
        }
        private static int sumOfBase(int A, int Base)
        {
            int ans = 0;
            while (A > 0)
            {
                ans += A % Base;
                A /= Base;
            }
            return ans;
        }

    }
}


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

namespace CodeForce
{
    class _13a
    {
        public static void Main()
        {
            var line = Console.ReadLine();
            var n = int.Parse(line);
            var sum = 0;
            for (var i = 2; i < n; i++)
            {
                var num = n;
                while (num != 0)
                {
                    sum += num % i;
                    num /= i;
                }
            }
            var low = n - 2;
            for (var i = 2; i < 1010; i++)
            {
                while (low % i == 0 && sum % i == 0)
                {
                    low /= i;
                    sum /= i;
                }
            }
            Console.WriteLine("{0}/{1}", sum, low);
        }
    }
}


using System;

namespace Codeforces
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			new Solution();
		}
	}
	class Solution
	{
		public Solution(){
            int x = int.Parse(Console.ReadLine());
            if (x == 1)
            {
                Console.WriteLine("1");
                return;
            }
            String sx = x.ToString();
            int count = 1;
            for (int i = 1; i <= Math.Sqrt(x); i++)
            {
                char[] si = i.ToString().ToCharArray();
                if (x % i == 0 && sx.IndexOfAny(si) >= 0)
                {
                    count++;
                }
                if (i > 1 && i != x / i && x % (x / i) == 0)
                {
                    char[] ssi = (x / i).ToString().ToCharArray();
                    if(sx.IndexOfAny(ssi)>=0)
                        count++;
                }
            }
            Console.Write(count);
            //Console.ReadKey(true);

		}
	}
}
/*A
int n=int.Parse(Console.ReadLine());
Console.Write(n+" ");
for (int i = 1; i < n; i++)
{
    Console.Write(i + " ");
}
*/

/* B
            int x = int.Parse(Console.ReadLine());
            if (x == 1)
            {
                Console.WriteLine("1");
                return;
            }
            String sx=x.ToString();
            int count=1;
            for (int i = 1; i <= Math.Sqrt(x); i++)
            {
                char[] si=i.ToString().ToCharArray();
                if (x%i==0 && sx.IndexOfAny(si)>=0)
                {
                        count++;
                 }
            }
            Console.Write(count);
            */
/*C
            int n = int.Parse(Console.ReadLine());
            String s=Console.ReadLine();
            String[] z=s.Split(' ');
            int[] c = new int[n];
            for (int i = 0; i < n; i++)
            {
                c[i] = int.Parse(z[i]);
            }
            int count = 0;
            for (int i = 1; i < n; i++)
            {
                if (c[i - 1] > c[i]) count++;
                if (count > 2)
                {
                    Console.WriteLine("NO");
                    return;
                }
            }
            if (count == 2 || count ==0)
            {
                Console.WriteLine("YES");
                return;
            }
            if (count == 1)
            {
                int i=0;
                while (c[i] <= c[i + 1]) i++;
                int p=c[i];
                int t=c[i+1];i++;
                while (i<n && c[i] == t) i++;
                if (i == n)
                {
                    Console.WriteLine("YES");
                    return;
                }
                if (c[i] == p)
                {
                    Console.WriteLine("YES");
                }
                else
                {
                    Console.WriteLine("NO");
                }
            }
            */


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

class PairVariable : IComparable<PairVariable>
{
    public int a, b;
    public PairVariable()
    {
        a = b = 0;
    }
    public PairVariable(string s)
    {
        string[] q = s.Split();
        a = int.Parse(q[0]);
        b = int.Parse(q[1]);
    }
    public PairVariable(int a, int b)
    {
        this.a = a;
        this.b = b;
    }

    public int CompareTo(PairVariable other)
    {
        return other.a.CompareTo(this.a);
    }
}

namespace ConsoleApplication254
{

    class Program
    {

        static bool foo(string s1, string s2)
        {
            for (int i = 0; i < s1.Length; i++)
            {
                for (int e = 0; e < s2.Length; e++)
                {
                    if (s1[i] == s2[e])
                    {
                        return true;
                    }
                }
            }
            return false;
        }
        static void Main(string[] args)
        {
            string[] ss = Console.ReadLine().Split();
            int n = int.Parse(ss[0]);
            List<int> d = new List<int>();
            int ans = 0;
            for (int i = 1; i <= Math.Sqrt(n); i++)
            {
                if (n % i == 0)
                {
                    d.Add(i);
                }
            }

            int x = d.Count;
            for (int i = 0; i < x; i++)
            {
                if (n / d[i] != d[i])
                {
                    d.Add(n / d[i]);
                }
            }

            string z = n.ToString();
            for (int i = 0; i < d.Count; i++)
            {
                string s = d[i].ToString();

                if (foo(s, z))
                {
                    ans++;
                }
            }
            Console.WriteLine(ans);
        }
    }
}


using System;
using System.Linq;

class Program
{
    static void Main()
    {
        string str = Console.ReadLine();
        int n = int.Parse(str);

        var squares = new int[n, 4];

        int minX = -1, maxX = -1, minY = -1, maxY = -1;

        for (int i = 0; i < n; i++)
        {
            str = Console.ReadLine();
            var q = str.Split(new char[] {' '});

            squares[i, 0] = int.Parse(q[0]);
            squares[i, 1] = int.Parse(q[1]);
            squares[i, 2] = int.Parse(q[2]);
            squares[i, 3] = int.Parse(q[3]);

            if (i == 0)
            {
                minX = squares[i, 0];
                minY = squares[i, 1];
                maxX = squares[i, 2];
                maxY = squares[i, 3];
            }

            if (minX > squares[i, 0]) minX = squares[i, 0];
            if (minY > squares[i, 1]) minY = squares[i, 1];
            if (maxX < squares[i, 2]) maxX = squares[i, 2];
            if (maxY < squares[i, 3]) maxY = squares[i, 3];
            // Console.WriteLine(str);
        }

        if (maxX - minX != maxY - minY)
        {
            Console.WriteLine("NO");
            return;
        }

        int square1 = (maxX - minX) * (maxY - minY);
        int square2 = 0;

        for (int i = 0; i < n; i++)
        {
            square2 += (squares[i, 2] - squares[i, 0]) * (squares[i, 3] - squares[i, 1]);
        }

        if (square1 != square2)
        {
            // Console.WriteLine("NO 2 1: {0} 2: {1}", square1, square2);
            Console.WriteLine("NO");
            return;
        }

        Console.WriteLine("YES");
    }
}


using System;
using System.Linq;
class Demo
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int S = 0;
        int minx = 31401, miny = 31401, maxx = 0, maxy = 0;
        while (n-- > 0)
        {
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            S += (a[2] - a[0]) * (a[3] - a[1]);
            if (a[0] < minx) minx = a[0];
            if (a[1] < miny) miny = a[1];
            if (a[2] > maxx) maxx = a[2];
            if (a[3] > maxy) maxy = a[3];
        }
        string ans = maxx - minx == maxy - miny && Math.Pow(maxx - minx, 2) == S ? "YES" : "NO";
        Console.WriteLine(ans);
    }
}


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

namespace A
{
    class Program
    {
        static int Dist(int x1, int y1, int x2, int y2)
        {
            return ((x1 - x2) * (x1 - x2) + (y2 - y1) * (y2 - y1));
        }
        static bool F(int x1, int y1, int x2, int y2, int x3, int y3)
        {
            if (x1 == x2 && y1 == y2) return false;
            if (x1 == x3 && y1 == y3) return false;
            if (x3 == x2 && y3 == y2) return false;
            int a = Dist(x1, y1, x2, y2);
            int b = Dist(x1, y1, x3, y3);
            int c = Dist(x3, y3, x2, y2);

            if (a + b == c)
                return true;
            if (a == b + c)
                return true;
            if (b == a + c)
                return true;
            return false;
        }

        static bool Ans(int x1, int y1, int x2, int y2, int x3, int y3)
        {
            if (F(x1 + 1, y1, x2, y2, x3, y3)) return true;
            if (F(x1 - 1, y1, x2, y2, x3, y3)) return true;
            if (F(x1, y1 + 1, x2, y2, x3, y3)) return true;
            if (F(x1, y1 - 1, x2, y2, x3, y3)) return true;
            return false;
        }
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int x1 = int.Parse(s[0]);
            int y1 = int.Parse(s[1]);
            int x2 = int.Parse(s[2]);
            int y2 = int.Parse(s[3]);
            int x3 = int.Parse(s[4]);
            int y3 = int.Parse(s[5]);
            if (F(x1, y1, x2, y2, x3, y3))
            {
                Console.WriteLine("RIGHT");
            }
            else
            {
                if (Ans(x1, y1, x2, y2, x3, y3))
                {
                    Console.WriteLine("ALMOST");
                    return;
                }
                if (Ans(x2, y2, x1, y1, x3, y3))
                {
                    Console.WriteLine("ALMOST");
                    return;
                }
                if (Ans(x3, y3, x1, y1, x2, y2))
                {
                    Console.WriteLine("ALMOST");
                    return;
                }
                Console.WriteLine("NEITHER");
            }
        }
    }
}


using System;
using System.Linq;

namespace _18A
{
    class Program
    {
        static int[] dx = new[] { -1, 1, 0, 0 };
        static int[] dy = new[] { 0, 0, -1, 1 };

        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int[] x = new int[3], y = new int[3];
            for (int i = 0; i < 6; i++)
            {
                if (i % 2 == 0)
                    x[i / 2] = int.Parse(input[i]);
                else
                    y[i / 2] = int.Parse(input[i]);
            }

            bool right = Check(x, y), almost = false;
            if (!right)
            {
                for (int i = 0; i < 4 && !almost; i++) // direction
                {
                    for (int j = 0; j < 3 && !almost; j++) // point
                    {
                        x[j] += dx[i]; y[j] += dy[i];
                        almost = Check(x, y);
                        x[j] -= dx[i]; y[j] -= dy[i];
                    }
                }
            }

            if (right) Console.WriteLine("RIGHT");
            else if (almost) Console.WriteLine("ALMOST");
            else Console.WriteLine("NEITHER");
        }

        static bool Check(int[] x, int[] y)
        {
            if (x.All(a => a == x[0]) || y.All(a => a == y[0]))
                return false;

            for (int i = 0; i < 3; i++)
                for (int j = i + 1; j < 3; j++)
                    if (x[i] == x[j] && y[i] == y[j])
                        return false;

            double[] dist = new[]
            {
                Distance(x[0], y[0], x[1], y[1]),
                Distance(x[1], y[1], x[2], y[2]),
                Distance(x[2], y[2], x[0], y[0])
            };
            int maxIndex = -1; double max = 0;
            for (int i = 0; i < 3; i++)
                if (dist[i] > max)
                {
                    max = dist[i];
                    maxIndex = i;
                }

            double sum = 0;
            for (int i = 0; i < 3; i++)
                if (i != maxIndex)
                    sum += dist[i];

            return sum == max;
        }

        static double Distance(double x1, double y1, double x2, double y2)
        {
            return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
        }
    }
}


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

namespace ConsoleApp2
{
    class Program
    {
        const long MOD = 1000000007;
        static int before(int x, int ost)
        {
            if (x < ost)
                return 0;
            return (x - ost) / 3 + 1;
        }
        static void Main(string[] args)
        {
            int n, l, r;
            string[] input = Console.ReadLine().Split();
            n = int.Parse(input[0]);
            l = int.Parse(input[1]);
            r = int.Parse(input[2]);
            long[,] dp = new long[n, 3];
            dp[0, 0] = before(r, 0) - before(l - 1, 0);
            dp[0, 1] = before(r, 1) - before(l - 1, 1);
            dp[0, 2] = before(r, 2) - before(l - 1, 2);
            for (int i = 1; i < n; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    int pred0 = j;
                    int pred1 = j - 1;
                    int pred2 = j - 2;
                    if (pred1 < 0)
                        pred1 += 3;
                    if (pred2 < 0)
                        pred2 += 3;
                    dp[i, j] += dp[i - 1, pred0] * dp[0, 0];
                    dp[i, j] %= MOD;
                    dp[i, j] += dp[i - 1, pred1] * dp[0, 1];
                    dp[i, j] %= MOD;
                    dp[i, j] += dp[i - 1, pred2] * dp[0, 2];
                    dp[i, j] %= MOD;
                }
            }
            /*for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < 3; j++)
                    Console.Write($"{dp[i, j]} ");
                Console.WriteLine();
            }*/
            Console.WriteLine((dp[n - 1, 0])%MOD);
        }
    }
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		int N = I[0], l = I[1], r = I[2];
		var mx = new int[3];
		mx[0] = (r + 3) / 3 - (l + 2) / 3;
		mx[1] = (r + 2) / 3 - (l + 1) / 3;
		mx[2] = (r + 1) / 3 - l / 3;
		var dp = new long[N + 1, 3];
		dp[0, 0] = 1;
		for (var n = 1; n <= N; n++)
			for (var m = 0; m < 3; m++)
				for (var x = 0; x < 3; x++)
					dp[n, m] = (dp[n, m] + mx[x] * dp[n - 1, (m - x + 3) % 3] % MOD) % MOD;
		WriteLine(dp[N, 0]);
	}
}


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

class Program
{

    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        string str = Console.ReadLine();
        int[] arr = new int[n];

        HashSet<char> set = new HashSet<char>();
        for (int i = 0; i < n; i++)
        {
            if (char.IsUpper(str[i]))
            {
                arr[i] = 0;
                set = new HashSet<char>();
            }

            else
            {
                set.Add(str[i]);
                arr[i] = set.Count();
            }
        }

        Console.WriteLine(arr.Max());
    }
}


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

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Int32.Parse(Console.ReadLine());
            string str = Console.ReadLine();
            int currentMax = 0;
            for (int i = 0; i < n; ++i)
            {
                if(char.IsLower(str, i))
                {
                    int max = 1;
                    for(int j = i+1; j<n; ++j)
                    {
                        if (char.IsLower(str, j))
                        {
                            if (!str.Substring(i, j - i).Contains(str[j]))
                                max++;
                        }
                        else goto exit;
                     }
                exit:
                    if (max > currentMax)
                        currentMax = max;
                }
            }
            Console.WriteLine(currentMax);
        }
    }
}


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());
            int[] a = new int[n+4];
            string[] s = Console.ReadLine().Split(' ');
            int ans = 0;
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(s[i]);
                if (a[i] == 1)
                    ans++;
            }
            for (int i = 0; i < n; i++)
                if (a[i] == 1 && a[i + 1] == 0 && a[i + 2] == 1)
                    ans++;

            Console.WriteLine(ans);
           // Console.ReadLine();
        }
    }
}


using System;

class Program
{

    static void Main()
    {
        string[] t = new string[1];
        t[0] = Console.ReadLine();

        int n = int.Parse(t[0]);
        int[] arr = new int[n];
        t[0] = Console.ReadLine();

        t = t[0].Split();

        for (int j = 0; j < n; ++j)
        {
            arr[j] = int.Parse(t[j]);
        }

        int i = 0, ans = 0;

        while (i < n && arr[i] == 0)
            ++i;

        for (; i < n;)
        {
            int q = 0;

            if (arr[i] != 0)
            {
                ++ans;
                ++i;
                continue;
            }

            while (i < n && arr[i] == 0)
            {
                ++i; ++q;
                if (i == n) q = 0;
            }

            if (q == 1)
                ++ans;

        }

        Console.WriteLine(ans);
    }
}


using System;
class Program
{
    static void Main()
    {
      int ans = 0;
        string[] tokens = Console.ReadLine().Split();
        long l = long.Parse(tokens[0]);
        long r = long.Parse(tokens[1]);
        for (int i = 0; i <= 32; ++i) {
          for (int j = 0; j <= 20; ++j)
          {
            long x = (long)Math.Pow(2, i) * (long)Math.Pow(3, j);
            if (x >= l && x <=r)
              ans++;
          }
        }
        Console.WriteLine(ans);

    }

}


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

namespace Codeforces
{
	class Program
	{
		static void Main(string[] args)
		{
			string input1 = Console.ReadLine();
			//string input2 = Console.ReadLine();

			//string input3 = Console.ReadLine();
			//string input4 = Console.ReadLine();

			var inputs1 = input1.Split(new[] {' ', '}', '{', ','}, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
			//var inputs2 = input2.Split(new[] { ' ', '}', '{', ',' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToList();
			//var inputs3 = input3.Split(new[] { ' ', '}', '{', ',' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
			//var inputs4 = input4.Split(new[] { ' ', '}', '{', ',' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();

			long l = inputs1[0];
			long r = inputs1[1];

			long end2 = (long)Math.Log(r, 2) + 1;

			var set = new HashSet<long>();
			for (long i = 0; i < end2 + 1; i++)
			{
				long start3 = (long)Math.Log(l / Math.Pow(2, i), 3);
				if (start3 < 0)
				{
					start3 = 0;
				}

				long end3 = (long)Math.Log(r / Math.Pow(2, i), 3) + 1;
				if (end3 < 0)
				{
					end3 = 0;
				}

				for (long j = start3; j < end3 + 1; j++)
				{
					long current = (long)(Math.Pow(2, i) * Math.Pow(3, j));
					if (current < l || current > r)
					{
						continue;
					}

					set.Add(current);
				}
			}

			Console.WriteLine(set.Count);
		}

		public class Team
		{
			public string Name { get; set; }

			public int Points { get; set; }

			public int GoalsFor { get; set; }

			public int GoalsAgainst { get; set; }
		}

		static long Factorial(long a)
		{
			return a > 1 ? a * Factorial(a - 1) : 1;
		}
	}
}


using System;
using System.Linq;

namespace CSharp
{
    public class _822A
    {
        public static void Main(string[] args)
        {
            Console.WriteLine(Enumerable.Range(1, Console.ReadLine().Split().Select(token => int.Parse(token)).Min()).Aggregate((a, b) => a * b));
        }
    }
}


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

        var s = Array.ConvertAll( Console.ReadLine().Split(), Convert.ToInt32 );
        int a = s[0], b = s[1];

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

        Console.WriteLine( kq( Math.Min( a, b ) ) );

    }

    private static long kq(int p)
    {
        if(p == 1)
            return 1;
        else
            return p * kq( p - 1 );
    }
}


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

namespace ConsoleApplication6
{

    class Program
    {
        static void Main(string[] args)
        {
            int[,] tabl = new int[3, 3];
            int[,] tablrezult = new int[3, 3];
            string[] str1 = new string[3];
            for (int i = 0; i < 3; i++)
            {
                str1[i] = Console.ReadLine();
            }
            string[] strin1 = str1[0].Split(' ');
            string[] strin2 = str1[1].Split(' ');
            string[] strin3 = str1[2].Split(' ');
            for (int i = 0; i < 3; i++)
            {
                tabl[0, i] = int.Parse(strin1[i]);
                tabl[1, i] = int.Parse(strin2[i]);
                tabl[2, i] = int.Parse(strin3[i]);
            }

            tablrezult[2, 1] = tabl[2, 0] + tabl[2, 2] + tabl[1, 1] + tabl[2, 1];

            tablrezult[0, 1] = tabl[1, 1] + tabl[0, 0] + tabl[0, 2] + tabl[0, 1];
            tablrezult[1, 0] = tabl[0, 0] + tabl[2, 0] + tabl[1, 1] + tabl[1, 0];
            tablrezult[1, 2] = tabl[2, 2] + tabl[1, 1] + tabl[0, 2] + tabl[1, 2];

            tablrezult[0, 0] = tabl[1, 0] + tabl[0, 1] + tabl[0, 0];

            tablrezult[2, 2] = tabl[1, 2] + tabl[2, 1] + tabl[2, 2];

            tablrezult[0, 2] = tabl[1, 2] + tabl[0, 1] + tabl[0, 2];

            tablrezult[2, 0] = tabl[1, 0] + tabl[2, 1] + tabl[2, 0];

            tablrezult[1, 1] = tabl[2, 1] + tabl[1, 2] + tabl[0, 1] + tabl[1, 0] + tabl[1, 1];

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if ((tablrezult[i, j] % 2) == 0)
                    {
                        tablrezult[i, j] = 1;
                    }
                    else { tablrezult[i, j] = 0; }

                }
            }

                Console.WriteLine(tablrezult[0, 0].ToString() + tablrezult[0, 1].ToString() + tablrezult[0, 2].ToString());
                Console.WriteLine(tablrezult[1, 0].ToString() + tablrezult[1, 1].ToString() + tablrezult[1, 2].ToString());
                Console.WriteLine(tablrezult[2, 0].ToString() + tablrezult[2, 1].ToString() + tablrezult[2, 2].ToString());

            Console.ReadLine();
        }

    }
}


using System;

namespace ConvexShape
{
    class Program
    {
        public static void Main(string[] args)
        {
            int[,] lights = new int[3,3];
            int[,] lightsCumulative = new int[3, 3];
            for (int i = 0; i < 3; ++i)
            {
                string s = Console.ReadLine();
                string[] nums = s.Split(new[]{' '}, StringSplitOptions.RemoveEmptyEntries);
                for (int j = 0; j < 3; ++j )
                {
                    lights[i, j] = int.Parse(nums[j]);
                }
            }

            for (int i = 0; i < 3; ++i)
            {
                for (int j = 0; j < 3; ++j)
                {
                    int l=0, r=0, t=0, b=0;
                    l = (i - 1) >= 0 && (i - 1) < 3 ? lights[i - 1,j] : 0;
                    r = (i + 1) >= 0 && (i + 1) < 3 ? lights[i + 1,j] : 0;
                    b = (j + 1) >= 0 && (j + 1) < 3 ? lights[i ,j+1] : 0;
                    t = (j - 1) >= 0 && (j - 1) < 3 ? lights[i ,j-1] : 0;
                    lightsCumulative[i, j] = lights[i, j] + l + r + t + b;

                    Console.Write((lightsCumulative[i, j] + 1) % 2);
            }
                Console.WriteLine();
            }

        }

    }
}


using System;
using System.Collections.Generic;

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return Double.Parse(next());
    }
}

class Myon
{
    Scanner cin;
    Myon() { }

    public static void Main()
    {
        new Myon().calc();
    }

    void calc()
    {
        cin = new Scanner();
        long ret = 0;
        int n, m, t;
        n = cin.nextInt();
        m = cin.nextInt();
        t = cin.nextInt();
        int i, j;
        const int MAX = 100;
        long[] choosen = new long[MAX];
        long[] choosem = new long[MAX];
        choosen[0] = choosem[0] = 1;
        for (i = 0; i < n; i++)
        {
            for (j = MAX - 1; j > 0; j--)
            {
                choosen[j] += choosen[j - 1];
            }
        }
        for (i = 0; i < m; i++)
        {
            for (j = MAX - 1; j > 0; j--)
            {
                choosem[j] += choosem[j - 1];
            }
        }
        for (i = 4; i < t; i++)
        {
            ret += choosen[i] * choosem[t - i];
        }
        Console.WriteLine(ret);

    }
}


using System;

namespace CSharp
{
    class _131C
    {
        public static void Main()
        {
            var tokens = Console.ReadLine().Split();

            int n = int.Parse(tokens[0]);
            int m = int.Parse(tokens[1]);
            int t = int.Parse(tokens[2]);

            long ways = 0;

            for (int b = 4; b <= n; b++)
            {
                int g = t - b;

                if (g >= 1 && g <= m)
                {
                    ways += Choose(n, b) * Choose(m, g);
                }
            }

            Console.WriteLine(ways);
        }

        private static long Choose(int n, int k)
        {
            long result = 1;

            for (int i = 0; i < k; i++)
            {
                result *= n - i;
                result /= i + 1;
            }

            return result;
        }
    }
}


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

namespace codeforces
{

    class Program
    {
        public static int ReadInt() => Int32.Parse(Console.ReadLine());

        public static int[] ReadInts() =>
            Console.ReadLine().Split(new[]{' '}, StringSplitOptions.RemoveEmptyEntries)
                .Select(Int32.Parse).ToArray();

        static void Main(string[] args)
        {
            int n = ReadInt();
            var grades = ReadInts();
            Array.Sort(grades);
            var todo = n*9 - grades.Sum() * 2;

            int i;
            for (i = 0; i < grades.Length && todo > 0; i++)
            {
                var grade = grades[i];
                var plus = (5 - grade)*2;
                todo -= plus;
            }
            Console.WriteLine(i);
        }
    }
}


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

namespace cs
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int twos = 0, threes = 0, fours = 0;
            int[] scores = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            for (int i = 0; i < scores.Length; i++)
            {
                if (scores[i] == 2)
                    twos++;
                else if (scores[i] == 3)
                    threes++;
                else if (scores[i] == 4)
                    fours++;
            }
            double EPSILON = 0E-12;
            int count = 0;
            int sum = scores.Sum();
            while ((double)sum / n - 4.5 < EPSILON && twos + threes + fours > 0)
            {
                if (twos > 0)
                {
                    twos--;
                    sum += 3;
                    count++;
                }
                else if (threes > 0)
                {
                    threes--;
                    sum += 2;
                    count++;
                }
                else if (fours > 0)
                {
                    fours--;
                    sum += 1;
                    count++;
                }
            }

            Console.WriteLine(count);
        }
    }
}


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

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

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

            if (k > a && k > b)
                writer.WriteLine("-1");
            else
            {
                int ma = a%k;
                int mb = b%k;

                if (ma > 0 && b/k == 0 || mb > 0 && a/k == 0)
                    writer.WriteLine("-1");
                else
                    writer.WriteLine(a/k + b/k);
            }

            writer.Flush();
        }

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


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

namespace Codeforces
{
	internal class Template
	{
		private void Solve()
		{
			var k = cin.NextInt();
			var a = cin.NextInt();
			var b = cin.NextInt();

			if (k > a && (b%k != 0 || b == 0))
			{
				Console.WriteLine(-1);
				return;
			}
			if (k > b && (a % k != 0 || a == 0))
			{
				Console.WriteLine(-1);
				return;
			}

			if (k > a && k > b)
			{
				Console.WriteLine(-1);
				return;
			}
			var count = a / k + b / k;
			Console.WriteLine(count);
		}

		private static readonly Scanner cin = new Scanner();

		private static void Main()
		{
#if DEBUG
			var inputText = File.ReadAllText(@"..\..\input.txt");
			var testCases = inputText.Split(new[] { "input" }, StringSplitOptions.RemoveEmptyEntries);
			var consoleOut = Console.Out;
			for (var i = 0; i < testCases.Length; i++)
			{
				var parts = testCases[i].Split(new[] { "output" }, StringSplitOptions.RemoveEmptyEntries);
				Console.SetIn(new StringReader(parts[0].Trim()));
				var stringWriter = new StringWriter();
				Console.SetOut(stringWriter);
				var sw = Stopwatch.StartNew();
				new Template().Solve();
				sw.Stop();
				var output = stringWriter.ToString();

				Console.SetOut(consoleOut);
				var color = ConsoleColor.Green;
				var status = "Passed";
				if (parts[1].Trim() != output.Trim())
				{
					color = ConsoleColor.Red;
					status = "Failed";
				}
				Console.ForegroundColor = color;
				Console.WriteLine("Test {0} {1} in {2}ms", i + 1, status, sw.ElapsedMilliseconds);
			}
			Console.ReadLine();
			Console.ReadKey();
#else
			new Template().Solve();
			Console.ReadLine();
#endif
		}
	}

	internal class Scanner
	{
		private string[] s = new string[0];
		private int i;
		private readonly char[] cs = { ' ' };

		public string NextString()
		{
			if (i < s.Length) return s[i++];
			var line = Console.ReadLine() ?? string.Empty;
			s = line.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			i = 1;
			return s.First();
		}

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

		public int NextInt()
		{
			return int.Parse(NextString());
		}

		public long NextLong()
		{
			return long.Parse(NextString());
		}
	}
}


using System;
using System.Collections.Generic;

namespace CodeForces
{
    static class Program
    {
        static void Main()
        {
            const string filePath = @"Data/MR18R2C.txt";
            if (System.IO.File.Exists(filePath))
            {
                Console.SetIn(new System.IO.StreamReader(filePath));
            }

            IProblem counter = new MR18R2C();

            foreach (var result in counter.GetResults())
            {
                Console.WriteLine(result);
            }
        }
    }

    internal class MR18R2C : ProblemBase
    {
        public override IEnumerable<string> GetResults()
        {
            var ints = this.ReadLongArray();
            var la = ints[0];
            var ra = ints[1];
            var ta = ints[2];

            ints = this.ReadLongArray();
            var lb = ints[0];
            var rb = ints[1];
            var tb = ints[2];

            var l = Math.Min(la, lb);

            la -= l;
            ra -= l;
            lb -= l;
            rb -= l;

            long result = 0;

            if (ta == tb)
            {
                result = GetLength(la, ra, lb, rb);
            }
            else
            {
                var t = Math.Max(ta, tb);
                var delta = t - Math.Min(ta, tb);

                var d = (int)this.Gcd(delta, t);
                if (d == 1)
                {
                    result = Math.Min(ra - la + 1, rb - lb + 1);
                }
                else // cycles
                {
                    var aDiff = (la / d) * d;
                    la -= aDiff;
                    ra -= aDiff;

                    var bDiff = (lb / d) * d;
                    lb -= bDiff;
                    rb -= bDiff;

                    var deltas = new[] {-2, -1, 0, 1, 2};

                    for (int i = 0; i < deltas.Length; i++)
                    {
                        long current = GetLength(la, ra, lb + deltas[i] * d, rb + deltas[i] * d);
                        if (current >= result)
                        {
                            result = current;
                        }

                    }
                }
            }

            yield return result.ToString();
        }

        private static long GetLength(long la, long ra, long lb, long rb)
        {
            var left = Math.Max(la, lb);
            var right = Math.Min(ra, rb);
            if (right >= left)
            {
                return right - left + 1;
            }

            return 0;
        }

        private long Gcd(long a, long b)
        {
            var first = a;
            var second = b;

            while (second != 0)
            {
                var temp = first % second;
                first = second;
                second = temp;
            }
            return first;
        }

    }

    internal class MR18R2D : ProblemBase
    {
        public override IEnumerable<string> GetResults()
        {
            yield return "n/a";
        }
    }

    abstract class MultipleTestsBase : ProblemBase
    {
        public sealed override IEnumerable<string> GetResults()
        {
            var t = Convert.ToInt32(Console.ReadLine());
            for (int testCaseNumber = 0; testCaseNumber < t; testCaseNumber++)
            {
                foreach (var result in GetTestResult(testCaseNumber + 1))
                {
                    yield return result;
                }

            }

        }

        protected abstract IEnumerable<string> GetTestResult(int caseNumber);
    }

    public interface IProblem
    {
        IEnumerable<string> GetResults();
    }

    public abstract class ProblemBase : IProblem
    {
        public void PrintArray<T>(IEnumerable<T> items, string prefixMessage)
        {
            Console.WriteLine("{0}: {1}", prefixMessage, string.Join(",", items));
        }

        public void WriteDiagnostics(string message, params object[] objects)
        {
            Console.WriteLine(message, objects);
        }

        public virtual IEnumerable<string> GetResults()
        {
            yield return "No result";
        }

        protected int[] ReadIntArray()
        {
            return Array.ConvertAll(ReadTokens(), Convert.ToInt32);
        }

        protected long[] ReadLongArray()
        {
            return Array.ConvertAll(ReadTokens(), Convert.ToInt64);
        }

        protected string[] ReadTokens()
        {
            var readLine = Console.ReadLine();
            if (readLine == null)
            {
                throw new Exception("Value read from Console is null");
            }
            return readLine.Split(' ');
        }

        protected int ReadInt32()
        {
            return Convert.ToInt32(Console.ReadLine());
        }
    }
}


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

class Program
{
    class T
    {
        public int X;
        public int Y;

        public T(int x, int y)
        {
            X = x;
            Y = y;
        }
    }
    //////////////////////////////////////////////////

    long gcda(long a, long b,out long x,out long y)
    {
        if (a == 0)
        {
            x = 0; y = 1;
            return b;
        }
        long x1, y1;
        long d = gcda(b % a, a,out x1,out y1);
        x = y1 - (b / a) * x1;
        y = x1;
        return d;
    }

    bool find_any_solution(long a, long b, long c, out long x0, out long y0, out long g)
    {
        g = gcda(Math.Abs(a), Math.Abs(b), out x0, out y0);
        if (c % g != 0)
            return false;
        change(a,b, c, g, ref x0, ref y0);
        return true;
    }

    void change(long a, long b, long c, long g, ref long x0, ref long y0)
    {
        x0 *= c / g;
        y0 *= c / g;
        if (a < 0) x0 *= -1;
        if (b < 0) y0 *= -1;
    }

        //////////////////////////////////////////////////
        void Solution()
    {
        var la = rl;
        var ra = rl;
        var ta = rl;
        var lb = rl;
        var rb = rl;
        var tb = rl;

        //kb*tb=ka*ta+la-lb
        //tb*kb-ta*ka=la-lb
        var c = la - lb;
        //long x = 0;// kb;
        var a = -ta;
        //long y = 0;// ka;
        var b = tb;

        if (c < 0)
        {
            c *= -1;
            a *= -1;
            b *= -1;
        }

        if (c == 0)
        {
            wln(Math.Min(rb, ra) - la + 1);
            return;
        }

        var flag = find_any_solution(a, b, c, out long x, out long y, out long g);
        if (flag)
        {
            wln(Math.Min(rb + y * tb - x * ta, ra) - la + 1);
        }
        else
        {

            var c1 = (c / g) * g;
            var c2 = c1 + g;
            var c0 = c1 - g;
            find_any_solution(a, b, c1, out long x1, out long y1, out long g1);
            find_any_solution(a, b, c2, out long x2, out long y2, out long g2);
            if (c0 < 0)
            {
                c0 *= -1;
                a *= -1;
                b *= -1;
            }
            find_any_solution(a, b, c0, out long x0, out long y0, out long g0);

            var res1 = Math.Min((rb + y1 * tb - x1 * ta), ra) - Math.Max(la, (lb + y1 * tb - x1 * ta)) + 1;
            var res2 = Math.Min((rb + y2 * tb - x2 * ta), ra) - Math.Max(la, (lb + y2 * tb - x2 * ta)) + 1;
            var res0 = Math.Min((rb + y0 * tb - x0 * ta), ra) - Math.Max(la, (lb + y0 * tb - x0 * ta)) + 1;
            wln(Math.Max(0, Math.Max(res0, Math.Max(res1, res2))));
        }
    }

    //////////////////////////////////////////////////

    struct P : IComparable<P>
    {
        public long X;
        public long Y;

        public P(long x, long y)
        {
            X = x;
            Y = y;
        }

        public int CompareTo(P other) => X != other.X ? X.CompareTo(other.X) : Y.CompareTo(other.Y);
        public static int Comparison(P p1, P p2) => p1.CompareTo(p2);

        public static bool operator ==(P p1, P p2) => (p1.X == p2.X) && (p1.Y == p2.Y);
        public static bool operator !=(P p1, P p2) => (p1.X != p2.X) || (p1.Y != p2.Y);

        public static P operator +(P p1, P p2) => new P(p1.X + p2.X, p1.Y + p2.Y);
        public static P operator -(P p1, P p2) => new P(p1.X - p2.X, p1.Y - p2.Y);
    }

    void swap<T>(ref T o1, ref T o2) { var o = o1; o1 = o2; o2 = o; }
    long gcd(long a, long b) => (b != 0) ? gcd(b, a % b) : a;
    long lcm(long a, long b) => a / gcd(a, b) * b;

    long rast2(long x1, long y1, long x2, long y2) => (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
    long rast2(P p1, P p2) => (p1.X - p2.X) * (p1.X - p2.X) + (p1.Y - p2.Y) * (p1.Y - p2.Y);
    long ccw(P p1, P p2, P p3) => p1.X * p2.Y + p1.Y * p3.X + p2.X * p3.Y - p2.Y * p3.X - p3.Y * p1.X - p1.Y * p2.X;

    StringBuilder _sb = new StringBuilder();
    void wln() { _sb.AppendLine(); }
    void wln<T>(T o) { _sb.AppendLine(o.ToString()); }
    void wsp<T>(T o) { _sb.Append(o).Append(" "); }
    void wrt<T>(T o) { _sb.Append(o); }
    void wln(double o) { _sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "{0:F12}", o)); }
    void wsp(double o) { _sb.Append(string.Format(CultureInfo.InvariantCulture, "{0:F12} ", o)); }
    void wrt(double o) { _sb.Append(string.Format(CultureInfo.InvariantCulture, "{0:F12}", o)); }

    List<P> rpa(int n)
    {
        var res = new List<P>(n);
        for (int i = 0; i < n; i++)
            res.Add(new P(rl, rl));
        return res;
    }

    int ri
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind;
            int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            int p = 0;
            while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;
        }
    }
    long rl
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind;
            int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            long p = 0;
            while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;
        }
    }
    double rd
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind; int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            long p = 0, q = 1; while (_ind < _count && _str[_ind] != ' ' && _str[_ind] != '.') p = p * 10 + _str[_ind++] - '0';
            if (_ind < _count && _str[_ind] == '.') { ++_ind; while (_ind < _count && _str[_ind] != ' ') { p = p * 10 + _str[_ind++] - '0'; q *= 10; } }
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return (double)p / q * sign;
        }
    }
    string rs
    {
        get
        {
            _read(); while (_ind < _count && _str[_ind] == ' ') ++_ind;
            var tmp = _str.IndexOf(' ', _ind);
            if (tmp == -1) { var res = _str.Substring(_ind); _count = 0; _ind = 0; return res; }
            var s = _str.Substring(_ind, tmp - _ind); _ind = tmp + 1;
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return s;
        }
    }

    List<int> ria(int n)
    {
        var res = new int[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                int p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;
            }
        }
        _count = 0; _ind = 0; return res.ToList();
    }
    List<long> rla(int n)
    {
        var res = new long[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                long p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;
            }
        }
        _count = 0; _ind = 0; return res.ToList();
    }
    List<double> rda(int n)
    {
        var res = new double[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                long p = 0, q = 1; while (i < m && s[i] != ' ' && s[i] != '.') p = p * 10 + s[i++] - '0';
                if (i < m && s[i] == '.') { ++i; while (i < m && s[i] != ' ') { p = p * 10 + s[i++] - '0'; q *= 10; } }
                res[k++] = (double)p / q * sign;
            }
        }
        _count = 0; _ind = 0; return res.ToList();
    }
    List<string> rsa(int n) { var res = new string[n]; for (int k = 0; k < n; ++k) res[k] = Console.ReadLine(); _count = 0; _ind = 0; return res.ToList(); }
    string _str = null; int _count = 0; int _ind = 0;
    void _read() { if (_ind == _count) { _str = Console.ReadLine(); _count = _str.Length; _ind = 0; } }
    static void Main(string[] args) { new Program().Main(); }
    void Main()
    {
        //Console.SetIn(new StreamReader("input.txt")); Console.SetOut(new StreamWriter("output.txt"));
        Solution();
        Console.Write(_sb);
        //Console.In.Close(); Console.Out.Close();
    }
}


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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){

		int mod=(int)(1e9+7);
		int N=200001;

		int[][] dp=new int[2][];

		dp[0]=new int[N];
		dp[1]=new int[N];
		dp[0][0]=1;

		int[] d=new int[1010];
		d[0]=1;

		int h=0;
		int rmax=0;
		int next;
		int now;
		int rr;
		int gg;
		for(int i=1;i<894;i++){
			next=i%2;
			now=1-next;
			for(int j=0;j<=Math.Min(rmax+i,N-1);j++)dp[next][j]=0;
			for(int j=0;j<=rmax;j++){
				if(dp[now][j]==0)continue;
				rr=j;
				gg=((i-1+1)*(i-1))/2-rr;

				if(r-rr>=i){
					dp[next][rr+i]+=dp[now][j];
					dp[next][rr+i]%=mod;
					if(rmax<rr+i)rmax=rr+i;
					d[i]+=dp[now][j];
					d[i]%=mod;
					h=i;
				}
				if(g-gg>=i){
					dp[next][rr]+=dp[now][j];
					dp[next][rr]%=mod;
					d[i]+=dp[now][j];
					d[i]%=mod;
					h=i;
				}
			}
		}
		//Console.WriteLine(h);
		Console.WriteLine(d[h]);

	}

	int r;
	int g;
	public Sol(){
		var d=ria();
		r=d[0];
		g=d[1];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(){return Console.ReadLine().Split(' ');}
	static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
	static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
	static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}


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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){

		int mod=(int)(1e9+7);
		int N=200001;

		int[][] dp=new int[2][];

		dp[0]=new int[N];
		dp[1]=new int[N];
		dp[0][0]=1;

		int[] d=new int[1010];
		d[0]=1;

		int h=0;
		int rmax=0;
		int next;
		int now;
		int rr;
		int gg;
		for(int i=1;i<894;i++){
			next=i%2;
			now=1-next;
			for(int j=0;j<=Math.Min(rmax+i,N-1);j++)dp[next][j]=0;
			for(int j=0;j<=rmax;j++){
				if(dp[now][j]==0)continue;
				rr=j;
				gg=((i-1+1)*(i-1))/2-rr;

				if(r-rr>=i){
					dp[next][rr+i]+=dp[now][j];
					if(dp[next][rr+i]>mod)dp[next][rr+i]-=mod;
					if(rmax<rr+i)rmax=rr+i;
					d[i]+=dp[now][j];
					if(d[i]>mod)d[i]-=mod;
					h=i;
				}
				if(g-gg>=i){
					dp[next][rr]+=dp[now][j];
					if(dp[next][rr]>mod)dp[next][rr]-=mod;
					d[i]+=dp[now][j];
					if(d[i]>mod)d[i]-=mod;
					h=i;
				}
			}
		}
		//Console.WriteLine(h);
		Console.WriteLine(d[h]%mod);

	}

	int r;
	int g;
	public Sol(){
		var d=ria();
		r=d[0];
		g=d[1];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(){return Console.ReadLine().Split(' ');}
	static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
	static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
	static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
public class Codeforces
{
    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
        reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);
        writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);
        var v1 = ReadInt();
        var v2 = ReadInt();
        var t = ReadInt();
        var d = ReadInt();
        var a = 0;
        for (int i = 0; i < t; i++)
        {
            a += Math.Min(v1 + i * d, v2 + (t - i - 1) * d);
        }
        Write(a);
        reader.Close();
        writer.Close();
    }
    #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<T>(params T[] array)
    {
        WriteArray(array);
    }

    public static void WriteLines<T>(IEnumerable<T> array)
    {
        foreach (var a in array)
            writer.WriteLine(a);
    }
    #endregion
}


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

namespace Takmicenja.CodeForces.CF298
{
    class B
    {
        public static void Main(string[] varg)
        {
            string[] tok = Console.ReadLine().Split(new char[] { ' ' });
            int v1 = int.Parse(tok[0]);
            int v2 = int.Parse(tok[1]);

            tok = Console.ReadLine().Split(new char[] { ' ' });
            int t = int.Parse(tok[0]);
            int d = int.Parse(tok[1]);

            int[] vleft = new int[t];
            vleft[0] = v1;
            for (int i = 1; i < t; i++)
                vleft[i] = vleft[i - 1] + d;

            int[] vright = new int[t];
            vright[0] = v2;
            for (int i = 1; i < t; i++)
                vright[i] = vright[i - 1] + d;

            int maxSpeed = v1>v2?v1:v2;
            int[] vUpper = new int[t];
            for (int i=0;i<t;i++)
            {
                vUpper[i] = vleft[i];
            }
            for (int i=0;i<t;i++)
            {
                if (vUpper[i] > vright[t - i - 1])
                    vUpper[i] = vright[t - i - 1];
            }

            long s = 0;
            for (int i = 0; i < t; i++)
                s += vUpper[i];

            Console.WriteLine(s);

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
public class Codeforces
{
    static void Main()
    {
        var _ = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var a = _[0];
        var c = _[1];
        var a3 = new Stack<int>();
        var a3ctr = 0;
        var b3 = new Stack<int>();
        var c3 = new Stack<int>();
        var c3ctr = 0;
        while (a > 0)
        {
            var rem = a % 3;
            a /= 3;
            a3.Push(rem);
            a3ctr++;
        }
        while (c > 0)
        {
            var rem = c % 3;
            c /= 3;
            c3.Push(rem);
            c3ctr++;
        }
        if (a3ctr > c3ctr)
        {
            for (int i = 0; i < a3ctr - c3ctr; i++)
            {
                c3.Push(0);
            }
            c3ctr = a3ctr;
        }
        else if (c3ctr > a3ctr)
        {
            for (int i = 0; i < c3ctr - a3ctr; i++)
            {
                a3.Push(0);
            }
            a3ctr = c3ctr;
        }
        long res = 0L;
        for (int i = 0; i < a3ctr; i++)
        {
            var ter = new[] { 0, 1, 2 };
            var m = c3.Pop();
            var n = a3.Pop();
            while (n-- != 0)
            {
                m--;
                if (m < 0) m = 2;
            }
            b3.Push(m);
            res += m * (long)Math.Pow(3, (a3ctr - 1 - i));
        }
        Console.WriteLine(res);
    }
}


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

namespace ConsoleApplication2
{

    class Program
    {

        static void Main(string[] args)
        {

            string[] str = Console.ReadLine().Split(' ');
            long a = long.Parse(str[0]);
            long c = long.Parse(str[1]);

            if(a == 0 && c ==0)
            {
                Console.WriteLine(0);
                return;
            }

            int length = (int)Math.Max(Math.Ceiling(Math.Log(a, 3)), Math.Ceiling(Math.Log(c, 3)))+1;

            //Console.WriteLine(length);

            int[] astr = new int[length];
            for (int i = 0; i < length; i++ )
            {
                astr[i] = (int)((a / (int)Math.Pow(3, i)) % 3);
            }

            int[] cstr = new int[length];
            for (int i = 0; i < length; i++)
            {
                cstr[i] = (int)((c / (int)Math.Pow(3, i)) % 3);
            }

            int[] bstr = new int[length];
            for (int i = 0; i < length; i++)
            {
                if (astr[i] <= cstr[i])
                {
                    bstr[i] = cstr[i] - astr[i];
                }
                else
                {
                    bstr[i] = cstr[i] - astr[i] + 3;
                }
            }

            /*
            for (int i = 0; i < length; i++ )
            {
                Console.Write(astr[i]);
            }
            Console.WriteLine();

            for (int i = 0; i < length; i++)
            {
                Console.Write(bstr[i]);
            }
            Console.WriteLine();

            for (int i = 0; i < length; i++)
            {
                Console.Write(cstr[i]);
            }
            Console.WriteLine();
            */

            long res = 0;
            for (int i = 0; i < length; i++)
            {
                //Console.WriteLine(bstr[i] + "  " + (int)Math.Pow(3, i));
                res += bstr[i] * (long)Math.Pow(3, i);
            }
            Console.WriteLine(res);
        }

    }
}


// CodeForces Basic Question For Recursions
//https://codeforces.com/group/MWSDmqGsZm/contest/223339

using System;
using System.Collections;
using System.Diagnostics;

public static class Program
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        for (int i = 0; i < n; i++)
        {
            int[] x = Array.ConvertAll(Console.ReadLine().Split(' '), (item) => Convert.ToInt32(item));
            int[] y = Array.ConvertAll(Console.ReadLine().Split(' '), (item2) => Convert.ToInt32(item2));
            Console.WriteLine(Solve(x, y));
        }
    }
    public static int Solve(int[] x, int[] y)
    {
        int count = 0;
        for (int i = 0; i < 2; i++)
        {
            if (x[i] == 1) count++;
            if (y[i] == 1) count++;
        }
        if(count == 0) return 0;
        if (count == 4) return 2;
        else return 1;
    }
}