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

namespace Codeforces
{
    class Program : ProgramBase
    {
        private const long commonMod = 1000000007;

        static void Main(string[] args)
        {
            var p = new Program();
            var x = p.Get();
            p.Out(x);
        }

        object Get()
        {
            checked
            {
                //FileName = "input";
                var n = ReadLongToken();
                var m = ReadLongToken();
                var nlog = logbase7(n);
                var mlog = logbase7(m);
                if (nlog + mlog > 7)
                    return 0;
                var log = nlog + mlog;

                var result = 0;

                var a = new int[7] { 0, 1, 2, 3, 4, 5, 6 };
                int[] prev = new int[7];
                do
                {
                    if (prev != null)
                    {
                        var fl = true;
                        for (int i = 0; i < log; i++)
                        {
                            if (a[i] != prev[i])
                            {
                                fl = false;
                                break;
                            }
                        }
                        if (fl)
                        {
                            continue;
                        }
                    }
                    var v = 0;
                    var pow = 1;
                    for (int i = 0; i < nlog; i++)
                    {
                        v += a[i] * pow;
                        pow *= 7;
                    }
                    if (v >= n)
                    {
                        Array.Copy(a, prev, 7);
                        continue;
                    }

                    pow = 1;
                    v = 0;
                    for (int i = 0; i < mlog; i++)
                    {
                        v += a[nlog + i] * pow;
                        pow *= 7;
                    }
                    if (v >= m)
                    {
                        Array.Copy(a, prev, 7);
                        continue;
                    }
                    result++;
                    Array.Copy(a, prev, 7);
                } while (NextPermutation(a));
                return result;
            }

        }
        private static bool NextPermutation(int[] numList)
        {
            /*
             Knuths
             1. Find the largest index j such that a[j] < a[j + 1]. If no such index exists, the permutation is the last permutation.
             2. Find the largest index l such that a[j] < a[l]. Since j + 1 is such an index, l is well defined and satisfies j < l.
             3. Swap a[j] with a[l].
             4. Reverse the sequence from a[j + 1] up to and including the final element a[n].

             */
            var largestIndex = -1;
            for (var i = numList.Length - 2; i >= 0; i--)
            {
                if (numList[i] < numList[i + 1])
                {
                    largestIndex = i;
                    break;
                }
            }

            if (largestIndex < 0) return false;

            var largestIndex2 = -1;
            for (var i = numList.Length - 1; i >= 0; i--)
            {
                if (numList[largestIndex] < numList[i])
                {
                    largestIndex2 = i;
                    break;
                }
            }

            var tmp = numList[largestIndex];
            numList[largestIndex] = numList[largestIndex2];
            numList[largestIndex2] = tmp;

            for (int i = largestIndex + 1, j = numList.Length - 1; i < j; i++, j--)
            {
                tmp = numList[i];
                numList[i] = numList[j];
                numList[j] = tmp;
            }

            return true;
        }

        public int logbase7(long v)
        {
            if (v <= 1)
                return 1;
            var res = 0;
            v = v - 1;
            while(v > 0)
            {
                v /= 7;
                res++;
            }
            return res;
        }

        public static class Struct
        {
            public static Pair<T1, T2> Create<T1,T2>(T1 item1, T2 item2)
            {
                return new Pair<T1, T2> { Item1 = item1, Item2 = item2 };
            }
        }

        public struct Pair<T1, T2>
        {
            public T1 Item1 { get; set; }
            public T2 Item2 { get; set; }
        }

        class Automata
        {
            bool[] terminals;
            public int sigma;
            public int len;
            public int[,] jumps;

            public void Create()
            {
                var a = ReadInts();
                len = a[0];
                sigma = a[2];
                var ts = ReadInts();
                terminals = new bool[len];
                for (int i = 0; i < ts.Length; i++)
                    terminals[ts[i]] = true;
                jumps = new int[len, sigma];
                for (int i = 0; i < len * sigma; i++)
                {
                    var b = Console.ReadLine().Split(' ');
                    jumps[Convert.ToInt32(b[0]), b[1][0] - 'a'] = Convert.ToInt32(b[2]);
                }
            }
            protected int[] ReadInts()
            {
                return Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
            }

            public bool IsTerminal(int s)
            {
                return terminals[s];
            }
        }
    }

    abstract class ProgramBase
    {
        bool? prod = null;
        StreamReader f;
        Queue<string> tokens;
        protected string FileName { private get; set; }

        protected string Read()
        {
            if (f == null)
                f = string.IsNullOrEmpty(FileName)
                    ? new StreamReader(Console.OpenStandardInput())
                    : new StreamReader((GetProd() ? "" : "c:\\dev\\") + FileName);
            return f.ReadLine();
        }

        protected int ReadInt()
        {
            return int.Parse(Read());
        }

        protected int ReadIntToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return int.Parse(tokens.Dequeue());
        }

        protected int[] ReadInts()
        {
            var tokens = Read().Split(' ');
            var result = new int[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = int.Parse(tokens[i]);
            return result;
        }

        protected long ReadLongToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return long.Parse(tokens.Dequeue());
        }

        protected long ReadLong()
        {
            return Convert.ToInt64(Read());
        }

        protected long[] ReadLongs()
        {
            var tokens = Read().Split(' ');
            var result = new long[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = long.Parse(tokens[i]);
            return result;
        }

        public void Out(object r)
        {
            if (string.IsNullOrEmpty(FileName))
                Console.WriteLine(r);
            else if (GetProd())
                File.WriteAllText(FileName, r.ToString());
            else
                Console.WriteLine(r);
        }

        private bool GetProd()
        {

            if (!prod.HasValue)
                try
                {
                    prod = Environment.MachineName != "RENADEEN-W7";
                }
                catch (Exception)
                {
                    prod = true;
                }
            return prod.Value;
        }
    }

    public static class Huj
    {
        public static T MinBy<T>(this IEnumerable<T> source, Func<T, double> func) where T : class
        {
            T result = null;
            var min = double.MaxValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (min > current)
                {
                    min = current;
                    result = item;
                }
            }
            return result;
        }

        public static T MaxBy<T>(this IEnumerable<T> source, Func<T, double> func, T defaultValue = default(T))
        {
            T result = defaultValue;
            var max = double.MinValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (max < current)
                {
                    max = current;
                    result = item;
                }
            }
            return result;
        }

        public static string JoinStrings(this IEnumerable<string> source, string delimeter)
        {
            return string.Join(delimeter, source.ToArray());
        }

        public static string JoinStrings(this IEnumerable<int> source, string delimeter)
        {
            return source.Select(x => x.ToString()).JoinStrings(delimeter);
        }
    }
}


using System;
using System.Linq;

namespace CodeForce
{
    internal class Quserty
    {
        private static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var inps = input.Split(' ');
            var length = int.Parse(inps.First());
            var diameter = int.Parse(inps[1]);

            input = Console.ReadLine();
            var array = input.Split(' ').Select(int.Parse).OrderBy(it => it).ToArray();
            var max = array[array.Length - 1];

            var isInSet = new int[max + 1];
            for (var i = 0; i < array.Length; i++)
            {
                var el = array[i];
                isInSet[el] += 1;
            }

            for (var i = 1; i < isInSet.Length; i++)
            {
                isInSet[i] = isInSet[i - 1] + isInSet[i];
            }

            var result = int.MaxValue;

            for (var i = 0;; i++)
            {
                var leftElement = array[i];
                var rightElement = leftElement + diameter;
                if (rightElement > max)
                {
                    rightElement = max;
                }

                var diff = isInSet[rightElement] - isInSet[leftElement - 1];
                var newResult = array.Length - diff;
                result = Math.Min(result, newResult);

                if (rightElement == max)
                {
                    break;
                }
            }

            Console.WriteLine(result);
        }
    }
}


using System;
using System.Linq;

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

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

            var x = Console.ReadLine().Split().Select(token => int.Parse(token)).ToArray();
            Array.Sort(x);

            Console.WriteLine(n - Enumerable.Range(0, n).Max(r => Enumerable.Range(0, r + 1).Where(l => x[r] - x[l] <= d).Max(l => r + 1 - l)));
        }
    }
}


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

        int[] id = new int[m];
        int?[] status = new int?[n];

        int cand = -1;
        for (int i = 0; i < m; i++)
        {
            bool action = ReadToken() == "+";
            id[i] = ReadInt() - 1;
            if (status[id[i]] == null)
            {
                status[id[i]] = action ? 1 : 2;
                if (!action)
                    cand = id[i];
            }
        }
        if (cand == -1)
            cand = id[0];

        var set = new SortedSet<int>(Enumerable.Range(1, n).Where(i => status[i - 1] == null));
        bool[] on = Enumerable.Range(0, n).Select(i => status[i] == 2).ToArray();
        int onCount = status.Count(s => s == 2);
        int step;
        for (step = 0; step < m; step++)
        {
            if (id[step] == cand)
            {
                if (on[cand] && onCount > 1)
                    break;
            }
            else if (!on[cand])
                    break;
            on[id[step]] = !on[id[step]];
            if (on[id[step]])
                onCount++;
            else
                onCount--;
        }
        if (step == m)
            set.Add(cand + 1);

        writer.WriteLine(set.Count);
        WriteArray(set);

        return null;
    }

    #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 = Console.Out;
#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()
    {
        if (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 string[] ReadLines(int quantity)
    {
        string[] lines = new string[quantity];
        for (int i = 0; i < quantity; i++)
            lines[i] = reader.ReadLine().Trim();
        return lines;
    }

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

    #endregion
}


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

namespace ProblemSets
{
    using System;
    using System.Collections.Generic;
    using System.Collections;
    using System.Linq;
    using System.Text;

    namespace LongPath
    {
        public class Problem420b
        {
            public static void Main(string[] args)
            {
                var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                var numberOfPeople = input[0];
                var numberOfMessage = input[1];

                bool[] seen = new bool[100000 + 1];
                int leaderId = -1;
                bool leaderOnline = false;
                var peopleOnline = 0;

                for (int i = 0; i < numberOfMessage; i++)
                {
                    var status = Console.ReadLine().Split(' ');
                    var symbol = status[0][0];
                    var id = int.Parse(status[1]);

                    if (symbol == '+')
                    {

                            if(i== 0)
                            {
                               leaderId = id;
                               leaderOnline = true;
                            }

                        else // there is a leader
                        {
                            if (leaderOnline)
                            {
                                //do nothing
                            }
                            else
                            {
                                if (leaderId == id)
                                {
                                    leaderOnline = true;
                                }
                                else
                                {
                                    leaderId = -1;
                                    leaderOnline = false;
                                }
                            }
                        }
                        peopleOnline++;
                    }

                    if (symbol == '-')
                    {
                        if (!seen[id])
                        {
                            if (peopleOnline == 0)
                            {
                                leaderId = id;
                                leaderOnline = false;
                            }
                            else
                            {
                                leaderId = -1;
                                leaderOnline = false;
                            }
                        }

                        else
                        {
                            peopleOnline = Math.Max(--peopleOnline, 0);
                            if (leaderId == -1)
                            {
                                //if there is no leader, do nothing
                            }
                            else
                            {
                                if (leaderId == id)
                                {
                                    if (peopleOnline > 0)
                                    {
                                        leaderId = -1;
                                        leaderOnline = false;
                                    }
                                    else
                                    {
                                        leaderOnline = false;
                                    }
                                }
                                else
                                {
                                    if (!leaderOnline)
                                    {
                                        leaderId = -1;
                                        leaderOnline = false;
                                    }
                                }
                            }
                        }

                    }
                    seen[id] = true;
                }

                var leaders = new ArrayList();
                for (int i = 1; i <= numberOfPeople; i++)
                {
                    if (!seen[i]) leaders.Add(i);
                    else if (leaderId == i) leaders.Add(i);
                }

                var numberOfLeader = leaders.Count;
                Console.WriteLine(numberOfLeader);

                foreach (var leader in leaders)
                {
                    Console.Write(leader);
                    Console.Write(" ");
                }

            }
        }
    }
}


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

namespace example
{
    class Program
    {
        public static void Main(string[] args)
        {
            var line = Console.ReadLine().Split();
            int[] array = line.Select(p => int.Parse(p)).ToArray();
            Array.Sort(array);
            int a = array[0];
            int b = array[1];
            int c = array[2];
            if(Can(a,b,c))
                Console.WriteLine("YES");
            else Console.WriteLine("NO");
        }

        public static bool Can(int a, int b, int c)
        {
            if (a == 1)
                return true;
            if (a == 2 && (b == 2 ||(b == 4 && c == 4)))
                return true;
            if (a == 3 && b == 3 && c == 3)
                return true;

            return false;
        }
    }
}


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

class Solver
{
    public void Solve(Scanner sc)
    {
        var K = sc.ArrInt.Select((v, idx) => (v: v, idx: idx)).ToArray();
        Array.Sort(K, (a, b) => a.v - b.v);
        if (K[0].v == 1) Fail("YES");
        if (K.Select(k => k.v).Count(a => a <= 2) >= 2) Fail("YES");
        if (K.Select(k => k.v).All(v => v == 3)) Fail("YES");
        if (K[0].v == 2 && K[1].v == 4 && K[2].v == 4) Fail("YES");
        Console.WriteLine("NO");
    }
}

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

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

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

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


using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
using System.Numerics;
using Point = System.Numerics.Complex;
using Number = System.Int64;
namespace Program
{
    public class Solver
    {
        public void Solve()
        {
            var q = sc.Integer();
            var par = new int[500002];
            par[0] = -1;
            var dp = Enumerate(500002, x => new double[45]);
            for (int i = 1; i < 45; i++)
                dp[0][i] = 1.0;

            var ptr = 1;
            Action<int> recalc = null;
            recalc = v =>
              {
                  for (int h = 1; h < 40; h++)
                      dp[v][h] = 1.0;
                  var ps = new List<int>();
                  for (int h = 0; h <= 40; h++)
                  {
                      if (v == -1) break;
                      ps.Add(v);
                      v = par[v];
                  }
                  for (int i = ps.Count - 2; i > 0; i--)
                  {
                      var u = ps[i]; var h = i;
                      var p = ps[i + 1];
                      dp[p][h + 1] /= (dp[u][h] + 1) / 2;
                  }
                  for (int i = 0; i + 1 < ps.Count; i++)
                  {
                      var u = ps[i]; var h = i;
                      var p = ps[i + 1];
                      dp[p][h + 1] *= (dp[u][h] + 1) / 2;
                  }
              };
            for (int i = 0; i < q; i++)
            {
                if (sc.Integer() == 1)
                {
                    var p = sc.Integer() - 1;
                    par[ptr] = p;
                    recalc(ptr);
                    ptr++;

                }
                else
                {
                    var v = sc.Integer() - 1;
                    var ans = 0.0;
                    for (int h = 1; h < 40; h++)
                        ans += 1 - dp[v][h];
                    Debug.WriteLine(dp[v].AsJoinedString());
                    IO.Printer.Out.WriteLine(ans);

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

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

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

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


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

namespace codeforces
{
    class Program
    {

        static void Main(string[] args)
        {
            ulong n = Convert.ToUInt64(Console.ReadLine());
            ulong value = n % 2;
            if (value == 0)
                value = 2;
            Console.WriteLine(value);
        }
    }
}


using System;

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

            if (n % 2 == 0)
                Console.WriteLine(2);
            else
                Console.WriteLine(1);
        }
    }
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        string cf = "codeforces";
        var k = long.Parse(Console.ReadLine());
        long[] counts = Enumerable.Repeat(1L, cf.Length).ToArray();
        int ind = 0;
        while (true)
        {
            if (k <= counts.Aggregate(1L, (x, y) => x * y)) break;
            counts[ind]++;
            ind = (ind + 1) % counts.Length;
        }
        Console.WriteLine(string.Join("", counts.SelectMany((count, i) => Enumerable.Repeat(cf[i], (int)count))));
    }
}


using System;
using System.Linq;

namespace TaskB
{
    class Program
    {
        static void Main(string[] args)
        {
            var p = long.Parse(Console.ReadLine());

            long ans = 1;
            var mas = new[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
            var i = 0;
            while (ans < p)
            {
                mas[i]++;

                ans = Calc(mas);

                i++;
                i %= 10;

            }

            var s = "codeforces";
            for (int j = 0; j < 10; j++)
            {
                for (int k = 0; k < mas[j]; k++)
                {
                    Console.Write(s[j]);
                }
            }
        }

        private static long Calc(int[] mas)
        {
            return mas.Aggregate<int, long>(1, (current, t) => current * t);
        }
    }
}


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

namespace Codeforces
{

    public class C
    {

        public static void Main(string[] args)
        {
            string[] token = Console.ReadLine().Split();

            int n = int.Parse(token[0]);
            int m = int.Parse(token[1]);
            long k = long.Parse(token[2]);
            int x = int.Parse(token[3]);
            int y = int.Parse(token[4]);

            int sTo = ((x-1)*m) + y;
            int sBo = ((n-x)*m) + y;

            if(k<m*n){
              int sQ = (sTo<=k)?1:0;
              Console.WriteLine(1 + " " + 0 + " " + sQ);
            }
            else if (n > 2)
            {
                int A = (n * m) - m;
                long KK = k - m;
                long mod = KK % A;
                long div = (KK - mod) / A;
                long max = 0;
             //   if( n>2){
                  max = (mod > 0) ? div + 1 : div;
                  long v = 1 + div;
                  long min = (v%2!=0)?(v-1)/2:v/2;

                  long sQ = div;

                  if(x==1){
                    sQ =(div%2!=0)?(div-1)/2:div/2;
                    sQ++;
                  }else if(x==n){
                    sQ =(div%2!=0)?(div+1)/2:div/2;
                  }

                //  Console.WriteLine(v);
                  if((v%2==0 && sBo-m<=mod && x!=n) || (v%2!=0 && sTo-m<=mod && x!=1)){
                      sQ++;
                  }

                  Console.WriteLine((max) + " " + (min) + " " + sQ);
               // }
            }
            else
            {
                long mod = k%(m*n);
                long min = (k - mod) / (m*n);
                long max = (mod > 0) ? min + 1 : min;
                long sQ = (sTo<=mod)?min+1:min;

                Console.WriteLine(max + " " + min + " " + sQ);
            }
        }
    }

}


using System;

namespace _758C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            long n = long.Parse(input[0]), m = long.Parse(input[1]), x = long.Parse(input[3]), y = long.Parse(input[4]),
                k = long.Parse(input[2]);
            long T = 0, periods = 0;
            if (n > 2) T = m * (2 * n - 2);
            else T = m * n;
            if (T > 0)
            {
                periods = k / T;
                k = k % T;
            }
            long[,] matrix = new long[n, m];
            long min = long.MaxValue, max = 0;
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                {
                    matrix[i, j] = periods * ((i == 0 || i == n - 1) ? 1 : 2);
                    if (k > 0)
                    {
                        matrix[i, j]++;
                        k--;
                    }
                }
            for (int i = (int)n - 2; i >= 0; i--)
                for (int j = 0; j < m; j++)
                {
                    if (k > 0)
                    {
                        matrix[i, j]++;
                        k--;
                    }
                }
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                {
                    if (matrix[i, j] < min) min = matrix[i, j];
                    if (matrix[i, j] > max) max = matrix[i, j];
                }
            Console.WriteLine(max + " " + min + " " + matrix[x - 1, y - 1]);
        }
    }
}


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

class Program
{
    private static bool IsSimple(int x)
    {
        if ((x & 1) == 0) return x == 2;

        int end = (int)Math.Sqrt(x);
        for (int i = 3; i <= end; i += 2)
            if (x % i == 0)
                return false;

        return true;
    }

    private static int Solve(int n)
    {
        if (IsSimple(n)) return 1;
        if (n % 2 == 0) return 2;

        if (IsSimple(n - 2))
            return 2;

        return 3;
    }

    static void Main(string[] args)
    {
        Console.WriteLine(Solve(RI()));
    }

    private const int Mod = 1000000000 + 7;

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

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

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

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

        return g;
    }

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

        return matrix;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        return s.ToArray();
    }

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

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

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

        return s;
    }

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

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

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

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

        return s.ToArray();
    }

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

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

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

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

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

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

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

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

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

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


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

namespace _735D
{
    class Program
    {
        static bool IsPrime(long x)
        {
            if (x == 2)
            {
                return true;
            }
            else
            {
                var boundary = (int)Math.Floor(Math.Sqrt(x));
                for (int i = 2; i <= boundary; ++i)
                {
                    if (x % i == 0) return false;
                }
                return true;
            }
        }

        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            if (IsPrime(n))
            {
                Console.WriteLine("1");
            }
            else if (n % 2 == 0 || IsPrime(n - 2))
            {
                Console.WriteLine("2");
            }
            else
            {
                Console.WriteLine("3");
            }
            //Console.ReadLine();
        }
    }
}


/*
csc -debug C.cs && mono --debug C.exe <<< "3 3 0"
*/

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

public class HelloWorld {
    static public void Main () {
        SolveCodeForces();
    }

    public static void SolveCodeForces() {
        var sc = new Scanner();
        var n = sc.NextInt();
        var m = sc.NextUlong();
        var k = sc.NextInt();

        const ulong MOD = 998244353ul;

        var S = new ulong[n, k+1];
        S[0, 0] = m;

        for (var i = 1; i < n; i++) {

            S[i, 0] = m;

            for (var j = 1; j <= k; j++) {
                S[i, j] = (  S[i-1, j-1] * (m-1) + S[i-1, j]  ) % MOD;
            }

        }

        System.Console.WriteLine(S[n-1, k]);
    }
}

public static class Helpers {
    public static T[] CreateArray<T>(int length, Func<int, T> itemCreate) {
        var result = new T[length];
        for (var i = 0; i < result.Length; i++)
            result[i] = itemCreate(i);
        return result;
    }

    public static T ElementWithMax<T>(this IEnumerable<T> seq, Func<T, long> func) {
        var bi = default(T);
        var bv = long.MinValue;
        foreach (var item in seq) {
            var v = func(item);
            if (v > bv) {
                bi = item;
                bv = v;
            }
        }
        return bi;
    }

    public static IEnumerable<int> IndicesWhere<T>(this IEnumerable<T> seq, Func<T, bool> cond) {
        var i = 0;
        foreach (var item in seq) {
            if (cond(item)) yield return i;
            i++;
        }
    }
}

public class Scanner
{
    private string[] line = new string[0];
    private int index = 0;

    public string Next() {
        if (line.Length <= index) {
            line = Console.ReadLine().Split(' ');
            index = 0;
        }
        var res = line[index];
        index++;
        return res;
    }

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

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

    public ulong NextUlong() {
        return ulong.Parse(Next());
    }

    public string[] Array() {
        line = Console.ReadLine().Split(' ');
        index = line.Length;
        return line;
    }

    public int[] IntArray() {
        var array = Array();
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = int.Parse(array[i]);
        return result;
    }

    public long[] LongArray() {
        var array = Array();
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = long.Parse(array[i]);
        return result;
    }

    public ulong[] UlongArray() {
        var array = Array();
        var result = new ulong[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = ulong.Parse(array[i]);
        return result;
    }
}


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

namespace codeforces
{

    class Program
    {
        const int N = 2000;
        const int MOD = 998244353;

        static int n, m, k;
        static int[,] dp = new int[N, N];

        static int mul(int a, int b)
        {
            return (int) ((1L * a * b) % MOD);
        }

        static int add(int a, int b)
        {
            int result = a + b;
            if (result >= MOD)
            {
                result -= MOD;
            }
            return result;
        }

        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split(' ');
            n = int.Parse(s[0]);
            m = int.Parse(s[1]);
            k = int.Parse(s[2]);
            for (int i = 0; i < n; ++i)
            {
                for (int j = 0; j < n; ++j)
                {
                    dp[i, j] = 0;
                }
            }
            dp[0, 0] = m;
            for (int i = 1; i < n; ++i)
            {
                for (int j = 0; j <= i; ++j)
                {
                    dp[i, j] = j == 0
                        ? dp[i - 1, j]
                        : add(dp[i - 1, j], mul(m - 1, dp[i - 1, j - 1]));
                }
            }
            Console.WriteLine(dp[n - 1, k]);
        }
    }
}


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

namespace HayCragrer
{
    class Problem4
    {
        static void Main(string[] args)
        {
            int[] coords = new int[4];
            string[] text = Console.ReadLine().Split();
            string[] text1 = Console.ReadLine().Split();
            int[] steps = new int[2];
            for (int i = 0; i < 4; i++)
            {
                coords[i] = int.Parse(text[i]);
            }
            for (int i = 0; i < 2; i++)
            {
                steps[i] = int.Parse(text1[i]);
            }
            int x = coords[2] - coords[0];
            int y = coords[3] - coords[1];
            if ((x % steps[0] == 0) && (y % steps[1] == 0))
            {
                if ((x / steps[0] -y / steps[1]) % 2==0)
                {
                    Console.WriteLine("YES");
                }
                else
                {
                    Console.WriteLine("NO");
                }

            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}


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

namespace Codeforces
{
    class P817A
    {
        static void Main(string[] args)
        {
            string[] input1 = Console.ReadLine().Split();
            int x1 = int.Parse(input1[0]);
            int y1 = int.Parse(input1[1]);
            int x2 = int.Parse(input1[2]);
            int y2 = int.Parse(input1[3]);
            string[] input2 = Console.ReadLine().Split();
            int x = int.Parse(input2[0]);
            int y = int.Parse(input2[1]);
            Console.WriteLine((Math.Abs(x1 - x2) % x == 0 && Math.Abs(y1 - y2) % y == 0 && (Math.Abs(x1 - x2) / x) % 2 == (Math.Abs(y1 - y2) / y) % 2) ? "YES" : "NO");
        }
    }
}


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

namespace CodeForces.C664
{
    class Pa
    {
        static void Main(string[] args)
        {
            string[] numbers = Console.ReadLine().Split(' ').ToArray();
            if (numbers[0] == numbers[1]) Console.WriteLine(numbers[0]);
            else Console.WriteLine(1);
        }
    }
}


using System;

namespace CSharp
{
    public class _664A
    {
        public static void Main()
        {
            string[] tokens = Console.ReadLine().Split();
            Console.WriteLine(tokens[0] == tokens[1] ? tokens[0] : "1");
        }
    }
}


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

public class C1
{
  public static void Main ( )
  {
#if MYTRIAL
    Console.SetIn ( new StreamReader ( @"e:\zin.txt" ) );
#endif
    //solve ( );
    Console.WriteLine ( solve ( ) );
  }

  private static int solve ( )
  {
    long N = long.Parse ( Console.ReadLine ( ) );
    for ( int b = 0; b <= 90; b++ )
    {
      long D = GetDisc ( 1, b, -N );
      if ( D < 0 )
        continue;
      long sqrtd = ( long ) Math.Sqrt ( D );
      if ( sqrtd * sqrtd != D )
        continue;
      double x1 = ( -b + sqrtd ) / 2.0;
      if ( x1 == Math.Floor ( x1 ) && x1 >= 0 )
      {
        if ( b == sumd ( ( int ) x1 ) )
          return ( int ) x1;
      }

      double x2 = ( -b - sqrtd ) / 2.0;
      if ( x2 == Math.Floor ( x2 ) && x2 >= 0 )
      {
        if ( b == sumd ( ( int ) x2 ) )
          return ( int ) x2;
      }
    }

    return -1;
  }

  static int sumd ( int x )
  {
    int sum=0;
    while ( x > 0 )
    {
      sum += x % 10;
      x = x / 10;
    }
    return sum;
  }

  static long GetDisc ( long a, long b, long c )
  {
    return b * b - 4 * a * c;
  }

  public static int[] ReadLineToInts ( int length )
  {
    string line = Console.ReadLine ( ).Trim ( );
    string[] arStrings = line.Split ( ' ' );

    int[] ints = new int[length];
    for ( int i=0; i < length; i++ )
      ints[i] = int.Parse ( arStrings[i] );
    return ints;
  }

}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Int64 n = Convert.ToInt64(Console.ReadLine());

            int i, f = 0;
            Int64 s, d, x = -1;

            for (i = 1; i <= 90; i++)
            {
                d = i * i + 4 * n;
                s = (Int64)Math.Sqrt(d);
                if(s*s==d)
                {
                    x = (Int64)s - i;

                    if (x % 2 == 0)
                    {
                        x = (int)(s - i) / 2;
                        if (i == DigitSum(x))
                        {
                            f = 1;
                            break;
                        }
                    }
                }
            }

            if (f == 0)
                Console.WriteLine("-1");
            else
                Console.WriteLine(x);

        }

        private static int DigitSum(Int64 x)
        {
            int sum = 0;
            while (x != 0)
            {
                sum += (int)(x % 10);
                x /= 10;
            }
            return sum;
        }
    }
}


using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
using System.Numerics;
namespace Program
{

    public class Solver
    {
        public void Solve()
        {
            var n = sc.Integer();
            var T = sc.Integer();
            var a = sc.Integer(n);
            var v = a.Distinct().ToList();
            v.Sort();
            for (int i = 0; i < n; i++)
                a[i] = v.BinarySearch(a[i]);
            var m = v.Count;
            var mat = new TropicalMatrix(m, m);
            for (int i = 0; i < m; i++)
                for (int j = i; j < m; j++)
                {
                    var dp = Enumerate(n + 1, x => 1L << 60);
                    foreach (var x in a)
                    {
                        if (x < i || x > j) continue;
                        dp[dp.UpperBound(x)] = x;
                    }
                    mat[i, j] = dp.LowerBound(1L << 60);
                    Debug.WriteLine("{0} {1} {2}", i, j, mat[i, j]);
                }
            var ret = TropicalMatrix.Pow(mat, T);
            IO.Printer.Out.WriteLine(ret[0, m - 1]);
        }
        public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());
        static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; }
        static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
    }

}

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

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

        public char[] Char(int n) { return enumerate(n, Char); }
        public string[] Scan(int n) { return enumerate(n, Scan); }
        public double[] Double(int n) { return enumerate(n, Double); }
        public int[] Integer(int n) { return enumerate(n, Integer); }
        public long[] Long(int n) { return enumerate(n, Long); }
    }
}
#endregion
#region Tropical Matrix
public class TropicalMatrix
{
    int row, col;
    public long[] mat;
    const long min = -1L << 60;
    public long this[int r, int c]
    {
        get { return mat[r * col + c]; }
        set { mat[r * col + c] = value; }
    }
    public TropicalMatrix(int r, int c)
    {
        row = r; col = c;
        mat = new long[row * col];
        for (int i = 0; i < row * col; i++)
            mat[i] = min;
    }
    public static TropicalMatrix operator +(TropicalMatrix l, TropicalMatrix r)
    {
        check(l, r);
        var ret = new TropicalMatrix(l.row, l.col);
        for (int i = 0; i < l.row; i++)
            for (int j = 0; j < l.col; j++)
                ret.mat[i * ret.col + j] = Math.Max(l.mat[i * l.col + j], r.mat[i * r.col + j]);
        return ret;

    }
    public static TropicalMatrix operator *(TropicalMatrix l, TropicalMatrix r)
    {
        checkMul(l, r);
        var ret = new TropicalMatrix(l.row, l.col);

        for (int i = 0; i < l.row; i++)
            for (int k = 0; k < l.row; k++)
                for (int j = 0; j < l.col; j++)
                    ret.mat[i * l.col + j] = Math.Max(ret.mat[i * l.col + j],
                        l.mat[i * l.col + k] + r.mat[k * l.col + j]);
        return ret;
    }
    public static TropicalMatrix Pow(TropicalMatrix m, long n)
    {
        var ret = new TropicalMatrix(m.row, m.col);
        for (int i = 0; i < m.row; i++)
            ret.mat[i * m.col + i] = 0;
        for (; n > 0; m *= m, n >>= 1)
            if ((n & 1) == 1)
                ret = ret * m;
        return ret;

    }
    public static TropicalMatrix Trans(TropicalMatrix m)
    {
        var ret = new TropicalMatrix(m.col, m.row);
        for (int i = 0; i < m.row; i++)
            for (int j = 0; j < m.col; j++)
                ret.mat[j * m.col + i] = m.mat[i * m.col + j];
        return ret;
    }
    [System.Diagnostics.Conditional("DEBUG")]
    static private void check(TropicalMatrix a, TropicalMatrix b)
    {
        if (a.row != b.row || a.col != b.col)
            throw new Exception("row and col have to be same.");

    }
    [System.Diagnostics.Conditional("DEBUG")]
    static private void checkMul(TropicalMatrix a, TropicalMatrix b)
    {
        if (a.col != b.row)
            throw new Exception("row and col have to be same.");

    }
}
#endregion

#region BinarySearch for long[]
static public partial class Algorithm
{

    static public int LowerBound(this long[] arr, long v)
    {
        int l = 0, h = arr.Length - 1;
        while (l <= h)
        {
            int m = ((h + l) >> 1);
            if (arr[m] < v) l = m + 1;
            else h = m - 1;
        }
        return l;
    }
    static public int UpperBound(this long[] a, long v)
    {
        int l = 0, h = a.Length - 1;
        while (l <= h)
        {
            int m = ((h + l) >> 1);
            if (a[m] <= v) l = m + 1;
            else h = m - 1;
        }
        return l;
    }

}
#endregion


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

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

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

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

            var maxK = new int[nn.Max() + 1];
            foreach (int i in nn)
            {
                maxK[i]++;
            }
            int maxx = maxK.Max();

            var max1 = new int[nn.Max() + 1];

            for (int t = 1; t <= 102; t++)
            {
                for (int i = 0; i < n; i++)
                {
                    int m = 0;
                    for (int j = 0; j <= nn[i]; j++)
                    {
                        if (m < max1[j])
                            m = max1[j];
                    }
                    max1[nn[i]] = m + 1;
                }
                if (T == t)
                {
                    writer.WriteLine(max1.Max());
                    writer.Flush();
                    return;
                }
            }

            writer.WriteLine(max1.Max() + maxx*(T - 102));
            writer.Flush();
        }

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


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

namespace CodeForces
{
    class R172_Div2_B
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int x = int.Parse(s[0]);
            int y = int.Parse(s[1]);
            int n = int.Parse(s[2]);
            double dx = (double) x;
            double dy = (double) y;

            long mina = 0, minb = 0;
            double min = long.MaxValue;
            for (long b = 1; b <= n; b++)
            {
                double db = (double)b;
                long aMin = b * x / y;
                long aMax = Convert.ToInt64(Math.Ceiling(db * dx / dy));

                for (long a = aMin; a <= aMax; a++)
                {
                    double da = (double)a;
                    double d = Math.Abs(dx / dy - da / db);
                    d = Math.Floor(d * 1e15) / 1e15;
                    if (d < min)
                    {
                        min = d;
                        mina = a;
                        minb = b;
                    }
                }
            }

            Console.WriteLine(mina + "/" + minb);

        }
    }
}


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

namespace Codeforces.R281.B
{
    public static class Solver
    {
        public static void Main()
        {
            using (var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false })
            {
                Solve(Console.In, sw);
            }
        }

        public static void Solve(TextReader tr, TextWriter tw)
        {
            var w = tr.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            tw.WriteLine(Calc(w[0], w[1], w[2]));
        }

        private static string Calc(int x, int y, int n)
        {
            var e = long.MaxValue;
            var eDenominator = 1L;

            var resA = 0L;
            var resB = 0L;

            for (var b = 1L; b <= n; ++b)
            {
                var l = 0L;
                var h = (x / y + 1) * b + 3;

                for (; l + 2 < h; )
                {
                    var m1 = (l * 2 + h) / 3;
                    var m2 = (l + h * 2) / 3;
                    var err1 = Math.Abs(x * b - y * m1);
                    var err2 = Math.Abs(x * b - y * m2);

                    if (err1 <= err2)
                    {
                        h = m2;
                    }
                    else
                    {
                        l = m1;
                    }
                }

                for (var a = l; a <= h; ++a)
                {
                    var currentError = Math.Abs(x * b - y * a);
                    if (currentError * eDenominator < e * b)
                    {
                        e = currentError;
                        eDenominator = b;
                        resA = a;
                        resB = b;
                    }
                }
            }

            return resA + "/" + resB;
        }
    }
}


/*
 * Created by SharpDevelop.
 * Handle: Arcos
 */
using System;
using System.Collections;
using System.ComponentModel;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;

namespace TestingStuff
{
	class Program
	{
		public static void Main(string[] args)
		{
			var st = Console.ReadLine();
			Regex rgx1 = new Regex("[A-Z]");
			Regex rgx2 = new Regex("[a-z]");
			Regex rgx3 = new Regex("[0-9]");
			if (st.Length > 4 &&
			    rgx1.IsMatch(st) &&
			    rgx2.IsMatch(st) &&
			    rgx3.IsMatch(st)){
				print("Correct");
			} else {
				print("Too weak");
			}

//			read();
			return;
		}

		public static String formatDouble(Double num){
			return String.Format("{0:0.0000000}",num).Replace(',','.');
		}

		public static void print(object a){
			Console.WriteLine(a.ToString());
		}

		public static void printList(List<String> a){
			foreach (object o in a){
				Console.WriteLine(o.ToString());
			}

		}

		public static void printList(List<int> a){
			String ou = "";
			foreach (object o in a){
				ou += o.ToString();
			}
			Console.WriteLine("List: " + ou);
		}

		public static void printListList(List<List<int>> a){
			String ou = "";
			foreach (List<int> o in a){
				foreach (int oo in o){
					ou += oo + " ";
				}
			}
			Console.WriteLine("List: " + ou);
		}

		public static void read(){
			Console.ReadLine();
		}
	}
}

// Remember these:
// lis2.Take(n-1).Sum()
// String.Format("{0:0}",f).ToString(CultureInfo.InvariantCulture); -- handles printing double/float
// Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase);
// var splstr = Console.ReadLine().Split(' ').ToList();
// var str = Console.ReadLine();
// var lis = new List<int>();
//			foreach(string strItem in splstr ){
//				lis.Add(int.Parse(strItem));
//			}
//			for(int i = 0; i < n; i++){
//				for(int j = 0; j < 3; j++){
//					print(lisLis[i][j]);
//				}
//			}


using System;
using System.Text.RegularExpressions;

namespace codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            Console.WriteLine(Regex.IsMatch(str, ".{5,}") &&
                              Regex.IsMatch(str, "[a-z]{1,}") &&
                              Regex.IsMatch(str, "[A-Z]{1,}") &&
                              Regex.IsMatch(str, "[0-9]{1,}") ?
                              "Correct" :
                              "Too weak");
        }
    }
}


using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		int[]A = new int[N];
		string[]str = Console.ReadLine().Split();
		int min = 999999999;
		for(var i=0;i<N;i++){
			A[i] = int.Parse(str[i]);
			min = Math.Min(A[i],min);
		}
		int ct = 0;
		for(var i=0;i<N;i++){
			if(A[i]==min){
				ct++;
			}
		}
		string ans = "";
		if(ct > N/2){
			ans = "Bob";
		} else {
			ans = "Alice";
		}
		Console.WriteLine(ans);
	}
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;
public class CodeForces
{
#if TEST
    // To set this go to Project -> Properties -> Build -> General -> Conditional compilation symbols: -> enter 'TEST' into text box.
    const bool testing = true;
#else
const bool testing = false;
#endif

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

    struct Point
    {
        public int x { get; set; }
        public int y { get; set; }
    }
    static void program(TextReader input)
    {
        //var n = int.Parse(input.ReadLine().TrimEnd());
        var data = input.ReadLine().Split(' ').Select(int.Parse).ToList();
        var x1 = data[0];
        var y1 = data[1];
        var data2 = input.ReadLine().Split(' ').Select(int.Parse).ToList();
        var x2 = data2[0];
        var y2 = data2[1];

        var points = new List<Point>();
        var stepX = new int[] { -1, 0, 1, 1, 1, 0, -1, -1 };
        var stepY = new int[] { 1, 1, 1, 0, -1, -1, -1, 0 };
        var min = int.MaxValue;
        for(var i = 0; i < stepX.Length; i++)
        {
            var distance = Math.Abs(x1 - (x2 + stepX[i])) + Math.Abs(y1 - (y2 + stepY[i]));
            min = Math.Min(min, distance);
        }

        writer.WriteLine(2*min + 8);
        writer.Flush();
    }

    public static void Main(string[] args)
    {
        if (!testing)
        { // set testing to false when submiting to codeforces
            program(Console.In); // write your program in 'program' function (its your new main !)
            return;
        }

        Console.WriteLine("Test Case(1) => expected :");
        Console.WriteLine("18\n");
        Console.WriteLine("Test Case(1) => found    :");
        program(new StringReader("1 5\n5 2\n"));
        Console.WriteLine();
        Console.ReadLine();

        Console.WriteLine("Test Case(2) => expected :");
        Console.WriteLine("8\n");
        Console.WriteLine("Test Case(2) => found    :");
        program(new StringReader("0 1\n0 0\n"));
        Console.WriteLine();
        Console.ReadLine();

    }
}


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

namespace Quadcopter
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string str = Console.ReadLine();
            var list = str.Split(new[] { ' ' }).Select(Int64.Parse).ToList();
            long x1 = list[0];
            long y1 = list[1];

            str = Console.ReadLine();
            list = str.Split(new[] { ' ' }).Select(Int64.Parse).ToList();
            long x2 = list[0];
            long y2 = list[1];

            //long x1=1, y1=5, x2=5, y2=2;

            long width=0, height=0;
            if(x1==x2) width++;
            if(x1<x2)
                while(x1<=x2){
                    x1++;
                    width++;
                }
            else
                while(x1>=x2){
                    x1--;
                    width++;
                }
           if(y1==y2) height++;
           if(y1<y2)
                while(y1<=y2){
                    y1++;
                    height++;
                }
            else
                while(y1>=y2){
                    y1--;
                    height++;
                }

            Console.WriteLine(width*2 + height*2);
        }
    }
}


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

namespace codeforces
{
    class Program
    {

        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            List<int> a = new List<int>();
            a.Add(input[1] - '0');
            a.Add(input[3] - '0');
            a.Add(input[4] - '0');
            a.Add(input[2] - '0');
            a.Add(input[0] - '0');

            List<int> b = new List<int>();
            b.Add(input[1] - '0');
            b.Add(input[3] - '0');
            b.Add(input[4] - '0');
            b.Add(input[2] - '0');
            b.Add(input[0] - '0');

            List<int> c = new List<int>();
            c.Add(0);
            c.Add(0);
            c.Add(0);
            c.Add(0);
            c.Add(0);

            for (int st = 1; st < 5; ++st)
            {
                for (int i = 0; i < 5; ++i)
                    for (int j = 0, carry = 0; j < 5 && i + j < 5; ++j)
                    {
                        int cur = c[i + j] + a[i] * b[j] + carry;
                        c[i + j] = cur % 10;
                        carry = cur / 10;
                    }

                b = new List<int>();
                for (int i = 0; i < 5; ++i)
                    b.Add(c[i]);
                for (int i = 0; i < 5; ++i)
                    c[i] = 0;
            }
            Console.WriteLine(b[4] + "" + b[3] + "" + b[2] + "" + b[1] + "" + b[0]);
        }
    }
}


using System;

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

        int a5 = n % 10;
        int a4 = (n / 10) % 10;
        int a3 = (n / 100) % 10;
        int a2 = (n / 1000) % 10;
        int a1 = (n / 10000) % 10;

        long m = a1 * 10000 + a3 * 1000 + a5 * 100 + a4 * 10 + a2;

        long k = m;
        for (int i = 2; i <= 5; i++ )
        {
            k = k * m;
            k = k % 100000;
        }

        Console.WriteLine(k.ToString("00000"));
    }
}


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

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

            string[] tokens = Console.ReadLine().Split(' ');

            long   x=0, y=0, m = 0;
            x =long.Parse(tokens[0]);
            y = long.Parse(tokens[1]);
            m = long.Parse(tokens[2]);

            long p=mperfect(x, y, m);

            Console.WriteLine(p);
            Console.ReadLine();

        }

        protected static long mperfect(long x, long y, long m)
        {
            long i = 0;

            if (x >= m || y >= m)
                return 0;
             if (x <= 0 && y <= 0 )
                return -1;

             if (x > y)
             {
                 x ^= y;
                 y ^= x;
                 x ^= y;

            //     x ^= (y ^= (x ^= y));
             }

                if (x < 0 && y > 0)
                {
                    i = -x / y;
                    x = x + y * i;
                }
                else if (y < 0 && x > 0)
                {
                    i = -y / x;
                    y = y + x * i;
                }

                while (x < m && y < m)
                {
                    if (x < y)
                    {
                        x = x + y;
                        i++;
                        if (x >= m || y >= m)
                            return i;
                    }
                    else
                    {
                        y = x + y;
                        i++;
                        if (x >= m || y >= m)
                            return i;
                    }

                }

                return i;

        }
    }
}


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

namespace Solution {

    class Solution {

        class StdIn {
            int currPos = 0;
            string[] tokens = new string[0];

            private string getNextToken() {
                if (currPos < tokens.Length) return tokens[currPos++];
                currPos = 0;
                tokens = Console.ReadLine().Split(new char[] { ' ', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                return tokens[currPos++];
            }

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

            public string nextString() {
                return getNextToken();
            }

            public double nextDouble() {
                return double.Parse(getNextToken());
            }

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

        public static void swap<T>(ref T a, ref T b) {
            T c = a;
            a = b;
            b = c;
        }

        public static void Main(string[] args) {
            StdIn std = new StdIn();

            long x = std.nextLong();
            long y = std.nextLong();
            long m = std.nextLong();

            if (x >= m || y >= m) {
                Console.WriteLine(0);
                return;
            }
            if (x <= 0 && y <= 0) {
                Console.WriteLine(-1);
                return;
            }

            long ans = 0;
            if (x < 0) {
                ans += (-x) / y;
                x += ans * y;
            }
            if (y < 0) {
                ans += (-y) / x;
                y += ans * x;
            }

            while (x < m && y < m) {
                ++ans;
                if (x < y) x += y;
                else y += x;
            }

            Console.WriteLine(ans);

            //Console.ReadLine();
        }
    }
}


using System;
using System.Linq;

namespace Test
{
    class Program
    {
        static long Gcd(long i, long j)
        {
            while (i != 0 && j != 0)
                if (i > j)
                    i %= j;
                else
                    j %= i;
            return Math.Max(i, j);
        }

        static void Main(string[] args)
        {
            long[] a = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            long k = Gcd(a[2], a[3]);
            Console.WriteLine(Math.Min(a[0] / (a[2] / k), a[1] / (a[3] / k)));
        }
    }
}


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

namespace Competitive_Programming.CodeForces
{
    class tvset
    {
        static void Main()
        {
            string[] data = Console.ReadLine().Split();

            long a = long.Parse(data[0]), b = long.Parse(data[1]);
            long x = long.Parse(data[2]), y = long.Parse(data[3]);

            long gc = gcd(x, y);

            x /= gc;
            y /= gc;

            Console.WriteLine(Math.Min(a/x, b/y));
        }

        static long gcd(long a, long b)
        {
            while (b != 0)
            {
                long temp = a % b;
                a = b;
                b = temp;
            }

            return a;
        }
    }
}