using System;
using System.Collections.Generic;
using System.Collections;
using System.Globalization;
using System.IO;
using System.Linq;
//Гавно код недорешенный
public class Source
{
    public void Program()
    {
    }
    void dfs(int pos, int start, int wavenum)
    {
        if (d[start][pos] > wavenum)
        {
            d[start][pos] = wavenum;
            // d[pos][start] = wavenum;
            dfs(a[pos], start, wavenum + 1);
        }
    }
    int n;
    int[] a;
    bool[] color;
    int[][] d;
    void Read()
    {
        n = ri();
        newarray(ref d, n, n);
        fill(d, int.MaxValue);
        a = ReadIntArray();
        color = new bool[n];
        for (int i = 0; i < n; i++)
        {
            a[i] = a[i] - 1;
        }
        for (int i = 0; i < n; i++)
        {
            dfs(a[i], i, 1);
        }
        /* for (int i = 0; i < n; i++)
         {
             Array.Sort(d[i]);
         }*/
        int endn = int.MaxValue;
        for (int i = 1; i < 10000000; i++)
        {
            for (int j = 0; j < n; j++)
            {
                bool ex = false;
                for (int l = 0; l < n; l++)
                {
                    if (i % d[j][j] == d[j][l] || i % d[j][j] == 0)
                    {
                        if (d[l][j] == d[j][l])
                            ex = true;
                    }
                    if (ex)
                        break;
                }
                if (!ex)
                    goto br;
                if (j == n - 1)
                {
                    endn = Math.Min(i, endn);
                    //writeLine(num);
                    //return;
                }
            }
        br:;
        }
        if (endn == int.MaxValue)
            writeLine(-1);
        else
            writeLine(endn);
    }

    #region hide it
    #region Main

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

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

    #endregion

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

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

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

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

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

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

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

}


using Codeforces.R270;
using System;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;

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

        public static void Solve(TextReader tr, TextWriter tw)
        {
            Contract.Requires(tr != null);
            Contract.Requires(tw != null);

            var info = CultureInfo.InvariantCulture;

            var a = new int[3][];
            for (int i = 0; i < 3; ++i)
            {
                a[i] = tr.ReadLine().Split().Select(x => int.Parse(x, info)).ToArray();
            }

            var res = Calc(a);
            foreach (var l in res)
            {
                tw.WriteLine(l);
            }
        }

        private static string[] Calc(int[][] a)
        {
            Contract.Requires(a != null);

            var board = Enumerable.Range(0, 3).Select(i => Enumerable.Repeat(true, 3).ToArray()).ToArray();

            for (int i = 0; i < 3; ++i)
            {
                for (int j = 0; j < 3; ++j)
                {
                    if (a[i][j] % 2 == 1)
                    {
                        board[i][j] = !board[i][j];
                        if (i > 0)
                        {
                            board[i - 1][j] = !board[i - 1][j];
                        }
                        if (i < 2)
                        {
                            board[i + 1][j] = !board[i + 1][j];
                        }
                        if (j > 0)
                        {
                            board[i][j - 1] = !board[i][j - 1];
                        }
                        if (j < 2)
                        {
                            board[i][j + 1] = !board[i][j + 1];
                        }
                    }
                }
            }

            return board.Select(line => new string(line.Select(b => b ? '1' : '0').ToArray())).ToArray();
        }
    }
}


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

namespace Mashmokh_and_Lights
{
    class Program
    {
        static void Main(string[] args)
        {
            IO io = new IO();

            int i_N = io.ReadNextInt();
            int i_M = io.ReadNextInt();
            int[] arr_T = new int[i_N];
            int i_X = 0;
            for (int i = 0; i < i_M; i++)
            {
                i_X = io.ReadNextInt();
                for (int j = 0; j < i_N; j++)
                {
                    if (arr_T[j]==0)
                    {
                        arr_T[j] = i_X;
                    }
                }
            }
            for (int i = 0; i <= i_N; i++)
            {
                Console.Write(arr_T[i]+" ");
            }
        }
    }

    class IO
    {
        private static Queue<string> currentLineTokens = new Queue<string>();
        private static string[] ReadAndSplitLine()
        {
            return Console.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
        }
        public int ReadNextInt()
        {
            return int.Parse(ReadToken());
        }
        public long ReadNextLong()
        {
            return long.Parse(ReadToken());
        }

        public int ReadInt()
        {
            return Convert.ToInt32(Console.ReadLine());
        }
        public long ReadLong()
        {
            return Convert.ToInt64(Console.ReadLine());
        }
        public string ReadStr()
        {
            return Console.ReadLine();
        }
        public string[] ReadStrArr()
        {
            return Console.ReadLine().Split(' ');
        }
        public int[] ReadIntArr()
        {
            return Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), s => int.Parse(s));
        }
        public long[] ReadLongArr()
        {
            return Array.ConvertAll<string, long>(Console.ReadLine().Split(' '), s => long.Parse(s));
        }
        public void PutStr(string str)
        {
            Console.WriteLine(str);
        }
        public void PutStr(int str)
        {
            Console.WriteLine(str);
        }
        public void PutStr(long str)
        {
            Console.WriteLine(str);
        }
        public void PutStr(double str)
        {
            Console.WriteLine(str);
        }

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


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

namespace Bag_of_mice
{
    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 double[,] nn;

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

            nn = new double[w + 1,b + 1];
            for (int i = 1; i <= w; i++)
            {
                nn[i, 0] = 1;
            }

            for (int j = 1; j <= b; j++)
            {
                for (int i = 1; i <= w; i++)
                {
                    nn[i, j] = 1.0*i/(i + j) +
                               1.0*j/(i + j)*(1.0*(j - 1)/(i + j - 1)*(gnn(i, j - 3)*(j - 2)/(i + j - 2) + gnn(i - 1, j - 2)*(i)/(i + j - 2)));
                }
            }

            writer.WriteLine(nn[w, b].ToString("#0.000000000", CultureInfo.InvariantCulture));
            writer.Flush();
        }

        private static double gnn(int i, int j)
        {
            if (j < 0)
                return 0;
            return nn[i, j];
        }

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

namespace TaskC
{
    class Program
    {
        static void Main(string[] args)
        {
            new Solver().Solve().OutputResult();
        }

        private class ExtendedReader : StreamReader
        {
            private static readonly char Separator = ' ';

            public ExtendedReader(Stream stream) : base(stream) { }
            public ExtendedReader(Stream stream, bool detectEncodingFromByteOrderMarks) : base(stream, detectEncodingFromByteOrderMarks) { }
            public ExtendedReader(Stream stream, Encoding encoding) : base(stream, encoding) { }
            public ExtendedReader(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks) : base(stream, encoding, detectEncodingFromByteOrderMarks) { }
            public ExtendedReader(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize) : base(stream, encoding, detectEncodingFromByteOrderMarks, bufferSize) { }
            public ExtendedReader(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize, bool leaveOpen) : base(stream, encoding, detectEncodingFromByteOrderMarks, bufferSize, leaveOpen) { }
            public ExtendedReader(string path) : base(path) { }
            public ExtendedReader(string path, bool detectEncodingFromByteOrderMarks) : base(path, detectEncodingFromByteOrderMarks) { }
            public ExtendedReader(string path, Encoding encoding) : base(path, encoding) { }
            public ExtendedReader(string path, Encoding encoding, bool detectEncodingFromByteOrderMarks) : base(path, encoding, detectEncodingFromByteOrderMarks) { }
            public ExtendedReader(string path, Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize) : base(path, encoding, detectEncodingFromByteOrderMarks, bufferSize) { }

            public char ReadChar()
            {
                return (char)this.Read();
            }

            public double ReadDoubleFromArray()
            {
                StringBuilder sb = new StringBuilder();
                char ch = this.ReadChar();
                while (ch != Separator && ch != '\n')
                {
                    sb.Append(ch);
                    ch = this.ReadChar();
                }
                return Convert.ToDouble(sb.ToString());
            }

            public int ReadInt()
            {
                return int.Parse(this.ReadLine());
            }

            public Int64 ReadInt64()
            {
                return Int64.Parse(this.ReadLine());
            }

            public int[] ReadIntArray()
            {
                return this.ReadLine().Split(' ').Select(int.Parse).ToArray();
            }

            public char[] ReadCharArray()
            {
                return this.ReadLine().ToCharArray();
            }

            public string ReadString()
            {
                return this.ReadLine();
            }

            public Int64[] ReadInt64Array()
            {
                return this.ReadLine().Split(Separator).Select(Int64.Parse).ToArray();
            }

            public Double[] ReadDoubleArray()
            {
                return this.ReadLine().Split(Separator).Select(Double.Parse).ToArray();
            }
        }

        private abstract class SolverBase
        {
            protected readonly ExtendedReader _reader;
            protected readonly TextWriter _writer;

            protected SolverBase()
            {
#if DEBUG
                _reader = new ExtendedReader(@"input.txt");
                //_writer = new StreamWriter(@"output.txt");
                _writer = new StreamWriter(Console.OpenStandardOutput());
#else
                _reader = new ExtendedReader(Console.OpenStandardInput());
                _writer = new StreamWriter(Console.OpenStandardOutput());
#endif
            }

            public abstract Solver Solve();

            public abstract void OutputResult();
        }

        private class Solver : SolverBase
        {
            private int result = 0;

            public override Solver Solve()
            {
                // link to task: http://codeforces.com/contest//problem/B

                var input = _reader.ReadIntArray();
                int length = input[0];
                int changes = input[1];
                var str = _reader.ReadString();

                var a = GetMaximum(changes, str, 'a', 0);
                var b = GetMaximum(changes, str, 'b', 0);

                result = Math.Max(a, b);

                return this;
            }

            private int GetMaximum(int changes, string str, char ch, int index)
            {
                int current = 0;
                int max = 0;

                for (int i = 0; i < str.Length; i++)
                {
                    if (str[i] == ch)
                    {
                        current++;
                    }
                    else
                    {
                        if (changes > 0 && i >= index)
                        {
                            var test = GetMaximum(changes, str, ch, i + 1);
                            if (max < test)
                            {
                                max = test;
                            }

                            changes--;
                            current++;
                        }
                        else
                        {
                            current = 0;
                        }
                    }

                    if (max < current) max = current;
                }

                return max;
            }

            public override void OutputResult()
            {
                string answer = result.ToString();

                _writer.WriteLine(answer);
                _writer.Dispose();
            }
        }
    }
}


#define Online
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.IO;

delegate double F (double x);

delegate decimal Fdec (decimal x);

partial class Program
{
	public static StreamReader sr;
	public static StreamWriter sw;

	static void Main (string[] args)
	{

#if FileIO
		sr = new StreamReader ("maxincycle.in");
		sw = new StreamWriter ("maxincycle.out");
		Console.SetIn (sr);
		Console.SetOut (sw);
#endif

		B ();

#if Online
		Console.ReadLine ();
#endif

#if FileIO
		sr.Close ();
		sw.Close ();
#endif

	}

	static void A ()
	{
	}

	static void B ()
	{
		int a, b, w, x, c;
		a = NextInt ();
		b = NextInt ();
		w = NextInt ();
		x = NextInt ();
		c = NextInt ();
		long time = (long)Math.Max (a, c) * 10;
		long[] t = new long[1001];
		long[] d = new long[1001];
		int[] last = new int[1001];
		long[] th = new long[1001];
		long[] th_t = new long[1001];
		int[] last_th = new int[1001];
		for (int i=0; i<t.Length; i++) {
			int _b = i;
			int j = 0;
			int cnt = 0;
			while (_b>=x) {
				_b -= x;
				++j;
			}
			while (_b<x) {
				++cnt;
				_b = w - (x - _b);
				j++;
			}
			last [i] = _b;
			t [i] = j;
			d [i] = cnt;
		}
		for (int i=0; i<t.Length; i++) {
			int _b = i;
			while (th[i]<1000) {
				th [i] += d [_b];
				th_t [i] += t [_b];
				_b = last [_b];

			}
			last_th [i] = _b;
		}
		long left = 0;
		long right = time;
		long mid = 0;
		while (left<right) {
			mid = (left + right) / 2;
			time = mid;
			long _a = a;
			long _c = c;
			int _b = b;
			while (_c-th_t[_b]>_a-th[_b]) {
				_a -= th [_b];
				_c -= th_t [_b];
				time -= th_t [_b];
				_b = last_th [_b];
			}
			while (_c-t[_b]>_a-d[_b]) {
				time -= t [_b];
				_c -= t [_b];
				_a -= d [_b];
				_b = last [_b];
			}
			while (_b>=x && _c>_a) {
				--_c;
				--time;
				_b -= x;
			}
			while (_b<x && _c>_a) {
				--_a;
				--_c;
				_b = w - (x - _b);
				--time;
			}
			if (time >= 0) {
				right = mid;
			} else {
				left = mid + 1;
			}
		}
		Console.WriteLine (right);
	}

	static void C ()
	{

	}

	static void D ()
	{

	}

	static void E ()
	{

	}

	static void TestGen ()
	{

	}

}

public static class MyMath
{
	public static long BinPow (long a, long n, long mod)
	{
		long res = 1;
		while (n > 0) {
			if ((n & 1) == 1) {
				res = (res * a) % mod;
			}
			a = (a * a) % mod;
			n >>= 1;
		}
		return res;
	}

	public static long GCD (long a, long b)
	{
		while (b != 0)
			b = a % (a = b);
		return a;
	}

	public static int GCD (int a, int b)
	{
		while (b != 0)
			b = a % (a = b);
		return a;
	}

	public static long LCM (long a, long b)
	{
		return (a * b) / GCD (a, b);
	}

	public static int LCM (int a, int b)
	{
		return (a * b) / GCD (a, b);
	}
}

static class ArrayUtils
{
	static void Swap<T> (T[] a, int l, int r)
	{
		T t = a [l];
		a [l] = a [r];
		a [r] = t;
	}

	public static bool NextPermutation (int[] a)
	{
		bool isOkay = false;
		int n = a.Length;
		for (int i=n-2; i>=0; i--) {
			if (a [i] < a [i + 1]) {
				isOkay = true;
				int j = i + 1;
				while (j+1<n && a[j+1]>a[i]) {
					j++;
				}
				Swap (a, i, j);
				for (j=1; i+j<n-j; j++) {
					Swap (a, i + j, n - j);
				}
				break;
			}
		}
		return isOkay;
	}

	public static int BinarySearch (int[] a, int val)
	{
		int left = 0;
		int right = a.Length - 1;
		int mid;

		while (left < right) {
			mid = left + ((right - left) >> 1);
			if (val <= a [mid]) {
				right = mid;
			} else {
				left = mid + 1;
			}
		}

		if (a [left] == val)
			return left;
		else
			return -1;
	}

	public static double Bisection (F f, double left, double right, double eps)
	{
		double mid;
		while (right - left > eps) {
			mid = left + ((right - left) / 2d);
			if (Math.Sign (f (mid)) != Math.Sign (f (left)))
				right = mid;
			else
				left = mid;
		}
		return (left + right) / 2d;
	}

	public static decimal TernarySearchDec (Fdec f, decimal eps, decimal l, decimal r, bool isMax)
	{
		decimal m1, m2;
		while (r - l > eps) {
			m1 = l + (r - l) / 3m;
			m2 = r - (r - l) / 3m;
			if (f (m1) < f (m2))
			if (isMax)
				l = m1;
			else
				r = m2;
			else
                    if (isMax)
				r = m2;
			else
				l = m1;
		}
		return r;
	}

	public static double TernarySearch (F f, double eps, double l, double r, bool isMax)
	{
		double m1, m2;
		while (r - l > eps) {
			m1 = l + (r - l) / 3d;
			m2 = r - (r - l) / 3d;
			if (f (m1) < f (m2))
			if (isMax)
				l = m1;
			else
				r = m2;
			else
                    if (isMax)
				r = m2;
			else
				l = m1;
		}
		return r;
	}

	public static void Merge_Sort<T> (T[]A, int p, int r, Comparison<T> comp)
	{
		T[] L = new T[A.Length];
		T[] R = new T[A.Length];
		Merge_Sort (A, p, r, L, R, comp);
	}

	public static void Merge<T> (T[] A, int p, int q, int r, T[] L, T[] R, Comparison<T> comp)
	{
		for (int i = p; i <= q; i++)
			L [i] = A [i];
		for (int i = q + 1; i <= r; i++)
			R [i] = A [i];

		for (int k = p, i = p, j = q + 1; k <= r; k++) {
			if (i > q) {
				for (; k <= r; k++, j++)
					A [k] = R [j];
				return;
			}
			if (j > r) {
				for (; k <= r; k++, i++)
					A [k] = L [i];
				return;
			}
			if (comp (L [i], R [j]) <= 0) {
				A [k] = L [i];
				i++;
			} else {
				A [k] = R [j];
				j++;
			}
		}
	}

	private static void Merge_Sort<T> (T[] A, int p, int r, T[] L, T[] R, Comparison<T> comp)
	{
		if (p >= r)
			return;
		int q = p + ((r - p) >> 1);
		Merge_Sort (A, p, q, L, R, comp);
		Merge_Sort (A, q + 1, r, L, R, comp);
		Merge (A, p, q, r, L, R, comp);
	}

	public static void Merge_Sort<T> (T[]A, int p, int r)where T:IComparable<T>
	{
		T[] L = new T[A.Length];
		T[] R = new T[A.Length];
		Merge_Sort (A, p, r, L, R);
	}

	public static void Merge<T> (T[] A, int p, int q, int r, T[] L, T[] R) where T : IComparable<T>
	{
		for (int i = p; i <= q; i++)
			L [i] = A [i];
		for (int i = q + 1; i <= r; i++)
			R [i] = A [i];

		for (int k = p, i = p, j = q + 1; k <= r; k++) {
			if (i > q) {
				for (; k <= r; k++, j++)
					A [k] = R [j];
				return;
			}
			if (j > r) {
				for (; k <= r; k++, i++)
					A [k] = L [i];
				return;
			}
			if (L [i].CompareTo (R [j]) <= 0) {
				A [k] = L [i];
				i++;
			} else {
				A [k] = R [j];
				j++;
			}
		}
	}

	private static void Merge_Sort<T> (T[] A, int p, int r, T[] L, T[] R) where T : IComparable<T>
	{
		if (p >= r)
			return;
		int q = p + ((r - p) >> 1);
		Merge_Sort (A, p, q, L, R);
		Merge_Sort (A, q + 1, r, L, R);
		Merge (A, p, q, r, L, R);
	}

	public static void Merge_Sort_Non_Recursive<T> (T[] A, int p, int r) where T : IComparable<T>
	{
		T[] L = new T[A.Length];
		T[] R = new T[A.Length];
		int k = 1;
		while (k < r - p + 1) {
			int i = 0;
			while (i < r) {
				int _r = Math.Min (i + 2 * k - 1, r);
				int q = Math.Min (i + k - 1, r);
				Merge (A, i, q, _r, L, R);
				i += 2 * k;
			}
			k <<= 1;
		}
	}

	public static void Merge_Sort_Non_Recursive<T> (T[] A, int p, int r, Comparison<T> comp)
	{
		T[] L = new T[A.Length];
		T[] R = new T[A.Length];
		int k = 1;
		while (k < r - p + 1) {
			int i = 0;
			while (i < r) {
				int _r = Math.Min (i + 2 * k - 1, r);
				int q = Math.Min (i + k - 1, r);
				Merge (A, i, q, _r, L, R, comp);
				i += 2 * k;
			}
			k <<= 1;
		}
	}

	public static void Shake<T> (T[] a)
	{
		Random rnd = new Random (Environment.TickCount);
		int b;
		for (int i = 0; i < a.Length; i++) {
			b = rnd.Next (i, a.Length);
			Swap (a, i, b);
		}
	}
}

partial class Program
{
	static string[] tokens = new string[0];
	static int cur_token = 0;

	static void ReadArray (char sep)
	{
		cur_token = 0;
		tokens = Console.ReadLine ().Split (sep);
	}

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

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

	static int NextInt ()
	{
		if (cur_token == tokens.Length)
			ReadArray (' ');
		return int.Parse (tokens [cur_token++]);
	}

	static long NextLong ()
	{
		if (cur_token == tokens.Length)
			ReadArray (' ');
		return long.Parse (tokens [cur_token++]);
	}

	static double NextDouble ()
	{
		if (cur_token == tokens.Length)
			ReadArray (' ');
		return double.Parse (tokens [cur_token++]);
	}

	static decimal NextDecimal ()
	{
		if (cur_token == tokens.Length)
			ReadArray (' ');
		return decimal.Parse (tokens [cur_token++]);
	}

	static string NextToken ()
	{
		if (cur_token == tokens.Length)
			ReadArray (' ');
		return tokens [cur_token++];
	}

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


#define FileIO
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.IO;

delegate double F (double x);

delegate decimal Fdec (decimal x);

partial class Program
{
	public static StreamReader sr;
	public static StreamWriter sw;

	static void Main (string[] args)
	{

#if FileIO
		sr = new StreamReader ("input.in");
		sw = new StreamWriter ("input.out");
		Console.SetIn (sr);
		Console.SetOut (sw);
#endif

		B ();

#if Online
		Console.ReadLine ();
#endif

#if FileIO
		sr.Close ();
		sw.Close ();
#endif

	}

	static void A ()
	{
	}

	static void B ()
	{
		int a, b, w, x, c;
		a = NextInt ();
		b = NextInt ();
		w = NextInt ();
		x = NextInt ();
		c = NextInt ();
		long time = long.MaxValue;
		long[] t = new long[1001];
		long[] d = new long[1001];
		int[] last = new int[1001];
		long[] th = new long[1001];
		long[] th_t = new long[1001];
		int[] last_th = new int[1001];
		for (int i=0; i<t.Length; i++) {
			int _b = i;
			int j = 0;
			int cnt = 0;
			while (_b>=x) {
				_b -= x;
				++j;
			}
			while (_b<x) {
				++cnt;
				_b = w - (x - _b);
				j++;
			}
			last [i] = _b;
			t [i] = j;
			d [i] = cnt;
		}
		for (int i=0; i<t.Length; i++) {
			int _b = i;
			while (th_t[i]-th[i]<1000) {
				th [i] += d [_b];
				th_t [i] += t [_b];
				_b = last [_b];

			}
			last_th [i] = _b;
		}

		long left = 0;
		long right = time;
		long mid = 0;
		while (left<right) {
			mid = (left + right) / 2;
			time = mid;
			long _a = a;
			long _c = c;
			int _b = b;
			while (_c-th_t[_b]>_a-th[_b]) {
				_a -= th [_b];
				_c -= th_t [_b];
				time -= th_t [_b];
				_b = last_th [_b];
			}
			while (_c-t[_b]>_a-d[_b]) {
				time -= t [_b];
				_c -= t [_b];
				_a -= d [_b];
				_b = last [_b];
			}
			while (_b>=x && _c>_a) {
				--_c;
				--time;
				_b -= x;
			}
			while (_b<x && _c>_a) {
				--_a;
				--_c;
				_b = w - (x - _b);
				--time;
			}
			if (time >= 0) {
				right = mid;
			} else {
				left = mid + 1;
			}
		}
		Console.WriteLine (right);
	}

	static void C ()
	{

	}

	static void D ()
	{

	}

	static void E ()
	{

	}

	static void TestGen ()
	{

	}

}

public static class MyMath
{
	public static long BinPow (long a, long n, long mod)
	{
		long res = 1;
		while (n > 0) {
			if ((n & 1) == 1) {
				res = (res * a) % mod;
			}
			a = (a * a) % mod;
			n >>= 1;
		}
		return res;
	}

	public static long GCD (long a, long b)
	{
		while (b != 0)
			b = a % (a = b);
		return a;
	}

	public static int GCD (int a, int b)
	{
		while (b != 0)
			b = a % (a = b);
		return a;
	}

	public static long LCM (long a, long b)
	{
		return (a * b) / GCD (a, b);
	}

	public static int LCM (int a, int b)
	{
		return (a * b) / GCD (a, b);
	}
}

static class ArrayUtils
{
	static void Swap<T> (T[] a, int l, int r)
	{
		T t = a [l];
		a [l] = a [r];
		a [r] = t;
	}

	public static bool NextPermutation (int[] a)
	{
		bool isOkay = false;
		int n = a.Length;
		for (int i=n-2; i>=0; i--) {
			if (a [i] < a [i + 1]) {
				isOkay = true;
				int j = i + 1;
				while (j+1<n && a[j+1]>a[i]) {
					j++;
				}
				Swap (a, i, j);
				for (j=1; i+j<n-j; j++) {
					Swap (a, i + j, n - j);
				}
				break;
			}
		}
		return isOkay;
	}

	public static int BinarySearch (int[] a, int val)
	{
		int left = 0;
		int right = a.Length - 1;
		int mid;

		while (left < right) {
			mid = left + ((right - left) >> 1);
			if (val <= a [mid]) {
				right = mid;
			} else {
				left = mid + 1;
			}
		}

		if (a [left] == val)
			return left;
		else
			return -1;
	}

	public static double Bisection (F f, double left, double right, double eps)
	{
		double mid;
		while (right - left > eps) {
			mid = left + ((right - left) / 2d);
			if (Math.Sign (f (mid)) != Math.Sign (f (left)))
				right = mid;
			else
				left = mid;
		}
		return (left + right) / 2d;
	}

	public static decimal TernarySearchDec (Fdec f, decimal eps, decimal l, decimal r, bool isMax)
	{
		decimal m1, m2;
		while (r - l > eps) {
			m1 = l + (r - l) / 3m;
			m2 = r - (r - l) / 3m;
			if (f (m1) < f (m2))
			if (isMax)
				l = m1;
			else
				r = m2;
			else
                    if (isMax)
				r = m2;
			else
				l = m1;
		}
		return r;
	}

	public static double TernarySearch (F f, double eps, double l, double r, bool isMax)
	{
		double m1, m2;
		while (r - l > eps) {
			m1 = l + (r - l) / 3d;
			m2 = r - (r - l) / 3d;
			if (f (m1) < f (m2))
			if (isMax)
				l = m1;
			else
				r = m2;
			else
                    if (isMax)
				r = m2;
			else
				l = m1;
		}
		return r;
	}

	public static void Merge_Sort<T> (T[]A, int p, int r, Comparison<T> comp)
	{
		T[] L = new T[A.Length];
		T[] R = new T[A.Length];
		Merge_Sort (A, p, r, L, R, comp);
	}

	public static void Merge<T> (T[] A, int p, int q, int r, T[] L, T[] R, Comparison<T> comp)
	{
		for (int i = p; i <= q; i++)
			L [i] = A [i];
		for (int i = q + 1; i <= r; i++)
			R [i] = A [i];

		for (int k = p, i = p, j = q + 1; k <= r; k++) {
			if (i > q) {
				for (; k <= r; k++, j++)
					A [k] = R [j];
				return;
			}
			if (j > r) {
				for (; k <= r; k++, i++)
					A [k] = L [i];
				return;
			}
			if (comp (L [i], R [j]) <= 0) {
				A [k] = L [i];
				i++;
			} else {
				A [k] = R [j];
				j++;
			}
		}
	}

	private static void Merge_Sort<T> (T[] A, int p, int r, T[] L, T[] R, Comparison<T> comp)
	{
		if (p >= r)
			return;
		int q = p + ((r - p) >> 1);
		Merge_Sort (A, p, q, L, R, comp);
		Merge_Sort (A, q + 1, r, L, R, comp);
		Merge (A, p, q, r, L, R, comp);
	}

	public static void Merge_Sort<T> (T[]A, int p, int r)where T:IComparable<T>
	{
		T[] L = new T[A.Length];
		T[] R = new T[A.Length];
		Merge_Sort (A, p, r, L, R);
	}

	public static void Merge<T> (T[] A, int p, int q, int r, T[] L, T[] R) where T : IComparable<T>
	{
		for (int i = p; i <= q; i++)
			L [i] = A [i];
		for (int i = q + 1; i <= r; i++)
			R [i] = A [i];

		for (int k = p, i = p, j = q + 1; k <= r; k++) {
			if (i > q) {
				for (; k <= r; k++, j++)
					A [k] = R [j];
				return;
			}
			if (j > r) {
				for (; k <= r; k++, i++)
					A [k] = L [i];
				return;
			}
			if (L [i].CompareTo (R [j]) <= 0) {
				A [k] = L [i];
				i++;
			} else {
				A [k] = R [j];
				j++;
			}
		}
	}

	private static void Merge_Sort<T> (T[] A, int p, int r, T[] L, T[] R) where T : IComparable<T>
	{
		if (p >= r)
			return;
		int q = p + ((r - p) >> 1);
		Merge_Sort (A, p, q, L, R);
		Merge_Sort (A, q + 1, r, L, R);
		Merge (A, p, q, r, L, R);
	}

	public static void Merge_Sort_Non_Recursive<T> (T[] A, int p, int r) where T : IComparable<T>
	{
		T[] L = new T[A.Length];
		T[] R = new T[A.Length];
		int k = 1;
		while (k < r - p + 1) {
			int i = 0;
			while (i < r) {
				int _r = Math.Min (i + 2 * k - 1, r);
				int q = Math.Min (i + k - 1, r);
				Merge (A, i, q, _r, L, R);
				i += 2 * k;
			}
			k <<= 1;
		}
	}

	public static void Merge_Sort_Non_Recursive<T> (T[] A, int p, int r, Comparison<T> comp)
	{
		T[] L = new T[A.Length];
		T[] R = new T[A.Length];
		int k = 1;
		while (k < r - p + 1) {
			int i = 0;
			while (i < r) {
				int _r = Math.Min (i + 2 * k - 1, r);
				int q = Math.Min (i + k - 1, r);
				Merge (A, i, q, _r, L, R, comp);
				i += 2 * k;
			}
			k <<= 1;
		}
	}

	public static void Shake<T> (T[] a)
	{
		Random rnd = new Random (Environment.TickCount);
		int b;
		for (int i = 0; i < a.Length; i++) {
			b = rnd.Next (i, a.Length);
			Swap (a, i, b);
		}
	}
}

partial class Program
{
	static string[] tokens = new string[0];
	static int cur_token = 0;

	static void ReadArray (char sep)
	{
		cur_token = 0;
		tokens = Console.ReadLine ().Split (sep);
	}

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

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

	static int NextInt ()
	{
		if (cur_token == tokens.Length)
			ReadArray (' ');
		return int.Parse (tokens [cur_token++]);
	}

	static long NextLong ()
	{
		if (cur_token == tokens.Length)
			ReadArray (' ');
		return long.Parse (tokens [cur_token++]);
	}

	static double NextDouble ()
	{
		if (cur_token == tokens.Length)
			ReadArray (' ');
		return double.Parse (tokens [cur_token++]);
	}

	static decimal NextDecimal ()
	{
		if (cur_token == tokens.Length)
			ReadArray (' ');
		return decimal.Parse (tokens [cur_token++]);
	}

	static string NextToken ()
	{
		if (cur_token == tokens.Length)
			ReadArray (' ');
		return tokens [cur_token++];
	}

	static string ReadLine ()
	{
		return 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)
        {
            string []numbers = Console.ReadLine().Split(' ');
            int c = int.Parse(numbers[4]), a = int.Parse(numbers[0]), b = int.Parse(numbers[1]), w = int.Parse(numbers[2]), x = int.Parse(numbers[3]);
            int seconds = 0;
            while (c > a)
            {
                c = c - 1;
                if (b >= x)
                    b = b - x;
                if (b < x)
                {
                    a = a - 1;
                    b = w - (x - b);
                }
                seconds++;
            }
            seconds -= 1;
            Console.WriteLine(seconds);
        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int t=0,q=0,w=0;
            int[] i = new int[10];
            for (int k = 0; k <= 5; k++)
            {
                i[k] = int.Parse(Console.ReadLine());
            }

            for (var k=0;k<5;k++)
    {
        for(var l=k;l<6;l++)
        {
            if(i[k]>i[l])
            {
                t=i[k];
                i[k]=i[l];
                i[l]=t;

            }
        }

    }

            if (i[0] == i[3] || i[1] == i[4] || i[2] == i[5])
            {
                if (i[4] == i[5] || i[0] == i[5] ||i[1]==i[0])
                {
                    Console.WriteLine("Elephant");
                }

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

            }
            else
            {
                Console.WriteLine("Alien");
            }
                Console.ReadKey();
        }
    }
}


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

namespace Problem471A {
    class Program {
        static void Main(string[] args) {
            string[] input = Console.ReadLine().Split(' ');
            List<int> sticks = new List<int>();

            for (int i = 0; i < 6; i++) {
                int actStick = Convert.ToInt32(input[i]);
                sticks.Add(actStick);
            }

            int legL = findLegs(sticks);
            if (legL == -1) {
                Console.WriteLine("Alien");
            } else {
                List<int> restOfSticks = deleteLegs(sticks, legL);
                int head = restOfSticks[0];
                int body = restOfSticks[1];

                if (head == body) {
                    Console.WriteLine("Elephant");
                } else {
                    Console.WriteLine("Bear");
                }
            }
        }

        static List<int> deleteLegs(List<int> sticks, int legL) {
            List<int> restOfLegs = new List<int>();
            int deleted = 0;
            for (int i = 0; i < 6; i++) {
                int actStick = sticks[i];
                if (actStick == legL) {
                    if (deleted == 4) {
                        restOfLegs.Add(actStick);
                    } else {
                        deleted++;
                    }
                }

                if (actStick != legL) {
                    restOfLegs.Add(actStick);
                }
            }

            return restOfLegs;
        }

        static int findLegs(List<int> sticks) {
            int legStickL = -1;  //-1 - Alien
            int[] count = new int[9];

            for (int i = 0; i < 6; i++) {
                int actStick = sticks[i];
                count[actStick]++;
            }

            for (int i = 0; i < 9; i++) {
                int actCount = count[i];
                if (actCount >= 4) {
                    legStickL = i;
                    break;
                }
            }

            return legStickL;
        }
    }
}


using System;
using System.Linq;

namespace CSharp
{
    public class _938A
    {
        public static void Main()
        {
            char[] vowels = new char[] { 'a', 'e', 'i', 'o', 'u', 'y' };

            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();

            Console.WriteLine(new string(Enumerable.Range(0, n).Where(i => i == '0' || !vowels.Contains(s[i]) || !vowels.Contains(s[i - 1])).Select(i => s[i]).ToArray()));
        }
    }
}


 char[] vowels = { 'a', 'e', 'i', 'o', 'u', 'y' };
            int inputLetterSize = int.Parse(Console.ReadLine());
            string letter = Console.ReadLine();
            StringBuilder letterBilder = new StringBuilder(letter);

            for (int i = 0; i < letterBilder.Length-1; i++)
            {
                if (vowels.Contains(letterBilder[i])){
                    if (vowels.Contains(letterBilder[i + 1])) { letterBilder.Remove(i + 1, 1); i--; }

                }
            }

            //for (int i = 1; i < letterBilder.Length; i++)
            //{
            //    if(vowels.Contains(letterBilder[i]))
            //    {
            //        if (vowels.Contains(letterBilder[i - 1]))
            //        { letterBilder.Remove(i, 1);
            //            i = 0;
            //        }
            //    }
            //}
            Console.WriteLine(letterBilder);


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace test
{
    class Program
    {
        static bool judge(char x)
        {
            if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u' || x == 'y')
            {
                return true;
            }
            return false;
        }
        static void Main(string[] args)
        {
            var str1 = Console.ReadLine();
            var str = Console.ReadLine();
            int a = int.Parse(str1);
            int len = str.Length;
            string ans = string.Empty;
            for (int i = 0; i < str.Length; i++)
            {
                if (judge(str[i]))
                {
                    ans += str[i];
                    while (judge(str[i + 1]))
                    {
                        i++;
                        if (i == len - 1)
                            break;
                    }
                }
                else
                    ans += str[i];
            }
            Console.WriteLine(ans);
        }
    }
}


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

namespace Rextester
{
    public class Program
    {
        public static void Main(string[] args)
        {
           Dictionary <string, int> days = new Dictionary<string, int>();
            days.Add ("monday", 1);
            days.Add ("tuesday", 2);
            days.Add ("wednesday", 3);
            days.Add ("thursday", 4);
            days.Add ("friday", 5);
            days.Add ("saturday", 6);
            days.Add ("sunday", 7);

            string first = Console.ReadLine();
            string second = Console.ReadLine();

            int day1 = days[first];
            int day2 = days[second];

            int dif = Math.Abs(day1-day2);

            if(dif == 0 || dif == 2 || dif == 3 ||dif == 4 || dif == 5)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");

        }
    }
}


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

namespace ConsoleApplication9
{
    class Program
    {
        static void Main(string[] args)
        {
            Dictionary<string, int> dics = new Dictionary<string, int>();

            var numb = "monday,tuesday,wednesday,thursday,friday,saturday,sunday".Split(',');

            int c = 0;
            foreach (var i in numb)
            {
                dics.Add(i, c);
                c++;
            }

            var numbers = "31,28,31,30,31,30,31,31,30,31,30,31".Split(',');

            int b = 1;

            var f = Console.ReadLine();
            var s = Console.ReadLine();

            if ((dics[s] +4)%7== dics[f] || dics[s] - dics[f] == 0 || (dics[s] +3)%7 == dics[f])
            {
                Console.WriteLine("YES");

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

        }
    }
}


using System;
class Program {
    static void Main(string[] args) {
        string s = Console.ReadLine();
        Console.WriteLine(s.Length*25 + 65);
    }
}


using System;

public static class Program
{
    public static void Main(string[] args){
         string s = Console.ReadLine();
         int length = s.Count + 1;
         Console.WriteLine((26 * length) - length);
}
}


/*
 * Created by SharpDevelop.
 * User: tagirov2
 * Date: 08.03.2016
 * Time: 13:56
 *

A. ���������
������ ��������� �������� � ���������. � ��� ���� ��� ��������� � ������ ���� �������.
���������� ������ �������� ������� �� a1 ���������, � ������ �� a2 ���������.
���������� �������� � ������� ����� ������ ������� ������ ������.
�� ������ ���� �������� ��� ������� ����������� �� 2 ��������, � � �������� ���������� �� 1 �������.
���� ������������ ���� ����� ����� ���������� ������ �����������.
����� �������, ���� � ������ ��������� ������ � ������-���� ��������� ������� 1 ������� ������,
�� ��� ���������� ���������� � ������� ��� ���� ����� �����������.
���� � ������-�� ��������� ������� 0 ��������� �������, �� ���� ���������������.
���������� ������������ ����� � �������, ������� ����� ���������� ����.
������ ����� � ���� ������, �� ���� ������ ������ ��� ��������� ����������� ������ ���� � ����.
� ���� ����������� �����������, ������ �� ���������� ����� ���� ������� ����� ��� �� 100 ���������.
������� ������
� ������ ������ ������� ������ ���������� ��� ����� ������������� ����� a1, a2 (1 <= a1, a2 <= 100) �
��������� ������� ������ ������� � ������� ��������� ��������������.
�������� ������
�������� ������������ ����� ����� � ������������ ���������� �����, ������� ����� ������������ ����.
���� ������������ ���� �����-���� �� ���������� �� ����������.
�������
������� ������
3 5
�������� ������
6
������� ������
4 4
�������� ������
5
����������
� ������ ������� ���� ����� ������������ 6 �����, ��������, ��� ����� ������������������ ��������:
�	� ������ ������ ���������� � ������� ������ �������� � �������� ����, � ����� ������ ������ ������ �������� ����� ������� �� 4%, � ������ � �� 3%;
�	�� ����� ������� ������ ��� ������, � ����� ������ ������ ������ �������� ����� ������� �� 5%, � ������ � �� 1%;
�	����� ������� ������� ����������� ������� �� ������ ��������, ����� ��� ������ ����� ������� �� 3%, ������ � �� 2%;
�	�� ����� ������� ������ ��� ������, � ����� ������ ������ ������ �������� ����� ������� �� 1%, � ������ � �� 3%;
�	����� ����� ������� ����������� ������� �� ������ ��������, ����� ��� ������ ����� ������� �� 2%, ������ � �� 1%;
�	����� ������ ������� ����������� ������� �� ������ ��������, ����� ��� ������ ����� ������� �� 0%, ������ � �� 2%.
��� ��� ������ �������� ��������� ����������, ���������� ���� ����� ������.
 */

using System;

class Program
{
	public static void Main(string[] args)
	{
		string ss = Console.ReadLine ();
		string [] s = ss.Split (' ');
		int a = int.Parse (s [0]);
		int b = int.Parse (s [1]);

		int m = 0;
		for ( ; true; )
		{
//			Console.WriteLine (a + " " + b);
			if ( a > b )
			{
				if ( a == 2)
				{
					m++;
					break;
				}
				if ( a % 2 == 1 )
				{
					b += a / 2;
					m += a / 2;
					a = 1;
				}
				else
				{
					b += a / 2 - 1;
					m += a / 2 - 1;
					a = 2;
				}
			}
			else
			{
				if ( b == 2)
				{
					m++;
					break;
				}
				if ( b % 2 == 1 )
				{
					a += b / 2;
					m += b / 2;
					b = 1;
				}
				else
				{
					a += b / 2 - 1;
					m += b / 2 - 1;
					b = 2;
				}
			}
		}

		Console.WriteLine (m);
//		Console.ReadKey(true);
	}
}


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

namespace _37N
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int[] l = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            Array.Sort(l);
            int distc = 0, len = 1,maxLen = 1;
            for(int i = 1;i<n;i++)
            {
                if (l[i] == l[i - 1])
                {
                    len++;
                    if (len > maxLen)
                        maxLen = len;
                }
                else
                {
                    len = 1;
                    distc++;
                }
            }
            Console.WriteLine("{0} {1}", maxLen, distc+1);
        }
    }
}


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

namespace ProgrammingContest.Codeforces.Round59
{
    class C
    {
        int n;
        int[][] dat;
        int count;
        int res;

        bool ok(int id, params int[] xs)
        {
            int a = 0, b = 0;
            int[] pos = new int[10];
            for (int i = 0; i < 10; i++)
                pos[i] = -1;
            for (int i = 0; i < 4; i++)
                pos[xs[i]] = i;
            for (int m = dat[id][0], i = 3; i >= 0; i--, m /= 10)
            {
                if (pos[m % 10] == i) a++;
                else if (pos[m % 10] >= 0) b++;
            }
            //for (int i = 0; i < 4; i++)
            //    Console.Write("{0} ", xs[i]);
            //Console.WriteLine(": {0} {1} : {2} {3}", a, b, dat[id][1], dat[id][2]);
            return a == dat[id][1] && b == dat[id][2];
        }

        C()
        {
            n = int.Parse(Console.ReadLine());
            dat = new int[n][];
            for (int i = 0; i < n; i++)
                dat[i] = Array.ConvertAll(Console.ReadLine().Split(' '), sss => int.Parse(sss));

            for (int a = 0; a < 10; a++)
                for (int b = 0; b < 10; b++)
                    if (a != b)
                        for (int c = 0; c < 10; c++)
                            if (a != c && b != c)
                                for (int d = 0; d < 10; d++)
                                    if (a != d && b != d && c != d)
                                    {
                                        bool chk = true;
                                        for (int i = 0; i < n; i++)
                                            chk &= ok(i, a, b, c, d);
                                        if (chk)
                                        {
                                            count++;
                                            res = a * 1000 + b * 100 + c * 10 + d;
                                        }
                                    }

            Console.WriteLine(count == 0 ? "Incorrect data" : (count != 1 ? "Need more data" : res.ToString()));
        }

        public static void Main()
        {
            new C();
        }
    }
}


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

namespace k_Tree
{
    class Program
    {
        static short n, k, d;

        static int[,] dpMaxWays;

        static void Main(string[] args)
        {
            // Reading input as n, k, d
            string iLine = Console.ReadLine();
            string[] iStrings = iLine.Split(' ');
            n = Convert.ToInt16(iStrings[0]);
            k = Convert.ToInt16(iStrings[1]);
            d = Convert.ToInt16(iStrings[2]);

            dpMaxWays = new int[n + 1, 2];

            Console.WriteLine(NumberOfWays(remaining: n, gotD: 0));
        }

        static int NumberOfWays(int remaining, int gotD)
        {
            if (remaining == 0)
            {
                if (gotD != 0)
                {
                    return 1;
                }
                else
                {
                    return 0;
                }
            }
            else if (remaining < 0)
            {
                return 0;
            }
            else if (dpMaxWays[remaining, gotD] != 0)
            {
                return dpMaxWays[remaining, gotD];
            }

            int ways = 0;
            int sonGotD = gotD;

            for (int e = 1; e <= k; e++)
            {
                sonGotD = e >= d? 1 : sonGotD;
                ways += NumberOfWays(remaining - e, sonGotD);
                ways %= 1000000007;
            }

            dpMaxWays[remaining, gotD] = ways;

            return ways;
        }
    }
}


using System;
using System.Collections.Generic;

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

             string[] input = Console.ReadLine().Split(" ");

            Console.WriteLine(FindDivisor(Convert.ToInt32(input[0]), Convert.ToInt32(input[1])));

    }

        static int FindDivisor(int x , int y)
        {
            List<int> a = new List<int>();

            for (int i = 1 ; i <= x; i++) if (x % i == 0) a.Add(i);

            try
            {
                return a[y - 1];
            }
            catch (ArgumentOutOfRangeException)
            {

                return -1;
            }

        }

    }
}


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

            int input1 = Convert.ToInt32(Console.ReadLine());

            int input2 = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine(FindDivisor(input1, input2));

        }

        static int FindDivisor(int x , int y)
        {
            List<int> a = new List<int>();

            for (int i = 1 ; i <= x; i++) if (x % i == 0) a.Add(i);

            try
            {
                return a[y - 1];
            }
            catch (ArgumentOutOfRangeException)
            {

                return -1;
            }

        }
    }


using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;

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

             string[] input = Console.ReadLine().Split(" ");

            Console.WriteLine(FindDivisor(Convert.ToInt64(input[0]), Convert.ToInt64(input[1])));

    }

        static long FindDivisor(long x , long y)
        {
            List<long> a = new List<long>();

            for (int i = 1; i <= x; i++)
            {
                if (x % i == 0) a.Add(i);

            }
            try
            {
                int z = (int) y;
                return a[z-1];
            }
            catch (ArgumentOutOfRangeException)
            {

                return -1;
            }

        }

    }
}


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

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

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

            var divisors = new SortedSet<long>();

            for (int i = 1; i * i <= n; i++)
            {
                if (n % i == 0)
                {
                    divisors.Add(i);
                    divisors.Add(n / i);
                }
            }

            Console.WriteLine(divisors.Skip(k - 1).DefaultIfEmpty(-1).First());
        }
    }
}


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

namespace KingsWay
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] token = Console.ReadLine().Split();
            long n = long.Parse(token[0]);
            long k = long.Parse(token[1]);

            long num = n;
            List<long> myList = new List<long>();
           // myList.Contains(i)
            for(int i=1; ;i++)
            {
                if(i>=num)
                     break;
                if(n%i==0)
                {
                     if(!myList.Contains(i))
                     myList.Add(i);
                     num =n / i;
                     if(!myList.Contains(num))
                     myList.Add(num);
                }

            }
            myList.Sort();
            long count = -1;
           //myList.Add(13);
            for(int i = 0;i<myList.Count;i++)
            {
                if(i==k-1)
                {
                    count = myList[i];
                    break;
                }
              // Console.WriteLine(myList[i]);
            }

            if(myList.Count<=1)
               count = 1;
             if(k>n)
             {
                 count = -1;
             }
            Console.WriteLine(count);

        }
    }
}


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

namespace KingsWay
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] token = Console.ReadLine().Split();
            long n = long.Parse(token[0]);
            long k = long.Parse(token[1]);

            long num = n;
            List<long> myList = new List<long>();
           // myList.Contains(i)
            int h = (n%2==0)?n/2:n+1/2;
            for(int i=1;i<h ;i++)
            {
                if(i>=num)
                     break;
                if(n%i==0)
                {
                     if(!myList.Contains(i))
                     myList.Add(i);
                     num =n / i;
                     if(!myList.Contains(num))
                     myList.Add(num);
                }

            }
            myList.Sort();
            long count = -1;
           //myList.Add(13);
            for(int i = 0;i<myList.Count;i++)
            {
                if(i==k-1)
                {
                    count = myList[i];
                    break;
                }
              // Console.WriteLine(myList[i]);
            }

            if(myList.Count<=1)
               count = 1;
             if(k>n)
             {
                 count = -1;
             }
            Console.WriteLine(count);

        }
    }
}


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

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

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

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

			long n = inputs1[0];
			long k = inputs1[1];

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

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

			var d = new List<long> { 1 };
			int index = 1;
			var border = n;

			for (long i = 2; i < border; i++)
			{
				if (n % i == 0)
				{
					var res = n / i;
					d.Insert(index, res);
					if (i != res)
					{
						d.Insert(index, i);
					}

					index++;
					border = res;
				}
			}

			d.Insert(d.Count, n);

			if (d.Count >= k)
			{
				Console.WriteLine(d.ElementAt((int)(k - 1)));
			}
			else
			{
				Console.WriteLine(-1);
			}
		}

		public static void Print(int[] number)
		{
			var stringBuilder = new StringBuilder();
			foreach (var i in number)
			{
				if (i == 0 && stringBuilder.Length == 0)
				{
					continue;
				}

				stringBuilder.Append(i);
			}

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

		public void Method1(ref int n1, ref int n2, ref int k1, ref int k2)
		{
			double a = (double)n1 / k1;
			double b = (double)n2 / k2;
			if (n1 >= n2 || (a >= b && a < 2 * b))
			{

			}
		}

		public void Method2(ref int n1, ref int n2, ref int k1, ref int k2)
		{
			double a = (double)n1 / k1;
			double b = (double)n2 / k2;
			if (n2 >= n1 || (b >= a && b < 2 * a))
			{

			}
		}

		public class Node
		{
			public int Count { get; set; }

			public int FirstIndex { get; set; } = -1;

			public int LastIndex { get; set; } = -1;
		}

		//public class Node<T>
		//{
		//	public Node<T> Left { get; set; }

		//	public Node<T> Right { get; set; }

		//	public T Value { get; set; }

		//	public Node(T value)
		//	{
		//		Value = value;
		//	}
		//}

		//public class Tree<T>
		//{
		//	public Node<T> Root { get; set; }

		//	public Tree(T value)
		//	{
		//		Root = new Node<T>(value);
		//	}
		//}

		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.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
class Problem
{
    static void Main()
    {
        //--------------------------------input--------------------------------//

        var str = Array.ConvertAll( Console.ReadLine().Split(), Convert.ToInt32 );
        int n = str[0], h = str[1], m = str[2];
        var l = new int[m];
        var r = new int[m];
        var x = new int[m];
        for(int i = 0 ; i < m ; i++)
        {
            str = Array.ConvertAll( Console.ReadLine().Split(), Convert.ToInt32 );
            l[i] = str[0];
            r[i] = str[1];
            x[i] = str[2];
        }

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

        var houses = new int[n];
        for(int i = 0 ; i < n ; i++)
            houses[i] = h;
        for(int i = 0 ; i < m ; i++)
            for(int j = l[i]-1 ; j <= r[i]-1 ; j++)
                houses[j] = x[i];
        var kq = houses.Select( t => t * t ).ToList();
        Console.WriteLine( kq.Sum() );
    }
}


using System;
class Program
{
    static void Main()
    {
        int[] args = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int[] houses = new int[args[0]];
        int sum = 0;
        for (int i = 0; i < houses.Length; i++)
            houses[i] = args[1];
        for (int i = 0; i < args[2]; i++)
        {
            int[] m = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            for (int j = m[0]; j <= m[1]; j++)
                houses[j-1] = m[2];
        }
        for (int i = 0; i < houses.Length; i++)
            sum += houses[i] * houses[i];
        Console.WriteLine(sum);
    }
}


using System;
using System.Linq;
using CompLib.Util;
using System.Threading;
using CompLib.Mathematics;

public class Program
{
    int N;
    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        // 長さ2Nのかっこ列すべて
        // Trieの最大マッチング

        // 木
        // 2色に塗って少ない方

        // 頂点増え方
        // 以降>しか置けない

        // < >>>>>

        //    0 1 2 3
        // 0: 1
        // 1: 1 1 ... 1
        // 2: 2 2 1 ... 3
        // 3: 5 5 3 1
        // 4:

        var dp = new ModInt[N + 1][];
        for (int i = 0; i <= N; i++)
        {
            dp[i] = new ModInt[i + 1];
        }

        dp[0][0] = 1;
        for (int i = 0; i < N; i++)
        {
            ModInt tmp = 0;
            for (int j = i; j >= 0; j--)
            {
                tmp += dp[i][j];
                dp[i + 1][j + 1] = tmp;
            }
            dp[i + 1][0] = tmp;
        }

        //for (int i = 0; i <= N; i++)
        //{
        //    Console.WriteLine(string.Join(" ", dp[i]));
        //}
        ModInt ans = 0;
        for (int i = 1; i <= N; i++)
        {
            ans += dp[N][i];
        }

        Console.WriteLine(ans);
    }

    public static void Main(string[] args) => new Program().Solve();
    // public static void Main(string[] args) => new Thread(new Program().Solve, 1 << 27).Start();
}

// https://bitbucket.org/camypaper/complib
namespace CompLib.Mathematics
{
    #region ModInt
    /// <summary>
    /// [0,<see cref="Mod"/>) までの値を取るような数
    /// </summary>
    public struct ModInt
    {
        /// <summary>
        /// 剰余を取る値．
        /// </summary>
        public const long Mod = (int)1e9 + 7;
        // public const long Mod = 998244353;

        /// <summary>
        /// 実際の数値．
        /// </summary>
        public long num;
        /// <summary>
        /// 値が <paramref name="n"/> であるようなインスタンスを構築します．
        /// </summary>
        /// <param name="n">インスタンスが持つ値</param>
        /// <remarks>パフォーマンスの問題上，コンストラクタ内では剰余を取りません．そのため，<paramref name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/> を渡してください．このコンストラクタは O(1) で実行されます．</remarks>
        public ModInt(long n) { num = n; }
        /// <summary>
        /// このインスタンスの数値を文字列に変換します．
        /// </summary>
        /// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10 進表記したもの．</returns>
        public override string ToString() { return num.ToString(); }
        public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; }
        public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; }
        public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); }
        public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); }

        /// <summary>
        /// 与えられた 2 つの数値からべき剰余を計算します．
        /// </summary>
        /// <param name="v">べき乗の底</param>
        /// <param name="k">べき指数</param>
        /// <returns>繰り返し二乗法により O(N log N) で実行されます．</returns>
        public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }

        /// <summary>
        /// 与えられた 2 つの数値からべき剰余を計算します．
        /// </summary>
        /// <param name="v">べき乗の底</param>
        /// <param name="k">べき指数</param>
        /// <returns>繰り返し二乗法により O(N log N) で実行されます．</returns>
        public static ModInt Pow(long v, long k)
        {
            long ret = 1;
            for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
                if ((k & 1) == 1) ret = ret * v % Mod;
            return new ModInt(ret);
        }
        /// <summary>
        /// 与えられた数の逆元を計算します．
        /// </summary>
        /// <param name="v">逆元を取る対象となる数</param>
        /// <returns>逆元となるような値</returns>
        /// <remarks>法が素数であることを仮定して，フェルマーの小定理に従って逆元を O(log N) で計算します．</remarks>
        public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
    }
    #endregion
    #region Binomial Coefficient
    public class BinomialCoefficient
    {
        public ModInt[] fact, ifact;
        public BinomialCoefficient(int n)
        {
            fact = new ModInt[n + 1];
            ifact = new ModInt[n + 1];
            fact[0] = 1;
            for (int i = 1; i <= n; i++)
                fact[i] = fact[i - 1] * i;
            ifact[n] = ModInt.Inverse(fact[n]);
            for (int i = n - 1; i >= 0; i--)
                ifact[i] = ifact[i + 1] * (i + 1);
            ifact[0] = ifact[1];
        }
        public ModInt this[int n, int r]
        {
            get
            {
                if (n < 0 || n >= fact.Length || r < 0 || r > n) return 0;
                return fact[n] * ifact[n - r] * ifact[r];
            }
        }
        public ModInt RepeatedCombination(int n, int k)
        {
            if (k == 0) return 1;
            return this[n + k - 1, k];
        }
    }
    #endregion
}

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()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        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()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.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.Text;
using System.Threading.Tasks;

namespace ProbB
{
    class ProbC
    {

        private long m;
        private long ans = -1;

        public void ReadInput()
        {
            m = int.Parse(Console.ReadLine());
        }

        public long TestMiddle(long k)
        {
            long p = 2;
            long sum = 0;
            while (true)
            {
                long pow = p * p * p;
                if (k / pow == 0) return sum;
                sum += k / pow;
                if (sum >= k) return sum;
                p++;
            }
        }

        public void Solve()
        {

            long lowerBound = 8;
            long upperBound = 8 * m;

            while(upperBound>=lowerBound)
            {
                long middle = (lowerBound + upperBound) / 2;
                long sol = TestMiddle(middle);
                if (sol<m) lowerBound = middle + 1;
                else
                {
                    if (sol == m) ans = middle;
                    upperBound = middle - 1;
                }
            }
        }

        public void OutputResult()
        {
            Console.WriteLine(ans);
        }

        static void Main(string[] args)
        {

            ProbC p = new ProbC();
            p.ReadInput();
            p.Solve();
            p.OutputResult();

        }

    }
}


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

namespace c
{
    class Program
    {
        static void Main(string[] args)
        {
            int m = int.Parse(Console.ReadLine());
            int cnt = 0;
            int num = 7;
            while(cnt < m)
            {
                num++;
                for (int k = 2; k*k*k <= num; k++)
                {
                    if(num%(k * k * k)==0)
                    {
                        cnt++;
                    }
                }
            }
            if (cnt == m) Console.WriteLine(num);
            else Console.WriteLine(-1);
        }
    }
}


using System;
class Test {
    static void Main() {
        string [] str = Console.ReadLine().Split();
        int n = int.Parse(str[0]);
        int k = int.Parse(str[1]);
        int v = n/2;
        int len = n/2;
        int min = n;
        while(v!=0){
            int con = 0;
            int i = 0;
            while(true){
                int tmp = (int)(Math.Pow(k,i));
                if(v/tmp>0){
                    con += v/tmp;
                }else{
                    break;
                }
                i++;
            }
            if(con>=n){
                if(v<min){
                    min = v;
                }else{
                    break;
                }
                v -= len/2;
            }else{
                v += len/2;
            }
            len /= 2;
        }
        Console.WriteLine(min);
    }
}


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

namespace ConsoleApplication12
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            int n = int.Parse(s[0]);
            int k = int.Parse(s[1]);
            for(int i =1;i<int.MaxValue;i++)
            {
                if((i/k)*(i%k) ==n)
                {
                    Console.WriteLine(i);
                    break;
                }
            }
        }
    }
}


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

namespace CodilityToptal
{
    public class ToptalCodility
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(' ');
            var n = int.Parse(line[0]);
            var k = int.Parse(line[1]);
            Solve(n, k);
            //Solve(6, 3);
            //Solve(1, 2);
            //Solve(4, 6);
            //Solve(1000000,1000);
           //Solve(999983,1000);

        }

        public static void Solve(int n, int k)
        {
            long res = 0;
            var i = 1;
            while(true)
            {
                res = (i / k) * (i % k);
                if (res == n)
                {
                    Console.WriteLine(i);
                    return;
                }
                i++;
            }
        }

    }
}


using System;
using System.Text;

namespace ConsoleApplication1
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            var inputStrArr = Console.ReadLine().Split(' ');
            var n = int.Parse(inputStrArr[0]);
            var k = int.Parse(inputStrArr[1]);

            int i = k;
            while (true)
            {
                if (i / k * (i % k) == n)
                {
                    Console.WriteLine(i);
                    break;
                }

                i++;
            }

        }
    }
}


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

class Startup
{
    public static void Main()
    {
        List<int> liInput = ReadLineAndParseToList();
        int numberOfRows = liInput[0];
        int numberOfGroups = liInput[1];

        int oneSeat = 0;
        int twoSeats = numberOfRows * 2;
        int fourSeats = numberOfRows;

        List<int> liSoldiers = ReadLineAndParseToList();
        List<int> liLeft = new List<int> { 0, 0, 0 };

        bool blnOk = true;

        liSoldiers.Sort();
        liSoldiers.Reverse();

        for (int i = 0; i < liSoldiers.Count; i++)
        {
            while (liSoldiers[i]>=3 && blnOk)
            {
                if (fourSeats>0)
                {
                    liSoldiers[i] -= 4;
                    fourSeats--;
                }
                else if (twoSeats > 0)
                {
                    liSoldiers[i] -= 2;
                    twoSeats--;
                }
                else
                {
                    blnOk = false;
                }
            }

            if (blnOk)
            {
                liLeft[liSoldiers[i]]++;
            }
        }

        while(liLeft[2]>0 && blnOk)
        {
            if (twoSeats>0)
            {
                twoSeats--;
            }
            else if(fourSeats>0)
            {
                fourSeats--;
                oneSeat++;
            }
            else
            {
                liLeft[1] += 2;
            }
            liLeft[2]--;
        }

        if (liLeft[1] > oneSeat + twoSeats + fourSeats * 2)
        {
            blnOk = false;
        }
        Console.WriteLine("{0}",blnOk ? "YES":"NO");
    }

    public static List<int> ReadLineAndParseToList()
    {
        return Console.ReadLine().Split().Select(int.Parse).ToList();
    }
}


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

namespace codeforce
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, k, ost2, ost4, sum = 0; ;
            string s = Console.ReadLine();
            n = Convert.ToInt32(s.Split(new char[] { ' ' })[0]);
            k = Convert.ToInt32(s.Split(new char[] { ' ' })[1]);
            s = Console.ReadLine();
            ost2 = n * 2; ost4 = n;
            int[] a = new int[k];
            for (int i = 0; i < k; i++)
            {
                a[i] = Convert.ToInt32(s.Split(new char[] { ' ' })[i]);
                while (true)
                {
                    if ((a[i] == 1) || (a[i] == 0)) break;
                    if ((ost4 == 0) && (ost2 == 0)) break;
                    if ((a[i] >= 4) && (ost4 > 0)) { ost4--; a[i] -= 4; continue; }
                    if ((a[i] >= 2) && (ost2 > 0)) { ost2--; a[i] -= 2; continue; }
                }
                sum += a[i];
            }
            if ((ost4 == 0) && (ost2 == 0) && (sum == 0)) Console.WriteLine("YES");
            if ((ost4 > 0) || (ost2 > 0)) { if ((ost4 * 2 + ost2) >= sum) { Console.WriteLine("YES"); } else Console.WriteLine("NO"); }

        }
    }
}


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

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

        var n = RI();
        var k = RI();

        var c4 = n;
        var c2 = n + n;
        var c1 = 0;

        for (int i = 0; i < k; i++)
        {
            var a = RI();
            if (a % 2 == 1)
            {
                c1++;
                a -= (a & 1);
            }

            c4 -= a / 4;
            c2 -= (a % 4) / 2;
        }

        if (c4 < 0)
        {
            c2 -= Math.Abs(c4) * 2;
            c4 = 0;
        }

        if (c4 > 0)
        {
            c2 += c4;
            c1 -= c4;
            c4 = 0;
        }

        if (c1 > 0 && c2 > 0)
        {
            c1 -= c2;
            c2 = 0;
        }

        if (c2 < 0 && c1 < 0)
        {
            c1 += Math.Abs(c2) * 2;
            c2 = 0;
        }

        Console.WriteLine((c2 < 0 || c1 > 0) ? "NO" : "YES");
    }

    private const int Mod = 1000000000 + 7;

    #region Data Read

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

    private static List<int>[] ReadTree(int n)
    {
        return ReadGraph(n, n - 1);
    }

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

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

        return g;
    }

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

        return matrix;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        return s.ToArray();
    }

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

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

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

        return s;
    }

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

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

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

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

        return s.ToArray();
    }

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

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

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

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

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

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

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

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

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

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


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int result;
            int n = int.Parse(Console.ReadLine());
            int newNumber = (int)Math.Ceiling(Math.Sqrt(n));
            int fullLineNumber = n / newNumber;
            //int leftBlocksInLine = n % newNumber;
            if (newNumber*newNumber == n)
                result = newNumber * 4;
            else result = newNumber * 2 + fullLineNumber * 2 + 2;
            Console.WriteLine(result);
        }
    }
}


	using System;

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

            int prev = 8;

			if (n <= 0) { Console.WriteLine(0); return; }
            if (n == 1) { Console.WriteLine(4); return;}
			if (n == 2) { Console.WriteLine(6); return; }
			if (n == 3) { Console.WriteLine(8); return; }
			if (n == 4) { Console.WriteLine(8); return; }

            for (int i = 5; i <= n; i ++)
            {
                int c = (int)Math.Sqrt(i);

                if (i == c * c + 1)
                {
                    prev += 2;
                    continue;
                }

                if (i == c * (c + 1))
                {
                    prev += 2;
                    continue;
                }

            }

            Console.WriteLine(prev);
        }
    }


using System;

class Tanya{
	static void Main(){
		int n = Convert.ToInt32(Console.ReadLine());
		int k = Convert.ToInt32(Console.ReadLine());
		int A = Convert.ToInt32(Console.ReadLine());
		int B = Convert.ToInt32(Console.ReadLine());
		long mincoins = 0;
		int x = n;
		int costA;
		if (k == 1){
			mincoins = mincoins + (long) A*(x-1);
			Console.WriteLine(mincoins);
		}else if (n == 1){
			Console.WriteLine(mincoins);
		}else if (n > 1){
			while (x > 1){
				if (x % k == 0){
					costA = A*(x - (x/k));
					if (costA < B){
						if (x > k){
							x = x - k;
							mincoins = mincoins + (long)(A*k);
						}else{
							x = x - (k-1);
							mincoins = mincoins + (long)A*(k-1);
						}
					}else{
						x = x / k;
						mincoins = mincoins + B;
					}
				}else{
					if ((x - x%k) > 0){
						mincoins = mincoins + (long) A*(x%k);
						x = x - (x%k);
					}else{
						mincoins = mincoins + (long) A*((x%k)-1);
						x = x - ((x%k)-1);
					}
				}
			}
			Console.WriteLine(mincoins);
		}
	}
}