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

class Program
{
    class tutu:IComparable<tutu>
    {
        public int ind { get; set; }
        public int val { get; set; }
        public int CompareTo(tutu o)
        {
            return val.CompareTo(o.val);
        }
    }

    //////////////////////////////////////////////////
    void Solution()
    {
        var n = ri;
        var a = ria(n);
        var b = new tutu[n];
        for (int i = 0; i < n; i++)
        {
            b[i] = new tutu()
            {
                ind = i + 1,
                val = a[i]
            };
        }
        Array.Sort(b);
        for (int i = 0; i < n / 2; i++)
        {
            wln(b[i].ind + " " + b[n - 1 - i].ind);
        }
    }
    //////////////////////////////////////////////////

    static void swap(ref object o1, ref object o2) { var o = o1; o1 = o2; o2 = o; }
    static void wln(object o = null) { Console.WriteLine(o); }
    static void wsp(object o) { Console.Write(o + " "); }
    static void wrt(object o) { Console.Write(o); }
    //Console.Write(string.Format(CultureInfo.InvariantCulture, "{0:F12}", o));

    static long gcd(long a, long b) { return (b != 0) ? gcd(b, a % b) : a; }
    static long lcm(long a, long b) { return a / gcd(a, b) * b; }

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

    int[] ria(int n)
    {
        var res = new int[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                int p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    long[] rla(int n)
    {
        var res = new long[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                long p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    double[] rda(int n)
    {
        var res = new double[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                long p = 0, q = 1; while (i < m && s[i] != ' ' && s[i] != '.') p = p * 10 + s[i++] - '0';
                if (i < m && s[i] == '.') { ++i; while (i < m && s[i] != ' ') { p = p * 10 + s[i++] - '0'; q *= 10; } }
                res[k++] = (double)p / q * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    string[] rsa(int n) { var res = new string[n]; for (int k = 0; k < n; ++k) res[k] = Console.ReadLine(); _count = 0; _ind = 0; return res; }
    string _str = null; int _count = 0; int _ind = 0;
    void _read() { if (_ind == _count) { _str = Console.ReadLine(); _count = _str.Length; _ind = 0; } }
    static void Main() { new Program().Solution(); }
}


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

// (づ°ω°)づﾐ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    private const int MAX = 500000;

    public void Solve()
    {
        int n = ReadInt();
        int d = ReadInt();
        var a = ReadIntArray();

        var dp = new bool[MAX + 1];
        dp[0] = true;
        for (int i = 0; i < n; i++)
        {
            for (int j = MAX; j >= 0; j--)
                if (dp[j])
                    dp[j + a[i]] = true;
        }

        int x = 0;
        int ans = 0;
        while (true)
        {
            int y = Math.Min(x + d, MAX);
            while (!dp[y])
                y--;
            if (x == y)
                break;
            ans++;
            x = y;
        }

        Write(x, ans);
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;

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

    #endregion

    #region Read / Write

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

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

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

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

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

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

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

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

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

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

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

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

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

    public static void Write(params object[] array)
    {
        WriteArray(array);
    }

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

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

    #endregion
}


using System;
using System.IO;
class Program
{
    static void Main()
    {
        int n1, m1, n2, m2, res;
        string[] h = Console.ReadLine().Split(new char[] { ' ' });
        int n = int.Parse(h[0]);
        int m = int.Parse(h[1]);
        int k = int.Parse(h[2]);
        h = Console.ReadLine().Split(new char[] { ' ' });
        int A1 = int.Parse(h[0]);
        int A2 = int.Parse(h[1]);
        if (A1 % (m * k) == 0)
        {
            n1 = A1 / (m * k);
        }
        else
        {
            n1 = A1 / (m * k) + 1;
        }
        if ((A1 - (n1 - 1) * m * k) % k == 0)
        {
            m1 = (A1 - (n1 - 1) * m * k) / k;
        }
        else
        {
            m1 = (A1 - (n1 - 1) * m * k) / k + 1;
        }
        if (A2 % (m * k) == 0)
        {
            n2 = A2 / (m * k);
        }
        else
        {
            n2 = A2 / (m * k) + 1;
        }
        if ((A2 - (n2 - 1) * m * k) % k == 0)
        {
            m2 = (A2 - (n2 - 1) * m * k) / k;
        }
        else
        {
            m2 = (A2 - (n2 - 1) * m * k) / k + 1;
        }
        if (n1 == n2)
        {
            if (m1 == m2)
            {
                Console.WriteLine(0);
            }
            else
            {
                if (Math.Abs(m1 - m2) >= 3)
                {
                    Console.WriteLine(10 + Math.Abs(m1 - m2));
                }
                else
                {
                    Console.WriteLine(5 * Math.Abs(m1 - m2));
                }
            }
        }
        else
        {
            if (n1 < n2)
            {
                if (n2 - n1 < n - n2 + n1)
                {
                    if (m1 >= 4)
                    {
                        if (m2 >= 4)
                        {
                            Console.WriteLine(10 + m1 - 1 + (n2 - n1) * 15 + 10 + m2 - 1);
                        }
                        else
                        {
                            Console.WriteLine(10 + m1 - 1 + (n2 - n1) * 15 + 5 * (m2 - 1));
                        }
                    }
                    else
                    {
                        if (m2 >= 4)
                        {
                            Console.WriteLine(5 * (m1 - 1) + (n2 - n1) * 15 + 10 + m2 - 1);
                        }
                        else
                        {
                            Console.WriteLine(5 * (m1 - 1) + (n2 - n1) * 15 + 5 * (m2 - 1));
                        }
                    }

                }
                else
                {
                    if (m1 >= 4)
                    {
                        if (m2 >= 4)
                        {
                            Console.WriteLine(10 + m1 - 1 + (n - n2 + n1) * 15 + 10 + m2 - 1);
                        }
                        else
                        {
                            Console.WriteLine(10 + m1 - 1 + (n - n2 + n1) * 15 + 5 * (m2 - 1));
                        }
                    }
                    else
                    {
                        if (m2 >= 4)
                        {
                            Console.WriteLine(5 * (m1 - 1) + (n - n2 + n1) * 15 + 10 + m2 - 1);
                        }
                        else
                        {
                            Console.WriteLine(5 * (m1 - 1) + (n - n2 + n1) * 15 + 5 * (m2 - 1));
                        }
                    }
                }
            }
            else
            {
                if (n1 - n2 < n - n1 + n2)
                {
                    if (m1 >= 4)
                    {
                        if (m2 >= 4)
                        {
                            Console.WriteLine(10 + m1 - 1 + (n1 - n2) * 15 + 10 + m2 - 1);
                        }
                        else
                        {
                            Console.WriteLine(10 + m1 - 1 + (n1 - n2) * 15 + 5 * (m2 - 1));
                        }
                    }
                    else
                    {
                        if (m2 >= 4)
                        {
                            Console.WriteLine(5 * (m1 - 1) + (n1 - n2) * 15 + 10 + m2 - 1);
                        }
                        else
                        {
                            Console.WriteLine(5 * (m1 - 1) + (n1 - n2) * 15 + 5 * (m2 - 1));
                        }
                    }
                }
                else
                {
                    if (m1 >= 4)
                    {
                        if (m2 >= 4)
                        {
                            Console.WriteLine(10 + m1 - 1 + (n - n1 + n2) * 15 + 10 + m2 - 1);
                        }
                        else
                        {
                            Console.WriteLine(10 + m1 - 1 + (n - n1 + n2) * 15 + 5 * (m2 - 1));
                        }
                    }
                    else
                    {
                        if (m2 >= 4)
                        {
                            Console.WriteLine(5 * (m1 - 1) + (n - n1 + n2) * 15 + 10 + m2 - 1);
                        }
                        else
                        {
                            Console.WriteLine(5 * (m1 - 1) + (n - n1 + n2) * 15 + 5 * (m2 - 1));
                        }
                    }
                }
            }
        }
    }
}


using System;
using System.Linq;

namespace codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = "";
            for (int i = 0; i < 3; i++)
                str += Console.ReadLine();
            Console.WriteLine(Enumerable.Range(0,4).Count(x=>str[x]==str[8-x])==4?"YES":"NO");
        }
    }
}


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

namespace Codeforces.TaskD
{
    public class Task
    {
        private int d;
        private Point[] points;

        private double Distance(double l, int i)
        {
            // tg a1 = x/y
            // tg (alpha - a1) = (z-x)/y => z = x + y tg (alpha - a1)
            // tg (a+b) = (tg a + tg b)/(1 - tg a tg b)
            // z = x + y (tg alpha - x/y) / (1 + (x/y) tg alpha) = x + y (y tg alpha - x) / (y + x tg alpha) =
            // (xy + x2 tg + y2 tg - xy) / (y + x tg) = tg alpha (x2 + y2) / (y + x tg alpha)

            // tg a2 = -x/y
            // tg (alpha + a2) = (z-x)/y

            var p = points[i];
            var x = p.X - l;
            var y = p.Y;
            var tg = p.TgAlpha;

            if (x < 0)
            {
                var maxAlpha = Math.PI/2 - Math.Abs(Math.Atan2(x, y));
                if (p.Alpha >= maxAlpha) return d;
            }

            var denom = y + x*tg;
            if (denom == 0) return d;
            var z = l + Math.Abs(tg*(x*x + y*y)/denom);
            return Math.Min(d, z);
        }

        void Solve()
        {
            int n, l, r;
            Input.Next(out n, out l, out r);
            d = r - l;

            points = new Point[n];
            for (var i = 0; i < n; i++)
            {
                points[i] = new Point();
                Input.Next(out points[i].X, out points[i].Y, out points[i].Angle);
                points[i].X -= l;
                points[i].Alpha = points[i].Angle * Math.PI / 180;
                points[i].TgAlpha = Math.Tan(points[i].Alpha);
            }

            var dp = new double[1 << n << 1];
            for (var j = 0; j < 1<<n; j++)
                for (var i=0;i<n;i++)
                    if ((j & (1 << i)) == 0)
                        dp[j | (1 << i)] = Math.Max(dp[j | (1 << i)], Distance(dp[j], i));
            Console.Write(dp[(1<<n)-1].ToString("f9", CultureInfo.InvariantCulture));
        }

        public static void Main()
        {
            var task = new Task();
            #if DEBUG
            task.Solve();
            #else
            try
            {
                task.Solve();
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex);
            }
            #endif
        }
    }

    sealed class Point
    {
        public int X;
        public int Y;
        public int Angle;
        public double Alpha;
        public double TgAlpha;
    }
}

namespace Codeforces
{
    public class Input
    {
        private static string _line;

        public static bool Next()
        {
            _line = Console.ReadLine();
            return _line != null;
        }

        public static bool Next(out long a)
        {
            var ok = Next();
            a = ok ? long.Parse(_line) : 0;
            return ok;
        }

        public static bool Next(out long a, out long b)
        {
            var ok = Next();
            if (ok)
            {
                var array = _line.Split(' ').Select(long.Parse).ToArray();
                a = array[0];
                b = array[1];
            }
            else
            {
                a = b = 0;
            }

            return ok;
        }

        public static bool Next(out long a, out long b, out long c)
        {
            var ok = Next();
            if (ok)
            {
                var array = _line.Split(' ').Select(long.Parse).ToArray();
                a = array[0];
                b = array[1];
                c = array[2];
            }
            else
            {
                a = b = c = 0;
            }
            return ok;
        }

        public static bool Next(out long a, out long b, out long c, out long d)
        {
            var ok = Next();
            if (ok)
            {
                var array = _line.Split(' ').Select(long.Parse).ToArray();
                a = array[0];
                b = array[1];
                c = array[2];
                d = array[3];
            }
            else
            {
                a = b = c = d = 0;
            }
            return ok;
        }

        public static bool Next(out long a, out long b, out long c, out long d, out long e)
        {
            var ok = Next();
            if (ok)
            {
                var array = _line.Split(' ').Select(long.Parse).ToArray();
                a = array[0];
                b = array[1];
                c = array[2];
                d = array[3];
                e = array[4];
            }
            else
            {
                a = b = c = d = e = 0;
            }
            return ok;
        }

        public static bool Next(out int a)
        {
            var ok = Next();
            a = ok ? int.Parse(_line) : 0;
            return ok;
        }

        public static bool Next(out int a, out int b)
        {
            var ok = Next();
            if (ok)
            {
                var array = _line.Split(' ').Select(int.Parse).ToArray();
                a = array[0];
                b = array[1];
            }
            else
            {
                a = b = 0;
            }

            return ok;
        }

        public static bool Next(out int a, out int b, out int c)
        {
            var ok = Next();
            if (ok)
            {
                var array = _line.Split(' ').Select(int.Parse).ToArray();
                a = array[0];
                b = array[1];
                c = array[2];
            }
            else
            {
                a = b = c = 0;
            }
            return ok;
        }

        public static bool Next(out int a, out int b, out int c, out int d)
        {
            var ok = Next();
            if (ok)
            {
                var array = _line.Split(' ').Select(int.Parse).ToArray();
                a = array[0];
                b = array[1];
                c = array[2];
                d = array[3];
            }
            else
            {
                a = b = c = d = 0;
            }
            return ok;
        }

        public static bool Next(out int a, out int b, out int c, out int d, out int e)
        {
            var ok = Next();
            if (ok)
            {
                var array = _line.Split(' ').Select(int.Parse).ToArray();
                a = array[0];
                b = array[1];
                c = array[2];
                d = array[3];
                e = array[4];
            }
            else
            {
                a = b = c = d = e = 0;
            }
            return ok;
        }

        public static bool Next(out int a, out int b, out int c, out int d, out int e, out int f)
        {
            var ok = Next();
            if (ok)
            {
                var array = _line.Split(' ').Select(int.Parse).ToArray();
                a = array[0];
                b = array[1];
                c = array[2];
                d = array[3];
                e = array[4];
                f = array[5];
            }
            else
            {
                a = b = c = d = e = f = 0;
            }
            return ok;
        }

        public static IEnumerable<long> ArrayLong()
        {
            return !Next() ? new List<long>() : _line.Split().Select(long.Parse);
        }

        public static IEnumerable<int> ArrayInt()
        {
            return !Next() ? new List<int>() : _line.Split().Select(int.Parse);
        }

        public static bool Next(out string value)
        {
            value = string.Empty;
            if (!Next()) return false;
            value = _line;
            return true;
        }
    }

    public class DisjointSet
    {
        private readonly int[] _parent;
        private readonly int[] _rank;
        public int Count { get; private set; }

        public DisjointSet(int count, int initialize = 0)
        {
            Count = count;
            _parent = new int[Count];
            _rank = new int[Count];
            for (var i = 0; i < initialize; i++) _parent[i] = i;
        }

        private DisjointSet(int count, int[] parent, int[] rank)
        {
            Count = count;
            _parent = parent;
            _rank = rank;
        }

        public void Add(int v)
        {
            _parent[v] = v;
            _rank[v] = 0;
        }

        public int Find_Recursive(int v)
        {
            if (_parent[v] == v) return v;
            return _parent[v] = Find(_parent[v]);
        }

        public int Find(int v)
        {
            if (_parent[v] == v) return v;
            var last = v;
            while (_parent[last] != last) last = _parent[last];
            while (_parent[v] != v)
            {
                var t = _parent[v];
                _parent[v] = last;
                v = t;
            }
            return last;
        }

        public int this[int v]
        {
            get { return Find(v); }
            set { Union(v, value); }
        }

        public void Union(int a, int b)
        {
            a = Find(a);
            b = Find(b);
            if (a == b) return;
            if (_rank[a] < _rank[b])
            {
                var t = _rank[a];
                _rank[a] = _rank[b];
                _rank[b] = t;
            }
            _parent[b] = a;
            if (_rank[a] == _rank[b]) _rank[a]++;
        }

        public int GetSetCount()
        {
            var result = 0;
            for (var i = 0; i < Count; i++)
            {
                if (_parent[i] == i) result++;
            }
            return result;
        }

        public DisjointSet Clone()
        {
            var rank = new int[Count];
            _rank.CopyTo(rank, 0);
            var parent = new int[Count];
            _parent.CopyTo(parent, 0);
            return new DisjointSet(Count, parent, rank);
        }

        public override string ToString()
        {
            return string.Join(",", _parent.Take(50));
        }
    }

    public class Matrix
    {
        public static Matrix Create(int i, int j)
        {
            var m = new Matrix(i, j);
            return m;
        }

        public static Matrix Create(int i)
        {
            var m = new Matrix(i, i);
            return m;
        }

        public long Modulo { get; set; }

        private readonly int _width;
        private readonly int _height;
        private readonly long[,] _data;
        public int Width { get { return _width; } }
        public int Height { get { return _height; } }

        private Matrix(int i, int j)
        {
            Modulo = 1000000000000000000L;
            _width = j;
            _height = i;
            _data = new long[_height, _width];
        }

        public static Matrix operator *(Matrix m1, Matrix m2)
        {
            if (m1.Width != m2.Height) throw new InvalidDataException("m1.Width != m2.Height");
            var m = Create(m2.Width, m1.Height);
            m.Modulo = m1.Modulo;
            for (var i = 0; i < m2.Width; i++)
                for (var j = 0; j < m1.Height; j++)
                {
                    for (var k = 0; k < m1.Width; k++)
                        m[j, i] += (m1[j, k] * m2[k, i]) % m1.Modulo;
                    m[j, i] %= m1.Modulo;
                }
            return m;
        }

        public static Matrix operator +(Matrix m1, Matrix m2)
        {
            var m = m1.Clone();
            for (var i = 0; i < m2.Width; i++)
                for (var j = 0; j < m1.Height; j++)
                    m[j, i] = (m[j, i] + m2[j, i]) % m1.Modulo;
            return m;
        }

        public static Matrix operator -(Matrix m1, Matrix m2)
        {
            var m = m1.Clone();
            for (var i = 0; i < m2.Width; i++)
                for (var j = 0; j < m1.Height; j++)
                    m[j, i] = (m[j, i] - m2[j, i]) % m1.Modulo;
            return m;
        }

        public static Matrix operator *(Matrix m1, long l)
        {
            var m = m1.Clone();
            for (var i = 0; i < m1.Width; i++)
                for (var j = 0; j < m1.Height; j++)
                    m[j, i] = (m[j, i] * l) % m.Modulo;
            return m;
        }

        public static Matrix operator *(long l, Matrix m1)
        {
            return m1 * l;
        }

        public static Matrix operator +(Matrix m1, long l)
        {
            var m = m1.Clone();
            for (var i = 0; i < m1.Width; i++)
                m[i, i] = (m[i, i] + l) % m.Modulo;
            return m;
        }

        public static Matrix operator +(long l, Matrix m1)
        {
            return m1 + l;
        }

        public static Matrix operator -(Matrix m1, long l)
        {
            return m1 + (-l);
        }

        public static Matrix operator -(long l, Matrix m1)
        {
            var m = m1.Clone() * -1;
            return m + l;
        }

        public Matrix BinPower(long l)
        {
            var n = 1;
            var m = Clone();
            var result = new Matrix(m.Height, m.Width) + 1;
            result.Modulo = m.Modulo;
            while (l != 0)
            {
                var i = l & ~(l - 1);
                l -= i;
                while (n < i)
                {
                    m = m * m;
                    n <<= 1;
                }
                result *= m;
            }
            return result;
        }

        public void Fill(long l)
        {
            l %= Modulo;
            for (var i = 0; i < _height; i++)
                for (var j = 0; j < _width; j++)
                    _data[i, j] = l;
        }

        public Matrix Clone()
        {
            var m = new Matrix(_width, _height);
            Array.Copy(_data, m._data, _data.Length);
            m.Modulo = Modulo;
            return m;
        }

        public long this[int i, int j]
        {
            get { return _data[i, j]; }
            set { _data[i, j] = value % Modulo; }
        }
    }

    public class RedBlackTree<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>
    {
        private readonly List<Node> _items;
        private Node _root;
        private readonly IComparer<TKey> _comparer;

        public RedBlackTree(int capacity = 10)
        {
            _items = new List<Node>(capacity);
            _comparer = Comparer<TKey>.Default;
        }

        private Node _search(TKey key)
        {
            var node = _root;
            while (node != null)
            {
                var i = _comparer.Compare(key, node.Key);
                if (i == 0) return node;
                node = i > 0 ? node.Right : node.Left;
            }
            return null;
        }

        /// <summary>
        /// Returns lower or equal key
        /// </summary>
        public TKey Lower(TKey key, TKey notFound = default(TKey))
        {
            var node = _root;
            Node good = null;
            while (node != null)
            {
                var i = _comparer.Compare(key, node.Key);
                if (i == 0) return key;
                if (i > 0)
                {
                    good = node;
                    node = node.Right;
                }
                else
                    node = node.Left;
            }
            return good == null ? notFound : good.Key;
        }

        /// <summary>
        /// Returns higher or equal key
        /// </summary>
        public TKey Higher(TKey key, TKey notFound = default(TKey))
        {
            var node = _root;
            Node good = null;
            while (node != null)
            {
                var i = _comparer.Compare(key, node.Key);
                if (i == 0) return key;
                if (i < 0)
                {
                    good = node;
                    node = node.Left;
                }
                else
                    node = node.Right;
            }
            return good == null ? notFound : good.Key;
        }

        /// <summary>
        /// Returns minimum region, which encloses given key
        /// </summary>
        public Tuple<TKey, TKey> Bounds(TKey key, TKey notFound = default(TKey))
        {
            var node = _root;
            Node lower = null;
            Node higher = null;
            while (node != null)
            {
                var i = _comparer.Compare(key, node.Key);
                if (i == 0) return new Tuple<TKey, TKey>(key, key);
                if (i < 0)
                {
                    higher = node;
                    node = node.Left;
                }
                else
                {
                    lower = node;
                    node = node.Right;
                }
            }
            return new Tuple<TKey, TKey>(lower == null ? notFound : lower.Key, higher == null ? notFound : higher.Key);
        }

        public void Add(TKey key, TValue value)
        {
            var node = new Node { Key = key, Value = value, Red = true };
            _items.Add(node);
            if (_root == null)
            {
                _root = node;
                _root.Red = false;
                return;
            }
            var x = _root;
            Node y = null;
            while (x != null)
            {
                y = x;
                x = _comparer.Compare(key, x.Key) > 0 ? x.Right : x.Left;
            }
            node.Parent = y;
            if (y == null) _root = node;
            else if (_comparer.Compare(key, y.Key) > 0) y.Right = node;
            else y.Left = node;
            InsertFixup(node);
        }

        private void InsertFixup(Node node)
        {
            while (true)
            {
                var parent = node.Parent;
                if (parent == null || !parent.Red || parent.Parent == null) break;
                var grand = parent.Parent;

                if (parent == grand.Left)
                {
                    var uncle = grand.Right;
                    if (uncle != null && uncle.Red) /* parent and uncle both red: we could swap colors of them with grand */
                    {
                        parent.Red = false;
                        uncle.Red = false;
                        grand.Red = true;
                        node = grand; /* and continue fixing tree for grand */
                    }
                    else if (node == parent.Right) /* we rotate around the parent */
                    {
                        node = parent;
                        RotateLeft(node);
                    }
                    else /* rotate around grand and switch colors of grand and parent */
                    {
                        parent.Red = false;
                        grand.Red = true;
                        RotateRight(grand);
                        if (grand == _root) _root = parent;
                        break; /* and finish since tree is fixed */
                    }
                }
                else
                {
                    if (_root.Parent != null) Debugger.Break();

                    var uncle = grand.Left;
                    if (uncle != null && uncle.Red) /* parent and uncle both red: we could swap colors of them with grand */
                    {
                        parent.Red = false;
                        uncle.Red = false;
                        grand.Red = true;
                        node = grand; /* and continue fixing tree for grand */
                    }
                    else if (node == parent.Left) /* we rotate around the parent */
                    {
                        node = parent;
                        RotateRight(node);
                    }
                    else /* rotate around grand and switch colors of grand and parent */
                    {
                        parent.Red = false;
                        grand.Red = true;
                        RotateLeft(grand);
                        if (grand == _root) _root = parent;
                        break; /* and finish since tree is fixed */
                    }
                }
            }
            _root.Red = false;
        }

        private void RotateLeft(Node node)
        {
            if (node.Right == null)
                throw new NotSupportedException("Cannot rotate left: right node is missing");
            var parent = node.Parent;
            var right = node.Right;
            right.Parent = parent;
            if (parent != null)
            {
                if (parent.Left == node) parent.Left = right;
                else parent.Right = right;
            }
            node.Right = right.Left;
            if (node.Right != null)
                node.Right.Parent = node;
            right.Left = node;
            node.Parent = right;
        }

        private void RotateRight(Node node)
        {
            if (node.Left == null)
                throw new NotSupportedException("Cannot rotate right: left node is missing");
            var parent = node.Parent;
            var left = node.Left;
            left.Parent = parent;
            if (parent != null)
            {
                if (parent.Left == node) parent.Left = left;
                else parent.Right = left;
            }
            node.Left = left.Right;
            if (node.Left != null)
                node.Left.Parent = node;
            left.Right = node;
            node.Parent = left;
        }

        public void Remove(TKey key)
        {
            var node = _search(key);
            if (node == null) return;

            var deleted = node.Left == null || node.Right == null ? node : Next(node);
            var child = deleted.Left ?? deleted.Right;
            if (child != null)
                child.Parent = deleted.Parent;
            if (deleted.Parent == null) /* root */
                _root = child;
            else if (deleted == deleted.Parent.Left)
                deleted.Parent.Left = child;
            else
                deleted.Parent.Right = child;
            if (node != deleted)
            {
                node.Key = deleted.Key;
                node.Value = deleted.Value;
            }

            if (!deleted.Red)
            {
                DeleteFixup(child, deleted.Parent);
            }
        }

        private void DeleteFixup(Node node, Node parent)
        {
            while (parent != null && (node == null || !node.Red))
            {
                if (node == parent.Left)
                {
                    var brother = parent.Right;
                    if (brother.Red)
                    {
                        brother.Red = false;
                        parent.Red = true;
                        RotateLeft(parent);
                        brother = parent.Right;
                    }
                    if ((brother.Left == null || !brother.Left.Red) && (brother.Right == null || !brother.Right.Red))
                    {
                        node = parent.Red ? _root : parent;
                        brother.Red = true;
                        parent.Red = false;
                    }
                    else
                    {
                        if (brother.Right == null || !brother.Right.Red)
                        {
                            if (brother.Left != null)
                                brother.Left.Red = false;
                            brother.Red = true;
                            RotateRight(brother);
                            brother = parent.Right;
                        }
                        if (!brother.Right.Red) Debugger.Break();
                        brother.Red = parent.Red;
                        parent.Red = false;
                        if (brother.Right != null)
                            brother.Right.Red = false;
                        RotateLeft(parent);
                        node = _root;
                    }
                }
                else
                {
                    var brother = parent.Left;
                    if (brother.Red)
                    {
                        brother.Red = false;
                        parent.Red = true;
                        RotateRight(parent);
                        brother = parent.Left;
                    }
                    if ((brother.Right == null || !brother.Right.Red) && (brother.Left == null || !brother.Left.Red))
                    {
                        node = parent.Red ? _root : parent;
                        brother.Red = true;
                        parent.Red = false;
                    }
                    else
                    {
                        if (brother.Left == null || !brother.Left.Red)
                        {
                            if (brother.Right != null)
                                brother.Right.Red = false;
                            brother.Red = true;
                            RotateLeft(brother);
                            brother = parent.Left;
                        }
                        brother.Red = parent.Red;
                        parent.Red = false;
                        if (brother.Left != null)
                            brother.Left.Red = false;
                        RotateRight(parent);
                        node = _root;
                    }
                }
                parent = node.Parent;
            }

            node.Red = false;
        }

        public TValue this[TKey key]
        {
            get
            {
                var node = _search(key);
                return node == null ? default(TValue) : node.Value;
            }
            set
            {
                var node = _search(key);
                if (node == null) Add(key, value);
                else node.Value = value;
            }
        }

        public bool Check()
        {
            int count;
            return _root == null || _root.Check(out count);
        }

        private Node Minimum(Node node)
        {
            var result = node;
            while (result.Left != null) result = result.Left;
            return result;
        }

        private Node Maximum(Node node)
        {
            var result = node;
            while (result.Right != null) result = result.Right;
            return result;
        }

        private Node Next(Node node)
        {
            Node result;
            if (node.Right != null)
            {
                result = Minimum(node.Right);
            }
            else
            {
                while (node.Parent != null && node.Parent.Right == node)
                    node = node.Parent;
                result = node.Parent;
            }
            return result;
        }

        private Node Previous(Node node)
        {
            Node result;
            if (node.Left != null)
            {
                result = Maximum(node.Left);
            }
            else
            {
                while (node.Parent != null && node.Parent.Left == node)
                    node = node.Parent;
                result = node.Parent;
            }
            return result;
        }

        public void Print()
        {
            var node = Minimum(_root);
            while (node != null)
            {
                Console.Write(node.Red ? '*' : ' ');
                Console.Write(node.Key);
                Console.Write('\t');
                node = Next(node);
            }
        }

        #region Nested classes

        [DebuggerDisplay("{ToString()}")]
        private sealed class Node
        {
            public TKey Key;
            public TValue Value;
            public bool Red;

            public Node Parent;
            public Node Left;
            public Node Right;

            public bool Check(out int count)
            {
                count = 0;
                if (Red)
                {
                    if (Left != null && Left.Red) return false;
                    if (Right != null && Right.Red) return false;
                }
                var left = 0;
                var right = 0;
                if (Left != null && !Left.Check(out left)) return false;
                if (Right != null && !Right.Check(out right)) return false;
                count = left + (Red ? 0 : 1);
                if (left != right)
                {
                    ;
                }
                return left == right;
            }

            public override string ToString()
            {
                return ToShortString(2);
            }

            private string ToShortString(int depth = 0)
            {
                return depth == 0
                    ? string.Format("{0}{1}", Red ? "*" : "", Key)
                    : string.Format("({1}<{0}>{2})", ToShortString(), Left == null ? "null" : Left.ToShortString(depth - 1), Right == null ? "null" : Right.ToShortString(depth - 1));
            }
        }

        #endregion

        #region IEnumerable

        public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
        {
            throw new NotImplementedException();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        #endregion
    }

    public class RedBlackTreeSimple<TKey>
    {
        private readonly List<Node> _items;
        private Node _root;
        private readonly IComparer<TKey> _comparer;

        public RedBlackTreeSimple(int capacity = 10)
        {
            _items = new List<Node>(capacity);
            _comparer = Comparer<TKey>.Default;
        }

        private Node _search(TKey key)
        {
            var node = _root;
            while (node != null)
            {
                var i = _comparer.Compare(key, node.Key);
                if (i == 0) return node;
                node = i > 0 ? node.Right : node.Left;
            }
            return null;
        }

        /// <summary>
        /// Returns lower or equal key
        /// </summary>
        public TKey Lower(TKey key, TKey notFound = default(TKey))
        {
            var node = _root;
            Node good = null;
            while (node != null)
            {
                var i = _comparer.Compare(key, node.Key);
                if (i == 0) return key;
                if (i > 0)
                {
                    good = node;
                    node = node.Right;
                }
                else
                    node = node.Left;
            }
            return good == null ? notFound : good.Key;
        }

        /// <summary>
        /// Returns higher or equal key
        /// </summary>
        public TKey Higher(TKey key, TKey notFound = default(TKey))
        {
            var node = _root;
            Node good = null;
            while (node != null)
            {
                var i = _comparer.Compare(key, node.Key);
                if (i == 0) return key;
                if (i < 0)
                {
                    good = node;
                    node = node.Left;
                }
                else
                    node = node.Right;
            }
            return good == null ? notFound : good.Key;
        }

        /// <summary>
        /// Returns minimum region, which encloses given key
        /// </summary>
        public Tuple<TKey, TKey> Bounds(TKey key, TKey notFound = default(TKey))
        {
            var node = _root;
            Node lower = null;
            Node higher = null;
            while (node != null)
            {
                var i = _comparer.Compare(key, node.Key);
                if (i == 0) return new Tuple<TKey, TKey>(key, key);
                if (i < 0)
                {
                    higher = node;
                    node = node.Left;
                }
                else
                {
                    lower = node;
                    node = node.Right;
                }
            }
            return new Tuple<TKey, TKey>(lower == null ? notFound : lower.Key, higher == null ? notFound : higher.Key);
        }

        public void Add(TKey key)
        {
            var node = new Node(key);
            _items.Add(node);
            if (_root == null)
            {
                _root = node;
                _root.Red = false;
                return;
            }
            var x = _root;
            Node y = null;
            while (x != null)
            {
                y = x;
                x = _comparer.Compare(key, x.Key) > 0 ? x.Right : x.Left;
            }
            node.Parent = y;
            if (y == null) _root = node;
            else if (_comparer.Compare(key, y.Key) > 0) y.Right = node;
            else y.Left = node;
            InsertFixup(node);
        }

        private void InsertFixup(Node node)
        {
            while (true)
            {
                var parent = node.Parent;
                if (parent == null || !parent.Red || parent.Parent == null) break;
                var grand = parent.Parent;

                if (parent == grand.Left)
                {
                    var uncle = grand.Right;
                    if (uncle != null && uncle.Red) /* parent and uncle both red: we could swap colors of them with grand */
                    {
                        parent.Red = false;
                        uncle.Red = false;
                        grand.Red = true;
                        node = grand; /* and continue fixing tree for grand */
                    }
                    else if (node == parent.Right) /* we rotate around the parent */
                    {
                        node = parent;
                        RotateLeft(node);
                    }
                    else /* rotate around grand and switch colors of grand and parent */
                    {
                        parent.Red = false;
                        grand.Red = true;
                        RotateRight(grand);
                        if (grand == _root) _root = parent;
                        break; /* and finish since tree is fixed */
                    }
                }
                else
                {
                    if (_root.Parent != null) Debugger.Break();

                    var uncle = grand.Left;
                    if (uncle != null && uncle.Red) /* parent and uncle both red: we could swap colors of them with grand */
                    {
                        parent.Red = false;
                        uncle.Red = false;
                        grand.Red = true;
                        node = grand; /* and continue fixing tree for grand */
                    }
                    else if (node == parent.Left) /* we rotate around the parent */
                    {
                        node = parent;
                        RotateRight(node);
                    }
                    else /* rotate around grand and switch colors of grand and parent */
                    {
                        parent.Red = false;
                        grand.Red = true;
                        RotateLeft(grand);
                        if (grand == _root) _root = parent;
                        break; /* and finish since tree is fixed */
                    }
                }
            }
            _root.Red = false;
        }

        private void RotateLeft(Node node)
        {
            if (node.Right == null)
                throw new NotSupportedException("Cannot rotate left: right node is missing");
            var parent = node.Parent;
            var right = node.Right;
            right.Parent = parent;
            if (parent != null)
            {
                if (parent.Left == node) parent.Left = right;
                else parent.Right = right;
            }
            node.Right = right.Left;
            if (node.Right != null)
                node.Right.Parent = node;
            right.Left = node;
            node.Parent = right;
        }

        private void RotateRight(Node node)
        {
            if (node.Left == null)
                throw new NotSupportedException("Cannot rotate right: left node is missing");
            var parent = node.Parent;
            var left = node.Left;
            left.Parent = parent;
            if (parent != null)
            {
                if (parent.Left == node) parent.Left = left;
                else parent.Right = left;
            }
            node.Left = left.Right;
            if (node.Left != null)
                node.Left.Parent = node;
            left.Right = node;
            node.Parent = left;
        }

        public void Remove(TKey key)
        {
            var node = _search(key);
            if (node == null) return;

            var deleted = node.Left == null || node.Right == null ? node : Next(node);
            var child = deleted.Left ?? deleted.Right;
            if (child != null)
                child.Parent = deleted.Parent;
            if (deleted.Parent == null) /* root */
                _root = child;
            else if (deleted == deleted.Parent.Left)
                deleted.Parent.Left = child;
            else
                deleted.Parent.Right = child;
            if (node != deleted)
            {
                node.Key = deleted.Key;
            }

            if (!deleted.Red)
            {
                DeleteFixup(child, deleted.Parent);
            }
        }

        private void DeleteFixup(Node node, Node parent)
        {
            while (parent != null && (node == null || !node.Red))
            {
                if (node == parent.Left)
                {
                    var brother = parent.Right;
                    if (brother.Red)
                    {
                        brother.Red = false;
                        parent.Red = true;
                        RotateLeft(parent);
                        brother = parent.Right;
                    }
                    if ((brother.Left == null || !brother.Left.Red) && (brother.Right == null || !brother.Right.Red))
                    {
                        node = parent.Red ? _root : parent;
                        brother.Red = true;
                        parent.Red = false;
                    }
                    else
                    {
                        if (brother.Right == null || !brother.Right.Red)
                        {
                            if (brother.Left != null)
                                brother.Left.Red = false;
                            brother.Red = true;
                            RotateRight(brother);
                            brother = parent.Right;
                        }
                        if (!brother.Right.Red) Debugger.Break();
                        brother.Red = parent.Red;
                        parent.Red = false;
                        if (brother.Right != null)
                            brother.Right.Red = false;
                        RotateLeft(parent);
                        node = _root;
                    }
                }
                else
                {
                    var brother = parent.Left;
                    if (brother.Red)
                    {
                        brother.Red = false;
                        parent.Red = true;
                        RotateRight(parent);
                        brother = parent.Left;
                    }
                    if ((brother.Right == null || !brother.Right.Red) && (brother.Left == null || !brother.Left.Red))
                    {
                        node = parent.Red ? _root : parent;
                        brother.Red = true;
                        parent.Red = false;
                    }
                    else
                    {
                        if (brother.Left == null || !brother.Left.Red)
                        {
                            if (brother.Right != null)
                                brother.Right.Red = false;
                            brother.Red = true;
                            RotateLeft(brother);
                            brother = parent.Left;
                        }
                        brother.Red = parent.Red;
                        parent.Red = false;
                        if (brother.Left != null)
                            brother.Left.Red = false;
                        RotateRight(parent);
                        node = _root;
                    }
                }
                parent = node.Parent;
            }

            node.Red = false;
        }

        private Node Minimum(Node node)
        {
            var result = node;
            while (result.Left != null) result = result.Left;
            return result;
        }

        private Node Maximum(Node node)
        {
            var result = node;
            while (result.Right != null) result = result.Right;
            return result;
        }

        private Node Next(Node node)
        {
            Node result;
            if (node.Right != null)
            {
                result = Minimum(node.Right);
            }
            else
            {
                while (node.Parent != null && node.Parent.Right == node)
                    node = node.Parent;
                result = node.Parent;
            }
            return result;
        }

        private Node Previous(Node node)
        {
            Node result;
            if (node.Left != null)
            {
                result = Maximum(node.Left);
            }
            else
            {
                while (node.Parent != null && node.Parent.Left == node)
                    node = node.Parent;
                result = node.Parent;
            }
            return result;
        }

        public void Print()
        {
            var node = Minimum(_root);
            while (node != null)
            {
                Console.Write(node.Red ? '*' : ' ');
                Console.Write(node.Key);
                Console.Write('\t');
                node = Next(node);
            }
        }

        #region Nested classes

        private sealed class Node
        {
            public Node(TKey key)
            {
                Key = key;
            }

            public TKey Key;
            public bool Red = true;

            public Node Parent;
            public Node Left;
            public Node Right;
        }

        #endregion
    }

    /// <summary>
    /// Fenwick tree for summary on the array
    /// </summary>
    public class FenwickSum
    {
        public readonly int Size;
        private readonly int[] _items;
        public FenwickSum(int size)
        {
            Size = size;
            _items = new int[Size];
        }

        public FenwickSum(IList<int> items)
            : this(items.Count)
        {
            for (var i = 0; i < Size; i++)
                Increase(i, items[i]);
        }

        private int Sum(int r)
        {
            if (r < 0) return 0;
            if (r >= Size) r = Size - 1;
            var result = 0;
            for (; r >= 0; r = (r & (r + 1)) - 1)
                result += _items[r];
            return result;
        }

        private int Sum(int l, int r)
        {
            return Sum(r) - Sum(l - 1);
        }

        public int this[int r]
        {
            get { return Sum(r); }
        }

        public int this[int l, int r]
        {
            get { return Sum(l, r); }
        }

        public void Increase(int i, int delta)
        {
            for (; i < Size; i = i | (i + 1))
                _items[i] += delta;
        }
    }

    /// <summary>
    /// Prime numbers
    /// </summary>
    public class Primes
    {
        /// <summary>
        /// Returns prime numbers in O(n)
        /// Returns lowet divisors as well
        /// Memory O(n)
        /// </summary>
        public static void ImprovedSieveOfEratosthenes(int n, out int[] lp, out List<int> pr)
        {
            lp = new int[n];
            pr = new List<int>();
            for (var i = 2; i < n; i++)
            {
                if (lp[i] == 0)
                {
                    lp[i] = i;
                    pr.Add(i);
                }
                foreach (var prJ in pr)
                {
                    var prIj = i * prJ;
                    if (prJ <= lp[i] && prIj <= n - 1)
                    {
                        lp[prIj] = prJ;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }

        /// <summary>
        /// Returns prime numbers in O(n*n)
        /// </summary>
        public static void SieveOfEratosthenes(int n, out List<int> pr)
        {
            var m = 2 * n / 5;
            pr = new List<int> { 2 };
            var f = new bool[n + 1];
            for (var i = 3; i <= m; i += 2)
                if (!f[i])
                    for (long j = (long)i * i; j <= n; j += i)
                        f[j] = true;
            for (var i = 3; i <= n; i += 2)
                if (!f[i])
                    pr.Add(i);
        }

        /// <summary>
        /// Returns array of inverted prime numbers map in O(n*n)
        /// </summary>
        public static void SieveOfEratosthenes(int n, out bool[] isPrime)
        {
            var m = 2 * n / 5;
            var f = new bool[n + 1];
            for (var i = 3; i <= m; i += 2)
                if (!f[i])
                    for (long j = (long)i * i; j <= n; j += i)
                        f[j] = true;
            isPrime = f;
        }

        /// <summary>
        /// Greatest common divisor
        /// </summary>
        public static int Gcd(int x, int y)
        {
            while (y != 0)
            {
                var c = y;
                y = x % y;
                x = c;
            }
            return x;
        }

        /// <summary>
        /// Greatest common divisor
        /// </summary>
        public static long Gcd(long x, long y)
        {
            while (y != 0)
            {
                var c = y;
                y = x % y;
                x = c;
            }
            return x;
        }

        /// <summary>
        /// Greatest common divisor
        /// </summary>
        public static BigInteger Gcd(BigInteger x, BigInteger y)
        {
            while (y != 0)
            {
                var c = y;
                y = x % y;
                x = c;
            }
            return x;
        }

        /// <summary>
        /// Returns all divisors of n in O(√n)
        /// </summary>
        public static IEnumerable<long> GetDivisors(long n)
        {
            long r;
            while (true)
            {
                var x = Math.DivRem(n, 2, out r);
                if (r != 0) break;
                n = x;
                yield return 2;
            }
            var i = 3;
            while (i <= Math.Sqrt(n))
            {
                var x = Math.DivRem(n, i, out r);
                if (r == 0)
                {
                    n = x;
                    yield return i;
                }
                else i += 2;
            }
            if (n != 1) yield return n;
        }
    }

    /// <summary>
    /// Graph matching algorithms
    /// </summary>
    public class GraphMatching
    {
        #region Kuhn algorithm

        /// <summary>
        /// Kuhn algorithm for finding maximal matching
        /// in bipartite graph
        /// Vertexes are numerated from zero: 0, 1, 2, ... n-1
        /// Return array of matchings
        /// </summary>
        public static int[] Kuhn(List<int>[] g, int leftSize, int rightSize)
        {
            Debug.Assert(g.Count() == leftSize);

            var matching = new int[leftSize];
            for (var i = 0; i < rightSize; i++)
                matching[i] = -1;
            var used = new bool[leftSize];

            for (var v = 0; v < leftSize; v++)
            {
                Array.Clear(used, 0, leftSize);
                _kuhn_dfs(v, g, matching, used);
            }

            return matching;
        }

        private static bool _kuhn_dfs(int v, List<int>[] g, int[] matching, bool[] used)
        {
            if (used[v]) return false;
            used[v] = true;
            for (var i = 0; i < g[v].Count; i++)
            {
                var to = g[v][i];
                if (matching[to] == -1 || _kuhn_dfs(matching[to], g, matching, used))
                {
                    matching[to] = v;
                    return true;
                }
            }
            return false;
        }

        #endregion
    }
}


using System;

namespace HighSchool
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            double x = double.Parse(s[0]);
            double y = double.Parse(s[1]);

            double logx = Math.Log10(x);
            double logy = Math.Log10(y);

            double y_logx = y * logx;
            double x_logy = x * logy;

            if (y_logx > x_logy)
            {
                Console.Write(">");
            }
            else
            {
                if (y_logx < x_logy)
                    Console.Write("<");
                else
                    Console.Write("=");
            }
        }
    }
}


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

namespace Test
{
    class IOHelper : IDisposable
    {
        StreamReader reader;
        StreamWriter writer;

        public IOHelper(string inputFile, string outputFile, Encoding encoding)
        {
            StreamReader iReader;
            StreamWriter oWriter;
            if (inputFile == null)
                iReader = new StreamReader(Console.OpenStandardInput(), encoding);
            else
                iReader = new StreamReader(inputFile, encoding);

            if (outputFile == null)
                oWriter = new StreamWriter(Console.OpenStandardOutput(), encoding);
            else
                oWriter = new StreamWriter(outputFile, false, encoding);

            reader = iReader;
            writer = oWriter;

            curLine = new string[] { };
            curTokenIdx = 0;
        }

        string[] curLine;
        int curTokenIdx;

        char[] whiteSpaces = new char[] { ' ', '\t', '\r', '\n' };

        public string ReadNextToken()
        {
            if (curTokenIdx >= curLine.Length)
            {
                //Read next line
                string line = reader.ReadLine();
                if (line != null)
                    curLine = line.Split(whiteSpaces, StringSplitOptions.RemoveEmptyEntries);
                else
                    curLine = new string[] { };
                curTokenIdx = 0;
            }

            if (curTokenIdx >= curLine.Length)
                return null;

            return curLine[curTokenIdx++];
        }

        public int ReadNextInt()
        {
            return int.Parse(ReadNextToken());
        }

        public double ReadNextDouble()
        {
            string tkn = ReadNextToken();
            StringBuilder token = new StringBuilder(tkn);
            token [tkn.IndexOf(".")] = System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator[0];
            return double.Parse(token.ToString());
        }

        public void Write(double val, int precision)
        {
            Int64 valI = (Int64)val;
            writer.Write(valI.ToString());
            double diff = val - valI;
            if (precision > 0)
                writer.Write(".");
            int i;
            for (i = 0; i < precision; i++)
            {
                diff *= 10;
                writer.Write(((int)diff).ToString());
                diff -= (int)diff;
            }
        }

        public void Write(string stringToWrite)
        {
            writer.Write(stringToWrite);
        }

        public void WriteLine(string stringToWrite)
        {
            writer.WriteLine(stringToWrite);
        }

        public void Dispose()
        {
            try
            {
                if (reader != null)
                {
                    reader.Dispose();
                }
                if (writer != null)
                {
                    writer.Dispose();
                }
            }
            catch { };
        }

        public void Flush()
        {
            if (writer != null)
            {
                writer.Flush();
            }
        }
    }

    class Program
    {
        protected IOHelper ioHelper;

        int n, t;
        double p;
        double result;

        protected double Compute1(int t, int curPeople, double p)
        {
            double result = 1;
            for (int i = 1; i <= t; i++)
            {
                result *= i;
                if (i <= curPeople)
                    result /= (double)i;
                if (i <= t - curPeople)
                    result /= (double)i;

                if (i <= curPeople)
                    result *= p;
                else
                    result *= (1 - p);
            }

            return result;
        }

        public void Solve()
        {
            n = ioHelper.ReadNextInt();
            p = ioHelper.ReadNextDouble();
            t = ioHelper.ReadNextInt();

            double combination = 1;

            result = 0;
            for (int curPeople = 0; curPeople < n; curPeople++)
            {
                if (curPeople > t)
                    break;
                double curProb = 0;

                curProb = Compute1(t, curPeople, p);

                result += curProb * curPeople;

                combination *= (t - curPeople)/ (curPeople + 1.0);
            }

            int posN;
            combination = 1;
            if (n > 1)
            {
                for (posN = n; posN <= t; posN++)
                {
                    double curProb = 0;

                    curProb = Compute1(posN-1,n-1,p)*p;

                    result += curProb * n;

                    combination *= (posN + 0.0) / (posN - (n - 1.0));
                }
            }
            else
            {
                double curProb = Math.Pow(1 - p, t);
                curProb = 1 - curProb;
                result += curProb * 1;
            }

            ioHelper.Write(result, 7);
            ioHelper.WriteLine("");
        }

        public Program(string inputFile, string outputFile)
        {
            ioHelper = new IOHelper(inputFile, outputFile, Encoding.Default);
            Solve();
            ioHelper.Dispose();
        }

        static void Main(string[] args)
        {
            Program myProgram = new Program(null, null);
        }
    }
}


using System;
using System.Globalization;
using System.IO.Pipes;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace ContestV
{
    internal class Program
    {
        static bool APsearch(string a, string b)
        {
            string h = string.Empty;
            bool ans = false;
            int t = 0;

            for (int i = 0, j = 0; i < a.Length; i++)
            {
                if (a[i] == b[j])
                {
                    j++;
                    t++;
                    h += a[i];
                    if(j==b.Length) break;
                }
            }

            if (h == b) ans = true;

            return ans;
        }

        static bool Asearch(string a, string b)
        {
            bool ans = false;

         StringBuilder aa = new StringBuilder(a);

            int t = 0;
            for (int i = 0; i < b.Length; i++)
            {
                for (int j = 0; j < aa.Length; j++)
                {
                    if (b[i] == aa[j])
                    {
                        t++;
                        aa.Remove(j, 1);
                        break;
                    }
                }

            }
            if (t == b.Length) ans = true;

            return ans;
        }

        private static void Main(string[] args)
        {

            string a = Console.ReadLine();

            string b = Console.ReadLine();

            string ans = "need tree";

            if (a.Length>=b.Length)
            {
                if (Asearch(a, b))
                {
                    if (a.Length == b.Length) ans = "array";

                    else if (APsearch(a, b)) ans = "automaton";
                    else
                    {
                        ans = "both";
                    }

                }

            }

            Console.WriteLine(ans);

        }
    }
}


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

namespace CF
{
    class Program
    {
        public static void Ron()
        {
            Console.Write("Ron");
        }

        public static void Hermione()
        {
            Console.Write("Hermione");
        }

        static void Main(string[] args)
        {
            string[] ss = Console.ReadLine().Split(' ');
            int a = int.Parse(ss[0]);
            int b = int.Parse(ss[1]);
            int c = int.Parse(ss[2]);
            int d = int.Parse(ss[3]);
            int e = int.Parse(ss[4]);
            int f = int.Parse(ss[5]);

            if (d > 0)
            {
                if (c > 0)
                {
                    if (b > 0)
                    {
                        if (a > 0)
                        {
                            if (f > 0)
                            {
                                if (e > 0)
                                {
                                    if (a * c * e < b * d * f)
                                        Ron();
                                    else
                                        Hermione();
                                }
                                else
                                {
                                    Ron();
                                }
                            }
                            else
                            {
                                Hermione();
                            }
                        }
                        else
                        {
                            Ron();
                        }
                    }
                    else
                    {
                        Hermione();
                    }
                }
                else
                {
                    Ron();
                }
            }
            else
            {
                Hermione();
            }
            Console.ReadKey();
        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int min, max;
            max = 0;
            min = 2200;
            int[] years = new int[n];
            int i = 0;
            foreach (string s in Console.ReadLine().Split())
            {
                years[i] = Convert.ToInt32(s);
                max = max <= years[i] ? years[i] : max;
                min = min >= years[i] ? years[i] : min;
                i++;
            }
            Console.WriteLine("{0}", (max + min) / 2);
        }
    }
}


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

namespace C1
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string[] strInts = s.Split(new char[1] { ' ' });
            int a = int.Parse(strInts[0]);
            int b = int.Parse(strInts[1]);
            int f = int.Parse(strInts[2]);
            int k = int.Parse(strInts[3]);

            int kCurrent = 0;
            int bCurrent = b;
            int nextPoint = a;
            bool can = true;
            int tanked = 0;

            if (f > bCurrent)
            {
                can = false;
            }
            else
                bCurrent -= f;

            while (kCurrent!=k && can)
            {
                int Destantion = kCurrent==k-1? Math.Abs(f - nextPoint): 2 * Math.Abs(f - nextPoint);
                if (bCurrent >= Destantion)
                {
                    nextPoint = nextPoint == 0 ? a : 0;
                    bCurrent -= Destantion;
                    kCurrent++;
                }
                else
                {
                    if (bCurrent == b)
                    {
                        can = false;
                    }
                    else
                    {
                        bCurrent = b;
                        tanked++;
                    }

                }
            }

            if (kCurrent == k)
            {
                Console.WriteLine(tanked);
            }
            else
                Console.WriteLine(-1);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Text.RegularExpressions;
using System.Threading;

namespace CodeForces
{
    class Program
    {
        public static string Rw() => Console.ReadLine();
        public static int GetInt() => Int32.Parse(Console.ReadLine());
        public static int[] GetArr() => Array.ConvertAll(Console.ReadLine().Split(' '), Int32.Parse);

        public static void Main(string[] args)
        {
            int[] arr = GetArr();
            int n = arr[0];
            int w = arr[1];
            arr = GetArr();

            int max = 0;
            for (int i = 0; i < n; i++)
                max += arr[i];

            if (max < w)
            {
                Console.WriteLine(-1);
                return;
            }

            int[] tea = new int[n];
            for (int i = 0; i < n; i++)
            {
                tea[i] = (arr[i] + 1)/2;
                w -= tea[i];
                if (w < 0)
                {
                    Console.WriteLine(-1);
                    return;
                }
            }

            while (w > 0)
            {
                int max_index = -1;
                int i = 0;
                for (i = 0; i < n && max_index == -1; i++)
                    if (tea[i] != arr[i])
                        max_index = i;

                for (; i < n; i++)
                    if (tea[i] != arr[i] && arr[max_index] < arr[i])
                        max_index = i;

                max = Math.Min(arr[max_index] - tea[max_index], w);
                w -= max;
                tea[max_index] += max;
            }

            for (int i = 0; i < n; i++)
                Console.Write(tea[i] + " ");

        }
    }

}


// Problem: 1146A - Love "A"
// Author: Gusztav Szmolik

using System;

class LoveA
    {
    public static int Main ()
        {
        string line = Console.ReadLine ();
        if (line == null)
            return -1;
        string[] words = line.Split ();
        if (words.Length != 1)
            return -1;
        string s = words[0];
        byte sLength = Convert.ToByte (s.Length);
        if (sLength > 50)
            return -1;
        byte aCount = 0;
        char c;
        for (byte i = 0; i < sLength; i++)
            {
            c = s[i];
            if (!Char.IsLower (c))
                return -1;
            if (c == 'a')
                aCount++;
            }
        if (aCount == 0)
            return -1;
        byte ansTmp = Convert.ToByte (2*aCount-1);
        byte ans = (ansTmp < sLength ? ansTmp : sLength);
        Console.WriteLine (ans);
        return 0;
        }
    }


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

namespace CodeForce
{
    public class Program
    {
        static void Main(string[] args)
        {
            int k;
            k = int.Parse(System.Console.ReadLine());

            int [] mem =new int[10];
            for (int i = 0; i < 4; i++)
            {
                string a = System.Console.ReadLine();
                foreach (char c in a)
                {
                    if (c >= '1' && c <= '9')
                        mem[c-'0']++;
                }

            }

            bool yes = true;
            for (int i = 1; i < 10; i++)
            {
                if (mem[i] > 2*k)
                {
                    yes = false;
                    break;
                }

            }

            System.Console.WriteLine(yes?"YES":"NO");
            //System.Console.ReadLine();

        }

    }
}


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

namespace PracticeProblems
{
	class Program
	{
		static void Main(String[] args)
		{
			P_146A tenth = new P_146A();
			tenth.Run();
			Console.Read();
		}
	}

	class P_158A
	{
		public P_158A() { }

		public void Run()
		{
			String[] paramz = Console.ReadLine().Split(' ');
			int n = Convert.ToInt16(paramz[0]);
			int ptctr = Convert.ToInt16(paramz[1]) - 1;

			String[] input = Console.ReadLine().Split(' ');

			if (Convert.ToInt16(input[ptctr]) != 0)
			{
				while (ptctr < n - 1)
				{
					if (Convert.ToInt16(input[ptctr + 1]) == Convert.ToInt16(input[ptctr]))
					{
						ptctr++;
					}
					else
						break;
				}
			}
			else
			{
				while (ptctr >= 0)
				{
					if (Convert.ToInt16(input[ptctr]) == 0)
					{
						ptctr--;
					}
					else
					{
						break;
					}
				}
			}

			Console.Write(ptctr + 1);
		}
	}

	class P_158B
	{
		public P_158B() { }

		public void Run()
		{
			int numCabs = 0;

			// [0] = 1 ... [3] = 4
			int[] countArr = new int[4];

			// Flush line b/c of conversion
			Console.ReadLine();

			String[] input = Console.ReadLine().Split(' ');

			// Count number of occurrences of each group size = countArr[]
			foreach (String groupSize in input)
			{
				switch (groupSize)
				{
					case "1":
						countArr[0]++;
						break;
					case "2":
						countArr[1]++;
						break;
					case "3":
						countArr[2]++;
						break;
					case "4":
						countArr[3]++;
						break;
				}
			}

			/*	Is performing this before the bottom steps faster?
			 *		I don't think so because worst case, you'll be performing n*(this method's complexity) + Theta(bottom steps)
			 *
			 * Accept input one value at a time.
			 *	if 1:
			 *		if any 3's, then dec num 3's and total++
			 *		else, inc num 1's
			 *	if 2:
			 *		if any 2's, then dec num 2's and total++
			 *		else if at least two 1's, then decx2 num 1's and total++
			 *		else, inc num 2's
			 *	if 3:
			 *		if any 1's, then dec num 1's and total++
			 *		else, inc num 3's
			 *	if 4:
			 *		total++
			 *
			 */

			// 1. Count number of 4's
			// 2. Find the lesser of 1's and 3's, subtract from both and += lesser and += remaining 3's
			// 3. += (2's divided by two, integer division); if odd, then if there are at least two 1's left, then += 1 and decx2 num 1's | otherwise (no more 1's), += 1 and RETURN
			// 4. += (Ceiling of remaining 1's divided by 4)

			// ONE
			numCabs += countArr[3];

			// TWO
			int lesser = Math.Min(countArr[0], countArr[2]);
			countArr[0] -= lesser;
			countArr[2] -= lesser;
			numCabs += lesser;
			numCabs += countArr[2];

			// THREE
			numCabs += (countArr[1] / 2);
			if (countArr[1] % 2 == 1)
			{
				if (countArr[0] > 1)
				{
					numCabs++;
					countArr[0] -= 2;
				}
				else // END CASE: ADD ONE AND WRITE
				{
					numCabs++; // for the 2 (and remaining 1)
					Console.WriteLine(numCabs);
					return;
				}
			}

			// FOUR
			numCabs += Convert.ToInt32(Math.Ceiling((double)(countArr[0]) / 4));

			Console.WriteLine(numCabs);
		}
	}

	class P_71A
	{
		public P_71A() { }

		public void Run()
		{
			int numLines = Convert.ToInt32(Console.ReadLine());

			while (numLines > 0)
			{
				String input = Console.ReadLine();

				if (input.Length <= 10)
				{
					Console.WriteLine(input);
				}
				else
				{
					StringBuilder sb = new StringBuilder();
					sb.Append(input[0]);
					sb.Append(input.Length - 2);
					sb.Append(input[input.Length - 1]);
					Console.WriteLine(sb.ToString());
				}

				numLines--;
			}
		}
	}

	class P_118A
	{
		public P_118A() { }

		public void Run()
		{
			LinkedList<char> input = new LinkedList<char>(Console.ReadLine().ToCharArray());

			// Remove all vowels
			// Place '.' behind all consonants
			// Upper to lower case
			// NOTE: combined all three because can be done concurrently

			LinkedList<char> temp = new LinkedList<char>();

			foreach (char elt in input)
			{
				if (!IsVowel(elt))
				{
					temp.AddLast('.');
					temp.AddLast(UpperToLower(elt));
				}
			}

			Print(temp);
		}

		private bool IsVowel(char input)
		{
			if (input == 'a' || input == 'A'
					|| input == 'e' || input == 'E'
					|| input == 'i' || input == 'I'
					|| input == 'o' || input == 'O'
					|| input == 'u' || input == 'U'
					|| input == 'y' || input == 'Y')
				return true;

			return false;
		}

		private char UpperToLower(char input)
		{
			if (input < 'a')
			{
				return (char)(input + ('a' - 'A'));
			}

			return input;
		}

		private void Print(LinkedList<char> output)
		{
			foreach (char elt in output)
			{
				Console.Write(elt);
			}
		}
	}

	public class P_40A
	{
		public P_40A() { }

		public void Run()
		{
			String[] input = Console.ReadLine().Split(' ');
			int l = Convert.ToInt32(input[0]);
			int w = Convert.ToInt32(input[1]);
			double total = 0;

			if (l % 2 == 1 && w % 2 == 1)
			{
				total += (l * (w - 1)) / 2;
				total += (l - 1) / 2;
			}
			else
			{
				total += (l * w) / 2;
			}

			Console.WriteLine(total);
		}
	}

	class P_231A
	{
		public P_231A() { }

		public void Run()
		{
			int lines = Convert.ToInt32(Console.ReadLine());
			int counter = 0;

			while (lines > 0)
			{
				String input = Console.ReadLine();

				if (Convert.ToInt32(input[0]) + Convert.ToInt32(input[2]) + Convert.ToInt32(input[4]) >= 146)
					counter++;

				lines--;
			}

			Console.WriteLine(counter);
		}
	}

	class P_116A
	{
		public P_116A() { }

		public void Run()
		{
			int lines = Convert.ToInt32(Console.ReadLine());
			int counter = 0;
			int max = 0;

			while (lines > 0)
			{
				String[] line = Console.ReadLine().Split(' ');

				counter += (Convert.ToInt32(line[1]) - Convert.ToInt32(line[0]));

				max = Greater(max, counter);

				lines--;
			}

			Console.WriteLine(max);
		}

		private int Greater(int first, int second)
		{
			if (first > second)
				return first;

			return second;
		}
	}

	class P_146A
	{
		public P_146A() { }

		public void Run()
		{
			int[] luckyCount1 = new int[2];
			int[] luckyCount2 = new int[2];

			int iters = Convert.ToInt16(Console.ReadLine()) / 2;
			String num = Console.ReadLine();

			for (int i = 0; i < iters; i++)
			{
				if (num[i] == '4')
					luckyCount1[0]++;
				else if (num[i] == '7')
					luckyCount1[1]++;
				else
				{
					Console.WriteLine("NO");
					return;
				}

				if (num[iters + i] == '4')
					luckyCount2[0]++;
				else if (num[iters + i] == '7')
					luckyCount2[1]++;
				else
				{
					Console.WriteLine("NO");
					return;
				}
			}

			if (luckyCount1[0] == luckyCount2[0] && luckyCount1[1] == luckyCount2[1])
			{
				Console.WriteLine("YES");
			}
			else
			{
				Console.WriteLine("NO");
			}
		}
	}

	//public class LinkedListNode<T>
	//{
	//	public LinkedListNode() { }
	//	public LinkedListNode(T value) { Value = value; }

	//	public LinkedListNode<T> Previous { get; set; }
	//	public LinkedListNode<T> Next { get; set; }
	//	public T Value { get; set; }
	//}
}


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

namespace ProjectEuler
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = Convert.ToInt32(Console.ReadLine());
            int b = Convert.ToInt32(Console.ReadLine());
            int c = Convert.ToInt32(Console.ReadLine());

            if (a != 1 && b != 1 && c != 1 )
            {
                Console.WriteLine(a*b*c);
            }
            else if (a == 1 && c != 1)
            {
                Console.WriteLine((a + b) * c);
            }
            else if (a == 1 && c == 1)
            {
                Console.WriteLine(a + b + c);
            }
            else if (b == 1)
            {
                if (a >= c)
                {
                    Console.WriteLine(a * (1 + c));
                }
                else
                {
                    Console.WriteLine((a + 1) * c);
                }
            }
            else if (a != 1 && c == 1)
            {
                Console.WriteLine(a * (b + 1));
            }

        }

    }
}


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

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

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

            int mi1 = Next(), ma1 = Next();
            int mi2 = Next(), ma2 = Next();
            int mi3 = Next(), ma3 = Next();

            int n1 = Math.Min(ma1, n - mi2 - mi3);
            int n2 = Math.Min(ma2, n - n1 - mi3);
            int n3 = n - n1 - n2;

            writer.WriteLine("{0} {1} {2}", n1, n2, n3);
            writer.Flush();
        }

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


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Convert.ToInt32(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(ai => Convert.ToInt32(ai)).ToList();

            var half = a.Sum() / 2 + 1;

            var alica = a[0];
            a = a.Skip(1).ToList();

            var result = new List<int>();
            result.Add(1);

            var sum = alica;
            for (var i = 0; i < a.Count; i++)
            {
                var ai = a[i];
                if (ai * 2 <= alica)
                {
                    result.Add(i + 2);
                    sum += ai;
                    if (sum >= half)
                    {
                        break;
                    }
                }
            }

            if (sum >= half)
            {
                Console.WriteLine(result.Count);
                foreach (var k in result)
                {
                    Console.Write(k + " ");
                }
            }
            else
            {
                Console.WriteLine(0);
            }

            //Console.ReadKey();
        }
    }
}


using System;

class A514 {
    public static void Main() {
        var s = Console.ReadLine().ToCharArray();
        for (int i = s[0] == '9' ? 1 : 0; i < s.Length; ++i)
            s[i] = (char)Math.Min(s[i], '0' + ('9' - s[i]));
        Console.WriteLine(new string(s));
    }
}


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

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

        private static readonly StreamWriter writer =
            new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

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

            int k = int.Parse(ss[0]);
            int a = int.Parse(ss[1]);
            int b = int.Parse(ss[2]);
            int v = int.Parse(ss[3]);

            int count = 0;

            while (a > 0)
            {
                int used = Math.Min(k-1, b);
                b -= used;
                int n = (used + 1)*v;
                a -= n;
                count++;
            }

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