using System;
using System.Collections.Generic;
using System.Linq;
using Solver.Ex;
using Debug = System.Diagnostics.Debug;
using Watch = System.Diagnostics.Stopwatch;
using StringBuilder = System.Text.StringBuilder;
namespace Solver
{
    public class Solver
    {
        public void Solve()
        {
            var a = sc.Integer();
            var m = sc.Integer();
            var p = a;
            while (p>0)
            {
                p += p % m;
                p %= m;
                if (p == a)
                    break;
            }
            if(p==0)
                IO.Printer.Out.WriteLine("Yes");
            else IO.Printer.Out.WriteLine("No");
        }
        internal IO.StreamScanner sc;
    }

    #region Main and Settings
    static class Program
    {
        static void Main(string[] arg)
        {
#if DEBUG
            var errStream = new System.IO.FileStream(@"..\..\dbg.out", System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite);
            Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(errStream, "debugStream"));
            Debug.AutoFlush = false;
            var sw = new Watch(); sw.Start();
            IO.Printer.Out.AutoFlush = true;
            try
            {
#endif

                var solver = new Solver();
                solver.sc = new IO.StreamScanner(Console.OpenStandardInput());
                solver.Solve();
                IO.Printer.Out.Flush();
#if DEBUG
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
                Console.Error.WriteLine(ex.StackTrace);
            }
            finally
            {
                sw.Stop();
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Error.WriteLine("Time:{0}ms", sw.ElapsedMilliseconds);
                Debug.Close();
                System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
            }
#endif
        }

    }
    #endregion
}
#region IO Helper
namespace Solver.IO
{
    public class Printer : System.IO.StreamWriter
    {
        static Printer()
        {
            Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
#if DEBUG
            Error = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
#else
            Error = new Printer(System.IO.Stream.Null) { AutoFlush = false };
#endif
        }
        public static Printer Out { get; set; }
        public static Printer Error { get; set; }
        public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } }
        public Printer(System.IO.Stream stream) : base(stream, new System.Text.UTF8Encoding(false, true)) { }
        public Printer(System.IO.Stream stream, System.Text.Encoding encoding) : base(stream, encoding) { }
        public void Write<T>(string format, IEnumerable<T> source) { Write(format, source.OfType<object>().ToArray()); }
        public void WriteLine<T>(string format, IEnumerable<T> source) { WriteLine(format, source.OfType<object>().ToArray()); }
    }
    public class StreamScanner
    {
        public StreamScanner(System.IO.Stream stream) { iStream = stream; }
        private readonly System.IO.Stream iStream;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        private bool eof = false;
        public bool IsEndOfStream { get { return eof; } }
        const byte lb = 33, ub = 126, el = 10, cr = 13;
        public byte read()
        {
            if (eof) throw new System.IO.EndOfStreamException();
            if (ptr >= len) { ptr = 0; if ((len = iStream.Read(buf, 0, 1024)) <= 0) { eof = true; return 0; } }
            return buf[ptr++];
        }
        public char Char() { byte b = 0; do b = read(); while (b < lb || ub < b);            return (char)b; }
        public char[] Char(int n) { var a = new char[n]; for (int i = 0; i < n; i++) a[i] = Char(); return a; }
        public char[][] Char(int n, int m) { var a = new char[n][]; for (int i = 0; i < n; i++) a[i] = Char(m); return a; }
        public string Scan()
        {
            if (eof) throw new System.IO.EndOfStreamException();
            StringBuilder sb = null;
            var enc = System.Text.UTF8Encoding.Default;
            do
            {
                for (; ptr < len && (buf[ptr] < lb || ub < buf[ptr]); ptr++) ;
                if (ptr < len) break;
                ptr = 0;
                if ((len = iStream.Read(buf, 0, 1024)) <= 0) { eof = true; return ""; }
            } while (true);
            do
            {
                var f = ptr;
                for (; ptr < len; ptr++)
                    if (buf[ptr] < lb || ub < buf[ptr])
                    //if (buf[ptr] == cr || buf[ptr] == el)
                    {
                        string s;
                        if (sb == null) s = enc.GetString(buf, f, ptr - f);
                        else { sb.Append(enc.GetChars(buf, f, ptr - f)); s = sb.ToString(); }
                        ptr++; return s;
                    }
                if (sb == null) sb = new StringBuilder(enc.GetString(buf, f, len - f));
                else sb.Append(enc.GetChars(buf, f, len - f));
                ptr = 0;

            }
            while (!eof && (len = iStream.Read(buf, 0, 1024)) > 0);
            eof = true; return (sb != null) ? sb.ToString() : "";
        }
        public long Long()
        {
            long ret = 0; byte b = 0; bool isMynus = false;
            const byte zr = 48, nn = 57, my = 45;
            do b = read();
            while (b != my && (b < zr || nn < b));
            if (b == my) { isMynus = true; b = read(); }
            for (; true; b = read())
                if (b < zr || nn < b)
                    return isMynus ? -ret : ret;
                else ret = ret * 10 + b - zr;
        }
        public int Integer()
        {
            int ret = 0; byte b = 0; bool isMynus = false;
            const byte zr = 48, nn = 57, my = 45;
            do b = read();
            while (b != my && (b < zr || nn < b));
            if (b == my) { isMynus = true; b = read(); }
            for (; true; b = read())
                if (b < zr || nn < b)
                    return isMynus ? -ret : ret;
                else ret = ret * 10 + b - zr;
        }
        public double Double() { return double.Parse(Scan(), System.Globalization.CultureInfo.InvariantCulture); }
        public string[] Scan(int n) { var a = new string[n]; for (int i = 0; i < n; i++) a[i] = Scan(); return a; }
        public double[] Double(int n) { var a = new double[n]; for (int i = 0; i < n; i++) a[i] = Double(); return a; }
        public int[] Integer(int n) { var a = new int[n]; for (int i = 0; i < n; i++) a[i] = Integer(); return a; }
        public long[] Long(int n) { var a = new long[n]; for (int i = 0; i < n; i++)a[i] = Long(); return a; }
        public void Flush() { iStream.Flush(); }
    }
}
#endregion
#region Extension
namespace Solver.Ex
{
    static public partial class EnumerableEx
    {
        static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); }
        static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); }
        static public T[] Enumerate<T>(this int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) a[i] = f(i); return a; }
    }
}
#endregion


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]), m = int.Parse(s[1]);
            bool[] used = new bool[100001];
            int x = a % m;
            while (true) {
                if (x == 0) {
                    Console.Write("Yes");
                }
                if (used[x]) {
                    Console.Write("No");
                }
                used[x] = true;
                x = (x + x) % m;
            }

            //Console.ReadKey();
        }
    }
}


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

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

            long a = int.Parse(s[0]);

            long m = int.Parse(s[1]);

            string ans = "No";

            for (int i = 0; i < 10000000000; i++)
            {
                if (a%m==0)
                {
                    ans = "Yes";
                    break;
                }

                a += a%m;
            }

            Console.WriteLine(ans);

        }
    }
}


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

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

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

            long count;
            if (n == 1)
                count = 4;
            else if (n == 0)
                count = 1;
            else if (n == 2)
                count = 8;
            else
            {

                long y = (long)Math.Sqrt(n/2*n)+2;
                long nn = n*n;

                while (2*y*y > nn)
                {
                    y--;
                }
                if (y*y + (y+1)*(y+1) > nn)
                {
                    count = (y + 1)*8;
                }
                else
                {
                    count = (2*y + 1)*4;
                }
            }

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

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

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

            long count;
            if (n == 1)
                count = 4;
            else if (n == 0)
                count = 1;
            else if (n == 2)
                count = 8;
            else
            {

                long y = (long)Math.Sqrt(n/2*n)+2;
                long nn = n*n;

                while (2*y*y > nn)
                {
                    y--;
                }
                if (y*y + (y+1)*(y+1) > nn)
                {
                    count = (y)*8;
                }
                else
                {
                    count = (2*y + 1)*4;
                }
            }

            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;

namespace CodeF_Block
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Prog();
        }

        public void Prog()
        {
            long n = long.Parse(Console.ReadLine());
            long blocked = 0;

            if (n == 0)
                blocked = 1;
            else if (n == 1)
                blocked = 4;
            else
            {
                double y = n / Math.Sqrt(2.00);
                y = Math.Truncate(y);

                double dist = Math.Sqrt((y * y) + (y + 1) * (y + 1));
                Console.WriteLine(dist.ToString());
                if (dist <= n)
                {
                    blocked = (long)y * 8 + 4;
                }
                else
                {
                    blocked = (long)y * 8;
                }

                //blocked *= 4;
            }

            Console.WriteLine(blocked.ToString());
            // Console.ReadLine();

        }
    }
}


using System;

namespace CodeF_Block
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Prog();
        }

        public void Prog()
        {
            while (true)
            {
                long n = long.Parse(Console.ReadLine());
                long blocked = 0;

                if (n == 0)
                    blocked = 1;
                else if (n == 1)
                    blocked = 4;
                else
                {
                    double y = n / Math.Sqrt(2.00);
                    y = Math.Truncate(y);

                    double dist = Math.Sqrt((y * y) + (y + 1) * (y + 1));
                    Console.WriteLine(dist.ToString());
                    if (dist <= n)
                    {
                        blocked = (long)y * 8 + 4;
                    }
                    else
                    {
                        blocked = (long)y * 8;
                    }

                    //blocked *= 4;
                }

                Console.WriteLine(blocked.ToString());
               // Console.ReadLine();
            }
        }
    }
}


 class Program
    {
        public static void Main(string[] args)
        {
            string data = Console.ReadLine();
            if (data.Length > 20) Console.WriteLine("BigInteger");
            else
            {
                if(data.Length<19 || data.Length==19 && data[0]=='-')
                {
                    long inp = long.Parse(data);
                    if (inp < 128L && inp >= sbyte.MinValue) Console.WriteLine("byte");
                    else if (inp < 32768L && inp >= short.MinValue) Console.WriteLine("short");
                    else if (inp < 2147483648L && inp >= int.MinValue) Console.WriteLine("int");
                    else Console.WriteLine("long");
                }
                else
                {
                    long halfA= 9223372036, halfB, hlfA, hlfB;
                    if (data[0] == '-')
                    {
                        halfB = 854775808;
                        hlfA = long.Parse(data.Substring(1, 10));
                        hlfB = long.Parse(data.Substring(11));
                    }
                    else
                    {
                        halfB = 854775807;
                        hlfA = long.Parse(data.Substring(0, 10));
                        hlfB = long.Parse(data.Substring(10));
                    }
                    if (halfA > hlfA) Console.WriteLine("long");
                    else if (halfA == hlfA)
                    {
                        if (halfB > hlfB) Console.WriteLine("long");
                        else Console.WriteLine(hlfB == halfB ? "long" : "BigInteger");
                    }
                    else Console.WriteLine("BigInteger");
                }
            }
        }
    }


class program
{
    static void Main()
    {
        double t = double.Parse(Console.ReadLine());
        if(t >= - 128 && t  <= 127)
            Console.WriteLine("byte");
        if (t >= -32768 && t <= 32767)
            Console.WriteLine("short");
        if (t >= - 2147483648 && t <= 2147483647)
            Console.WriteLine("int");
        if (t >= -9223372036854775808 && t <= 9223372036854775807)
            Console.WriteLine("long ");
        else
            Console.WriteLine("BigInteger");
    }
}


public static string Func(string n)
		{

			long d = 0;

			try{
				d = Convert.ToInt64 (n);
			}
			catch (System.OverflowException)
			{
				return "BigInteger";
			}
			string[] arr = new string[]{"byte","short", "int", "long", "BigInteger"};
			if ((-128 <= d) && (d <= 127)) return arr [0];
			if((-32768 <= d) && (d<= 32767))
				return arr [1];
			if((-2147483648 <= d) && (d<= 2147483647))
				return arr [2];
			else
				return arr [3];

		}


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

namespace Gift
{
    class Program
    {
        static void Main(string[] args)
        {
            IO io = new IO();
            int i_N = io.ReadInt();
            int[] arr_Weight = new int[i_N];
            double d_Sum = 0;
            for (int i = 0; i < i_N; i++)
            {
                arr_Weight[i] = io.ReadNextInt();
                d_Sum += arr_Weight[i];
            }
            Array.Sort(arr_Weight);

            io.PutStr(arr_Weight[i_N / 2+1] == (d_Sum / 2) ? "YES" : "NO");
            io.ReadStr();
        }
    }

    class IO
    {
        private static Queue<string> currentLineTokens = new Queue<string>();
        private static string[] ReadAndSplitLine()
        {
            return Console.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
        }
        public int ReadNextInt()
        {
            return int.Parse(ReadToken());
        }
        public long ReadNextLong()
        {
            return long.Parse(ReadToken());
        }

        public int ReadInt()
        {
            return Convert.ToInt32(Console.ReadLine());
        }
        public long ReadLong()
        {
            return Convert.ToInt64(Console.ReadLine());
        }
        public string ReadStr()
        {
            return Console.ReadLine();
        }
        public string[] ReadStrArr()
        {
            return Console.ReadLine().Split(' ');
        }
        public int[] ReadIntArr()
        {
            return Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), s => int.Parse(s));
        }
        public long[] ReadLongArr()
        {
            return Array.ConvertAll<string, long>(Console.ReadLine().Split(' '), s => long.Parse(s));
        }
        public void PutStr(string str)
        {
            Console.WriteLine(str);
        }
        public void PutStr(int str)
        {
            Console.WriteLine(str);
        }
        public void PutStr(long str)
        {
            Console.WriteLine(str);
        }

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


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

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

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

            var l = new int[k];
            var r = new int[k];
            for (int i = 0; i < k; i++)
            {
                l[i] = Next();
                r[i] = Next();
            }

            var dp = new List<Interval>[k + 1];

            for (int i = 0; i < dp.Length; i++)
            {
                dp[i] = new List<Interval>();
            }
            dp[0].Add(new Interval(0, 0));

            int prev = 0;
            for (int i = 0; i < k; i++)
            {
                var next = new List<Interval>[k + 1];
                for (int ii = 0; ii < dp.Length; ii++)
                {
                    next[ii] = new List<Interval>();
                }

                int delta = l[i] - prev;
                for (int index = 0; index < dp.Length; index++)
                {
                    if (index%2 == 0)
                    {
                        List<Interval> t = dp[index];
                        foreach (Interval interval in t)
                        {
                            interval.l += delta;
                            interval.r += delta;
                        }
                    }
                }
                delta = r[i] - l[i];
                for (int ii = 0; ii < dp.Length; ii++)
                {
                    if (ii%2 == 0)
                    {
                        foreach (Interval interval in dp[ii])
                        {
                            next[ii].Add(new Interval(interval.l + delta, interval.r + delta));
                            next[ii + 1].Add(new Interval(interval.l, interval.r + delta));
                        }
                    }
                    else
                    {
                        foreach (Interval interval in dp[ii])
                        {
                            next[ii].Add(new Interval(interval.l, interval.r));
                            next[ii + 1].Add(new Interval(interval.l, interval.r + delta));
                        }
                    }
                }

                prev = r[i];
                for (int index = 0; index < dp.Length; index++)
                {
                    dp[index].Clear();

                    Interval pr = null;
                    foreach (Interval interval in next[index].OrderBy(t => t.l))
                    {
                        if (interval.l > n)
                            break;
                        if (pr != null && pr.r >= interval.l)
                        {
                            pr.r = Math.Max(pr.r, interval.r);
                        }
                        else
                        {
                            dp[index].Add(interval);
                            pr = interval;
                        }
                    }
                }
            }

            {
                int delta = 2*n - prev;
                for (int index = 0; index < dp.Length; index++)
                {
                    if (index%2 == 0)
                    {
                        List<Interval> t = dp[index];
                        foreach (Interval interval in t)
                        {
                            interval.l += delta;
                            interval.r += delta;
                        }
                    }
                }
            }

            for (int i = 0; i < dp.Length; i++)
            {
                foreach (Interval interval in dp[i])
                {
                    if (interval.l <= n && interval.r >= n)
                    {
                        writer.WriteLine("Full");
                        writer.WriteLine(i);
                        return;
                    }
                }
            }

            writer.WriteLine("Hungry");
        }

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

        #region Nested type: Interval

        private class Interval
        {
            public int l, r;

            public Interval(int l, int r)
            {
                this.l = l;
                this.r = r;
            }
        }

        #endregion
    }
}


using System;

namespace MyFirstProject
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            Int32 n = Convert.ToInt32(Console.ReadLine());
            Int32 friend = 0;
            for (int i = 0; i < n; i++)
            {
                friend += Convert.ToInt32(Console.ReadLine());
            }
            n++;
            Int32 res = 0;
            for (int i = 1; i < 6; i++)
            {
                if (((friend+i-1) % (n)) != 0)
                {
                    //Console.WriteLine((friend + i)+" % "+n+" = "+((friend+i) % (n)));
                    res++;
                }
            }
            Console.WriteLine(res);
        }
    }
}


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

class Program
{
    private static void Main()
    {
        int result = 0;
        int n = ConsoleReadLineAsInteger();
        var kk1 = ConsoleReadLineAsArrayOfIntegers();
        var kk2 = ConsoleReadLineAsArrayOfIntegers();

        List<int> k1 = new List<int>();
        for(int i = 1; i < kk1.Length; i++)
            k1.Add(kk1[i]);

        List<int> k2 = new List<int>();
        for(int i = 1; i < kk2.Length; i++)
            k2.Add(kk2[i]);

        int f = 0;
        int ccc = 0;
        while(true)
        {
            ccc++;

            if (ccc > 40000000)
            {
                Console.WriteLine("-1");
                return;
            }
            f++;

            int v1 = k1[0]; k1.RemoveAt(0);
            int v2 = k2[0]; k2.RemoveAt(0);

            if (v1 > v2)
            {
                k1.Add(v2);
                k1.Add(v1);
            }
            else
            {
                k2.Add(v1);
                k2.Add(v2);
            }

            // test
            if (k1.Count == 0)
            {
                ConsoleWriteLine("" + f + " 2");
                return;
            }
            else if (k2.Count == 0)
            {
                ConsoleWriteLine("" + f + " 1");
                return;
            }
            /*
            else if (k1.Count == kk1.Length - 1 && k2.Count == kk2.Length - 1)
            {
                bool k1s = true;
                for(int i = 0; i < k1.Count; i++)
                {
                    if (k1[i] != kk1[i+1])
                    {
                        k1s = false;
                        break;
                    }
                }

                if (k1s)
                {
                    bool k2s = true;
                    for(int j = 0; j < k2.Count; j++)
                    {
                        if (k2[j] != kk2[j+1])
                        {
                            k2s = false;
                            break;
                        }
                    }

                    if (k1s == k2s)
                    {
                        ConsoleWriteLine("-1");
                        return;
                    }
                }
            }
            */

        }

        Console.WriteLine("" + result);
    }

    private static int[] ConsoleReadLineAsArrayOfIntegers()
    {
        return Console.ReadLine().Split(' ').Select(n => Convert.ToInt32(n)).ToArray();
    }

    private static int ConsoleReadLineAsInteger()
    {
        return Convert.ToInt32(Console.ReadLine());
    }

    private static void ConsoleWriteLine(string line)
    {
        Console.WriteLine(line);
    }
}


using System;
using System.Text;

namespace _82A
{
    class Program
    {
        public enum Names
        { Sheldon=1, Leonard, Penny, Rajesh, Howard}

        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            StringBuilder queue = new StringBuilder("12345", n + 5);
            for (int i=1;i<n;i++)
            {
                queue.Append(""+ queue[0] + queue[0]);
                queue.Remove(0,1);
            }
            Console.WriteLine((Names)Char.GetNumericValue(queue[0]));
            Console.ReadLine();
        }
    }
}


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

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

            Console.WriteLine("+------------------------+");
            if (x < 1) Console.Write("|#.");
            else Console.Write("|O.");
            for (int m = 5; m <= 32; m = m + 3)
            {
                if (x >= m) Console.Write("O.");
                else Console.Write("#.");
            }

            Console.Write("|D|)\n");
            if (x < 2) Console.Write("|#.");
            else Console.Write("|O.");
            for (int m = 6; m <= 33; m = m + 3)
            {
                if (x >= m) Console.Write("O.");
                else Console.Write("#.");
            }

            Console.Write("|.|)\n");
            if (x < 3) Console.WriteLine("|#.......................|");
            else Console.WriteLine("|O.......................|");

            if (x < 4) Console.Write("|#.");
            else Console.Write("|O.");
            for (int m = 7; m <= 34; m = m + 3)
            {
                if (x >= m) Console.Write("O.");
                else Console.Write("#.");
            }
            Console.Write("|.|)\n");
            Console.WriteLine("+------------------------+");
        }
    }
}


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

namespace Bayan
{
    class Program
    {
        static List<string> Do(int PassengersCount)
        {
            List<string> Lines = new List<string>();

            var RowCount = 6;
            var ColumnCount = 27;
            var Bus = new char[RowCount, ColumnCount];

            for (int row = 0; row < RowCount; row++)
            {
                string line = "";

                for (int column = 0; column < ColumnCount; column++)
                {
                    if (row == 0 || row == RowCount - 1)
                    {
                        if (column == 0 || column == (ColumnCount - 2))
                            Bus[row, column] = '+';
                        else if (column == (ColumnCount - 1))
                            Bus[row, column] = ' ';
                        else
                            Bus[row, column] = '-';
                    }
                    else
                    {
                        // ستون های ردیف های 1 تا 4
                        if (column == 0)
                            Bus[row, column] = '|';
                        else
                        {
                            if (column < 23)
                            {
                                if (column == 1)
                                {
                                    Bus[row, column] = '#';
                                }
                                else
                                {
                                    if (row == 3)
                                        Bus[row, column] = '.';
                                    else
                                    {
                                        var isOdd = column % 2 == 1;
                                        if (isOdd)
                                        {
                                            Bus[row, column] = '#';
                                        }
                                        else
                                        {
                                            Bus[row, column] = '.';
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (column == 23)
                                {
                                    if (row != 3)
                                        Bus[row, column] = '|';
                                    else
                                        Bus[row, column] = '.';
                                }
                                else if (column == 24)
                                {
                                    if (row == 1)
                                        Bus[row, column] = 'D';
                                    else
                                        Bus[row, column] = '.';
                                }
                                else if (column == 25)
                                {
                                    Bus[row, column] = '|';
                                }
                                else if (column == 26)
                                {
                                    if (row == 1 || row == 4)
                                        Bus[row, column] = ')';
                                    else
                                        Bus[row, column] = ' ';
                                }
                            }
                        }

                    }

                    var s = Bus[row, column].ToString();
                    line = line + s;
                }

                Lines.Add(line);
            }

            //PassengersCount

            var c = 0;

            string[] BusArray = Lines.ToArray();

            while (PassengersCount != 0)
            {
                var ss = BusArray[c];

                if (c >= 1 && c <= 4)
                {
                    if (c == 3)
                    {
                        var cc = ss.ToCharArray();
                        for (int i = 0; i < cc.Length; i++)
                        {
                            if (i == 1)
                            {
                                if (cc[i] == '#')
                                {
                                    cc[i] = 'O';
                                    PassengersCount--;
                                    ss = string.Join("", cc);
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        var cc = ss.ToCharArray();

                        for (int r = 0; r < cc.Length; r++)
                        {
                            if (cc[r] == '#')
                            {
                                cc[r] = 'O';
                                PassengersCount--;
                                break;
                            }
                        }

                        ss = string.Join("", cc);
                    }

                }

                BusArray[c] = ss;

                c++;

                if (c > 5)
                    c = 0;
            };

            return BusArray.ToList();
        }

        static void Main(string[] args)
        {
            try
            {
                var OutputLines = Do(int.Parse(Console.ReadLine()));
                Console.Write(string.Join("\n", OutputLines));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.Write(Environment.NewLine);
                Console.Write("any key to exit");
                Console.ReadKey();
            }
        }
    }

    #region Extensions

    public static class Extensions
    {
        public static void ForEach<T>(this IEnumerable<T> Collection, Action<T, int> Action)
        {
            var ListCollection = Collection.ToList();

            var Length = ListCollection.Count;
            for (int i = 0; i < Length; i++)
            {
                Action(ListCollection[i], i);
            }
        }
    }

    #endregion

    #region IO

    public class IO
    {
        #region Constructor

        public IO(string InputPath, string OutputPath)
        {
            this.InputPath = InputPath;
            this.OutputPath = OutputPath;
        }

        #endregion

        #region Properties

        public string InputPath { get; set; }
        public string OutputPath { get; set; }

        #endregion

        #region Read Public Methods

        public string Read()
        {
            string Text = string.Empty;
            using (StreamReader Reader = new StreamReader(this.InputPath))
                Text = Reader.ReadToEnd();

            return Text;
        }

        public List<string> ReadLines()
        {
            var Text = Read();
            var Lines = Text
                .Split('\n')
                .Where(u => !string.IsNullOrEmpty(u))
                .ToList();
            return Lines;
        }

        #endregion

        #region Write Public Methods

        public void Write(string Text)
        {
            using (StreamWriter Writer = new StreamWriter(this.OutputPath))
                Writer.Write(Text);
        }

        public void WriteLines(List<string> Lines)
        {
            var Text = String.Join(Environment.NewLine, Lines);
            Write(Text);
        }

        #endregion
    }

    #endregion
}


using System;
using System.Linq;

namespace CodeForces
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			string line1 = Console.ReadLine();
			int n = Int32.Parse(line1);
			int[,] columns = new int[11 , 4];
			if (n >= 4)
			{
				n -= 4;
				for (int i = 0; i < 4; i++)
				{
					columns[0, i] = 1;
				}
				int column = 1;
				int row = 0;
				while (n > 0)
				{
					n -= 1;
					columns[column, row] = 1;
					row += 1;
					if (row == 2)
					{
						row += 1;
					}
					if (row == 4)
					{
						row = 0;
						column += 1;
					}
				}
			}
			else
			{
				if (n == 3)
				{
					for (int i = 0; i < 3; i++)
					{
						columns[0, i] = 1;
					}
				}
				else if (n == 2)
				{
					for (int i = 0; i < 2; i++)
					{
						columns[0, i] = 1;
					}
				}
				else if (n == 1)
				{
					for (int i = 0; i < 1; i++)
					{
						columns[0, i] = 1;
					}
				}
				else
				{

				}
			}
			Console.WriteLine("+------------------------+");
			Console.Write("|");
			for (int i = 0; i < 11; i++)
			{
				if (columns[i, 0] == 1)
				{
					Console.Write("O.");
				}
				else
				{
					Console.Write("#.");
				}
			}
			Console.Write("|D|)" + Environment.NewLine);
			Console.Write("|");
			for (int i = 0; i < 11; i++)
			{
				if (columns[i, 1] == 1)
				{
					Console.Write("O.");
				}
				else
				{
					Console.Write("#.");
				}
			}
			Console.Write("|.|" + Environment.NewLine);
			Console.Write("|");
			for (int i = 0; i < 11; i++)
			{
				if (columns[i, 2] == 1)
				{
					Console.Write("O.");
				}
				else
				{
					Console.Write("..");
				}
			}
			Console.Write("..|" + Environment.NewLine);
			Console.Write("|");
			for (int i = 0; i < 11; i++)
			{
				if (columns[i, 3] == 1)
				{
					Console.Write("O.");
				}
				else
				{
					Console.Write("#.");
				}
			}
			Console.Write("|.|)" + Environment.NewLine);
			Console.WriteLine("+------------------------+");

		}

	}

}


using System;
using System.Linq;

namespace CodeForces
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			string line1 = Console.ReadLine();
			int n = Int32.Parse(line1);
			int[,] columns = new int[11 , 4];
			if (n >= 4)
			{
				n -= 4;
				for (int i = 0; i < 4; i++)
				{
					columns[0, i] = 1;
				}
				int column = 1;
				int row = 0;
				while (n > 0)
				{
					n -= 1;
					columns[column, row] = 1;
					row += 1;
					if (row == 2)
					{
						row += 1;
					}
					if (row == 4)
					{
						row = 0;
						column += 1;
					}
				}
			}
			else
			{
				if (n == 3)
				{
					for (int i = 0; i < 3; i++)
					{
						columns[0, i] = 1;
					}
				}
				else if (n == 2)
				{
					for (int i = 0; i < 2; i++)
					{
						columns[0, i] = 1;
					}
				}
				else if (n == 1)
				{
					for (int i = 0; i < 1; i++)
					{
						columns[0, i] = 1;
					}
				}
				else
				{

				}
			}
			Console.WriteLine("+------------------------+");
			Console.Write("|");
			for (int i = 0; i < 11; i++)
			{
				if (columns[i, 0] == 1)
				{
					Console.Write("O.");
				}
				else
				{
					Console.Write("#.");
				}
			}
			Console.Write("|D|)" + Environment.NewLine);
			Console.Write("|");
			for (int i = 0; i < 11; i++)
			{
				if (columns[i, 1] == 1)
				{
					Console.Write("O.");
				}
				else
				{
					Console.Write("#.");
				}
			}
			Console.Write("|.|" + Environment.NewLine);
			Console.Write("|");
			for (int i = 0; i < 11; i++)
			{
				if (columns[i, 2] == 1)
				{
					Console.Write("O.");
				}
				else
				{
					if (i = 0)
					{
						Console.Write("#.);

					}
					else
					{
						Console.Write("..");
					}

				}
			}
			Console.Write("..|" + Environment.NewLine);
			Console.Write("|");
			for (int i = 0; i < 11; i++)
			{
				if (columns[i, 3] == 1)
				{
					Console.Write("O.");
				}
				else
				{
					Console.Write("#.");
				}
			}
			Console.Write("|.|)" + Environment.NewLine);
			Console.WriteLine("+------------------------+");

		}

	}

}


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

namespace ConsoleApplication8
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = int.Parse(Console.ReadLine());
            string[,] bus = new string[6, 14];
            int n = 0;
            string[] output = new string[6];
            n = count;
            bus[0, 0] = "+";
            bus[5, 0] = "+";
            bus[0, 13] = "+";
            bus[5, 13] = "+";
            bus[1, 12] = "|D";
            bus[1, 13] = "|";
            bus[2, 12] = "|.";
            bus[2, 13] = "|";
            bus[4, 12] = "|.";
            bus[4, 13] = "|";
            bus[3, 13] = "|";
            for (int i = 1; i < 5; i++)
            {
                bus[i, 0] = "|";
            }

            for (int i = 2; i <= 11; i++)
            {
                bus[3, i] = ".";
            }
            for (int i = 1; i <= 11; i++)
            {
                for (int j = 1; j < 5; j++)
                {
                    if ((bus[j,i] != ".") && (n != 0) )
                    {
                        bus[j, i] = "O.";
                        n--;
                    }
                    else if ( (bus[j,i] != "."))
                    {
                        bus[j, i] = "#.";
                    }

                }

            }

            Console.Write('+');
            for (int l = 1; l < 25; l++)
            {
                Console.Write('-');
            }
            Console.Write('+');
            for (int i = 1; i < 5; i++)
            {
                Console.WriteLine();
                for (int j  = 0; j < 14; j++)
                {
                    output[i] += bus[i, j];

                }

                if ((i == 1) || (i == 4))
                {
                    Console.Write(output[i] + ')');
                }
                else
                {
                    Console.Write(output[i]);
                }
            }
            Console.WriteLine();
            Console.Write('+');
            for (int l = 1; l < 25; l++)
            {
                Console.Write('-');
            }
            Console.Write('+');

            Console.Read();

        }
    }
}


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

class PairVariable : IComparable<PairVariable>
{
    public int a, b;
    public PairVariable()
    {
        a = b = 0;
    }
    public PairVariable(string s)
    {
        string[] q = s.Split();
        a = int.Parse(q[0]);
        b = int.Parse(q[1]);
    }
    public PairVariable(int a, int b)
    {
        this.a = a;
        this.b = b;
    }
    public int CompareTo(PairVariable pv)
    {
        if (this.a > pv.a)
        {
            return 1;
        }
        else if (this.a < pv.a)
        {
            return -1;
        }
        else
        {
            if (this.b >= pv.b)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
    }

}
namespace ConsoleApplication254
{
    class Program
    {
        static Dictionary<int, List<int>> d = new Dictionary<int, List<int>>();
        static int[] mark;
        static Dictionary<long, long> cnt;
        static int[] color;
        static int size = 0;
        static void dfs(int v)
        {
            size++;
            mark[v] = 1;
            bool w = false;
            if (cnt.ContainsKey(color[v]))
            {
                cnt[color[v]]++;
            }
            else
            {
                cnt.Add(color[v], 1);
            }
            for (int i = 0; i < d[v].Count; i++)
            {
                if (mark[d[v][i]] == 0)
                {

                    dfs(d[v][i]);
                }

            }

        }
        static void Main(string[] args)
        {
            string[] ss = Console.ReadLine().Split();
            int n = int.Parse(ss[0]);
            int k1 = 0;
            int k2 = 0;
            int k3 = 0;
            if (n > 4)
            {
                string a1 = "+------------------------+";
                string a2 = "|#.#.#.#.#.#.#.#.#.#.#.|D|)";
                string a3 = "|#.#.#.#.#.#.#.#.#.#.#.|.|";
                string a4 = "|O.......................|";
                string a5 = "|#.#.#.#.#.#.#.#.#.#.#.|.|)";
                string a6 = "+------------------------+";
                if ((n - 1) % 3 == 0)
                {
                    k1 = (n - 1) / 3;
                    k2 = (n - 1) / 3;
                    k3 = (n - 1) / 3;
                }
                else if ((n - 1) % 3 == 1)
                {
                    k1 = (n - 1) / 3 + 1;
                    k2 = (n - 1) / 3;
                    k3 = (n - 1) / 3;
                }
                else
                {
                    k1 = (n - 1) / 3 + 1;
                    k2 = (n - 1) / 3 + 1;
                    k3 = (n - 1) % 3;
                }
                //Console.WriteLine(k1+" "+k2+" "+k3);
                int k = 1;
                string c1 = a1;
                string c2 = "";
                string c3 = "";
                string c4 = a4;
                string c5 = "";
                string c6 = a6;
                for (int i = 0; i < a2.Length; i++)
                {
                    if (k <= k1)
                    {
                        if (a2[i] == '#')
                        {
                            c2 += 'O';
                            k++;
                        }
                        else
                        {
                            c2 += a2[i];
                        }
                    }
                    else
                    {
                        c2 += a2[i];
                    }
                }
                k = 1;
                for (int i = 0; i < a3.Length; i++)
                {
                    if (k <= k2)
                    {
                        if (a3[i] == '#')
                        {
                            c3 += 'O';
                            k++;
                        }
                        else
                        {
                            c3 += a3[i];
                        }
                    }
                    else
                    {
                        c3 += a3[i];
                    }
                }
                k = 1;
                for (int i = 0; i < a5.Length; i++)
                {
                    if (k <= k3)
                    {
                        if (a5[i] == '#')
                        {
                            c5 += 'O';
                            k++;
                        }
                        else
                        {
                            c5 += a5[i];
                        }
                    }
                    else
                    {
                        c5 += a5[i];
                    }
                }
                Console.WriteLine(c1);
                Console.WriteLine(c2);
                Console.WriteLine(c3);
                Console.WriteLine(c4);
                Console.WriteLine(c5);
                Console.WriteLine(c6);
            }
            else
            {

                if (n == 1)
                {
                    Console.WriteLine("+------------------------+");
                    Console.WriteLine("|O.#.#.#.#.#.#.#.#.#.#.|D|)");
                    Console.WriteLine("|#.#.#.#.#.#.#.#.#.#.#.|.|");
                    Console.WriteLine("|#.......................|");
                    Console.WriteLine("|#.#.#.#.#.#.#.#.#.#.#.|.|)");
                    Console.WriteLine("+------------------------+");
                }
                else if (n == 2)
                {

                    Console.WriteLine("+------------------------+");
                    Console.WriteLine("|O.#.#.#.#.#.#.#.#.#.#.|D|)");
                    Console.WriteLine("|O.#.#.#.#.#.#.#.#.#.#.|.|");
                    Console.WriteLine("|#.......................|");
                    Console.WriteLine("|#.#.#.#.#.#.#.#.#.#.#.|.|)");
                    Console.WriteLine("+------------------------+");
                }
                else if (n == 3)
                {
                    Console.WriteLine("+------------------------+");
                    Console.WriteLine("|O.#.#.#.#.#.#.#.#.#.#.|D|)");
                    Console.WriteLine("|O.#.#.#.#.#.#.#.#.#.#.|.|");
                    Console.WriteLine("|O.......................|");
                    Console.WriteLine("|#.#.#.#.#.#.#.#.#.#.#.|.|)");
                    Console.WriteLine("+------------------------+");
                }
                else if (n == 4)
                {
                    Console.WriteLine("+------------------------+");
                    Console.WriteLine("|O.#.#.#.#.#.#.#.#.#.#.|D|)");
                    Console.WriteLine("|O.#.#.#.#.#.#.#.#.#.#.|.|");
                    Console.WriteLine("|O.......................|");
                    Console.WriteLine("|O.#.#.#.#.#.#.#.#.#.#.|.|)");
                    Console.WriteLine("+------------------------+");
                }
                else
                {

                    Console.WriteLine("+------------------------+");
                    Console.WriteLine("|#.#.#.#.#.#.#.#.#.#.#.|D|)");
                    Console.WriteLine("|#.#.#.#.#.#.#.#.#.#.#.|.|");
                    Console.WriteLine("|#.......................|");
                    Console.WriteLine("|#.#.#.#.#.#.#.#.#.#.#.|.|)");
                    Console.WriteLine("+------------------------+");
                }
            }
        }
    }
}


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

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

            Console.WriteLine("+------------------------+");
            for(int row = 0; row < 4; row++) {
                string r = "|";
                int seats = (passengers - 4) / 3;
                if(row == 0) {
                    if((passengers - 4) % 3 > 0) {
                        seats += 1;
                    }
                } else if(row == 1) {
                    if((passengers - 4) % 3 > 1) {
                        seats += 1;
                    }
                }
                if(row == 2) {
                    if(passengers >= 3) {
                        Console.WriteLine("|O.......................|");
                    } else {
                        Console.WriteLine("|#.......................|");
                    }
                    continue;
                }

                for(int i = 0; i <= seats; i++) {
                    if(row == 3 && passengers < 4) {
                        continue;
                    }
                    r += "O.";
                }
                if(passengers - (row + 1) == 0 && row == 0) {
                    r += "O.";
                    seats++;
                }
                for(int i = seats; i < 10; i++) {
                    r += "#.";

                }
                if(row == 0) {
                    r += "|D|)";
                } else if(row == 1) {
                    r += "|.|";
                } else if(row == 2) {
                    r += "..|";
                } else if (row == 3) {
                    r += "|.|)";
                }
                Console.WriteLine(r);
            }
            Console.WriteLine("+------------------------+");
        }
    }
}


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Collections;
using System.Text.RegularExpressions;

namespace Task
{

    #region MyIo

    internal class MyIo : IDisposable
    {
        private readonly TextReader inputStream;
        private readonly TextWriter outputStream = Console.Out;

        private string[] tokens;
        private int pointer;

        public MyIo()
#if  LOCAL_TEST
            : this(new StreamReader("input.txt"))
#else
            : this(System.Console.In)
#endif
        {

        }

        public MyIo(TextReader inputStream)
        {
            this.inputStream = inputStream;
        }

        public char NextChar()
        {
            try
            {
                return (char)inputStream.Read();
            }
            catch (IOException)
            {
                return '\0';
            }
        }

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

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

        public int NextInt()
        {
            return Next<int>();
        }

        public long NextLong()
        {
            return Next<long>();
        }

        public T Next<T>()
        {
            var t = typeof(T);

            if (t == typeof(char))
                return (T)(object)NextChar();

            object s = NextString();

            if (t == typeof(string))
                return (T)s;

            return (T)Convert.ChangeType(s, typeof(T));
        }

        public IEnumerable<T> NextWhile<T>(Predicate<T> pred)
        {
            if (pred == null)
                yield break;

            T res = Next<T>();

            while (pred(res))
            {
                yield return res;

                res = Next<T>();
            }
        }

        public IEnumerable<T> NextSeq<T>(long n)
        {
            for (var i = 0; i < n; i++)
                yield return Next<T>();
        }

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

        public void PrintLine(string format, params object[] args)
        {
            Print(format, args);

            outputStream.WriteLine();
        }

        public void Print(bool o)
        {
            Print(o ? "yes" : "no");
        }

        public void PrintLine(bool o)
        {
            Print(o);

            outputStream.WriteLine();
        }

        public void Print<T>(T o)
        {
            outputStream.Write(Convert.ToString(o, CultureInfo.InvariantCulture));
        }

        public void PrintLine<T>(T o)
        {
            Print(o);

            outputStream.WriteLine();
        }

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

        void IDisposable.Dispose()
        {
            Close();

#if  LOCAL_TEST
            Console.ReadLine();
#endif
        }
    }

    public static class ListExtensions
    {
        public static void Each<T>(this IEnumerable<T> self, Action<T> action)
        {
            foreach (var v in self)
                action(v);
        }

        public static IEnumerable<T> ToCycleEnumerable<T>(this IEnumerable<T> self)
        {
            if (self != null)
            {
                for (; ; )
                {
                    foreach (var x in self)
                        yield return x;
                }
            }
        }

        public static T CycleGet<T>(this IList<T> self, int index)
        {
            var c = self.Count;
            return self[(index % c + c) % c];
        }

        public static IList<T> Shuffle<T>(this IList<T> self)
        {
            var rnd = new Random(DateTime.Now.Millisecond);

            var n = self.Count;

            while (n > 1)
            {
                n--;
                var k = rnd.Next(n + 1);
                var value = self[k];
                self[k] = self[n];
                self[n] = value;
            }

            return self;
        }

        public static IList<IList<T>> UseForNew2D<T>(this T def, int fd, int sd)
        {
            var fdim = new T[fd][];

            for (int i = 0; i < fd; i++)
            {
                fdim[i] = new T[sd];
                Fill(fdim[i], def);
            }

            return fdim;
        }

        public static IList<T> Fill<T>(this IList<T> self, Func<T> fval)
        {
            for (var i = 0; i < self.Count; i++)
                self[i] = fval();

            return self;
        }

        public static IList<T> Fill<T>(this IList<T> self, T val)
        {
            return self.Fill(() => val);
        }

        public static long Hash<T>(this IList<T> self, Func<T, long> val = null)
        {
            return val != null ? self.Hash((t, current) => unchecked(current * 19L + val(t))) : self.Hash(HashOne);
        }

        public static long Hash<T>(this IList<T> self, Func<T, long, long> val)
        {
            return self.Aggregate(0L, (current, t) => unchecked(val(t, current)));
        }

        public static long HashOne<T>(this T self, long current)
        {
            return unchecked(current * 19L + (Equals(self, default(T)) ? 0 : self.GetHashCode()));
        }

        public static IList<T1> BuildSegTree<T1, T2>(this IList<T2> a, Func<T1, T1, T1> combine, Func<T2, T1> convert)
        {
            var t = new T1[a.Count << 2];

            a.BuildSegTree(t, 1, 0, a.Count - 1, combine, convert);

            return t;
        }

        private static void BuildSegTree<T1, T2>(this IList<T2> a, IList<T1> t, int v, int tl, int tr, Func<T1, T1, T1> combine, Func<T2, T1> convert)
        {
            if (tl == tr)
            {
                t[v] = convert(a[tl]);
            }
            else
            {
                int tm = (tl + tr) >> 1;

                BuildSegTree(a, t, v << 1, tl, tm, combine, convert);
                BuildSegTree(a, t, (v << 1) + 1, tm + 1, tr, combine, convert);

                t[v] = combine(t[v << 1], t[(v << 1) + 1]);
            }
        }
    }

    public static class P
    {
        public static P<T1, T2> Create<T1, T2>(T1 key, T2 val)
        {
            return new P<T1, T2>(key, val);
        }
    }

    public class P<T1, T2>
    {
        private class PComparer : IComparer<P<T1, T2>>
        {
            private readonly bool? byKey;

            public PComparer(bool? byKey)
            {
                this.byKey = byKey;
            }

            public int Compare(P<T1, T2> x, P<T1, T2> y)
            {
                x = x ?? new P<T1, T2>();
                y = y ?? new P<T1, T2>();

                if (byKey == true)
                    return Comparer<T1>.Default.Compare(x.Key, y.Key);
                else if (byKey == false)
                    return Comparer<T2>.Default.Compare(x.Value, y.Value);
                else
                {
                    var tr = Comparer<T1>.Default.Compare(x.Key, y.Key);

                    if (tr != 0)
                        tr = Comparer<T2>.Default.Compare(x.Value, y.Value);

                    return tr;
                }
            }
        }

        public P()
        {
        }

        public P(T1 key, T2 val)
        {
            this.Key = key;
            this.Value = val;
        }

        public T1 Key
        {
            get;
            set;
        }

        public T2 Value
        {
            get;
            set;
        }

        public P<T1, T2> Clone()
        {
            return new P<T1, T2>(Key, Value);
        }

        public static IComparer<P<T1, T2>> KeyComparer
        {
            get { return new PComparer(true); }
        }

        public static IComparer<P<T1, T2>> ValueComparer
        {
            get { return new PComparer(false); }
        }

        public static implicit operator T1(P<T1, T2> obj)
        {
            return obj.Key;
        }

        public static implicit operator T2(P<T1, T2> obj)
        {
            return obj.Value;
        }

        public P<T1, T2> SetKey(T1 key)
        {
            Key = key;
            return this;
        }

        public P<T1, T2> SetValue(T2 value)
        {
            Value = value;
            return this;
        }

        public override string ToString()
        {
            return string.Format("Key: {0}, Value: {1}", Key, Value);
        }

        public override bool Equals(object obj)
        {
            var co = obj as P<T1, T2>;

            return co != null && co.GetHashCode() == GetHashCode();
        }

        public override int GetHashCode()
        {
            int hash = 17;
            hash = hash * 31 + ((Equals(Key, default(T1))) ? 0 : Key.GetHashCode());
            hash = hash * 31 + ((Equals(Value, default(T1))) ? 0 : Value.GetHashCode());
            return hash;

        }
    }

    #endregion

    internal class Program
    {
        #region Program

        private readonly MyIo io;

        public Program(MyIo io)
        {
            this.io = io;
        }

        public static void Main(string[] args)
        {
            using (MyIo io = new MyIo())
            {
                new Program(io)
                    .Solve();
            }
        }

        #endregion

        public const long MOD = 1000000007;
        public const double EPS = 1e-14;

        private void Solve()
        {
            var n = io.NextLong();

            var x = io.NextLong();
            var y = io.NextLong();

            var c = io.NextLong();

            long s = 0;

            if (c > 1)
            {

                var ub = (long)Math.Sqrt(1+8*c);
                var lb = Math.Max(ub / 4L - 1L, 0L);

                s = ub;

                do
                {

                    var m = (ub + lb) >> 1;

                    var cn = Calc(n, x, y, m);

                    if (cn > c)
                    {
                        ub--;
                        s = Math.Min(m, s);
                    }
                    else if (cn < c)
                    {
                        lb++;
                    }
                    else if (cn == c)
                    {
                        s = m;
                        break;
                    }

                } while (ub > lb);

            }

            io.Print(s);
        }

        private long Pos0(long x)
        {
            return x > 0 ? x : 0;
        }

        private long Pow2(long x)
        {

            return x*x;
        }

        private long Pow2120(long x)
        {
            x = Pos0(x);

            return x * (x + 1L) / 2;
        }

        private long Calc(long n, long x, long y, long s)
        {
           // s = 37707;

            if (s == 0)
                return 1;

            var r = Pos0(s + y - n);
            var b = Pos0(s + x - n);

            var l = Pos0(1 - y + s);
            var t = Pos0(1 - x + s);

            var ix = 1 + n - x;
            var iy = 1 + n - y;

            var bse = s*s + (s + 1)*(s + 1) - Pow2(r) - Pow2(t) - Pow2(b) - Pow2(l);

            bse += Pow2120(l - x);
            bse += Pow2120(r - x);

            bse += Pow2120(l - ix);
            bse += Pow2120(r - ix);

            return bse;
        }
    }

}


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Collections;
using System.Text.RegularExpressions;

namespace Task
{

    #region MyIo

    internal class MyIo : IDisposable
    {
        private readonly TextReader inputStream;
        private readonly TextWriter outputStream = Console.Out;

        private string[] tokens;
        private int pointer;

        public MyIo()
#if  LOCAL_TEST
            : this(new StreamReader("input.txt"))
#else
            : this(System.Console.In)
#endif
        {

        }

        public MyIo(TextReader inputStream)
        {
            this.inputStream = inputStream;
        }

        public char NextChar()
        {
            try
            {
                return (char)inputStream.Read();
            }
            catch (IOException)
            {
                return '\0';
            }
        }

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

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

        public int NextInt()
        {
            return Next<int>();
        }

        public long NextLong()
        {
            return Next<long>();
        }

        public T Next<T>()
        {
            var t = typeof(T);

            if (t == typeof(char))
                return (T)(object)NextChar();

            object s = NextString();

            if (t == typeof(string))
                return (T)s;

            return (T)Convert.ChangeType(s, typeof(T));
        }

        public IEnumerable<T> NextWhile<T>(Predicate<T> pred)
        {
            if (pred == null)
                yield break;

            T res = Next<T>();

            while (pred(res))
            {
                yield return res;

                res = Next<T>();
            }
        }

        public IEnumerable<T> NextSeq<T>(long n)
        {
            for (var i = 0; i < n; i++)
                yield return Next<T>();
        }

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

        public void PrintLine(string format, params object[] args)
        {
            Print(format, args);

            outputStream.WriteLine();
        }

        public void Print(bool o)
        {
            Print(o ? "yes" : "no");
        }

        public void PrintLine(bool o)
        {
            Print(o);

            outputStream.WriteLine();
        }

        public void Print<T>(T o)
        {
            outputStream.Write(Convert.ToString(o, CultureInfo.InvariantCulture));
        }

        public void PrintLine<T>(T o)
        {
            Print(o);

            outputStream.WriteLine();
        }

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

        void IDisposable.Dispose()
        {
            Close();

#if  LOCAL_TEST
            Console.ReadLine();
#endif
        }
    }

    public static class ListExtensions
    {
        public static void Each<T>(this IEnumerable<T> self, Action<T> action)
        {
            foreach (var v in self)
                action(v);
        }

        public static IEnumerable<T> ToCycleEnumerable<T>(this IEnumerable<T> self)
        {
            if (self != null)
            {
                for (; ; )
                {
                    foreach (var x in self)
                        yield return x;
                }
            }
        }

        public static T CycleGet<T>(this IList<T> self, int index)
        {
            var c = self.Count;
            return self[(index % c + c) % c];
        }

        public static IList<T> Shuffle<T>(this IList<T> self)
        {
            var rnd = new Random(DateTime.Now.Millisecond);

            var n = self.Count;

            while (n > 1)
            {
                n--;
                var k = rnd.Next(n + 1);
                var value = self[k];
                self[k] = self[n];
                self[n] = value;
            }

            return self;
        }

        public static IList<IList<T>> UseForNew2D<T>(this T def, int fd, int sd)
        {
            var fdim = new T[fd][];

            for (int i = 0; i < fd; i++)
            {
                fdim[i] = new T[sd];
                Fill(fdim[i], def);
            }

            return fdim;
        }

        public static IList<T> Fill<T>(this IList<T> self, Func<T> fval)
        {
            for (var i = 0; i < self.Count; i++)
                self[i] = fval();

            return self;
        }

        public static IList<T> Fill<T>(this IList<T> self, T val)
        {
            return self.Fill(() => val);
        }

        public static long Hash<T>(this IList<T> self, Func<T, long> val = null)
        {
            return val != null ? self.Hash((t, current) => unchecked(current * 19L + val(t))) : self.Hash(HashOne);
        }

        public static long Hash<T>(this IList<T> self, Func<T, long, long> val)
        {
            return self.Aggregate(0L, (current, t) => unchecked(val(t, current)));
        }

        public static long HashOne<T>(this T self, long current)
        {
            return unchecked(current * 19L + (Equals(self, default(T)) ? 0 : self.GetHashCode()));
        }

        public static IList<T1> BuildSegTree<T1, T2>(this IList<T2> a, Func<T1, T1, T1> combine, Func<T2, T1> convert)
        {
            var t = new T1[a.Count << 2];

            a.BuildSegTree(t, 1, 0, a.Count - 1, combine, convert);

            return t;
        }

        private static void BuildSegTree<T1, T2>(this IList<T2> a, IList<T1> t, int v, int tl, int tr, Func<T1, T1, T1> combine, Func<T2, T1> convert)
        {
            if (tl == tr)
            {
                t[v] = convert(a[tl]);
            }
            else
            {
                int tm = (tl + tr) >> 1;

                BuildSegTree(a, t, v << 1, tl, tm, combine, convert);
                BuildSegTree(a, t, (v << 1) + 1, tm + 1, tr, combine, convert);

                t[v] = combine(t[v << 1], t[(v << 1) + 1]);
            }
        }
    }

    public static class P
    {
        public static P<T1, T2> Create<T1, T2>(T1 key, T2 val)
        {
            return new P<T1, T2>(key, val);
        }
    }

    public class P<T1, T2>
    {
        private class PComparer : IComparer<P<T1, T2>>
        {
            private readonly bool? byKey;

            public PComparer(bool? byKey)
            {
                this.byKey = byKey;
            }

            public int Compare(P<T1, T2> x, P<T1, T2> y)
            {
                x = x ?? new P<T1, T2>();
                y = y ?? new P<T1, T2>();

                if (byKey == true)
                    return Comparer<T1>.Default.Compare(x.Key, y.Key);
                else if (byKey == false)
                    return Comparer<T2>.Default.Compare(x.Value, y.Value);
                else
                {
                    var tr = Comparer<T1>.Default.Compare(x.Key, y.Key);

                    if (tr != 0)
                        tr = Comparer<T2>.Default.Compare(x.Value, y.Value);

                    return tr;
                }
            }
        }

        public P()
        {
        }

        public P(T1 key, T2 val)
        {
            this.Key = key;
            this.Value = val;
        }

        public T1 Key
        {
            get;
            set;
        }

        public T2 Value
        {
            get;
            set;
        }

        public P<T1, T2> Clone()
        {
            return new P<T1, T2>(Key, Value);
        }

        public static IComparer<P<T1, T2>> KeyComparer
        {
            get { return new PComparer(true); }
        }

        public static IComparer<P<T1, T2>> ValueComparer
        {
            get { return new PComparer(false); }
        }

        public static implicit operator T1(P<T1, T2> obj)
        {
            return obj.Key;
        }

        public static implicit operator T2(P<T1, T2> obj)
        {
            return obj.Value;
        }

        public P<T1, T2> SetKey(T1 key)
        {
            Key = key;
            return this;
        }

        public P<T1, T2> SetValue(T2 value)
        {
            Value = value;
            return this;
        }

        public override string ToString()
        {
            return string.Format("Key: {0}, Value: {1}", Key, Value);
        }

        public override bool Equals(object obj)
        {
            var co = obj as P<T1, T2>;

            return co != null && co.GetHashCode() == GetHashCode();
        }

        public override int GetHashCode()
        {
            int hash = 17;
            hash = hash * 31 + ((Equals(Key, default(T1))) ? 0 : Key.GetHashCode());
            hash = hash * 31 + ((Equals(Value, default(T1))) ? 0 : Value.GetHashCode());
            return hash;

        }
    }

    #endregion

    internal class Program
    {
        #region Program

        private readonly MyIo io;

        public Program(MyIo io)
        {
            this.io = io;
        }

        public static void Main(string[] args)
        {
            using (MyIo io = new MyIo())
            {
                new Program(io)
                    .Solve();
            }
        }

        #endregion

        public const long MOD = 1000000007;
        public const double EPS = 1e-14;

        private void Solve()
        {
            var n = io.NextLong();

            var x = io.NextLong();
            var y = io.NextLong();

            var c = io.NextLong();

            long s = 0;

            if (c > 1)
            {

                var lb = 1;
                var ub = n;

                s = n;

                do
                {
                    var m = (ub + lb) >> 1;
                    var cn = Calc(n, x, y, m);

                    if (cn > c)
                    {
                        ub--;
                        s = Math.Min(m, s);
                    }
                    else if (cn < c)
                        lb++;

                } while (lb < ub);

            }

            io.Print(s);
        }

        private long Pos0(long x)
        {
            return x > 0 ? x : 0;
        }

        private long Pow2(long x)
        {
            return x*x;
        }

        private long Calc(long n, long x, long y, long s)
        {
            if (s == 0)
                return 1;

            var r = Pos0(s + y - n);
            var b = Pos0(s + x - n);

            var l = Pos0(1 - y + s);
            var t = Pos0(1 - x + s);

            var bse = s * s + (s + 1) * (s + 1) - Pow2(r) - Pow2(t) - Pow2(b) - Pow2(l);

            if (r > 1 && b > 1)
                bse += r*(b - 1) / 2 ;

            if (l > 1 && b > 1)
                bse += l * (b - 1) / 2;

            if (r > 1 && t > 1)
                bse += r * (t - 1) / 2;

            if (l > 1 && t > 1)
                bse += l * (t - 1) /2;

            return bse;
        }
    }

}


sing System;
using System.Linq;

namespace _119A
{
    class Program
    {
        static void Main()
        {
            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int winner=0;
            while (true)
            {
                if (FindGCD(input[0], input[1]) <= input[2])
                input[2] -= input[0];
                else { winner = 1; break; }
                if (FindGCD(input[0], input[1]) <= input[2])
                    input[2] -= input[1];
                else { winner = 0; break; }
            }
            Console.WriteLine(winner);
        }

        static int FindGCD(int x,int y)
        {
            int GCD=0;
            if (y > 0)
            {
                for (int i = 1; i <= Math.Min(x, y); i++)
                {
                    if ((x % i == 0) && (y % i == 0)) { GCD = i; }
                }
            }
            else GCD = x;
            return GCD;
        }
    }
}


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

namespace Petya_Exam
{
    class Program
    {
        struct Exam
        {
            public int ExamIndex;
            public int Publish;
            public int ExamDay;
            public int PrepDays;
        }

        static void Main(string[] args)
        {
            string[] s = (Console.ReadLine()).Split(' ');
            int N_Days = int.Parse(s[0]);
            int Total_exams = int.Parse(s[1]);
            List<Exam> list2 = new List<Exam>();
            for (int i = 0; i < Total_exams; ++i)
            {
                Exam exm;
                s = (Console.ReadLine()).Split(' ');
                exm.ExamIndex = i + 1;
                exm.Publish = int.Parse(s[0]);
                exm.ExamDay = int.Parse(s[1]);
                exm.PrepDays = int.Parse(s[2]);
                list2.Add(exm);
            }
           list2.Sort((x, y) => x.ExamDay.CompareTo(y.ExamDay));
            List<int> seq = new List<int>();
            for (int i = 0; i <= N_Days; ++i)
            {
                seq.Add(0);
            }
            int print = 0;
            foreach (Exam l in list2)
            {
                if (l.Publish - 1 + l.PrepDays < l.ExamDay)
                {
                    if (Ispossible(l.ExamIndex, l, seq))
                    {
                        seq[l.ExamDay] = Total_exams + 1;

                        continue;
                    }
                    else
                    {
                        print = -1;
                        break;
                    }
                }
            }
            if (print == 0)
            {
                if (seq.Sum() != 0)
                {
                    for (int j = 1; j < seq.Count; ++j)
                    {
                        if (j + 1 == seq.Count)
                        {
                            Console.Write(seq[j]);
                            continue;
                        }
                        Console.Write(seq[j] + " ");
                    }
                }
                else
                {
                    Console.WriteLine("-1");
                }
            }
            else
            {
                Console.WriteLine("-1");
            }

           // Console.ReadKey();
        }

        private static bool Ispossible(int exam_number, Exam l, List<int> seq)
        {
            int days = l.PrepDays;

            int i = l.Publish;
            while (i < l.ExamDay && days > 0)
            {
                if (seq[i] == 0)
                {
                    seq[i] = exam_number;
                    days--;
                }
                i++;
            }
            return days == 0 ? true : false;
        }

    }
}


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

namespace CF2
{
    class Program
    {
        static void Main(string[] args)
        {
            string s1 = Console.ReadLine();
            for (int i=1;i<=100;i++)
            s1 = RemoveSlashes(s1);
            if (s1[s1.Length] == '/') s1.Remove(s1.Length);
                Console.WriteLine(s1);

        }
        static string RemoveSlashes(string txt)
        {
            string text = txt.Replace("//", "/");

            if (text.Contains("//"))
                RemoveSlashes(text);
            return text;
        }

    }
}


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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            TextReader sr = Console.In;
            //StreamReader sr = new StreamReader("in7.txt");
            string[] s = sr.ReadLine().Split();
            int x = Convert.ToInt32(s[0]);
            int y = Convert.ToInt32(s[1]);
            int z = Convert.ToInt32(s[2]);
            int t1 = Convert.ToInt32(s[3]);
            int t2 = Convert.ToInt32(s[4]);
            int t3 = Convert.ToInt32(s[5]);
            int lift = Math.Abs(z - x) * t2 + 2 * t3 + Math.Abs(y - x) * t2;
            int poxod = Math.Abs(y - x) * t1;
            if(lift<=poxod) Console.WriteLine("YES");
            else Console.WriteLine("NO");
        }
    }
}


using System;

public class Program
{
	public static void Main()
	{
		long otv1 = 0;
		long otv2 = 0;
		string[] temp = Console.ReadLine().Split(' ');
		int x = Convert.ToInt32(temp[0]);
		int y = Convert.ToInt32(temp[1]);
		int lf = Convert.ToInt32(temp[2]);
		int sh = Convert.ToInt32(temp[3]);
		int d = Convert.ToInt32(temp[4]);
		int op = Convert.ToInt32(temp[5]);
		if(x>=y)
		{
			otv1 = (x - y) * sh;
			otv2 = ((x - y) * d) + 3;
		}
		if(x<y)
		{
			otv1 = (y - x) * sh;
			otv2 = ((y - x) * d) + 3;
		}
		if(lf>=x)
		{
			otv2 += (lf-x) * d;
		}
		if(lf<x)
		{
			otv2 += (x-lf) * d;
		}
		if(otv1<otv2)
		Console.WriteLine("NO");
		else
		Console.WriteLine("YES");
	}
}


using System;

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

            var x = int.Parse(input[0]);
            var y = int.Parse(input[1]);
            var z = int.Parse(input[2]);
            var t1 = int.Parse(input[3]);
            var t2 = int.Parse(input[4]);
            var t3 = int.Parse(input[5]);

            var leg = Math.Abs(x - y) * t1;

            var lift = (Math.Abs(z - x) + Math.Abs(x - y)) * t2 + 3 * t3;

            if (leg > lift)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}


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

using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Text.RegularExpressions;

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

            int x = int.Parse(str1[0]);
            int y = int.Parse(str1[1]);
            int z = int.Parse(str1[2]);
            int t1 = int.Parse(str1[3]);
            int t2 = int.Parse(str1[4]);
            int t3 = int.Parse(str1[5]);

            if (Math.Abs(x-z)*t2 + Math.Abs(x-y)*t2 +3*t3 < Math.Abs(x-y)*t1)
            {
                Console.WriteLine("YES");

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

            }
        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int x = int.Parse(s[0]);
            int y = int.Parse(s[1]);
            int z = int.Parse(s[2]);
            int t1 = int.Parse(s[3]);
            int t2 = int.Parse(s[4]);
            int t3 = int.Parse(s[5]);
            int q1 = Math.Abs(x - z);
            int q2 = (Math.Max(x, y) - Math.Min(x, y))*t2;
            int lift = q1 + q2+t3*3;
            int mash = t1 * (Math.Max(x, y) - Math.Min(x, y));
            //Console.WriteLine(lift);
            //Console.WriteLine(mash);
            if (mash >= lift)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
            //Console.ReadKey();
        }
    }
}


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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split(' ');
            int x = Convert.ToInt32(s[0]);
            int y = Convert.ToInt32(s[1]);
            int z = Convert.ToInt32(s[2]);
            int t1 = Convert.ToInt32(s[3]);
            int t2 = Convert.ToInt32(s[4]);
            int t3 = Convert.ToInt32(s[5]);

            var d = Math.Abs(x - y);
            var xx = Math.Abs(z - x);
            var tt1 = xx + 3 * t3 + d * t2;
            var tt2 = d * t1;

            if(tt1<=tt2)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }

        }

    }

}


using System;

class MainClass
{
	public static void Main (string[] args)
	{
		int x = Convert.ToInt32 (Console.ReadLine ());
		int count = 1;
		while ((x != 1 || count==0) ) {
			x++;
			count++;
			while (x % 10 == 0)
				x /= 10;
		}
		Console.WriteLine (count);
	}
}


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

public class Program
{
	public static void Main()
	{
		//Console.SetIn(new StreamReader("input.txt"));
        solve_555A();
	}

	public static void solve_555A()
	{
		long n = Convert.ToInt32(Console.ReadLine());
		long num = n;
		long count = 0;

		while (true)
		{
			long left = 10 - num % 10;

			count += num < 10 ? 9 : left;

			num += left;

			while (num % 10 == 0)
			{
				num /= 10;
			}

			if (num == 1)
			{
				break;
			}
		}

		/*while (n >= 10 && num > 1)
		{
			long lastDigit = num % 10;

			long left = 10 - lastDigit;

			Console.WriteLine(left);
			count += left;

			num += left;

			while (num % 10 == 0)
			{
				num /= 10;
			}
		}
 		*/
		Console.WriteLine(count);
	}
	public static void solve_547B()
	{
		int n = Convert.ToInt32(Console.ReadLine());
		string[] tests = Console.ReadLine().Split(' ');

		List<int> maxs = new List<int>();
		int curCount = 0;
		for (int i = 0; i < tests.Length; i++)
		{
			if (tests[i] == "1")
			{
				curCount++;
			}

			if (i == tests.Length - 1 || tests[i] == "0")
			{
				maxs.Add(curCount);
				curCount = 0;
			}
		}

		if (tests[0] == tests[tests.Length - 1] && tests[0] != "0")
		{
			maxs[0] = maxs[0] + maxs[maxs.Count - 1];
		}

		int max = 0;
		for (int i = 0; i < maxs.Count; i++)
		{
			if (max < maxs[i])
			{
				max = maxs[i];
			}
		}

		Console.WriteLine(max);
	}
}


using System;
using System.Collections.Generic;
using System.Linq;
using CompLib.Util;

public class Program
{

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

        long ans = 0;
        var hs = new HashSet<int>();
        hs.Add(n);
        while (n > 1)
        {
            n = F(n);

            hs.Add(n);
        }

        Console.WriteLine(hs.Count);
    }

    int F(int n)
    {
        n++;
        while (n % 10 == 0)
        {
            n /= 10;
        }
        return n;
    }

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

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

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

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

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

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

            return _line[_index++];
        }

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

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

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

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


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

namespace ConsoleApp14
{
    class Program
    {
        public static int Reachable_Num(int i)
        {
            List<int> dict = new List<int>();
            dict.Add(i);
            do
            {
                i++;
                while (i % 10 == 0)
                {
                    i = i / 10;
                }
                if (!dict.Contains(i))
                {
                    dict.Add(i);
                }
            } while (!dict.Contains(RemoveZero(i+1)));
            foreach(int el in dict)
            { Console.WriteLine(el); }
            return dict.Count;
        }
        public static int RemoveZero(int i)
        {
            while (i % 10 == 0)
            {
                i = i / 10;
            }
            return i;
        }
        static void Main(string[] args)
        {
            Console.WriteLine(Reachable_Num(Convert.ToInt32(Console.ReadLine())));
            Console.ReadLine();
        }
    }
}


using System;
using System.Collections.Generic;

namespace ConsoleApp14
{
    class Program
    {
        public static int Reachable_Num(int ip)
        {
           if (ip < 10)
            {
                Console.WriteLine('9');
                return;
            }
            int res = 10 - (ip % 10);
            ip /= 10;
            while(ip>= 10)
            {
                res += 9 - (ip % 10);
                ip /= 10;
            }
            res += 9;
            return res;
        }

        static void Main(string[] args)
        {
            Console.WriteLine(Reachable_Num(Convert.ToInt32(Console.ReadLine())));
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using static System.Array;
using static System.Console;
using static System.Math;

namespace Olymp
{
  public class ProblemSolver
  {
    private readonly Tokenizer input;

    public void Solve()
    {
      var n = input.ReadInt();
      var f = (Func<int, int>)(x =>
      {
        x++;
        while (x % 10 == 0)
          x /= 10;
        return x;
      });
      var a = new HashSet<int> { n };
      do
      {
        n = f(n);
        if (a.Contains(n))
          break;
        a.Add(n);
      }
      while (n != 1);
      Write(a.Count);
    }

    public ProblemSolver(TextReader input)
    {
      this.input = new Tokenizer(input);
    }
  }

  #region Service classes

  public class Tokenizer
  {
    private readonly TextReader reader;

    public string ReadToEnd() => reader.ReadToEnd();

    public int ReadInt()
    {
      var c = SkipWs();
      if (c == -1)
        throw new EndOfStreamException();
      var isNegative = false;
      if (c == '-' || c == '+')
      {
        isNegative = c == '-';
        c = reader.Read();
        if (c == -1)
          throw new EndOfStreamException("Digit expected, but end of stream occurs");
      }

      if (!char.IsDigit((char)c))
        throw new InvalidOperationException($"Digit expected, but was: '{(char)c}'");

      checked
      {
        var result = (char)c - '0';
        c = reader.Read();
        while (c > 0 && !char.IsWhiteSpace((char)c))
        {
          if (!char.IsDigit((char)c))
            throw new InvalidOperationException($"Digit expected, but was: '{(char)c}'");
          result = result * 10 + (char)c - '0';
          c = reader.Read();
        }

        if (isNegative)
          result = -result;
        return result;
      }
    }

    public string ReadLine() => reader.ReadLine();

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

    public double ReadDouble() => double.Parse(ReadToken(), CultureInfo.InvariantCulture);

    public int[] ReadIntArray(int n)
    {
      var a = new int[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadInt();
      return a;
    }

    public (int, int) Read2Int() => (ReadInt(), ReadInt());

    public (int, int, int) Read3Int() => (ReadInt(), ReadInt(), ReadInt());

    public (int, int, int, int) Read4Int() => (ReadInt(), ReadInt(), ReadInt(), ReadInt());

    public (long, long) Read2Long() => (ReadLong(), ReadLong());

    public long[] ReadLongArray(int n)
    {
      var a = new long[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadLong();
      return a;
    }

    public double[] ReadDoubleArray(int n)
    {
      var a = new double[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadDouble();
      return a;
    }

    public string ReadToken()
    {
      var c = SkipWs();
      if (c == -1)
        return null;
      var sb = new StringBuilder();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        sb.Append((char)c);
        c = reader.Read();
      }

      return sb.ToString();
    }

    private int SkipWs()
    {
      var c = reader.Read();
      if (c == -1)
        return c;
      while (c > 0 && char.IsWhiteSpace((char)c))
        c = reader.Read();
      return c;
    }

    public Tokenizer(TextReader reader)
    {
      this.reader = reader;
    }
  }

  internal class Program
  {
    public static void Main()
    {
      var solver = new ProblemSolver(In);
      solver.Solve();
    }
  }

  #endregion
}


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

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

            int k = int.Parse(Console.ReadLine());
            Dictionary<int, int> dic = new Dictionary<int, int>();
            int m = k;
            int i = 1;
            while (true)
            {
                int a = getDigit(k);
                if (!dic.ContainsKey(a))
                {
                    dic.Add(a, a);
                    i++;
                    //Console.WriteLine(a);
                }
                else break;
                k = a;

                m--;
            }
            Console.WriteLine(i);

        }
        static int getDigit(int k)
        {
            int digit = k + 1;
            while (digit % 10 == 0)
                digit /= 10;
            return digit;
        }

    }
}


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

namespace ProjectEuler
{
    class Program
    {

        private static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            HashSet<int> hs = new HashSet<int>();
            bool flag = true;

            if (n == 1)
            {
                Console.WriteLine(9);
            }
            else
            {
                while (flag)
                {
                    if (!hs.Contains(n))
                    {
                        hs.Add(n);
                    }

                    n = Fofx(n);
                    if (hs.Contains(1) && hs.Contains(2) && hs.Contains(3) && hs.Contains(4) && hs.Contains(5) && hs.Contains(6) && hs.Contains(7) && hs.Contains(8) && hs.Contains(9))
                    {
                        flag = false;
                    }
                }
                Console.WriteLine(hs.Count);
            }

        }
    }
}


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

namespace C_sarp_tests
{
    class Program
    {
        private static int counter = 1;
        static void Main(string[] args)
        {
            int num = Convert.ToInt32(Console.ReadLine());

            while (num > 0)
            {
                num = Important(num);
            }

            Console.WriteLine(counter);
        }

        private static int Important(int n)
        {
            n++;
            if (n % 10 != 0)
            {
                counter++;

            }

            while (n % 10 == 0)
            {
                n /= 10;

                if (n > 9 && n % 10 != 0)
                {
                    counter++;

                }
                else if (n <= 9)
                {
                    counter += 9;

                    return 0;
                }
            }

            return n;
        }
}}