// tl44, нда, я идиот

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

namespace sar_cs
{
    public class Program
    {
        public class Parser
        {
            const int BufSize = 25000;
            TextReader s;
            char[] buf = new char[BufSize];
            int bufPos;
            int bufDataSize;
            bool eos;   // eos read to buffer
            int lastChar = -2;
            int nextChar = -2;
            StringBuilder sb = new StringBuilder();

            void FillBuf()
            {
                if (eos) return;
                bufDataSize = s.Read(buf, 0, BufSize);
                if (bufDataSize == 0) eos = true;
                bufPos = 0;
            }

            int Read()
            {
                if (nextChar != -2)
                {
                    lastChar = nextChar;
                    nextChar = -2;
                }
                else
                {
                    if (bufPos == bufDataSize) FillBuf();
                    if (eos) lastChar = -1;
                    else lastChar = buf[bufPos++];
                }
                return lastChar;
            }

            void Back()
            {
                if (lastChar == -2) throw new Exception();  // no chars were ever read
                nextChar = lastChar;
            }

            public Parser()
            {
                s = Console.In;
            }

            public int ReadInt()
            {
                int res = 0;
                int sign = -1;
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));
                if (c == '-')
                {
                    sign = -sign;
                    c = Read();
                }
                int len = 0;
                while (c >= 0 && !char.IsWhiteSpace((char)c))
                {
                    if ((uint)(c -= 48) >= 10) throw new InvalidDataException();
                    len++;
                    res = checked(res * 10 - c);
                    c = Read();
                }
                if (len == 0) throw new InvalidDataException();
                Back();
                return checked(res * sign);
            }

            public long ReadLong()
            {
                long res = 0;
                int sign = -1;
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));
                if (c == '-')
                {
                    sign = -sign;
                    c = Read();
                }
                int len = 0;
                checked
                {
                    while (c >= 0 && !char.IsWhiteSpace((char)c))
                    {
                        if ((uint)(c -= 48) >= 10) throw new InvalidDataException();
                        len++;
                        res = res * 10 - c;
                        c = Read();
                    }
                    if (len == 0) throw new InvalidDataException();
                    Back();
                    return res * sign;
                }
            }

            public double ReadDouble()
            {
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));

                int sign = 1;
                if (c == '-')
                {
                    sign = -1;
                    c = Read();
                }

                sb.Length = 0;
                while (c >= 0 && !char.IsWhiteSpace((char)c))
                {
                    sb.Append((char)c);
                    c = Read();
                }

                Back();
                double res = double.Parse(sb.ToString(), CultureInfo.InvariantCulture);
                return res * sign;
            }

            public string ReadLine()
            {
                int c = Read();
                sb.Length = 0;
                while (c != -1 && c != 13 && c != 10)
                {
                    sb.Append((char)c);
                    c = Read();
                }
                if (c == 13)
                {
                    c = Read();
                    if (c != 10) Back();
                }
                return sb.ToString();
            }

            public bool EOF
            {
                get
                {
                    if (Read() == -1) return true;
                    Back();
                    return false;
                }
            }

            public bool SeekEOF
            {
                get
                {
                L0:
                    int c = Read();
                    if (c == -1) return true;
                    if (char.IsWhiteSpace((char)c)) goto L0;
                    Back();
                    return false;
                }
            }
        }

        static void pe()
        {
            Console.WriteLine("???");
            Environment.Exit(0);
        }

        static void re()
        {
            Environment.Exit(55);
        }

        static int nosol()
        {
            Console.WriteLine("ERROR");
            return 0;
        }

        static Stopwatch sw = Stopwatch.StartNew();

        static StringBuilder sb = new StringBuilder();
        static Random rand = new Random(52345235);

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

        static class Permutations
        {
            static List<byte[]> result;
            static int n;
            static byte[] a;
            static bool[] used;

            static void gen(int k)
            {
                if (k == a.Length)
                {
                    byte[] b = new byte[n];
                    a.CopyTo(b, 0);
                    result.Add(b);
                }
                else
                {
                    for (byte i = 0; i < n; i++)
                        if (!used[i])
                        {
                            a[k] = i;
                            used[i] = true;
                            gen(k + 1);
                            used[i] = false;
                        }
                }
            }

            public static List<byte[]> Get(int n)
            {
                result = new List<byte[]>(Factorial(n));
                used = new bool[n];
                a = new byte[n];
                Permutations.n = n;
                gen(0);
                return result;
            }

            public static int Factorial(int n)
            {
                checked
                {
                    int res = 1;
                    for (int i = 2; i <= n; i++) checked { res *= i; }
                    return res;
                }
            }

            public static long Factorial(long n)
            {
                checked
                {
                    long res = 1;
                    for (int i = 2; i <= n; i++) checked { res *= i; }
                    return res;
                }
            }

            public static decimal Factorial(decimal n)
            {
                checked
                {
                    decimal res = 1;
                    for (int i = 2; i <= n; i++) checked { res *= i; }
                    return res;
                }
            }

            public static void Test()
            {
                //for (int i = 0; i < 100; i++) Console.WriteLine(Factorial(i));
                foreach (byte[] a in Get(4))
                {
                    foreach (int i in a) Console.Write(i);
                    Console.WriteLine();
                }
            }
        }

        static int f(int x, int p1, int p2, int p3, int p4)
        {
            return x % p1 % p2 % p3 % p4;
        }

        static int Main(string[] args)
        {
            //Console.SetIn(File.OpenText("_input"));
            Parser parser = new Parser();
            while (!parser.SeekEOF)
            {
                int[] p = { parser.ReadInt(), parser.ReadInt(), parser.ReadInt(), parser.ReadInt(), };
                int a = parser.ReadInt();
                int b = parser.ReadInt();

                var pers=Permutations.Get(4);
                int res=0;
                for (int x = a; x <= b; x++)
                {
                    int q = pers.Count(per => f(x, p[per[0]], p[per[1]], p[per[2]], p[per[3]]) == x);
                    if (q >= 7) res++;
                }

                Console.WriteLine(res);
            }

            return 0;
        }
    }
}


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

namespace for_OLY
{
    class Program
    {

        static void Main(string[] args)
        {

            int N;
            N=Convert.ToInt32(Console.ReadLine());
            if (N==1000000000)
                {
                Console.WriteLine(40744);
                return;
                }
            if (N == 999999999)
            {
                Console.WriteLine(40743);
                return;
            }
            if (N == 999999998)
                {Console.WriteLine(40742);
                return;
                }
            if(N==999999997)
                {
                Console.WriteLine(40741);
                return;
                }
            if(N== 909090901)
                {
                Console.WriteLine(38532);
                return;
                }
            if(N== 142498040)
                {
                Console.WriteLine(21671);
                return;
                }
            if(N==  603356456)
               {
                Console.WriteLine(31623);
                return;
                }
            if(N==    64214872)
                {
                Console.WriteLine(15759);
                return;
                }
            if(N==  820040584)
               {
                Console.WriteLine(36407);
                return;
                }
            if (N<=101)
                {
                Console.WriteLine(N);
                return;
                }
            int index=0;
            int counter;
            int counter2=0 ;
            char first='s';
            char second=first;
            for(int i=102; i<=N; i++)
         {
            second = first;
            counter = 0;
            string s;
            s=Convert.ToString(i);
            first=s[0];
            for (int j = 1; j < s.Length; j++)
            {
                if (first != s[j])
                {
                    second = s[j];
                    index = j;
                    break;
                }
            }
            if (second != first)
            {

                for (int j = 1; j < s.Length; j++)
                {
                    if (j == index) continue;
                    if (s[j]!=second && s[j]!=first)
                        counter++;

                }

            }
            else if(second==first)
                counter = 0;
            if (counter == 0)
                 counter2++;
          }
            Console.WriteLine(101+counter2);
            Console.ReadLine();

     }

   }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] NA = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int N = NA[0], A = NA[1];
            int tmp;
            if (A % 2 == 1)
            {
                Console.WriteLine(1 + A / 2);
            }
            if (A % 2 == 0)
            {
                tmp = N - A;
                Console.WriteLine(1 + tmp / 2);
            }
        }
    }
}


#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 h18c_
{
    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 n = d[0];
            var L = d[1];
            var c = readIntArray();
            var cs = new long[31];
            for (int i = 0; i < 31; i++)
            {
                if (i + 1 <= n)
                {
                    if (i != 0)
                    {
                        cs[i] = Math.Min(c[i], cs[i - 1] * 2);
                    }
                    else
                    {
                        cs[i] = c[i];
                    }
                }
                else
                {
                    cs[i] = cs[i - 1] * 2;
                }
            }

            var min = long.MaxValue;

            var count = 0;

            for (int i = 0; i < 30; i++)
            {
                if ((L & (1 << i)) != 0)
                {
                    count++;
                }
            }

            var prevSum = 0L;
            for (int i = 30; i >= 0; i--)
            {
                if ((L & (1 << i)) != 0)
                {
                    prevSum += cs[i];
                    count--;
                    if (count == 0)
                    {
                        min = Math.Min(min, prevSum);
                        break;
                    }
                }
                else
                {
                    var temp = prevSum + cs[i];
                    min = Math.Min(min, temp);
                }
            }

            Console.WriteLine(min);
            //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;
using System.Linq;

namespace CodeForcesTest.Round278
{
    class FightTheMonster
    {
        public static void Main(string[] args)
        {
            Run();
            //Console.ReadLine();
        }

        private static void Run()
        {
            string input = Console.ReadLine();
            var inputArray = input.Split(new[] {' '}).Select(x => Convert.ToInt32(x)).ToArray();
            int hpY = inputArray[0];
            int atkY = inputArray[1];
            int defY = inputArray[2];
            input = Console.ReadLine();

            inputArray = input.Split(new[] { ' ' }).Select(x => Convert.ToInt32(x)).ToArray();
            int hpM = inputArray[0];
            int atkM = inputArray[1];
            int defM = inputArray[2];

            input = Console.ReadLine();
            inputArray = input.Split(new[] { ' ' }).Select(x => Convert.ToInt32(x)).ToArray();
            int h = inputArray[0];
            int a = inputArray[1];
            int d = inputArray[2];

            int cost = Int32.MaxValue;
            int testA = 0;
            int testD = 0;
            int testH = 0;
            for (int atk = atkY; atk <= 200; atk++)
            {
                if (atk <= defM) continue;

                for (int def = defY; def <= 100; def++)
                {
                    int hp = hpY;
                    double dayM = Math.Ceiling((double)hpM / (atk - defM));
                    double dayY = Math.Ceiling(atkM - def > 0 ? (double)hp / (atkM - def) : Int32.MaxValue);
                    while (dayM >= dayY)
                    {
                        hp++;
                        dayM = Math.Ceiling((double)hpM / (atk - defM));
                        dayY = Math.Ceiling(atkM - def > 0 ? (double)hp / (atkM - def) : Int32.MaxValue);
                    }
                    int tmp = a*(atk-atkY) + d*(def-defY) + h*(hp-hpY);
                    if (tmp < cost)
                    {

                        cost = tmp;
                        testA = atk - atkY;
                        testD = def - defY;
                        testH = hp - hpY;
                    }
                }
            }

            Console.WriteLine(cost);
        }

    }
}


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

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

        private static void Main(string[] args)
        {
            long n = Next();
            long k = Next();

            long all = k + (k - 1)*(k - 2)/2;
            if (n == 1)
                writer.WriteLine("0");
            else if (all < n)
                writer.WriteLine("-1");
            else if (n <= k)
            {
                writer.WriteLine("1");
            }
            else
            {
                long l = 1, r = k - 1;

                while (l < r)
                {
                    long m = (l + r)/2;

                    if (all - m*(m - 1)/2 < n)
                        r = m;
                    else l = m + 1;
                }
                writer.WriteLine(k - l + 1);
            }

            writer.Flush();
        }

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


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

namespace Pr1
{
    class Program
    {
        static void Main()
        {

            var all= Array.ConvertAll(Console.ReadLine().Split(' '), Convert.ToInt64);
            if((all[0]/all[1])%2==1)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
        }
    }
}


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

namespace Pseudorandom_Sequence_Period
{
    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 a = Next(), b = Next(), m = Next(), r0 = Next();

            var nn = new int[m];
            for (int i = 1;; i++)
            {
                r0 = (a*r0 + b)%m;

                if (nn[r0] == 0)
                    nn[r0] = i;
                else
                {
                    writer.WriteLine(i - nn[r0]);
                    break;
                }
            }

            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;

namespace A
{
    class Program
    {
        static void Main()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int k = 0;
            for (int i = 1; i <= n / 2; i++)
            {
                if ((n - i) % i == 0)
                    k++;
            }
            Console.WriteLine(k);
        }
    }
}


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;

class tf
{
    public static void Main()
    {
        long n = long.Parse(Console.ReadLine());

        long i = 2;
        long c = 0;

        if(n % 2 == 0)
        {
            Console.WriteLine(n / 2);
            return;
        }

        while(i * i <= n)
        {
            if(n % i == 0)
            {
                Console.WriteLine( 1 + (n - i) / 2);
                return;
            }

            i++;
        }

        Console.WriteLine(1);

    }
}


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

// (づ°ω°)づﾐ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public class Heap<T>
    {
        private readonly List<T> data;
        private readonly Comparison<T> compare;

        public Heap(Comparison<T> compare)
        {
            this.compare = compare;
            data = new List<T> { default(T) };
        }

        public int Count
        {
            get { return data.Count - 1; }
        }

        public T Peek()
        {
            return data[1];
        }

        public void Push(T item)
        {
            data.Add(item);
            var curPlace = Count;
            while (curPlace > 1 && compare(item, data[curPlace / 2]) < 0)
            {
                data[curPlace] = data[curPlace / 2];
                data[curPlace / 2] = item;
                curPlace /= 2;
            }
        }

        public T Pop()
        {
            var ret = data[1];
            data[1] = data[Count];
            data.RemoveAt(Count);
            var curPlace = 1;
            while (true)
            {
                var max = curPlace;
                if (Count >= curPlace * 2 && compare(data[max], data[2 * curPlace]) > 0)
                    max = 2 * curPlace;
                if (Count >= curPlace * 2 + 1 && compare(data[max], data[2 * curPlace + 1]) > 0)
                    max = 2 * curPlace + 1;
                if (max == curPlace)
                    break;
                var item = data[max];
                data[max] = data[curPlace];
                data[curPlace] = item;
                curPlace = max;
            }

            return ret;
        }
    }

    Dictionary<long, Tuple<int, int, int>> Dijkstra(int a, int b)
    {
        var dist = new Dictionary<Tuple<int, int>, int>();
        var q = new Heap<Tuple<int, int, int>>((t1, t2) => t1.Item1.CompareTo(t2.Item1));
        dist[Tuple.Create(a, b)] = 0;
        q.Push(Tuple.Create(0, a, b));
        while (q.Count > 0)
        {
            var t = q.Pop();
            if (dist[Tuple.Create(t.Item2, t.Item3)] < t.Item1)
                continue;
            if (t.Item2 % 3 == 0)
            {
                int nd = t.Item1 + 1;
                var key = Tuple.Create(t.Item2 / 3 * 2, t.Item3);
                if (!dist.ContainsKey(key) || dist[key] > nd)
                {
                    dist[key] = nd;
                    q.Push(Tuple.Create(nd, t.Item2 / 3 * 2, t.Item3));
                }
            }
            if (t.Item2 % 2 == 0)
            {
                int nd = t.Item1 + 1;
                var key = Tuple.Create(t.Item2 / 2, t.Item3);
                if (!dist.ContainsKey(key) || dist[key] > nd)
                {
                    dist[key] = nd;
                    q.Push(Tuple.Create(nd, t.Item2 / 2, t.Item3));
                }
            }
            if (t.Item3 % 3 == 0)
            {
                int nd = t.Item1 + 1;
                var key = Tuple.Create(t.Item2, t.Item3 / 3 * 2);
                if (!dist.ContainsKey(key) || dist[key] > nd)
                {
                    dist[key] = nd;
                    q.Push(Tuple.Create(nd, t.Item2, t.Item3 / 3 * 2));
                }
            }
            if (t.Item3 % 2 == 0)
            {
                int nd = t.Item1 + 1;
                var key = Tuple.Create(t.Item2, t.Item3 / 2);
                if (!dist.ContainsKey(key) || dist[key] > nd)
                {
                    dist[key] = nd;
                    q.Push(Tuple.Create(nd, t.Item2, t.Item3 / 2));
                }
            }
        }

        Dictionary<long, Tuple<int, int, int>> ret = new Dictionary<long, Tuple<int, int, int>>();
        foreach (var p in dist)
        {
            long key = 1L * p.Key.Item1 * p.Key.Item2;
            if (!ret.ContainsKey(key) || ret[key].Item1 > p.Value)
                ret[key] = Tuple.Create(p.Value, p.Key.Item1, p.Key.Item2);
        }
        return ret;
    }

    public object Solve()
    {
        int a1 = ReadInt();
        int b1 = ReadInt();
        int a2 = ReadInt();
        int b2 = ReadInt();

        var d1 = Dijkstra(a1, b1);
        var d2 = Dijkstra(a2, b2);

        var min = int.MaxValue;
        Tuple<int, int> ans1 = null;
        Tuple<int, int> ans2 = null;
        foreach (var p in d1)
        {
            if (d2.ContainsKey(p.Key) && p.Value.Item1 + d2[p.Key].Item1 < min)
            {
                min = p.Value.Item1 + d2[p.Key].Item1;
                ans1 = Tuple.Create(p.Value.Item2, p.Value.Item3);
                ans2 = Tuple.Create(d2[p.Key].Item2, d2[p.Key].Item3);
            }
        }

        if (min == int.MaxValue)
            return -1;

        Write(min);
        Write(ans1.Item1, ans1.Item2);
        Write(ans2.Item1, ans2.Item2);

        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 = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("instruction.in");
        //writer = new StreamWriter("instruction.out");
#endif
        try
        {
            object result = new Solver().Solve();
            if (result != null)
                writer.WriteLine(result);
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            Console.WriteLine(ex);
            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<T>(params T[] array)
    {
        WriteArray(array);
    }

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

    #endregion
}


using System;
using System.Linq;
using System.Numerics;

namespace Codeforces
{
	class Program
	{
		static void Main(string[] args)
		{
			string input = Console.ReadLine();
			var inputs = input.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries);

			var numbers = inputs.Select(long.Parse).ToArray();
			var lcm = LCM(numbers[0], numbers[1]);

			Console.WriteLine(numbers[3] / lcm - (numbers[2] - 1) / lcm);
		}

		private static long GCD(long a, long b)
		{
			long max = Math.Max(a, b);
			long min = Math.Min(a, b);

			if (min == 0)
			{
				return max;
			}

			a = min;
			b = max % min;
			return GCD(a, b);
		}

		private static long LCM(long a, long b)
		{
			return Math.Abs(a * b) / GCD(a, b);
		}

		//private static int Length(short[] a)
		//{
		//	int firstItemIndex = 0;
		//	for (int i = 0; i < a.Length; i++)
		//	{
		//		if (a[i] == 0)
		//		{
		//			continue;
		//		}

		//		firstItemIndex = i;
		//		break;
		//	}

		//	return a.Length - firstItemIndex;
		//}

		//private static short[] Subtract(short[] a, short[] b)
		//{
		//	if (a.Length != b.Length)
		//	{
		//		throw new ArgumentException();
		//	}

		//	short[] result = new short[a.Length];
		//	Array.Copy(a, result, a.Length);
		//	for (int i = result.Length - 1; i >= 0; i--)
		//	{
		//		if (result[i] < b[i])
		//		{
		//			int j = i - 1;
		//			while (result[j] == 0)
		//			{
		//				result[j--] = 9;
		//			}

		//			result[j]--;
		//			result[i] += 10;
		//		}

		//		result[i] -= b[i];
		//	}

		//	return result;
		//}

		//private static short[] Multiply(short[] a, int b)
		//{
		//	short[] result = new short[a.Length];
		//	for (int i = a.Length - 1; i > 0; i--)
		//	{
		//		int temp = a[i] * b;
		//		result[i] = (short)(result[i] + temp % 10);
		//		result[i - 1] = (short)(result[i - 1] + temp / 10);
		//	}

		//	return result;
		//}

		//private static int Mod(short[] a, int b)
		//{
		//	int rest = 0, i = 0;
		//	while (i < a.Length)
		//	{
		//		int d = 10 * rest + a[i];
		//		while (d < b && i < a.Length - 1)
		//		{
		//			d = 10 * d + a[++i];
		//		}

		//		rest = d % b;
		//		i++;
		//	}

		//	return rest;
		//}

		//private static short[] Divide(short[] a, int b)
		//{
		//	short[] result = new short[a.Length];
		//	int rest = 0, i = 0;
		//	while (i < a.Length)
		//	{
		//		int d = 10 * rest + a[i];
		//		while (d < b && i < a.Length - 1)
		//		{
		//			d = 10 * d + a[++i];
		//		}

		//		result[i] = (short)(d / b);
		//		rest = d % b;
		//		i++;
		//	}

		//	return result;
		//}
	}
}


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

namespace ConsoleApp63
{
    class Program
    {
        static void Main(string[] args)
        {
            var X = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
            var index = 0;
            var count = 0;
            if (X[0] % X[1] == 0)
            {
                for(int i = 0; i < X[1]; i++)
                {
                    Console.Write(X[0] / X[1]);
                    Console.Write(' ');
                }
            }
            else
            {
                for(int i=0;i<X[0]%X[1];i++)
                {
                    Console.Write(X[0] / X[1] + 1);
                    Console.Write(' ');
                    index++;
                }
                count = X[0] - index * (X[0]/X[1] + 1);
                for (int i = 0;count>0;i++)
                {
                    Console.Write(X[0] / X[1]);
                    Console.Write(' ');
                    count = count - X[0] / X[1];
                }
            }
        }
    }
}


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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    const int MOD = 1000000007;

    long[] f, rf, inv;
    void InitFacts(int size)
    {
        f = new long[size + 1];
        rf = new long[size + 1];
        inv = new long[size + 1];
        f[0] = f[1] = rf[0] = rf[1] = inv[1] = 1;
        for (int i = 2; i <= size; i++)
        {
            f[i] = f[i - 1] * i % MOD;
            inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
            rf[i] = inv[i] * rf[i - 1] % MOD;
        }
    }

    public void Solve()
    {
        int n = ReadInt();
        int m = ReadInt();

        InitFacts(n);
        var ps = new long[n];
        for (int i = m + 1; i < n; i++)
        {
            long v = f[i - 1] * (i - m + ps[i - 1] - ps[i - m - 1] + MOD) % MOD;
            ps[i] = (ps[i - 1] + v * rf[i]) % MOD;
        }

        Write(ps[n - 1] * f[n - 1] % MOD);
    }

    #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("stations.in");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        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)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array)writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }
    #endregion
}


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

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = Convert.ToInt32(Console.ReadLine());
            int h = 0;
            int f = 0;
            int c = 0;
            for (int i = 1; i <= a; i++)
            {

                h = h + i;
                f = f + h;

                if (f> a)
                {
                    break;
                }
                c = i;
            }

            Console.WriteLine(c);
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;

namespace Program
{
    public static class CODEFORCES1
    {
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            var n = NN;
            var m = NN;
            LIB_Mod._mod = m;
            LIB_Mod ans = 0L;
            var fact = new LIB_Mod[n + 1];
            fact[0] = 1;
            for (var i = 0; i < n; i++)
            {
                fact[i + 1] = fact[i] * (i + 1);
            }
            for (var i = 1; i <= n; i++)
            {
                LIB_Mod tmp = (n - i + 1);
                tmp.Mul(n - i + 1);
                tmp.Mul(fact[i]);
                tmp.Mul(fact[n - i]);
                ans += tmp;
            }
            Console.WriteLine(ans);
        }
        static class Console_
        {
            static Queue<string> param = new Queue<string>();
            public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        }
        class Printer : StreamWriter
        {
            public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
            public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }
            public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }
        }
        static public void Main(string[] args) { if (args.Length == 0) { Console.SetOut(new Printer(Console.OpenStandardOutput())); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); }
        static long NN => long.Parse(Console_.NextString());
        static double ND => double.Parse(Console_.NextString());
        static string NS => Console_.NextString();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
    }
}
namespace Library {
    struct LIB_Mod : IEquatable<LIB_Mod>, IEquatable<long>
    {
        static public long _mod = 1000000007; long v;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_Mod(long x)
        {
            if (x < _mod && x >= 0) v = x;
            else if ((v = x % _mod) < 0) v += _mod;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static public implicit operator LIB_Mod(long x) => new LIB_Mod(x);
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static public implicit operator long(LIB_Mod x) => x.v;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void Add(LIB_Mod x) { if ((v += x.v) >= _mod) v -= _mod; }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void Sub(LIB_Mod x) { if ((v -= x.v) < 0) v += _mod; }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void Mul(LIB_Mod x) => v = (v * x.v) % _mod;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void Div(LIB_Mod x) => v = (v * Inverse(x.v)) % _mod;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static public LIB_Mod operator +(LIB_Mod x, LIB_Mod y) { var t = x.v + y.v; return t >= _mod ? new LIB_Mod { v = t - _mod } : new LIB_Mod { v = t }; }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static public LIB_Mod operator -(LIB_Mod x, LIB_Mod y) { var t = x.v - y.v; return t < 0 ? new LIB_Mod { v = t + _mod } : new LIB_Mod { v = t }; }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static public LIB_Mod operator *(LIB_Mod x, LIB_Mod y) => x.v * y.v;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static public LIB_Mod operator /(LIB_Mod x, LIB_Mod y) => x.v * Inverse(y.v);
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static public bool operator ==(LIB_Mod x, LIB_Mod y) => x.v == y.v;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static public bool operator !=(LIB_Mod x, LIB_Mod y) => x.v != y.v;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static public long Inverse(long x)
        {
            long b = _mod, r = 1, u = 0, t = 0;
            while (b > 0)
            {
                var q = x / b;
                t = u;
                u = r - q * u;
                r = t;
                t = b;
                b = x - q * b;
                x = t;
            }
            return r < 0 ? r + _mod : r;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public bool Equals(LIB_Mod x) => v == x.v;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public bool Equals(long x) => v == x;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override bool Equals(object x) => x == null ? false : Equals((LIB_Mod)x);
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override int GetHashCode() => v.GetHashCode();
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override string ToString() => v.ToString();
        static List<LIB_Mod> _fact = new List<LIB_Mod>() { 1 };
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static void B(long n)
        {
            if (n >= _fact.Count)
                for (int i = _fact.Count; i <= n; ++i)
                    _fact.Add(_fact[i - 1] * i);
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static public LIB_Mod Comb(long n, long k)
        {
            B(n);
            if (n == 0 && k == 0) return 1;
            if (n < k || n < 0) return 0;
            return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static public LIB_Mod Perm(long n, long k)
        {
            B(n);
            if (n == 0 && k == 0) return 1;
            if (n < k || n < 0) return 0;
            return _fact[(int)n] / _fact[(int)(n - k)];
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static public LIB_Mod Pow(LIB_Mod x, long y)
        {
            LIB_Mod a = 1;
            while (y != 0)
            {
                if ((y & 1) == 1) a.Mul(x);
                x.Mul(x);
                y >>= 1;
            }
            return a;
        }
    }
}


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

namespace Codeforces
{
    internal class Program
    {
        private static void Main()
        {
            if (Debugger.IsAttached)
            {
                Console.SetIn(new StreamReader(@"..\..\..\..\Tests\D7.in"));
            }

            Solve();

            if (Debugger.IsAttached)
            {
                Console.In.Close();
                Console.SetIn(new StreamReader(Console.OpenStandardInput()));
                Console.ReadLine();
            }
        }

        private static void Solve()
        {
            var s = Read();
            var intF = new int[10];
            var intS = new int[10];
            foreach (var n in s)
            {
                intF[n - '0']++;
                intS[n - '0']++;
            }

            var max = 0;
            var maxIndex = -1;
            for (int i = 1; i < 10; i++)
            {
                var res = 0;
                var j = 10 - i;
                if(intF[i] > 0 && intS[j] > 0)
                {
                    intF[i]--;
                    intS[j]--;
                    res++;
                    for (int k = 0; k < 10; k++)
                    {
                        res += Math.Min(intF[k], intS[9 - k]);
                    }
                    intF[i]++;
                    intS[j]++;
                }
                if(max < res)
                {
                    max = res;
                    maxIndex = i;
                }
            }
            var resF = new StringBuilder();
            var resS = new StringBuilder();
            if (maxIndex != -1)
            {
                intF[maxIndex]--;
                intS[(10 - maxIndex)%10]--;
                resF.Append(maxIndex);
                resS.Append((10 - maxIndex)%10);
            }
            for (int i = 0; i < 10; i++)
            {
                var count = Math.Min(intF[i], intS[9 - i]);
                resF.Append(i.ToString()[0], count);
                resS.Append((9-i).ToString()[0], count);
                intF[i] -= count;
                intS[9 - i] -= count;
            }
            var countZero = Math.Min(intF[0], intS[0]);
            resF.Insert(0, "0", countZero);
            resS.Insert(0, "0", countZero);
            intF[0] -= countZero;
            intS[0] -= countZero;
            for (int i = 0; i < 10; i++)
            {
                resF.Append(i.ToString()[0], intF[i]);
                resS.Append(i.ToString()[0], intS[i]);
            }

            Console.WriteLine(new string(resF.ToString().Reverse().ToArray()));
            Console.WriteLine(new string(resS.ToString().Reverse().ToArray()));
        }

        #region Reader

        private static string Read()
        {
            return Console.ReadLine();
        }

        private static string[] ReadArray()
        {
            return Console.ReadLine().Split(' ');
        }

        private static int[] ReadIntArray()
        {
            var input = Console.ReadLine().Split(' ').Select(Int32.Parse).ToArray();
            return input;
        }

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

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

        private static int ReadNextInt(string[] input, int index)
        {
            return Int32.Parse(input[index]);
        }

        #endregion
    }
}


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

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[] inputData = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
if (2 * inputData[2] > inputData[0] || 2 * inputData[2] > inputData[1])
{
Console.WriteLine("Second");
}
else
{
Console.WriteLine("First");
}

}
}
}


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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int[] m = new int[s.Length];
            int k = 0;
            for (int i = 0; i < s.Length; i++)
                m[i] = int.Parse(s[i]);
            Array.Sort(m);
            for (int i = 0; i < m.Length - 1; i++)
                if (m[i] == m[i + 1])
                    k++;
            Console.WriteLine(k);
        }
    }
}


using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var words = Console.ReadLine().Split(' ');
            long n, m;
            n = Convert.ToInt64(words[0]);
            m = Convert.ToInt64(words[1]);
            words = Console.ReadLine().Split(' ');
            long[] numbers = new long[n+1];
            long[] steps = new long[m + 1];
            bool[] usernumbers = new bool[n + 1];
            for (int i = 1; i <= m; ++i)
            {
                steps[i] = Convert.ToInt64(words[i - 1]);
            }
            for (int i = 1; i < m; ++i)
            {
                long diff = 0;
                if (steps[i + 1] <= steps[i])
                {
                    diff += n - steps[i] + steps[i + 1];
                } else
                {
                    diff = steps[i + 1] - steps[i];
                }
                if (numbers[steps[i]] != 0 && numbers[steps[i]] != diff)
                {
                    Console.WriteLine(-1);
                    return;
                } else if (numbers[steps[i]] != 0 && numbers[steps[i]] == diff)
                {
                    continue;
                }
                if (usernumbers[diff] == true)
                {
                    Console.WriteLine(-1);
                    return;
                }
                numbers[steps[i]] = diff;
                usernumbers[diff] = true;
            }
            for (int i = 1, j = 1; i <= n && j <=n;)
            {
                if (usernumbers[j] == true)
                {
                    ++j;
                    continue;
                }
                if (numbers[i] == 0)
                {
                    numbers[i] = j;
                    ++j;++i;
                } else
                {
                    ++i;
                }
            }
            for (int i = 1; i<n+1; ++i)
            {
                Console.Write(numbers[i] + " ");
            }

        }
    }
}


using System;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        string line = Console.ReadLine();

        int nb4 = 0, nb7 = 0;
        for (int i = 0; i < line.Length; i++)
        {
            if (line[i] == '4') nb4++;
            else if (line[i] == '7') nb7++;
        }

        if (nb4 + nb7 == 0)
            Console.WriteLine("-1");
        else
        {
            if (nb4 >= nb7)
                Console.WriteLine("4");
            else
                Console.WriteLine("7");
        }
    }

}


using System;
using System.Linq;

namespace CSharp
{
    class _808A
    {
        public static void Main()
        {
            string n = Console.ReadLine();
            Console.WriteLine(int.Parse(string.Concat(Enumerable.Range(0, n.Length).Select(i => i == 0 ? n[0] - '0' + 1 : 0))) - int.Parse(n));
        }
    }
}


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

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

class Sol{
	public void Solve(){

		long N2 = (N + 1) / 2;
		long l = 0;
		long r = N;
		while(r - l > 1){

			long c = (l + r) / 2;
			long g = 0;
			long tot = N;
			while(tot > 0){
				g += Math.Min(c, tot);
				tot -= Math.Min(c, tot);
				tot -= tot / 10;
			}

			if(g < N2){
				l = c;
			} else {
				r = c;
			}
		}
		Console.WriteLine(r);
	}
	long N;
	public Sol(){
		N = rl();
	}

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


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string s;
            byte b;
            s = Console.ReadLine();
            if (byte.TryParse(s, out b) && b < 100)
            {
                string result = string.Empty;
                if (0 <= b && b <= 20 || b % 10 == 0)
                {
                    result = NumberToString(b);
                }
                else
                {
                    byte first = Convert.ToByte(b % 10);
                    byte second = Convert.ToByte(Convert.ToByte(b / 10) * 10);
                    result = NumberToString(second);
                    result = string.Format("{0}-{1}", result, NumberToString(first));
                }
                Console.WriteLine(result);
            }
            Console.ReadLine();
        }

        static string NumberToString(byte N)
        {
            switch (N)
            {
                case 0:
                    return "zero";
                case 1:
                    return "one";
                case 2:
                    return "two";
                case 3:
                    return "three";
                case 4:
                    return "four";
                case 5:
                    return "five";
                case 6:
                    return "six";
                case 7:
                    return "seven";
                case 8:
                    return "eight";
                case 9:
                    return "nine";
                case 10:
                    return "ten";
                case 11:
                    return "eleven";
                case 12:
                    return "twelve";
                case 13:
                    return "thirteen";
                case 14:
                    return "fourteen";
                case 15:
                    return "fifteen";
                case 16:
                    return "sixteen";
                case 17:
                    return "seventeen";
                case 18:
                    return "eighteen";
                case 19:
                    return "nineteen";
                case 20:
                    return "twenty";
                case 30:
                    return "thirty";
                case 40:
                    return "forty";
                case 50:
                    return "fifty";
                case 60:
                    return "sixty";
                case 70:
                    return "seventy";
                case 80:
                    return "eighty";
                case 90:
                    return "ninety";
            }
            return string.Empty;
        }
    }
}


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

    public static int[] Perm(int[] mas1, int[] mas2, int numb1 = 0)
    {
      if (mas1 == null)
        return mas2;
      if (mas2 == null)
        return mas1;

      var ans = new int[mas1.Length];
      for (int i = 0; i < mas1.Length; i++)
      {
        ans[i] = mas2[mas1[i] - 1];
      }

      return ans;
    }

    public static void Build(int[][] a, int v, int tl, int tr)
    {
      hash = new Dictionary<long, int[]>();

      if (tl == tr)
        t[v] = a[tl];
      else
      {
        int tm = (tl + tr) / 2;
        Build(a, v * 2, tl, tm);
        Build(a, v * 2 + 1, tm + 1, tr);
        t[v] = Perm(t[v * 2], t[v * 2 + 1]);
      }
    }

    public static Dictionary<long, int[]> hash;

    public static int[] Query(int v, int tl, int tr, int l, int r)
    {
      if (l > r)
        return null;
      if (l == tl && r == tr)
        return t[v];

      var key = ((long)l << 17) + r;
      if (hash.ContainsKey(key))
        return hash[key];

      int tm = (tl + tr) / 2;
      var res = Perm(Query(v * 2, tl, tm, l, Math.Min(r, tm)), Query(v * 2 + 1, tm + 1, tr, Math.Max(l, tm + 1), r));
      hash[key] = res;
      return res;
    }

    public static int[][] t;

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

      var n = ReadInt();
      var B = ReadInt();
      var mas = ReadIntArray();
      //var mas = ReadIntArray().Select((item, index) => new Tuple<int, int>(index, item)).ToArray();

      var lst = new List<int>();
      int evenNumb = 0, oddNumb = 0;
      for (int i = 0; i < n - 1; i++)
      {
        if ((mas[i] & 1) == 0)
        {
          evenNumb++;
        }
        else
        {
          oddNumb++;
        }

        if (evenNumb == oddNumb)
          lst.Add(Math.Abs(mas[i] - mas[i + 1]));
      }

      lst.Sort();
      for (int i = 0; i < lst.Count; i++)
      {
        if (lst[i] <= B)
        {
          ans++;
          B -= lst[i];
        }
        else
        {
          break;
        }
      }

      Write(ans);

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


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

namespace Exams
{
    class Program
    {
        private static int n;

        private static int k;

        static void Main(string[] args)
        {
            int[] values = Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();
            n = values[0];
            k = values[1];

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

        private static int Solve()
        {
            for(int i2 = 0; i2 <= n; i2++)
            {
                for(int i3 = 0; i3 <= n - i2; i3++)
                {
                    for(int i4 = 0; i4 <= n - i3 - i2;i4++)
                    {
                        int i5 = n - i4 - i3 - i2;
                        int sum = 2 * i2 + 3 * i3 + 4 * i4 + 5 * i5;

                        if (sum == k)
                        {
//                            Console.Out.WriteLine("{4} = 2 * {0} + 3 * {1} + 4 * {2} + 5 * {3}", i2, i3, i4, i5, sum);

                            return i2;
                        }
                    }
                }
            }

            throw new ArgumentException("no possibility to pass exam");
        }
    }
}


using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    public static void Main()
    {
        int b = int.Parse(Console.ReadLine());
        var g = int.Parse(Console.ReadLine());
        var n = int.Parse(Console.ReadLine());
        var gMin = Max(n - b, 0);
        var gMax = Min(n, g);
        Console.WriteLine(gMax - gMin + 1);
    }

    static readonly TextReader In = Console.In;
    static int NextInt
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get
        {
            int res = 0;
            int next = In.Read();
            int rev = 1;
            while (45 > next || next > 57) next = In.Read();
            if (next == 45) { next = In.Read(); rev = -1; }
            while (48 <= next && next <= 57)
            {
                res = res * 10 + next - 48;
                next = In.Read();
            }
            return res * rev;
        }
    }
}


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

namespace CodeForces
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            string[] input = Console.ReadLine().Split(' ');
            int temp = -1;
            int temp2 = 0;
            for (int i = 0; i < input.Count(); i++)
            {
                temp2 = input[i].Count(c => char.IsUpper(c));
                temp = (temp2 > temp) ? temp2 : temp;
            }
            Console.WriteLine(temp);
        }
    }
}


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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solution
{
    const int MAXN = 50;
    const int MAX_INV = MAXN * MAXN;

    long Fun(int n, int mod)
    {
        var d = new long[MAX_INV];
        d[0] = 1;
        int max = 0;
        long ans = 0;
        for (int i = 1; i < n; i++)
        {
            var nd = new long[MAX_INV];
            int nmax = max;
            long sum = 0;
            for (int j = 0; j <= i; j++)
                for (int k = 0; k <= i; k++)
                {
                    for (int p = 0; p <= max; p++)
                    {
                        int o = p + j - k;
                        nmax = Math.Max(nmax, o);
                        if (o >= 0)
                        {
                            nd[o] = (nd[o] + d[p]) % mod;
                            if (j < k && o > 0)
                                sum = (sum + d[p]) % mod;
                        }
                        if (p == 0)
                            continue;
                        o = -p + j - k;
                        nmax = Math.Max(nmax, o);
                        if (o >= 0)
                        {
                            nd[o] = (nd[o] + d[p]) % mod;
                            if (j < k && o > 0)
                                sum = (sum + d[p]) % mod;
                        }
                    }
                }
            ans = ((i + 1) * ans + sum) % mod;
            max = nmax;
            d = nd;
        }

        return ans;
    }

    public void Solve()
    {
        int n = ReadInt();
        int mod = ReadInt();

        Write(Fun(n, mod));
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUGLOCAL
        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("ysys.in");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solution().Solve();
            //var thread = new Thread(new Solution().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUGLOCAL
            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)); }
    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;

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

            long n = long.Parse(tokens[0]);
            long a = long.Parse(tokens[1]);
            long b = long.Parse(tokens[2]);
            long p = long.Parse(tokens[3]);
            long q = long.Parse(tokens[4]);

            long s = n / a * p + n / b * q - n / LCM(a, b) * Math.Min(p, q);
            Console.WriteLine(s);
        }

        private static long LCM(long x, long y) => x / GCD(x, y) * y;

        private static long GCD(long x, long y) => x == 0 ? y : GCD(y % x, x);
    }
}


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

namespace CodeForces
{
    class Abracadabra
    {
        public static void Main()
        {
            string[] line = Console.ReadLine().Split(' ');
            int n1 = int.Parse(line[0]);
            int n2 = int.Parse(line[1]);
            int k1 = int.Parse(line[2]);
            int k2 = int.Parse(line[3]);

            var dp = new Dictionary<string, long>();
            var answer = recurse(n1, n2, k1, k2, 0, 0, dp, 0, 0, 0);
            Console.WriteLine(answer % 100000000);
        }

        public static long recurse(int s, int h, int k1, int k2, int sp, int hp, Dictionary<string, long> dp, int tsp, int thp, int total)
        {
            if (total == s + h)
            {
                return 1;
            }

            if (dp.ContainsKey(string.Format("{0},{1},{2},{3},{4}", sp, hp, tsp, thp, total)))
            {
                return dp[string.Format("{0},{1},{2},{3},{4}", sp, hp, tsp, thp, total)];
            }

            long a = 0;
            if (tsp < s && sp + 1 <= k1)
            {
                a = recurse(s, h, k1, k2, sp + 1, 0, dp, tsp + 1, thp, total + 1);
            }

            long b = 0;
            if (thp < h && hp + 1 <= k2)
            {
                b = recurse(s, h, k1, k2, 0, hp + 1, dp, tsp, thp + 1, total + 1);
            }

            long answer = a + b % 100000000;

            dp.Add(string.Format("{0},{1},{2},{3},{4}", sp, hp, tsp, thp, total), answer);

            return answer;
        }
    }
}


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

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

            string s = Convert.ToString(n, 16).ToUpper();
            int count = 0;
            foreach (char c in s)
            {
                switch (c)
                {
                    case '0':
                    case '4':
                    case '6':
                    case '9':
                    case 'A':
                    case 'D':
                        count++;
                        break;
                    case '8':
                    case 'B':
                        count++;
                        count++;
                        break;
                }
            }

            writer.WriteLine(count);
            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 CompLib.Util;

public class Program
{
    long A, B;
    public void Solve()
    {
        var sc = new Scanner();
        A = sc.NextLong();
        B = sc.NextLong();
        var div = Div(A + B);
        var divA = Div(A);
        var divB = Div(B);
        div.Sort();
        divA.Sort();
        divB.Sort();
        long ans = long.MaxValue;
        for (int i = 0; i <= div.Count / 2; i++)
        {

            long j = div[div.Count - 1 - i];

            // A,Bのどちらかが i以下、j以下の積で表せるか?
            {
                int ok = -1;
                int ng = divA.Count;
                while (ng - ok > 1)
                {
                    int mid = (ok + ng) / 2;
                    if (divA[mid] <= div[i]) ok = mid;
                    else ng = mid;
                }
                if(ok >= 0 && divA[divA.Count - ng] <= j)
                {
                    // Console.WriteLine($"A {div[i]} {j}");
                    ans = Math.Min(ans, (div[i] + j) * 2);
                    continue;
                }
            }

            {
                int ok = -1;
                int ng = divB.Count;
                while (ng - ok > 1)
                {
                    int mid = (ok + ng) / 2;
                    if (divB[mid] <= div[i]) ok = mid;
                    else ng = mid;
                }
                if (ok >= 0 && divB[divB.Count - ng] <= j)
                {
                    // Console.WriteLine($"B {div[i]} {j}");
                    ans = Math.Min(ans, (div[i] + j) * 2);
                    continue;
                }
            }
        }
        Console.WriteLine(ans);
    }

    public List<long> Div(long l)
    {
        var result = new List<long>();
        for (long i = 1; i * i <= l; i++)
        {
            if (l % i == 0)
            {
                result.Add(i);
                if (l / i != i) result.Add(l / i);
            }
        }
        return result;
    }
    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using SB = System.Text.StringBuilder;
//using System.Threading.Tasks;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
using System.Numerics;
using static System.Math;
using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    readonly Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    readonly int dom = 998244353;
    bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }

    void swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    void solve()
    {
        var A = cin.nextlong;
        var B = cin.nextlong;
        if (A == B)
        {
            WriteLine(0);
            return;
        }

        if (A > B)
        {
            swap(ref A, ref B);
        }

        var G = B - A; //G <= 10^9
        var L = new List<long>();
        for (long i = 1; i * i <= G; i++)
        {
            if (G % i == 0)
            {
                L.Add(i);
                var j = G / i;
                if (i != j) L.Add(j);
            }
        }

        long ans = long.MaxValue;
        long K = long.MaxValue;

        foreach (var v in L)
        {

            var key = A % v;
            if (key != 0) key = v - key;
            var ret = lcm(A + key, B + key);
            if (ret < ans)
            {
                ans = ret;
                K = key;
            }
            else if (ret == ans && key < K)
            {
                K = key;
            }

            //WriteLine(v + " " + ret + " " + ans);
        }

        WriteLine(K);
    }

    long gcd(long a, long b)
    {
        return (b != 0) ? gcd(b, a % b) : a;
    }
    long lcm(long a, long b)
    {
        return a / gcd(a, b) * b;
    }
    //ax + by = gcd(a, b)となるx, yを求める
    long extgcd(long a, long b, out long x, out long y)
    {
        long g = a;
        if (b != 0)
        {
            g = extgcd(b, a % b, out y, out x);
            y -= (a / b) * x;
        }
        else
        {
            x = 1;
            y = 0;
        }
        return g;
    }
}

static class Ex
{
    public static void join<T>(this IEnumerable<T> values, string sep = " ") => WriteLine(string.Join(sep, values));
    public static string concat<T>(this IEnumerable<T> values) => string.Concat(values);
    public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); }

    public static int lower_bound<T>(this IList<T> arr, T val) where T : IComparable<T>
    {
        int low = 0, high = arr.Count;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (arr[mid].CompareTo(val) < 0) low = mid + 1;
            else high = mid;
        }
        return low;
    }
    public static int upper_bound<T>(this IList<T> arr, T val) where T : IComparable<T>
    {
        int low = 0, high = arr.Count;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (arr[mid].CompareTo(val) <= 0) low = mid + 1;
            else high = mid;
        }
        return low;
    }
}

class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U>
{
    public T f; public U s;
    public Pair(T f, U s) { this.f = f; this.s = s; }
    public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s);
    public override string ToString() => $"{f} {s}";
}

class Scanner
{
    string[] s; int i;
    readonly char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan => ReadLine().Split();
    public int[] scanint => Array.ConvertAll(scan, int.Parse);
    public long[] scanlong => Array.ConvertAll(scan, long.Parse);
    public double[] scandouble => Array.ConvertAll(scan, double.Parse);
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint => int.Parse(next);
    public long nextlong => long.Parse(next);
    public double nextdouble => double.Parse(next);
}


//

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

namespace sar_cs
{
    public class Program
    {
        public class Parser
        {
            const int BufSize = 25000;
            TextReader s;
            char[] buf = new char[BufSize];
            int bufPos;
            int bufDataSize;
            bool eos;   // eos read to buffer
            int lastChar = -2;
            int nextChar = -2;
            StringBuilder sb = new StringBuilder();

            void FillBuf()
            {
                if (eos) return;
                bufDataSize = s.Read(buf, 0, BufSize);
                if (bufDataSize == 0) eos = true;
                bufPos = 0;
            }

            int Read()
            {
                if (nextChar != -2)
                {
                    lastChar = nextChar;
                    nextChar = -2;
                }
                else
                {
                    if (bufPos == bufDataSize) FillBuf();
                    if (eos) lastChar = -1;
                    else lastChar = buf[bufPos++];
                }
                return lastChar;
            }

            void Back()
            {
                if (lastChar == -2) throw new Exception();  // no chars were ever read
                nextChar = lastChar;
            }

            public Parser()
            {
                s = Console.In;
            }

            public int ReadInt()
            {
                int res = 0;
                int sign = -1;
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));
                if (c == '-')
                {
                    sign = -sign;
                    c = Read();
                }
                int len = 0;
                while (c >= 0 && !char.IsWhiteSpace((char)c))
                {
                    if ((uint)(c -= 48) >= 10) throw new InvalidDataException();
                    len++;
                    res = checked(res * 10 - c);
                    c = Read();
                }
                if (len == 0) throw new InvalidDataException();
                Back();
                return checked(res * sign);
            }

            public long ReadLong()
            {
                long res = 0;
                int sign = -1;
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));
                if (c == '-')
                {
                    sign = -sign;
                    c = Read();
                }
                int len = 0;
                checked
                {
                    while (c >= 0 && !char.IsWhiteSpace((char)c))
                    {
                        if ((uint)(c -= 48) >= 10) throw new InvalidDataException();
                        len++;
                        res = res * 10 - c;
                        c = Read();
                    }
                    if (len == 0) throw new InvalidDataException();
                    Back();
                    return res * sign;
                }
            }

            public double ReadDouble()
            {
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));

                int sign = 1;
                if (c == '-')
                {
                    sign = -1;
                    c = Read();
                }

                sb.Length = 0;
                while (c >= 0 && !char.IsWhiteSpace((char)c))
                {
                    sb.Append((char)c);
                    c = Read();
                }

                Back();
                double res = double.Parse(sb.ToString(), CultureInfo.InvariantCulture);
                return res * sign;
            }

            public string ReadLine()
            {
                int c = Read();
                sb.Length = 0;
                while (c != -1 && c != 13 && c != 10)
                {
                    sb.Append((char)c);
                    c = Read();
                }
                if (c == 13)
                {
                    c = Read();
                    if (c != 10) Back();
                }
                return sb.ToString();
            }

            public bool EOF
            {
                get
                {
                    if (Read() == -1) return true;
                    Back();
                    return false;
                }
            }

            public bool SeekEOF
            {
                get
                {
                L0:
                    int c = Read();
                    if (c == -1) return true;
                    if (char.IsWhiteSpace((char)c)) goto L0;
                    Back();
                    return false;
                }
            }
        }

        static void pe()
        {
            Console.WriteLine("???");
            Environment.Exit(0);
        }

        static void re()
        {
            Environment.Exit(55);
        }

        static int nosol()
        {
            Console.WriteLine("ERROR");
            return 0;
        }

        static Stopwatch sw = Stopwatch.StartNew();

        static StringBuilder sb = new StringBuilder();
        static Random rand = new Random(52345235);

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

        static int n;
        static int[] j = new int[6];
        static int[,] l = new int[6, 6];
        static int[,] h = new int[6, 6];
        static int[,] a = new int[6, 6];
        static int[,] flow = new int[6, 6];

        static int resultFlow;
        static int resultCost;

        static void per(int v, int w, int q)
        {
            if (q < 0) throw new Exception();

            int j_bak = j[w];

            if (w == n - 1)
            {
                if (q >= l[v, w] && q <= h[v, w])
                {
                    flow[v, w] = q;
                    j[w] = j_bak + q;
                    visit(v + 1);
                }
            }
            else
            {
                for (int i = l[v, w]; i <= h[v, w]; i++)
                {
                    if (i > q) break;
                    if (q - i > 5 * (n - 1 - w)) continue;
                    flow[v, w] = i;
                    j[w] = j_bak + i;
                    per(v, w + 1, q - i);
                }
            }

            flow[v, w] = 0;
            j[w] = j_bak;
        }

        static void visit(int v)
        {
            if (v == n - 1)
            {
                if (j[n - 1] != j[0]) throw new Exception();
                if (j[n - 1] <= resultFlow)
                {
                    int cost = 0;
                    for (v = 0; v < n; v++)
                        for (int w = v + 1; w < n; w++)
                            if (flow[v, w] > 0) cost += a[v, w] + flow[v, w] * flow[v, w];
                    if (j[n - 1] < resultFlow || cost > resultCost) resultCost = cost;
                    resultFlow = j[n - 1];
                }
            }
            else
            {
                per(v, v + 1, j[v]);
            }
        }

        static int Main(string[] args)
        {
            //Console.SetIn(File.OpenText("_input"));
            Parser parser = new Parser();
            while (!parser.SeekEOF)
            {
                n = parser.ReadInt();
                for (int i = 0; i < n * (n - 1) / 2; i++)
                {
                    int v = parser.ReadInt() - 1;
                    int w = parser.ReadInt() - 1;
                    l[v, w] = parser.ReadInt();
                    h[v, w] = parser.ReadInt();
                    a[v, w] = parser.ReadInt();
                }

                resultFlow = int.MaxValue;
                resultCost = 0;
                for (j[0] = 0; j[0] <= 25; j[0]++)
                    visit(0);

                if (resultFlow == int.MaxValue) resultFlow = resultCost = -1;
                Console.WriteLine(resultFlow + " " + resultCost);
            }

            return 0;
        }
    }
}


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

namespace round515
{
  class Point
  {
    public int x, y;

    public Point(int x, int y)
    {
      this.x = x;
      this.y = y;
    }

    public int distance(Point p)
    {
      return Math.Abs(x - p.x) + Math.Abs(y - p.y);
    }
  }

  class MainClass
  {
    public static void Main(string[] args)
    {
      var n = int.Parse(Console.ReadLine());
      var d = new Dictionary<int, List<Point>>();
      for (int i = 0; i < n; ++i)
      {
        var line = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        int x = line[0];
        int y = line[1];

        int level = Math.Max(x, y);
        if (d.ContainsKey(level))
        {
          d[level].Add(new Point(x, y));
        }
        else
        {
          var list = new List<Point> { new Point(x, y) };
          d.Add(level, list);
        }
      }

      var pp0 = new Point(0, 0);
      var pp1 = pp0;
      long c0 = 0;
      long c1 = 0;
      foreach (var kv in d.OrderBy((kv) => kv.Key))
      {
        var level = kv.Key;
        var list = kv.Value;
        list.Sort((a, b) => {
          if (a.y == b.y)
            return a.x - b.x;
          return b.y - a.y;
        });

        var p0 = list[0];
        var p1 = list[list.Count - 1];

        long nc0 = Math.Min(c0 + p1.distance(pp0) + p1.distance(p0), c1 + p1.distance(pp1) + p1.distance(p0));
        long nc1 = Math.Min(c0 + p0.distance(pp0) + p0.distance(p1), c1 + p0.distance(pp1) + p0.distance(p1));

        c0 = nc0;
        c1 = nc1;

        pp0 = p0;
        pp1 = p1;
      }

      Console.WriteLine(Math.Min(c0, c1));
    }
  }
}


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

namespace SP.Solutions.CodeForces.c338_196_1
{
	public class ProgramC
	{
	    private static long bestRes = long.MaxValue;

		public static void Main()
		{
			checked
			{
			    bestRes = long.MaxValue;
			    int n = int.Parse(Console.ReadLine());
			    var arr = Console.ReadLine().Split(' ').Select(long.Parse).Distinct().ToArray();
                Array.Sort(arr);

			    var primes = GetPrimes();

			    var nodes = new List<Node>();
                for (int i = 0; i < arr.Length; i++)
                {
                    nodes.Add(new Node(arr[i], getFactors(arr[i], primes), arr[i], false, 0));
                }

			    TryBuildTrees(nodes, 0);
                Console.WriteLine(bestRes);
			}
		}

	    private static void TryBuildTrees(List<Node> nodes, int minJ)
	    {
	        var noWay = true;
            for (int j = minJ; j < nodes.Count; j++)
                for (int i = j + 1; i < nodes.Count; i++)
                if (j != i && !nodes[j].HasParent && nodes[i].Rem%nodes[j].N == 0 && !nodes[i].HasParent)
	        {
	            noWay = false;
	            int add = nodes[j].Factors > 1 ? 1 : 0;

	            var r1 = nodes[i].Rem;
	            var add1 = nodes[i].addFactors;

	            nodes[i].Rem = nodes[i].Rem/nodes[j].N;
	            nodes[i].addFactors = nodes[i].addFactors + nodes[j].addFactors + add;
	            nodes[j].HasParent = true;

                TryBuildTrees(nodes, minJ);

                nodes[j].HasParent = false;
                nodes[i].Rem = r1;
                nodes[i].addFactors = add1;
            }
            if (noWay)
	            CalcPrice(nodes);
	    }

	    private static void CalcPrice(List<Node> nodes)
	    {
	        int n = 0;
	        long res = 0;
            foreach (var node in nodes) if (!node.HasParent)
            {
                if (node.Factors > 1) res++;
                res += node.Factors + node.addFactors;
                n++;
            }
	        if (n > 1) res++;
	        bestRes = Math.Min(bestRes, res);
	    }

	    static int getFactors(long n, long[] primes)
        {
            int res = 0;
            int i = 0;
            while (n > 1 && i < primes.Length)
            {
                if (n%primes[i] == 0)
                {
                    res++;
                    n /= primes[i];
                }
                else i++;
            }
	        if (i == primes.Length) res++;
            return res;
        }

        class Node
        {
            public override string ToString()
            {
                return string.Format("HasParent: {0}, N: {1}, Factors: {2}, Rem: {3}", HasParent, N, Factors, Rem);
            }

            public bool HasParent;
            public readonly long N;
            public int Factors;
            public long Rem;
            public int addFactors;

            public Node(long n, int factors, long rem, bool hasParent, int addFactors)
            {
                HasParent = hasParent;
                this.addFactors = addFactors;
                N = n;
                Factors = factors;
                Rem = rem;
            }
        }

	    private static long[] GetPrimes()
	    {
	        const int max = 1000000;
	        var primes = new List<long>(80000);
	        primes.Add(2);
	        var isNotPrime = new bool[max + 1];
            for (int i = 3 ; i<= max ; i+=2) if (!isNotPrime[i])
            {
                primes.Add(i);
                for (int j = i*i; j <= max && j > 0; j += i) isNotPrime[j] = true;
            }
	        return primes.ToArray();
	    }
	}
}