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

namespace Maximum_Sum_of_Digits
{
    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());
            writer.Flush();
        }

        private static int Solve()
        {
            string s = reader.ReadLine();

            int ans = s[0] - '0';
            bool fn9 = false;
            for (int i = s.Length - 1; i > 0; i++)
            {
                if (fn9 || s[i] != '9')
                {
                    ans += 9;
                    ans += s[i] - '0';
                    fn9 = true;
                }
                else
                {
                    ans += 9;
                }
            }

            return ans;
        }
    }
}


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

namespace ProblemSolving
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] num = new int[3];
            while ((num[0] = Convert.ToInt16(Console.ReadLine()))!=null)
            {
                for (int i = 1; i < 3; i++)
                {
                    num[i] = Convert.ToInt16(Console.ReadLine());
                }

                int a = Math.Max(num[0] + num[1] + num[2], Math.Max(num[0] * num[1] * num[2],
                    Math.Max(num[0] + num[1] * num[2],Math.Max((num[0] + num[1]) * num[2], num[0] * (num[1] + num[2])))));
                Console.WriteLine(a.ToString());
            }
        }
    }
}


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

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

            int spin = 0;
            int bicz = 0;
            int grud = 0;

            string fd = Console.ReadLine();

            int[] arrayiNT = new int[n];

            for (int i = 1; i < n + 1; i++)
            {
                arrayiNT[i-1] = Int32.Parse(fd.Split(' ')[i-1]);
                if (i % 3 == 0)
                {
                    spin += arrayiNT[i-1];
                }
                if (i % 3 == 1)
                {
                    grud += arrayiNT[i-1];
                }
                if (i % 3 == 2)
                {
                    bicz += arrayiNT[i-1];
                }
             }

            Dictionary<int, string> slovar = new Dictionary<int, string>() { { spin, "back" }, { bicz, "biceps" }, { grud, "chest" } };
            List<int> upra = new List<int>();

            upra.Add(spin);
            upra.Add(grud);
            upra.Add(bicz);

            Console.WriteLine(slovar[upra.Max()]);
                   }
    }
}


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

namespace checkForSplit
{

    class Program
    {

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
           // List<int>[]lst = new List<int>[1000];
            List<int> lst = new List<int>();
            int k = 0;
            int beg = n / 2;
            lst.Add(n);
            while (beg != 1)
            {
                if (lst[lst.Count - 1] % beg == 0)
                {
                    lst.Add(beg);
                    beg /= 2;
                }
                else beg--;
            }
            lst.Add(1);
            foreach (var i in lst)
            {
                Console.Write(i+" ");
            }
            Console.WriteLine();
        }
    }

}


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

namespace CF_058B {
  class Program {
    static void Main(string[] args) {
      int[] p=new int[1000]; p[0]=2;
      int t=1,u=1,j;while(t<=1000){t+=2;p[u]=t;
        j=1;while(t%p[j]!=0)j++;
        if(j==u)u++;
      }
      int n=int.Parse(Console.ReadLine());
      p[u]=n;
      int mlu=0; int[] m=new int[10],l=new int[10];
      for(j=0;p[u]!=1;j++) {
        if(p[u]%p[j]!=0) continue;
        m[mlu]=p[j];
        while(p[u]%p[j]==0) { l[mlu]++; p[u]/=p[j]; };
        mlu++;
      }
      for(j=0;j<mlu;j++)
       while(l[j]>0){
         Console.Write("{0} ",n);
           n/=m[j];l[j]--;
       }
      Console.WriteLine(1);

    }
  }
}


using System;

public class Coins
{
    private static void Main()
    {

            const int max = 1000;
            int n = Convert.ToInt32(Console.ReadLine());
            int[] primes = new int[max + 1];
            primes[1] = 2;
            primes[2] = 3;
            int curr_prime = 3;
            int sqrt = 1;
            for (int i = 4; (curr_prime <= max && i < Int32.MaxValue); i++)
            {
                if ((sqrt + 1) * (sqrt + 1) == i)
                    sqrt++;

                bool f = true;
                for (int j = 1; primes[j] <= sqrt; j++)
                {
                    if (i % primes[j] == 0)
                    {
                        f = false;
                        break;
                    }
                }

                if (f)
                {
                    primes[curr_prime] = i;
                    curr_prime++;
                }
            }

            bool f = true;
            while (n > 1 && f)
            {
                sqrt = (int)Math.Sqrt(n);
                f = false;
                for (int i = 1; primes[i] <= n; i++)
                {
                    if (n % primes[i] == 0)
                    {
                      Console.WriteLine(primes[i].ToString());
                      n /= primes[i];
                      f = true;
                      break;
                    }
                }
            }
                                  Console.WriteLine(primes[0].ToString());

    }
}


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

namespace CR_111_A
{
    class Program
    {

        static void Main()
        {
            //int k = int.Parse(Console.ReadLine());
            //string[] tmp = Console.ReadLine().Split(' ');
            int k = int.Parse(Console.ReadLine());
            int[] ans = new int[k];
            int j = k - 1 ;
            while (k % j != 0)
                j--;
            if (j != 1)
            {
                for (int i = k, p = 0; i >= j; i -= j, p++)
                    Console.Write("{0} ", k - p * j);
                Console.Write(1);

            }
            else
                Console.Write("{0} {1}", k, 1);

        }

    }
}


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

class testcodeforces
{
    int N;
    int[,] board;
    Dictionary<int, Tuple<int, int>> locations;

    public static void Main()
    {
        testcodeforces obj = new testcodeforces();
        obj.ThreePieces();
    }

    enum Pawn
    {
        Bishop = 0,
        Knight,
        Rook
    }
    class Move : IComparable<Move>
    {
        public int Moves { get; set; }
        public int Rep { get; set; }

        public int Num { get; set; }
        public Pawn pawn { get; set; }
        public int CompareTo(Move other)
        {
            if (Moves < other.Moves) return -1;
            if (Moves > other.Moves) return 1;

            if (Moves == other.Moves) return Rep.CompareTo(other.Rep);

            return 0;
        }
    }
    private void ThreePieces()
    {
        N = int.Parse(Console.ReadLine());

        board = new int[N, N];
        locations = new Dictionary<int, Tuple<int, int>>();

        for (int i = 0; i < N; i++)
        {
            var array = Array.ConvertAll(Console.ReadLine().Split(new char[] { ' ' }), int.Parse);

            for (int j = 0; j < N; j++)
            {
                board[i, j] = array[j];
                locations.Add(array[j], Tuple.Create(i + 1, j + 1));
            }
        }

        //Min of all
        #region rook Distances
        //Find rook distances
        var rook_distances = new Tuple<int, int>[(N * N) + 1];
        rook_distances[1] = Tuple.Create(0, 0);

        for (int i = 2; i <= N * N; i++)
        {
            var current_location = locations[i - 1];
            var new_location = locations[i];

            if (current_location.Item1 == new_location.Item1 ||
                current_location.Item2 == new_location.Item2)
                rook_distances[i] = Tuple.Create(1, 0);
            else
                rook_distances[i] = Tuple.Create(2, 0);
        }
        #endregion

        #region Bishop Distances
        //Find Bishop Distances
        var bishop_distances = new Tuple<int, int>[(N * N) + 1];
        bishop_distances[1] = Tuple.Create(0, 0);

        for (int i = 2; i <= N * N; i++)
        {
            var current_location = locations[i - 1];
            var new_location = locations[i];

            if ((current_location.Item1 + current_location.Item2) % 2 != (new_location.Item1 + new_location.Item2) % 2)
                bishop_distances[i] = Tuple.Create(int.MaxValue, 0);
            else
            {
                bool found = false;
                //Move North East
                for (int k = 1; k <= Math.Min(current_location.Item1 - 1, N - current_location.Item2); k++)
                {
                    if (new_location.Item1 == current_location.Item1 - k && new_location.Item2 == current_location.Item2 + k)
                    {
                        bishop_distances[i] = Tuple.Create(1, 0);
                        found = true;
                        break;
                    }
                }

                //Move South west
                if (!found)
                {
                    for (int k = 1; k <= Math.Min(N - current_location.Item1, current_location.Item2 - 1); k++)
                    {
                        if (new_location.Item1 == current_location.Item1 + k && new_location.Item2 == current_location.Item2 - k)
                        {
                            bishop_distances[i] = Tuple.Create(1, 0);
                            found = true;
                            break;
                        }
                    }
                }

                //Move South east
                if (!found)
                {
                    for (int k = 1; k <= Math.Min(N - current_location.Item1, N - current_location.Item2 - 1); k++)
                    {
                        if (new_location.Item1 == current_location.Item1 + k && new_location.Item2 == current_location.Item2 + k)
                        {
                            bishop_distances[i] = Tuple.Create(1, 0);
                            found = true;
                            break;
                        }
                    }
                }

                //Move North West
                if (!found)
                {
                    for (int k = 1; k <= Math.Min(current_location.Item1 - 1, current_location.Item2 - 1); k++)
                    {
                        if (new_location.Item1 == current_location.Item1 - k && new_location.Item2 == current_location.Item2 - k)
                        {
                            bishop_distances[i] = Tuple.Create(1, 0);
                            found = true;
                            break;
                        }
                    }
                }

                if (!found)
                {
                    bishop_distances[i] = Tuple.Create(2, 0);
                }
            }
        }
        #endregion

        #region Knight Distances
        //Find Knight Distances
        var X = new int[] { 2, 2, -2, -2, 1, 1, -1, -1 };
        var Y = new int[] { -1, 1, -1, 1, 2, -2, 2, -2 };

        var Knight_distances = new Tuple<int, int>[(N * N) + 1];
        Knight_distances[1] = Tuple.Create(0, 0);

        for (int i = 2; i <= N * N; i++)
        {
            var current_location = locations[i - 1];
            var new_location = locations[i];

            var list = new List<Tuple<int, int>>();

            bool found = false;

            for (int t = 0; t < 8; t++)
            {
                var new_X = current_location.Item1 + X[t];
                var new_Y = current_location.Item2 + Y[t];
                if (new_X == new_location.Item1 && new_Y == new_location.Item2)
                {
                    Knight_distances[i] = Tuple.Create(1, 0);
                    found = true;
                    break;
                }
                else
                {
                    if (new_X >= 1 && new_X <= N && new_Y >= 1 && new_Y <= N)
                        list.Add(Tuple.Create(new_X, new_Y));
                }
            }

            if (!found)
            {
                for (int l = 0; l < list.Count; l++)
                {
                    for (int t = 0; t < 8; t++)
                    {
                        var new_X = list[l].Item1 + X[t];
                        var new_Y = list[l].Item2 + Y[t];
                        if (new_X == new_location.Item1 && new_Y == new_location.Item2)
                        {
                            Knight_distances[i] = Tuple.Create(2, 0);
                            found = true;
                            break;
                        }
                    }
                }
            }

            if (!found) Knight_distances[i] = Tuple.Create(int.MaxValue, 0);

        }
        #endregion

        var minheap = new MinHeap<Move>();

        var states = new Move[3][];
        states[0] = new Move[(N * N) + 1];
        states[1] = new Move[(N * N) + 1];
        states[2] = new Move[(N * N) + 1];

        for (int j = 1; j <= N * N; j++)
            states[0][j] = new Move() { pawn = Pawn.Bishop, Num = j, Moves = int.MaxValue, Rep = int.MaxValue };
        for (int j = 1; j <= N * N; j++)
            states[1][j] = new Move() { pawn = Pawn.Knight, Num = j, Moves = int.MaxValue, Rep = int.MaxValue };
        for (int j = 1; j <= N * N; j++)
            states[2][j] = new Move() { pawn = Pawn.Rook, Num = j, Moves = int.MaxValue, Rep = int.MaxValue };

        states[0][1] = new Move() { pawn = Pawn.Bishop, Num = 1, Moves = 0, Rep = 0 };
        states[1][1] = new Move() { pawn = Pawn.Knight, Num = 1, Moves = 0, Rep = 0 };
        states[2][1] = new Move() { pawn = Pawn.Rook, Num = 1, Moves = 0, Rep = 0 };

        minheap.Add(states[0][1]);
        minheap.Add(states[1][1]);
        minheap.Add(states[2][1]);

        while (minheap.Count > 0)
        {
            var item = minheap.ExtractMin();

            Pawn p = item.pawn;
            int currentnum = item.Num;
            int intPaws = (int)p;

            Console.WriteLine("*******************");
            Console.WriteLine("" + p + " currentnum " + currentnum);

            if (currentnum == N * N) break;

            if (p == Pawn.Bishop)
            {
                //Get Bishop distance
                var dist = bishop_distances[currentnum + 1];
                if (dist.Item1 != int.MaxValue)
                {
                    if (item.Moves + dist.Item1 < states[0][currentnum + 1].Moves
                        || (item.Moves + dist.Item1 == states[0][currentnum + 1].Moves && item.Rep < states[0][currentnum + 1].Rep))
                    {
                        states[0][currentnum + 1] = new Move()
                        {
                            Num = currentnum + 1,
                            Moves = item.Moves + dist.Item1,
                            pawn = Pawn.Bishop,
                            Rep = item.Rep
                        };

                        minheap.Add(states[0][currentnum + 1]);
                    }
                }

                //Get Knight distance
                dist = Knight_distances[currentnum + 1];
                if (dist.Item1 != int.MaxValue)
                {
                    if (item.Moves + dist.Item1 + 1 < states[1][currentnum + 1].Moves
                        || (item.Moves + dist.Item1 + 1 == states[1][currentnum + 1].Moves && item.Rep + 1 < states[1][currentnum + 1].Rep))
                    {
                        states[1][currentnum + 1] = new Move()
                        {
                            Num = currentnum + 1,
                            Moves = item.Moves + dist.Item1 + 1,
                            pawn = Pawn.Knight,
                            Rep = item.Rep + 1
                        };

                        minheap.Add(states[1][currentnum + 1]);
                    }
                }

                //Get Rook distance
                dist = rook_distances[currentnum + 1];
                if (dist.Item1 != int.MaxValue)
                {
                    if (item.Moves + dist.Item1 + 1 < states[2][currentnum + 1].Moves
                        || (item.Moves + dist.Item1 + 1 == states[2][currentnum + 1].Moves && item.Rep + 1 < states[2][currentnum + 1].Rep))
                    {
                        states[2][currentnum + 1] = new Move()
                        {
                            Num = currentnum + 1,
                            Moves = item.Moves + dist.Item1 + 1,
                            pawn = Pawn.Rook,
                            Rep = item.Rep + 1
                        };

                        minheap.Add(states[2][currentnum + 1]);
                    }
                }
            }
            else if (p == Pawn.Knight)
            {
                var dist = Knight_distances[currentnum + 1];
                if (dist.Item1 != int.MaxValue)
                {
                    if (item.Moves + dist.Item1 < states[1][currentnum + 1].Moves
                        || (item.Moves + dist.Item1 == states[1][currentnum + 1].Moves && item.Rep < states[1][currentnum + 1].Rep))
                    {
                        states[1][currentnum + 1] = new Move()
                        {
                            Num = currentnum + 1,
                            Moves = item.Moves + dist.Item1,
                            pawn = Pawn.Knight,
                            Rep = item.Rep
                        };

                        minheap.Add(states[1][currentnum + 1]);
                    }
                }

                dist = rook_distances[currentnum + 1];
                if (dist.Item1 != int.MaxValue)
                {
                    if (item.Moves + dist.Item1 + 1 < states[2][currentnum + 1].Moves
                        || (item.Moves + dist.Item1 + 1 == states[2][currentnum + 1].Moves && item.Rep + 1 < states[2][currentnum + 1].Rep))
                    {
                        states[2][currentnum + 1] = new Move()
                        {
                            Num = currentnum + 1,
                            Moves = item.Moves + dist.Item1 + 1,
                            pawn = Pawn.Rook,
                            Rep = item.Rep + 1
                        };

                        minheap.Add(states[2][currentnum + 1]);
                    }
                }

                dist = bishop_distances[currentnum + 1];
                if (dist.Item1 != int.MaxValue)
                {
                    if (item.Moves + dist.Item1 + 1 < states[0][currentnum + 1].Moves
                        || (item.Moves + dist.Item1 + 1 == states[0][currentnum + 1].Moves && item.Rep + 1 < states[0][currentnum + 1].Rep))
                    {
                        states[0][currentnum + 1] = new Move()
                        {
                            Num = currentnum + 1,
                            Moves = item.Moves + dist.Item1 + 1,
                            pawn = Pawn.Bishop,
                            Rep = item.Rep + 1
                        };

                        minheap.Add(states[0][currentnum + 1]);
                    }
                }
            }
            else if (p == Pawn.Rook)
            {
                var dist = rook_distances[currentnum + 1];
                if (dist.Item1 != int.MaxValue)
                {
                    if (item.Moves + dist.Item1 < states[2][currentnum + 1].Moves
                        || (item.Moves + dist.Item1 == states[2][currentnum + 1].Moves && item.Rep < states[2][currentnum + 1].Rep))
                    {
                        states[2][currentnum + 1] = new Move()
                        {
                            Num = currentnum + 1,
                            Moves = item.Moves + dist.Item1,
                            pawn = Pawn.Rook,
                            Rep = item.Rep
                        };

                        minheap.Add(states[2][currentnum + 1]);
                    }
                }

                dist = bishop_distances[currentnum + 1];
                if (dist.Item1 != int.MaxValue)
                {
                    if (item.Moves + dist.Item1 + 1 < states[0][currentnum + 1].Moves
                        || (item.Moves + dist.Item1 + 1 == states[0][currentnum + 1].Moves && item.Rep + 1 < states[0][currentnum + 1].Rep))
                    {
                        states[0][currentnum + 1] = new Move()
                        {
                            Num = currentnum + 1,
                            Moves = item.Moves + dist.Item1 + 1,
                            pawn = Pawn.Bishop,
                            Rep = item.Rep + 1
                        };

                        minheap.Add(states[0][currentnum + 1]);
                    }
                }

                dist = Knight_distances[currentnum + 1];
                if (dist.Item1 != int.MaxValue)
                {
                    if (item.Moves + dist.Item1 + 1 < states[2][currentnum + 1].Moves
                        || (item.Moves + dist.Item1 + 1 == states[2][currentnum + 1].Moves && item.Rep + 1 < states[2][currentnum + 1].Rep))
                    {
                        states[2][currentnum + 1] = new Move()
                        {
                            Num = currentnum + 1,
                            Moves = item.Moves + dist.Item1 + 1,
                            pawn = Pawn.Knight,
                            Rep = item.Rep + 1
                        };

                        minheap.Add(states[2][currentnum + 1]);
                    }
                }
            }
        }

        int res = int.MaxValue;

        res = Math.Min(states[1][N * N].Moves, res);
        res = Math.Min(states[2][N * N].Moves, res);
        res = Math.Min(states[0][N * N].Moves, res);

        int moves = int.MaxValue;

        if (res == states[0][N * N].Moves)
            moves = Math.Min(states[0][N * N].Rep, moves);

        if (res == states[1][N * N].Moves)
            moves = Math.Min(states[1][N * N].Rep, moves);
        if (res == states[2][N * N].Moves)
            moves = Math.Min(states[2][N * N].Rep, moves);

        Console.WriteLine("" + res + " " + moves);
    }
}


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

namespace ConsoleTidbits
{
      class MinHeap<T> where T : IComparable
    {
        public IList<T> m_array;

        public MinHeap()
        {
            m_array = new List<T>();
        }
        public T GetRoot()
        {
            return m_array[0];
        }

        public T ExtractMin()
        {
            var result = m_array[0];
            m_array[0] = m_array[Count - 1];
            m_array.RemoveAt(m_array.Count - 1);
            ShiftDown(0);

            return result;
        }

        public void Remove(int index)
        {
        }

        public void ShiftDown(int index)
        {
            int left = 2 * index + 1;
            int right = 2 * index + 2;
            int Index = index;

            if (left < Count && m_array[index].CompareTo(m_array[left]) > 0)
            {
                index = left;
            }

            if (right < Count && m_array[index].CompareTo(m_array[right]) > 0)
            {
                index = right;
            }

            if (index != Index)
            {
                var temp = m_array[Index];
                m_array[Index] = m_array[index];
                m_array[index] = temp;

                ShiftDown(index);
            }
        }

        public int Count
        {
            get
            {
                return m_array.Count();
            }
        }

        private void Balance(int index)
        {
            if (index < 0)
            {
                return;
            }

            int parent = (index - 1) / 2;

            if (m_array[parent].CompareTo(m_array[index]) > 0)
            {
                var temp = m_array[parent];
                m_array[parent] = m_array[index];
                m_array[index] = temp;
                Balance(parent);
            }
        }

        public void Add(T number)
        {
            m_array.Add(number);
            //BuildHeap();
            Balance(m_array.Count - 1);
        }

        private void BuildHeap()
        {
            for (int i = Count / 2; i >= 0; i--)
            {
                Heapify(m_array, i);
            }
        }
        private void Heapify(IList<T> array, int index)
        {
            int N = array.Count;

            int Index = index;
            int left = 2 * index + 1;
            int right = 2 * index + 2;

            if (left < N && array[left].CompareTo(array[index]) < 0)
            {
                index = left;
            }

            if (right < N && array[right].CompareTo(array[index]) < 0)
            {
                index = right;
            }

            if (index != Index)
            {
                var temp = array[Index];
                array[Index] = array[index];
                array[index] = temp;

                Heapify(array, index);
            }

        }
    }

    class JustCodeForces
    {
        int N;
        int[,] board;
        Dictionary<int, Tuple<int, int>> locations;

        public static void Main()
        {
            JustCodeForces obj = new JustCodeForces();

            while (true)
                obj.ThreePieces();
        }

        enum Pawn
        {
            Bishop = 0,
            Knight,
            Rook
        }
        class Move : IComparable
        {
            public int Moves { get; set; }
            public int Rep { get; set; }

            public int Num { get; set; }
            public Pawn pawn { get; set; }
            public int CompareTo(object o)
            {
                var other = o as Move;
                if (Moves < other.Moves) return -1;
                if (Moves > other.Moves) return 1;

                if (Moves == other.Moves) return Rep.CompareTo(other.Rep);

                return -1;
            }
        }
        private void ThreePieces()
        {
            N = int.Parse(Console.ReadLine());

            board = new int[N, N];
            locations = new Dictionary<int, Tuple<int, int>>();

            for (int i = 0; i < N; i++)
            {
                var array = Array.ConvertAll(Console.ReadLine().Split(new char[] { ' ' }), int.Parse);

                for (int j = 0; j < N; j++)
                {
                    board[i, j] = array[j];
                    locations.Add(array[j], Tuple.Create(i + 1, j + 1));
                }
            }

            //Min of all
            #region rook Distances
            //Find rook distances
            var rook_distances = new Tuple<int, int>[(N * N) + 1];
            rook_distances[1] = Tuple.Create(0, 0);

            for (int i = 2; i <= N * N; i++)
            {
                var current_location = locations[i - 1];
                var new_location = locations[i];

                if (current_location.Item1 == new_location.Item1 ||
                    current_location.Item2 == new_location.Item2)
                    rook_distances[i] = Tuple.Create(1, 0);
                else
                    rook_distances[i] = Tuple.Create(2, 0);
            }
            #endregion

            #region Bishop Distances
            //Find Bishop Distances
            var bishop_distances = new Tuple<int, int>[(N * N) + 1];
            bishop_distances[1] = Tuple.Create(0, 0);

            for (int i = 2; i <= N * N; i++)
            {
                var current_location = locations[i - 1];
                var new_location = locations[i];

                if ((current_location.Item1 + current_location.Item2) % 2 != (new_location.Item1 + new_location.Item2) % 2)
                    bishop_distances[i] = Tuple.Create(int.MaxValue, 0);
                else
                {
                    bool found = false;
                    //Move North East
                    for (int k = 1; k <= Math.Min(current_location.Item1 - 1, N - current_location.Item2); k++)
                    {
                        if (new_location.Item1 == current_location.Item1 - k && new_location.Item2 == current_location.Item2 + k)
                        {
                            bishop_distances[i] = Tuple.Create(1, 0);
                            found = true;
                            break;
                        }
                    }

                    //Move South west
                    if (!found)
                    {
                        for (int k = 1; k <= Math.Min(N - current_location.Item1, current_location.Item2 - 1); k++)
                        {
                            if (new_location.Item1 == current_location.Item1 + k && new_location.Item2 == current_location.Item2 - k)
                            {
                                bishop_distances[i] = Tuple.Create(1, 0);
                                found = true;
                                break;
                            }
                        }
                    }

                    //Move South east
                    if (!found)
                    {
                        for (int k = 1; k <= Math.Min(N - current_location.Item1, N - current_location.Item2); k++)
                        {
                            if (new_location.Item1 == current_location.Item1 + k && new_location.Item2 == current_location.Item2 + k)
                            {
                                bishop_distances[i] = Tuple.Create(1, 0);
                                found = true;
                                break;
                            }
                        }
                    }

                    //Move North West
                    if (!found)
                    {
                        for (int k = 1; k <= Math.Min(current_location.Item1 - 1, current_location.Item2 - 1); k++)
                        {
                            if (new_location.Item1 == current_location.Item1 - k && new_location.Item2 == current_location.Item2 - k)
                            {
                                bishop_distances[i] = Tuple.Create(1, 0);
                                found = true;
                                break;
                            }
                        }
                    }

                    if (!found)
                    {
                        bishop_distances[i] = Tuple.Create(2, 0);
                    }
                }
            }
            #endregion

            #region Knight Distances
            //Find Knight Distances
            var X = new int[] { 2, 2, -2, -2, 1, 1, -1, -1 };
            var Y = new int[] { -1, 1, -1, 1, 2, -2, 2, -2 };

            var Knight_distances = new Tuple<int, int>[(N * N) + 1];
            Knight_distances[1] = Tuple.Create(0, 0);

            for (int i = 2; i <= N * N; i++)
            {
                var current_location = locations[i - 1];
                var new_location = locations[i];

                var list = new List<Tuple<int, int>>();

                bool found = false;

                for (int t = 0; t < 8; t++)
                {
                    var new_X = current_location.Item1 + X[t];
                    var new_Y = current_location.Item2 + Y[t];
                    if (new_X == new_location.Item1 && new_Y == new_location.Item2)
                    {
                        Knight_distances[i] = Tuple.Create(1, 0);
                        found = true;
                        break;
                    }
                    else
                    {
                        if (new_X >= 1 && new_X <= N && new_Y >= 1 && new_Y <= N)
                            list.Add(Tuple.Create(new_X, new_Y));
                    }
                }

                var new_list = new List<Tuple<int, int>>();

                if (!found)
                {
                    for (int l = 0; l < list.Count; l++)
                    {
                        for (int t = 0; t < 8; t++)
                        {
                            var new_X = list[l].Item1 + X[t];
                            var new_Y = list[l].Item2 + Y[t];
                            if (new_X == new_location.Item1 && new_Y == new_location.Item2)
                            {
                                Knight_distances[i] = Tuple.Create(2, 0);
                                found = true;
                                break;
                            }
                            else
                            {
                                if (new_X >= 1 && new_X <= N && new_Y >= 1 && new_Y <= N)
                                    new_list.Add(Tuple.Create(new_X, new_Y));
                            }
                        }
                    }
                }

                if (!found)
                {
                    for (int l = 0; l < new_list.Count; l++)
                    {
                        for (int t = 0; t < 8; t++)
                        {
                            var new_X = new_list[l].Item1 + X[t];
                            var new_Y = new_list[l].Item2 + Y[t];
                            if (new_X == new_location.Item1 && new_Y == new_location.Item2)
                            {
                                Knight_distances[i] = Tuple.Create(3, 0);
                                found = true;
                                break;
                            }
                        }
                    }
                }

                if (!found) Knight_distances[i] = Tuple.Create(int.MaxValue, 0);

            }
            #endregion

            var minheap = new MinHeap<Move>();

            var states = new Move[3][];
            states[0] = new Move[(N * N) + 1];
            states[1] = new Move[(N * N) + 1];
            states[2] = new Move[(N * N) + 1];

            for (int j = 1; j <= N * N; j++)
                states[0][j] = new Move() { pawn = Pawn.Bishop, Num = j, Moves = int.MaxValue, Rep = int.MaxValue };
            for (int j = 1; j <= N * N; j++)
                states[1][j] = new Move() { pawn = Pawn.Knight, Num = j, Moves = int.MaxValue, Rep = int.MaxValue };
            for (int j = 1; j <= N * N; j++)
                states[2][j] = new Move() { pawn = Pawn.Rook, Num = j, Moves = int.MaxValue, Rep = int.MaxValue };

            states[0][1] = new Move() { pawn = Pawn.Bishop, Num = 1, Moves = 0, Rep = 0 };
            states[1][1] = new Move() { pawn = Pawn.Knight, Num = 1, Moves = 0, Rep = 0 };
            states[2][1] = new Move() { pawn = Pawn.Rook, Num = 1, Moves = 0, Rep = 0 };

            minheap.Add(states[0][1]);
            minheap.Add(states[1][1]);
            minheap.Add(states[2][1]);

            while (minheap.Count > 0)
            {
                var item = minheap.ExtractMin();

                Pawn p = item.pawn;
                int currentnum = item.Num;
                int intPaws = (int)p;

                //  Console.WriteLine("*******************");
                //  Console.WriteLine("" + p + " currentnum " + currentnum);

                if (currentnum == N * N) break;

                if (p == Pawn.Bishop)
                {
                    //Get Bishop distance
                    var dist = bishop_distances[currentnum + 1];
                    if (dist.Item1 != int.MaxValue)
                    {
                        if (item.Moves + dist.Item1 < states[0][currentnum + 1].Moves
                            || (item.Moves + dist.Item1 == states[0][currentnum + 1].Moves && item.Rep < states[0][currentnum + 1].Rep))
                        {
                            states[0][currentnum + 1] = new Move()
                            {
                                Num = currentnum + 1,
                                Moves = item.Moves + dist.Item1,
                                pawn = Pawn.Bishop,
                                Rep = item.Rep
                            };

                            minheap.Add(states[0][currentnum + 1]);
                        }
                    }

                    //Get Knight distance
                    dist = Knight_distances[currentnum + 1];
                    if (dist.Item1 != int.MaxValue)
                    {
                        if (item.Moves + dist.Item1 + 1 < states[1][currentnum + 1].Moves
                            || (item.Moves + dist.Item1 + 1 == states[1][currentnum + 1].Moves && item.Rep + 1 < states[1][currentnum + 1].Rep))
                        {
                            states[1][currentnum + 1] = new Move()
                            {
                                Num = currentnum + 1,
                                Moves = item.Moves + dist.Item1 + 1,
                                pawn = Pawn.Knight,
                                Rep = item.Rep + 1
                            };

                            minheap.Add(states[1][currentnum + 1]);
                        }
                    }

                    //Get Rook distance
                    dist = rook_distances[currentnum + 1];
                    if (dist.Item1 != int.MaxValue)
                    {
                        if (item.Moves + dist.Item1 + 1 < states[2][currentnum + 1].Moves
                            || (item.Moves + dist.Item1 + 1 == states[2][currentnum + 1].Moves && item.Rep + 1 < states[2][currentnum + 1].Rep))
                        {
                            states[2][currentnum + 1] = new Move()
                            {
                                Num = currentnum + 1,
                                Moves = item.Moves + dist.Item1 + 1,
                                pawn = Pawn.Rook,
                                Rep = item.Rep + 1
                            };

                            minheap.Add(states[2][currentnum + 1]);
                        }
                    }
                }
                else if (p == Pawn.Knight)
                {
                    var dist = Knight_distances[currentnum + 1];
                    if (dist.Item1 != int.MaxValue)
                    {
                        if (item.Moves + dist.Item1 < states[1][currentnum + 1].Moves
                            || (item.Moves + dist.Item1 == states[1][currentnum + 1].Moves && item.Rep < states[1][currentnum + 1].Rep))
                        {
                            states[1][currentnum + 1] = new Move()
                            {
                                Num = currentnum + 1,
                                Moves = item.Moves + dist.Item1,
                                pawn = Pawn.Knight,
                                Rep = item.Rep
                            };

                            minheap.Add(states[1][currentnum + 1]);
                        }
                    }

                    dist = rook_distances[currentnum + 1];
                    if (dist.Item1 != int.MaxValue)
                    {
                        if (item.Moves + dist.Item1 + 1 < states[2][currentnum + 1].Moves
                            || (item.Moves + dist.Item1 + 1 == states[2][currentnum + 1].Moves && item.Rep + 1 < states[2][currentnum + 1].Rep))
                        {
                            states[2][currentnum + 1] = new Move()
                            {
                                Num = currentnum + 1,
                                Moves = item.Moves + dist.Item1 + 1,
                                pawn = Pawn.Rook,
                                Rep = item.Rep + 1
                            };

                            minheap.Add(states[2][currentnum + 1]);
                        }
                    }

                    dist = bishop_distances[currentnum + 1];
                    if (dist.Item1 != int.MaxValue)
                    {
                        if (item.Moves + dist.Item1 + 1 < states[0][currentnum + 1].Moves
                            || (item.Moves + dist.Item1 + 1 == states[0][currentnum + 1].Moves && item.Rep + 1 < states[0][currentnum + 1].Rep))
                        {
                            states[0][currentnum + 1] = new Move()
                            {
                                Num = currentnum + 1,
                                Moves = item.Moves + dist.Item1 + 1,
                                pawn = Pawn.Bishop,
                                Rep = item.Rep + 1
                            };

                            minheap.Add(states[0][currentnum + 1]);
                        }
                    }
                }
                else if (p == Pawn.Rook)
                {
                    var dist = rook_distances[currentnum + 1];
                    if (dist.Item1 != int.MaxValue)
                    {
                        if (item.Moves + dist.Item1 < states[2][currentnum + 1].Moves
                            || (item.Moves + dist.Item1 == states[2][currentnum + 1].Moves && item.Rep < states[2][currentnum + 1].Rep))
                        {
                            states[2][currentnum + 1] = new Move()
                            {
                                Num = currentnum + 1,
                                Moves = item.Moves + dist.Item1,
                                pawn = Pawn.Rook,
                                Rep = item.Rep
                            };

                            minheap.Add(states[2][currentnum + 1]);
                        }
                    }

                    dist = bishop_distances[currentnum + 1];
                    if (dist.Item1 != int.MaxValue)
                    {
                        if (item.Moves + dist.Item1 + 1 < states[0][currentnum + 1].Moves
                            || (item.Moves + dist.Item1 + 1 == states[0][currentnum + 1].Moves && item.Rep + 1 < states[0][currentnum + 1].Rep))
                        {
                            states[0][currentnum + 1] = new Move()
                            {
                                Num = currentnum + 1,
                                Moves = item.Moves + dist.Item1 + 1,
                                pawn = Pawn.Bishop,
                                Rep = item.Rep + 1
                            };

                            minheap.Add(states[0][currentnum + 1]);
                        }
                    }

                    dist = Knight_distances[currentnum + 1];
                    if (dist.Item1 != int.MaxValue)
                    {
                        if (item.Moves + dist.Item1 + 1 < states[1][currentnum + 1].Moves
                            || (item.Moves + dist.Item1 + 1 == states[1][currentnum + 1].Moves && item.Rep + 1 < states[1][currentnum + 1].Rep))
                        {
                            states[1][currentnum + 1] = new Move()
                            {
                                Num = currentnum + 1,
                                Moves = item.Moves + dist.Item1 + 1,
                                pawn = Pawn.Knight,
                                Rep = item.Rep + 1
                            };

                            minheap.Add(states[1][currentnum + 1]);
                        }
                    }
                }
            }

            int res = int.MaxValue;

            res = Math.Min(states[1][N * N].Moves, res);
            res = Math.Min(states[2][N * N].Moves, res);
            res = Math.Min(states[0][N * N].Moves, res);

            int moves = int.MaxValue;

            if (res == states[0][N * N].Moves)
                moves = Math.Min(states[0][N * N].Rep, moves);

            if (res == states[1][N * N].Moves)
                moves = Math.Min(states[1][N * N].Rep, moves);
            if (res == states[2][N * N].Moves)
                moves = Math.Min(states[2][N * N].Rep, moves);

            Console.WriteLine("" + res + " " + moves);
        }

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using static Template;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pi = Pair<int, int>;

class Solver
{
    Scanner sc = new Scanner();
    //

    public void Solve()
    {
        var a = ReadLine();
        var b = ReadLine();
        if (a.Length < b.Length) Fail(new string(a.OrderByDescending(c => c).ToArray()));
        if (a==b) Fail(a);
        var max = 0L;
        for (var j = 0; j <= a.Length; j++)
        {
            var u = new List<char>();
            for (var i = 0; i < a.Length; i++)
                u.Add(a[i]);
            var res = "";
            for(var i = 0; i < j; i++)
            {
                u.Sort((c, d) => d - c);
                var idx = 0;
                while (idx!=a.Length&&b[i] < u[idx]) idx++;
                if (idx == a.Length || u[idx] != b[i]) goto END;
                res += u[idx]; u.RemoveAt(idx);
            }
            if (j == a.Length)
            {
                chmax(ref max, long.Parse(res));break;
            }
            u.Sort((c, d) => d - c);
            var id = 0;
            while (id != u.Count && b[j] <= u[id]) id++;
            if (id == u.Count) continue;
            res += u[id];u.RemoveAt(id);
            u.Sort((c, d) => d - c);
            for (var i = 0; i < u.Count; i++)
                res += u[i];
            chmax(ref max, long.Parse(res));
        }
    END:;
        WriteLine(max);
    }
}

#region Template
public class Template
{
    static void Main(string[] args)
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver().Solve();
        Console.Out.Flush();
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmin<T>(ref T a, T b) where T : IComparable<T>
    { if (a.CompareTo(b) == 1) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmax<T>(ref T a, T b) where T : IComparable<T>
    { if (a.CompareTo(b) == -1) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(ref T a, ref T b)
    { var t = b; b = a; a = t; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static T[] Create<T>(int n, Func<T> f)
    {
        var rt = new T[n];
        for (var i = 0; i < rt.Length; ++i)
            rt[i] = f();
        return rt;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static T[] Create<T>(int n, Func<int, T> f)
    {
        var rt = new T[n];
        for (var i = 0; i < rt.Length; ++i)
            rt[i] = f(i);
        return rt;
    }
    public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }
}

public class Scanner
{
    public string Str => ReadLine().Trim();
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
    public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
    public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
    public int[] ArrInt1D(int n) => Create(n, () => Int);
    public long[] ArrLong1D(int n) => Create(n, () => Long);
    public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
    public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
    public Pair<T1, T2> PairMake<T1, T2>() => new Pair<T1, T2>(Next<T1>(), Next<T2>());
    public Pair<T1, T2, T3> PairMake<T1, T2, T3>() => new Pair<T1, T2, T3>(Next<T1>(), Next<T2>(), Next<T3>());
    private Queue<string> q = new Queue<string>();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }
    public void Make<T1>(out T1 v1) => v1 = Next<T1>();
    public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); }
    public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); }
    public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); }
    public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); }
    public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); }
}

public class Pair<T1, T2> : IComparable<Pair<T1, T2>>
{
    public T1 v1;
    public T2 v2;
    public Pair() { }
    public Pair(T1 v1, T2 v2)
    { this.v1 = v1; this.v2 = v2; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2> p)
    {
        var c = Comparer<T1>.Default.Compare(v1, p.v1);
        if (c == 0)
            c = Comparer<T2>.Default.Compare(v2, p.v2);
        return c;
    }
    public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
    public void Tie(out T1 a, out T2 b) { a = v1; b = v2; }
}

public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>>
{
    public T3 v3;
    public Pair() : base() { }
    public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2)
    { this.v3 = v3; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2, T3> p)
    {
        var c = base.CompareTo(p);
        if (c == 0)
            c = Comparer<T3>.Default.Compare(v3, p.v3);
        return c;
    }
    public override string ToString() => $"{base.ToString()} {v3.ToString()}";
    public void Tie(out T1 a, out T2 b, out T3 c) { Tie(out a, out b); c = v3; }
}
#endregion


using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using static Template;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pi = Pair<int, int>;

class Solver
{
    Scanner sc = new Scanner();
    //

    public void Solve()
    {
        var a = ReadLine();
        var b = ReadLine();
        if (a.Length < b.Length) Fail(new string(a.OrderByDescending(c => c).ToArray()));
        if (a==b) Fail(a);
        var max = 0L;
        for (var j = 0; j <= a.Length; j++)
        {
            var u = new List<char>();
            for (var i = 0; i < a.Length; i++)
                u.Add(a[i]);
            var res = "";
            for(var i = 0; i < j; i++)
            {
                u.Sort((c, d) => d - c);
                var idx = 0;
                while (idx!=u.Length&&b[i] < u[idx]) idx++;
                if (idx == u.Length || u[idx] != b[i]) goto END;
                res += u[idx]; u.RemoveAt(idx);
            }
            if (j == a.Length)
            {
                chmax(ref max, long.Parse(res));break;
            }
            u.Sort((c, d) => d - c);
            var id = 0;
            while (id != u.Count && b[j] <= u[id]) id++;
            if (id == u.Count) continue;
            res += u[id];u.RemoveAt(id);
            if (u.Count == 0) { chmax(ref max, long.Parse(res));continue; }
            u.Sort((c, d) => d - c);
            for (var i = 0; i < u.Count; i++)
                res += u[i];
            chmax(ref max, long.Parse(res));
        }
    END:;
        WriteLine(max);
    }
}

#region Template
public class Template
{
    static void Main(string[] args)
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver().Solve();
        Console.Out.Flush();
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmin<T>(ref T a, T b) where T : IComparable<T>
    { if (a.CompareTo(b) == 1) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmax<T>(ref T a, T b) where T : IComparable<T>
    { if (a.CompareTo(b) == -1) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(ref T a, ref T b)
    { var t = b; b = a; a = t; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static T[] Create<T>(int n, Func<T> f)
    {
        var rt = new T[n];
        for (var i = 0; i < rt.Length; ++i)
            rt[i] = f();
        return rt;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static T[] Create<T>(int n, Func<int, T> f)
    {
        var rt = new T[n];
        for (var i = 0; i < rt.Length; ++i)
            rt[i] = f(i);
        return rt;
    }
    public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }
}

public class Scanner
{
    public string Str => ReadLine().Trim();
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
    public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
    public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
    public int[] ArrInt1D(int n) => Create(n, () => Int);
    public long[] ArrLong1D(int n) => Create(n, () => Long);
    public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
    public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
    public Pair<T1, T2> PairMake<T1, T2>() => new Pair<T1, T2>(Next<T1>(), Next<T2>());
    public Pair<T1, T2, T3> PairMake<T1, T2, T3>() => new Pair<T1, T2, T3>(Next<T1>(), Next<T2>(), Next<T3>());
    private Queue<string> q = new Queue<string>();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }
    public void Make<T1>(out T1 v1) => v1 = Next<T1>();
    public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); }
    public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); }
    public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); }
    public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); }
    public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); }
}

public class Pair<T1, T2> : IComparable<Pair<T1, T2>>
{
    public T1 v1;
    public T2 v2;
    public Pair() { }
    public Pair(T1 v1, T2 v2)
    { this.v1 = v1; this.v2 = v2; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2> p)
    {
        var c = Comparer<T1>.Default.Compare(v1, p.v1);
        if (c == 0)
            c = Comparer<T2>.Default.Compare(v2, p.v2);
        return c;
    }
    public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
    public void Tie(out T1 a, out T2 b) { a = v1; b = v2; }
}

public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>>
{
    public T3 v3;
    public Pair() : base() { }
    public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2)
    { this.v3 = v3; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2, T3> p)
    {
        var c = base.CompareTo(p);
        if (c == 0)
            c = Comparer<T3>.Default.Compare(v3, p.v3);
        return c;
    }
    public override string ToString() => $"{base.ToString()} {v3.ToString()}";
    public void Tie(out T1 a, out T2 b, out T3 c) { Tie(out a, out b); c = v3; }
}
#endregion


using System;
using System.Linq;
class Program
{
    static void Main()
    {
        int[] alm = Console.ReadLine().Split(' ').Select(x=>int.Parse(x)).ToArray();
        int[] oil = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        oil[0] = oil[0] * 2 + oil[1];
        oil[1] = oil[2] * 3 + oil[1];
        oil[2] = 0;
        var result = oil.Sum() - alm.Sum();
        Console.WriteLine(result);
    }
}


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

namespace _869C
{
    class Program
    {
        public static void Swap<T>(ref T lhs, ref T rhs)
        {
            T temp = lhs;
            lhs = rhs;
            rhs = temp;
        }

        static void Main(string[] args)
        {
            int[] tmp = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
            if (tmp[1] < tmp[0])
            {
                Swap(ref tmp[0], ref tmp[1]);
            }
            if (tmp[2] < tmp[0])
            {
                Swap(ref tmp[0], ref tmp[1]);
            }

            long[,] dp = new long[tmp[1] + 1, tmp[2] + 1];
            for (int i = 0; i <= tmp[1]; i++)
            {
                for (int j = 0; j <= tmp[2]; j++)
                {
                    if (i == 0 || j == 0)
                    {
                        dp[i, j] = 1;
                    }
                    else
                    {
                        dp[i, j] = (dp[i - 1, j] + dp[i - 1, j - 1] * j) % 998244353;
                    }
                }
            }

            long r = (((dp[tmp[1], tmp[0]] * dp[tmp[1], tmp[2]]) % 998244353) * dp[tmp[0], tmp[2]]) % 998244353;
            Console.WriteLine(r);
        }
    }
}


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

namespace CF
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            using (var sr = new InputReader(Console.In))
//			using (var sr = new InputReader(new StreamReader("input.txt")))
            using (var sw = Console.Out)
                //using (var sw = new StreamWriter("output.txt"))
            using (var task = new Task(sr, sw)) {
                task.Solve();
//                Console.ReadKey();
            }
        }
    }

    internal class Task : IDisposable
    {
        private readonly InputReader sr;
        private readonly TextWriter sw;
        private bool isDispose;

        const long mod = 998244353L;

        public Task(InputReader sr, TextWriter sw)
        {
            this.sr = sr;
            this.sw = sw;
        }

        public void Solve()
        {
            var a = sr.NextInt32();
            var b = sr.NextInt32();
            var c = sr.NextInt32();
            var facts = Facts(2*Math.Max(a, Math.Max(b, c)));
            var coeffs = BinCoeff(2*Math.Max(a, Math.Max(b, c)));
            sw.WriteLine((Func(a, b, facts, coeffs)*Func(b, c, facts, coeffs)*Func(c, a, facts, coeffs))%mod);
        }

        private long[] Facts(int max)
        {
            var facts = new long[max + 1];
            facts[0] = 1L;
            for (var i = 1; i <= max; i++) {
                facts[i] = (facts[i - 1] * i) % mod;
            }

            return facts;
        }

        private long Func(long a, long b, long[] facts, long[,] binCoeff)
        {
            var r = binCoeff[b, 0] * facts[0] + binCoeff[b, 1] * facts[0];
            for (var i = 2; i <= a; i++) {
                for (var j = 0; j < i; j++) {
                    r = (r + b * binCoeff[b - 1, j] * binCoeff[i - 1, j] * facts[j] % mod) % mod;
                }
            }

            return r;
        }

        private long[,] BinCoeff(int max)
        {
            var coeff = new long[max + 1, max + 1];
            for (var i = 0; i <= max; i++) {
                coeff[i, 0] = 1;
                coeff[i, i] = 1;
            }
            for (var i = 1; i <= max; i++) {
                for (var j = 1; j <= max; j++) {
                    coeff[i, j] = (coeff[i - 1, j] + coeff[i - 1, j - 1])%mod;
                }
            }

            return coeff;
        }

        ~Task()
        {
            Dispose(false);
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        private void Dispose(bool disposing)
        {
            if (!isDispose) {
                if (disposing) {
                    if(sr != null)
                        sr.Dispose();

                    if(sw != null)
                        sw.Dispose();
                }

                isDispose = true;
            }
        }
    }
}

internal class InputReader : IDisposable
{
    private bool isDispose;
    private readonly TextReader sr;
    private string[] buffer;
    private int seek;

    public InputReader(TextReader stream)
    {
        sr = stream;
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    public string NextString()
    {
        var result = sr.ReadLine();
        return result;
    }

    public int NextInt32()
    {
        return Int32.Parse(ReadNextToken());
    }

    private string ReadNextToken()
    {
        if (buffer == null || seek == buffer.Length) {
            seek = 0;
            buffer = NextSplitStrings();
        }

        return buffer[seek++];
    }

    public long NextInt64()
    {
        return Int64.Parse(ReadNextToken());
    }

    public int[] ReadArrayOfInt32()
    {
        return ReadArray(Int32.Parse);
    }

    public long[] ReadArrayOfInt64()
    {
        return ReadArray(Int64.Parse);
    }

    public string[] NextSplitStrings()
    {
        return NextString()
            .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
    {
        return NextSplitStrings()
            .Select(s => func(s, CultureInfo.InvariantCulture))
            .ToArray();
    }

    public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
    {
        return
            str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(s => func(s, CultureInfo.InvariantCulture))
                .ToArray();
    }

    protected void Dispose(bool dispose)
    {
        if (!isDispose)
        {
            if (dispose)
                sr.Close();

            isDispose = true;
        }
    }

    ~InputReader()
    {
        Dispose(false);
    }
}


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

namespace Suffix_Structures
{
    class Program
    {
        static bool chec(  string ss,  string tt)
        {
            char[] s =  ss.ToCharArray();
            char[] t = tt.ToCharArray();
            for (int i = 0; i < t.Count(); i++)
            {
                bool ddd = false;
                for (int c = 0; c < s.Count(); c++)
                {
                    if (t[i] == s[c])
                    { ddd = true;

                        s[c] = ',';

                        break; }
                }

                if (!ddd)
                {
                    return false;
                }
            }
            return true;
        }
        static void Main(string[] args)
        {
           // var bb = chec("arary", "array");

            Console.WriteLine(ss);
            string s, t;
            s = Console.ReadLine();

            t= Console.ReadLine();
            int cc, rr;
            cc = s.Count();
            rr = t.Count();
            if (chec(s,t)&&rr==cc)
            {
                Console.WriteLine("array"); return;
            }

            int column = 0,i;
            for (  i = 0; i < rr; i++)
            {
                while (column<cc && t[i]!=s[column])
                {
                    column++;
                }
                if (column==cc)
                {
                    break;
                }
            }
            if (i==rr)
            {
                Console.WriteLine("automaton"); return;
            }
            if (chec(s, t) && rr < cc)
            {
                Console.WriteLine("both"); return;
            }
            Console.WriteLine("need tree"); return;

        }
    }
}


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

namespace Testerka
{
    class Program
    {
        static void Main(string[] args)
        {
            int ans = 0;
            string input = Console.ReadLine();
            string input2 = Console.ReadLine();
            string[] numba = input.Split(' ');
            int yellow = Convert.ToInt32(numba[0]);
            int blue = Convert.ToInt32(numba[1]);
            string[] numba2 = input2.Split(' ');
            int yellowneed = Convert.ToInt32(numba[0]);
            int greenneed = Convert.ToInt32(numba[1]);
            int blueneed = Convert.ToInt32(numba[2]);
            yellow = yellow - yellowneed * 2;
            blue = blue - blueneed;
            yellow = yellow - greenneed * 3;
            blue = blue - blueneed;

            if (blue > 0) blue = 0;
            else blue = blue - blue - blue;
            if (yellow > 0) yellow = 0;
            else yellow = yellow - yellow - yellow;

            ans = yellow + blue;

            Console.WriteLine(ans);

        }
    }
}


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

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int a = sc.NextInt();
        for (int n = a; ; n++)
        {
            var str = n.ToString();
            var sum = 0;
            foreach (var c in sum)
            {
                sum += c - '0';
            }

            if (sum % 4 == 0)
            {
                Console.WriteLine(n);
                return;
            }
        }
    }

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


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30011.22
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeForces", "CodeForces\CodeForces.csproj", "{EED76156-CCE4-42C9-A987-930CFF62AF5F}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Any CPU = Debug|Any CPU
		Release|Any CPU = Release|Any CPU
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{EED76156-CCE4-42C9-A987-930CFF62AF5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{EED76156-CCE4-42C9-A987-930CFF62AF5F}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{EED76156-CCE4-42C9-A987-930CFF62AF5F}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{EED76156-CCE4-42C9-A987-930CFF62AF5F}.Release|Any CPU.Build.0 = Release|Any CPU
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
	GlobalSection(ExtensibilityGlobals) = postSolution
		SolutionGuid = {1C1D43E7-DF4C-4656-AEE4-ABD77639473E}
	EndGlobalSection
EndGlobal


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

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

            for (int i = n; i <= 1000; i++)
            {
                int[] arr = IntArray(i);
                int total = 0;

                for (int k = 0; k < arr.Length; k++)
                {
                    total += arr[k];
                }

                if (total % 4 == 0)
                {
                    Console.WriteLine(i);
                    break;
                }
            }
        }

        public static int[] IntArray(int num)
        {
            List<int> listOfInts = new List<int>();
            while (num > 0)
            {
                listOfInts.Add(num % 10);
                num = num / 10;
            }
            listOfInts.Reverse();
            return listOfInts.ToArray();
        }
    }
}


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

namespace CodeJam
{
    class Solution4
    {
        static void Main()
        {
            new Thread(new Solution4().run, 64 * 1024 * 1024).Start();
        }
        long x0, y0, ax, ay, bx, by, xs, ys, t;
        List<long> xC;
        List<long> yC;
        long answer = 0;
        void ReadData()
        {
            x0 = NextLong();
            y0 = NextLong();
            ax = NextLong();
            ay = NextLong();
            bx = NextLong();
            by = NextLong();
            xs = NextLong();
            ys = NextLong();
            t = NextLong();
            xC = new List<long>();
            yC = new List<long>();
            xC.Add(x0);
            yC.Add(y0);

            do
            {
                long newX = ax * xC[xC.Count - 1] + bx;
                long newY = ay * yC[yC.Count - 1] + by;
                if (newX > 1.16e18 || newY > 1.16e18)
                    break;
                xC.Add(newX);
                yC.Add(newY);
            } while (true);
        }
        long mhDist(long x1, long x2, long y1, long y2)
        {
            return Math.Abs(x1 - x2) + Math.Abs(y1 - y2);
        }

        void Solve()
        {

            for (int i=0; i<xC.Count; i++)
            {
                answer = Math.Max(answer, SolveForStart(i));
            }
        }

        long SolveForStart(int startDevice)
        {
            long localTime = t;
            localTime -= mhDist(xC[startDevice], xs, yC[startDevice], ys);
            if (localTime < 0)
                return 0;
            if (localTime == 0)
                return 1;
            long res = 1;
            for (int i=startDevice-1; i>=0;i--)
            {
                localTime -= mhDist(xC[i], xC[i + 1], yC[i], yC[i + 1]);
                if (localTime < 0)
                    break;
                res++;
            }
            if (startDevice == xC.Count - 1)
                return res;
            localTime -= mhDist(xC[0], xC[startDevice], yC[0], yC[startDevice]);
            for (int i=startDevice; i<xC.Count;i++)
            {
                localTime -= mhDist(xC[i], xC[i + 1], yC[i], yC[i + 1]);
                if (localTime < 0)
                    break;
                res++;
            }
            return res;
        }

        void WriteAnswer()
        {
            _outputStream.WriteLine(answer);
        }

        #region ...

        void run()
        {
            //Console.SetIn(new StreamReader(Console.OpenStandardInput(), Console.InputEncoding, false, bufferSize: 100024));
            //_inputStream = new StreamReader(File.OpenRead(@"C:\Users\v.lukiantsev\Downloads\progresspie.in"));
            //_outputStream = new StreamWriter(File.OpenWrite(@"C:\Users\v.lukiantsev\Downloads\progress_pie.out"));

            _inputStream = Console.In;
            _outputStream = Console.Out;

            int testsCount = 1;
            var solvers = new Solution4[testsCount];
            for (int i = 0; i < testsCount; ++i)
            {
                solvers[i] = new Solution4();
                solvers[i].ReadData();
            }

            int done = 0;
            for (int i = 0; i < testsCount; ++i)
            {
                solvers[i].Solve();
                Console.Title = (++done).ToString() + " of " + testsCount;
            }
            for (int i = 0; i < testsCount; ++i)
            {
                //Out.Write(string.Format("Case #{0}: ", i + 1));
                solvers[i].WriteAnswer();
            }
            Out.Flush();
            Out.Close();
        }

        static TextWriter Out { get { return _outputStream; } }

        private static TextReader _inputStream;
        private static TextWriter _outputStream;

        public double NextDouble()
        {
            var token = NextToken();
            if (string.IsNullOrEmpty(token)) throw new ApplicationException("Input data missing");
            return double.Parse(token, CultureInfo.InvariantCulture);
        }

        public long NextLong()
        {
            var token = NextToken();
            if (string.IsNullOrEmpty(token)) throw new ApplicationException("Input data missing");
            return long.Parse(token);
        }

        public int NextInt()
        {
            var token = NextToken();
            if (string.IsNullOrEmpty(token)) throw new ApplicationException("Input data missing");
            return int.Parse(token);
        }

        private static readonly Queue<string> Tokens = new Queue<string>();
        public string NextToken()
        {
            if (Tokens.Count > 0)
            {
                return Tokens.Dequeue();
            }
            while (Tokens.Count == 0)
            {
                var line = _inputStream.ReadLine();
                if (line == null) return null;
                foreach (var token in line.Split(_whiteSpaces, StringSplitOptions.RemoveEmptyEntries))
                {
                    Tokens.Enqueue(token);
                }
            }
            return Tokens.Count == 0 ? null : Tokens.Dequeue();
        }

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

        #endregion
    }
}


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

namespace ConsoleApp2
{
    class Program
    {
        struct point
        {
            public long x;
            public long y;
        }

        static int count(long X0, long Y0, long Ax, long Ay, long Bx, long By, long Xs,
            long Ys, List<point> Needpoints, long t)
        {
            int Result = 0;
            long CurX = Xs;
            long CurY = Ys;
            for (int i = Needpoints.Count - 1; i >= 0; i--)
            {
                if ((CurX - Needpoints[i].x) + (CurY - Needpoints[i].y) <= t)
                {
                    t -= (CurX - Needpoints[i].x) + (CurY - Needpoints[i].y);
                    Result++;
                    CurX = Needpoints[i].x;
                    CurY = Needpoints[i].y;
                }
                else
                {
                    return Result;
                }
            }
            CurX = X0;
            CurY = Y0;
            long NextX = Ax * Needpoints[Needpoints.Count - 1].x + Bx;
            long NextY = Ay * Needpoints[Needpoints.Count - 1].y + By;
            while (true)
            {
                if ((NextX - CurX) + (NextY - CurY) <= t)
                {
                    t -= (NextX - CurX) + (NextY - CurY);
                    Result++;
                    CurX = NextX;
                    CurY = NextY;
                    NextX = Ax * NextX + Bx;
                    NextY = Ay * NextY + By;
                }
                else
                {
                    return Result;
                }
            }
        }
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            long X0 = long.Parse(str[0]);
            long Y0 = long.Parse(str[1]);
            long Ax = long.Parse(str[2]);
            long Ay = long.Parse(str[3]);
            long Bx = long.Parse(str[4]);
            long By = long.Parse(str[5]);
            str = Console.ReadLine().Split();
            long Xs = long.Parse(str[0]);
            long Ys = long.Parse(str[1]);
            long t = long.Parse(str[2]);
            List<point> Needpoints = new List<point>();
            long CurX = X0, CurY = Y0;
            while (true)
            {
                if (CurX <= Xs && CurY <= Ys)
                {
                    Needpoints.Add(new point() { x = CurX, y = CurY });
                }
                else
                {
                    break;
                }
                CurX = Ax * CurX + Bx;
                CurY = Ay * CurY + By;
            }
            int count1 = count(X0, Y0, Ax, Ay, Bx, By, Xs, Ys, Needpoints, t);
            long NextX = Ax * Needpoints[Needpoints.Count - 1].x + Bx;
            long NextY = Ay * Needpoints[Needpoints.Count - 1].y + By;
            int count2 = 0;
            if (Math.Abs(NextX - Xs) + Math.Abs(NextY - Ys) <= t)
            {
                t -= Math.Abs(NextX - Xs) + Math.Abs(NextY - Ys);
                Xs = NextX;
                Ys = NextY;
                Needpoints.Add(new point() { x = NextX, y = NextY });
                count2 = count(X0, Y0, Ax, Ay, Bx, By, Xs, Ys, Needpoints, t);
            }
            Console.WriteLine(Math.Max(count1, count2));
        }
    }
}


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

class Program
{

    //////////////////////////////////////////////////
    void Solution()
    {
        var d = rl;
        var k = rl;
        var a = rl;
        var b = rl;
        var t = rl;

        d -= k;
        if (d <= 0)
        {
            wln(d * a);
            return;
        }

        long pesh = d * b;
        long auto = (d / k) * (k * a + t);
        long s = auto + (d % k) * b;
        if (d % k != 0)
        {
            auto += (d % k) * a + t;
        }

        long res = Math.Min(pesh, Math.Min(auto, s));
        wln(k * a + res);

    }
    //////////////////////////////////////////////////

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

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

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

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


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

namespace Task55A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int ct = 0;
            int omit = 0;
            int sit = 1;
            HashSet<int> container = new HashSet<int>() { sit };
            string ans = "No";
            while (true)
            {
                if (container.Count == n)
                {
                    ans = "Yes";
                    break;
                }
                else if (omit > 2 * n)
                    break;

                sit += omit;
                if (sit > n) sit %= n;
                container.Add(sit);
                omit++;

            }
            Console.WriteLine(ans);
           // Console.ReadKey();
        }
    }
}


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

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = 1,n2, pad,Ln,Rn,L = 0,R = 0,timel,timer;
            string[] s1, s2, s3;
            s1 = Console.ReadLine().Split();
            s2 = Console.ReadLine().Split();
            s3 = Console.ReadLine().Split();
            pad = Convert.ToInt32(s1[1]);
            timel = Convert.ToInt32(s3[0]);
            timer = Convert.ToInt32(s3[s3.Length-1]);
            n2 = s3.Length - 2;
            for(int m = 0;m<s2.Length;m++)
            {
                Ln = Convert.ToInt32(s2[m]) - pad * timel;
                if(Ln>0)
                {
                    L = L+Ln;
                }

                if (n < s2.Length)
                {
                    timel = timel + Convert.ToInt32(s3[n]);
 n++;
                }
                Rn =  Convert.ToInt32(s2[s2.Length - 1 - m]) - pad * timer;
               if(Rn>0)
               {
                   R = R+Rn;
               }
                if (n2>=0)
                {
                    timer = timer + Convert.ToInt32(s3[n2]);
                    n2--;
                }
            }
            if (L > R)
            {
                Console.Write("Limark");
            }
            if(L<R)
            {
                Console.Write("Radewoosh");
            }
            if(L == R)
            {
                Console.Write("Tie");
            }

        }
    }
}


using System;
using System.Linq;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(' ');

            var secores= Console.ReadLine().Split(' ');

            var times = Console.ReadLine().Split(' ');

            var length = Convert.ToInt32(inputs[0]);

            var dp = Convert.ToDecimal(inputs[1]);

            decimal Limak = 0;
            decimal Radewoosh = 0;
            decimal ttimes = 0;

            for (int i=0;i< length;i++)
            {
                ttimes +=Convert.ToDecimal(times[i]);

                var indPoints = Convert.ToDecimal(secores[i]) - ttimes * dp;

                if(indPoints>0)
                {
                    Limak += indPoints;
                }
            }
            ttimes = 0;
            for (int i = length-1; i > 0; i--)
            {
                ttimes += Convert.ToDecimal(times[i]);

                var indPoints = Convert.ToDecimal(secores[i]) - ttimes * dp;

                if (indPoints > 0)
                {
                    Radewoosh += indPoints;
                }
            }
            if(Limak> Radewoosh)
            {
                Console.WriteLine("Limak");
            }
            else if (Limak < Radewoosh)
            {
                Console.WriteLine("Radewoosh");
            }
            else
            {
                Console.WriteLine("Tie");
            }
        }
    }
}


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

namespace Colorful_Bricks
{
    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));
            writer.Flush();
        }

        private static long Solve(string[] args)
        {
            int n = Next();
            int m = Next();
            int k = Next();

            const int mod = 998244353;

            var dp = new long[k + 1];
            dp[0] = m;

            for (int i = 2; i <= n; i++)
            {
                for (int j = 1; j < dp.Length; j++)
                {
                    dp[j] = (dp[j] + dp[j - 1]*(m - 1))%mod;
                }
            }

            return dp[k];
        }

        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;

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

                var answer = new char[q];
                for (var i = 0; i < q; ++i)
                {
                        string[] input = Console.ReadLine().Split(' ');
                        int n = int.Parse(input[0]);
                        long k = long.Parse(input[1]) - 1;

                        char c;
                        if (Scan(n, k, out c, out k))
                        {
                                answer[i] = c;

                        }
                        else
                        {
                                answer[i] = '.';
                        }
                }
                Console.WriteLine(string.Join(string.Empty, answer));
        }

        static readonly string f0 = "What are you doing at the end of the world? Are you busy? Will you save us?";
        static readonly string pa1 = "What are you doing while sending \"";
        static readonly string pa2 = "\"? Are you busy? Will you send \"";
        static readonly string pa3 = "\"?";
        static bool Scan(int n, long k, out char c, out long newK)
        {
                newK = k;
                c = '.';
                if (n == 0)
                {
                        if (k > f0.Length)
                        {
                                newK = k - f0.Length;
                                return false;
                        }
                        c = f0[(int)k];
                        return true;
                }

                if (k < pa1.Length)
                {
                        c = pa1[(int)k];
                        return true;
                }

                if (Scan(n - 1, k - pa1.Length, out c, out newK))
                {
                        return true;
                }

                if (newK < pa2.Length)
                {
                        c = pa2[(int)newK];
                        return true;
                }

                if (Scan(n - 1, newK - pa2.Length, out c, out newK))
                {
                        return true;
                }

                if (newK < pa3.Length)
                {
                        c = pa3[(int)newK];
                        return true;
                }
                newK = newK - pa3.Length;
                return false;
        }
}


using System;

class Program
{
        const int nMax = 53; // NOTE: Levels greater that 53 will be definately greater that any k.
        static string f0 = "What are you doing at the end of the world? Are you busy? Will you save us?";
        static string pa1 = "What are you doing while sending \"";
        static string pa2 = "\"? Are you busy? Will you send \"";
        static string pa3 = "\"?";
        static long[] fnLen = new long[nMax + 1];

        static void Main(string[] args)
        {
                fnLen[0] = f0.Length;
                for (var i = 1; i <= nMax; ++i)
                {
                        fnLen[i] = 2 * fnLen[i - 1] + pa1.Length + pa2.Length + pa3.Length;
                }

                var q = int.Parse(Console.ReadLine());
                for (var i = 0; i < q; ++i)
                {
                        string[] input = Console.ReadLine().Split(' ');
                        int n = int.Parse(input[0]);
                        long k = long.Parse(input[1]) - 1;

                        Console.Write(Scan(n, k) ?? '.');

                }
                Console.Out.Flush();
        }

        static char? Scan(int n, long k)
        {
                if (n <= nMax && fnLen[n] <= k)
                        return null;

                if (n == 0)
                {
                        return f0[(int)k];
                }

                if (pa1.Length > k)
                {
                        return pa1[(int)k];
                }
                if (n - 1 > nMax || fnLen[n - 1] > k)
                {
                        return Scan(n - 1, k - pa1.Length);
                }
                if (pa2.Length > k - pa1.Length - fnLen[n - 1])
                {
                        return pa2[(int)(k - pa1.Length - fnLen[n - 1])];
                }
                if (n - 1 > nMax || fnLen[n - 1] > (k - pa1.Length - fnLen[n - 1] - pa2.Length))
                {
                        return Scan(n - 1, k - pa1.Length - fnLen[n - 1] - pa2.Length);
                }
                return pa3[(int)(k - pa1.Length - fnLen[n - 1] - pa2.Length - fnLen[n - 1])];
        }
}