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

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

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

            int b = Next();
            int tb = Next();

            int hh = Next();
            int mm = Next();

            var start = new DateTime(10, 10, 10, hh, mm, 0);
            DateTime end = start.AddMinutes(ta);
            if (end > new DateTime(10, 10, 10, 23, 59, 1))
                end = new DateTime(10, 10, 10, 23, 59, 1);

            int count = 0;
            for (var i = new DateTime(10, 10, 10, 5, 0, 0); i < end; i = i.AddMinutes(b))
            {
                DateTime e = i.AddMinutes(tb);

                if (e > start)
                    count++;
            }

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

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


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

namespace AlgoTraining.Codeforces.A_s
{

    public class FastScanner : StreamReader
    {
        private string[] _line;
        private int _iterator;

        public FastScanner(Stream stream) : base(stream)
        {
            _line = null;
            _iterator = 0;
        }
        public int NextInt()
        {
            if (_line == null || _iterator >= _line.Length)
            {
                _line = base.ReadLine().Split(' ');
                _iterator = 0;
            }
            if (_line.Count() == 0) throw new IndexOutOfRangeException("Input string is empty");
            return Convert.ToInt32(_line[_iterator++]);
        }
        public long NextLong()
        {
            if (_line == null || _iterator >= _line.Length)
            {
                _line = base.ReadLine().Split(' ');
                _iterator = 0;
            }
            if (_line.Count() == 0) throw new IndexOutOfRangeException("Input string is empty");
            return Convert.ToInt64(_line[_iterator++]);
        }
    }
    class BusesBetweenCitiesECR12
    {
        public static void Main(string[] args)
        {
            using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
            using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
            {
                int fa = fs.NextInt(), ta = fs.NextInt();
                int fb = fs.NextInt(), tb = fs.NextInt();
                string[] time = fs.ReadLine().Split(':');
                int dep = Convert.ToInt32(time[0]) * 60 + Convert.ToInt32(time[1]);
                int arr = dep + ta;
                int t = 300, z = 0;
                while (t < 1440)
                {
                    if ((t >= dep && t < arr) || (t + tb > dep && t + tb <= arr) || (t < dep && t + tb > arr)) z++;
                    t += fb;
                }
                writer.WriteLine(z);
            }
        }
    }
}


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

namespace MyFirst
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Choice.Simple();

        }
    }// End OF Program Class

    public class Choice
    {

        public static void Simple()
        {
            // ..................... Program Begin...............................
            // Take String From Input Line .............
            string input1 = Console.ReadLine();
            string input2 = Console.ReadLine();
            string input3 = Console.ReadLine();

            Scanner Input1 = new Scanner(input1);
            Scanner Input2 = new Scanner(input2);
            Scanner Input3 = new Scanner(input3,':');

            // Take Necessary Input  Formate For Program ..........
            int ah = Input1.TakeIntInputNext(), am = Input1.TakeIntInputNext();
           int bh = Input2.TakeIntInputNext(), bm = Input2.TakeIntInputNext();
           int th = Input3.TakeIntInputNext()  , tm=Input3.TakeIntInputNext() ;
           int counter = 0;

            //..... Calculation........

           for (int b = 300; b <= (23 * 60 + 59) && b <= (th * 60 + tm + am); b = b + bh)
           {
               if ((th * 60 + tm) < (b + bm) && b < (th * 60 + tm + am)) counter++;

           }

            //................ OutPut ..............
           Console.WriteLine("{0}", counter);
            //............. Program End ..............

        }

    }

    public class Scanner
    {
        string Input;
        string[] InputArray;
        int Index = 0;
        public int LengthInputString;

        public Scanner(string Input)
        {
            this.Input = Input;
            InputArray = this.Input.Split(' ');
            LengthInputString = InputArray.Length;
        }

        public Scanner(string Input, char split)
        {
            this.Input = Input;
            InputArray = this.Input.Split(split);
            LengthInputString = InputArray.Length;
        }

        public int TakeIntInputNext()
        {
            return (System.Convert.ToInt32(InputArray[Index++]));
        }

        public double TakeDoubleInputNext()
        {
            return (System.Convert.ToDouble(InputArray[Index++]));
        }

        public string TakeStringInputNext()
        {
            return InputArray[Index++].ToString();
        }

        public char TakeOneCharInputNext()
        {
            return System.Convert.ToChar(InputArray[Index++]);
        }

        public char[] TakeCharArrayInputNext()
        {
            return InputArray[Index++].ToCharArray();
        }

        public string Take_Specific_String_Input(int index)
        {
            return InputArray[index].ToString();
        }

    }
}


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

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

            //Console.SetIn(new StreamReader("file.in"));
            /*
            FileStream filestream = new FileStream("out.txt", FileMode.Create);
            var streamwriter = new StreamWriter(filestream);
            streamwriter.AutoFlush = true;
            Console.SetOut(streamwriter);
            */

            string[] s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]), ta = int.Parse(s[1]);
            s = Console.ReadLine().Split(' ');
            int b = int.Parse(s[0]), tb = int.Parse(s[1]);
            s = Console.ReadLine().Split(':');
            int h = int.Parse(s[0]), m = int.Parse(s[1]);
            int t1 = Math.Max(300, h * 60 + m - tb + 1), d1 = t1 - 300, n1 = d1 / b;
            if (d1 % b != 0) {
                n1++;
            }
            int t2 = Math.Min(1439, h * 60 + m + ta - 1), d2 = t2 - 300, n2 = d2 / b;
            Console.Write(n2 - n1 + 1);

            //Console.ReadKey();
        }
    }
}


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

namespace ReadWriteTemplate
{
    public static class Solver
    {
        public static void Solve()
        {
            int a = ReadInt();
            int ta = ReadInt();
            int b = ReadInt();
            int tb = ReadInt();

            var timeStr = Reader.ReadLine().Split(':');
            int startTime = int.Parse(timeStr[0]) * 60 + int.Parse(timeStr[1]);
            int endTime = startTime + ta;

            int ans = 0;

            int t = 5 * 60;
            while (t <= 60 * 23 + 59)
            {
                if (!(t >= endTime || t + tb <= startTime))
                {
                    ans++;
                }

                t += b;
            }

            Writer.WriteLine(ans);
        }

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

        public static void Main()
        {
            Reader = Console.In; Writer = Console.Out;
            // Reader = File.OpenText("input.txt"); Writer = File.CreateText("output.txt");

            Solve();

            Reader.Close();
            Writer.Close();
        }

        public static IOrderedEnumerable<TSource> OrderByWithShuffle<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
        {
            return source.Shuffle().OrderBy(keySelector);
        }

        public static T[] Shuffle<T>(this IEnumerable<T> source)
        {
            T[] result = source.ToArray();
            Random rnd = new Random();
            for (int i = result.Length - 1; i >= 1; i--)
            {
                int k = rnd.Next(i + 1);
                T tmp = result[k];
                result[k] = result[i];
                result[i] = tmp;
            }
            return result;
        }

        #region Read/Write

        private static TextReader Reader;

        private static TextWriter Writer;

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

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

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

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

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

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

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

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

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

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

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

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

        #endregion
    }

    public class AccDict<T>
    {
        private Dictionary<T, long> _dict = new Dictionary<T, long>();

        public void Add(T key)
        {
            if (_dict.ContainsKey(key))
            {
                _dict[key]++;
            }
            else
            {
                _dict[key] = 1;
            }
        }

        public long Get(T key)
        {
            return _dict.ContainsKey(key) ? _dict[key] : 0;
        }

        public Dictionary<T, long>.ValueCollection Values
        {
            get { return _dict.Values; }
        }
    }
}


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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public void Solve()
    {
        ReadInt();
        int ta = ReadInt();
        int b = ReadInt();
        int tb = ReadInt();
        var s = ReadToken().Split(':');
        int x = int.Parse(s[0]) * 60 + int.Parse(s[1]);

        int ans = 0;
        for (int i = 300; i < 1440; i += b)
            if (i < x + ta && i + tb > x)
                ans++;

        Write(ans);
    }

    #region Main

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

    #endregion

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


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

namespace ConsoleApplication20
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int[] n1 = Array.ConvertAll(s, int.Parse);
            s = Console.ReadLine().Split(' ');
            int[] n2 = Array.ConvertAll(s, int.Parse);
            s = Console.ReadLine().Split(':');

            int a = int.Parse(s[0]) * 60 + int.Parse(s[1]);
            int b1 = 5 * 60;
            int b2 = 23 * 60 + 59;
            int am = Math.Max(a - n2[1] + 1, b1);
            int bm = Math.Min(a + n1[1] - 1, b2);
            int f = 0;
            int c = 0;

            if ((am - b1) % n2[0] == 0)
            {
                f = am;
            }
            else
            {
                f = am + (n2[0] - (am - b1) % n2[0]);
            }

            if (bm >= f)
            {
                c = (bm - f) / n2[0] + 1;
            }
            Console.WriteLine(c);

        }
    }
}


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

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

	internal class Task
	{
		public void Solve(int testNumber, InputReader sr, TextWriter sw)
		{
			var input = sr.ReadArray(Int32.Parse);
			var a = input[0];
			var ta = input[1];
			input = sr.ReadArray(Int32.Parse);
			var b = input[0];
			var tb = input[1];
			var str = sr.NextString().Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
			var h = str[0][0] == '0' ? Int32.Parse(str[0][1].ToString(CultureInfo.InvariantCulture)) : Int32.Parse(str[0]);
			var m = str[1][0] == '0' ? Int32.Parse(str[1][1].ToString(CultureInfo.InvariantCulture)) : Int32.Parse(str[1]);
			var count = 0;
			var start = h * 60 + m;
			int end =start + ta;
			var bArr = new List<Tuple<int, int>>();
			for (var startB = 5 * 60; startB <= 23*60 + 59; startB += b) {
				bArr.Add(new Tuple<int, int>(startB, startB + tb));
			}
			for (var i = 0; i < bArr.Count; i++) {
				var next = bArr[i];
				if (start < next.Item2 && next.Item1 < end) {
					count++;
				}
			}

			sw.WriteLine(count);
		}
	}

	internal class InputReader : IDisposable
	{
		private bool isDispose;
		private readonly TextReader sr;

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

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

		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;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;

namespace Codeforces
{
    internal class Program
    {
        private static void Main()
        {
            if (Debugger.IsAttached)
            {
                Console.SetIn(new StreamReader(@"..\..\..\..\Tests\D5.in"));
            }

            Solve();

            if (Debugger.IsAttached)
            {
                Console.In.Close();
                Console.SetIn(new StreamReader(Console.OpenStandardInput()));
                Console.ReadLine();
            }
        }

        private static void Solve()
        {
            var s = Read();
            var intF = new int[10];
            var intS = new int[10];
            foreach (var n in s)
            {
                intF[n - '0']++;
                intS[n - '0']++;
            }

            var max = 0;
            var maxIndex = -1;
            for (int i = 1; i < 10; i++)
            {
                var res = 0;
                var j = 10 - i;
                if(intF[i] > 0 && intS[j] > 0)
                {
                    intF[i]--;
                    intS[j]--;
                    res++;
                    for (int k = 0; k < 10; k++)
                    {
                        res += Math.Min(intF[k], intS[9 - k]);
                    }
                    intF[i]++;
                    intS[j]++;
                }
                if(max < res)
                {
                    max = res;
                    maxIndex = i;
                }
            }
            if(maxIndex == -1)
            {
                Console.WriteLine(s);
                Console.WriteLine(s);
                return;
            }
            intF[maxIndex]--;
            intS[(10 - maxIndex)%10]--;
            var resF = new StringBuilder();
            var resS = new StringBuilder();
            resF.Append(maxIndex);
            resS.Append((10 - maxIndex)%10);
            for (int i = 0; i < 10; i++)
            {
                var count = Math.Min(intF[i], intS[9 - i]);
                resF.Append(i.ToString()[0], count);
                resS.Append((9-i).ToString()[0], count);
                intF[i] -= count;
                intS[9 - i] -= count;
            }
            resF.Insert(0, "0", intF[0]);
            resS.Insert(0, "0", intS[0]);
            for (int i = 1; i < 10; i++)
            {
                resF.Append(i.ToString()[0], intF[i]);
                resS.Append(i.ToString()[0], intS[i]);
            }

            Console.WriteLine(new string(resF.ToString().Reverse().ToArray()));
            Console.WriteLine(new string(resS.ToString().Reverse().ToArray()));
        }

        #region Reader

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

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

        private static int[] ReadIntArray()
        {
            var input = Console.ReadLine().Split(' ').Select(Int32.Parse).ToArray();
            return input;
        }

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

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

        private static int ReadNextInt(string[] input, int index)
        {
            return Int32.Parse(input[index]);
        }

        #endregion
    }
}


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

namespace Codeforces
{
    class Program
    {
        public static void Main(string[] args)
        {
            string N = Console.ReadLine();
            int[] dig1 = new int[10];
            int[] dig2 = new int[10];
            foreach (char ch in N)
            {
                ++dig1[ch - '0'];
                ++dig2[ch - '0'];
            }

            List<char> ret1 = new List<char>();
            List<char> ret2 = new List<char>();
            int[] counts = new int[10];

            //try max
            counts[0] = counts[9] = Math.Min(dig1[0], dig1[9]);
            counts[1] = counts[8] = Math.Min(dig1[1], dig1[8]);
            counts[2] = counts[7] = Math.Min(dig1[2], dig1[7]);
            counts[3] = counts[6] = Math.Min(dig1[3], dig1[6]);
            counts[4] = counts[5] = Math.Min(dig1[4], dig1[5]);

            while (dig1[0] > counts[0])
            {
                ret1.Add('0');
                ret2.Add('0');
                dig1[0]--;
                dig2[0]--;
            }

            //try 10
            bool max = false;
            for (int x = 1; x < 6; x++)
            {
                if (dig1[x] > counts[x] && dig1[10 - x] > counts[10 - x])
                {
                    ret1.Add((char)('0'+x));
                    ret2.Add((char)('0'+10-x));
                    dig1[x]--;
                    dig2[10-x]--;

                    max = true;
                    break;
                }
            }

            if (!max)
            {
                for (int x = 1; x < 10; x++)
                {
                    if (dig1[x] > counts[x] && dig1[10-x] > 0)
                    {
                        ret1.Add((char)('0' + x));
                        ret2.Add((char)('0' + 10 - x));
                        dig1[x]--;
                        dig2[10 - x]--;

                        max = true;
                        break;
                    }
                }
            }

            if (!max)
            {
                for (int x = 1; x < 10; x++)
                {
                    if (dig1[x] > 0 && dig1[10 - x] > 0)
                    {
                        ret1.Add((char)('0' + x));
                        ret2.Add((char)('0' + 10 - x));
                        dig1[x]--;
                        dig2[10 - x]--;

                        max = true;
                        break;
                    }
                }
            }

            if (max)
            {
                for (int i = 0; i < 5; i++)
                {
                    for (int j = 0; j < counts[i]; j++)
                    {
                        ret1.Add((char)('0'+i));
                        dig1[i]--;
                        ret2.Add((char)('0' + 9 - i));
                        dig2[9 - i]--;
                    }
                }
            }

            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < dig1[i]; j++) {
                    ret1.Add((char)('0' + i));
                }
                for (int j = 0; j < dig2[i]; j++)
                {
                    ret2.Add((char)('0' + i));
                }
            }

            ret1.Reverse();
            ret2.Reverse();
            foreach(char ch in ret1)
            {
                Console.Write(ch);
            }
            Console.WriteLine();
            foreach (char ch in ret2)
            {
                Console.Write(ch);
            }
            Console.WriteLine();
        }
    }

    public class IO
    {
        public static int GetInt()
        {
            return int.Parse(Console.ReadLine());
        }

        public static IEnumerable<int> GetInts()
        {
            foreach (string s in Console.ReadLine().Split())
            {
                yield return int.Parse(s);
            }
        }

        public static void Wl(object o)
        {
            Console.WriteLine(o.ToString());
        }
    }

    public struct Tuple<T, K>
    {
        public T Item1;
        public K Item2;

        public Tuple(T t, K k)
        {
            Item1 = t;
            Item2 = k;
        }

        public override bool Equals(object obj)
        {
            var o = (Tuple<T, K>)obj;
            return o.Item1.Equals(Item1) && o.Item2.Equals(Item2);
        }

        public override int GetHashCode()
        {
            return Item1.GetHashCode() ^ Item2.GetHashCode();
        }
    }
}


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

namespace Codeforces
{
    internal class Program
    {
        private static void Main()
        {
            if (Debugger.IsAttached)
            {
                Console.SetIn(new StreamReader(@"..\..\..\..\Tests\D4.in"));
            }

            Solve();

            if (Debugger.IsAttached)
            {
                Console.In.Close();
                Console.SetIn(new StreamReader(Console.OpenStandardInput()));
                Console.ReadLine();
            }
        }

        private static void Solve()
        {
            var s = Read();
            var intF = new int[10];
            var intS = new int[10];
            foreach (var n in s)
            {
                intF[n - '0']++;
                intS[n - '0']++;
            }
            var res = 0;
            var max = 0;
            var maxIndex = -1;
            for (int i = 0; i < 10; i++)
            {
                var j = (10 - i)%10;
                if(intF[i] > 0 && intS[j] > 0)
                {
                    intF[i]--;
                    intS[j]--;
                    res++;
                    for (int k = 0; k < 10; k++)
                    {
                        res += Math.Min(intF[k], intS[9 - k]);
                    }
                    intF[i]++;
                    intS[j]++;
                }
                if(max < res)
                {
                    max = res;
                    maxIndex = i;
                }
            }
            if(maxIndex == -1)
            {
                Console.WriteLine(s);
                Console.WriteLine(s);
                return;
            }
            intF[maxIndex]--;
            intS[(10 - maxIndex)%10]--;
            var resF = new StringBuilder();
            var resS = new StringBuilder();
            resF.Append(maxIndex);
            resS.Append((10 - maxIndex)%10);
            for (int i = 0; i < 10; i++)
            {
                var count = Math.Min(intF[i], intS[9 - i]);
                resF.Append(i.ToString()[0], count);
                resS.Append((9-i).ToString()[0], count);
                intF[i] -= count;
                intS[9 - i] -= count;
            }
            resF.Insert(0, "0", intF[0]);
            resS.Insert(0, "0", intS[0]);
            for (int i = 1; i < 10; i++)
            {
                resF.Append(i.ToString()[0], intF[i]);
                resS.Append(i.ToString()[0], intS[i]);
            }

            Console.WriteLine(new string(resF.ToString().Reverse().ToArray()));
            Console.WriteLine(new string(resS.ToString().Reverse().ToArray()));
        }

        #region Reader

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

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

        private static int[] ReadIntArray()
        {
            var input = Console.ReadLine().Split(' ').Select(Int32.Parse).ToArray();
            return input;
        }

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

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

        private static int ReadNextInt(string[] input, int index)
        {
            return Int32.Parse(input[index]);
        }

        #endregion
    }
}


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

namespace Codeforces
{
    internal class Program
    {
        private static void Main()
        {
            if (Debugger.IsAttached)
            {
                Console.SetIn(new StreamReader(@"..\..\..\..\Tests\D2.in"));
            }

            Solve();

            if (Debugger.IsAttached)
            {
                Console.In.Close();
                Console.SetIn(new StreamReader(Console.OpenStandardInput()));
                Console.ReadLine();
            }
        }

        private static void Solve()
        {
            var s = Read();
            var intF = new int[10];
            var intS = new int[10];
            foreach (var n in s)
            {
                intF[n - '0']++;
                intS[n - '0']++;
            }
            var res = 0;
            var max = 0;
            var maxIndex = -1;
            for (int i = 0; i < 10; i++)
            {
                var j = (10 - i)%10;
                if(intF[i] > 0 && intS[j] > 0)
                {
                    intF[i]--;
                    intS[j]--;
                    res++;
                    for (int k = 0; k < 10; k++)
                    {
                        res += Math.Min(intF[k], intS[9 - k]);
                    }
                    intF[i]++;
                    intS[j]++;
                }
                if(max < res)
                {
                    max = res;
                    maxIndex = i;
                }
            }
            intF[maxIndex]--;
            intS[(10 - maxIndex)%10]--;
            var resF = new StringBuilder();
            var resS = new StringBuilder();
            resF.Append(maxIndex);
            resS.Append((10 - maxIndex)%10);
            for (int i = 1; i < 10; i++)
            {
                var count = Math.Min(intF[i], intS[9 - i]);
                resF.Append(i.ToString()[0], count);
                resS.Append((9-i).ToString()[0], count);
                intF[i] -= count;
                intS[9 - i] -= count;
            }
            resF.Insert(0, "0", intF[0]);
            resS.Insert(0, "0", intF[0]);
            for (int i = 1; i < 10; i++)
            {
                resF.Append(i.ToString()[0], intF[i]);
                resS.Append(i.ToString()[0], intS[i]);
            }

            Console.WriteLine(new string(resF.ToString().Reverse().ToArray()));
            Console.WriteLine(new string(resS.ToString().Reverse().ToArray()));
        }

        #region Reader

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

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

        private static int[] ReadIntArray()
        {
            var input = Console.ReadLine().Split(' ').Select(Int32.Parse).ToArray();
            return input;
        }

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

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

        private static int ReadNextInt(string[] input, int index)
        {
            return Int32.Parse(input[index]);
        }

        #endregion
    }
}


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

namespace Codeforces
{
    internal class Program
    {
        private static void Main()
        {
            if (Debugger.IsAttached)
            {
                Console.SetIn(new StreamReader(@"..\..\..\..\Tests\D5.in"));
            }

            Solve();

            if (Debugger.IsAttached)
            {
                Console.In.Close();
                Console.SetIn(new StreamReader(Console.OpenStandardInput()));
                Console.ReadLine();
            }
        }

        private static void Solve()
        {
            var s = Read();
            var intF = new int[10];
            var intS = new int[10];
            foreach (var n in s)
            {
                intF[n - '0']++;
                intS[n - '0']++;
            }

            var max = 0;
            var maxIndex = -1;
            for (int i = 1; i < 10; i++)
            {
                var res = 0;
                var j = 10 - i;
                if(intF[i] > 0 && intS[j] > 0)
                {
                    intF[i]--;
                    intS[j]--;
                    res++;
                    for (int k = 0; k < 10; k++)
                    {
                        res += Math.Min(intF[k], intS[9 - k]);
                    }
                    intF[i]++;
                    intS[j]++;
                }
                if(max < res)
                {
                    max = res;
                    maxIndex = i;
                }
            }
            var resF = new StringBuilder();
            var resS = new StringBuilder();
            if (maxIndex != -1)
            {
                intF[maxIndex]--;
                intS[(10 - maxIndex)%10]--;
                resF.Append(maxIndex);
                resS.Append((10 - maxIndex)%10);
            }
            for (int i = 0; i < 10; i++)
            {
                var count = Math.Min(intF[i], intS[9 - i]);
                resF.Append(i.ToString()[0], count);
                resS.Append((9-i).ToString()[0], count);
                intF[i] -= count;
                intS[9 - i] -= count;
            }
            resF.Insert(0, "0", intF[0]);
            resS.Insert(0, "0", intS[0]);
            for (int i = 1; i < 10; i++)
            {
                resF.Append(i.ToString()[0], intF[i]);
                resS.Append(i.ToString()[0], intS[i]);
            }

            Console.WriteLine(new string(resF.ToString().Reverse().ToArray()));
            Console.WriteLine(new string(resS.ToString().Reverse().ToArray()));
        }

        #region Reader

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

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

        private static int[] ReadIntArray()
        {
            var input = Console.ReadLine().Split(' ').Select(Int32.Parse).ToArray();
            return input;
        }

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

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

        private static int ReadNextInt(string[] input, int index)
        {
            return Int32.Parse(input[index]);
        }

        #endregion
    }
}


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

class Solver
{
    public void Solve()
    {
        //  count
        var cs = new int[10];
        var s = CF.ReadLine();
        foreach (var c in s)
        {
            int n = c-'0';
            cs[n]++;
        }

        //
        int max = -1;
        int[] best1 = new int[10];
        Array.Copy(cs, best1, 10);
        int[] best2 = new int[10];
        Array.Copy(cs, best2, 10);
        string max_n1 = "";
        string max_n2 = "";

        for (int a = 1; a <= 9; a++)
        {
            string n1 = "";
            string n2 = "";

            int b = 10 - a;

            int zc = 0;
            int[] tmp1 = new int[10];
            int[] tmp2 = new int[10];
            Array.Copy(cs, tmp1, 10);
            Array.Copy(cs, tmp2, 10);

            tmp1[a]--;
            if (tmp1[a] < 0)
                continue;
            tmp2[b]--;
            if (tmp2[b] < 0)
                continue;

            n1 += a;
            n2 += b;

            //  c+d=9
            for (int c = 1; c <= 9; c++)
            {
                int d = 9 - c;

                int p = Math.Min(tmp1[c],tmp2[d]);

                tmp1[c] -= p;
                tmp2[d] -= p;

                zc += p;

                n1 = new string((char)('0'+c),p)+n1;
                n2 = new string((char)('0' + d), p) + n2;
            }

            if (zc > max)
            {
                max = zc;
                best1 = tmp1;
                best2 = tmp2;
                max_n1 = n1;
                max_n2 = n2;
            }
        }

        //  0+0=0
        int z = Math.Min(best1[0],best2[0]);
        max_n1 += new string('0', z);
        max_n2 += new string('0', z);
        best2[0] -=z;
        best1[0] -=z;

        for (int i = 0; i <= 9; i++)
        {
            max_n1 = new string((char)('0'+i), best1[i])+max_n1;
            max_n2 = new string((char)('0'+i), best2[i])+max_n2;
        }
        CF.WriteLine(max_n1);
        CF.WriteLine(max_n2);
    }

    //  test
    static Utils CF = new Utils(new[]{
@"
192819280
"
,
@"
198
"
,
@"
500
"
,
@"
0
"
,
@"
1
"
 ,
@"
10
"

    });
    #region test

    static void Main(string[] args)
    {
#if DEBUG
        for (int t=0;t<CF.TestCount;t++ )
        {
            CF.Test(t);
			var sw = new Stopwatch();
			sw.Start();
            new Solver().Solve();
			Debug.WriteLine("time: "+sw.ElapsedMilliseconds+ " ms");
		}
#else
        new Solver().Solve();
#endif
    }

    class Utils
    {
        public void Test(int t)
        {
            _lines = new List<string>();
            string[] ss = _test_input[t].Replace("\n", "").Split('\r');
            for (int i = 0; i < ss.Length; i++)
            {
                if (
                    (i == 0 || i == ss.Length - 1) &&
                    ss[i].Length == 0
                    )
                    continue;

                _lines.Add(ss[i]);
            }
        }

        public int TestCount
        {
            get
            {
                return _test_input.Length;
            }
        }

        public string ReadLine()
        {
#if DEBUG
            string s = null;
            if (_lines.Count > 0)
            {
                s = _lines[0];
                _lines.RemoveAt(0);
            }
            return s;

#else
            //return _sr.ReadLine();
        return Console.In.ReadLine();
#endif
        }

        public void WriteLine(object o)
        {
#if DEBUG
            System.Diagnostics.Trace.WriteLine(o);
#else
            //_sw.WriteLine(o);
        Console.WriteLine(o);
#endif
        }

        public void Write(object o)
        {
#if DEBUG
            System.Diagnostics.Trace.Write(o);
#else
                //_sw.Write(o);
        Console.Write(o);
#endif
        }

        string[] _test_input;

        List<string> _lines;

#if DEBUG
        public Utils(string[] test_input)
        {
            _test_input = test_input;
        }
#else

        public Utils(string[] dummy)
        {
            //_sr = new System.IO.StreamReader("input.txt");
            //_sw = new System.IO.StreamWriter("output.txt");
        }
#endif

    }

    #endregion
}


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

namespace Codeforces
{
    class Program
    {
        public static void Main(string[] args)
        {
            string N = Console.ReadLine();
            int[] dig1 = new int[10];
            int[] dig2 = new int[10];
            foreach (char ch in N)
            {
                ++dig1[ch - '0'];
                ++dig2[ch - '0'];
            }

            List<char> ret1 = new List<char>();
            List<char> ret2 = new List<char>();
            int[] counts = new int[10];

            //try max
            counts[0] = counts[9] = Math.Min(dig1[0], dig1[9]);
            counts[1] = counts[8] = Math.Min(dig1[1], dig1[8]);
            counts[2] = counts[7] = Math.Min(dig1[2], dig1[7]);
            counts[3] = counts[6] = Math.Min(dig1[3], dig1[6]);
            counts[4] = counts[5] = Math.Min(dig1[4], dig1[5]);

            while (dig1[0] > counts[0])
            {
                ret1.Add('0');
                ret2.Add('0');
                dig1[0]--;
                dig2[0]--;
            }

            //try 10
            bool max = false;
            for (int x = 1; x < 6; x++)
            {
                if (dig1[x] > counts[x] && dig1[10 - x] > counts[10 - x])
                {
                    ret1.Add((char)('0'+x));
                    ret2.Add((char)('0'+10-x));
                    dig1[x]--;
                    dig2[10-x]--;

                    max = true;
                    break;
                }
            }

            if (!max)
            {
                for (int x = 1; x < 10; x++)
                {
                    if (dig1[x] > counts[x] && dig1[10-x] > 0)
                    {
                        ret1.Add((char)('0' + x));
                        ret2.Add((char)('0' + 10 - x));
                        dig1[x]--;
                        dig2[10 - x]--;

                        max = true;
                        break;
                    }
                }
            }

            if (!max)
            {
                for (int x = 1; x < 10; x++)
                {
                    if (dig1[x] > 0 && dig1[10 - x] > 0)
                    {
                        ret1.Add((char)('0' + x));
                        ret2.Add((char)('0' + 10 - x));
                        dig1[x]--;
                        dig2[10 - x]--;

                        max = true;
                        break;
                    }
                }
            }

            if (max)
            {
                for (int i = 0; i < 10; i++)
                {
                    while (dig1[i] > 0 && dig2[9-i] > 0)
                    {
                        ret1.Add((char)('0'+i));
                        dig1[i]--;
                        ret2.Add((char)('0' + 9 - i));
                        dig2[9 - i]--;
                    }
                }
            }

            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < dig1[i]; j++) {
                    ret1.Add((char)('0' + i));
                }
                for (int j = 0; j < dig2[i]; j++)
                {
                    ret2.Add((char)('0' + i));
                }
            }

            ret1.Reverse();
            ret2.Reverse();
            foreach(char ch in ret1)
            {
                Console.Write(ch);
            }
            Console.WriteLine();
            foreach (char ch in ret2)
            {
                Console.Write(ch);
            }
            Console.WriteLine();
        }
    }

    public class IO
    {
        public static int GetInt()
        {
            return int.Parse(Console.ReadLine());
        }

        public static IEnumerable<int> GetInts()
        {
            foreach (string s in Console.ReadLine().Split())
            {
                yield return int.Parse(s);
            }
        }

        public static void Wl(object o)
        {
            Console.WriteLine(o.ToString());
        }
    }

    public struct Tuple<T, K>
    {
        public T Item1;
        public K Item2;

        public Tuple(T t, K k)
        {
            Item1 = t;
            Item2 = k;
        }

        public override bool Equals(object obj)
        {
            var o = (Tuple<T, K>)obj;
            return o.Item1.Equals(Item1) && o.Item2.Equals(Item2);
        }

        public override int GetHashCode()
        {
            return Item1.GetHashCode() ^ Item2.GetHashCode();
        }
    }
}


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

namespace Codeforces
{
    internal class Program
    {
        private static void Main()
        {
            if (Debugger.IsAttached)
            {
                Console.SetIn(new StreamReader(@"..\..\..\..\Tests\D7.in"));
            }

            Solve();

            if (Debugger.IsAttached)
            {
                Console.In.Close();
                Console.SetIn(new StreamReader(Console.OpenStandardInput()));
                Console.ReadLine();
            }
        }

        private static void Solve()
        {
            var s = Read();
            var intF = new int[10];
            var intS = new int[10];
            foreach (var n in s)
            {
                intF[n - '0']++;
                intS[n - '0']++;
            }

            var max = 0;
            var maxIndex = -1;
            for (int i = 1; i < 10; i++)
            {
                var res = 0;
                var j = 10 - i;
                if(intF[i] > 0 && intS[j] > 0)
                {
                    intF[i]--;
                    intS[j]--;
                    res++;
                    for (int k = 0; k < 10; k++)
                    {
                        res += Math.Min(intF[k], intS[9 - k]);
                    }
                    intF[i]++;
                    intS[j]++;
                }
                if(max < res)
                {
                    max = res;
                    maxIndex = i;
                }
            }
            var resF = new StringBuilder();
            var resS = new StringBuilder();
            if (maxIndex != -1)
            {
                intF[maxIndex]--;
                intS[(10 - maxIndex)%10]--;
                resF.Append(maxIndex);
                resS.Append((10 - maxIndex)%10);
            }
            for (int i = 0; i < 10; i++)
            {
                var count = Math.Min(intF[i], intS[9 - i]);
                resF.Append(i.ToString()[0], count);
                resS.Append((9-i).ToString()[0], count);
                intF[i] -= count;
                intS[9 - i] -= count;
            }
            var countZero = Math.Min(intF[0], intS[0]);
            resF.Insert(0, "0", countZero);
            resS.Insert(0, "0", countZero);
            intF[0] -= countZero;
            intS[0] -= countZero;
            for (int i = 0; i < 10; i++)
            {
                resF.Append(i.ToString()[0], intF[i]);
                resS.Append(i.ToString()[0], intS[i]);
            }

            Console.WriteLine(new string(resF.ToString().Reverse().ToArray()));
            Console.WriteLine(new string(resS.ToString().Reverse().ToArray()));
        }

        #region Reader

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

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

        private static int[] ReadIntArray()
        {
            var input = Console.ReadLine().Split(' ').Select(Int32.Parse).ToArray();
            return input;
        }

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

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

        private static int ReadNextInt(string[] input, int index)
        {
            return Int32.Parse(input[index]);
        }

        #endregion
    }
}


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

class Solver
{
    public void Solve()
    {
        //  count
        var cs = new int[10];
        var s = CF.ReadLine();
        foreach (var c in s)
        {
            int n = c-'0';
            cs[n]++;
        }

        //
        int max = -1;
        int[] best1 = new int[10];
        Array.Copy(cs, best1, 10);
        int[] best2 = new int[10];
        Array.Copy(cs, best2, 10);
        string max_n1 = "";
        string max_n2 = "";

        for (int a = 1; a <= 9; a++)
        {
            string n1 = "";
            string n2 = "";

            int b = 10 - a;

            int zc = 0;
            int[] tmp1 = new int[10];
            int[] tmp2 = new int[10];
            Array.Copy(cs, tmp1, 10);
            Array.Copy(cs, tmp2, 10);

            tmp1[a]--;
            if (tmp1[a] < 0)
                continue;
            tmp2[b]--;
            if (tmp2[b] < 0)
                continue;

            n1 += a;
            n2 += b;

            //  c+d=9
            for (int c = 0; c <= 9; c++)
            {
                int d = 9 - c;

                int p = Math.Min(tmp1[c],tmp2[d]);

                tmp1[c] -= p;
                tmp2[d] -= p;

                zc += p;

                n1 = new string((char)('0'+c),p)+n1;
                n2 = new string((char)('0' + d), p) + n2;
            }

            if (zc > max)
            {
                max = zc;
                best1 = tmp1;
                best2 = tmp2;
                max_n1 = n1;
                max_n2 = n2;
            }
        }

        //  0+0=0
        int z = Math.Min(best1[0],best2[0]);
        max_n1 += new string('0', z);
        max_n2 += new string('0', z);
        best2[0] -=z;
        best1[0] -=z;

        for (int i = 0; i <= 9; i++)
        {
            max_n1 = new string((char)('0'+i), best1[i])+max_n1;
            max_n2 = new string((char)('0'+i), best2[i])+max_n2;
        }
        CF.WriteLine(max_n1);
        CF.WriteLine(max_n2);
    }

    //  test
    static Utils CF = new Utils(new[]{
@"
1099
"
,
@"
198
"
,
@"
500
"
,
@"
0
"
,
@"
1
"
 ,
@"
10
"

    });
    #region test

    static void Main(string[] args)
    {
#if DEBUG
        for (int t=0;t<CF.TestCount;t++ )
        {
            CF.Test(t);
			var sw = new Stopwatch();
			sw.Start();
            new Solver().Solve();
			Debug.WriteLine("time: "+sw.ElapsedMilliseconds+ " ms");
		}
#else
        new Solver().Solve();
#endif
    }

    class Utils
    {
        public void Test(int t)
        {
            _lines = new List<string>();
            string[] ss = _test_input[t].Replace("\n", "").Split('\r');
            for (int i = 0; i < ss.Length; i++)
            {
                if (
                    (i == 0 || i == ss.Length - 1) &&
                    ss[i].Length == 0
                    )
                    continue;

                _lines.Add(ss[i]);
            }
        }

        public int TestCount
        {
            get
            {
                return _test_input.Length;
            }
        }

        public string ReadLine()
        {
#if DEBUG
            string s = null;
            if (_lines.Count > 0)
            {
                s = _lines[0];
                _lines.RemoveAt(0);
            }
            return s;

#else
            //return _sr.ReadLine();
        return Console.In.ReadLine();
#endif
        }

        public void WriteLine(object o)
        {
#if DEBUG
            System.Diagnostics.Trace.WriteLine(o);
#else
            //_sw.WriteLine(o);
        Console.WriteLine(o);
#endif
        }

        public void Write(object o)
        {
#if DEBUG
            System.Diagnostics.Trace.Write(o);
#else
                //_sw.Write(o);
        Console.Write(o);
#endif
        }

        string[] _test_input;

        List<string> _lines;

#if DEBUG
        public Utils(string[] test_input)
        {
            _test_input = test_input;
        }
#else

        public Utils(string[] dummy)
        {
            //_sr = new System.IO.StreamReader("input.txt");
            //_sw = new System.IO.StreamWriter("output.txt");
        }
#endif

    }

    #endregion
}


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

namespace Codeforces
{
    internal class Program
    {
        private static void Main()
        {
            if (Debugger.IsAttached)
            {
                Console.SetIn(new StreamReader(@"..\..\..\..\Tests\D3.in"));
            }

            Solve();

            if (Debugger.IsAttached)
            {
                Console.In.Close();
                Console.SetIn(new StreamReader(Console.OpenStandardInput()));
                Console.ReadLine();
            }
        }

        private static void Solve()
        {
            var s = Read();
            var intF = new int[10];
            var intS = new int[10];
            foreach (var n in s)
            {
                intF[n - '0']++;
                intS[n - '0']++;
            }
            var res = 0;
            var max = 0;
            var maxIndex = -1;
            for (int i = 0; i < 10; i++)
            {
                var j = (10 - i)%10;
                if(intF[i] > 0 && intS[j] > 0)
                {
                    intF[i]--;
                    intS[j]--;
                    res++;
                    for (int k = 0; k < 10; k++)
                    {
                        res += Math.Min(intF[k], intS[9 - k]);
                    }
                    intF[i]++;
                    intS[j]++;
                }
                if(max < res)
                {
                    max = res;
                    maxIndex = i;
                }
            }
            intF[maxIndex]--;
            intS[(10 - maxIndex)%10]--;
            var resF = new StringBuilder();
            var resS = new StringBuilder();
            resF.Append(maxIndex);
            resS.Append((10 - maxIndex)%10);
            for (int i = 0; i < 10; i++)
            {
                var count = Math.Min(intF[i], intS[9 - i]);
                resF.Append(i.ToString()[0], count);
                resS.Append((9-i).ToString()[0], count);
                intF[i] -= count;
                intS[9 - i] -= count;
            }
            resF.Insert(0, "0", intF[0]);
            resS.Insert(0, "0", intS[0]);
            for (int i = 1; i < 10; i++)
            {
                resF.Append(i.ToString()[0], intF[i]);
                resS.Append(i.ToString()[0], intS[i]);
            }

            Console.WriteLine(new string(resF.ToString().Reverse().ToArray()));
            Console.WriteLine(new string(resS.ToString().Reverse().ToArray()));
        }

        #region Reader

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

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

        private static int[] ReadIntArray()
        {
            var input = Console.ReadLine().Split(' ').Select(Int32.Parse).ToArray();
            return input;
        }

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

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

        private static int ReadNextInt(string[] input, int index)
        {
            return Int32.Parse(input[index]);
        }

        #endregion
    }
}


using System;

namespace CodeForce
{
    public class Program
    {
        static void Main(string[] args)
        {
            var input1 = Console.ReadLine();
            var answer = Solve(input1);
            Console.WriteLine(answer);
        }

        public static long Solve(string input)
        {
            var candies = long.Parse(input);
            var min = 1L;
            var top = candies;
            var result = top;
            while (min <= top)
            {
                var k = (min + top) / 2;
                var moreThanHalf = VasyaEatsMoreThanHalf(candies, k);
                if (moreThanHalf)
                {
                    result = k;
                    top = k - 1;
                }
                else
                {
                    min = k + 1;
                }
            }

            return result;
        }

        private static bool VasyaEatsMoreThanHalf(long candies, long k)
        {
            var totalCandies = candies;
            var vasya = 0L;
            while (candies > 0)
            {
                candies -= k;
                vasya += k;
                if (candies >= 10)
                {
                    var tenPercent = (long)(candies / 10);
                    candies -= tenPercent;
                }
                else
                {
                    vasya += candies;
                    candies = 0;
                }
            }

            return vasya * 2 >= totalCandies;
        }
    }
}


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

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

class Sol{
	public void Solve(){

		long N2 = (N + 1) / 2;
		long l = 0;
		long r = N;
		while(r - l > 1){

			long c = (l + r) / 2;
			long g = 0;
			long tot = N;
			while(tot > 0){
				g += Math.Min(c, tot);
				tot -= Math.Min(c, tot);
				tot -= tot / 10;
			}

			if(g < N2){
				l = c;
			} else {
				r = c;
			}
		}
		Console.WriteLine(r);
	}
	long N;
	public Sol(){
		N = rl();
	}

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


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

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

    public static bool NextPermutation(List<int> perm)
    {
      for (int i = perm.Count - 2; i >= 0; i--)
      {
        if (perm[i] < perm[i + 1])
        {
          int min = i + 1;
          for (int j = min; j < perm.Count; j++)
            if (perm[j] > perm[i] && perm[j] < perm[min])
              min = j;

          int tmp = perm[i];
          perm[i] = perm[min];
          perm[min] = tmp;
          perm.Reverse(i + 1, perm.Count - i - 1);
          return true;
        }
      }

      return false;
    }

    public static long CalcEkler(long n, long k)
    {
      long ans = 0;
      while (n > 0)
      {
        long min = Math.Min(k, n);
        ans += min;
        n -= min;

        n -= n / 10;
      }

      return ans;
    }

    static void Main(string[] args)
    {
      long i = 0;
      long ans = 0;
      reader = new StreamReader(Console.OpenStandardInput());
      writer = new StreamWriter(Console.OpenStandardOutput());

      long n = ReadLong();
      long needEkler = n / 2 + (n & 1);

      long l = 1;
      long r = n;
      long k = n / 2;
      ans = k;
      do
      {
        k = (l + r) / 2;
        long calcedEkler = CalcEkler(n, k);
        if (calcedEkler >= needEkler)
        {
          ans = k;
          r = k - 1;
        }
        else
        {
          l = k + 1;
        }
      } while (l <= r);

      Write(ans);
      reader.Close();
      writer.Close();
    }
  }
}


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

namespace Candies
{
    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)
        {
            long n = long.Parse(reader.ReadLine());

            long l = 1, r = (n + 1)/2;
            while (l < r)
            {
                long m = (l + r)/2;

                long nn = n;
                long v = 0;
                while (nn > 0)
                {
                    long t = Math.Min(nn, m);
                    v += t;
                    nn -= t;
                    nn -= nn/10;
                }
                if (2*v >= n)
                {
                    r = m;
                }
                else
                {
                    l = m + 1;
                }
            }

            return r;
        }
    }
}


using System;

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

            Console.WriteLine(binarySearch(n) + 1);
        }

        static long binarySearch(long total) {
            long low = 1;
            long high = total;
		    while (low <= high) {
			    long middle = (low + high) / 2;

			    if (canEat(middle, total)) {
				    high = middle - 1;
			    }
			    else {
				    low = middle + 1;
			    }
		    }

		    return high;
	    }

        static bool canEat(long k, long total)
        {
            long eatenA = 0;
            long eatenB = 0;
            long current = total;

            while(current > 0)
            {
                eatenA += Math.Min(k, current);
                current = Math.Max(current - k, 0);
                eatenB += current / 10;
                current -= current / 10;
            }

            if(total % 2 == 0)
            {
                return eatenA >= total / 2;
            }
            else
            {
                return eatenA > total / 2;
            }
        }
    }
}


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

namespace ReadWriteTemplate
{
    public static class Solver
    {
        private static void SolveCase()
        {
            long n = ReadLong();
            long l = 1;
            long r = n;
            while (l < r)
            {
                long m = (l + r) / 2;
                if (Check(n, m))
                {
                    r = m;
                }
                else
                {
                    l = m + 1;
                }
            }
            Writer.WriteLine(l);
        }

        private static bool Check(long n, long k)
        {
            long start = n;
            long vCount = 0;
            while (n > 0)
            {
                long e = Math.Min(n, k);
                vCount += e;
                n -= e;
                n -= n / 10;
            }
            return 2 * vCount >= start;
        }

        public static void Solve()
        {
            SolveCase();

            /*var sw = Stopwatch.StartNew();*/

            /*int T = ReadInt();
            for (int i = 0; i < T; i++)
            {
                Writer.Write("Case #{0}: ", i + 1);
                SolveCase();
            }*/

            /*sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds);*/
        }

        public static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

#if DEBUG
            //Reader = Console.In; Writer = Console.Out;
            Reader = File.OpenText("input.txt"); Writer = File.CreateText("output.txt");
#else
            Reader = Console.In; Writer = Console.Out;
#endif

            // Solve();
            Thread thread = new Thread(Solve, 64 * 1024 * 1024);
            thread.CurrentCulture = CultureInfo.InvariantCulture;
            thread.Start();
            thread.Join();

            Reader.Close();
            Writer.Close();
        }

        public static IOrderedEnumerable<TSource> OrderByWithShuffle<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
        {
            return source.Shuffle().OrderBy(keySelector);
        }

        public static T[] Shuffle<T>(this IEnumerable<T> source)
        {
            T[] result = source.ToArray();
            Random rnd = new Random();
            for (int i = result.Length - 1; i >= 1; i--)
            {
                int k = rnd.Next(i + 1);
                T tmp = result[k];
                result[k] = result[i];
                result[i] = tmp;
            }
            return result;
        }

        #region Read/Write

        private static TextReader Reader;

        private static TextWriter Writer;

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

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

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

        public static string ReadLine()
        {
            return Reader.ReadLine();
        }

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

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

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

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

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

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

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

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

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

        #endregion
    }
}


using System;

namespace CodeForce
{
    public class Program
    {
        static void Main(string[] args)
        {
            var input1 = Console.ReadLine();
            var answer = Solve(input1);
            Console.WriteLine(answer);
        }

        public static long Solve(string input)
        {
            var candies = long.Parse(input);
            var top = candies;
            var min = 1L;
            var k = top / 2;
            while (top != min)
            {
                var moreThanHalf = VasyaEatsMoreThanHalf(candies, k);
                if (moreThanHalf)
                {
                    top /= 2;
                    k = top;
                }
                else
                {
                    top = top + min;
                    min = top / 2;
                    k = min;
                }
            }

            return k;
        }

        private static bool VasyaEatsMoreThanHalf(long candies, long k)
        {
            var totalCandies = candies;
            var vasya = 0L;
            while (candies > 0)
            {
                candies -= k;
                vasya += k;
                if (candies > 10)
                {
                    var tenPercent = (long)(candies / 10);
                    candies -= tenPercent;
                }
            }

            return vasya > totalCandies / 2;
        }
    }
}


using System;

namespace CodeForce
{
    public class Program
    {
        static void Main(string[] args)
        {
            var input1 = Console.ReadLine();
            var answer = Solve(input1);
            Console.WriteLine(answer);
        }

        public static long Solve(string input)
        {
            var candies = long.Parse(input);
            var min = 1L;
            var k = Math.Max(candies / 2, 1);
            var top = k;
            while (top != min)
            {
                var moreThanHalf = VasyaEatsMoreThanHalf(candies, k);
                if (moreThanHalf)
                {
                    top = k;
                    k /= 2;
                }
                else
                {
                    k = min + k;
                    min = k;
                }
            }

            return min;
        }

        private static bool VasyaEatsMoreThanHalf(long candies, long k)
        {
            var totalCandies = candies;
            var vasya = 0L;
            while (candies > 0)
            {
                candies -= k;
                vasya += k;
                if (candies > 10)
                {
                    var tenPercent = (long)(candies / 10);
                    candies -= tenPercent;
                }
            }

            return vasya > totalCandies / 2;
        }
    }
}


using System;

namespace CodeForce
{
    public class Program
    {
        static void Main(string[] args)
        {
            var input1 = Console.ReadLine();
            var answer = Solve(input1);
            Console.WriteLine(answer);
        }

        public static long Solve(string input)
        {
            var candies = long.Parse(input);
            var min = 1L;
            var k = Math.Max(candies / 2, 1);
            var top = k;
            while (top != min)
            {
                var moreThanHalf = VasyaEatsMoreThanHalf(candies, k);
                if (moreThanHalf)
                {
                    top = k;
                    k /= 2;
                }
                else
                {
                    k = min + k;
                    min = k;
                }
            }

            return min;
        }

        private static bool VasyaEatsMoreThanHalf(long candies, long k)
        {
            var totalCandies = candies;
            var vasya = 0L;
            while (candies > 0)
            {
                candies -= k;
                vasya += k;
                if (candies >= 10)
                {
                    var tenPercent = (long)(candies / 10);
                    candies -= tenPercent;
                }
                else
                {
                    vasya += candies;
                    candies = 0;
                }
            }

            return vasya >= Math.Ceiling(totalCandies / 2d);
        }
    }
}


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

namespace Candies
{
    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)
        {
            long n = long.Parse(reader.ReadLine());

            long l = 1, r = (n + 1)/2;
            while (l < r)
            {
                long m = (l + r)/2;

                long nn = n;
                long v = 0;
                while (nn > 1)
                {
                    long t = Math.Min(nn, m);
                    v += t;
                    nn -= t;
                    nn -= nn/10;
                }
                if (2*v > n)
                {
                    r = m;
                }
                else
                {
                    l = m + 1;
                }
            }

            return r;
        }
    }
}


using System;

namespace CodeForce
{
    public class Program
    {
        static void Main(string[] args)
        {
            var input1 = Console.ReadLine();
            var answer = Solve(input1);
            Console.WriteLine(answer);
        }

        public static long Solve(string input)
        {
            var candies = long.Parse(input);
            var top = candies;
            var min = 1L;
            var k = Math.Max(top / 2, 1);
            while (top != min)
            {
                var moreThanHalf = VasyaEatsMoreThanHalf(candies, k);
                if (moreThanHalf)
                {
                    top /= 2;
                    k = top;
                }
                else
                {
                    top = top + min;
                    min = top / 2;
                    k = min;
                }
            }

            return k;
        }

        private static bool VasyaEatsMoreThanHalf(long candies, long k)
        {
            var totalCandies = candies;
            var vasya = 0L;
            while (candies > 0)
            {
                candies -= k;
                vasya += k;
                if (candies > 10)
                {
                    var tenPercent = (long)(candies / 10);
                    candies -= tenPercent;
                }
            }

            return vasya > totalCandies / 2;
        }
    }
}


using System;

namespace CodeForce
{
    public class Program
    {
        static void Main(string[] args)
        {
            var input1 = Console.ReadLine();
            var answer = Solve(input1);
            Console.WriteLine(answer);
        }

        public static long Solve(string input)
        {
            var candies = long.Parse(input);
            var min = 1L;
            var k = Math.Max(candies / 2, 1);
            var top = k;
            while (top != min)
            {
                var moreThanHalf = VasyaEatsMoreThanHalf(candies, k);
                if (moreThanHalf)
                {
                    top = k;
                    k /= 2;
                }
                else
                {
                    k = (min + top) / 2;
                    min++;
                }
            }

            return min;
        }

        private static bool VasyaEatsMoreThanHalf(long candies, long k)
        {
            var totalCandies = candies;
            var vasya = 0L;
            while (candies > 0)
            {
                candies -= k;
                vasya += k;
                if (candies >= 10)
                {
                    var tenPercent = (long)(candies / 10);
                    candies -= tenPercent;
                }
                else
                {
                    vasya += candies;
                    candies = 0;
                }
            }

            return vasya >= Math.Ceiling(totalCandies / 2d);
        }
    }
}


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

namespace Beautiful_Numbers
{
    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 int mod = 1000000007;

        private static int[] fact;

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

            InitFact(n);

            long sum = 0;
            for (int i = 0; i <= n; i++)
            {
                int d = a*i + b*(n - i);
                bool ok = true;
                while (d > 0)
                {
                    int dd = d%10;
                    if (dd != a && dd != b)
                    {
                        ok = false;
                        break;
                    }
                    d /= 10;
                }
                if (!ok)
                    continue;

                sum = (sum + GetCFact(n, i))%mod;
            }

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

        private static void InitFact(int n)
        {
            fact = new int[n + 1];
            fact[0] = 1;

            for (long i = 1; i < fact.Length; i++)
            {
                fact[i] = (int) ((fact[i - 1]*i)%mod);
            }
        }

        private static long GetCFact(int n, int k)
        {
            return (((fact[n]*Pow(fact[k], mod - 2))%mod)*Pow(fact[n - k], mod - 2))%mod;
        }

        private static long Pow(long a, int k)
        {
            long r = 1;
            while (k > 0)
            {
                if ((k & 1) == 1)
                {
                    r = (r*a)%mod;
                }
                a = (a*a)%mod;
                k >>= 1;
            }
            return r;
        }

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

namespace Beautiful_Numbers
{
    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 int mod = 1000000007;

        private static long[] fact;
        private static long[] fact1;

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

            InitFact(n);

            long sum = 0;
            for (int i = 0; i <= n; i++)
            {
                int d = a*i + b*(n - i);
                bool ok = true;
                while (d > 0)
                {
                    int dd = d%10;
                    if (dd != a && dd != b)
                    {
                        ok = false;
                        break;
                    }
                    d /= 10;
                }
                if (!ok)
                    continue;

                sum = (sum + GetCFact(n, i))%mod;
            }

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

        private static void InitFact(int n)
        {
            fact = new long[n + 1];
            //fact1 = new long[n + 1];

            fact[0] = 1;
            //fact1[0] = 1;

            for (int i = 1; i < fact.Length; i++)
            {
                fact[i] = (fact[i - 1]*i)%mod;
                //fact1[i] = Pow(fact[i], mod - 2);
            }
        }

        private static long GetCFact(int n, int k)
        {
            return (((fact[n]*Pow(fact[k], mod - 2))%mod)*Pow(fact[n - k], mod - 2))%mod;
        }

        private static long Pow(long a, int k)
        {
            long r = 1;
            while (k > 0)
            {
                if ((k & 1) == 1)
                {
                    r = (r*a)%mod;
                }
                a = (a*a)%mod;
                k >>= 1;
            }
            return r;
        }

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


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

namespace CodeForces
{
    class Program
    {
        const int MOD = 1000000007;
        static long[] fac = new long[1000010];
        static long mod_pow(long num, long pow, long mod)
        {
            long  ret = 1;
            while (pow>0)
             {
                if (pow%2>0)
                {
                   ret = (ret*num)%mod;
                }
                pow>>=1;
                num = (num*num)%mod;
            }
            return ret;
        }
        static void precalc()
        {
            fac[0] = 1;
            for (int i = 1; i <= 1000000; i++)
            {
                fac[i] = i * fac[i - 1];
                fac[i] %= MOD;
            }
        }
        static long mod_inv(long num, long mod)
        {
             return mod_pow(num, mod-2, mod);
        }
        // (A/B) mod M = (A mod M) * mod_inv(B mod M, M)
        static long C(int n, int k)
        {
            long up = fac[n];
            long down = fac[k] * fac[n - k] % MOD;
            return up * mod_inv(down, MOD);
        }
        static long solve(int a, int b, int i, int n)
        {
            if ((i - a * n) % (b-a) > 0) return 0;
            int y = (i - a * n) / (b-a);
            if (y < 0) return 0;
            if (y > n) return 0;
            return C(n, y);
        }
        static void Main(string[] args)
        {
            precalc();
            int a, b, n;
            string[] s = Console.ReadLine().Split();
            a = int.Parse(s[0]);
            b = int.Parse(s[1]);
            n = int.Parse(s[2]);
            long ans=0;
            for (int i = 1; i <= 9*n; i++)
            {
                bool good = true;
                int j = i;
                int numofc = 0;
                while (j > 0)
                {
                    numofc++;
                    int last = j % 10;
                    j /= 10;
                    if (last != a && last != b) {good = false; break;}
                }
                if (!good) continue;
                //Console.WriteLine(i.ToString());
                ans += solve(a, b, i,n);
                ans %= MOD;
            }
            Console.WriteLine(ans.ToString());
            Console.ReadLine();
        }
    }
}


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

class Program
{
    static TextReader reader;
    static TextWriter writer;
    static Program()
    {
#if ONLINE_JUDGE
        reader = Console.In;
        writer = Console.Out;
#else
        reader = new StreamReader("input.txt");
        writer = new StreamWriter("output.txt");
#endif
    }
    static long gcd(long a, long b)
    {
        if (a < b)
        {
            long t = a;
            a = b;
            b = t;
        }
        return (b > 0) ? gcd(b, a % b) : a;
    }
    /*static BigInteger C(int k, int n)
    {
        BigInteger c = 1;
        if (k < n / 2)
            k = n - k;
        for (int i = k + 1; i <= n; ++i)
            c *= i;
        for (int i = 2; i <= n - k; ++i)
            c /= i;
        return c;
    }*/
    static void _235A()
    {
        long n = long.Parse(reader.ReadLine()), ans = n * (n - 1);
        if (n < 3)
            ans = n;
        else if (n % 2 == 1)
            ans *= n - 2;
        else
        {
            long t = (n - 2) / 2;
            for (long i = n - 3; i > (n - 2) / 2; --i)
            {
                long g = gcd(n, i);
                if (g == 1)
                    t = Math.Max(t, i);
            }
            ans *= t;
        }
        writer.Write(Math.Max(ans,(n-1)*(n-2)*(n-3)));
    }
    static void _106C()
    {
        string[] s = reader.ReadLine().Split();
        int n = int.Parse(s[0]), m = int.Parse(s[1]), c0 = int.Parse(s[2]), d0 = int.Parse(s[3]);
        int[] a = new int[m + 1], b = new int[m + 1], c = new int[m + 1], d = new int[m + 1];
        for (int i = 1; i <= m; ++i)
        {
            s = reader.ReadLine().Split();
            a[i] = int.Parse(s[0]);
            b[i] = int.Parse(s[1]);
            c[i] = int.Parse(s[2]);
            d[i] = int.Parse(s[3]);
        }
        int[] dp_d = new int[n + 1], dp_c = new int[n + 1];
        dp_d[0] = dp_c[0] = 0;
        int[,] dp_b = new int[n + 1, m + 1];
        for (int i = 1; i <= n; ++i)
        {
            if (c0 == i)
            {
                dp_d[i] = d0;
                dp_c[i] = i;
            }
            for (int j = 1; j <= m; ++j)
            {
                if (c[j] == i)
                {
                    if (dp_d[i] < d[j] && b[j] <= a[j])
                    {
                        dp_d[i] = d[j];
                        dp_c[i] = i;
                        dp_b[i, j] = b[j];
                    }
                    else if (dp_d[i] == d[j])
                    {
                        // ???
                    }
                }
            }
            // what about leftovers???
            for (int j = 1; j <= i / 2; ++j)
            {
                if (dp_d[j] + dp_d[i - j] > dp_d[i])
                {
                    bool ok = true;
                    for (int k = 1; k <= m && ok; ++k)
                    {
                        if (dp_b[j, k] + dp_b[i - j, k] > a[k])
                            ok = false;
                    }
                    if (ok)
                    {
                        dp_d[i] = dp_d[j] + dp_d[i - j];
                        dp_c[i] = dp_c[j] + dp_c[i - j];
                        for (int k = 1; k <= m; ++k)
                            dp_b[i,k] = dp_b[j, k] + dp_b[i - j, k];
                    }
                }
            }
            if (c0 <= i)
                if (d0 + dp_d[i - c0] > dp_d[i])
                {
                    dp_d[i] = d0 + dp_d[i - c0];
                    dp_c[i] = c0 + dp_c[i - c0];
                }
            if (dp_d[i] < dp_d[i - 1])
            {
                dp_d[i] = dp_d[i - 1];
                dp_c[i] = dp_c[i - 1];
                for (int j = 1; j <= m; ++j)
                    dp_b[i, j] = dp_b[i - 1, j];
            }
        }
        writer.Write(dp_d[n]);
    }
    static long pow(long a, long x, long mod)
    {
        long res = 1;
        while (x > 0)
        {
            if ((x & 1) != 0)
            {
                res = (res * a) % mod;
                --x;
            }
            else
            {
                a = (a * a) % mod;
                x >>= 1;
            }
        }
        return res;
    }
    static void _300C()
    {
        string[] s = reader.ReadLine().Split();
        long a = long.Parse(s[0]), b = long.Parse(s[1]), n = long.Parse(s[2]);
        if (a > b)
        {
            long t = a;
            a = b;
            b = t;
        }
        long[] fact = new long[n + 1];
        fact[0] = fact[1] = 1;
        long mod = 1000000007;
        for (long i = 2; i <= n; ++i)
            fact[i] = fact[i - 1] * i % mod;
        long an = n, bn = 0;
        long ans = 0;
        while (an >= 0)
        {
            long num = an * a + bn * b;
            bool ok = true;
            for (long p = 10; ok && p <= 10000000; p *= 10)
            {
                long t = num % p / (p / 10);
                if (t != a && t != b && (t != 0 || p <= num))
                    ok = false;
            }
            if (ok)
            {
                long c = (((fact[n] * pow(fact[an], mod - 2, mod)) % mod) * pow(fact[bn], mod - 2, mod)) % mod;
                ans += c;
                ans %= mod;
            }
            --an;
            ++bn;
        }
        writer.Write(ans);
    }
    static void Main(string[] args)
    {
        //_235A();
        //_106C();
        _300C();
        reader.Close();
        writer.Close();
    }
}


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

namespace CodeForces
{
    class R181_Div2_C
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);
            int n = int.Parse(s[2]);

            List<int> ind = new List<int>();
            for (int i = 0; i <= n; i++)
            {
                int sum = a * i + b * (n - i);
                string sumS = sum.ToString();
                bool good = true;
                for (int j = 0; j < sumS.Length; j++)
                {
                    int d = sumS[j] - '0';
                    if (d != a && d != b)
                    {
                        good = false;
                        break;
                    }
                }
                if (good)
                    ind.Add(i);
            }

            GenerateFactorials();

            long ans = 0;
            for (int i = 0; i < ind.Count; i++)
            {
                ans += nCk(n, ind[i]);
                ans = ans % MOD;
            }

            Console.WriteLine(ans);
        }

        static long MOD = 1000000007;

        static long AddMod(long x, long y)
        {
            return (x + y) % MOD;
        }
        static long MulMod(long x, long y)
        {
            return (x * y) % MOD;
        }
        static long GCDex(long a, long b, ref long nx, ref long ny)
        {
            if (b == 0)
            {
                nx = 1;
                ny = 0;
                return a;
            }
            long x = 0, y = 0;
            long d = GCDex(b, a % b, ref x, ref y);
            nx = y;
            ny = x - (a / b) * y;
            return d;
        }
        static long ModInv(long a)
        {
            long f = 0, g = 0;
            if (GCDex(a, MOD, ref f, ref g) != 1)  //MOD must be prime
                throw new System.ArgumentException("No Inverse");
            f %= MOD;
            f += MOD;
            f %= MOD;
            if (MulMod(a, f) != 1)
                throw new System.ArgumentException("No Inverse");
            return f;
        }
        static long DivMod(long a, long b)
        {
            return MulMod(a, ModInv(b));
        }

        static long[] facts = new long[1000001];
        static void GenerateFactorials()
        {
            facts[0] = 1;
            for (int i = 1; i < 1000001; i++)
                facts[i] = MulMod(facts[i - 1], i);
        }

        static long nCk(long n, long k)
        {
            if (n - k < 0)
                throw new System.ArgumentException("Invalid parms");
            long nCOMBk = DivMod(DivMod(facts[n], facts[k]), facts[n - k]);
            return nCOMBk;
        }
    }
}