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

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

    public static bool NextPermutation(List<int> perm)
    {
      for (int i = perm.Count - 2; i >= 0; i--)
      {
        if (perm[i] < perm[i + 1])
        {
          int min = i + 1;
          for (int j = min; j < perm.Count; j++)
            if (perm[j] > perm[i] && perm[j] < perm[min])
              min = j;

          int tmp = perm[i];
          perm[i] = perm[min];
          perm[min] = tmp;
          perm.Reverse(i + 1, perm.Count - i - 1);
          return true;
        }
      }

      return false;
    }

    static void Main(string[] args)
    {
      long i = 0;
      long ans = 0;
      reader = new StreamReader(Console.OpenStandardInput());
      writer = new StreamWriter(Console.OpenStandardOutput());

      var s = ReadLines(2);
      var mas = s.Select(it => it.Select(ch => ch == 'X' ? 1 : 0).ToArray()).ToArray();

      int n = mas[0].Length;
      if (n < 2)
      {
        Write(0);
      }
      else
      {
        for (i = 0; i < n - 1; i++)
        {
          int ones = mas[0][i] + mas[0][i + 1] + mas[1][i] + mas[1][i + 1];
          if (ones == 1)
          {
            ans++;
            mas[0][i] = mas[0][i + 1] = mas[1][i] = mas[1][i + 1] = 1;
          }
          else if (ones == 0)
          {
            ans++;
            mas[0][i] = mas[0][i + 1] = mas[1][i] = 1;
          }
        }
        Write(ans);
      }

      reader.Close();
      writer.Close();
    }
  }
}


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

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

            string[] numbers = Console.ReadLine().Split();
            double x = Convert.ToDouble(numbers[0]);
            double y = Convert.ToDouble(numbers[1]);
            double xpow = y * Math.Log(x);
            double ypow = x * Math.Log(y);

            if(xpow>ypow)
            {
                Console.WriteLine(">");
            }
            else if(xpow<ypow)
            {
                Console.WriteLine("<");
            }
            else
            {
                Console.WriteLine("=");
            }

        }
    }
}


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

namespace High_School_Become_Human
{
    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)
        {
            writer.WriteLine(Solve(args));
            writer.Flush();
        }

        private static char Solve(string[] args)
        {
            int x = Next();
            int y = Next();

            if (x == y)
                return '=';
            if (x == 1 || y == 3)
                return '<';
            if (y == 1 || x == 3)
                return '>';

            if (Math.Min(x, y) == 2 && Math.Max(x, y) == 4)
                return '=';

            return x > y ? '<' : '>';
        }

        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.IO;
using System.Text;

namespace Malek_Dance_Club
{
    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();

            long prev = 0;
            long count = 1;
            int mod = 1000000007;
            for (int i = s.Length - 1; i >= 0; i--)
            {
                long next;
                if (s[i] == '1')
                {
                    next = (count*count)%mod;
                    next += 2*prev;
                }
                else
                {
                    next = 2*prev;
                }

                count = (count*2)%mod;
                prev = next%mod;
            }

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


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

namespace Project1
{

    class Class1
    {
        static long MOD = 1000000007;
        static long power(long x, long n)
        {
            long r = 1;
            while (n > 0)
            {
                if ((n & 1) == 1)
                {
                    r = (r * x) % MOD;
                }
                x = (x * x) % MOD;
                n >>= 1;
            }
            return r;
        }
        public static void Main()
        {
            string s = System.Console.ReadLine();
            int len = s.Length;
           // long iver_two = power(2,MOD-2);
            long cur = power(2, len-1);
            long cur2 = 1;
            long ans = 0;
            int index=0;
            while (index<len)
            {
              //  cur *= iver_two;
               // cur %= MOD;
                if(s[len-index-1] == '1')
                    ans  = ans + ((cur*cur2)%MOD);
                ans %= MOD;
                cur2 *=2;
                cur2%=MOD;
                index++;

            }
            System.Console.WriteLine(ans);

        }
    }
}


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

namespace ConsoleApplication17
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string s = Console.ReadLine();
            int f = 0, si = 0;

            for (int  i = 1;  i <n ;  i++)
            {
                if (((s[i-1])=='S')&&(s[i]=='F')) f++;
                if (((s[i - 1]) == 'F') && (s[i] == 'S')) si++;

            }
            if (f > si) Console.WriteLine("YES");
            else Console.WriteLine("NO");

        }
    }
}


using System;
using System.Linq;

namespace CodeForcesTest
{
    class Program
    {

        static void Main(string[] args)
        {
            int _ = Convert.ToInt32(Console.ReadLine());
            char[] d = Console.ReadLine().ToCharArray();

            int ttsf = 0;
            int tts = 0;

            for (int i = 0; i < d.Count() - 1; i++)
            {
                if (d[i] == d[i + 1])
                    continue;

                if (d[i] == 'F')
                    tts++;
                else
                    ttsf++;
            }

            if (ttsf > tts)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
        }
    }
}


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

namespace Codeforces
{
    public class PetrAndACombinationLock
    {
        public static void Main()
        {
            StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            new PetrAndACombinationLock().Solve(Console.In, sw);
            sw.Flush();
        }

        public void Solve(TextReader tr, TextWriter tw)
        {
            var n = int.Parse(tr.ReadLine());
            var a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(tr.ReadLine());
            }

            tw.WriteLine(Solve(a));
        }

        public string Solve(int[] v)
        {
            int n = v.Length;
            int maxN = (1 << n);

            for (int i = 0; i < maxN; i++)
            {
                int res = 0;
                for (int x = 0; x < n; x++)
                {
                    if ((i & (1 << x)) == 0)
                    {
                        res += v[x];
                    }
                    else
                    {
                        res -= v[x];
                    }
                }
                if (res % 360 == 0)
                {
                    return "YES";
                }
            }

            return "NO";
        }
    }
}


using System;

namespace NetCore
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] arr = new int[n];
            for(int i = 0; i < n; i++)
            {
                arr[i] = int.Parse(Console.ReadLine());
            }
            bool valid = false;
            int mx = (1 << n);
            for(int i = 0; i < mx; i++)
            {
                int sum = 0;
                int j = 1;
                int counter = 0;
                while(counter < n)
                {
                    if ((j & i) != 0) sum += arr[counter];
                    else sum -= arr[counter];
                    counter++;
                    j <<= 1;
                    sum %= 360;
                }
                if (sum == 0) valid = true;
            }
            Console.WriteLine(valid ? "YES" : "NO");
        }
    }
}


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

namespace Comp_CSHARP
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries);
            int N = int.Parse(input[0]);
            int M = int.Parse(input[1]);
            int Min = int.Parse(input[2]);
            int Max = int.Parse(input[3]);

            IEnumerable<int> T =
                Console.ReadLine().Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);

            int rMin = T.Min();
            int rMax = T.Max();

            if (rMin < Min || rMax > Max)
                goto fail;

            int diff = 0;

            if (rMin > Min)
                diff++;
            if (rMax < Max)
                diff++;

            if (diff > N - M)
                goto fail;

        win:
            Console.WriteLine("Correct");
            return;

        fail:
            Console.WriteLine("Incorrect");
        }
    }
}


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

namespace Data_Recovery
{
    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[] ss = reader.ReadLine().Split(' ');
            int n = int.Parse(ss[0]);
            int m = int.Parse(ss[1]);
            int min = int.Parse(ss[2]);
            int max = int.Parse(ss[3]);

            int m1 = int.MaxValue;
            int m2 = int.MinValue;

            ss = reader.ReadLine().Split(' ');
            for (int i = 0; i < m; i++)
            {
                int mm = int.Parse(ss[i]);
                if (m1 > mm)
                    m1 = mm;
                if (m2 < mm)
                    m2 = mm;
            }
            writer.WriteLine("{0}", check(n, m, min, max, m1, m2) ? "Correct" : "Incorrect");
            writer.Flush();
        }

        private static bool check(int n, int m, int min, int max, int m1, int m2)
        {
            if (m1 < min)
                return false;
            if (m2 > max)
                return false;
            int toadd = (m1 == min ? 0 : 1) + (m2 == max ? 0 : 1);
            if (m + toadd > n)
                return false;

            return true;
        }
    }
}


using System;

class Program
{
    static void Main(string[] args)
    {
        string[] l1 = Console.ReadLine().Split();
        int s = Int32.Parse(l1[0]);
        int x1 = Int32.Parse(l1[1]);
        int x2 = Int32.Parse(l1[2]);

        string[] l2 = Console.ReadLine().Split();
        int t1 = Int32.Parse(l2[0]);
        int t2 = Int32.Parse(l2[1]);

        string[] l3 = Console.ReadLine().Split();
        int p = Int32.Parse(l3[0]);
        int d = Int32.Parse(l3[1]);

        // First, trying by himself:
        int footTime = Math.Abs(x1 - x2) * t2;

        // For the train, he first needs to wait to get on.
        int trainTime = 0;
        if (d * (x1 - p) >= 0)
        {
            trainTime = Math.Abs(x1 - p) * t1;
        }
        else
        {
            int dist = (d > 0) ? 2 * s - x1 - p : x1 + p;
            trainTime = dist * t1;
            d = -d;
        }

        // Then wait to arrive at the destination
        if (d * (x2 - x1) >= 0)
        {
            trainTime += Math.Abs(x2 - x1) * t1;
        }
        else
        {
            int dist = (d > 0) ? 2 * s - x1 - x2 : x1 + x2;
            trainTime += dist * t1;
        }

        Console.WriteLine(Math.Min(trainTime, footTime));
        Console.ReadLine();

    }
}


using System;

namespace codeforcing
{
    class Program
    {
        static void Main(string[] args)
        {
            //INPUT PHASE
            string[] tokens = Console.ReadLine().Split();
            int s = int.Parse(tokens[0]);
            int x1 = int.Parse(tokens[1]);
            int x2 = int.Parse(tokens[2]);

            tokens = Console.ReadLine().Split();

            int t1 = int.Parse(tokens[0]);
            int t2 = int.Parse(tokens[1]);

            tokens = Console.ReadLine().Split();

            int p = int.Parse(tokens[0]);
            int d = int.Parse(tokens[1]);

            int timeWithNoTram = Math.Abs(x1 - x2) * t2;
            if(t2 < t1)
            {
                Console.WriteLine(timeWithNoTram);
                return;
            }

            int distanceWithTram = 0;
            if(p < x2 && x2 < x1)
            {
                //Console.WriteLine("am here 1");
                if (d == 1)
                {
                    distanceWithTram += s - p;

                }
                else
                {
                    distanceWithTram += p;
                    distanceWithTram += s;

                }

                distanceWithTram += s - x2;
            }
            else if(x1 < x2 && x2 < p)
            {
                //Console.WriteLine("am here 2");
                if (d == 1)
                {
                    distanceWithTram += s - p;
                    distanceWithTram += s;
                    distanceWithTram += x2;

                }
                else
                {
                    distanceWithTram += p;
                    distanceWithTram += x2;

                }

            }
            else if(p <= x1 && x1 < x2)
            {
                //Console.WriteLine("am here 3");
                if (d == 1)
                {
                    distanceWithTram += x2 - p;
                }

                else
                {
                    distanceWithTram += p;
                    distanceWithTram += x2;
                }
            }
            else if (x2 < x1 && x1 <= p)
            {
               // Console.WriteLine("am here 4");
                if (d == 1)
                {
                    distanceWithTram += s - p;
                    distanceWithTram += s - x2;
                }

                else
                {
                    distanceWithTram += p - x2;
                }
            }
            else if(x1<= p && p< x2)
            {
                //Console.WriteLine("am here 5");
                if (d == 1)
                {
                    distanceWithTram += s - p;
                    distanceWithTram += s;
                    distanceWithTram += x2;
                }

                else
                {
                    distanceWithTram += p;
                    distanceWithTram += x2;

                }
            }
            else if (x2 < p && p <= x1)
            {
               // Console.WriteLine("am here 6");
                if (d == 1)
                {

                    distanceWithTram += s - p;
                    distanceWithTram += s;
                    distanceWithTram += x2;
                }

                else
                {
                    distanceWithTram += p;
                    distanceWithTram += s;
                    distanceWithTram += s - x2;

                }
            }

            int timeWithTram = distanceWithTram * t1;

            Console.WriteLine((timeWithNoTram < timeWithTram ? timeWithNoTram : timeWithTram));

        }
    }
}


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

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

namespace _308c
{
    class Program
    {
        static string _inputFilename = "input.txt";
        static string _outputFilename = "output.txt";
        static bool _useFileInput = false;

        static void Main(string[] args)
        {
            StreamWriter file = null;
#if DEBUG
			Console.SetIn(getInput());
#else
            if (_useFileInput)
            {
                Console.SetIn(File.OpenText(_inputFilename));
                file = new StreamWriter(_outputFilename);
                Console.SetOut(file);
            }
#endif

            try
            {
                solution();
            }
            finally
            {
                if (_useFileInput)
                {
                    file.Close();
                }
            }
        }

        static void solution()
        {
            #region SOLUTION
            var d = readIntArray();
            var w = d[0];
            var m = d[1];
            var val = new int[101];
            var i = 1;
            while (true)
            {
                if (m == 0)
                {
                    break;
                }

                var rem = m % w;
                val[i] = rem;
                i++;
                m /= w;
            }

            var av = new bool[101];
            for (int j = 1; j < 101; j++)
            {
                av[j] = true;
            }

            for (int j = 1; j < 101; j++)
            {
                if (val[j] == 0 || val[j] == 1)
                {
                    continue;
                }

                if (val[j] == w)
                {
                    if (j == 100)
                    {
                        Console.WriteLine("NO");
                        return;
                    }

                    val[j + 1]++;
                }

                if (val[j] < w - 1)
                {
                    Console.WriteLine("NO");
                    return;
                }

                //if (val[j] == w - 2)
                //{
                //    if (j == 100)
                //    {
                //        Console.WriteLine("NO");
                //        return;
                //    }

                //    if (!av[j - 1])
                //    {
                //        Console.WriteLine("NO");
                //        return;
                //    }

                //    av[j - 1] = false;
                //    av[j] = false;
                //    val[j + 1]++;
                //}

                if (val[j] == w - 1)
                {
                    if (j == 100)
                    {
                        Console.WriteLine("NO");
                        return;
                    }

                    av[j] = false;
                    val[j + 1]++;
                }
            }

            Console.WriteLine("YES");

            //for (int j = 1; j < 101; j++)
            //{

            //}

            //var n = readInt();
            //var m = readInt();

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

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

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

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

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

#if DEBUG
		static StreamReader getInput()
		{
			var resName = Assembly.GetCallingAssembly().GetManifestResourceNames()[0];
			var resource = Assembly.GetCallingAssembly().GetManifestResourceStream(resName);

			return new StreamReader(resource);
		}
#endif
    }
}


using System;

public class Class2
{
    public static void Main()
    {
        string[] tokens = Console.ReadLine().Split();
        long w = long.Parse(tokens[0]);
        long m = long.Parse(tokens[1]);
        /*
        if (w == 2 || w == 3)
        {
            Console.Write("YES");
            return;
        }
        */

        bool ans = solve(w,m);
        if (ans)
        {
            Console.Write("YES");
        }
        else {
            Console.Write("NO");
        }

    }

    private static bool solve(long w, long m)
    {
        if (m<w) {
            if ((m == 1) || m==(w-1))
            {
                return true;
            }
            else {
                return false;
            }
        }
        //m = (w^k1 + w^k2 .. w^ki) - (w^l1 + w^l2 .. w^li)
        long rem = m % w;//rem = 1,0,-1 only
        if (rem == 0) {
            return solve(w, m/w);
        }
        else if (rem == 1) {
            return solve(w, ((m-1)/w));
        }
        else if (rem == (w - 1)) {
            return solve(w, ((m + 1) / w));
        }
        else {
            return false;
        }

    }
}


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

namespace Vanya_and_Scales
{
    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 w = Next();
            int m = Next();

            writer.WriteLine(Check(w, m) ? "YES" : "NO");
            writer.Flush();
        }

        private static bool Check(int w, int m, bool first = true)
        {
            if (m == 0)
                return true;
            if (m%w == 0)
                return Check(w, m/w);
            return first && (Check(w, m - 1, false) || Check(w, m + 1, false));
        }

        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;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static int getNext(int power, int number)
        {
            int result = 1;
            while (result <= number / 2)
            {
                result *= power;
            }
            return result / power;
        }
        static void Main(string[] args)
        {
            string input;
            int w, m;
            input = Console.ReadLine();
            w = Int32.Parse(input.Split(' ')[0]);
            m = Int32.Parse(input.Split(' ')[1]);

            while (m > 0)
            {
                int temp = m % w;
                if (temp < 2)
                {
                    m = m / w;
                }
                else if (temp == w - 1)
                {
                    m = (m + 1) / w;
                }
                else
                {
                    break;
                }
            }
            Console.WriteLine(m == 0 ? "YES" : "NO");
        }
    }
}


namespace topCoder
{
	using System;
	using System.Collections.Generic;

	class p3
	{
		static void Main(string[] args)
		{
			//p1 o = new p1();
			//o.foo();

			//p2 o = new p2();
			//o.foo();

			p3 o = new p3();
			o.foo();
		}
		bool[] h = new bool[100];
		public void foo()
		{
			string[] sp = Console.ReadLine().Split(' ');
			long w = long.Parse(sp[0]);
			long m = long.Parse(sp[1]);

			if (bar(m, w))
				Console.WriteLine("YES");
			else
				Console.WriteLine("NO");
		}
		private bool bar(long m, long w)
		{
			if (m == 0)
				return true;

			long r;
			long x = high(m, w);
			if (!h[x])
			{
				h[x] = true;
				r = m - (long)Math.Pow(w, x);
				if (r < m && bar(r, w))
					return true;
				h[x] = false;
			}
			if (!h[x+1])
			{
				h[x+1]=true;
				r = (long)Math.Pow(w, x + 1) - m;
				if (r < m && bar(r, w))
					return true;
				h[x+1]=false;
			}
			return false;
		}
		private long high(long m, long w)
		{
			int i = 0;
			for (; i <= 100; i++)
			{
				if ((long)Math.Pow(w, i) > m)
					break;
			}
			return i - 1;
		}
	}
}


using System;

namespace TaskC
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ', '\t');
            int w = Convert.ToInt32(s[0]);
            int m = Convert.ToInt32(s[1]);

            Console.WriteLine(Check(w, m) ? "YES" : "NO");
        }

        private static bool Check(int w, int m, bool first = true)
        {
            if (m == 0)
                return true;
            if (m % w == 0)
                return Check(w, m / w);
            return first && (Check(w, m - 1, false) || Check(w, m + 1, false));
        }
    }
}


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

// (づ°ω°)づﾐ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    long lim;
    bool Fun(long d, int n, long s)
    {
        if (s == 0)
            return true;
        if (d <= lim)
        {
            long nd = d * n;
            if (nd < d)
                return false;
            if (Fun(nd, n, s) || Fun(nd, n, s + d) || Fun(nd, n, s - d))
                return true;
        }

        return false;
    }

    void Solve()
    {
        int n = ReadInt();
        int m = ReadInt();
        lim = 1000000000L * n;

        Write(n < 4 || Fun(1, n, m) ? "YES" : "NO");
    }

    #region Main

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

    #endregion

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


using System;
using System.IO;
class _308_Div2_ProbD {
	static bool solve(int w, int m) {
		return w <= 3 || m == 1 || trysolve(w, m - 1) || trysolve(w, m) || trysolve(w, m + 1);
	}

	static bool trysolve(int w, int m) {
		return m % w == 0 && solve(w, m / w);
	}
	static void Main() {
		//Console.SetIn(new StreamReader(File.OpenRead("308_Div2_ProbC.txt")));
		var input = Console.ReadLine().Split(new char[] {' '});
		int w = int.Parse(input[0]);
		int m = int.Parse(input[1]);

		bool flag = solve(w, m);
		if (flag)
			Console.WriteLine("YES");
		else
			Console.WriteLine("NO");

	}
}


using System;

public class Class2
{
    public static void Main()
    {
        string[] tokens = Console.ReadLine().Split();
        long w = long.Parse(tokens[0]);
        long m = long.Parse(tokens[1]);

        if (w == 2 || w == 3)
        {
            Console.Write("YES");
            return;
        }

        bool ans = solve(w,m);
        if (ans)
        {
            Console.Write("YES");
        }
        else {
            Console.Write("NO");
        }

    }

    private static bool solve(long w, long m)
    {
        if (m<w) {
            if ((m == 1) || m==(w-1))
            {
                return true;
            }
            else {
                return false;
            }
        }
        //m = (w^k1 + w^k2 .. w^ki) - (w^l1 + w^l2 .. w^li)
        long rem = m % w;//rem = 1,0,-1 only
        if (rem == 0) {
            return solve(w, m/w);
        }
        else if (rem == 1) {
            return solve(w, ((m-1)/w));
        }
        else if (rem == (w - 1)) {
            return solve(w, ((m + 1) / w));
        }
        else {
            return false;
        }

    }
}


//Template by _Trung_Nguyen
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
using System.IO;

using Libraries;
using Libraries.IO;
using Libraries.Collections;

namespace Codeforces
{
	public class sample
	{
		private static int [] convertBase(int a, int numberBase)
		{
			Deque<int> result = new Deque<int>();
			while (a > 0)
			{
				result.AddFirst(a % numberBase);
				a /= numberBase;
			}
			return result.ToArray();
		}
		private static int solution()
		{
			int w = cin.ReadInt32();
			int m = cin.ReadInt32();

			int [] a = convertBase(m, w);

			for (int i = a.Length - 1; i >= 0; --i)
			{
				if ((a[i] == 0) || (a[i] == 1)) continue;
				a[i] -= w;
				if (i > 0)
					++a[i - 1];
				//else ignore it as the higher digit is one LMAO.
				if ((a[i] != -1) && (a[i] != 0))
				{
					cout.Write("NO");
					return 0;
				}
			}

			cout.Write("YES");

			return 0;
		}

//===============Prewritten code======================
		private static istream cin = new istream(Console.OpenStandardInput());
		private static ostream cout = new ostream(Console.OpenStandardOutput());
		private static ostream cerr = new ostream(Console.OpenStandardError());
		private static ostream clog = new ostream(Console.OpenStandardError(), true);

		public static int Main()
		{
			try
			{
				int returnValue = solution();
				cout.Flush();
				cerr.Flush();
				return returnValue;
			}
			catch (Exception e)
			{
				Console.WriteLine(e.ToString());
				return -1;
			}
		}
	}
}

namespace Libraries.IO
{
	public class istream : IDisposable
	{
		private BufferedStream buffer;
		private StreamReader reader;
		private Queue<string> words = new Queue<string>();
		private void getWords()
		{
			while (words.Count == 0)
			{
				string [] temp = reader.ReadLine().Split();
				foreach (var str in temp)
				{
					if (str.Length == 0) continue;
					words.Enqueue(str);
				}
			}
		}
		public istream(Stream istr)
		{
			buffer = new BufferedStream(istr);
			reader = new StreamReader(buffer);
		}
		public int Peek()
		{
			return reader.Peek();
		}
		public int Read()
		{
			return reader.Read();
		}
		public string ReadLine()
		{
			return reader.ReadLine();
		}
		public int [] ReadInt32Array()
		{
			return reader.ReadLine().Split().Select(x => Convert.ToInt32(x)).ToArray();
		}
		public long [] ReadInt64Array()
		{
			return reader.ReadLine().Split().Select(x => Convert.ToInt64(x)).ToArray();
		}
		public string [] ReadStringArray()
		{
			return reader.ReadLine().Split();
		}
		public int ReadInt32()
		{
			getWords();
			return Convert.ToInt32(words.Dequeue());
		}
		public long ReadInt64()
		{
			getWords();
			return Convert.ToInt64(words.Dequeue());
		}
		public string ReadString()
		{
			getWords();
			return words.Dequeue();
		}
		public void Dispose()
		{
			reader.Dispose();
			buffer.Dispose();
		}
	}
	public class ostream : IDisposable
	{
		private BufferedStream buffer;
		private StreamWriter writer;
		public ostream(Stream ostr, bool autoflush = false)
		{
			buffer = new BufferedStream(ostr);
			writer = new StreamWriter(buffer);
			writer.AutoFlush = autoflush;
		}
		public void Write(string format, params object[] args)
		{
			writer.Write(format, args);
		}
		public void Write<T>(T value)
		{
			writer.Write(value);
		}
		public void Write<T>(T [] arr, string sep)
		{
			string fmt = "{0}" + sep;
			foreach (var x in arr) writer.Write(fmt, x);
		}
		public void WriteLine(string format, params object[] args)
		{
			writer.WriteLine(format, args);
		}
		public void WriteLine<T>(T value)
		{
			writer.WriteLine(value);
		}
		public void WriteLine<T>(IEnumerable<T> arr, string sep)
		{
			string fmt = "{0}" + sep;
			foreach (var x in arr) writer.Write(fmt, x);
			writer.WriteLine();
		}
		public void WriteLine<T>(IEnumerable<T> arr, string sep, Func<T, T> funct)
		{
			string fmt = "{0}" + sep;
			foreach (var x in arr) writer.Write(fmt, funct(x));
			writer.WriteLine();
		}
		public void WriteLine()
		{
			writer.WriteLine();
		}
		public void Flush()
		{
			writer.Flush();
		}
		public void Dispose()
		{
			writer.Dispose();
			buffer.Dispose();
		}
	}
}
namespace Libraries
{
	public class Utilities
	{
		public static void Swap<T>(ref T x, ref T y)
		{
			T temp = y;
			y = x;
			x = temp;
		}
	}

	public static class Arrays
	{
		private static T Inc<T>(ref T value)
		{
			dynamic temp = value;
			dynamic temp2 = temp;
			value = ++temp2;
			return temp++;
		}
		public static IEnumerable<T> FillDefault<T>(int size) where T : new()
		{
			for (int i = 0; i < size; ++i) yield return new T();
		}
		public static IEnumerable<T> Fill<T>(int size, T value)
		{
			for (int i = 0; i < size; ++i) yield return value;
		}
		public static IEnumerable<T> Fill<T>(int size, Func<T> funct)
		{
			for (int i = 0; i < size; ++i) yield return funct();
		}
		public static IEnumerable<T> Iota<T>(int size, T init)
		{
			for (int i = 0; i < size; ++i) yield return Inc(ref init);
		}
		public static T First<T> (this IList<T> container)
		{
			if (container.Count == 0) throw new InvalidOperationException("The container is empty");
			return container[0];
		}
		public static T Last<T> (this IList<T> container)
		{
			if (container.Count == 0) throw new InvalidOperationException("The container is empty");
			return container[container.Count - 1];
		}
		public static void RemoveLast<T> (this IList<T> container)
		{
			if (container.Count == 0) throw new InvalidOperationException("The container is empty");
			container.RemoveAt(container.Count - 1);
		}
	}
}

namespace Libraries.Collections
{
	class PriorityQueue<T> where T : IComparable
	{
	    private List<T> list;
	    public int Count { get { return list.Count; } }
	    public readonly bool IsDescending;

	    public PriorityQueue(bool isdesc = true)
	    {
	        list = new List<T>();
	        IsDescending = isdesc;
	    }

	    public PriorityQueue(int capacity, bool isdesc = true)
	    {
	        list = new List<T>(capacity);
	        IsDescending = isdesc;
	    }

	    public PriorityQueue(IEnumerable<T> collection, bool isdesc = true)
	        : this()
	    {
	        IsDescending = isdesc;
	        foreach (var item in collection)
	            Enqueue(item);
	    }

	    public void Enqueue(T x)
	    {
	        list.Add(x);
	        int i = Count - 1;

	        while (i > 0)
	        {
	            int p = (i - 1) / 2;
	            if ((IsDescending ? -1 : 1) * list[p].CompareTo(x) <= 0) break;

	            list[i] = list[p];
	            i = p;
	        }

	        if (Count > 0) list[i] = x;
	    }

	    public T Dequeue()
	    {
	        T target = Peek();
	        T root = list[Count - 1];
	        list.RemoveAt(Count - 1);

	        int i = 0;
	        while (i * 2 + 1 < Count)
	        {
	            int a = i * 2 + 1;
	            int b = i * 2 + 2;
	            int c = b < Count && (IsDescending ? -1 : 1) * list[b].CompareTo(list[a]) < 0 ? b : a;

	            if ((IsDescending ? -1 : 1) * list[c].CompareTo(root) >= 0) break;
	            list[i] = list[c];
	            i = c;
	        }

	        if (Count > 0) list[i] = root;
	        return target;
	    }

	    public T Peek()
	    {
	        if (Count == 0) throw new InvalidOperationException("Queue is empty.");
	        return list[0];
	    }

	    public void Clear()
	    {
	        list.Clear();
	    }
	}
    internal class DequeUtility
    {
        public static int ClosestPowerOfTwoGreaterThan(int x)
        {
            x--;
            x |= (x >> 1);
            x |= (x >> 2);
            x |= (x >> 4);
            x |= (x >> 8);
            x |= (x >> 16);
            return (x+1);
        }

        public static int Count<TSource>(IEnumerable<TSource> source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            ICollection<TSource> genericCollection = source as ICollection<TSource>;
            if (genericCollection != null)
            {
                return genericCollection.Count;
            }

            ICollection nonGenericCollection = source as ICollection;
            if (nonGenericCollection != null)
            {
                return nonGenericCollection.Count;
            }

            checked
            {
                int count = 0;
                using (var iterator = source.GetEnumerator())
                {
                    while (iterator.MoveNext())
                    {
                        count++;
                    }
                }
                return count;
            }
        }
    }

    public class Deque<T> : IList<T>
    {
        private const int defaultCapacity = 16;

        private int startOffset;

        private T[] buffer;

        public Deque() : this(defaultCapacity) { }

        public Deque(int capacity)
        {
            if (capacity < 0)
            {
                throw new ArgumentOutOfRangeException(
                    "capacity", "capacity is less than 0.");
            }

            this.Capacity = capacity;
        }

        public Deque(IEnumerable<T> collection)
            : this(DequeUtility.Count(collection))
        {
            InsertRange(0, collection);
        }

        private int capacityClosestPowerOfTwoMinusOne;

        public int Capacity
        {
            get
            {
                return buffer.Length;
            }

            set
            {
                if (value < 0)
                {
                    throw new ArgumentOutOfRangeException(
                        "value",
                        "Capacity is less than 0.");
                }
                else if (value < this.Count)
                {
                    throw new InvalidOperationException(
                        "Capacity cannot be set to a value less than Count");
                }
                else if (null != buffer && value == buffer.Length)
                {
                    return;
                }

                int powOfTwo = DequeUtility.ClosestPowerOfTwoGreaterThan(value);

                value = powOfTwo;

                T[] newBuffer = new T[value];
                this.CopyTo(newBuffer, 0);

                buffer = newBuffer;
                startOffset = 0;
                this.capacityClosestPowerOfTwoMinusOne = powOfTwo - 1;
            }
        }

        public bool IsFull
        {
            get { return this.Count == this.Capacity; }
        }

        public bool IsEmpty
        {
            get { return 0 == this.Count; }
        }

        private void ensureCapacityFor(int numElements)
        {
            if (this.Count + numElements > this.Capacity)
            {
                this.Capacity = this.Count + numElements;
            }
        }

        private int toBufferIndex(int index)
        {
            int bufferIndex;

            bufferIndex = (index + this.startOffset)
                & this.capacityClosestPowerOfTwoMinusOne;

            return bufferIndex;
        }

        private void checkIndexOutOfRange(int index)
        {
            if (index >= this.Count)
            {
                throw new IndexOutOfRangeException(
                    "The supplied index is greater than the Count");
            }
        }

        private static void checkArgumentsOutOfRange(
            int length,
            int offset,
            int count)
        {
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException(
                    "offset", "Invalid offset " + offset);
            }

            if (count < 0)
            {
                throw new ArgumentOutOfRangeException(
                    "count", "Invalid count " + count);
            }

            if (length - offset < count)
            {
                throw new ArgumentException(
                    String.Format(
                    "Invalid offset ({0}) or count + ({1}) "
                    + "for source length {2}",
                    offset, count, length));
            }
        }

        private int shiftStartOffset(int value)
        {
            this.startOffset = toBufferIndex(value);

            return this.startOffset;
        }

        private int preShiftStartOffset(int value)
        {
            int offset = this.startOffset;
            this.shiftStartOffset(value);
            return offset;
        }

        private int postShiftStartOffset(int value)
        {
            return shiftStartOffset(value);
        }

        #region IEnumerable

        public IEnumerator<T> GetEnumerator()
        {
            if (this.startOffset + this.Count > this.Capacity)
            {
                for (int i = this.startOffset; i < this.Capacity; i++)
                {
                    yield return buffer[i];
                }

                int endIndex = toBufferIndex(this.Count);
                for (int i = 0; i < endIndex; i++)
                {
                    yield return buffer[i];
                }
            }
            else
            {
                int endIndex = this.startOffset + this.Count;
                for (int i = this.startOffset; i < endIndex; i++)
                {
                    yield return buffer[i];
                }
            }
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator();
        }
        #endregion

        #region ICollection

        bool ICollection<T>.IsReadOnly
        {
            get { return false; }
        }

        public int Count
        {
            get;
            private set;
        }

        private void incrementCount(int value)
        {
            this.Count = this.Count + value;
        }

        private void decrementCount(int value)
        {
            this.Count = Math.Max(this.Count - value, 0);
        }

        public void Add(T item)
        {
            AddLast(item);
        }

        private void ClearBuffer(int logicalIndex, int length)
        {
            int offset = toBufferIndex(logicalIndex);
            if (offset + length > this.Capacity)
            {
                int len = this.Capacity - offset;
                Array.Clear(this.buffer, offset, len);

                len = toBufferIndex(logicalIndex + length);
                Array.Clear(this.buffer, 0, len);
            }
            else
            {
                Array.Clear(this.buffer, offset, length);
            }
        }

        public void Clear()
        {
            if (this.Count > 0)
            {
                ClearBuffer(0, this.Count);
            }
            this.Count = 0;
            this.startOffset = 0;
        }

        public bool Contains(T item)
        {
            return this.IndexOf(item) != -1;
        }

        public void CopyTo(T[] array, int arrayIndex)
        {
            if (null == array)
            {
                throw new ArgumentNullException("array", "Array is null");
            }

            if (null == this.buffer)
            {
                return;
            }

            checkArgumentsOutOfRange(array.Length, arrayIndex, this.Count);

            if (0 != this.startOffset
                && this.startOffset + this.Count >= this.Capacity)
            {
                int lengthFromStart = this.Capacity - this.startOffset;
                int lengthFromEnd = this.Count - lengthFromStart;

                Array.Copy(
                    buffer, this.startOffset, array, 0, lengthFromStart);

                Array.Copy(
                    buffer, 0, array, lengthFromStart, lengthFromEnd);
            }
            else
            {
                Array.Copy(
                    buffer, this.startOffset, array, 0, Count);
            }
        }

        public bool Remove(T item)
        {
            bool result = true;
            int index = IndexOf(item);

            if (-1 == index)
            {
                result = false;
            }
            else
            {
                RemoveAt(index);
            }

            return result;
        }

        #endregion

        #region List<T>

        public T this[int index]
        {
            get
            {
                return this.Get(index);
            }

            set
            {
                this.Set(index, value);
            }
        }

        public void Insert(int index, T item)
        {
            ensureCapacityFor(1);

            if (index == 0)
            {
                AddFirst(item);
                return;
            }
            else if (index == Count)
            {
                AddLast(item);
                return;
            }

            InsertRange(index, new[] { item });
        }

        public int IndexOf(T item)
        {
            int index = 0;
            foreach (var myItem in this)
            {
                if (myItem.Equals(item))
                {
                    break;
                }
                ++index;
            }

            if (index == this.Count)
            {
                index = -1;
            }

            return index;
        }

        public void RemoveAt(int index)
        {
            if (index == 0)
            {
                RemoveFirst();
                return;
            }
            else if (index == Count - 1)
            {
                RemoveLast();
                return;
            }

            RemoveRange(index, 1);
        }
        #endregion

        public void AddFirst(T item)
        {
            ensureCapacityFor(1);
            buffer[postShiftStartOffset(-1)] = item;
            incrementCount(1);
        }

        public void AddLast(T item)
        {
            ensureCapacityFor(1);
            buffer[toBufferIndex(this.Count)] = item;
            incrementCount(1);
        }

        public T RemoveFirst()
        {
            if (this.IsEmpty)
            {
                throw new InvalidOperationException("The Deque is empty");
            }

            T result = buffer[this.startOffset];
            buffer[preShiftStartOffset(1)] = default(T);
            decrementCount(1);
            return result;
        }

        public T RemoveLast()
        {
            if (this.IsEmpty)
            {
                throw new InvalidOperationException("The Deque is empty");
            }

            decrementCount(1);
            int endIndex = toBufferIndex(this.Count);
            T result = buffer[endIndex];
            buffer[endIndex] = default(T);

            return result;
        }

        public void AddRange(IEnumerable<T> collection)
        {
            AddLastRange(collection);
        }

        public void AddFirstRange(IEnumerable<T> collection)
        {
            AddFirstRange(collection, 0, DequeUtility.Count(collection));
        }

        public void AddFirstRange(
            IEnumerable<T> collection,
            int fromIndex,
            int count)
        {
            InsertRange(0, collection, fromIndex, count);
        }

        public void AddLastRange(IEnumerable<T> collection)
        {
            AddLastRange(collection, 0, DequeUtility.Count(collection));
        }

        public void AddLastRange(
            IEnumerable<T> collection,
            int fromIndex,
            int count)
        {
            InsertRange(this.Count, collection, fromIndex, count);
        }

        public void InsertRange(int index, IEnumerable<T> collection)
        {
            int count = DequeUtility.Count(collection);
            this.InsertRange(index, collection, 0, count);
        }

        public void InsertRange(
            int index,
            IEnumerable<T> collection,
            int fromIndex,
            int count)
        {
            checkIndexOutOfRange(index - 1);

            if (0 == count)
            {
                return;
            }

            ensureCapacityFor(count);

            if (index < this.Count / 2)
            {
                if (index > 0)
                {
                    int copyCount = index;
                    int shiftIndex = this.Capacity - count;
                    for (int j = 0; j < copyCount; j++)
                    {
                        buffer[toBufferIndex(shiftIndex + j)] =
                            buffer[toBufferIndex(j)];
                    }
                }

                this.shiftStartOffset(-count);

            }
            else
            {
                if (index < this.Count)
                {
                    int copyCount = this.Count - index;
                    int shiftIndex = index + count;
                    for (int j = 0; j < copyCount; j++)
                    {
                        buffer[toBufferIndex(shiftIndex + j)] =
                            buffer[toBufferIndex(index + j)];
                    }
                }
            }

            int i = index;
            foreach (T item in collection)
            {
                buffer[toBufferIndex(i)] = item;
                ++i;
            }

            incrementCount(count);
        }

        public void RemoveRange(int index, int count)
        {
            if (this.IsEmpty)
            {
                throw new InvalidOperationException("The Deque is empty");
            }
            if (index > Count - count)
            {
                throw new IndexOutOfRangeException(
                    "The supplied index is greater than the Count");
            }

            ClearBuffer(index, count);

            if (index == 0)
            {
                this.shiftStartOffset(count);
                this.Count -= count;
                return;
            }
            else if (index == Count - count)
            {
                this.Count -= count;
                return;
            }

            if ((index + (count / 2)) < Count / 2)
            {
                int copyCount = index;
                int writeIndex = count;
                for (int j = 0; j < copyCount; j++)
                {
                    buffer[toBufferIndex(writeIndex + j)]
                        = buffer[toBufferIndex(j)];
                }

                this.shiftStartOffset(count);
            }
            else
            {
                int copyCount = Count - count - index;
                int readIndex = index + count;
                for (int j = 0; j < copyCount; ++j)
                {
                    buffer[toBufferIndex(index + j)] =
                        buffer[toBufferIndex(readIndex + j)];
                }
            }

            decrementCount(count);
        }
        public T Get(int index)
        {
            checkIndexOutOfRange(index);
            return buffer[toBufferIndex(index)];
        }

        public void Set(int index, T item)
        {
            checkIndexOutOfRange(index);
            buffer[toBufferIndex(index)] = item;
        }

    }
}


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

namespace _630
{
    class Program
    {
        static void Main()
        {
            var n = long.Parse(Console.ReadLine());
            Console.WriteLine(n * n / 1 * (n-1) * (n-1)  / 2 * (n-2) * (n-2) / 3 * (n-3)*(n-3) / 4 * (n-4)*(n-4) / 5);
        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            decimal n = Convert.ToUInt64(Console.ReadLine());
            decimal k = n * n * (n - 1) * (n - 1) * (n - 2) * (n - 2) * (n - 3) * (n - 3) * (n - 4) * (n - 4);
            Console.WriteLine(k/5/4/3/2);
        }
    }
}


using System;
// you can also use other imports, for example:
using System.Collections.Generic;
using System.Linq;
using System.IO;

public class HelloWorld
{

    public static void Main(string[] args)
    {
        var n = Convert.ToInt64(Console.ReadLine());
        Console.WriteLine(n / 2520);
    }

}


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

namespace _630J_Divisibility
{
    class Program
    {
        static void Main(string[] args)
        {
            ulong n = ulong.Parse(Console.ReadLine());

            Console.WriteLine(n / 2520);
        }
    }
}


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

namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int n = int.Parse(s.Split(' ')[0]), m = int.Parse(s.Split(' ')[1]), k = int.Parse(s.Split(' ')[2]);
            if (m >= n && k >= n)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}


using System;
using System.Linq;

namespace CodeForcesTest
{
    class Program
    {

        static void Main(string[] args)
        {
            int[] n = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            Console.WriteLine(n[0] > n[1] || n[0] > n[2] ? "No" : "Yes");
        }
    }
}


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

namespace Rextester
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string str = Console.ReadLine();
            int a = 0, q = 0, count = 0;
            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] == 'Q')
                {
                    for (int j = i + 1; j < str.Length; j++)
                    {
                        if (str[j] == 'A') a++;
                        if (str[j] == 'Q') count += a;
                    }
                    a = 0;
                    q = 0;
                }

            }
            Console.Write(count);
            //Console.ReadKey();

        }
    }
}


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

namespace Codeforces
{
	static class Program
	{

		static void Main()
		{
			var s = Console.ReadLine();
			var pref = new int[s.Length];
			if (s[0] == 'Q') pref[0] = 1;
			for (int i = 1; i < s.Length; i++)
			{
				if (s[i] == 'Q')
					pref[i] = pref[i - 1] + 1;

				else pref[i] = pref[i - 1];
			}
			int count = 0;
			for (int i = 0; i < s.Length; i++)
			{
				if(s[i] == 'A')
				{
					if (pref[s.Length - 1] - pref[i] == 0) break;
					count +=pref[i] * (pref[s.Length - 1] - pref[i]);
				}
			}
			Console.WriteLine(count);
			Console.ReadLine();
		}

		private static List<long> ReadLongList() => Console.ReadLine().Split().Select(long.Parse).ToList();
		private static List<int> ReadIntList() => Console.ReadLine().Split().Select(int.Parse).ToList();
		private static int[] ReadIntArray() => Console.ReadLine().Split().Select(int.Parse).ToArray();
		private static long[] ReadLongArray() => Console.ReadLine().Split().Select(long.Parse).ToArray();
		private static int ReadInt() => int.Parse(Console.ReadLine());
		private static long ReadLong() => long.Parse(Console.ReadLine());
	}
}


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

namespace Contest {
    class Program {
        static void Main(string[] args) {
            var elem = Console.ReadLine().Split();
            int n = int.Parse(elem[0]), m = int.Parse(elem[1]);

            var nums = Console.ReadLine().Split().Select(str => int.Parse(str)).ToArray();

            int ans = 1, cur = 0;
            for (int i = 0; i < nums.Length; i++) {
                if (cur + nums[i] <= m) {
                    cur += nums[i];
                } else {
                    ans++;
                    cur = nums[i];
                }
            }

            Console.WriteLine(ans);
        }
    }
}


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

// (づ*ω*)づﾐ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public object Solve()
    {
        int n = ReadInt();
        int m = ReadInt();
        var a = ReadIntArray();
        int c = 0;
        int ans = 0;
        while (c < n)
        {
            ans++;
            int x = m;
            while (c < n && a[c] <= x)
            {
                x -= a[c];
                c++;
            }
        }

        return ans;
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;

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

    #endregion

    #region Read/Write

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

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

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

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

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

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

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

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

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

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

    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows);
        int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++)
        {
            ret[i] = new int[numberOfRows];
            for (int j = 0; j < numberOfRows; j++)
                ret[i][j] = matrix[j][i];
        }
        return ret;
    }

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

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

    #endregion
}


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

namespace cf495
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader("input.txt"));

            Console.WriteLine(solve_cfindahacks2016A());
        }

        public static string solve_cfindahacks2016A()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int[] t = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            for (int i =  0; i < n; i++)
            {
                for (int j = i + 1; j < n; j++)
                {
                    for (int k = j + 1; k < n; k++)
                    {
                        if ((t[i] != t[j] && t[j] != t[k] && t[i] != t[k]) && (Math.Abs(t[i] - t[j]) <= 2 && Math.Abs(t[j] - t[k]) <= 2 && Math.Abs(t[i] - t[k]) <= 2))
                        {
                            return "YES";
                        }
                    }
                }
            }

            return "NO";
        }
        public static void solve_cf495A()
        {
            int[] nd = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int n = nd[0];
            int d = nd[1];
            int[] x = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            int cnt = 2;

            int prev = x[0];

            for (int i = 1; i < n; i++)
            {
                int diff = (prev < 0 && x[i] > 0 || prev > 0 && x[i] < 0) ? Math.Abs(prev) + Math.Abs(x[i]) : Math.Abs(Math.Abs(prev) - Math.Abs(x[i]));
                if (diff >= 2 * d && prev + d != x[i] - d)
                {
                    cnt += 2;
                }
                else if (diff - d >= d)
                {
                    cnt++;
                }
                prev = x[i];
            }

            Console.WriteLine(cnt);
        }
    }
}


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

namespace Codeforces
{
	internal class Template
	{
		private void Solve()
		{
		    var n = cin.NextInt();
		    var t = new int[n];
		    for (var i = 0; i < t.Length; i++)
		    {
		        t[i] = cin.NextInt();
		    }
		    for (var i = 0; i < t.Length; i++)
		    {
		        for (var j = i + 1; j < t.Length; j++)
		        {
		            for (var k = j + 1; k < t.Length; k++)
		            {
		                if (t[i] != t[j] && t[i] != t[k] && t[j] != t[k])
		                {
		                    if (Math.Abs(t[i] - t[j]) <= 2 && Math.Abs(t[i] - t[k]) <= 2 && Math.Abs(t[j] - t[k]) <= 2)
		                    {
		                        Console.WriteLine("YES");
		                        return;
		                    }
		                }
		            }
		        }
		    }
            Console.WriteLine("NO");
		}

		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.Globalization;

namespace CodeForces
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime time = DateTime.ParseExact(Console.ReadLine(), "HH:mm", CultureInfo.InvariantCulture);
            Console.WriteLine("{0:0.#} {1:0.#}", (time.Hour % 12) * 30d + 30d * (time.Minute / 60d), time.Minute * 6);
        }
    }
}


using System;

namespace CodeForces
{
    class Depression
    {
        public static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(':');
            double hours = double.Parse(line[0]);
            double mins = double.Parse(line[1]);

            while (hours >= 12) {
                hours -= 12;
            }

            Console.WriteLine("{0} {1}", (hours + mins / 60) / 12 * 360, (mins / 60) * 360);
        }
    }
}


using System;

class Solution
{
	public static void Main(String[] args)
	{
		Int32 length = Int32.Parse(Console.ReadLine());
		String line = Console.ReadLine();

		for (int i = 1; i < length; i++)
		{
			if (line[i] != '?' && line[i] == line[i - 1])
			{
				Console.WriteLine("No");
				return;
			}
		}

		if(line.Contains("?") == false)
		{
			Console.WriteLine("No");
			return;
		}

		if(line[0] == '?' || line[length - 1] == '?')
		{
			Console.WriteLine("Yes");
			return;
		}

		for(int i = 1; i < length - 1; i ++)
		{
			if(line[i] == '?' && (line[i - 1] == '?' || line[i + 1] == '?' || line[i - 1] == line[i + 1]))
			{
				Console.WriteLine("Yes");
				return;
			}
		}

		Console.WriteLine("No");
		return;
	}
}


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

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

    internal class Task : IDisposable
    {
        private readonly InputReader sr;
        private readonly TextWriter sw;
        private bool isDispose;

        public Task(InputReader sr, TextWriter sw)
        {
            this.sr = sr;
            this.sw = sw;
        }

        public void Solve()
        {
            var n = sr.NextInt32();
            var str = sr.NextString().ToCharArray();
            for (var i = 1; i < str.Length; i++) {
                if (str[i] != '?' && str[i - 1] != '?') {
                    if (str[i - 1] == str[i]) {
                        sw.WriteLine("No");
                        return;
                    }
                }
            }
            for (var i = 0; i < str.Length; i++) {
                if (str[i] == '?') {
                    if (i + 1 < str.Length && str[i + 1] == '?') {
                            sw.WriteLine("Yes");
                            return;
                    }
                    else {
                        if (i + 1 < str.Length) {
                            if (i == 0) {
                                sw.WriteLine("Yes");
                                return;
                            }

                            if (str[i - 1] == str[i + 1]) {
                                sw.WriteLine("Yes");
                                return;
                            }
                        }
                        else {
                            sw.WriteLine("Yes");
                            return;
                        }
                    }
                }
            }

            sw.WriteLine("No");
        }

        ~Task()
        {
            Dispose(false);
        }

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

        private void Dispose(bool disposing)
        {
            if (!isDispose) {
                if (disposing) {
                    if(sr != null)
                        sr.Dispose();

                    if(sw != null)
                        sw.Dispose();
                }

                isDispose = true;
            }
        }
    }
}

internal class InputReader : IDisposable
{
    private bool isDispose;
    private readonly TextReader sr;
    private string[] buffer;
    private int seek;

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

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

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

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

    private string ReadNextToken()
    {
        if (buffer == null || seek == buffer.Length) {
            seek = 0;
            buffer = NextSplitStrings();
        }

        return buffer[seek++];
    }

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

    public int[] ReadArrayOfInt32()
    {
        return ReadArray(Int32.Parse);
    }

    public long[] ReadArrayOfInt64()
    {
        return ReadArray(Int64.Parse);
    }

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

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

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

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

            isDispose = true;
        }
    }

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


using System;
using System.Collections.Generic;
using System.Linq;
using Solver.Ex;
using Debug = System.Diagnostics.Debug;
using Watch = System.Diagnostics.Stopwatch;
using StringBuilder = System.Text.StringBuilder;
using System.Numerics;
namespace Solver
{
    public class Solver
    {
        public void Solve()
        {
            var a = sc.Long();
            var b = sc.Long();
            if (a == b)
                IO.Printer.Out.WriteLine("infinity");
            else if (a < b)
                IO.Printer.Out.WriteLine(0);
            else
            {
                var v = a - b;
                var set = new HashSet<long>();
                for (long i = 1; i * i <= v; i++)
                {
                    if (v % i == 0)
                    {
                        if (i > b) set.Add(i);
                        if (v / i > b) set.Add(v / i);
                    }
                }
                IO.Printer.Out.WriteLine(set.Count);

            }
        }

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

    #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);
            Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(errStream, "debugStream"));
            Debug.AutoFlush = false;
            var sw = new Watch(); sw.Start();
            IO.Printer.Out.AutoFlush = true;
            try
            {
#endif

                var solver = new Solver();
                solver.sc = new IO.StreamScanner(Console.OpenStandardInput());
                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);
                Debug.Close();
                System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
            }
#endif
        }

    }
    #endregion
}

#region IO Helper
namespace Solver.IO
{
    public class Printer : System.IO.StreamWriter
    {
        static Printer()
        {
            Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
#if DEBUG
            Error = new Printer(Console.OpenStandardError()) { AutoFlush = true };
#else
            Error = new Printer(System.IO.Stream.Null) { AutoFlush = false };
#endif
        }
        public static Printer Out { get; set; }
        public static Printer Error { get; set; }
        public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } }
        public Printer(System.IO.Stream stream) : base(stream, new System.Text.UTF8Encoding(false, true)) { }
        public Printer(System.IO.Stream stream, System.Text.Encoding encoding) : base(stream, encoding) { }
        public void Write<T>(string format, IEnumerable<T> source) { base.Write(format, source.OfType<object>().ToArray()); }
        public void WriteLine<T>(string format, IEnumerable<T> source) { base.WriteLine(format, source.OfType<object>().ToArray()); }
    }
    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 IsEndOfStream { get { return eof; } }
        const byte lb = 33, ub = 126, el = 10, cr = 13;
        public byte read()
        {
            if (eof) throw new System.IO.EndOfStreamException();
            if (ptr >= len) { ptr = 0; if ((len = iStream.Read(buf, 0, 1024)) <= 0) { eof = true; return 0; } }
            return buf[ptr++];
        }
        public char Char() { byte b = 0; do b = read(); while (b < lb || ub < b); return (char)b; }
        public char[] Char(int n) { var a = new char[n]; for (int i = 0; i < n; i++) a[i] = Char(); 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()
        {
            if (eof) throw new System.IO.EndOfStreamException();
            StringBuilder sb = null;
            var enc = System.Text.UTF8Encoding.Default;
            do
            {
                for (; ptr < len && (buf[ptr] < lb || ub < buf[ptr]); ptr++) ;
                if (ptr < len) break;
                ptr = 0;
                if ((len = iStream.Read(buf, 0, 1024)) <= 0) { eof = true; return ""; }
            } while (true);
            do
            {
                var f = ptr;
                for (; ptr < len; ptr++)
                    if (buf[ptr] < lb || ub < buf[ptr])
                    //if (buf[ptr] == cr || buf[ptr] == el)
                    {
                        string s;
                        if (sb == null) s = enc.GetString(buf, f, ptr - f);
                        else { sb.Append(enc.GetChars(buf, f, ptr - f)); s = sb.ToString(); }
                        ptr++; return s;
                    }
                if (sb == null) sb = new StringBuilder(enc.GetString(buf, f, len - f));
                else sb.Append(enc.GetChars(buf, f, len - f));
                ptr = 0;

            }
            while (!eof && (len = iStream.Read(buf, 0, 1024)) > 0);
            eof = true; return (sb != null) ? sb.ToString() : "";
        }
        public long Long()
        {
            long ret = 0; byte b = 0; bool isMynus = false;
            const byte zr = 48, nn = 57, my = 45;
            do b = read();
            while (b != my && (b < zr || nn < b));
            if (b == my) { isMynus = true; b = read(); }
            for (; true; b = read())
                if (b < zr || nn < b)
                    return isMynus ? -ret : ret;
                else ret = ret * 10 + b - zr;
        }
        public int Integer()
        {
            int ret = 0; byte b = 0; bool isMynus = false;
            const byte zr = 48, nn = 57, my = 45;
            do b = read();
            while (b != my && (b < zr || nn < b));
            if (b == my) { isMynus = true; b = read(); }
            for (; true; b = read())
                if (b < zr || nn < b)
                    return isMynus ? -ret : ret;
                else ret = ret * 10 + b - zr;
        }
        public double Double() { return double.Parse(Scan(), System.Globalization.CultureInfo.InvariantCulture); }
        public string[] Scan(int n) { var a = new string[n]; for (int i = 0; i < n; i++) a[i] = Scan(); return a; }
        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(int n) { var a = new int[n]; for (int i = 0; i < n; i++) a[i] = Integer(); return a; }
        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> ie) { return new string(ie.ToArray()); }
        static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); }

    }
}
#endregion


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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(File.OpenText("in.txt"));
            var data = Console.ReadLine().Split().Select(d => int.Parse(d)).ToArray();
            var a = data[0];
            var b = data[1];
            r = a - b;

            if (a == b)
            {
                Console.WriteLine("infinity");
                return;
            }
            else if (a < b)
            {
                Console.WriteLine(0);
                return;
            }
            else
            {
                var n = (int)Math.Floor(Math.Sqrt(r));
                var counter = 0;
                for (int i = 1; i <= n; i++)
                {
                    var rem = r % i;
                    if (rem == 0)
                    {
                        if (i > b)
                        {
                            counter++;
                        }

                        var d = r / i;
                        if (d != i && d > b)
                        {
                            counter++;
                        }
                    }
                }

                Console.WriteLine(counter);
                return;
            }

        }

        static int r;
        static int getT(int del)
        {
            //var r = r1;
            if (r % del == 0)
            {
                int pos = 0;
                while (true)
                {
                    var rem = r % del;

                    if (rem == 0)
                    {
                        pos++;
                        r = r / del;
                    }
                    else
                    {
                        break;
                    }
                }

                return pos;
            }
            else
            {
                return 0;
            }
        }

        static int getT(int del, int r2)
        {
            //var r = r1;
            if (r2 % del == 0)
            {
                int pos = 0;
                while (true)
                {
                    var rem = r2 % del;

                    if (rem == 0)
                    {
                        pos++;
                        r2 = r2 / del;
                    }
                    else
                    {
                        break;
                    }
                }

                return pos;
            }
            else
            {
                return 0;
            }
        }
    }
}


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

namespace Codeforces
{
    class B
    {
        private static bool s_time = false;

        private static long mod = 1000000007;
        private static long pow(long a, long b)
        {
            long ret = 1;
            for (int i = 0; i < b; i++)
            {
                ret = (ret * a) % mod;
            }
            return ret;
        }

        private static object Go()
        {
            int ret = 1;

            int n = GetInt();
            int m = GetInt();
            int k = GetInt();

            if (n < k || k == 1)
                return pow(m, n);
            if (n == k)
                return pow(m, (n + 1) / 2);
            if (k % 2 == 0)
                return m;

            return (m + m * (m - 1)) % mod;
        }

        #region Template

        public static void Main(string[] args)
        {
            DateTime start = DateTime.Now;
            object output = Go();
            TimeSpan duration = DateTime.Now.Subtract(start);
            if (output != null)
                Wl<string>(output.ToString());
            if (s_time)
                Wl(duration);
        }

        private static IEnumerator<string> ioEnum;
        private static string GetString()
        {
            while (ioEnum == null || !ioEnum.MoveNext())
            {
                ioEnum = Console.ReadLine().Split().AsEnumerable().GetEnumerator();
            }

            return ioEnum.Current;
        }

        private static int GetInt()
        {
            return int.Parse(GetString());
        }

        private static long GetLong()
        {
            return long.Parse(GetString());
        }

        private static double GetDouble()
        {
            return double.Parse(GetString());
        }

        private static void Wl<T>(T o)
        {
            Console.WriteLine(o.ToString());
        }

        private static void Wl<T>(IEnumerable<T> enumerable)
        {
            Wl(string.Join(" ", enumerable.Select(e => e.ToString()).ToArray()));
        }

        public struct Tuple<T, K> : IComparable<Tuple<T, K>>
            where T : IComparable<T>
            where K : IComparable<K>
        {
            public T Item1;
            public K Item2;

            public Tuple(T t, K k)
            {
                Item1 = t;
                Item2 = k;
            }

            public override bool Equals(object obj)
            {
                var o = (Tuple<T, K>)obj;
                return o.Item1.Equals(Item1) && o.Item2.Equals(Item2);
            }

            public override int GetHashCode()
            {
                return Item1.GetHashCode() ^ Item2.GetHashCode();
            }

            public override string ToString()
            {
                return "(" + Item1 + " " + Item2 + ")";
            }

            #region IComparable<Tuple<T,K>> Members

            public int CompareTo(Tuple<T, K> other)
            {
                int ret = Item1.CompareTo(other.Item1);
                if (ret != 0) return ret;
                return Item2.CompareTo(other.Item2);
            }

            #endregion
        }

        #endregion
    }
}


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

namespace Codeforces
{
    class Program
    {

        public static readonly int MOD = Convert.ToInt32(1e9 + 7);
        public static readonly int oo = Convert.ToInt32(1e9);
        public static readonly long OO = Convert.ToInt64(1e18);

        static void Main(string[] args)
        {
            String[] data = Console.ReadLine().Split(' ');
            int LengthOfWord = int.Parse(data[0]);
            int alphabetSize = int.Parse(data[1]);
            int requiredPalindromLength = int.Parse(data[2]);
            if (requiredPalindromLength > LengthOfWord)
            {
                Console.WriteLine(ModPow(alphabetSize, LengthOfWord));
                return;
            }

            Dsu dsu = new Dsu(LengthOfWord + 1);
            if (requiredPalindromLength % 2 == 0)
            {

                for (int center = 1; center <= LengthOfWord; center++)
                {
                    if (Math.Min(center, LengthOfWord - center) >= requiredPalindromLength / 2)
                    {
                        for (int count = 0; count < requiredPalindromLength / 2; count++)
                        {
                            dsu.Unite(center - count, center + count + 1);
                        }
                    }
                }
            } else
            {
                for (int center = 1; center <= LengthOfWord; center++)
                {
                    if (Math.Min(center - 1, LengthOfWord - center) >= requiredPalindromLength / 2)
                    {
                        dsu.Unite(center, center);
                        for (int count = 1; count <= requiredPalindromLength / 2; count++)
                        {
                            dsu.Unite(center - count, center + count);
                        }
                    }
                }
            }

            long ans = 1;
            for (int vertex = 1; vertex <= LengthOfWord; vertex++)
            {
                if (dsu.Rank[vertex] > 0)
                {
                    ans = (ans * alphabetSize) % MOD;
                }
            }
            Console.WriteLine(ans);
        }

        static long ModPow(long num, long exponent)
        {
            if (exponent == 0) return 1;
            long m = ModPow(num, exponent / 2);
            return exponent % 2 == 0 ? m * m % MOD : m * m % MOD * num % MOD;
        }

        class Dsu
        {
            private int vertices;
            private int connectedComponent;
            private int[] parentOf;
            private int[] rank;

            public int Vertices { get; set; }
            public int ConnectedComponent { get; set; }
            public int[] ParentOf { get; set; }
            public int[] Rank { get; set; }

            public Dsu(int vertices)
            {
                Vertices = vertices;
                ConnectedComponent = vertices;
                ParentOf = Enumerable.Range(0, vertices).ToArray();
                Rank = Enumerable.Range(0, vertices).Select(v => v = 1).ToArray();
            }

            public bool IsConnected(int from, int to)
            {
                return GetAncestor(from) == GetAncestor(to);
            }

            public int GetAncestor(int descended)
            {
                while (descended != ParentOf[descended]) descended = ParentOf[descended];
                return descended;
            }

            public void Unite(int from, int to)
            {
                int ancestorOfFrom = GetAncestor(from);
                int ancestorOfTo = GetAncestor(to);
                if (ancestorOfFrom == ancestorOfTo) return;
                connectedComponent--;
                if (Rank[ancestorOfFrom] > Rank[ancestorOfTo])
                {
                    ParentOf[ancestorOfTo] = ParentOf[ancestorOfFrom];
                    Rank[ancestorOfFrom] += Rank[ancestorOfTo];
                    Rank[ancestorOfTo] = 0;
                } else
                {
                    ParentOf[ancestorOfFrom] = ParentOf[ancestorOfTo];
                    Rank[ancestorOfTo] += Rank[ancestorOfFrom];
                    Rank[ancestorOfFrom] = 0;
                }
            }

        }

    }

}


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

namespace tc2019r2
{
    class Program
    {
        static void Main(string[] args)
        {
           // Console.SetIn(new StreamReader("input.txt"));
            solve_tc2019r2A();
        }

        public static void solve_tc2019r2A()
        {
            int[] whk = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            int w = whk[0];
            int h = whk[1];
            int k = whk[2];

            int i = 0;

            int sum = 0;

            while (i < k)
            {
                sum += 2 * (w - i * 4 + h - i * 4) - 4;
                i++;
            }

            Console.WriteLine(sum);
        }
    }
}


using System;

namespace CSharp
{
    public class _1031A
    {
        public static void Main()
        {
            string[] tokens = Console.ReadLine().Split();

            int w = int.Parse(tokens[0]);
            int h = int.Parse(tokens[1]);
            int k = int.Parse(tokens[2]);

            Console.WriteLine(2 * k * (h + w + 2 - 4 * k));
        }
    }
}


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

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

    }

    public PairVariable(int a, int b, int c)
    {
        this.a = a;
        this.b = b;
        this.c = c;

    }

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

namespace ConsoleApplication3
{
    class Program
    {

        static bool isPrime(int n)
        {
            for (int i = 2; i <= Math.Sqrt(n); i++)
            {
                if (n % i == 0)
                {
                    return false;
                }
            }
            return true;
        }
        static int gcd(int a, int b)
        {
            if (b == 0)
            {
                return a;
            }
            else
            {
                return gcd(b, a % b);
            }
        }

        static int[] mark;
        static Dictionary<int, List<int>> d = new Dictionary<int, List<int>>();
        static void dfs(int v)
        {
            mark[v] = 1;
            for (int i = 0; i < d[v].Count; i++)
            {
                if (mark[d[v][i]] == 0)
                {
                    dfs(d[v][i]);
                }
            }
        }
        static void Main(string[] args)
        {
            long ans = 0;
            string[] ss = Console.ReadLine().Split();
            int m = int.Parse(ss[0]);
            int b = int.Parse(ss[1]);
            for (int y = 0; y <= b; y++)
            {
                int x = -((y - b) * m);
                if (x >= 0)
                {
                    //cout<<x<<" "<<y<<endl;
                    long temp = 0;
                    for (int j = 0; j <= y; j++)
                    {

                        if (j != 0)
                        {
                            long xx = x + j;
                            long yy = j - 1;

                            temp += ((xx * (xx + 1) / 2)) - (yy * (yy + 1) / 2);
                        }
                        else
                        {

                            long xx = x;

                            temp += (xx * (xx + 1) / 2);

                        }

                    }
                    ans = Math.Max(ans, temp);
                }

            }
            Console.WriteLine(ans);
        }
    }
}