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

namespace Task
{
    class Subj
    {
        public long a, b;
        public int c;
    }

    class Program
    {
        Subj[] subjects;

        bool[, ,] done;
        long[, ,] memo;

        int[, ,] nextSubjId;
        int[, ,] nextComplexityShift;

        int n;
        int k;

        long getMax(int day, int lastSubjId, int complexityShift)
        {
            if (day == n)
                return 0;

            if (!done[day, lastSubjId, complexityShift])
            {
                long ans = -1;
                int bestNextSubjId = -1;
                int bestComplexityShift = -1;

                for (int nextSubjId = 0; nextSubjId < subjects.Length; nextSubjId++)
                {
                    Subj nextSubj = subjects[nextSubjId];
                    if (day != 0 && subjects[lastSubjId].c >= nextSubj.c)
                        continue;

                    if (day == 0)
                    {
                        for (long complexity = nextSubj.a; complexity <= nextSubj.b; complexity++)
                        {
                            int nextShift = (int)(complexity - nextSubj.a);
                            long temp = getMax(day + 1, nextSubjId, nextShift);
                            if (temp == -1)
                                continue;

                            temp += complexity;
                            if (temp > ans)
                            {
                                ans = temp;
                                bestNextSubjId = nextSubjId;
                                bestComplexityShift = nextShift;
                            }
                        }
                    }
                    else
                    {
                        Subj lastSubj = subjects[lastSubjId];
                        for (int mode = 0; mode < 2; mode++)
                        {
                            long nextComplexity = mode == 0 ? (lastSubj.a + complexityShift) * k : ((lastSubj.a + complexityShift) + k);
                            if (nextComplexity < nextSubj.a || nextComplexity > nextSubj.b)
                                continue;

                            int nextShift = (int)(nextComplexity - nextSubj.a);
                            long temp = getMax(day + 1, nextSubjId, nextShift);
                            if (temp == -1)
                                continue;

                            temp += nextComplexity;
                            if (temp > ans)
                            {
                                ans = temp;
                                bestNextSubjId = nextSubjId;
                                bestComplexityShift = nextShift;
                            }
                        }
                    }
                }

                memo[day, lastSubjId, complexityShift] = ans;

                if (ans >= 0)
                {
                    nextSubjId[day, lastSubjId, complexityShift] = bestNextSubjId;
                    nextComplexityShift[day, lastSubjId, complexityShift] = bestComplexityShift;
                }

                done[day, lastSubjId, complexityShift] = true;

            }

            return memo[day, lastSubjId, complexityShift];

        }

        void Solve()
        {
            // Place your code here
            n = io.NextInt();
            int m = io.NextInt();
            k = io.NextInt();

            subjects = new Subj[m];

            for (int i = 0; i < m; i++)
            {
                Subj s = new Subj();
                s.a = io.NextLong();
                s.b = io.NextLong();
                s.c = io.NextInt();
                subjects[i] = s;
            }

            done = new bool[n, m, 101];
            memo = new long[n, m, 101];
            nextSubjId = new int[n, m, 101];
            nextComplexityShift = new int[n, m, 101];

            long ans = getMax(0, 0, 0);

            if (ans == -1)
            {
                io.Print("NO");
                return;
            }

            io.Print("YES");
            int curSubj = 0;
            int curShift = 0;
            for (int day = 0; day < n; day++)
            {
                int nextSubj = nextSubjId[day, curSubj, curShift];
                int nextShift = nextComplexityShift[day, curSubj, curShift];

                io.PrintLine("");
                io.Print("{0} {1}", nextSubj + 1, nextShift + subjects[nextSubj].a);

                curSubj = nextSubj;
                curShift = nextShift;
            }

        }

        MyIo io = new MyIo();

        static void Main(string[] args)
        {
            var p = new Program();

            p.Solve();
            p.io.Close();
        }
    }

    class MyIo
    {
        char[] separators = new char[] { ' ', '\t' };

#if TEST
        TextReader inputStream = new StreamReader("..\\..\\input.txt");
#else
        TextReader inputStream = System.Console.In;
#endif
        TextWriter outputStream = Console.Out;

        string[] tokens;
        int pointer;

        public string NextLine()
        {
            try
            {
                return inputStream.ReadLine();
            }
            catch (IOException)
            {
                return null;
            }
        }

        public string NextString()
        {
            try
            {
                while (tokens == null || pointer >= tokens.Length)
                {
                    tokens = NextLine().Split(separators, StringSplitOptions.RemoveEmptyEntries);
                    pointer = 0;
                }
                return tokens[pointer++];
            }
            catch (IOException)
            {
                return null;
            }
        }

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

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

        public void Print(string format, params object[] args)
        {
            outputStream.Write(format, args);
        }

        public void PrintLine(string format, params object[] args)
        {
            outputStream.WriteLine(format, args);
        }

        public void Print<T>(T o)
        {
            outputStream.Write(o);
        }

        public void PrintLine<T>(T o)
        {
            outputStream.WriteLine(o);
        }

        public void Close()
        {
            inputStream.Close();
            outputStream.Close();
        }
    }
}


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

namespace B_Mahmud_and_triangle
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] inp = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            List<int> ribs = inp.ToList();
            ribs.Sort();

            for (int i = 0; i < inp.Length - 2; i++)
                if (ribs[i] + ribs[i + 1] > ribs[i + 2]) { Console.WriteLine("YES"); return; }
            Console.WriteLine("NO");
        }
    }
}


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

namespace Template {
    class Program {
        static string[] presidents = {
            "Washington",
            "Adams",
            "Jefferson",
            "Madison",
            "Monroe",
            "Adams",
            "Jackson",
            "Van Buren",
            "Harrison",
            "Tyler",
            "Polk",
            "Taylor",
            "Fillmore",
            "Pierce",
            "Buchanan",
            "Lincoln",
            "Johnson",
            "Grant",
            "Hayes",
            "Garfield",
            "Arthur",
            "Cleveland",
            "Harrison",
            "Cleveland",
            "McKinley",
            "Roosevelt",
            "Taft",
            "Wilson",
            "Harding",
            "Coolidge",
            "Hoover",
            "Roosevelt",
            "Truman",
            "Eisenhower",
            "Kennedy",
            "Johnson",
            "Nixon",
            "Ford",
            "Carter",
            "Reagan",
            "Bush",
            "Clinton",
            "Bush",
            "Obama"

        };
        static void Main(string[] args) {
            string ProgramName = "A";
#if ONLINE_JUDGE
#else
            StreamWriter sw = new StreamWriter("pr" + ProgramName + ".out");
            Console.SetOut(sw);
            Console.SetIn(new StreamReader("pr" + ProgramName + ".in"));
#endif

            int a = int.Parse(Console.ReadLine());
            //string s = presidents[a - 1];
            //string[] ss = s.Split(' ');
            //for (int i = 1; i < ss.Count() - 1; i++) {
            //    Console.Write(ss[i]);
            //    Console.Write(' ');
            //}

            //Console.Write(ss[ss.Count() - 1]);
            Console.WriteLine(presidents[a - 1]);
#if ONLINE_JUDGE
#else
            sw.Close();
#endif
        }
    }
}


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

namespace B.Mancala
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            long[] Holes = new long[14];
            for (int i = 0; i < 14; i++)
            {
                Holes[i] = int.Parse(input[i]);
            }

            long score = 0;
            for (int i = 0; i < 14; i++)
            {
                if (Holes[i] == 0)
                {
                    continue;
                }
                long[] temp = (long[])Holes.Clone();
                long num = Holes[i];
                temp[i] = 0;
                long add = num / 14;
                long bonus = num % 14;
                for (int y = i+1; y <= i+14; y++)
                {
                    temp[y % 14] += add;
                    if (bonus > 0)
                    {
                        temp[y % 14]++;
                        bonus--;
                    }
                }
                long tempScore = SumAll(temp);
                if (tempScore > score)
                {
                    score = tempScore;
                }
            }
            Console.WriteLine(score);
            //Console.ReadKey();
        }

        static long SumAll(long[] Holes)
        {
            long sum = 0;
            for (int i = 0; i < 14; i++)
            {
                if (Holes[i] % 2 == 0)
                    sum += Holes[i];
            }

            return sum;
        }
    }

}


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

namespace CodeforcesTemplate
{
    public static class Permutation
    {
        private static bool Next(ref int[] arr)
        {
            int k, j, l;
            for (j = arr.Length - 2; (j >= 0) && (arr[j] >= arr[j + 1]); j--) { }
            if (j == -1)
            {
                arr = arr.OrderBy(c => c).ToArray();
                return false;
            }
            for (l = arr.Length - 1; (arr[j] >= arr[l]) && (l >= 0); l--) { }
            var tmp = arr[j];
            arr[j] = arr[l];
            arr[l] = tmp;
            for (k = j + 1, l = arr.Length - 1; k < l; k++, l--)
            {
                tmp = arr[k];
                arr[k] = arr[l];
                arr[l] = tmp;
            }
            return true;
        }
        public static IEnumerable<int[]> AllPermutations(int[] arr)
        {
            do yield return arr;
            while (Next(ref arr));
        }
    }

    class Program
    {
        private const string FILENAME = "distance4";

        private const string INPUT = FILENAME + ".in";

        private const string OUTPUT = FILENAME + ".out";

        private static Stopwatch _stopwatch = new Stopwatch();

        private static StreamReader _reader = null;
        private static StreamWriter _writer = null;

        private static string[] _curLine;
        private static int _curTokenIdx;

        private static char[] _whiteSpaces = new char[] { ' ', '\t', '\r', '\n' };

        static int Count(string source, string key)
        {

            List<int> indices = new List<int>();

            int index = source.IndexOf(key, 0);

            while (index > -1)
            {
                indices.Add(index);
                index = source.IndexOf(key, index + key.Length);
            }

            return indices.Count();
        }

        public static string Check(string s)
        {
            string letters = "aeiouy";

            while (true)
            {
                bool used = false;

                for (int i = 0; i < s.Length - 1; i++)
                {
                    if (letters.Contains(s[i].ToString()) && letters.Contains(s[i + 1].ToString()))
                    {
                        s = s.Remove(i + 1, 1);

                        used = true;
                    }
                }

                if (!used)
                {
                    return s;
                }
            }
        }

        private static string ReadNextToken()
        {
            if (_curTokenIdx >= _curLine.Length)
            {
                //Read next line
                string line = _reader.ReadLine();
                if (line != null)
                    _curLine = line.Split(_whiteSpaces, StringSplitOptions.RemoveEmptyEntries);
                else
                    _curLine = new string[] { };
                _curTokenIdx = 0;
            }

            if (_curTokenIdx >= _curLine.Length)
                return null;

            return _curLine[_curTokenIdx++];
        }

        private static int ReadNextInt()
        {
            return int.Parse(ReadNextToken());
        }

        private static void RunTimer()
        {
#if (DEBUG)

            _stopwatch.Start();

#endif
        }

        private static void Main(string[] args)
        {

#if (DEBUG)
            double before = GC.GetTotalMemory(false);
#endif
            int n = int.Parse(Console.ReadLine());

            string a = Console.ReadLine();

            string a1 = string.Empty;
            string a2 = string.Empty;

            int count = a.Length;

            if (n % 2 != 0)
            {
                for (int i = (n - 1) / 2; i >= 0; i--)
                {
                    a1 = a.Substring(0, i);

                    a2 = a.Substring(i, i);

                    if (a1 == a2 && i > 0)
                    {
                        count = count - a1.Length + 1;
                        break;
                    }
                }
            }
            else
            {
                for (int i = n / 2; i >= 0; i--)
                {
                    a1 = a.Substring(0, i);

                    a2 = a.Substring(i, i);
                    if (a1 == a2 && i > 0)
                    {
                        count = count - a1.Length + 1;
                        break;
                    }
                }

            }

            Console.WriteLine(count);

#if (DEBUG)
            _stopwatch.Stop();

            double after = GC.GetTotalMemory(false);

            double consumedInMegabytes = (after - before) / (1024 * 1024);

            Console.WriteLine($"Time elapsed: {_stopwatch.Elapsed}");

            Console.WriteLine($"Consumed memory (MB): {consumedInMegabytes}");

            Console.ReadKey();
#endif

        }

        private static int CountLeadZeros(string source)
        {
            int countZero = 0;

            for (int i = source.Length - 1; i >= 0; i--)
            {
                if (source[i] == '0')
                {
                    countZero++;
                }

                else
                {
                    break;
                }

            }

            return countZero;
        }

        private static string ReverseString(string source)
        {
            char[] reverseArray = source.ToCharArray();

            Array.Reverse(reverseArray);

            string reversedString = new string(reverseArray);

            return reversedString;
        }

        private static int[] CopyOfRange(int[] src, int start, int end)
        {
            int len = end - start;
            int[] dest = new int[len];
            Array.Copy(src, start, dest, 0, len);
            return dest;
        }

        private static string StreamReader()
        {

            if (_reader == null)
                _reader = new StreamReader(INPUT);
            string response = _reader.ReadLine();
            if (_reader.EndOfStream)
                _reader.Close();
            return response;

        }

        private static void StreamWriter(string text)
        {

            if (_writer == null)
                _writer = new StreamWriter(OUTPUT);
            _writer.WriteLine(text);

        }

        private static int BFS(int start, int end, int[,] arr)
        {
            Queue<KeyValuePair<int, int>> queue = new Queue<KeyValuePair<int, int>>();
            List<bool> visited = new List<bool>();
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                visited.Add(false);
            }

            queue.Enqueue(new KeyValuePair<int, int>(start, 0));
            KeyValuePair<int, int> node;
            int level = 0;
            bool flag = false;

            while (queue.Count != 0)
            {
                node = queue.Dequeue();
                if (node.Key == end)
                {
                    return node.Value;
                }
                flag = false;
                for (int i = 0; i < arr.GetLength(0); i++)
                {

                    if (arr[node.Key, i] == 1)
                    {
                        if (visited[i] == false)
                        {
                            if (!flag)
                            {
                                level = node.Value + 1;
                                flag = true;
                            }
                            queue.Enqueue(new KeyValuePair<int, int>(i, level));
                            visited[i] = true;
                        }
                    }
                }

            }
            return 0;

        }

        private static void Write(string source)
        {
            File.WriteAllText(OUTPUT, source);
        }

        private static string ReadString()
        {
            return File.ReadAllText(INPUT);
        }

        private static void WriteStringArray(string[] source)
        {
            File.WriteAllLines(OUTPUT, source);
        }

        private static string[] ReadStringArray()
        {
            return File.ReadAllLines(INPUT);
        }

        private static int[] GetIntArray()
        {
            return ReadString().Split(' ').Select(int.Parse).ToArray();
        }

        private static double[] GetDoubleArray()
        {
            return ReadString().Split(' ').Select(double.Parse).ToArray();
        }

        private static int[,] ReadINT2XArray(List<string> lines)
        {
            int[,] arr = new int[lines.Count, lines.Count];

            for (int i = 0; i < lines.Count; i++)
            {
                int[] row = lines[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();

                for (int j = 0; j < lines.Count; j++)
                {
                    arr[i, j] = row[j];
                }
            }

            return arr;
        }
    }
}


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

class Program
{
    private static int Next()
    {
        int c;
        int res = 0;
        do
        {
            c = reader.Read();
            if (c == -1)
                return res;
        } while (c < '0' || c > '9');
        res = c - '0';
        while (true)
        {
            c = reader.Read();
            if (c < '0' || c > '9')
                return res;
            res *= 10;
            res += c - '0';
        }
    }
    private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), Encoding.ASCII, false, 1024 * 10);
    private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), Encoding.ASCII, 1024 * 10);

    static void Main(String[] args)
    {
        var data = Console.ReadLine().Split(' ').Select(long.Parse).ToList();
        //var n = int.Parse(Console.ReadLine());
        var a = data[0];
        var b = data[1];
        var h = data[2];
        var w = data[3];
        var n = data[4];

        data = Console.ReadLine().Split(' ').Select(long.Parse).ToList();
        data.Sort();
        data.Reverse();
        var all = new Dictionary<int, List<Tuple<long, long>>>();
        all[0] = new List<Tuple<long, long>>();
        all[0].Add(new Tuple<long, long>(h, w));
        for(var i = 0; i < Math.Min(60, n); i++)
        {
            var cur = data[i];
            all[i + 1] = new List<Tuple<long, long>>();
            var used = new Dictionary<string, bool>();
            foreach (var prev in all[i])
            {
                if ((prev.Item1 >= a && prev.Item2 >= b) || (prev.Item2 >= a && prev.Item1 >= b))
                {
                    Console.WriteLine(i);
                    return;
                }
                if(prev.Item1 * cur < 0|| prev.Item2 * cur < 0)
                {
                    Console.WriteLine(-1);
                    return;
                }
                var new1 = new Tuple<long, long>(prev.Item1 * cur, prev.Item2);
                var new2 = new Tuple<long, long>(prev.Item1, prev.Item2 * cur);
                //if (prev.Item1 < a && prev.Item2 < b)
                //{
                    if (!used.ContainsKey(new1.Item1 + "#" + new1.Item2))
                    {
                        all[i + 1].Add(new1);
                        used[new1.Item1 + "#" + new1.Item2] = true;
                    }
                    if (!used.ContainsKey(new2.Item1 + "#" + new2.Item2))
                    {
                        all[i + 1].Add(new2);
                        used[new2.Item1 + "#" + new2.Item2] = true;
                    }

            }
        }

        foreach (var prev in all[(int)Math.Min(60, n)])
        {
            if (prev.Item1 >= a && prev.Item2 >= b)
            {
                Console.WriteLine((int)Math.Min(60, n));
                return;
            }
        }

        Console.WriteLine(-1);
    }
}


using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.IO;

namespace TestCodes
{
    class Problem
    {
        static void Main()
        {
            var w = ReadLine();

            if (string.IsNullOrEmpty(w))
                WriteLine("YES");
            else if (w.Length <= 2)
				WriteLine("YES");
            else if (((w[0] - 'A' + w[1] - 'A') % 26) == (w[2] - 'A'))
                WriteLine("YES");
            else
                WriteLine("NO");
        }
    }
}


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

namespace ConsoleApp1
{
	class Program
	{
		static void Main(string[] args)
		{
			string[] str = Console.ReadLine().Split(new char[] { ' ' });

			long x = Convert.ToInt64(str[0]);
			long n = Convert.ToInt64(str[1]);

			List<long> primes = new List<long>();

			for (long i = 2; i * i <= x; ++i)
			{
				if (x % i == 0 && isPrime(i))
					primes.Add(i);

				if (x % i == 0 && isPrime(x / i) && !primes.Contains(x / i))
					primes.Add(x / i);
			}

			if (isPrime(x))
				primes.Add(x);

			long mod = 1000000007;
			long res = 1;

			List<long> powers = new List<long>();

			for (int i = 0; i < primes.Count(); ++i)
			{
				powers.Add(powerInFact(n, primes[i]));
			}

			for (int i = 0; i < primes.Count(); ++i)
			{
				if (powers[i] != 0)
				{
					res = (res * (binpow(primes[i], powers[i], mod) % mod)) % mod;
				}
			}

			Console.WriteLine(res);
			Console.ReadLine();
		}

		public static bool isPrime(long n)
		{
			for (long i = 2; i * i <= n; ++i)
			{
				if (n % i == 0)
					return false;
			}

			return true;
		}

		public static long powerInFact(long n, long k)
		{
			long res = 0;
			while (n > 0)
			{
				n /= k;
				res += n;
			}
			return res;
		}

		public static long binpow(long a, long n, long mod)
		{
			if (n == 0)
				return 1;
			if (n % 2 == 1)
				return ((binpow(a, n - 1, mod) % mod) * a) % mod;
			else
			{
				long b = binpow(a, n / 2, mod) % mod;
				return (b * b) % mod;
			}
		}
	}
}


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

namespace B_Sum
{
    public class Sum
    {
        static int GetNotation(string input)
        {
            int max = 0;
            foreach (char c in input)
                max = Math.Max(max, (int)c);
            return max - 47;
        }

        static int Calculate(int notation, int result_10)
        {
            int output = 0;
            int temp = result_10;

            do
            {
                output++;
                temp = temp / notation;
            } while (temp >= notation);
            output++;
            return output;

        }

        static int Convert_10(int notation, string x)
        {

            int count = 0;
            int output = 0;
            for (int i = x.Length - 1; i >= 0; i--)
            {
                int temp = ((int)x[i] - 48) * Pow(notation, count);
                count++;
                output += temp;
            }
            return output;
        }

        static int Pow(int x, int g)
        {
            if (g == 0) return 1;
            else return x * Pow(x, g - 1);
        }

        static public int MaxLength(string input)
        {
            int notation = GetNotation(input);
            string[] s = input.Split(' ');
            int x = Convert_10(notation, s[0]);
            int y = Convert_10(notation, s[1]);
            return Calculate(notation, x + y);
        }
    }
    class Program
    {

        static void Main(string[] args)
        {
            Sum X = new Sum();
            Console.WriteLine(Sum.MaxLength(Console.ReadLine()));
            //Console.WriteLine(Convert_10(9, "78"));
        }
    }
}


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

namespace Primes_or_Palindromes
{
    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)
        {
            var pals = new List<int>();

            for (int j = 1; j < 10; j++)
            {
                pals.Add(j);
            }
            for (int i = 1; i < 1000; i++)
            {
                string s = i.ToString();
                char[] cc = s.ToCharArray();
                Array.Reverse(cc);
                var sr = new string(cc);

                pals.Add(int.Parse(s + sr));
                for (int j = 0; j < 10; j++)
                {
                    pals.Add(int.Parse(s + j + sr));
                }
            }

            pals.Sort();

            var primes = new List<int> {2, 3, 5, 7};
            for (int i = 11; i < 2000000; i += 2)
            {
                bool f = false;
                for (int j = 0; primes[j]*primes[j] <= i; j++)
                {
                    if (i%primes[j] == 0)
                    {
                        f = true;
                        break;
                    }
                }
                if (!f)
                    primes.Add(i);
            }

            long p = Next();
            long q = Next();

            int l = 1;
            for (int i = 1; i < 2000000; i++)
            {
                int index1 = primes.BinarySearch(i);
                if (index1 < 0)
                    index1 = ~index1;
                else
                {
                    index1++;
                }
                int index2 = pals.BinarySearch(i);
                if (index2 < 0)
                    index2 = ~index2;
                else
                {
                    index2++;
                }

                if (q*index1 <= p*index2)
                {
                    l = i;
                }
            }

            writer.WriteLine(l);
            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';
            }
        }
    }
}


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

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

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

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

        const ulong MOD = 998244353ul;

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

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

            S[i, 0] = m;

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

        }

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

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

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

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

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

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

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

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

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

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

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

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

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


using System;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.IO;
using System.Linq;

namespace Codeforces.R316D1
{
    public struct ModInteger : IEquatable<ModInteger>
    {
        readonly int mod;
        readonly long value;
        public ModInteger(int mod, long value = 0L)
        {
            this.mod = mod;
            this.value = value % mod;
            if (value < 0)
            {
                this.value = value + mod;
            }
        }

        public bool Equals(ModInteger other)
        {
            return mod == other.mod && value == other.value;
        }

        public override bool Equals(object obj)
        {
            if (!(obj is ModInteger))
            {
                return false;
            }
            var other = (ModInteger)obj;
            return Equals(other);
        }

        public override int GetHashCode()
        {
            return (int)value;
        }

        public static bool operator ==(ModInteger left, ModInteger right)
        {
            return left.Equals(right);
        }

        public static bool operator !=(ModInteger left, ModInteger right)
        {
            return !(left == right);
        }

        public static ModInteger LeftShift(ModInteger left, int right)
        {
            return left << right;
        }

        public static ModInteger operator <<(ModInteger left, int right)
        {
            if (right > 32)
            {
                return left << 32 << (right - 32);
            }
            return new ModInteger(left.mod, left.value << right);
        }

        public static ModInteger Add(ModInteger left, int right)
        {
            return left + right;
        }

        public static ModInteger operator +(ModInteger left, int right)
        {
            return new ModInteger(left.mod, left.value + right);
        }

        public static ModInteger operator ++(ModInteger m)
        {
            return m + 1;
        }

        public static ModInteger Multiply(ModInteger left, int right)
        {
            return new ModInteger(left.mod, left.value * right);
        }

        public static ModInteger operator *(ModInteger left, int right)
        {
            return Multiply(left, right);
        }

        public static ModInteger Div(int left, int right, int mod)
        {
            return Pow(right, mod - 2, mod) * left;
        }

        public static ModInteger Pow(long x, int n, int mod)
        {
            var res = 1L;
            for (; n > 0; n >>= 1)
            {
                if ((n & 1) == 1)
                {
                    res = res * x % mod;
                }
                x = x * x % mod;
            }
            return new ModInteger(mod, res);
        }

        public static ModInteger ToModInteger(int value)
        {
            return new ModInteger(0, value);
        }

        public static implicit operator int(ModInteger value)
        {
            return (int)value.value;
        }

        public static int ToInt32(ModInteger value)
        {
            return value;
        }

        public static ModInteger Increment(ModInteger item)
        {
            return ++item;
        }
    }
    public static class Solver
    {
        const int mod = 1000000007;
        public static void Main()
        {
            using (var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false })
            {
                Solve(Console.In, sw);
            }
        }

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

            tw.WriteLine(Parse(tr));
        }

        private static int Parse(TextReader tr)
        {
            var info = CultureInfo.InvariantCulture;
            tr.ReadLine();
            var a = tr.ReadLine().Split().Select(x => int.Parse(x, info)).ToArray();

            return Calc(a);
        }

        private static ModInteger Calc(int[] a)
        {
            int num1 = a.Count(x => x == 1);
            int num2 = a.Length - num1;

            return F(num1, num2);
        }

        private static ModInteger F(int a, int b)
        {
            var res = new ModInteger(mod, 1);

            for (int i = 0; i < b; ++i)
            {
                res *= a + 1 + i;
            }

            if (a == 0)
            {
                return res;
            }

            var I = new ModInteger[a + 1];
            I[0] = new ModInteger(mod, 1);
            I[1] = new ModInteger(mod, 1);
            for (int i = 2; i <= a; ++i)
            {
                I[i] = I[i - 1] + (i - 1) * I[i - 2];
            }
            return res * I[a];
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Cryptography;

namespace codeforces
{
	class Program
	{
		public class User
		{
			public int c;

			public int r;
		}

		public class Point
		{
			public int x;

			public int y;
		}

		public class Comparer : IComparer<User>
		{
			public int Compare(User x, User y)
			{
				if (x.c < y.c || (x.c == y.c && x.r < y.r))
					return -1;
				return 1;
			}
		}

		public static long getGcd(long a, long b)
		{
			if (b == 0)
				return a;
			return getGcd(b, a % b);
		}

		public static void WriteYESNO(bool x, string yes = "YES", string no = "NO")
		{
			if (x)
				Console.WriteLine(yes);
			else
			{
				Console.WriteLine(no);
			}
		}

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

		public static List<int> getList()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(int.Parse).ToList();
		}

		public static List<long> getLongList()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(long.Parse).ToList();
		}

		public static int Min(int x, int y)
		{
			return Math.Min(x, y);
		}

		public static int Max(int x, int y)
		{
			return Math.Max(x, y);
		}

		public static int Abs(int x)
		{
			return Math.Abs(x);
		}

		public static int getInt()
		{
			var s = Console.ReadLine();
			return int.Parse(s);
		}

		public static long getLong()
		{
			var s = Console.ReadLine();
			return long.Parse(s);
		}

		public static bool Equal(int x, int y, int x1, int y1)
		{
			return x == x1 && y == y1;
		}

		public class Edge
		{
			public int v;

			public int w;
		}

		public class Vertex
		{
			public List<Edge> edges;

			public int ct;

			public bool was;
		}

		public static bool canAuto(string s, string s1)
		{
			var l = 0;
			for (var i = 0; i < s1.Length; ++i)
			{
				while (l < s.Length && s[l] != s1[i])
					l++;
				if (l == s.Length)
					return false;
				l++;
			}
			return true;
		}

		public static bool canArray(string s, string s1)
		{
			var l = s.ToCharArray().ToList();
			var l1 = s1.ToCharArray().ToList();
			l.Sort();
			l1.Sort();
			if (l.Count != l1.Count)
				return false;

			for (var i = 0; i < l.Count; ++i)
				if (l[i] != l1[i])
					return false;

			return true;
		}

		public static bool canBoth(string s, string s1)
		{
			var l = s.ToCharArray().ToList();
			var l1 = s1.ToCharArray().ToList();
			l.Sort();
			l1.Sort();
			var ll = 0;
			for (var i = 0; i < l1.Count; ++i)
			{
				while (ll < l.Count && l[ll] != l1[i])
					ll++;
				if (ll == l.Count)
					return false;
				ll++;
			}

			return true;
		}

		private static void Main(string[] args)
		{
/*			var input = new StreamReader("input.txt");
			var output = new StreamWriter("output.txt");*/
			var pos = new List<List<int>>();
			var ar = new List<List<int>>();
			for (var i = 0; i < 5; ++i)
			{
				pos.Add(new List<int>());
				for (var j = 0; j < 5; ++j)
					pos[i].Add(1);
			}
			ar.Add(getList());
			ar.Add(getList());
			ar.Add(getList());
			for (var i = 0; i < 3; ++i)
				for (var j = 0; j < 3; ++j)
				{
					if (ar[i][j] % 2 == 1)
					{
						var x = i + 1;
						var y = j + 1;
						pos[x - 1][y] = 1 - pos[x - 1][y];
						pos[x][y - 1] = 1 - pos[x][y - 1];
						pos[x][y] = 1 - pos[x][y];
						pos[x][y + 1] = 1 - pos[x][y + 1];
						pos[x + 1][y] = 1 - pos[x + 1][y];
					}
				}
			for (var i = 1; i <= 3; ++i)
			{
				for (var j = 1; j <= 3; ++j)
					Console.Write(pos[i][j]);
				Console.WriteLine();
			}
			Console.ReadLine();
		}
	}
}


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

// (づ*ω*)づﾐ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    int TrailingZeroes(int x)
    {
        int ret = 0;
        while (x % 2 == 0)
        {
            ret++;
            x >>= 1;
        }
        return ret;
    }

    public object Solve()
    {
        int x = ReadInt();
        int k = ReadInt();
        double p = ReadInt() / 100.0;
        double q = 1 - p;

        const int MASK = 1 << 8;
        const int MAX_ONES = 250;
        var dp = new double[MASK, MAX_ONES];

        int rep;
        if (x % MASK == 0)
            rep = TrailingZeroes(x) - 8;
        else
        {
            rep = 0;
            int xx = x >> 8;
            while (xx % 2 == 1)
            {
                rep++;
                xx >>= 1;
            }
        }
        dp[x % MASK, rep] = 1;

        for (int step = 0; step < k; step++)
        {
            var ndp = new double[MASK, MAX_ONES];
            for (int i = 0; i < MASK; i++)
                for (int j = 0; j < MAX_ONES; j++)
                    if (dp[i,j] > 0)
                    {
                        if (i == 0)
                        {
                            ndp[0, j + 1] += dp[0, j] * p;
                            ndp[1, 0] += dp[0, j] * q;
                        }
                        else
                        {
                            int ii = (i << 1) % MASK;
                            int jj;
                            if (ii == 0)
                                jj = 0;
                            else
                                jj = (i >> 7 & 1) == 1 ? j + 1 : 0;
                            ndp[ii, jj] += dp[i, j] * p;

                            ii = i + 1;
                            if (ii == MASK)
                                ndp[0, j] += dp[i, j] * q;
                            else
                                ndp[ii, j] += dp[i, j] * q;
                        }
                    }
            dp = ndp;
        }

        double ans = 0;

        for (int i = 0; i < MASK; i++)
            for (int j = 0; j < MAX_ONES; j++)
                if (i == 0)
                    ans += (8 + j) * dp[0, j];
                else
                    ans += TrailingZeroes(i) * dp[i, j];

        return ans.ToString(CultureInfo.InvariantCulture);
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;

    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = Console.In;
        writer = new StreamWriter(Console.OpenStandardOutput());
#endif
        try
        {
            object result = new Solver().Solve();
            if (result != null)
                writer.WriteLine(result);
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read/Write

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

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

    public static string ReadToken()
    {
        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));
    }

    #endregion
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.AccessControl;
using System.Security.Cryptography;
using System.Web;

class Program
{
    static int Max(int a1, int a2, int a3)
    {
        int max = a1 > a2 ? a1 : a2;
        return a3 > max ? a3 : max;
    }

    static int Max(int a1, int a2)
    {
        return a1 > a2 ? a1 : a2;
    }

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

        var a = new int[n + 1];
        var b = new int[n + 1];
        var c = new int[n + 1];
        var d = new int[n + 1];

        a[1] = 1;
        b[1] = 1;
        c[1] = 1;
        d[1] = 0;

        for (int i = 2; i <= n; i++)
        {
            a[i] = ((b[i - 1] + c[i - 1])%mod + d[i - 1])%mod;
            b[i] = ((a[i - 1] + c[i - 1])%mod + d[i - 1])%mod;
            c[i] = ((b[i - 1] + a[i - 1])%mod + d[i - 1])%mod;
            d[i] = ((b[i - 1] + c[i - 1])%mod + a[i - 1])%mod;
        }

        Console.WriteLine(d[n]);
    }

}


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

namespace prA {
    class Program {
#if ONLINE_JUDGE
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);
#else
        private static readonly StreamWriter writer = new StreamWriter(@"..\..\output");
        private static readonly StreamReader reader = new StreamReader(@"..\..\input");
#endif

        static void Main(string[] args) {
            HashSet<string> set = new HashSet<string>();
            string s = reader.ReadLine();
            char[] a = s.ToCharArray();
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < s.Length; i++) {
                sb.Clear();
                for (int j = i; j < s.Length; j++) {
                    sb.Append(a[j]);
                }
                for (int j = 0; j < i; j++) {
                    sb.Append(a[j]);
                }
                set.Add(sb.ToString());
            }

            writer.Write(set.Count);
            writer.Flush();
#if !ONLINE_JUDGE
            writer.Close();
#endif
        }
        private static int Next() {
            int c;
            int res = 0;
            do {
                c = reader.Read();
                if(c == -1)
                    return res;
            } while(c != '-' && (c < '0' || c > '9'));
            int sign = 1;
            if(c == '-') {
                sign = -1;
                c = reader.Read();
            }
            res = c - '0';
            while(true) {
                c = reader.Read();
                if(c < '0' || c > '9')
                    return res * sign;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(File.OpenText("in.txt"));
            var data = Console.ReadLine().Split().Select(d => int.Parse(d)).ToArray();

            var x = new int[3];
            var y = new int[3];
            x[0] = data[0];
            y[0] = data[1];
            x[1] = data[2];
            y[1] = data[3];
            x[2] = data[4];
            y[2] = data[5];

            for (int i = 0; i < 3; i++)
                for (int j = i + 1; j < 3; j++)
                {
                    var a = length(x[i], y[i], x[j], y[j]);
                    var tp = getOther(i, j);
                    var b = length(x[i], y[i], x[tp], y[tp]);
                    var c = length(x[j], y[j], x[tp], y[tp]);

                    if (checkPif(a, b, c))
                    {
                        Console.WriteLine("RIGHT");
                        return;
                    }
                }

            var ixs = new int[3];
            var iys = new int[3];
            for (int i = 0; i < 3; i++)
                for (int j = i + 1; j < 3; j++)
                {

                    var tp = getOther(i, j);

                    ixs[0] = x[i];
                    ixs[1] = x[j];
                    ixs[2] = x[tp];

                    iys[0] = y[i];
                    iys[1] = y[j];
                    iys[2] = y[tp];

                    for (int k = 0; k < 3; k++)
			        {
                        ixs[k] ++;
                        var a = length(ixs[0], iys[0], ixs[1], iys[1]);
                        var b = length(ixs[0], iys[0], ixs[2], iys[2]);
                        var c = length(ixs[1], iys[1], ixs[2], iys[2]);

                        if (!checkTr(a, b, c))
                        {
                            ixs[k]--;
                            continue;
                        }

                        if (checkPif(a, b, c))
                        {
                            Console.WriteLine("ALMOST");
                            return;
                        }

                        ixs[k]--;
			        }

                    for (int k = 0; k < 3; k++)
                    {
                        ixs[k]--;
                        var a = length(ixs[0], iys[0], ixs[1], iys[1]);
                        var b = length(ixs[0], iys[0], ixs[2], iys[2]);
                        var c = length(ixs[1], iys[1], ixs[2], iys[2]);

                        if (!checkTr(a, b, c))
                        {
                            ixs[k]++;
                            continue;
                        }

                        if (checkPif(a, b, c))
                        {
                            Console.WriteLine("ALMOST");
                            return;
                        }

                        ixs[k]++;
                    }

                    for (int k = 0; k < 3; k++)
                    {
                        iys[k]++;
                        var a = length(ixs[0], iys[0], ixs[1], iys[1]);
                        var b = length(ixs[0], iys[0], ixs[2], iys[2]);
                        var c = length(ixs[1], iys[1], ixs[2], iys[2]);

                        if (!checkTr(a, b, c))
                        {
                            iys[k]--;
                            continue;
                        }

                        if (checkPif(a, b, c))
                        {
                            Console.WriteLine("ALMOST");
                            return;
                        }

                        iys[k]--;
                    }

                    for (int k = 0; k < 3; k++)
                    {
                        iys[k]--;
                        var a = length(ixs[0], iys[0], ixs[1], iys[1]);
                        var b = length(ixs[0], iys[0], ixs[2], iys[2]);
                        var c = length(ixs[1], iys[1], ixs[2], iys[2]);

                        if (!checkTr(a, b, c))
                        {
                            iys[k]++;
                            continue;
                        }

                        if (checkPif(a, b, c))
                        {
                            Console.WriteLine("ALMOST");
                            return;
                        }

                        iys[k]++;
                    }
                }

            Console.WriteLine("NEITHER");

        }

        static HashSet<int> vars = new HashSet<int>() { 0, 1, 2 };
        static int getOther(int a, int b)
        {
            var s = new HashSet<int> { a, b };
            s.SymmetricExceptWith(vars);
            return s.FirstOrDefault();
        }

        static double length(int x1, int y1, int x2, int y2)
        {
            return Math.Sqrt(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2));
        }

        static bool checkTr(double a, double b, double c)
        {
            if (a + b <= c)
            {
                return false;
            }
            else if (a + c <= b)
            {
                return false;
            }
            else if (b + c <= a)
            {
                return false;
            }

            return true;
        }

        static bool checkPif(double a, double b, double c)
        {
            var a2 = a * a;
            var b2 = b * b;
            var c2 = c * c;
            if (Math.Abs(a2 + b2 - c2) < 0.0000001)
            {
                return true;
            }
            else if (Math.Abs(a2 + c2 - b2) < 0.0000001)
            {
                return true;
            }
            else if (Math.Abs(b2 + c2 - a2) < 0.0000001)
            {
                return true;
            }

            return false;
        }
    }
}


using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Globalization;
using System.Threading;

using static System.Math;

namespace FertiLib.Contest.A
{
	public class Solver
	{
		Scanner sr;
		StreamWriter sw;

		bool isMultipleTestCases = true;

		public void Solve()
		{
			var k = sr.ReadInt();
			Console.WriteLine(100 / GCD(k, 100 - k));
		}

		public static long GCD(long a, long b)
		{
			a = Math.Abs(a);
			b = Math.Abs(b);
			while (a > 0)
			{
				b %= a;
				var x = a;
				a = b;
				b = x;
			}
			return b;
		}

		public Solver(Scanner cin, StreamWriter cout)
		{
			this.sr = cin;
			this.sw = cout;
		}

		public void Start()
		{
			int _t = 1;
			if (isMultipleTestCases) _t = sr.ReadInt();
			while (_t-- > 0) Solve();
		}

		public static void YESNO(bool condition) => Console.WriteLine(condition ? "YES" : "NO");
		public static void YesNo(bool condition) => Console.WriteLine(condition ? "Yes" : "No");
		public static void yesno(bool condition) => Console.WriteLine(condition ? "yes" : "no");

		public static T SignOutput<T>(int x, T pos, T zero, T neg) => x == 0 ? zero : (x > 0 ? pos : neg);

		public static T[] CreateArray<T>(int n, Func<int, T> func) => Enumerable.Range(0, n).Select(p => func(p)).ToArray();
		public static T[][] CreateArray<T>(int h, int w, Func<int, int, T> func) => Enumerable.Range(0, h).Select(i => Enumerable.Range(0, w).Select(j => func(i, j)).ToArray()).ToArray();
	}

	public static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);
			var cin = new Scanner();
			var solver = new Solver(cin, sw);
			solver.Start();
			Console.Out.Flush();
		}
	}

	public static class Extention
	{
		public static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x);

		public static int UpperBound<T>(this IList<T> list, T value) => list.BinarySearch(value, true, 0, list.Count, Comparer<T>.Default);
		public static int LowerBound<T>(this IList<T> list, T value) => list.BinarySearch(value, false, 0, list.Count, Comparer<T>.Default);
		public static int BinarySearch<T>(this IList<T> list, T value, bool isUpperBound, int index, int length, Comparer<T> comparer)
		{
			var ng = index - 1;
			var ok = index + length;
			while (ok - ng > 1)
			{
				var mid = ng + (ok - ng) / 2;
				var res = comparer.Compare(list[mid], value);
				if (res < 0 || (isUpperBound && res == 0)) ng = mid;
				else ok = mid;
			}
			return ok;
		}

		public static bool Chmax<T>(ref this T a, T b) where T : struct, IComparable<T>
		{
			if (a.CompareTo(b) >= 0) return false;
			a = b;
			return true;
		}
		public static bool Chmin<T>(ref this T a, T b) where T : struct, IComparable<T>
		{
			if (a.CompareTo(b) <= 0) return false;
			a = b;
			return true;
		}
	}

	public class Scanner
	{
		string[] s;
		int i;

		char[] separator = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Read() => ReadString();

		public string ReadString()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(separator, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return ReadString();
			i = 0;
			return s[i++];
		}

		public string[] ReadStringArray(int N)
		{
			string[] Array = new string[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = ReadString();
			}
			return Array;
		}

		public int ReadInt() => int.Parse(ReadString());

		public int[] ReadIntArray(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = ReadInt() + add;
			}
			return Array;
		}

		public long ReadLong() => long.Parse(ReadString());

		public long[] ReadLongArray(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = ReadLong() + add;
			}
			return Array;
		}

		public double ReadDouble() => double.Parse(ReadString());

		public double[] ReadDoubleArray(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = ReadDouble() + add;
			}
			return Array;
		}

		public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(), typeof(T1));

		public (T1, T2) ReadValue<T1, T2>()
		{
			var inputs = ReadStringArray(2);
			var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
			var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
			return (v1, v2);
		}

		public (T1, T2, T3) ReadValue<T1, T2, T3>()
		{
			var inputs = ReadStringArray(3);
			var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
			var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
			var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
			return (v1, v2, v3);
		}

		public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>()
		{
			var inputs = ReadStringArray(4);
			var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
			var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
			var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
			var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
			return (v1, v2, v3, v4);
		}

		public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>()
		{
			var inputs = ReadStringArray(5);
			var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
			var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
			var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
			var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
			var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5));
			return (v1, v2, v3, v4, v5);
		}

		public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>()
		{
			var inputs = ReadStringArray(6);
			var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
			var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
			var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
			var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
			var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5));
			var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6));
			return (v1, v2, v3, v4, v5, v6);
		}

		public (T1, T2, T3, T4, T5, T6, T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>()
		{
			var inputs = ReadStringArray(7);
			var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
			var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
			var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
			var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
			var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5));
			var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6));
			var v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7));
			return (v1, v2, v3, v4, v5, v6, v7);
		}

		public T1[] ReadValueArray<T1>(int N)
		{
			var v1 = new T1[N];
			for (int i = 0; i < N; i++)
			{
				v1[i] = ReadValue<T1>();
			}
			return v1;
		}

		public (T1[], T2[]) ReadValueArray<T1, T2>(int N)
		{
			var (v1, v2) = (new T1[N], new T2[N]);
			for (int i = 0; i < N; i++)
			{
				var (t1, t2) = ReadValue<T1, T2>();
				v1[i] = t1;
				v2[i] = t2;
			}
			return (v1, v2);
		}

		public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int N)
		{
			var (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]);
			for (int i = 0; i < N; i++)
			{
				var (t1, t2, t3) = ReadValue<T1, T2, T3>();
				v1[i] = t1;
				v2[i] = t2;
				v3[i] = t3;
			}
			return (v1, v2, v3);
		}

		public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int N)
		{
			var (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]);
			for (int i = 0; i < N; i++)
			{
				var (t1, t2, t3, t4) = ReadValue<T1, T2, T3, T4>();
				v1[i] = t1;
				v2[i] = t2;
				v3[i] = t3;
				v4[i] = t4;
			}
			return (v1, v2, v3, v4);
		}

		public (T1[], T2[], T3[], T4[], T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int N)
		{
			var (v1, v2, v3, v4, v5) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]);
			for (int i = 0; i < N; i++)
			{
				var (t1, t2, t3, t4, t5) = ReadValue<T1, T2, T3, T4, T5>();
				v1[i] = t1;
				v2[i] = t2;
				v3[i] = t3;
				v4[i] = t4;
				v5[i] = t5;
			}
			return (v1, v2, v3, v4, v5);
		}

		public (T1[], T2[], T3[], T4[], T5[], T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int N)
		{
			var (v1, v2, v3, v4, v5, v6) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]);
			for (int i = 0; i < N; i++)
			{
				var (t1, t2, t3, t4, t5, t6) = ReadValue<T1, T2, T3, T4, T5, T6>();
				v1[i] = t1;
				v2[i] = t2;
				v3[i] = t3;
				v4[i] = t4;
				v5[i] = t5;
				v6[i] = t6;
			}
			return (v1, v2, v3, v4, v5, v6);
		}

		public (T1[], T2[], T3[], T4[], T5[], T6[], T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int N)
		{
			var (v1, v2, v3, v4, v5, v6, v7) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N], new T7[N]);
			for (int i = 0; i < N; i++)
			{
				var (t1, t2, t3, t4, t5, t6, t7) = ReadValue<T1, T2, T3, T4, T5, T6, T7>();
				v1[i] = t1;
				v2[i] = t2;
				v3[i] = t3;
				v4[i] = t4;
				v5[i] = t5;
				v6[i] = t6;
				v7[i] = t7;
			}
			return (v1, v2, v3, v4, v5, v6, v7);
		}
	}
}


//http://codeforces.com/contest/622/problem/B
using System;

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

            var parts = time.Split(':');
            var h = int.Parse(parts[0]);
            var m = int.Parse(parts[1]);

            h += (m + a) / 60;
            h %= 24;
            m = (m + a) % 60;

            Console.WriteLine(h.ToString("00") + ":" + m.ToString("00"));
        }
    }
}


using System;
class Program
{
	static void Main()
	{
		string input = Console.ReadLine(), ans = "no";

		for(int i = 0, count = int.MinValue; i < input.Length; ++i)
		{
			if (input[i] == '0') count++;
			else if(count < 0) count = 0;

			if (count == 6)
			{
				ans = "yes";
				break;
			}
		}
		Console.WriteLine(ans);
	}
}


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

namespace ConsoleApp6
{
    class Program
    {
        static void Main(string[] args)
        {
            char[] cw = { (char)94, (char)62, (char)118, (char)60 };
            char[] ccw = { (char)94, (char)60, (char)118, (char)62 };

            char[] s = Array.ConvertAll(Console.ReadLine().Split(), char.Parse);
            int n = int.Parse(Console.ReadLine());
            n = n % 4;
            int ndxL = Array.IndexOf(ccw, s[0]);
            int ndxR = Array.IndexOf(cw, s[0]);

            for(int i = 0; i < n; i++)
            {
                ndxR += 1;
                ndxL = ndxL + 1;
                if (ndxL >= ccw.Length)
                    ndxL = 0;
                if (ndxR >= cw.Length)
                    ndxR = 0;
            }
            if(cw[ndxR] == ccw[ndxL])
            {
                Console.WriteLine("undefined");
                return;
            }
            if (cw[ndxR] == s[1])
                Console.WriteLine("cw");
            else
                Console.WriteLine("ccw");

            Console.ReadLine();
        }
    }
}


/*
 * Created by SharpDevelop.
 * User: tagirov2
 * Date: 12.10.2015
 * Time: 12:56
 *
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Globalization;

namespace CF325A
{
	class Program
	{
		public static void Main(string[] args)
		{
//			Console.WriteLine("Hello World!");

			// TODO: Implement Functionality Here

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

			string [] s = Console.ReadLine().Trim().Split(' ');
			int [] a = new int [n+2];

			for ( int j=1; j <= n; j++ )
				a [j] = int.Parse (s [j-1]);

			int k=0, i=0;
			for ( i=1; i <= n; i++ )
				if ( a [i] > 0 )
					break;

			for ( ; i <= n; i++ )
				if ( a [i] == a [i-1] && a [i] == 0 )
					;
				else if ( a [i] == 1 )
					k++;
				else if ( a [i-1] == 1 && a [i] == 0 && a [i+1] == 1 )
					k++;

			Console.WriteLine (k);

//			Console.Write("Press any key to continue . . . ");
//			Console.ReadKey(true);
		}
	}
}
//
//Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
//Console.ReadLine().Split(new char[] {' ', '\t'}, StringSplitOptions.RemoveEmptyEntries);
//NumberFormatInfo nfi = NumberFormatInfo.InvariantInfo;
//string [] input = Console.In.ReadToEnd().Split(new char[] {' ', '\t', '\n', '\r'}, StringSplitOptions.RemoveEmptyEntries);


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

class Segtree<T>
{
    int n;
    T[] tree;
    Func<T, T, T> f;
    T exnum;
    public Segtree(int m, Func<T, T, T> f, T ex)
    {
        this.f = f;
        this.exnum = ex;
        n = 1;
        while (n < m) n <<= 1;

        tree = new T[(n << 1) - 1];
        for (int i = 0; i < tree.Length; i++) tree[i] = ex;
    }
    public Segtree(int m, T ini, Func<T, T, T> f, T ex)
    {
        this.f = f;
        this.exnum = ex;
        n = 1;
        while (n < m) n <<= 1;

        tree = new T[(n << 1) - 1];
        for (int i = 0; i < tree.Length; i++) tree[i] = ini;
        for (int i = 0; i < m; ++i) update(i, ini);
    }
    public void update(int j, T x)
    {
        int i = j + n - 1;
        tree[i] = x;
        while (i > 0)
        {
            i = (i - 1) >> 1;
            tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
        }
    }
    public T look(int i) { return tree[i + n - 1]; }

    // [s, t]
    public T run(int s, int t) { return query(s, t + 1, 0, 0, n); }
    T query(int s, int t, int k, int l, int r)
    {
        if (r <= s || t <= l) return exnum;
        if (s <= l && r <= t) return tree[k];

        return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r));
    }
}

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

            if (n == 1)
            {
                if (int.Parse(input[0]) == 0) Console.WriteLine("UP");
                else if (int.Parse(input[0]) == 15) Console.WriteLine("DOWN");
                else Console.WriteLine(-1);
                return;
            }
            int a = int.Parse(input[n - 2]);
            int b = int.Parse(input[n - 1]);

            if (a == 14 && b == 15) Console.WriteLine("DOWN");
            else if (a == 1 && b == 0) Console.WriteLine("UP");
            else if (a > b) Console.WriteLine("DOWN");
            else if (a < b) Console.WriteLine("UP");

        }
    }
}


using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;

static class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int res = 0;
        bool top = false;
        for (int i = 1; i < a.Length; i++)
        {
            var x = Min(a[i - 1], a[i]);
            var y = Max(a[i - 1], a[i]);
            if (x == 2 && y == 3) goto Infinite;
            if (x == 1 && y == 2) res += top ? 2 : 3;
            if (x == 1 && y == 3) res += 4;
            top = a[i - 1] == 3 && a[i] == 1;
        }
        Console.WriteLine("Finite");
        Console.WriteLine(res);
        return;
    Infinite:;
        Console.WriteLine("Infinite");

    }
}


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

namespace CodeForces
{
    internal class Solution
    {
        const int StackSize = 20 * 1024 * 1024;

        private const int MOD = 1000000000;

        private void No()
        {
            Out.WriteLine("NO");
            return;
        }

        private void Yes()
        {
            Out.WriteLine("YES");
            return;
        }

        private void Solve()
        {
            long k = NextLong();
            string input = k.ToString();
            for (int i = 0; i < input.Length; i++)
            {
                if (input[i] != '1' && input[i] != '4')
                {
                    No();
                    return;
                }

                if (input[i] == '4')
                {
                    if (i == 0)
                    {
                        No();
                        return;
                    }
                    if (i == 1 && input[0] != '1')
                    {
                        No();
                        return;
                    }
                    if (input[i - 1] == '4' && input[i - 2] != '1')
                    {
                        No();
                        return;
                    }
                }
            }
            Yes();
            return;
        }

        #region Local wireup

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

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

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

        public int NextInt()
        {
            return _in.NextInt();
        }

        public long NextLong()
        {
            return _in.NextLong();
        }

        public string NextLine()
        {
            return _in.NextLine();
        }

        public double NextDouble()
        {
            return _in.NextDouble();
        }

        readonly Scanner _in = new Scanner();
        static readonly TextWriter Out = Console.Out;

        void Start()
        {
#if !ONLINE_JUDGE
            var timer = new Stopwatch();
            timer.Start();
#endif
            var t = new Thread(Solve, StackSize);
            t.Start();
            t.Join();
#if !ONLINE_JUDGE
            timer.Stop();
            Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Done in {0} seconds.\nPress <Enter> to exit.", timer.ElapsedMilliseconds / 1000.0));
            Console.ReadLine();
#endif
        }

        static void Main()
        {
            new Solution().Start();
        }

        class Scanner : IDisposable
        {
            #region Fields

            readonly TextReader _reader;
            readonly int _bufferSize;
            readonly bool _closeReader;
            readonly char[] _buffer;
            int _length, _pos;

            #endregion

            #region .ctors

            public Scanner(TextReader reader, int bufferSize, bool closeReader)
            {
                _reader = reader;
                _bufferSize = bufferSize;
                _closeReader = closeReader;
                _buffer = new char[_bufferSize];
                FillBuffer(false);
            }

            public Scanner(TextReader reader, bool closeReader) : this(reader, 1 << 16, closeReader) { }

            public Scanner(string fileName) : this(new StreamReader(fileName, Encoding.Default), true) { }

#if ONLINE_JUDGE
            public Scanner() : this( Console.In, false ) { }
#else
            public Scanner() : this("d:\\input.txt") { }
#endif

            #endregion

            #region IDisposable Members

            public void Dispose()
            {
                if (_closeReader)
                {
                    _reader.Close();
                }
            }

            #endregion

            #region Properties

            public bool Eof
            {
                get
                {
                    if (_pos < _length) return false;
                    FillBuffer(false);
                    return _pos >= _length;
                }
            }

            #endregion

            #region Methods

            private char NextChar()
            {
                if (_pos < _length) return _buffer[_pos++];
                FillBuffer(true);
                return _buffer[_pos++];
            }

            private char PeekNextChar()
            {
                if (_pos < _length) return _buffer[_pos];
                FillBuffer(true);
                return _buffer[_pos];
            }

            private void FillBuffer(bool throwOnEof)
            {
                _length = _reader.Read(_buffer, 0, _bufferSize);
                if (throwOnEof && Eof)
                {
                    throw new IOException("Can't read beyond the end of file");
                }
                _pos = 0;
            }

            public int NextInt()
            {
                var neg = false;
                int res = 0;
                SkipWhitespaces();
                if (!Eof && PeekNextChar() == '-')
                {
                    neg = true;
                    _pos++;
                }
                while (!Eof && !IsWhitespace(PeekNextChar()))
                {
                    var c = NextChar();
                    if (c < '0' || c > '9') throw new ArgumentException("Illegal character");
                    res = 10 * res + c - '0';
                }
                return neg ? -res : res;
            }

            public long NextLong()
            {
                var neg = false;
                long res = 0;
                SkipWhitespaces();
                if (!Eof && PeekNextChar() == '-')
                {
                    neg = true;
                    _pos++;
                }
                while (!Eof && !IsWhitespace(PeekNextChar()))
                {
                    var c = NextChar();
                    if (c < '0' || c > '9') throw new ArgumentException("Illegal character");
                    res = 10 * res + c - '0';
                }
                return neg ? -res : res;
            }

            public string NextLine()
            {
                SkipUntilNextLine();
                if (Eof) return "";
                var builder = new StringBuilder();
                while (!Eof && !IsEndOfLine(PeekNextChar()))
                {
                    builder.Append(NextChar());
                }
                return builder.ToString();
            }

            public double NextDouble()
            {
                SkipWhitespaces();
                var builder = new StringBuilder();
                while (!Eof && !IsWhitespace(PeekNextChar()))
                {
                    builder.Append(NextChar());
                }
                return double.Parse(builder.ToString(), CultureInfo.InvariantCulture);
            }

            private void SkipWhitespaces()
            {
                while (!Eof && IsWhitespace(PeekNextChar()))
                {
                    ++_pos;
                }
            }

            private void SkipUntilNextLine()
            {
                while (!Eof && IsEndOfLine(PeekNextChar()))
                {
                    ++_pos;
                }
            }

            private static bool IsWhitespace(char c)
            {
                return c == ' ' || c == '\t' || c == '\n' || c == '\r';
            }

            private static bool IsEndOfLine(char c)
            {
                return c == '\n' || c == '\r';
            }

            #endregion
        }

        #endregion
    }
}


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

namespace A.Olesya_and_Rodion
{
    class Program
    {
        static void Main(string[] args)
        {
            string x = Console.ReadLine();
            int[]numberanddivisible = x.Split(' ').Select(int.Parse).ToArray();
            List<int> answer = new List<int>();
            for (int i = 0; i < numberanddivisible[0]; i++)
            {
                if (i == 0)
                {
                    if (numberanddivisible[1]==10)
                    {
                        answer.Add(1);
                    }
                    else
                    answer.Add(numberanddivisible[1]);
                }
                else
                    answer.Add(0);
            }
            if (numberanddivisible[1]==10 && numberanddivisible[0]==1)
            {
                Console.WriteLine("-1");
            }
            else
            {

            for (int i = 0; i < answer.Count; i++)
            {
             Console.Write(answer[i]);
            }
            }
            Console.ReadLine();
        }
    }
}


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

public class Solver
{
    public void Solve()
    {
        int a = ReadInt();
        int b = ReadInt();
        var ans = new int[3];
        for (int i = 1; i < 7; i++)
        {
            if (Math.Abs(a - i) < Math.Abs(b - i))
                ans[0]++;
            if (Math.Abs(a - i) == Math.Abs(b - i))
                ans[1]++;
            if (Math.Abs(a - i) > Math.Abs(b - i))
                ans[2]++;
        }

        WriteArray(ans);
    }

    #region Main

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

    #endregion

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


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

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

            long a = Convert.ToInt32(Console.ReadLine());

            long b = Convert.ToInt32(Console.ReadLine());

            for(long x = 0; x <= n; x++)
            {
                long c = n - a * x;

                if (c < 0)
                {
                    break;
                }

                if (c % b == 0)
                {
                    long y = c / b;
                    Console.WriteLine("YES\n" + x + " " + y);
                    return;
                }
            }

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


using System;

namespace NetCore
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] arr = new int[n];
            for(int i = 0; i < n; i++)
            {
                arr[i] = int.Parse(Console.ReadLine());
            }
            bool valid = false;
            int mx = (1 << n);
            for(int i = 0; i < mx; i++)
            {
                int sum = 0;
                int j = 1;
                int counter = 0;
                while(counter < n)
                {
                    if ((j & i) != 0) sum += arr[counter];
                    else sum -= arr[counter];
                    counter++;
                    j <<= 1;
                    sum %= 360;
                }
                if (sum == 0) valid = true;
            }
            Console.WriteLine(valid ? "YES" : "NO");
        }
    }
}


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

namespace ALGORITM_CodeForces
{
    class Program
    {
        static void Main()
        {
            string s = Console.ReadLine();
            var n = Convert.ToInt64(s.Split(' ')[0]);
            var k = Convert.ToInt64(s.Split(' ')[1]);

            Console.WriteLine(To(1,n,n,k,n));
            Console.WriteLine();
        }
        static long To(long left,long right,long cur,long y,long x)
        {
            long final;
            long y1=1;
            long mid = left + (right - left) / 2;
            long plus = mid;
            long t = mid;
            while ((t/y)!=0)
            {
                t = mid / (y1=y1*y);
                plus = plus + t;

            }

            if ((mid==left) && (left==right))

                return mid;

            else if (plus < cur)
            {
               final = To(mid+1, right, cur,y,x);
            }
            else
            {

               final=To(left, mid, cur,y,x);

            }
            return final;
        }
    }
}


using System;

namespace ConsoleApp5
{

    class Program
    {

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

            Console.Write(n/2 +1);
            Console.ReadLine();

        }
    }
}


using System;
namespace CF
{
    public class Intercal
    {
        public static void Main()
        {
            Console.WriteLine("INTERCAL");
        }
    }
}


using System;
using System.Linq;

namespace CF_141A
{
    class Program
    {
        static void Main()
        {
            var s = Console.ReadLine();
            s += Console.ReadLine();
            var sRes = Console.ReadLine();
            var s1 = s.OrderBy(x => x).ToList().Aggregate("", (current, t) => current + t);
            var s2 = sRes.OrderBy(x => x).ToList().Aggregate("", (current, t) => current + t);
            Console.WriteLine(string.Compare(s1, s2) == 0 ? "YES" : "NO");
        }
    }
}


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

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

class Sol{
	public void Solve(){

		int maxV = N*5*4;
		bool[][] vis = new bool[maxV][];
		for(int i=0;i<maxV;i++)vis[i] = new bool[maxV];

		HashSet<long> H = new HashSet<long>();
		H.Add(enc(maxV/2,maxV/2,0));
		for(int i=0;i<N;i++){
			HashSet<long> nxt = new HashSet<long>();
			foreach(var trc in H){
				var r = decR(trc);
				var c = decC(trc);
				var t = decT(trc);
				for(int j=1;j<=A[i];j++){
					var nr = r + dy[t]*j;
					var nc = c + dx[t]*j;
					vis[nr][nc] = true;
				}
				nxt.Add(enc(r + dy[t]*A[i], c + dx[t]*A[i], (t+1)%8));
				nxt.Add(enc(r + dy[t]*A[i], c + dx[t]*A[i], (t+7)%8));
			}
			H = nxt;
		}

		int ans = 0;
		for(int i=0;i<maxV;i++){
			for(int j=0;j<maxV;j++){
				if(vis[i][j]) ans++;
			}
		}

		Console.WriteLine(ans);

	}
	int N;
	int[] A;
	public Sol(){
		N = ri();
		A = ria();
	}

	int[] dy = new int[] {0,1,1,1,0,-1,-1,-1};
	int[] dx = new int[] {1,1,0,-1,-1,-1,0,1};

	long mod = (long)1e4;
	long mod2= (long)1e8;
	long enc(long r, long c, long t){ return t*mod2 + r*mod + c; }
	int decR(long trc){ return (int) ((trc % mod2 )/ mod); }
	int decC(long trc){ return (int) (trc % mod); }
	int decT(long trc){ return (int) (trc / mod2); }

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


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

namespace Codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string a = s.Split('+', '=')[0];
            string b = s.Split('+', '=')[1];
            string c = s.Split('+', '=')[2];

            if (a.Length + b.Length == c.Length)
            {
                Console.WriteLine(s);
            }
            else if (a.Length + b.Length - c.Length == -2)
            {
                b += "|";
                c = c.Remove(c.Length - 1);
                Console.WriteLine("{0}+{1}={2}", a, b, c);
            }
            else if (a.Length + b.Length - c.Length == 2)
            {
                c += "|";
                if (a.Length == 1)
                {
                    b = b.Remove(b.Length - 1);
                }
                else
                {
                    a = a.Remove(a.Length - 1);
                }
                Console.WriteLine("{0}+{1}={2}", a, b, c);
            }
            else
            {
                Console.WriteLine("Impossible");
            }
        }
    }
}


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

namespace Links_and_Pearls
{
    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)
        {
            writer.WriteLine(Solve(args) ? "Yes" : "No");
            writer.Flush();
        }

        private static bool Solve(string[] args)
        {
            string s = reader.ReadLine();

            int l = s.Count(c => c == '-');

            return s.Length - l == 0 || l%(s.Length - l) == 0;
        }
    }
}