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

namespace Program
{
    public static class CODEFORCES1
    {
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            var n = NN;
            var m = NN;
            var L = NN;
            var R = NN;
            LIB_Mod._mod = 998244353;
            if (R - L == 0)
            {
                Console.WriteLine(1);
                return;
            }
            var tmp = LIB_Mod.Pow(LIB_Mod.Pow(R - L + 1, n), m);
            Console.WriteLine(((n * m) % 2 == 0) ? (tmp + ((R - L + 1) % 2)) / 2 : tmp);
        }
        class Printer : StreamWriter
        {
            public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
            public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }
            public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }
        }
        static LIB_FastIO fastio = new LIB_FastIODebug();
        static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); }
        static long NN => fastio.Long();
        static double ND => fastio.Double();
        static string NS => fastio.Scan();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static IEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderBy(e => e, StringComparer.OrdinalIgnoreCase);
        static IEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderBy(selector, StringComparer.OrdinalIgnoreCase);
        static IEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase);
        static IEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByDescending(selector, StringComparer.OrdinalIgnoreCase);
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
    }
}
namespace Library {
    struct LIB_Mod : IEquatable<LIB_Mod>, IEquatable<long>
    {
        static public long _mod = 1000000007; long v;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_Mod(long x)
        {
            if (x < _mod && x >= 0) v = x;
            else if ((v = x % _mod) < 0) v += _mod;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static public implicit operator LIB_Mod(long x) => new LIB_Mod(x);
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static public implicit operator long(LIB_Mod x) => x.v;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void Add(LIB_Mod x) { if ((v += x.v) >= _mod) v -= _mod; }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void Sub(LIB_Mod x) { if ((v -= x.v) < 0) v += _mod; }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void Mul(LIB_Mod x) => v = (v * x.v) % _mod;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void Div(LIB_Mod x) => v = (v * Inverse(x.v)) % _mod;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static public LIB_Mod operator +(LIB_Mod x, LIB_Mod y) { var t = x.v + y.v; return t >= _mod ? new LIB_Mod { v = t - _mod } : new LIB_Mod { v = t }; }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static public LIB_Mod operator -(LIB_Mod x, LIB_Mod y) { var t = x.v - y.v; return t < 0 ? new LIB_Mod { v = t + _mod } : new LIB_Mod { v = t }; }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static public LIB_Mod operator *(LIB_Mod x, LIB_Mod y) => x.v * y.v;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static public LIB_Mod operator /(LIB_Mod x, LIB_Mod y) => x.v * Inverse(y.v);
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static public bool operator ==(LIB_Mod x, LIB_Mod y) => x.v == y.v;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static public bool operator !=(LIB_Mod x, LIB_Mod y) => x.v != y.v;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static public long Inverse(long x)
        {
            long b = _mod, r = 1, u = 0, t = 0;
            while (b > 0)
            {
                var q = x / b;
                t = u;
                u = r - q * u;
                r = t;
                t = b;
                b = x - q * b;
                x = t;
            }
            return r < 0 ? r + _mod : r;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public bool Equals(LIB_Mod x) => v == x.v;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public bool Equals(long x) => v == x;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override bool Equals(object x) => x == null ? false : Equals((LIB_Mod)x);
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override int GetHashCode() => v.GetHashCode();
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override string ToString() => v.ToString();
        static List<LIB_Mod> _fact = new List<LIB_Mod>() { 1 };
        static long _factm = _mod;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static void B(long n)
        {
            if (_factm != _mod) _fact = new List<LIB_Mod>() { 1 };
            if (n >= _fact.Count)
                for (int i = _fact.Count; i <= n; ++i)
                    _fact.Add(_fact[i - 1] * i);
            _factm = _mod;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static public LIB_Mod Comb(long n, long k)
        {
            B(n);
            if (n == 0 && k == 0) return 1;
            if (n < k || n < 0) return 0;
            return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static public LIB_Mod CombOK(long n, long k)
        {
            LIB_Mod ret = 1;
            for (var i = 0; i < k; i++) ret *= n - i;
            for (var i = 1; i <= k; i++) ret /= i;
            return ret;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static public LIB_Mod Perm(long n, long k)
        {
            B(n);
            if (n == 0 && k == 0) return 1;
            if (n < k || n < 0) return 0;
            return _fact[(int)n] / _fact[(int)(n - k)];
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static public LIB_Mod Pow(LIB_Mod x, long y)
        {
            LIB_Mod a = 1;
            while (y != 0)
            {
                if ((y & 1) == 1) a.Mul(x);
                x.Mul(x);
                y >>= 1;
            }
            return a;
        }
    }
    class LIB_FastIO
    {
        public LIB_FastIO() { str = Console.OpenStandardInput(); }
        readonly Stream str;
        readonly byte[] buf = new byte[1024];
        int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        byte read()
        {
            if (isEof) throw new EndOfStreamException();
            if (ptr >= len)
            {
                ptr = 0;
                if ((len = str.Read(buf, 0, 1024)) <= 0)
                {
                    isEof = true;
                    return 0;
                }
            }
            return buf[ptr++];
        }
        char Char()
        {
            byte b = 0;
            do b = read();
            while (b < 33 || 126 < b);
            return (char)b;
        }
        virtual public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        virtual public long Long()
        {
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != '-' && (b < '0' || '9' < b));
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); }
    }
    class LIB_FastIODebug : LIB_FastIO
    {
        Queue<string> param = new Queue<string>();
        string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        public LIB_FastIODebug() { }
        public override string Scan() => NextString();
        public override long Long() => long.Parse(NextString());
        public override double Double() => double.Parse(NextString());
    }
}


using System;
using System.Linq;
using CompLib.Util;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int a = sc.NextInt();
        int b = sc.NextInt();
        int c = sc.NextInt();

        int w = Math.Min(a / 3, Math.Min(b / 2, c / 2));

        a -= w * 3;
        b -= w * 2;
        c -= w * 2;
        int max = int.MinValue;
        for (int be = 0; be < 7; be++)
        {
            int ta = a;
            int tb = b;
            int tc = c;
            int cnt = 0;
            bool f = true;
            for (int i = 0; f && i < 7; i++)
            {
                switch ((i + be) % 7)
                {
                    case 0:
                    case 3:
                    case 6:
                        if (ta == 0)
                        {
                            f = false;
                            break;
                        }
                        ta--;
                        cnt++;
                        break;
                    case 1:
                    case 5:
                        if (tb == 0)
                        {
                            f = false;
                            break;
                        }
                        tb--;
                        cnt++;
                        break;
                    case 2:
                    case 4:
                        if (tc == 0)
                        {
                            f = false;
                            break;
                        }
                        tc--;
                        cnt++;
                        break;
                }
            }

            max = Math.Max(max, cnt);
        }

        Console.WriteLine(w * 7 + max);
    }

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

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

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

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

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

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

            return _line[_index++];
        }

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

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

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

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


using System;
 class Program
    {
        public static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            int b = a / 2 + 1;
            a = a % 2 == 0 ? a / 2 - 1 : a / 2;
            if(a%2==0 && b%2==0) { a--; b++; }
            Console.WriteLine("{0} {1}", a, b);
        }
    }


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

namespace CodeForce97
{
	class ClassC
	{
		static long Pow10(int p)
		{
			long ans = 1;
			for (int i = 0; i < p; i++)
				ans *= 10;
			return ans;
		}
		static long a(string s)
		{
			long ans = 0;
			if (s.Length == 1)
				return int.Parse(s);

			int d1 = int.Parse(s[0].ToString());
			int l = s.Length;

			ans = 9;
			for (int i = 1; i<l-1; i++)
			{
				ans += 9*Pow10(i-1);
			}

			ans += (d1 - 1) * Pow10(l - 2);

			if (l == 2)
			{
				if (s[0] <= s[s.Length - 1])
					ans++;
			}
			else
			{
				ans += long.Parse(s.Substring(1, l - 2))+1;
				if (s[0] > s[s.Length - 1])
					ans--;
			}
			return ans;
		}

		static void Main(string[] args)
		{
			string[] ss = Console.ReadLine().Split(' ');
			string sl = ss[0];
			string sr = ss[1];

			long ll = a(sl);
			long lr = a(sr);
			long ans = lr - ll;
			if (sl[0] == sl[sl.Length - 1])
				ans++;

			Console.WriteLine(ans);

//			Console.ReadKey();
		}
	}

}


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

namespace Some7
{
	class Program
	{
		static void Main(string[] args)
		{
			int n;
			string[] a = new string[8];

			for (int i = 0; i < 8; i++)
			{
				a[i] = Console.ReadLine();
			}
			int ans = 15;
			int row=8, col=8;
			for (int i = 0; i < 8; i++)
			{
				int s_row = 0, s_col = 0;
				for (int j = 0; j < 8; j++)
				{
					if (a[i][j] == 'B')
					{
						s_row++;
					}
					if (a[j][i] == 'B')
					{
						s_col++;
					}
				}
				row = min(row, s_row);
				col = min(s_col, col);
				ans = min(ans, row + col);

			}
			if (ans == 15)
			{
				ans = 8;
			}
			Console.WriteLine("{0}", ans);
			a[0] = Console.ReadLine();

		}

		private static int min(int s_col, int col)
		{
			return s_col < col ? s_col : col;
		}
	}
}


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

namespace _6A
{
    class Program
    {
        static void Main(string[] args)
        {
            CultureInfo culture = new CultureInfo("en-US");
            int[] data = Console.ReadLine().Trim().Split(' ').Select(x => int.Parse(x, culture)).ToArray();

            var list = data.ToList();
            list.Sort();

            if (list[0] + list[1] > list[2] || list[1] + list[2] > list[3])
            {
                Console.WriteLine("TRIANGLE");
            }
            else if (list[0] + list[1] == list[2] || list[1] + list[2] == list[3])
            {
                Console.WriteLine("SEGMENT");
            }
            else
            {
                Console.WriteLine("IMPOSSIBLE");
            }
        }
    }
}


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

class Program
{

    void solve()
    {
        int n = nextInt();
        string s = nextString();
        long[,] dp = new long[n + 1, n + 1];
        char[,] by = new char[n + 1, n + 1];
        for (int i = 0; i <= n; i++)
            for (int j = 0; j <= n; j++)
                dp[i, j] = -1;
        long res = go(0, 0, 0, n, s, dp, by);
        {
            int i = 0;
            int j = 0;
            string seq = "";
            while (i != n || j != n)
            {
                seq += by[i, j];
                if (by[i, j] == 'H')
                {
                    i++;
                }
                else
                    j++;
            }
            println(seq);
        }
    }

    private long go(int l1, int l2,int at, int n, string s,long[,]dp,char[,]by)
    {
        if (dp[l1,l2] != -1)
            return dp[l1,l2];
        if (l1 == n && l2 == n)
            return dp[l1,l2] = 0;
        long res = -1;
        if (l1 != n)
        {
            long cur = pow(n - l1-1) * (s[at] - '0');
            cur += go(l1 + 1, l2, at + 1, n, s, dp,by);
            if (cur > res)
            {
                res = cur;
                by[l1, l2] = 'H';

            }

        }
        if (l2 != n)
        {
            long cur = pow(n - l2 - 1) * (s[at] - '0');
            cur += go(l1, l2+1, at + 1, n, s, dp,by);
            if (cur > res)
            {
                res = cur;
                by[l1, l2] = 'M';
            }
        }

        return dp[l1, l2]=res;
    }

    private long pow(int p)
    {
        if (p == 0)
            return 1;
        return pow(p - 1) * 10;
    }

    ////////////
    private void println(string Stringst)
    {
        Console.WriteLine(Stringst);
    }
    private void println(char charnum)
    {
        Console.WriteLine(charnum);
    }
    private void println(int Intnum)
    {
        Console.WriteLine(Intnum);
    }
    private void println(long Longnum)
    {
        Console.WriteLine(Longnum);
    }
    private void println(double Doublenum)
    {
        string s = Doublenum.ToString(CultureInfo.InvariantCulture);
        Console.WriteLine(s);
    }

    private void print(string Stringst)
    {
        Console.Write(Stringst);
    }
    private void print(int Intnum)
    {
        Console.Write(Intnum);
    }
    private void print(char charnum)
    {
        Console.Write(charnum);
    }
    private void print(long Longnum)
    {
        Console.Write(Longnum);
    }
    private void print(double Doublenum)
    {
        Console.Write(Doublenum);
    }

    string[] inputLine = new string[0];
    int inputInd = 0;
    string nextLine()
    {
        return Console.ReadLine();
    }
    void readInput()
    {
        if (inputInd != inputLine.Length)
            throw new Exception();
        inputInd = 0;
        inputLine = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        if (inputLine.Length == 0)
            readInput();

    }
    int nextInt()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return int.Parse(inputLine[inputInd++]);
    }
    long nextLong()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return long.Parse(inputLine[inputInd++]);
    }
    double nextDouble()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return double.Parse(inputLine[inputInd++]);
    }
    string nextString()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return inputLine[inputInd++];
    }
    static void Main(string[] args)
    {
        new Program().solve();
    }
}


using System;
using System.Linq;
using CompLib.Util;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        string s = sc.Next();
        bool f = s.Count(c => c == '1') >= 2;
        for (int i = 0;; i++)
        {
            // 1 0が2*i個

            int len = 1 + 2 * i;

            if (s.Length < len || (s.Length == len && !f))
            {
                Console.WriteLine(i);
                break;
            }
        }
    }

    public static void Main(string[] args) => new Program().Solve();
}

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

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

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

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

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

            return _line[_index++];
        }

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

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

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


using System;
using System.Linq;

namespace CodeForces
{
    public class Program
    {
        private static void Main(string[] args)
        {
            var mod = (int) 1e9 + 7;
            var data = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            var a = data[0];
            var b = data[1];
            var k = data[2];
            var t = data[3];

            var nbFinalValues = 2*k*t + 1;
            var nbPathToValue = new long[nbFinalValues];
            var sumWinningPathForValue = new long[nbFinalValues + 1];

            nbPathToValue[k * t] = 1;
            for (var i = k*t + 1; i < sumWinningPathForValue.Length; ++i)
            {
                sumWinningPathForValue[i] = 1;
            }

            for (var i = 0; i < t; ++i)
            {
                var nextNbPathToValue = new long[nbFinalValues];
                var nextSumWinningPathForValue = new long[nbFinalValues + 1];
                for (var j = 0; j < nbPathToValue.Length; ++j)
                {
                    var leftIndex = Math.Max(0, j - k);
                    var rightIndex = Math.Min(nbPathToValue.Length - 1, j + k);
                    nextNbPathToValue[j] = (mod + sumWinningPathForValue[rightIndex+1] - sumWinningPathForValue[leftIndex]) % mod;
                    nextSumWinningPathForValue[j + 1] = (mod + nextSumWinningPathForValue[j] + nextNbPathToValue[j]) % mod;
                }
                sumWinningPathForValue = nextSumWinningPathForValue;
                nbPathToValue = nextNbPathToValue;
            }

            long result = 0;
            for (var i = Math.Max(0, b - a + 1); i<nbFinalValues; ++i)
            {
                result += (nbPathToValue[i]*sumWinningPathForValue[Math.Min(nbFinalValues, i+(a-b))]) % mod;
            }
            Console.WriteLine(result % mod);
        }
    }
}


using System;
class Program
    {
        static void Main(string[] args)
        {
            int n, k;
            {
                string[] input = Console.ReadLine().Split(new char[] { ' ', '\t'}, StringSplitOptions.RemoveEmptyEntries);
                n = int.Parse(input[0]);
                k = int.Parse(input[1]);
            }
            Console.WriteLine(3 * n+Math.Min(n-k, k-1));
        }
    }


using System;
class Program
{
    static void Main(string[] args)
    {
        //int n = 45; int k = 7;
        string s;
        s = Console.ReadLine();
        int n = 0;
        int k = 0;
        int num = 1;
        string mun = "";
        for (int i = 0; i < s.Length; i++)
        {
            if (i == s.Length - 1)
            {
                mun += s[i];
                k = int.Parse(mun);
            }

            if (s[i] != ' ')
                mun += s[i];
            else
                if (num == 1)
                {
                    n = int.Parse(mun);
                    num++;
                    mun = "";
                }
        }
        int p2 = 1;
        int flag = 0;
        int p = 0;
        int p1 = 0;
        if (k != 0) {
        for (int i = 7; i < n; i++)
        {

            for (int j = 2; j <= i / 2; j++)
            {
                flag = 0;
                if (i % j == 0)
                {
                    flag = 1;
                    break;
                }
            }
            if (flag == 0)
            {
                for (int l = 2; l < i; l++)
                {
                    for (int j1 = 2; j1 <= l / 2; j1++)
                    {
                        flag = 0;
                        if (l != 2 && l % j1 == 0)
                        {
                            flag = 1;
                            break;
                        }
                    }
                    if (flag == 0)
                        if (p % 2 == 0)
                        {
                            p1 = l;
                            p++;
                        }
                        else if (p % 2 != 0)
                        {
                            if (i == p1 + l + 1)
                            {
                                p2++;
                                break;
                            }
                            else p1 = l;
                        }
                    if (k == p2)
                        break;
                }
            }
            if (k == p2)
                break;
        }
        }
        if (k == p2||k == 0)
            Console.WriteLine("YES");
        else
            Console.WriteLine("NO");
    }
}


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

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int[] w = sc.IntArray();

        // 2n人

        // n-1 2人乗り
        // 2 1人乗り

        // 2人のりの不安定性 wの差

        int ans = int.MaxValue;
        Array.Sort(w);
        for (int i = 0; i < 2*n; i++)
        {
            for (int j = i + 1; j < 2*n; j++)
            {
                int s = 0;
                int idx = 0;
                for (int k = 0; k < 2*n; k++)
                {
                    if (i == k || j == k) continue;
                    s += (idx % 2 == 0 ? -1 : 1) * w[k];
                    idx++;
                }
                // Console.WriteLine(s);
                ans = Math.Min(ans, s);
            }

        }

        Console.WriteLine(ans);
    }

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

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

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

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

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

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

            return _line[_index++];
        }

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

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

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

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


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

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string[] ar = new string[10];
            for(int i = 0; i<10; i++)
            {
                ar[i] = Console.ReadLine();
            }
            string res = "";
            for (int i = 0; i < 8; i++ )
            {
                string sub = s.Substring(i * 10, 10);
                for (int j = 0; j < 10; j++ )
                {
                    if(sub.Equals(ar[j]))
                    {
                        res += (j);
                    }
                }
            }
            Console.WriteLine(res);
        }
    }
}


#define Online

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

delegate double F(double x);
delegate decimal Fdec(decimal x);

class Program
{
    static int Compare(long x, long y)
    {
        if (x > y) return 1;
        if (x < y) return -1;
        return 0;
    }
    static void Main(string[] args)
    {

        Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

#if FileIO
        StreamReader sr = new StreamReader("forest.in");
        StreamWriter sw = new StreamWriter("forest.out");
        Console.SetIn(sr);
        Console.SetOut(sw);
#endif
        long n = long.Parse(Console.ReadLine());
        const long m = 1000000000;
        List<long> div = new List<long>();

        for (long i = 1; i * i <= n; i++)
        {
            if (n % i == 0)
            {
                div.Add(i);
                div.Add(n / i);
            }
        }
        div.Sort(Compare);
        long min = long.MaxValue;
        long max = long.MinValue;
        long a,b,c;
        for (int i = 0; i < div.Count; i++)
        {
            a = div[i] + 1;
            for (int j = 0; j < div.Count; j++)
            {
                b = div[j] + 2;
                if ((a - 1) * (b - 2) > n) break;
                for (int z = 0; z < div.Count; z++)
                {
                    c = div[z] + 2;
                    if ((a - 1) * (b - 2) * (c - 2) > n) break;
                    if ((a - 1) * (b - 2) * (c - 2) != n) continue;
                    min = Math.Min(min, a * b * c - (a - 1) * (b - 2) * (c - 2));
                    max = Math.Max(max, a * b * c - (a - 1) * (b - 2) * (c - 2));
                }
            }
        }
        Console.WriteLine(min + " " + max);
#if Online
        Console.ReadLine();
#endif

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

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

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

    static decimal Sqrt(decimal x)
    {
        decimal mid;
        decimal right = (x <= 1 ? 1 : x);
        decimal left = 0;
        decimal eps = 0.00000000000000000001m;
        while (right - left > eps)
        {
            mid = left + ((right - left) / 2m);
            if (Math.Sign(mid * mid - x) != Math.Sign(left * left - x))
                right = mid;
            else
                left = mid;
        }
        return (left + right) / 2m;
    }

}

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

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

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

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

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

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

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

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

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


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

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

            var nn = new int[n,n];
            int index = 0;
            int jump = 1;
            while (true)
            {
                int next = (index + jump)%n;
                if (nn[index, next] == 1)
                {
                    break;
                }
                nn[index, next] = 1;
                index = next;
                jump++;
            }

            for (int i = 0; i < n; i++)
            {
                bool ok = false;
                for (int j = 0; j < n; j++)
                {
                    if (nn[i, j] == 1)
                    {
                        ok = true;
                        break;
                    }
                }
                if (ok == false)
                {
                    writer.WriteLine("NO");
                    writer.Flush();
                    return;
                }
            }

            writer.WriteLine("YES");
            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;

namespace ConsoleApplication1
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] y = Console.ReadLine().Split();
            int n = int.Parse(y[0]);
            int k = int.Parse(y[1]);
            string[] s = Console.ReadLine().Split();
            int[] m = new int[k];
            for (int i = 0; i < k; i++)
            {
                m[i] = int.Parse(s[i]);
            }
            Array.Sort(m);
            int a = 0;
            int min = int.MaxValue;

            for (int i = 0; i < k - n + 1; i++)
            {
                a = Math.Abs(m[i] - m[i + n-1]);
                if (a < min)
                {
                    min = a;
                }
            }
            Console.WriteLine(min);

        }
    }
}


using System;

namespace Codeforces.TaskD
{
    public class Task
    {
        public static void Main()
        {
            var task = new Task();
            try
            {
                task.Solve();
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex);
                throw;
            }
        }

        void Solve()
        {
            var arr = Console.ReadLine().Split();
            var N = int.Parse(arr[0]);
            var K = int.Parse(arr[1]);
            const int mod = 1000000007;

            var d = new int[K + 1, N + 2];

            for (var n = 1; n <= N; n++)
                d[1, n] = 1;

            for (var k = 2; k <= K; k++)
                for (var n = 1; n <= N; n++)
                    for (var i = n; i <= N; i += n)
                        d[k, i] = (d[k, i] + d[k - 1, n]) % mod;

            var result = 0;
            for (var i = 1; i <= N; i++)
                result = (result + d[K, i]) % mod;
            Console.WriteLine(result);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                int[] nk = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                string s = Console.ReadLine();
                int ig = 0;
                //     int it = 0;
                int step = nk[1];
                int it = 0;
                int i = 0;
                for ( i = 0; i < s.Length; i++)
                {
                    if (s[i] == 'G')
                        ig = i;
                    if (s[i] == 'T')
                        it = i;
                }
                i = 0;
                if(it<ig)
                {
                    for (i = ig - nk[1]; i > it ; i -= nk[1])
                    {
                        if (s[i] == '#')
                            break;
                    }
                }
                else
                {
                    for (i = ig + nk[1]; i < it ; i += nk[1])
                    {
                        if (s[i] == '#')
                            break;
                    }
                }
                if(i==it)
                    Console.WriteLine("YES");
                else
                    Console.WriteLine("NO");

                Console.ReadKey();
            }

            catch { }
        }

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using Debug = System.Diagnostics.Debug;
using SB = System.Text.StringBuilder;
using Number = System.Int64;
using System.Numerics;
using static System.Math;
namespace Program {
    public class Solver {
        Random rnd = new Random ();
        public void Solve () {
            var n = rl;
            var k = rl;
            var m = rl;
            var d = rl;
            BigInteger ans = 0;
            for (var i = 1; i <= d + 1; i++) {
                BigInteger min = n;
                BigInteger kk = k;
                kk *= i;
                min /= kk;
                kk = k;
                kk *= i - 1;
                kk += 1;
                var max = i == 1 ? m : (n / kk);
                min = BigInteger.Min (BigInteger.Max (1, min), m);
                max = BigInteger.Min (BigInteger.Max (1, max), m);

                foreach (var x in new BigInteger[] { min, max }) {
                    BigInteger V = n;
                    BigInteger u = x;
                    u *= k;
                    var cnt = 0;
                    while (V >= x && cnt <= d) {
                        V -= u;
                        cnt++;
                    }
                    //Console.WriteLine ($"{min} {max} {x} {cnt}");

                    if (cnt <= d) ans = BigInteger.Max (ans, cnt * x);
                }
            }
            System.Console.WriteLine (ans);

        }
        const long INF = 1L << 60;
        //static int[] dx = { -1, 0, 1, 0 };
        //static int[] dy = { 0, 1, 0, -1 };

        int ri { get { return sc.Integer (); } }
        long rl { get { return sc.Long (); } }
        double rd { get { return sc.Double (); } }
        string rs { get { return sc.Scan (); } }
        public IO.StreamScanner sc = new IO.StreamScanner (Console.OpenStandardInput ());

        static T[] Enumerate<T> (int n, Func<int, T> f) {
            var a = new T[n];
            for (int i = 0; i < n; ++i) a[i] = f (i);
            return a;
        }
        static public void Swap<T> (ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
    }
}
#region main
static class Ex {
    static public string AsString (this IEnumerable<char> ie) { return new string (ie.ToArray ()); }
    static public string AsJoinedString<T> (this IEnumerable<T> ie, string st = " ") {
        return string.Join (st, ie);
    }
    static public void Main () {
        Console.SetOut (new Program.IO.Printer (Console.OpenStandardOutput ()) { AutoFlush = false });
        var solver = new Program.Solver ();
        try {
            solver.Solve ();
            Console.Out.Flush ();
        } catch { }
    }
}
#endregion
#region Ex
namespace Program.IO {
    using System.Globalization;
    using System.IO;
    using System.Text;

    public class Printer : StreamWriter {
        public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
        public Printer (Stream stream) : base (stream, new UTF8Encoding (false, true)) { }
    }

    public class StreamScanner {
        public StreamScanner (Stream stream) { str = stream; }

        public readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }

        private byte read () {
            if (isEof) return 0;
            if (ptr >= len) {
                ptr = 0;
                if ((len = str.Read (buf, 0, 1024)) <= 0) {
                    isEof = true;
                    return 0;
                }
            }
            return buf[ptr++];
        }

        public char Char () {
            byte b = 0;
            do b = read (); while ((b < 33 || 126 < b) && !isEof);
            return (char) b;
        }
        public string Scan () {
            var sb = new StringBuilder ();
            for (var b = Char (); b >= 33 && b <= 126; b = (char) read ()) sb.Append (b);
            return sb.ToString ();
        }
        public string ScanLine () {
            var sb = new StringBuilder ();
            for (var b = Char (); b != '\n' && b != 0; b = (char) read ())
                if (b != '\r') sb.Append (b);
            return sb.ToString ();
        }
        public long Long () { return isEof ? long.MinValue : long.Parse (Scan ()); }
        public int Integer () { return isEof ? int.MinValue : int.Parse (Scan ()); }
        public double Double () { return isEof ? double.NaN : double.Parse (Scan (), CultureInfo.InvariantCulture); }
    }
}
#endregion


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

namespace TestConsole
{

    class Program
    {

        public static void Main(string[] args)
        {
            int[] input = readIntArray(System.Console.ReadLine().Split(' '));
            int a = input[0];
            int b = input[1];
            int k = input[2];

            bool[] seive = new bool[b + 1];
            for (int i = 2; i < b + 1; i++)
            {
                seive[i] = true;
            }

            for (int i = 2; i < b + 1; i++)
            {
                if (seive[i])
                {
                    if (((long)i) * i < b + 1)
                    {
                        for (int j = i * i; j < b + 1; j += i)
                        {
                            seive[j] = false;
                        }
                    }
                }
            }

            int result = -1;

            int left = k;
            int right = b - a + 2;

            while (left < right)
            {
                int l = (right + left) / 2;

                int firstWindow = 0;
                for (int i = a; i <= a + l - 1 && i < seive.Length; i++)
                {
                    if (seive[i]) firstWindow++;
                }

                bool forAllX = firstWindow >= k;

                if (forAllX)
                {
                    for (int x = a + 1; x <= b - l + 1; x++)
                    {
                        if (seive[x - 1]) firstWindow--;
                        if (seive[x + l - 1]) firstWindow++;
                        if (firstWindow < k)
                        {
                            forAllX = false;
                            break;
                        }
                    }
                }
                if (forAllX)
                {
                    result = l;
                    right = l;
                }
                else
                {
                    left = l + 1;
                }
            }
            Console.WriteLine(result);
        }

        static int[] readIntArray(string[] inArray)
        {
            return inArray.Select(i => Int32.Parse(i)).ToArray();
        }

    }

}


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

namespace ConsoleApp10
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] inp = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int k = inp[0];
            int a = inp[1];
            int b = inp[2];
            int u = a / k + b / k;
            if ((a>=k&&b>=k)||(a%k==0&&a!=0)||(b%k==0&&b!=0))
            {
                Console.WriteLine(u);
            }
            else
            {
                Console.WriteLine(-1);
            }

        }

    }
}


using System;
using System.Linq;

namespace A
{
    public static class Program
    {
        public static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            var s = Console.ReadLine().Reverse().ToArray();

            var min = 0;
            var curr = min;
            foreach (var m in s)
            {
                if (m == '-')
                {
                    curr++;
                } else
                {
                    curr--;
                }
                if (curr < 0)
                {
                    curr = 0;
                    min++;
                }
            }
            Console.WriteLine(min);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Numerics;
using E = System.Linq.Enumerable;

namespace ProbA {
    class Program {
        protected IOHelper io;

        public Program(string inputFile, string outputFile) {
            io = new IOHelper(inputFile, outputFile, Encoding.Default);

            int n=io.NextInt(), p=io.NextInt();
            string[] cmd = new string[n];
            for (int i = 0; i < n; i++) cmd[i] = io.NextToken();
            long has = 0, half = 0;
            for (int i = n - 1; i >= 0; i--) {
                if (cmd[i] == "half") {
                    has *= 2;
                } else {
                    has = has * 2 + 1;
                    half++;
                }
            }
            io.WriteLine(has * p - p / 2 * half);
            io.Dispose();
        }

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

    class IOHelper : IDisposable {
        public StreamReader reader;
        public StreamWriter writer;

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

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

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

        string[] curLine;
        int curTokenIdx;

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

        public bool hasNext() {
            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;
            }

            return curTokenIdx < curLine.Length;
        }

        public string NextToken() {
            return hasNext() ? curLine[curTokenIdx++] : null;
        }

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

        public double NextDouble() {
            string tkn = NextToken();
            return double.Parse(tkn, System.Globalization.CultureInfo.InvariantCulture);
        }

        public void Write(double val, int precision) {
            writer.Write(val.ToString("F" + precision, System.Globalization.CultureInfo.InvariantCulture));
        }

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

        public void WriteLine(double val, int precision) {
            writer.WriteLine(val.ToString("F" + precision, System.Globalization.CultureInfo.InvariantCulture));
        }

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

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

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


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

namespace Task66A
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            sbyte b = 0;
            bool bl = sbyte.TryParse(str,out b);
            if (bl==true)
            {
                Console.WriteLine("byte");
                return;
            }
            short s = 0;
            bl = short.TryParse(str, out s);
            if (bl == true)
            {
                Console.WriteLine("short");
                return;
            }
            int i = 0;
            bl = int.TryParse(str, out i);
            if (bl == true)
            {
                Console.WriteLine("int");
                return;
            }
            long l = 0;
            bl = long.TryParse(str, out l);
            if (bl == true)
            {
                Console.WriteLine("long");
                return;
            }
            Console.WriteLine("BigInteger");
        }
    }
}


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

using E = System.Linq.Enumerable;
using System.Numerics;

internal partial class Solver {
    public void Run() {
        var x0 = nl();
        var y0 = nl();
        var ax = nl();
        var ay = nl();
        var bx = nl();
        var by = nl();
        var xs = nl();
        var ys = nl();
        var t = nl();

        var x = new List<BigInteger> { x0 };
        var y = new List<BigInteger> { y0 };
        while (true) {
            if (x[x.Count - 1] >= long.MaxValue) break;
            if (y[y.Count - 1] >= long.MaxValue) break;
            var nx = x[x.Count - 1] * ax + bx;
            var ny = y[y.Count - 1] * ay + by;
            x.Add(nx);
            y.Add(ny);
        }
        //x.Dump();
        //y.Dump();
        int ans = 0;
        for (int i = 0; i < x.Count; i++) {
            for (int j = i; j < x.Count; j++) {
                var di = BigInteger.Abs(xs - x[i]) + BigInteger.Abs(ys - y[i]);
                var dj = BigInteger.Abs(xs - x[j]) + BigInteger.Abs(ys - y[j]);
                var dij = BigInteger.Abs(x[i] - x[j]) + BigInteger.Abs(y[i] - y[j]);
                int num = j - i + 1;
                if (di + dij <= t || dj + dij <= t) {
                    ans = Math.Max(ans, num);
                }
            }
        }
        cout.WriteLine(ans);
    }
}

// PREWRITEN CODE BEGINS FROM HERE
internal partial class Solver : Scanner {
    public static void Main(string[] args) {
#if LOCAL
        byte[] inputBuffer = new byte[1000000];
        var inputStream = Console.OpenStandardInput(inputBuffer.Length);
        using (var reader = new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)) {
            Console.SetIn(reader);
            new Solver(Console.In, Console.Out).Run();
        }
#else
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver(Console.In, Console.Out).Run();
        Console.Out.Flush();
#endif
    }

#pragma warning disable IDE0052
    private readonly TextReader cin;
    private readonly TextWriter cout;
#pragma warning restore IDE0052

    public Solver(TextReader reader, TextWriter writer)
        : base(reader) {
        cin = reader;
        cout = writer;
    }
    public Solver(string input, TextWriter writer)
        : this(new StringReader(input), writer) {
    }

#pragma warning disable IDE1006
#pragma warning disable IDE0051
    private int ni() { return NextInt(); }
    private int[] ni(int n) { return NextIntArray(n); }
    private long nl() { return NextLong(); }
    private long[] nl(int n) { return NextLongArray(n); }
    private double nd() { return NextDouble(); }
    private double[] nd(int n) { return NextDoubleArray(n); }
    private string ns() { return Next(); }
    private string[] ns(int n) { return NextArray(n); }
#pragma warning restore IDE1006
#pragma warning restore IDE0051
}

internal static class LinqPadExtension {
    [Conditional("DEBUG")]
    public static void Dump<T>(this T obj) {
#if DEBUG
        LINQPad.Extensions.Dump(obj);
#endif
    }
}

public class Scanner {
    private readonly TextReader Reader;
    private readonly CultureInfo ci = CultureInfo.InvariantCulture;

    private readonly char[] buffer = new char[2 * 1024];
    private int cursor = 0, length = 0;
    private string Token;
    private readonly StringBuilder sb = new StringBuilder(1024);

    public Scanner()
        : this(Console.In) {
    }

    public Scanner(TextReader reader) {
        Reader = reader;
    }

    public int NextInt() { return (int)NextLong(); }
    public long NextLong() {
        var s = Next();
        long r = 0;
        int i = 0;
        bool negative = false;
        if (s[i] == '-') {
            negative = true;
            i++;
        }
        for (; i < s.Length; i++) {
            r = r * 10 + (s[i] - '0');
#if DEBUG
            if (!char.IsDigit(s[i])) throw new FormatException();
#endif
        }
        return negative ? -r : r;
    }
    public double NextDouble() { return double.Parse(Next(), ci); }
    public string[] NextArray(int size) {
        string[] array = new string[size];
        for (int i = 0; i < size; i++) {
            array[i] = Next();
        }

        return array;
    }
    public int[] NextIntArray(int size) {
        int[] array = new int[size];
        for (int i = 0; i < size; i++) {
            array[i] = NextInt();
        }

        return array;
    }

    public long[] NextLongArray(int size) {
        long[] array = new long[size];
        for (int i = 0; i < size; i++) {
            array[i] = NextLong();
        }

        return array;
    }

    public double[] NextDoubleArray(int size) {
        double[] array = new double[size];
        for (int i = 0; i < size; i++) {
            array[i] = NextDouble();
        }

        return array;
    }

    public string Next() {
        if (Token == null) {
            if (!StockToken()) {
                throw new InvalidOperationException();
            }
        }
        var token = Token;
        Token = null;
        return token;
    }

    public bool HasNext() {
        if (Token != null) {
            return true;
        }

        return StockToken();
    }

    private bool StockToken() {
        while (true) {
            sb.Clear();
            while (true) {
                if (cursor >= length) {
                    cursor = 0;
                    if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) {
                        break;
                    }
                }
                var c = buffer[cursor++];
                if (33 <= c && c <= 126) {
                    sb.Append(c);
                } else {
                    if (sb.Length > 0) break;
                }
            }

            if (sb.Length > 0) {
                Token = sb.ToString();
                return true;
            }

            return false;
        }
    }
}


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

namespace Multiplication_Table
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] r = Console.ReadLine().Split(' ');
            int n = int.Parse(r[0]);
            int m = int.Parse(r[1]);
            long k = long.Parse(r[2]);
            int nn = Math.Min(n, m);
            int mm = n + m - nn;
            long levo = 1;
            long desno = 250000000000;
            long resenje = 0;
            while (levo <= desno)
            {
                long sredina = (levo + desno) / 2;
                long fsred = 0;
                for (int i = 1; i <= nn; i++)
                {
                    if (sredina >= i + 1) fsred += Math.Min((sredina - 1) / i, mm);
                    else break;
                }
                fsred++;
                if (fsred <= k) { resenje = sredina; levo = sredina + 1; }
                else desno = sredina - 1;
            }
            Console.WriteLine(resenje);
        }
    }
}


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

// (づ°ω°)づﾐ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    class Edge<T>
    {
        public int To, Inv;
        public T Capacity, Cost, Flow;
        public Edge(int to, int inv, T capacity, T cost, T flow)
        {
            To = to;
            Inv = inv;
            Capacity = capacity;
            Cost = cost;
            Flow = flow;
        }
    }

    static void AddEdge(List<Edge<int>>[] g, int from, int to, int capacity, int cost)
    {
        g[from].Add(new Edge<int>(to, g[to].Count, capacity, cost, 0));
        g[to].Add(new Edge<int>(from, g[from].Count - 1, 0, -cost, 0));
    }

    int MinCost(List<Edge<int>>[] g, int source, int sink, int limit)
    {
        const int INF = int.MaxValue / 2;

        int n = g.Length;
        int flow = 0, cost = 0;
        while (flow < limit)
        {
            var id = new int[n];
            var dist = Enumerable.Repeat(INF, n).ToArray();
            var q = new int[n];
            var path = new int[n];
            var epath = new int[n];
            int qh = 0, qt = 0;
            q[qt++] = source;
            dist[source] = 0;
            while (qh != qt)
            {
                int v = q[qh++];
                if (qh == n)
                    qh = 0;
                id[v] = 2;
                for (int i = 0; i < g[v].Count; i++)
                {
                    var r = g[v][i];
                    if (r.Flow < r.Capacity && dist[v] + r.Cost < dist[r.To])
                    {
                        dist[r.To] = dist[v] + r.Cost;
                        if (id[r.To] == 0)
                        {
                            q[qt++] = r.To;
                            if (qt == n)
                                qt = 0;
                        }
                        else if (id[r.To] == 2)
                        {
                            if (--qh == -1)
                                qh = n - 1;
                            q[qh] = r.To;
                        }
                        id[r.To] = 1;
                        path[r.To] = v;
                        epath[r.To] = i;
                    }
                }
            }
            if (dist[sink] == INF)
                break;
            int addflow = limit - flow;
            for (int v = sink; v != source; v = path[v])
            {
                int pv = path[v];
                int pr = epath[v];
                addflow = Math.Min(addflow, g[pv][pr].Capacity - g[pv][pr].Flow);
            }
            for (int v = sink; v != source; v = path[v])
            {
                int pv = path[v];
                int pr = epath[v], r = g[pv][pr].Inv;
                g[pv][pr].Flow += addflow;
                g[v][r].Flow -= addflow;
                cost += g[pv][pr].Cost * addflow;
            }
            flow += addflow;
        }
        return cost;
    }

    private int[] dr = {1, 0, -1, 0};
    private int[] dc = {0, 1, 0, -1};

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

        var g = Enumerable.Repeat(0, n * m + 2).Select(x => new List<Edge<int>>()).ToArray();
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
            {
                int x = i * m + j;
                if ((i + j) % 2 == 0)
                {
                    AddEdge(g, n * m, x, 1, 0);
                    for (int k = 0; k < 4; k++)
                    {
                        int ii = i + dr[k];
                        int jj = j + dc[k];
                        if (ii < 0 || ii == n || jj < 0 || jj == m)
                            continue;
                        AddEdge(g, x, ii * m + jj, 1, a[i][j] == a[ii][jj] ? 0 : 1);
                    }
                }
                else
                {
                    AddEdge(g, x, n * m + 1, 1, 0);
                }
            }

        Write(MinCost(g, n * m, n * m + 1, n * m / 2));
    }

    #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("game.in");
        //writer = new StreamWriter("game.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);
    }

    #endregion
}


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

namespace Program
{
    public static class CODEFORCES2
    {
        static public void Solve()
        {
            var list = NSList(3);
            var s = new List<int>();
            var m = new List<int>();
            var p = new List<int>();
            foreach (var item in list)
            {
                if (item[1] == 'm')
                {
                    m.Add(int.Parse(item[0].ToString()));
                }
                if (item[1] == 's')
                {
                    s.Add(int.Parse(item[0].ToString()));
                }
                if (item[1] == 'p')
                {
                    p.Add(int.Parse(item[0].ToString()));
                }
            }
            Func<List<int>, int> sameCount = x =>
            {
                var ans = 0;
                foreach (var item in x)
                {
                    ans = Max(ans, x.Count(e => e == item));
                }
                return ans;
            };
            Func<List<int>, int> junCount = x =>
            {
                var x2 = x.OrderBy(e => e).ToArray();
                if (x.Count == 0) return 0;
                if (x.Count == 1) return 1;
                if (x.Count == 2)
                {
                    if (x2[0] + 1 == x2[1])
                    {
                        return 2;
                    }
                    if (x2[0] + 2 == x2[1]) return 2;
                    return 1;
                }
                if (x2[0] + 1 == x2[1])
                {
                    if (x2[1] + 1 == x2[2])
                    {
                        return 3;
                    }
                    return 2;
                }
                if (x2[1] + 1 == x2[2])
                {
                    return 2;
                }
                if (x2[0] + 2 == x2[1]) return 2;
                if (x2[0] + 2 == x2[2]) return 2;
                return 1;
            };
            var max = 0;
            max = Max(max, sameCount(m));
            max = Max(max, sameCount(s));
            max = Max(max, sameCount(p));
            max = Max(max, junCount(m));
            max = Max(max, junCount(s));
            max = Max(max, junCount(p));
            Console.WriteLine(3 - max);

        }

        static public void Main(string[] args) { if (args.Length == 0) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } Solve(); Console.Out.Flush(); }
        static Random rand = new Random();
        static class Console_
        {
            static Queue<string> param = new Queue<string>();
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        }
        static long NN => long.Parse(Console_.NextString());
        static double ND => double.Parse(Console_.NextString());
        static string NS => Console_.NextString();
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => rand.Next());
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static void RevSort<T>(T[] l) where T : IComparable { Array.Sort(l, (x, y) => y.CompareTo(x)); }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static void RevSort<T>(T[] l, Comparison<T> comp) where T : IComparable { Array.Sort(l, (x, y) => comp(y, x)); }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static IEnumerable<long> Primes(long x) { if (x < 2) yield break; yield return 2; var halfx = x / 2; var table = new bool[halfx + 1]; var max = (long)(Math.Sqrt(x) / 2); for (long i = 1; i <= max; ++i) { if (table[i]) continue; var add = 2 * i + 1; yield return add; for (long j = 2 * i * (i + 1); j <= halfx; j += add) table[j] = true; } for (long i = max + 1; i <= halfx; ++i) if (!table[i] && 2 * i + 1 <= x) yield return 2 * i + 1; }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static IEnumerable<long> Factors(long x) { if (x < 2) yield break; while (x % 2 == 0) { x /= 2; yield return 2; } var max = (long)Math.Sqrt(x); for (long i = 3; i <= max; i += 2) while (x % i == 0) { x /= i; yield return i; } if (x != 1) yield return x; }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static IEnumerable<long> Divisor(long x) { if (x < 1) yield break; var max = (long)Math.Sqrt(x); for (long i = 1; i <= max; ++i) { if (x % i != 0) continue; yield return i; if (i != x / i) yield return x / i; } }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static long GCD(long a, long b) { while (b > 0) { var tmp = b; b = a % b; a = tmp; } return a; }
        static long LCM(long a, long b) => a * b / GCD(a, b);
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static Mat<T> Pow<T>(Mat<T> x, long y) => Mat<T>.Pow(x, y);
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static T Pow<T>(T x, long y) { T a = (dynamic)1; while (y != 0) { if ((y & 1) == 1) a *= (dynamic)x; x *= (dynamic)x; y >>= 1; } return a; }
        static List<long> _fact = new List<long>() { 1 };
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static void _B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static long Comb(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static long Perm(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; }
        class PQ<T> where T : IComparable
        {
            List<T> h; Comparison<T> c; public T Peek => h[0]; public int Count => h.Count;
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public PQ(int cap, Comparison<T> c, bool asc = true) { h = new List<T>(cap); this.c = asc ? c : (x, y) => c(y, x); }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public PQ(Comparison<T> c, bool asc = true) { h = new List<T>(); this.c = asc ? c : (x, y) => c(y, x); }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) { }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) { }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public void Push(T v) { var i = h.Count; h.Add(v); while (i > 0) { var ni = (i - 1) / 2; if (c(v, h[ni]) >= 0) break; h[i] = h[ni]; i = ni; } h[i] = v; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public T Pop() { var r = h[0]; var v = h[h.Count - 1]; h.RemoveAt(h.Count - 1); if (h.Count == 0) return r; var i = 0; while (i * 2 + 1 < h.Count) { var i1 = i * 2 + 1; var i2 = i * 2 + 2; if (i2 < h.Count && c(h[i1], h[i2]) > 0) i1 = i2; if (c(v, h[i1]) <= 0) break; h[i] = h[i1]; i = i1; } h[i] = v; return r; }
        }
        class PQ<TK, TV> where TK : IComparable
        {
            PQ<Tuple<TK, TV>> q; public Tuple<TK, TV> Peek => q.Peek; public int Count => q.Count;
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public PQ(int cap, Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>(cap, (x, y) => c(x.Item1, y.Item1), asc); }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public PQ(Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>((x, y) => c(x.Item1, y.Item1), asc); }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) { }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) { }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public void Push(TK k, TV v) => q.Push(Tuple.Create(k, v));
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public Tuple<TK, TV> Pop() => q.Pop();
        }
        public class UF
        {
            long[] d;
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public UF(long s) { d = Repeat(-1L, s).ToArray(); }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public bool Unite(long x, long y) { x = Root(x); y = Root(y); if (x != y) { if (d[y] < d[x]) { var t = y; y = x; x = t; } d[x] += d[y]; d[y] = x; } return x != y; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public bool IsSame(long x, long y) => Root(x) == Root(y);
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]);
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public long Count(long x) => -d[Root(d[x])];
        }
        struct Mod : IEquatable<object>
        {
            static public long _mod = 1000000007; long _val;
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public Mod(long x) { if (x < _mod && x >= 0) _val = x; else if ((_val = x % _mod) < 0) _val += _mod; }
            static public implicit operator Mod(long x) => new Mod(x);
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            static public implicit operator long(Mod x) => x._val;
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            static public Mod operator +(Mod x, Mod y) => x._val + y._val;
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            static public Mod operator -(Mod x, Mod y) => x._val - y._val;
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            static public Mod operator *(Mod x, Mod y) => x._val * y._val;
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            static public Mod operator /(Mod x, Mod y) => x._val * Inverse(y._val);
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            static public bool operator ==(Mod x, Mod y) => x._val == y._val;
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            static public bool operator !=(Mod x, Mod y) => x._val != y._val;
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            static public long Inverse(long x) { long b = _mod, r = 1, u = 0, t = 0; while (b > 0) { var q = x / b; t = u; u = r - q * u; r = t; t = b; b = x - q * b; x = t; } return r < 0 ? r + _mod : r; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            bool IEquatable<object>.Equals(object obj) => obj == null ? false : Equals((Mod)obj);
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public override bool Equals(object obj) => obj == null ? false : Equals((Mod)obj);
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public bool Equals(Mod obj) => obj == null ? false : _val == obj._val;
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public override int GetHashCode() => _val.GetHashCode();
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public override string ToString() => _val.ToString();
            static List<Mod> _fact = new List<Mod>() { 1 };
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            static void B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            static public Mod Comb(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            static public Mod Perm(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; }
        }
        struct Mat<T>
        {
            T[,] m;
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public Mat(T[,] v) { m = (T[,])v.Clone(); }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            static public implicit operator Mat<T>(T[,] v) => new Mat<T>(v);
            public T this[int r, int c] { get { return m[r, c]; } set { m[r, c] = value; } }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            static public Mat<T> operator +(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] += (dynamic)x; return tm; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            static public Mat<T> operator +(Mat<T> a, Mat<T> b) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] += (dynamic)b[r, c]; return tm; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            static public Mat<T> operator -(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] -= (dynamic)x; return tm; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            static public Mat<T> operator -(Mat<T> a, Mat<T> b) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] -= (dynamic)b[r, c]; return tm; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            static public Mat<T> operator *(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] *= (dynamic)x; return tm; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            static public Mat<T> operator *(Mat<T> a, Mat<T> b) { var nr = a.m.GetLength(0); var nc = b.m.GetLength(1); var tm = new T[nr, nc]; for (int i = 0; i < nr; ++i) for (int j = 0; j < nc; ++j) tm[i, j] = (dynamic)0; for (int r = 0; r < nr; ++r) for (int c = 0; c < nc; ++c) for (int i = 0; i < a.m.GetLength(1); ++i) tm[r, c] += a[r, i] * (dynamic)b[i, c]; return tm; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            static public Mat<T> Pow(Mat<T> x, long y) { var n = x.m.GetLength(0); var t = (Mat<T>)new T[n, n]; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) t[i, j] = (dynamic)(i == j ? 1 : 0); while (y != 0) { if ((y & 1) == 1) t *= x; x *= x; y >>= 1; } return t; }
        }
        class Tree
        {
            long N; int l; List<long>[] p; int[] d; long[][] pr; long r; Tuple<long, long, int>[] e; Tuple<long, long>[] b; bool lca; bool euler; bool bfs;
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public Tree(List<long>[] p_, long r_) { N = p_.Length; p = p_; r = r_; lca = false; euler = false; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public Tuple<long, long>[] FromRoot() { if (!bfs) { var nb = new List<Tuple<long, long>>(); var q = new Queue<long>(); var d = new bool[N]; nb.Add(Tuple.Create(r, -1L)); d[r] = true; q.Enqueue(r); while (q.Count > 0) { var w = q.Dequeue(); foreach (var i in p[w]) { if (d[i]) continue; d[i] = true; q.Enqueue(i); nb.Add(Tuple.Create(i, w)); } } b = nb.ToArray(); bfs = true; } return b; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public Tuple<long, long>[] FromLeaf() => FromRoot().Reverse().ToArray();
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public Tuple<long, long, int>[] Euler() { if (!euler) { var ne = new List<Tuple<long, long, int>>(); var s = new Stack<Tuple<long, long>>(); var d = new bool[N]; d[r] = true; s.Push(Tuple.Create(r, -1L)); while (s.Count > 0) { var w = s.Peek(); var ad = true; foreach (var i in p[w.Item1]) { if (d[i]) continue; d[i] = true; ad = false; s.Push(Tuple.Create(i, w.Item1)); } if (!ad || p[w.Item1].Count == 1) ne.Add(Tuple.Create(w.Item1, w.Item2, 1)); if (ad) { s.Pop(); ne.Add(Tuple.Create(w.Item1, w.Item2, -1)); } } e = ne.ToArray(); euler = true; } return e; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public long LCA(long u, long v) { if (!lca) { l = 0; while (N > (1 << l)) l++; d = new int[N]; pr = Repeat(0, l).Select(_ => new long[N]).ToArray(); d[r] = 0; pr[0][r] = -1; var q = new Stack<long>(); q.Push(r); while (q.Count > 0) { var w = q.Pop(); foreach (var i in p[w]) { if (i == pr[0][w]) continue; q.Push(i); d[i] = d[w] + 1; pr[0][i] = w; } } for (var k = 0; k + 1 < l; k++) for (var w = 0; w < N; w++) if (pr[k][w] < 0) pr[k + 1][w] = -1; else pr[k + 1][w] = pr[k][pr[k][w]]; lca = true; } if (d[u] > d[v]) { var t = u; u = v; v = t; } for (var k = 0; k < l; k++) if ((((d[v] - d[u]) >> k) & 1) != 0) v = pr[k][v]; if (u == v) return u; for (var k = l - 1; k >= 0; k--) if (pr[k][u] != pr[k][v]) { u = pr[k][u]; v = pr[k][v]; } return pr[0][u]; }
        }
        class BT<T> where T : IComparable
        {
            class Node { public Node l; public Node r; public T v; public bool b; }
            Comparison<T> c; Node r; bool ch; T lm;
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public BT(Comparison<T> _c) { c = _c; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public BT() : this((x, y) => x.CompareTo(y)) { }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            bool R(Node n) => n != null && !n.b;
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            bool B(Node n) => n != null && n.b;
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            Node RtL(Node n) { Node m = n.r, t = m.l; m.l = n; n.r = t; return m; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            Node RtR(Node n) { Node m = n.l, t = m.r; m.r = n; n.l = t; return m; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            Node RtLR(Node n) { n.l = RtL(n.l); return RtR(n); }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            Node RtRL(Node n) { n.r = RtR(n.r); return RtL(n); }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public void Add(T x) { r = A(r, x); r.b = true; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            Node A(Node n, T x) { if (n == null) { ch = true; return new Node() { v = x }; } var r = c(x, n.v); if (r < 0) { n.l = A(n.l, x); return Bl(n); } if (r > 0) { n.r = A(n.r, x); return Bl(n); } ch = false; return n; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            Node Bl(Node n) { if (!ch) return n; if (!B(n)) return n; if (R(n.l) && R(n.l.l)) { n = RtR(n); n.l.b = true; } else if (R(n.l) && R(n.l.r)) { n = RtLR(n); n.l.b = true; } else if (R(n.r) && R(n.r.l)) { n = RtRL(n); n.r.b = true; } else if (R(n.r) && R(n.r.r)) { n = RtL(n); n.r.b = true; } else ch = false; return n; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public void Remove(T x) { r = Rm(r, x); if (r != null) r.b = true; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            Node Rm(Node n, T x) { if (n == null) { ch = false; return n; } var r = c(x, n.v); if (r < 0) { n.l = Rm(n.l, x); return BlL(n); } if (r > 0) { n.r = Rm(n.r, x); return BlR(n); } if (n.l == null) { ch = n.b; return n.r; } n.l = RmM(n.l); n.v = lm; return BlL(n); }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            Node RmM(Node n) { if (n.r != null) { n.r = RmM(n.r); return BlR(n); } lm = n.v; ch = n.b; return n.l; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            Node BlL(Node n) { if (!ch) return n; if (B(n.r) && R(n.r.l)) { var b = n.b; n = RtRL(n); n.b = b; n.l.b = true; ch = false; } else if (B(n.r) && R(n.r.r)) { var b = n.b; n = RtL(n); n.b = b; n.r.b = true; n.l.b = true; ch = false; } else if (B(n.r)) { ch = n.b; n.b = true; n.r.b = false; } else { n = RtL(n); n.b = true; n.l.b = false; n.l = BlL(n.l); ch = false; } return n; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            Node BlR(Node n) { if (!ch) return n; if (B(n.l) && R(n.l.r)) { var b = n.b; n = RtLR(n); n.b = b; n.r.b = true; ch = false; } else if (B(n.l) && R(n.l.l)) { var b = n.b; n = RtR(n); n.b = b; n.l.b = true; n.r.b = true; ch = false; } else if (B(n.l)) { ch = n.b; n.b = true; n.l.b = false; } else { n = RtR(n); n.b = true; n.r.b = false; n.r = BlR(n.r); ch = false; } return n; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public bool Have(T x) { var t = FindUpper(x); return t.Item1 && t.Item2.CompareTo(x) == 0; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public Tuple<bool, T> FindUpper(T x) { var v = FU(r, x); return v == null ? Tuple.Create(false, default(T)) : v; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            Tuple<bool, T> FU(Node n, T x) { if (n == null) return null; var r = c(x, n.v); if (r < 0) { var v = FU(n.l, x); return v == null ? Tuple.Create(true, n.v) : v; } if (r > 0) return FU(n.r, x); return Tuple.Create(true, n.v); }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public Tuple<bool, T> FindLower(T x) { var v = FL(r, x); return v == null ? Tuple.Create(false, default(T)) : v; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            Tuple<bool, T> FL(Node n, T x) { if (n == null) return null; var r = c(x, n.v); if (r < 0) return FL(n.l, x); if (r > 0) { var v = FL(n.r, x); return v == null ? Tuple.Create(true, n.v) : v; } return Tuple.Create(true, n.v); }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public T Min() { Node n = r, p = null; while (n != null) { p = n; n = n.l; } return p == null ? default(T) : p.v; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public T Max() { Node n = r, p = null; while (n != null) { p = n; n = n.r; } return p == null ? default(T) : p.v; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public bool Any() => r != null;
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public int CountSlow() => L(r).Count();
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public IEnumerable<T> List() => L(r);
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            IEnumerable<T> L(Node n) { if (n == null) yield break; foreach (var i in L(n.l)) yield return i; yield return n.v; foreach (var i in L(n.r)) yield return i; }
        }
    }
}


using System;

namespace ConsoleApp15
{
    class Program
    {
        static void Main(string[] args)
        {
            var t = int.Parse(Console.ReadLine());

            while (t-- > 0)
            {
                var n = int.Parse(Console.ReadLine());

                if (n % 2 == 0)
                {
                    var a = n / 2;
                    Console.WriteLine(a + " " + a);
                    continue;
                }
                var b = true;
                for (int i = 2; i * i <= n; i++)
                {
                    if (n % i == 0)
                    {
                        Console.WriteLine((n / i) + " " + (n - (n / i)));
                        b = false;
                        break;
                    }
                }

                if (b) { Console.WriteLine("1 "+(n-1)); }

            }
        }
    }
}


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

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

            int[,] guardData = new int[4, 4];

            for (int i = 0; i < 4; i++)
            {
                var input = Console.ReadLine();
                var input2 = input.Split(' ');
                for (int a = 0; a < 4; a++)
                {
                    guardData[i, a] = int.Parse(input2[a]);
                }
            }

            int min;
            int min2;
            int spot = 0;
            int i1 = 0;
            int i2 = 0;
            for (int i = 0; i < 4; i++)
            {
                min = Math.Min(guardData[i, 0], guardData[i, 1]);
                min2 = Math.Min(guardData[i, 2], guardData[i, 3]);

                if ((min + min2) <= money)
                {
                    if (min == guardData[i, 0])
                    {
                        i1 = guardData[i, 0];
                    }
                    else
                    {
                        i1 = guardData[i, 1];
                    }

                    if (min2 == guardData[i, 2])
                    {
                        i2 = guardData[i, 2];
                    }
                    else
                    {
                        i2 = guardData[i, 3];
                    }
                    spot = i + 1;

                    if (min+min2 < money);
                    {
                        i2 += (money-(min+min2));
                    }
                }
            }
            if (spot > 0)
            {
                Console.WriteLine(spot + " " + i1 + " " + i2);
            }
            else
            {
                Console.WriteLine(-1);
            }
            //Console.ReadLine();
        }
    }
}