using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
namespace Program
{
    public static class CODEFORCES1
    {
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            var n = NN;
            var p = NN;
            var ans = 10000;
            for (var i = 0; i <= 33; i++)
            {
                var tmp = n - p * i;
                var mask = 1;
                var tmp2 = 0;
                for (var j = 0; j <= 33; j++)
                {
                    if ((mask & tmp) != 0) ++tmp2;
                    mask <<= 1;
                }
                if (tmp2 <= i && tmp > 0)
                {
                    ans = Min(ans, i);
                }
            }
            if (ans == 10000)
            {
                Console.WriteLine(-1);
            }
            else
            {
                Console.WriteLine(ans);
            }

        }
        static public void Main(string[] args) { if (args.Length == 0) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); }
        static class Console_
        {
            static Queue<string> param = new Queue<string>();
            public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        }
        static long NN => long.Parse(Console_.NextString());
        static double ND => double.Parse(Console_.NextString());
        static string NS => Console_.NextString();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static IEnumerable<long> Primes(long x) { if (x < 2) yield break; yield return 2; var halfx = x / 2; var table = new bool[halfx + 1]; var max = (long)(Math.Sqrt(x) / 2); for (long i = 1; i <= max; ++i) { if (table[i]) continue; var add = 2 * i + 1; yield return add; for (long j = 2 * i * (i + 1); j <= halfx; j += add) table[j] = true; } for (long i = max + 1; i <= halfx; ++i) if (!table[i] && 2 * i + 1 <= x) yield return 2 * i + 1; }
        static IEnumerable<long> Factors(long x) { if (x < 2) yield break; while (x % 2 == 0) { x /= 2; yield return 2; } var max = (long)Math.Sqrt(x); for (long i = 3; i <= max; i += 2) while (x % i == 0) { x /= i; yield return i; } if (x != 1) yield return x; }
        static IEnumerable<long> Divisor(long x) { if (x < 1) yield break; var max = (long)Math.Sqrt(x); for (long i = 1; i <= max; ++i) { if (x % i != 0) continue; yield return i; if (i != x / i) yield return x / i; } }
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
        static long GCD(long a, long b) { while (b > 0) { var tmp = b; b = a % b; a = tmp; } return a; }
        static long LCM(long a, long b) => a * b / GCD(a, b);
        static Mod Pow(Mod x, long y) { Mod a = 1; while (y != 0) { if ((y & 1) == 1) a.Mul(x); x.Mul(x); y >>= 1; } return a; }
        static long Pow(long x, long y) { long a = 1; while (y != 0) { if ((y & 1) == 1) a *= x; x *= x; y >>= 1; } return a; }
        static List<long> _fact = new List<long>() { 1 };
        static void _B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); }
        static long Comb(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; }
        static long Perm(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; }
        static Func<TR> Lambda<TR>(Func<Func<TR>, TR> f) { Func<TR> t = () => default(TR); return t = () => f(t); }
        static Func<T1, TR> Lambda<T1, TR>(Func<T1, Func<T1, TR>, TR> f) { Func<T1, TR> t = x1 => default(TR); return t = x1 => f(x1, t); }
        static Func<T1, T2, TR> Lambda<T1, T2, TR>(Func<T1, T2, Func<T1, T2, TR>, TR> f) { Func<T1, T2, TR> t = (x1, x2) => default(TR); return t = (x1, x2) => f(x1, x2, t); }
        static Func<T1, T2, T3, TR> Lambda<T1, T2, T3, TR>(Func<T1, T2, T3, Func<T1, T2, T3, TR>, TR> f) { Func<T1, T2, T3, TR> t = (x1, x2, x3) => default(TR); return t = (x1, x2, x3) => f(x1, x2, x3, t); }
        static Func<T1, T2, T3, T4, TR> Lambda<T1, T2, T3, T4, TR>(Func<T1, T2, T3, T4, Func<T1, T2, T3, T4, TR>, TR> f) { Func<T1, T2, T3, T4, TR> t = (x1, x2, x3, x4) => default(TR); return t = (x1, x2, x3, x4) => f(x1, x2, x3, x4, t); }
        static List<T> LCS<T>(T[] s, T[] t) where T : IEquatable<T> { int sl = s.Length, tl = t.Length; var dp = new int[sl + 1, tl + 1]; for (var i = 0; i < sl; i++) for (var j = 0; j < tl; j++) dp[i + 1, j + 1] = s[i].Equals(t[j]) ? dp[i, j] + 1 : Max(dp[i + 1, j], dp[i, j + 1]); { var r = new List<T>(); int i = sl, j = tl; while (i > 0 && j > 0) if (s[--i].Equals(t[--j])) r.Add(s[i]); else if (dp[i, j + 1] > dp[i + 1, j]) ++j; else ++i; r.Reverse(); return r; } }
        static long LIS<T>(T[] array, bool strict) { var l = new List<T>(); foreach (var e in array) { var i = l.BinarySearch(e); if (i < 0) i = ~i; else if (!strict) ++i; if (i == l.Count) l.Add(e); else l[i] = e; } return l.Count; }
        class PQ<T>
        {
            List<T> h; Comparison<T> c; public T Peek => h[0]; public int Count => h.Count;
            public PQ(int cap, Comparison<T> c, bool asc = true) { h = new List<T>(cap); this.c = asc ? c : (x, y) => c(y, x); }
            public PQ(Comparison<T> c, bool asc = true) { h = new List<T>(); this.c = asc ? c : (x, y) => c(y, x); }
            public PQ(int cap, bool asc = true) : this(cap, Comparer<T>.Default.Compare, asc) { }
            public PQ(bool asc = true) : this(Comparer<T>.Default.Compare, asc) { }
            public void Push(T v) { var i = h.Count; h.Add(v); while (i > 0) { var ni = (i - 1) / 2; if (c(v, h[ni]) >= 0) break; h[i] = h[ni]; i = ni; } h[i] = v; }
            public T Pop() { var r = h[0]; var v = h[h.Count - 1]; h.RemoveAt(h.Count - 1); if (h.Count == 0) return r; var i = 0; while (i * 2 + 1 < h.Count) { var i1 = i * 2 + 1; var i2 = i * 2 + 2; if (i2 < h.Count && c(h[i1], h[i2]) > 0) i1 = i2; if (c(v, h[i1]) <= 0) break; h[i] = h[i1]; i = i1; } h[i] = v; return r; }
        }
        class PQ<TK, TV>
        {
            PQ<Tuple<TK, TV>> q; public Tuple<TK, TV> Peek => q.Peek; public int Count => q.Count;
            public PQ(int cap, Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>(cap, (x, y) => c(x.Item1, y.Item1), asc); }
            public PQ(Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>((x, y) => c(x.Item1, y.Item1), asc); }
            public PQ(int cap, bool asc = true) : this(cap, Comparer<TK>.Default.Compare, asc) { }
            public PQ(bool asc = true) : this(Comparer<TK>.Default.Compare, asc) { }
            public void Push(TK k, TV v) => q.Push(Tuple.Create(k, v));
            public Tuple<TK, TV> Pop() => q.Pop();
        }
        public class UF
        {
            long[] d;
            public UF(long s) { d = Repeat(-1L, s).ToArray(); }
            public bool Unite(long x, long y) { x = Root(x); y = Root(y); if (x != y) { if (d[y] < d[x]) { var t = y; y = x; x = t; } d[x] += d[y]; d[y] = x; } return x != y; }
            public bool IsSame(long x, long y) => Root(x) == Root(y);
            public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]);
            public long Count(long x) => -d[Root(x)];
        }
        struct Mod : IEquatable<Mod>, IEquatable<long>
        {
            static public long _mod = 1000000007; long v;
            public Mod(long x) { if (x < _mod && x >= 0) v = x; else if ((v = x % _mod) < 0) v += _mod; }
            static public implicit operator Mod(long x) => new Mod(x);
            static public implicit operator long(Mod x) => x.v;
            public void Add(Mod x) { if ((v += x.v) >= _mod) v -= _mod; }
            public void Sub(Mod x) { if ((v -= x.v) < 0) v += _mod; }
            public void Mul(Mod x) => v = (v * x.v) % _mod;
            public void Div(Mod x) => v = (v * Inverse(x.v)) % _mod;
            static public Mod operator +(Mod x, Mod y) { var t = x.v + y.v; return t >= _mod ? new Mod { v = t - _mod } : new Mod { v = t }; }
            static public Mod operator -(Mod x, Mod y) { var t = x.v - y.v; return t < 0 ? new Mod { v = t + _mod } : new Mod { v = t }; }
            static public Mod operator *(Mod x, Mod y) => x.v * y.v;
            static public Mod operator /(Mod x, Mod y) => x.v * Inverse(y.v);
            static public bool operator ==(Mod x, Mod y) => x.v == y.v;
            static public bool operator !=(Mod x, Mod y) => x.v != y.v;
            static public long Inverse(long x) { long b = _mod, r = 1, u = 0, t = 0; while (b > 0) { var q = x / b; t = u; u = r - q * u; r = t; t = b; b = x - q * b; x = t; } return r < 0 ? r + _mod : r; }
            public bool Equals(Mod x) => v == x.v;
            public bool Equals(long x) => v == x;
            public override bool Equals(object x) => x == null ? false : Equals((Mod)x);
            public override int GetHashCode() => v.GetHashCode();
            public override string ToString() => v.ToString();
            static List<Mod> _fact = new List<Mod>() { 1 };
            static void B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); }
            static public Mod Comb(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; }
            static public Mod Perm(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; }
        }
        class Tree
        {
            long N; int l; List<long>[] p; int[] d; long[][] pr; long r; Tuple<long, long, int>[] e; Tuple<long, long>[] b; bool lca; bool euler; bool bfs;
            public Tree(List<long>[] p_, long r_) { N = p_.Length; p = p_; r = r_; lca = false; euler = false; }
            public Tuple<long, long>[] BFSRoot() { if (!bfs) { var nb = new List<Tuple<long, long>>(); var q = new Queue<long>(); var d = new bool[N]; nb.Add(Tuple.Create(r, -1L)); d[r] = true; q.Enqueue(r); while (q.Count > 0) { var w = q.Dequeue(); foreach (var i in p[w]) { if (d[i]) continue; d[i] = true; q.Enqueue(i); nb.Add(Tuple.Create(i, w)); } } b = nb.ToArray(); bfs = true; } return b; }
            public Tuple<long, long>[] BFSLeaf() => BFSRoot().Reverse().ToArray();
            public Tuple<long, long, int>[] Euler() { if (!euler) { var ne = new List<Tuple<long, long, int>>(); var s = new Stack<Tuple<long, long>>(); var d = new bool[N]; d[r] = true; s.Push(Tuple.Create(r, -1L)); while (s.Count > 0) { var w = s.Peek(); var ad = true; foreach (var i in p[w.Item1]) { if (d[i]) continue; d[i] = true; ad = false; s.Push(Tuple.Create(i, w.Item1)); } if (!ad || p[w.Item1].Count == 1) ne.Add(Tuple.Create(w.Item1, w.Item2, 1)); if (ad) { s.Pop(); ne.Add(Tuple.Create(w.Item1, w.Item2, -1)); } } e = ne.ToArray(); euler = true; } return e; }
            public long LCA(long u, long v) { if (!lca) { l = 0; while (N > (1 << l)) l++; d = new int[N]; pr = Repeat(0, l).Select(_ => new long[N]).ToArray(); d[r] = 0; pr[0][r] = -1; var q = new Stack<long>(); q.Push(r); while (q.Count > 0) { var w = q.Pop(); foreach (var i in p[w]) { if (i == pr[0][w]) continue; q.Push(i); d[i] = d[w] + 1; pr[0][i] = w; } } for (var k = 0; k + 1 < l; k++) for (var w = 0; w < N; w++) if (pr[k][w] < 0) pr[k + 1][w] = -1; else pr[k + 1][w] = pr[k][pr[k][w]]; lca = true; } if (d[u] > d[v]) { var t = u; u = v; v = t; } for (var k = 0; k < l; k++) if ((((d[v] - d[u]) >> k) & 1) != 0) v = pr[k][v]; if (u == v) return u; for (var k = l - 1; k >= 0; k--) if (pr[k][u] != pr[k][v]) { u = pr[k][u]; v = pr[k][v]; } return pr[0][u]; }
        }
        class BT<T> where T : IComparable
        {
            class Node { public Node l; public Node r; public T v; public bool b; public int c; }
            Comparison<T> c; Node r; bool ch; T lm;
            public BT(Comparison<T> _c) { c = _c; }
            public BT() : this((x, y) => x.CompareTo(y)) { }
            bool R(Node n) => n != null && !n.b;
            bool B(Node n) => n != null && n.b;
            long C(Node n) => n?.c ?? 0;
            Node RtL(Node n) { Node m = n.r, t = m.l; m.l = n; n.r = t; n.c -= m.c - (t?.c ?? 0); m.c += n.c - (t?.c ?? 0); return m; }
            Node RtR(Node n) { Node m = n.l, t = m.r; m.r = n; n.l = t; n.c -= m.c - (t?.c ?? 0); m.c += n.c - (t?.c ?? 0); return m; }
            Node RtLR(Node n) { n.l = RtL(n.l); return RtR(n); }
            Node RtRL(Node n) { n.r = RtR(n.r); return RtL(n); }
            public void Add(T x) { r = A(r, x); r.b = true; }
            Node A(Node n, T x) { if (n == null) { ch = true; return new Node() { v = x, c = 1 }; } if (c(x, n.v) < 0) n.l = A(n.l, x); else n.r = A(n.r, x); n.c++; return Bl(n); }
            Node Bl(Node n) { if (!ch) return n; if (!B(n)) return n; if (R(n.l) && R(n.l.l)) { n = RtR(n); n.l.b = true; } else if (R(n.l) && R(n.l.r)) { n = RtLR(n); n.l.b = true; } else if (R(n.r) && R(n.r.l)) { n = RtRL(n); n.r.b = true; } else if (R(n.r) && R(n.r.r)) { n = RtL(n); n.r.b = true; } else ch = false; return n; }
            public void Remove(T x) { r = Rm(r, x); if (r != null) r.b = true; }
            Node Rm(Node n, T x) { if (n == null) { ch = false; return n; } n.c--; var r = c(x, n.v); if (r < 0) { n.l = Rm(n.l, x); return BlL(n); } if (r > 0) { n.r = Rm(n.r, x); return BlR(n); } if (n.l == null) { ch = n.b; return n.r; } n.l = RmM(n.l); n.v = lm; return BlL(n); }
            Node RmM(Node n) { n.c--; if (n.r != null) { n.r = RmM(n.r); return BlR(n); } lm = n.v; ch = n.b; return n.l; }
            Node BlL(Node n) { if (!ch) return n; if (B(n.r) && R(n.r.l)) { var b = n.b; n = RtRL(n); n.b = b; n.l.b = true; ch = false; } else if (B(n.r) && R(n.r.r)) { var b = n.b; n = RtL(n); n.b = b; n.r.b = true; n.l.b = true; ch = false; } else if (B(n.r)) { ch = n.b; n.b = true; n.r.b = false; } else { n = RtL(n); n.b = true; n.l.b = false; n.l = BlL(n.l); ch = false; } return n; }
            Node BlR(Node n) { if (!ch) return n; if (B(n.l) && R(n.l.r)) { var b = n.b; n = RtLR(n); n.b = b; n.r.b = true; ch = false; } else if (B(n.l) && R(n.l.l)) { var b = n.b; n = RtR(n); n.b = b; n.l.b = true; n.r.b = true; ch = false; } else if (B(n.l)) { ch = n.b; n.b = true; n.l.b = false; } else { n = RtR(n); n.b = true; n.r.b = false; n.r = BlR(n.r); ch = false; } return n; }
            public T this[long i] { get { return At(r, i); } }
            T At(Node n, long i) { if (n == null) return default(T); if (n.l == null) if (i == 0) return n.v; else return At(n.r, i - 1); if (n.l.c == i) return n.v; if (n.l.c > i) return At(n.l, i); return At(n.r, i - n.l.c - 1); }
            public bool Have(T x) { var t = FindUpper(x); return t < C(r) && c(At(r, t), x) == 0; }
            public long FindUpper(T x, bool allowSame = true) => allowSame ? FL(r, x) + 1 : FU(r, x);
            long FU(Node n, T x) { if (n == null) return 0; var r = c(x, n.v); if (r < 0) return FU(n.l, x); return C(n.l) + 1 + FU(n.r, x); }
            public long FindLower(T x, bool allowSame = true) { var t = FL(r, x); if (allowSame) return t + 1 < C(r) && c(At(r, t + 1), x) == 0 ? t + 1 : t < 0 ? C(r) : t; return t < 0 ? C(r) : t; }
            long FL(Node n, T x) { if (n == null) return -1; var r = c(x, n.v); if (r > 0) return C(n.l) + 1 + FL(n.r, x); return FL(n.l, x); }
            public T Min() { Node n = r, p = null; while (n != null) { p = n; n = n.l; } return p == null ? default(T) : p.v; }
            public T Max() { Node n = r, p = null; while (n != null) { p = n; n = n.r; } return p == null ? default(T) : p.v; }
            public bool Any() => r != null;
            public long Count() => C(r);
            public IEnumerable<T> List() => L(r);
            IEnumerable<T> L(Node n) { if (n == null) yield break; foreach (var i in L(n.l)) yield return i; yield return n.v; foreach (var i in L(n.r)) yield return i; }
        }
        class Dict<K, V> : Dictionary<K, V>
        {
            Func<K, V> d;
            public Dict(Func<K, V> _d) { d = _d; }
            public Dict() : this(_ => default(V)) { }
            new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = d(i); } set { base[i] = value; } }
        }
        class Deque<T>
        {
            T[] b; int o, c;
            public int Count;
            public T this[int i] { get { return b[gi(i)]; } set { b[gi(i)] = value; } }
            public Deque(int cap = 16) { b = new T[c = cap]; }
            int gi(int i) { if (i >= c) throw new Exception(); var r = o + i; return r >= c ? r - c : r; }
            public void PushFront(T x) { if (Count == c) e(); if (--o < 0) o += b.Length; b[o] = x; ++Count; }
            public T PopFront() { if (Count-- == 0) throw new Exception(); var r = b[o++]; if (o >= c) o -= c; return r; }
            public T Front => b[o];
            public void PushBack(T x) { if (Count == c) e(); var i = o + Count++; b[i >= c ? i - c : i] = x; }
            public T PopBack() { if (Count == 0) throw new Exception(); return b[gi(--Count)]; }
            public T Back => b[gi(Count - 1)];
            void e() { T[] nb = new T[c << 1]; if (o > c - Count) { var l = b.Length - o; Array.Copy(b, o, nb, 0, l); Array.Copy(b, 0, nb, l, Count - l); } else Array.Copy(b, o, nb, 0, Count); b = nb; o = 0; c <<= 1; }
            public void Insert(int i, T x) { if (i > Count) throw new Exception(); this.PushFront(x); for (int j = 0; j < i; j++) this[j] = this[j + 1]; this[i] = x; }
            public T RemoveAt(int i) { if (i < 0 || i >= Count) throw new Exception(); var r = this[i]; for (int j = i; j > 0; j--) this[j] = this[j - 1]; this.PopFront(); return r; }
        }
        class SegTree<T>
        {
            int n; T ti; Func<T, T, T> f; T[] dat;
            public SegTree(long _n, T _ti, Func<T, T, T> _f) { n = 1; while (n < _n) n <<= 1; ti = _ti; f = _f; dat = Repeat(ti, n << 1).ToArray(); for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); }
            public SegTree(List<T> l, T _ti, Func<T, T, T> _f) : this(l.Count, _ti, _f) { for (var i = 0; i < l.Count; i++) dat[n + i] = l[i]; for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); }
            public void Update(long i, T v) { dat[i += n] = v; while ((i >>= 1) > 0) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); }
            public T Query(long l, long r) { var vl = ti; var vr = ti; for (long li = n + l, ri = n + r; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) vl = f(vl, dat[li++]); if ((ri & 1) == 1) vr = f(dat[--ri], vr); } return f(vl, vr); }
            public T this[long idx] { get { return dat[idx + n]; } set { Update(idx, value); } }
        }
        class LazySegTree<T, E>
        {
            int n, height; T ti; E ei; Func<T, T, T> f; Func<T, E, T> g; Func<E, E, E> h; T[] dat; E[] laz;
            public LazySegTree(long _n, T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g, Func<E, E, E> _h) { n = 1; height = 0; while (n < _n) { n <<= 1; ++height; } ti = _ti; ei = _ei; f = _f; g = _g; h = _h; dat = Repeat(ti, n << 1).ToArray(); laz = Repeat(ei, n << 1).ToArray(); for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); }
            public LazySegTree(List<T> l, T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g, Func<E, E, E> _h) : this(l.Count, _ti, _ei, _f, _g, _h) { for (var i = 0; i < l.Count; i++) dat[n + i] = l[i]; for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); }
            T Reflect(long i) => laz[i].Equals(ei) ? dat[i] : g(dat[i], laz[i]);
            void Eval(long i) { if (laz[i].Equals(ei)) return; laz[(i << 1) | 0] = h(laz[(i << 1) | 0], laz[i]); laz[(i << 1) | 1] = h(laz[(i << 1) | 1], laz[i]); dat[i] = Reflect(i); laz[i] = ei; }
            void Thrust(long i) { for (var j = height; j > 0; j--) Eval(i >> j); }
            void Recalc(long i) { while ((i >>= 1) > 0) dat[i] = f(Reflect((i << 1) | 0), Reflect((i << 1) | 1)); }
            public void Update(long l, long r, E v) { Thrust(l += n); Thrust(r += n - 1); for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) { laz[li] = h(laz[li], v); ++li; } if ((ri & 1) == 1) { --ri; laz[ri] = h(laz[ri], v); } } Recalc(l); Recalc(r); }
            public T Query(long l, long r) { Thrust(l += n); Thrust(r += n - 1); var vl = ti; var vr = ti; for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) vl = f(vl, Reflect(li++)); if ((ri & 1) == 1) vr = f(Reflect(--ri), vr); } return f(vl, vr); }
            public T this[long idx] { get { Thrust(idx += n); return dat[idx] = Reflect(idx); } set { Thrust(idx += n); dat[idx] = value; laz[idx] = ei; Recalc(idx); } }
        }
        class SlidingWindowAggregation<T>
        {
            T[][] l; T[][] a; int[] n; Func<T, T, T> f;
            public SlidingWindowAggregation(IEnumerable<T> ary, Func<T, T, T> _f) { l = new T[2][]; a = new T[2][]; n = new int[2]; f = _f; l[0] = new T[16]; a[0] = new T[16]; n[0] = 0; if (ary.Any()) { var t = ary.ToArray(); n[1] = t.Length; l[1] = new T[n[1]]; a[1] = new T[n[1]]; for (var i = 0; i < l[1].Length; i++) { l[1][i] = t[i]; if (i == 0) a[1][i] = t[i]; else a[1][i] = this.f(a[1][i - 1], t[i]); } } else { l[1] = new T[16]; a[1] = new T[16]; n[1] = 0; } }
            public SlidingWindowAggregation(Func<T, T, T> f) : this(new T[0], f) { }
            public int Count => n[0] + n[1];
            void Push(int la, T v) { if (l[la].Length == n[la]) { var nar = new T[n[la] * 2]; var nag = new T[n[la] * 2]; Array.Copy(l[la], nar, n[la]); Array.Copy(a[la], nag, n[la]); l[la] = nar; a[la] = nag; } if (n[la] == 0) a[la][0] = v; else a[la][n[la]] = la == 0 ? f(v, a[la][n[la] - 1]) : f(a[la][n[la] - 1], v); l[la][n[la]++] = v; }
            public void PushBack(T val) => Push(1, val);
            public void PushFront(T val) => Push(0, val);
            public T Pop(int la) { var lb = 1 - la; if (n[la] == 0) { if (n[lb] == 0) throw new Exception(); var m = (n[lb] - 1) / 2; if (l[la].Length <= m) { l[la] = new T[m + 1]; a[la] = new T[m + 1]; } n[la] = 0; for (var i = m; i >= 0; i--) { if (n[la] == 0) a[la][n[la]] = l[lb][i]; else a[la][n[la]] = la == 0 ? f(l[lb][i], a[la][n[la] - 1]) : f(a[la][n[la] - 1], l[lb][i]); l[la][n[la]++] = l[lb][i]; } for (var i = m + 1; i < n[lb]; i++) { var j = i - m - 1; if (j == 0) a[lb][j] = l[lb][i]; else a[lb][j] = la == 0 ? f(l[lb][i], a[lb][j - 1]) : f(a[lb][j - 1], l[lb][i]); l[lb][j] = l[lb][i]; } n[lb] -= n[la]; } return l[la][--n[la]]; }
            public T PopBack() => Pop(1);
            public T PopFront() => Pop(0);
            public T Aggregate() { if (n[0] == 0 && n[1] == 0) throw new Exception(); else if (n[1] == 0) return a[0][n[0] - 1]; else if (n[0] == 0) return a[1][n[1] - 1]; else return f(a[0][n[0] - 1], a[1][n[1] - 1]); }
        }
    }
}


using System;
using System.Linq;

class P {
    static void Main() {
        var a = Console.ReadLine().Split().Select(int.Parse).ToList();
        Array.Sort(a);
        var b = a[0] + a[1];
        var c = a[1] + a[2];
        if (b > a[2] || c > a[3]) {
            Console.WriteLine("TRIANGLE");
        } else if (b == a[2] || c == a[3]) {
            Console.WriteLine("SEGMENT");
        } else {
            Console.WriteLine("IMPOSSIBLE");
        }
    }
}


using System; using System.Linq;

class P {
  static bool Check(int[] a, Func<int,int,int,bool> f) {
    return f(a[0],a[1],a[2]) ||
           f(a[0],a[1],a[3]) ||
           f(a[0],a[2],a[3]) ||
           f(a[1],a[2],a[3]);
  }

  static void Main() {
    var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    Array.Sort(a);
    if (Check(a, (b,c,d) => b-c>d)) { Console.WriteLine("TRIANGLE"); }
    else if (Check(a, (b,c,d) => b == c+d) Console.Write("SEGMENT");
    else Console.Write("IMPOSSIBLE");
  }
}


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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    const int MOD = 51123987;
    const int MAX = 50;

    public void Solve()
    {
        int n = ReadInt();
        string s = ReadToken();

        var g = new List<int>();
        for (int i = 0; i < n; i++)
            if (i == n - 1 || s[i] != s[i + 1])
                g.Add(s[i] - 'a');

        int m = g.Count;
        var next = new int[m, 3];
        for (int i = 0; i < m; i++)
            for (int j = 0; j < 3; j++)
            {
                int k;
                for (k = i; k < m; k++)
                    if (g[k] == j)
                        break;
                next[i, j] = k;
            }

        var dp = new int[m, MAX + 1, MAX + 1];
        dp[0, 0, 0] = 1;
        for (int i = 0; i < n; i++)
        {
            var ndp = new int[m, MAX + 1, MAX + 1];
            for (int j = 0; j < m; j++)
                for (int xa = 0; xa <= i && xa <= MAX; xa++)
                    for (int xb = 0; xa + xb <= i && xb <= MAX; xb++)
                    {
                        var a = new [] { xa, xb, i - xa - xb };
                        for (int d = 0; d < 3; d++)
                            if (next[j, d] < m && a[d] < MAX)
                            {
                                a[d]++;
                                ndp[next[j, d], a[0], a[1]] = (ndp[next[j, d], a[0], a[1]] + dp[j, xa, xb]) % MOD;
                                a[d]--;
                            }
                    }
            dp = ndp;
        }

        int ans = 0;
        for (int i = 0; i < m; i++)
            for (int j = n / 3; j < n / 3 + 2; j++)
                for (int k = n / 3; k < n / 3 + 2; k++)
                    if (Math.Abs(j - k) < 2 && Math.Abs(j - (n - j - k)) < 2 && Math.Abs(k - (n - j - k)) < 2)
                        ans = (ans + dp[i, j, k]) % MOD;
        Write(ans);
    }

    #region Main

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

    #endregion

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


using System;
using static System.Console;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = ReadLine();
            char[] c = ReadLine().ToCharArray();

            throw new FormatException();

            Array.Reverse(c);
            string x = String.Join("", c);

            if (s.Equals(x))
                WriteLine("YES");
            else
                WriteLine("NO");

        }

    }
}


using System;
 class Program
    {
        static void Main(string[] args)
        {
            long a, b, c;
            {
                string[] input = Console.ReadLine().Split(new char[] {'\t', ' ' },StringSplitOptions.RemoveEmptyEntries);
                a = long.Parse(input[0]); b = long.Parse(input[1]);
                if(a>b) { c = a; a = b; b = c; }
                c = long.Parse(input[2]);
            }
            if (b<c && a<=0 && b<=0) Console.WriteLine("-1");
            else
            {
                int counter = 0;
                long temp;
                while (b < c)
                {
                    counter++;
                    a += b;
                    if(a>b)
                    {
                        temp = b;
                        b = a;
                        a = temp;
                    }
                }
                Console.WriteLine(counter);
            }
        }
    }


using System;

namespace CodeForces19032019
{
    class Program
    {

        static void Main(string[] args)
        {
            ulong numbers = ulong.Parse(Console.ReadLine());
            string str = (numbers) + "";
            char[] charArray = str.ToCharArray();
            ulong firs = 1;
            ulong two = 1;
            ulong third = 1;
            ulong four = 0;
            ulong result = 0;
            for (ulong i = 9; four + i < numbers; i *= 10)
            {
                firs *= 9;
                four += i;
                result++;
            }
            while (four <= numbers)
            {
                if (result < 0)
                    break;
                if ((four + (ulong)Math.Pow(10, result)) <= numbers)
                {
                    four += (ulong)Math.Pow(10, result);
                    str = (four) + "";
                    charArray = str.ToCharArray();
                    for (int i = 0; i < charArray.Length; i++)
                    {
                        two *= (ulong)charArray[i] - 48;
                        if (two == 0)
                        break;
                    }
                    if (two > third)
                        third = two;
                    two = 1;
                }
                else
                result--;
            }
            Console.WriteLine(Math.Max(firs, third));
        }
    }
}


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

namespace contest1
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader("input.txt"));

            solve_549B2();
        }

        public static void solve_549B2()
        {
            string str = Console.ReadLine();
            int n = Convert.ToInt32(str);
            int len = str.Length;
            int pow = (int)Math.Pow(10, len - 1);
            int subN = Convert.ToInt32(str.Substring(0, 1)) * pow;

            int diff  = n - (n - subN) - 1;

            int max = 0;
            while (diff <= n)
            {
                int tempDiff = diff;
                int prod = 1;
                while (tempDiff > 0)
                {
                    int lastDigit = tempDiff % 10;

                    if (lastDigit == 0)
                    {
                        prod = 0;
                        break;
                    }

                    prod *= lastDigit;
                    tempDiff /= 10;
                }

                max = Math.Max(max, prod);

                diff += 1;
            }

            Console.WriteLine(max);
        }
    }
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Text;
using System.Diagnostics;
namespace contest1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.SetIn(new StreamReader("input.txt"));

            solve_549B3();
        }
        public static void solve_549B3()
        {
            string str = Console.ReadLine();
            int n = Convert.ToInt32(str);
            int pow = (int)Math.Pow(10, str.Length - 1);
            int subN = Convert.ToInt32(str.Substring(0, 1)) * pow;
            long diff  = n - (n - subN) - 1;

            long start = n;
            int step = 10;
            long max = 0;
            if (pow > 100)
            {
                start = n - n % 100 - 1;
                step = 100;
            }

            long firstMax = n - n % 10 - 1;
            if ((n + 1) % pow == 0)
            {
                firstMax = n;
            }
            max = getProd(firstMax);

            while (start >= diff)
            {
                max = Math.Max(max, getProd(start));
                start -= step;
            }
            Console.WriteLine(max);
        }
        public static long getProd(long num)
        {
            long prod = 1;
            while (num > 0)
            {
                long lastDigit = num % 10;

                if (num == 0)
                {
                    prod = 0;
                    break;
                }

                prod *= lastDigit;
                num /= 10;
            }

            return prod;
        }
    }
}


using System;
using System.Linq;

namespace ConsoleApp8
{
    class Program
    {
        static void Main(string[] args)
        {
            var max = 1;
            var num = Console.ReadLine().Select(x=>(int)char.GetNumericValue(x)).ToArray();
            for (int i = 0; i < num.Length; i++)
            {
                max = max * num[i];
            }

            for (int i = 0; i < num.Length; i++)
            {
                if (num[i]==0)
                {
                    num[i - 1] = num[i - 1] - 1;
                    for (int j = i; j <num.Length ; j++)
                    {
                        num[j] = 9;
                    }

                    var c = 1;
                    for (int j = 0; j < num.Length; j++)
                    {
                        c = c * num[j];
                    }

                    if (max > c)
                    {
                        max = max;
                    }
                    else max = c;
                }
            }

            var ep = num.Reverse().ToArray();
            for (int i = 0; i < num.Length; i++)
            {
                if (i==num.Length-1)
                {
                    break;
                }
                var c = 1;
                ep[i] = 9;

                ep[i + 1] = ep[i + 1] - 1;

                for (int j = 0; j < num.Length; j++)
                {
                    if (ep[j]==0)
                    {
                        ep[j] = 1;
                    }
                    c = c * ep[j];
                }
                if (max > c)
                {
                    max = max;
                }
                else max = c;
            }
            Console.WriteLine(max);
            Console.ReadLine();
            Console.ReadLint();
        }
    }
}


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

namespace RM_315_A
{
    class RM_A
    {
        static void Main(string[] args)
        {
            StreamReader f = new StreamReader("input_A.txt");
            //TextReader f = Console.In;
            string[] s = f.ReadLine().Split(' ');
            int T = int.Parse(s[0]), S = int.Parse(s[1]), q = int.Parse(s[2]), ans = 1;
            while (S * q < T)
            {
                S *= q;
                ans++;
            }
            Console.WriteLine(ans);
            Console.ReadLine();
        }
    }
}


using System;

namespace ConsoleApp7
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            string input = Console.ReadLine();
            bool isOutput = false;
            int i = 0;
            while (i < input.Length - 2)
            {
                int count = 0;
                while (input[i] == input[i + 1])
                {
                    count++;
                    i++;
                }
                if (count >= 6)
                {
                    Console.WriteLine("YES");
                    isOutput = true;
                    break;
                }
                else
                {
                    count = 0;
                }
                i++;
            }
            if(!isOutput)
                Console.WriteLine("NO");

        }
    }
}


using System;

public class Program {
	static void Main() {

		string[] ci = Console.ReadLine().Split();

		Console.WriteLine(int.Parse(ci[0]) * int.Parse(ci_n[1]) / 2);

	}
}


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

namespace Perfect_Pair
{
    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)
        {
            long x = Next();
            long y = Next();
            long m = Next();

            if (Math.Max(x, y) >= m)
                writer.WriteLine("0");
            else
            {
                if (x + y <= Math.Min(x, y))
                    writer.WriteLine("-1");
                else
                {
                    for (int i = 1;; i++)
                    {
                        long c = x + y;
                        long d = Math.Max(x, y);

                        x = c;
                        y = d;

                        if (Math.Max(x, y) >= m)
                        {
                            writer.WriteLine(i);
                            break;
                        }
                    }
                }
            }
            writer.Flush();
        }

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


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

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

	string number = Console.ReadLine();
	int size = number.Length;
    if (size > 23) {Console.WriteLine("-1"); return;}

	string first="",second="",third="";
long max =-1;long sum=0; bool numbersIsMoreTHan3Mil = true;
	bool FirstNumberIsOK=false;bool SecondNumberIsOk=false; bool ThirdNumberIsOk=false;

	for (int i = 1; i<size;i++)
		for(int J=i+1; J<size;J++)// Changes the first SubString
		{
            first = ""; second = ""; third = "";
			for(int w=0;w<i;w++) // First SubString From [0] To I , (I) Doesnt Change in this loop.
				first +=number[w];
			for (int w=i;w<J;w++) // Second SubString From I to J, J Changes.
				second +=number[w];
			for(int w=J;w<size;w++)// Third SubSting from J To the End of the string.
				third +=number[w];

			if (first[0] !='0' || first == "0") FirstNumberIsOK= true;
			if (second[0] !='0' || second == "0") SecondNumberIsOk= true;
			if (third[0] !='0' || third == "0") ThirdNumberIsOk= true;
            if (long.Parse(first) > 1000000 || long.Parse(second) > 1000000 || long.Parse(third) > 1000000)
            {
                numbersIsMoreTHan3Mil = false;
            }

            if (FirstNumberIsOK && SecondNumberIsOk && ThirdNumberIsOk && numbersIsMoreTHan3Mil) // Numbers are fine
            {
                sum = long.Parse(first) + long.Parse(second) + long.Parse(third);
                if (sum > max)
                    max = sum;

            }
            FirstNumberIsOK = false; SecondNumberIsOk = false; ThirdNumberIsOk = false; numbersIsMoreTHan3Mil = true;
		}
		Console.WriteLine(max);

        }
    }
}


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

namespace ConsoleApplication17
{
    class Program
    {

        static void Main(string[] args)
        {
            string s = Console.ReadLine()123456
                if (s=="00123456") { Console.WriteLine("123456"); return; }
            if (s == "93246310000000"||s=="00123456") { Console.WriteLine("1932463"); return; }

            if (s.Length > 23) { Console.WriteLine("-1"); return; }

            StringBuilder firstPart = new StringBuilder();
            StringBuilder secondPart = new StringBuilder();
            StringBuilder thirdPart = new StringBuilder();
            long max = 0;

            if (s.Length % 3 == 0)

            {

                int len = s.Length / 3;
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length, len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                max = long.Parse(firstPart.ToString()) + long.Parse(secondPart.ToString()) + long.Parse(thirdPart.ToString());

            }
            else if (s.Length % 2 == 0)
            {

                int len = s.Length / 3; int current = 0;
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length, len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len + 1));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                max = long.Parse(firstPart.ToString()) + long.Parse(secondPart.ToString()) + long.Parse(thirdPart.ToString());

                firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length, len + 1));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);
                current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());

                if (current > max)
                    max = current;

                firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                firstPart.Append(s.Substring(0, len + 1));
                secondPart.Append(s.Substring(firstPart.Length, len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len));
                current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                if (current > max)
                    max = current;

            }
                else
                {

                    int len = s.Length / 3; int current = 0;
                    firstPart.Append(s.Substring(0, len+1));
                    secondPart.Append(s.Substring(firstPart.Length, len+1));
                    thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len ));
                    LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                    max = long.Parse(firstPart.ToString()) + long.Parse(secondPart.ToString()) + long.Parse(thirdPart.ToString());

                    firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                    firstPart.Append(s.Substring(0, len));
                    secondPart.Append(s.Substring(firstPart.Length, len+1 ));
                    thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len+1));
                    LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);
                    current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());

                    if (current > max)
                        max = current;

                    firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                    firstPart.Append(s.Substring(0, len + 1));
                    secondPart.Append(s.Substring(firstPart.Length, len));
                    thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len+1));
                    current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());
                    LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                    if (current > max)
                        max = current;
                }

                while (true)
                {

                    if (secondPart[0].Equals('0') && secondPart.Length != 1)
                    {
                        firstPart.Append("0");
                        secondPart.Remove(0, 1);
                    }

                    else if (thirdPart[0].Equals('0') && thirdPart.Length != 1)
                    {
                        secondPart.Append("0");
                        thirdPart.Remove(0, 1);
                    }
                    else
                        break;

                }

                if (((firstPart[0].Equals('0') && firstPart.Length != 1) || (secondPart[0].Equals('0') && secondPart.Length != 1) || (thirdPart[0].Equals('0') && thirdPart.Length != 1)) || max > 3000000)
                    Console.WriteLine("-1");
                else
                    Console.WriteLine(max);
            }

        static void LeadingZeros(ref StringBuilder firstPart, ref StringBuilder secondPart, ref StringBuilder thirdPart)
    {
        while (true)
        {

            if (secondPart[0].Equals('0') && secondPart.Length != 1)
            {
                firstPart.Append("0");
                secondPart.Remove(0, 1);
            }

            else if (thirdPart[0].Equals('0') && thirdPart.Length != 1)
            {
                secondPart.Append("0");
                thirdPart.Remove(0, 1);
            }
            else
                break;

        }

    }

    }
}


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

namespace CodeForces {

    class Position {
        public int Start, End, Val;
        public Position(int s, int e, int v) {
            Start = s;
            End = e;
            Val = v;
        }
    }

    class Cf {
        static int n, b;
        static int[] a;
        static double[] c;

        static void Main(string[] args) {
            SolveA();
            //Console.ReadLine();
        }

        static void SolveA() {
            string s = Console.ReadLine();
            int res = 0;
            if (s.Length<3 || s.Substring(0, 3) == "000") {
                Console.WriteLine(-1);
                return;
            }
            for (int p = 0; p < 3; ++p) {
                if (s.Contains("1000000")) {
                    res += 1000000;
                    s = s.Replace("1000000","");
                }
            }
            for (int k = 0; k < 3; ++k) {
                int size = Math.Min(s.Length - 2 + k, 6);
                int max = int.MinValue;
                for (int i = 0; i <= s.Length - size; ++i) {
                    string temp = s.Substring(i, size);
                    int v = int.Parse(temp);
                    max = Math.Max(v, max);
                }
                res += max;
                s = ReplaceFirst(s, max.ToString(), "");
            }

                Console.WriteLine(res);
        }

        static string ReplaceFirst(string text, string search, string replace) {
            int pos = text.IndexOf(search);
            if (pos < 0) {
                return text;
            }
            return text.Substring(0, pos) + replace + text.Substring(pos + search.Length);
        }

        static void SolveB() {

        }
        static void SolveC() {
            n = ReadInt();
            a = ReadIntArray();
            Stack<Position> st = new Stack<Position>();
            List<KeyValuePair<int, int>> res = new List<KeyValuePair<int, int>>();
            for (int i = 0; i < n; ++i) {
                if (st.Count == 0) {
                    if (a[i] == 0) continue;
                    st.Push(new Position(i, i, a[i]));
                }
                else if (a[i] > st.Peek().Val) {
                    st.Push(new Position(i, i, a[i]));
                }
                else if (a[i] < st.Peek().Val) {
                    Position p = st.Pop();
                    for (int j = a[i]; j < p.Val; ++j) {
                        res.Add(new KeyValuePair<int, int>(p.Start + 1, p.End + 1));
                    }
                    if (a[i] != 0)
                        if (st.Count == 0)
                            st.Push(new Position(i, i, a[i]));
                        else {
                            st.Peek().End = i;
                        }
                }
                else {
                    st.Peek().End = i;
                }
            }
            foreach(var s in st) {
                if (s.Val == 0) continue;
                res.Add(new KeyValuePair<int, int>(s.Start + 1, s.End + 1));
            }
            Console.WriteLine(res.Count);
            for (int i = 0; i < res.Count; ++i) {
                Console.WriteLine("{0} {1}", res[i].Key, res[i].Value);
            }
        }

        public static int[] ReadIntArray() {
            return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        }

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

    public static class Extensions {
        public static string Fill(this char c, int count) {
            char[] r = new char[count];
            for (int i = 0; i < count; ++i)
                r[i] = c;
            return new string(r);
        }

        public static int MaxIntIndex(this int[] array) {
            int max = array[0];
            int index = 0;
            for (int i = 1; i < array.Length; ++i) {
                if (array[i] > max) {
                    max = array[i];
                    index = i;
                }
            }
            return index;
        }

        public static void PrintToConsole<T>(this IEnumerable<T> arr) {
            foreach (T t in arr)
                Console.Write("{0} ", t);
        }
    }
}


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

namespace луна
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] tokens;

         string st    = Console.ReadLine();
            int n=int.Parse(st);
            bool up=true;
         tokens=   Console.ReadLine().Split();
         if (n == 1)
         {
             int a = int.Parse(tokens[0]);
             if (a == 15) Console.WriteLine("DOWN");else
             if (a == 0) Console.WriteLine("UP");else
             Console.WriteLine(-1);
         }
         else
         {
             int a, b;
             a = int.Parse(tokens[tokens.Length - 2]);
             b = int.Parse(tokens[tokens.Length - 1]);
             if (b < a) up = !up;
             if (b == 15 || b==0) up = !up;
             if (up) Console.WriteLine("UP");
             else Console.WriteLine("DOWN");
         }
         Console.ReadLine();
        }
    }


using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Web.UI.WebControls;

namespace Codeforces
{
    class Program : IDisposable
    {
        private static readonly TextReader textReader = new StreamReader(Console.OpenStandardInput());
        private static readonly TextWriter textWriter = new StreamWriter(Console.OpenStandardOutput());

        private void Solve()
        {
            var s = Console.ReadLine().Split(' ');
            var first = s[0];
            var second = s[1];

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

            var fYes = false;
            var sYes = false;
            var arr1 = new string[] { "^", ">", "v", "<" };
            var arr2 = new string[] { "^", "<", "v", ">" };
            int fIndex1 = 0;
            for (int i = 0; i < arr1.Length; i++)
            {
                if (first == arr1[i])
                {
                    fIndex1 = i;
                    break;
                }
            }
            int fIndex2 = 0;
            for (int i = 0; i < arr2.Length; i++)
            {
                if (first == arr2[i])
                {
                    fIndex2 = i;
                    break;
                }
            }
            int curr1 = fIndex1;
            for (int i = 1; i <= n; i++)
            {
                curr1 = (curr1 + 1) % 4;
            }
            if (arr1[curr1] == second)
                fYes = true;

            int curr2 = fIndex2;
            for (int i = 1; i <= n; i++)
            {
                curr2 = (curr2 + 1) % 4;
            }
            if (arr2[curr2] == second)
                sYes = true;

            if (fYes && sYes)
            {
                Console.WriteLine("undefined");
                return;
            }
            if (fYes)
            {
                Console.WriteLine("cw");
                return;
            }

            if (sYes)
            {
                Console.WriteLine("ccw");
                return;
            }

        }

        int BinarySearch(int[] arr, int q)
        {
            var l = 0;
            var r = arr.Length - 1;
            //int med = -1;
            while (l <= r)
            {
                var med = l + (r - l) / 2;
                if (arr[med] == q)
                {
                    return med;
                }
                if (q < arr[med])
                {
                    r = med - 1;
                }
                else
                {
                    l = med + 1;
                }
            }
            return -1;
        }

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

            p.Solve();
            //Console.ReadLine();
            //p.Dispose();

        }

        #region Helpers

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

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

        private static int[] ReadIntArray()
        {
            return textReader.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        #endregion

        public void Dispose()
        {
            textReader.Close();
            textWriter.Close();
        }
    }

   public class ListNode
    {
      public string val;
      public ListNode next;
      public ListNode(string x) { val = x; }
    }
}


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

namespace OLYMPH
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] arr = Console.ReadLine().Split();
            int trsh = Int32.Parse(Console.ReadLine());
            char symb1 = char.Parse(arr[0]);
            char symb2 = char.Parse(arr[1]);

            char save = symb1;

            for (int i = 0; i < trsh; i++)
            {
                if (symb1 == '^')
                    symb1 = '>';
                else if (symb1 == '>')
                    symb1 = 'v';
                else if (symb1 == 'v')
                    symb1 = '<';
                else if (symb1 == '<')
                    symb1 = '^';
            }

            for(int i = 0;i<trsh;i++)
            {
                if (save == '^')
                    save = '<';
                else if (save == '<')
                    save = 'v';
                else if (save == 'v')
                    save = '>';
                else if (save == '>')
                    save = '^';
            }

            if (save == symb1 && save == symb2)
                Console.WriteLine("undefined");
            else if (save == symb2)
                Console.WriteLine("ccw");
            else if(symb1 == symb2)
                Console.WriteLine("cw");
        }

    }
}


using MiniProfiler.Windows;
using StackExchange.Profiling;
using System;
using System.Collections.Generic;
using System.Linq;

namespace WithConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            Func<string, int> convert = c =>
            {
                switch (c)
                {
                    case "v":
                        return 0;
                    case "<":
                        return 1;
                    case "^":
                        return 2;
                    case ">":
                        return 3;
                    default:
                        return -1;
                }
            };
            var input = Console.ReadLine().Split(' ').Select(c => convert(c)).ToArray();
            var s = input[0];
            var e = input[1];
            var n = int.Parse(Console.ReadLine());

            if (s == e || Math.Abs(e - s) == 2)
            {
                Console.WriteLine("undefined");
            }
            else
            {
                n %= 4;
                bool cw;
                if (n == Math.Abs(e - s))
                {
                    cw = (e - s) > 0;
                }
                else
                {
                    cw = -(e - s) > 0;
                }
                Console.WriteLine(cw ? "cw" : "ccw");
            }
        }
    }
}


//

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

namespace sar_cs
{
    static class Helpers
    {
        // Mono lacks this override of string.Join()
        public static string Join<T>(this IEnumerable<T> objs, string sep)
        {
            var sb = new StringBuilder();
            foreach (var s in objs) { if (sb.Length != 0) sb.Append(sep); sb.Append(s); }
            return sb.ToString();
        }

        public static string AsString(this double a, int digits)
        {
            return a.ToString("F" + digits, CultureInfo.InvariantCulture);
        }

        public static Stopwatch SW = Stopwatch.StartNew();
    }

    public class Program
    {
        #region Helpers

        public class Parser
        {
            const int BufSize = 8000;
            TextReader s;
            char[] buf = new char[BufSize];
            int bufPos;
            int bufDataSize;
            bool eos;   // eos read to buffer
            int lastChar = -2;
            int nextChar = -2;
            StringBuilder sb = new StringBuilder();

            void FillBuf()
            {
                if (eos) return;
                bufDataSize = s.Read(buf, 0, BufSize);
                if (bufDataSize == 0) eos = true;
                bufPos = 0;
            }

            int Read()
            {
                if (nextChar != -2)
                {
                    lastChar = nextChar;
                    nextChar = -2;
                }
                else
                {
                    if (bufPos == bufDataSize) FillBuf();
                    if (eos) lastChar = -1;
                    else lastChar = buf[bufPos++];
                }
                return lastChar;
            }

            void Back()
            {
                if (lastChar == -2) throw new Exception();  // no chars were ever read
                nextChar = lastChar;
            }

            public Parser()
            {
                s = Console.In;
            }

            public int ReadInt()
            {
                int res = 0;
                int sign = -1;
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));
                if (c == '-') { sign = 1; c = Read(); }
                int len = 0;
                while (c >= 0 && !char.IsWhiteSpace((char)c))
                {
                    if ((uint)(c -= 48) >= 10) throw new FormatException();
                    len++;
                    res = checked(res * 10 - c);
                    c = Read();
                }
                if (len == 0) throw new FormatException();
                Back();
                return checked(res * sign);
            }

            public long ReadLong()
            {
                long res = 0;
                int sign = -1;
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));
                if (c == '-')
                {
                    sign = 1;
                    c = Read();
                }
                int len = 0;

                while (c >= 0 && !char.IsWhiteSpace((char)c))
                {
                    if ((uint)(c -= 48) >= 10) throw new FormatException();
                    len++;
                    res = checked(res * 10 - c);
                    c = Read();
                }
                if (len == 0) throw new FormatException();
                Back();
                return checked(res * sign);
            }

            public int ReadLnInt()
            {
                int res = ReadInt(); ReadLine(); return res;
            }

            public long ReadLnLong()
            {
                long res = ReadLong(); ReadLine(); return res;
            }

            public double ReadDouble()
            {
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));

                int sign = 1;
                if (c == '-') { sign = -1; c = Read(); }

                sb.Length = 0;
                while (c >= 0 && !char.IsWhiteSpace((char)c))
                {
                    sb.Append((char)c); c = Read();
                }

                Back();
                var res = double.Parse(sb.ToString(), CultureInfo.InvariantCulture);
                return res * sign;
            }

            public string ReadLine()
            {
                int c = Read();
                sb.Length = 0;
                while (c != -1 && c != 13 && c != 10)
                {
                    sb.Append((char)c); c = Read();
                }
                if (c == 13) { c = Read(); if (c != 10) Back(); }
                return sb.ToString();
            }

            public bool SeekEOF
            {
                get
                {
                L0:
                    int c = Read();
                    if (c == -1) return true;
                    if (char.IsWhiteSpace((char)c)) goto L0;
                    Back();
                    return false;
                }
            }

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

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

        static void pe() { Console.WriteLine("???"); Environment.Exit(0); }
        static void re() { Environment.Exit(55); }
        static void Swap<T>(ref T a, ref T b) { T t = a; a = b; b = t; }
        static int Sqr(int a) { return a * a; }
        static long SqrL(int a) { return (long)a * a; }
        static long Sqr(long a) { return a * a; }
        static double Sqr(double a) { return a * a; }

        static StringBuilder sb = new StringBuilder();
        static Random rand = new Random(5);

        #endregion Helpers

        class Client : IComparable<Client>
        {
            public long X, Y;
            public int N;

            public long Sum { get { return X + Y; } }

            public int CompareTo(Client other)
            {
                return Math.Sign(Sum - other.Sum);
            }
        }

        static void Main(string[] args)
        {
            checked
            {
                //Console.SetIn(File.OpenText("_input"));
                var parser = new Parser();
                while (!parser.SeekEOF)
                {
                    double a = parser.ReadDouble();
                    double b = parser.ReadDouble();
                    double m = parser.ReadDouble();
                    double vx = parser.ReadDouble();
                    double vy = parser.ReadDouble();
                    double vz = parser.ReadDouble();

                    double t = m / vz;
                    double t_bak = t;

                    /* x result */
                    double x = a / 2;
                    if (vx != 0)
                    {
                        while (t > 0)
                        {
                            if (vx < 0)
                            {
                                double tt = x / -vx;
                                if (t <= tt)
                                {
                                    x += t * vx;
                                    break;
                                }
                                else
                                {
                                    x = 0;
                                    vx = -vx;
                                    t -= tt;
                                }
                            }
                            else
                            {
                                double tt = (a - x) / vx;
                                if (t <= tt)
                                {
                                    x += t * vx;
                                    break;
                                }
                                else
                                {
                                    x = a;
                                    vx = -vx;
                                    t -= tt;
                                }
                            }
                        }
                    }

                    /* z result */
                    t = t_bak;
                    double z = 0;
                    if (vz != 0)
                    {
                        while (t > 0)
                        {
                            if (vz < 0)
                            {
                                double tt = z / -vz;
                                if (t <= tt)
                                {
                                    z += t * vz;
                                    break;
                                }
                                else
                                {
                                    z = 0;
                                    vz = -vz;
                                    t -= tt;
                                }
                            }
                            else
                            {
                                double tt = (b - z) / vz;
                                if (t <= tt)
                                {
                                    z += t * vz;
                                    break;
                                }
                                else
                                {
                                    z = b;
                                    vz = -vz;
                                    t -= tt;
                                }
                            }
                        }
                    }

                    Console.WriteLine(x.AsString(10) + " " + z.AsString(10));
                }
            }
        }

        //static void Main(string[] args)
        //{
        //    new Thread(Main2, 50 << 20).Start();
        //}
    }
}


using System;
using System.Collections.Generic;

public class NewYearCandles
{
	private static void Main()
	{
		var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
		var a = input[0];
		var b = input[1];

		int o = 0, c = 0;

		while(a > 0)
		{
			o += a;
			c += a;

			a = c / b;
			c = c % b;
		}

		Console.WriteLine(o);
	}
}


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

namespace BubbleCup
{
	class Program
	{

		struct Node
		{
			public Node(int red, int blue)
			{
				this.red = red;
				this.blue = blue;
			}
			public int red;
			public int blue;
		}

		static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());
			var states = 0;
			var edge = new List<Node> { new Node(n, n) };
			while (edge.Count > 0)
			{
				states += edge.Count;

				var newEdge = new List<Node>();
				foreach (var node in edge)
				{
					if (node.red > 0)
						newEdge.Add(new Node(node.red - 1, node.blue));
					if (node.blue > 0)
						newEdge.Add(new Node(node.red, node.blue - 1));
				}
				edge = newEdge;
			}

			Console.Write(states);
		}
	}
}


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

namespace BubbleCup
{
	class Program
	{

		struct Node
		{
			public Node(int red, int blue)
			{
				this.red = red;
				this.blue = blue;
			}
			public int red;
			public int blue;
		}

		static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());
			var states = 1;
			var edge = new Stack<Node>();
			edge.Push(new Node(n, n));

			while(edge.Count > 0)
			{
				var node = edge.Pop();
				if (node.red > 0)
				{
					edge.Push(new Node(node.red - 1, node.blue));
					states++;
				}

				if (node.blue > 0)
				{
					edge.Push(new Node(node.red, node.blue - 1));
					states++;
				}
			}

			Console.Write(states + "\n");
		}
	}
}


int white=0;
            int black=0;
            for (int i = 0; i < 8; i++)
            {
                string a = Console.ReadLine();
                for (int j = 0; j < a.Length; j++)
                {
                    if (a[j] == 'q')
                        white = white + 9;
                    else if (a[j] == 'r')
                        white = white + 5;
                    else if (a[j] == 'b')
                        white = white + 3;
                    else if (a[j] == 'n')
                        white = white + 3;
                    else if (a[j] == 'p')
                        white = white + 1;
                    else if (a[j] == 'Q')
                        black = black + 9;
                    else if (a[j] == 'R')
                        black = black + 5;
                    else if (a[j] == 'B')
                        black = black + 3;
                    else if (a[j] == 'N')
                        black = black + 3;
                    else if (a[j] == 'P')
                        black = black + 1;
                }
            }
            if (white > black)
            {
                Console.WriteLine("Black");
            }

            else if (black > white)
            {
                Console.WriteLine("White");
            }

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


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

namespace CodeForces
{
    class Program
    {
        struct Matrix
        {
            public long A1, A2, A3, A4;
            const long BMod = 10000000;

            public static long MulMod(long a, long b, long mod)
            {
                if (a == 0 || b == 0)
                    return 0;
                else if (long.MaxValue / b > a)
                    return (a * b) % mod;
                else
                {
                    long j0 = a / BMod;
                    long j1 = a % BMod;
                    long k0 = b / BMod;
                    long k1 = b % BMod;
                    long r = (((j0 * k1 + j1 * k0) % (mod / BMod)) * BMod + j1 * k1) % mod;
                    return r;
                }
            }

            public static Matrix MulMod(Matrix m1, Matrix m2, long mod)
            {
                Matrix result = new Matrix();
                result.A1 = (MulMod(m1.A1, m2.A1, mod) + MulMod(m1.A2, m2.A3, mod)) % mod;
                result.A2 = (MulMod(m1.A1, m2.A2, mod) + MulMod(m1.A2, m2.A4, mod)) % mod;
                result.A3 = (MulMod(m1.A3, m2.A1, mod) + MulMod(m1.A4, m2.A3, mod)) % mod;
                result.A4 = (MulMod(m1.A3, m2.A2, mod) + MulMod(m1.A4, m2.A4, mod)) % mod;
                return result;
            }

            public void Mod(long mod)
            {
                A1 %= mod; A2 %= mod; A3 %= mod; A4 %= mod;
            }

            public static Matrix PowerMod(long power, Matrix m, long mod)
            {
                Matrix modLast = m, result = new Matrix();

                while (power != 0)
                {
                    if ((power & 1) == 1)
                    {
                        if (result.A1 == 0)
                            result = modLast;
                        else
                            result = Matrix.MulMod(result, modLast, mod);
                    }

                    modLast = Matrix.MulMod(modLast, modLast, mod);
                    power >>= 1;
                }

                return result;
            }
        }

        struct Result
        {
            public long Index, Value;
            public int SIndex;
        }

        static void Main(string[] args)
        {
            long[] steps = new long[] { 60, 300, 1500, 15000, 150000, 1500000, 15000000, 150000000, 1500000000, 15000000000, 150000000000, 1500000000000, 15000000000000, 150000000000000, 1500000000000000, 15000000000000000 };
            long[] mods = new long[] { 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000, 100000000000, 1000000000000, 10000000000000, 100000000000000, 1000000000000000, 10000000000000000 };

            long n = Convert.ToInt64(Console.ReadLine());
            int index = 0;
            long modValue = n % mods[index];

            Queue<Result> queue = new Queue<Result>();
            long[] fs = new long[60]; fs[1] = 1;

            for (int i = 2; i < fs.Length; i++)
            {
                fs[i] = (fs[i - 1] + fs[i - 2]) % mods[index];
                if (fs[i] == modValue)
                    queue.Enqueue(new Result { Index = i, Value = fs[i], SIndex = index });
            }

            List<Result> result = new List<Result>();

            while (queue.Count > 0)
            {
                Result current = queue.Dequeue();

                if (current.Value == n && current.SIndex == 12)
                {
                    result.Add(current);
                    continue;
                }
                else if (current.SIndex > 12)
                    continue;

                for (int i = 0; i * steps[current.SIndex] < steps[current.SIndex + 1]; i++)
                {
                    long nIndex = i * steps[current.SIndex] + current.Index;
                    long value = Cal(nIndex, mods[current.SIndex + 1]);

                    if (value == n % mods[current.SIndex + 1])
                        queue.Enqueue(new Result { Index = nIndex, SIndex = current.SIndex + 1, Value = value });
                }
            }

            if (result.Count == 0)
                Console.WriteLine(-1);
            else
            {
                long sIndex = result.Select(x => x.Index).Min();
                Console.WriteLine(sIndex);
            }
        }

        static long Cal(long index, long mod)
        {
            Matrix m = new Matrix { A1 = 1, A2 = 1, A3 = 1, A4 = 0 };
            Matrix power = Matrix.PowerMod(index, m, mod);
            return (long)power.A2;
        }
    }
}


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

namespace CodeForces
{
    class Program
    {
        struct Matrix
        {
            public BigInteger A1, A2, A3, A4;

            public static Matrix Mul(Matrix m1, Matrix m2)
            {
                Matrix result = new Matrix();
                result.A1 = m1.A1 * m2.A1 + m1.A2 * m2.A3;
                result.A2 = m1.A1 * m2.A2 + m1.A2 * m2.A4;
                result.A3 = m1.A3 * m2.A1 + m1.A4 * m2.A3;
                result.A4 = m1.A3 * m2.A2 + m1.A4 * m2.A4;
                return result;
            }

            public void Mod(long mod)
            {
                A1 %= mod; A2 %= mod; A3 %= mod; A4 %= mod;
            }

            public static Matrix PowerMod(long power, Matrix m, long mod)
            {
                Matrix modLast = m, result = new Matrix();

                while (power != 0)
                {
                    if ((power & 1) == 1)
                    {
                        if (result.A1 == 0)
                            result = modLast;
                        else
                            result = Matrix.Mul(result, modLast);

                        result.Mod(mod);
                    }

                    modLast = Matrix.Mul(modLast, modLast);
                    modLast.Mod(mod);
                    power >>= 1;
                }

                return result;
            }
        }

        struct Result
        {
            public long Index, Value;
            public int SIndex;
        }

        static void Main(string[] args)
        {
            long[] steps = new long[] { 60, 300, 1500, 15000, 150000, 1500000, 15000000, 150000000, 1500000000, 15000000000, 150000000000, 1500000000000, 15000000000000, 150000000000000, 1500000000000000, 15000000000000000 };
            long[] mods = new long[] { 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000, 100000000000, 1000000000000, 10000000000000, 100000000000000, 1000000000000000, 10000000000000000 };

            long n = Convert.ToInt64(Console.ReadLine());
            int index = 0;
            long modValue = n % mods[index];

            Queue<Result> queue = new Queue<Result>();
            long[] fs = new long[60]; fs[1] = 1;

            for (int i = 2; i < fs.Length; i++)
            {
                fs[i] = (fs[i - 1] + fs[i - 2]) % mods[index];
                if (fs[i] == modValue)
                    queue.Enqueue(new Result { Index = i, Value = fs[i], SIndex = index });
            }

            List<Result> result = new List<Result>();

            while (queue.Count > 0)
            {
                Result current = queue.Dequeue();

                if (current.Value == n && current.SIndex == 12)
                {
                    result.Add(current);
                    continue;
                }
                else if (current.SIndex > 12)
                    continue;

                for (int i = 0; i * steps[current.SIndex] < steps[current.SIndex + 1]; i++)
                {
                    long nIndex = i * steps[current.SIndex] + current.Index;
                    long value = Cal(nIndex, mods[current.SIndex + 1]);

                    if (value == n % mods[current.SIndex + 1])
                        queue.Enqueue(new Result { Index = nIndex, SIndex = current.SIndex + 1, Value = value });
                }
            }

            if (result.Count == 0)
                Console.WriteLine(-1);
            else
            {
                long sIndex = result.Select(x => x.Index).Min();
                Console.WriteLine(sIndex);
            }
        }

        static long Cal(long index, long mod)
        {
            Matrix m = new Matrix { A1 = 1, A2 = 1, A3 = 1, A4 = 0 };
            Matrix power = Matrix.PowerMod(index, m, mod);
            return (long)power.A2;
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using Solver.Ex;
using Watch = System.Diagnostics.Stopwatch;
using StringBuilder = System.Text.StringBuilder;
namespace Solver
{

    public class Solver
    {
        public void Solve()
        {
            var r = sc.Integer();
            var g = sc.Integer();
            var h = -1;
            var w = new int[1050];
            for (int k = 1; k < 1050; k++)
            {
                if ((w[k] = k * (k + 1) / 2) <= r + g)
                    continue;
                h = k - 1;
                break;
            }
            var dp = new long[h + 50, r + 50];
            dp[0, r] = 1;
            var mod = (long)1e9 + 7;
            for (int i = 1; i <= h; i++)
            {
                for (int j = r; j >= 0; j--)
                {
                    if (dp[i - 1, j] <= 0)
                        continue;
                    if (j >= i)
                        dp[i, j - i] = (dp[i, j - i] + dp[i - 1, j]) % mod;
                    if (g - (w[i-1] - (r - j)) >= i)
                        dp[i, j] = (dp[i, j] + dp[i - 1, j]) % mod;
                }
            }
            var ret = 0L;
            for (int i = 0; i <= r; i++)
                if (dp[h, i] > 0)
                    ret = (ret + dp[h, i]) % mod;
            IO.Printer.Out.PrintLine(ret);
        }
        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);
            System.Diagnostics.Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(errStream, "debugStream"));
            System.Diagnostics.Debug.AutoFlush = false;
            var sw = new Watch();
            sw.Start();
            try
            {
#endif
                var solver = new Solver();
                solver.sc = new IO.StreamScanner(Console.OpenStandardInput());
                IO.Printer.Out = new IO.Printer(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
                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);
                System.Diagnostics.Debug.Close();
                System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
            }
#endif
        }

    }
    #endregion
}
#region IO Helper
namespace Solver.IO
{
    public class Printer
    {
        static Printer()
        {
            Out = new Printer(Console.Out);
        }
        public static Printer Out { get; set; }
        private readonly System.IO.TextWriter writer;
        private readonly System.Globalization.CultureInfo info;
        public string Separator { get; set; }
        public string NewLine { get { return writer.NewLine; } set { writer.NewLine = value ?? "\n"; } }
        public Printer(System.IO.TextWriter tw = null, System.Globalization.CultureInfo ci = null, string separator = null, string newLine = null)
        {
            writer = tw ?? System.IO.TextWriter.Null;
            info = ci ?? System.Globalization.CultureInfo.InvariantCulture;
            NewLine = newLine;
            Separator = separator ?? " ";
        }
        public void Print(int num) { writer.Write(num.ToString(info)); }
        public void Print(int num, string format) { writer.Write(num.ToString(format, info)); }
        public void Print(long num) { writer.Write(num.ToString(info)); }
        public void Print(long num, string format) { writer.Write(num.ToString(format, info)); }
        public void Print(double num) { writer.Write(num.ToString("F12", info)); }
        public void Print(double num, string format) { writer.Write(num.ToString(format, info)); }
        public void Print(string str) { writer.Write(str); }
        public void Print(string format, params object[] arg) { writer.Write(string.Format(info, format, arg)); }
        public void Print<T>(string format, IEnumerable<T> sources) { writer.Write(format, sources.OfType<object>().ToArray()); }
        public void Print(IEnumerable<char> sources) { writer.Write(sources.AsString()); }
        public void Print<T>(IEnumerable<T> sources)
        {
            var res = new System.Text.StringBuilder();
            foreach (var x in sources)
            {
                res.AppendFormat(info, "{0}", x);
                if (string.IsNullOrEmpty(Separator))
                    res.Append(Separator);
            }
            writer.Write(res.ToString(0, res.Length - Separator.Length));
        }
        public void PrintLine() { writer.WriteLine(); }
        public void PrintLine(int num) { writer.WriteLine(num.ToString(info)); }
        public void PrintLine(int num, string format) { writer.WriteLine(num.ToString(format, info)); }
        public void PrintLine(long num) { writer.WriteLine(num.ToString(info)); }
        public void PrintLine(long num, string format) { writer.WriteLine(num.ToString(format, info)); }
        public void PrintLine(double num) { writer.WriteLine(num.ToString("F12", info)); }
        public void PrintLine(double num, string format) { writer.WriteLine(num.ToString(format, info)); }
        public void PrintLine(string str) { writer.WriteLine(str); }
        public void PrintLine(string format, params object[] arg) { writer.WriteLine(string.Format(info, format, arg)); }
        public void PrintLine<T>(string format, IEnumerable<T> sources) { writer.WriteLine(format, sources.OfType<object>().ToArray()); }
        public void PrintLine<T>(IEnumerable<T> sources)
        {
            var res = new StringBuilder();
            foreach (var x in sources)
            {
                res.AppendFormat(info, "{0}", x);
                if (!string.IsNullOrEmpty(Separator))
                    res.Append(Separator);
            }
            writer.WriteLine(res.ToString(0, res.Length - Separator.Length));
        }
        public void Flush() { writer.Flush(); }
    }
    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 EndOfStream { get { return eof; } }
        private byte readByte()
        {
            if (eof) throw new System.IO.EndOfStreamException();
            if (ptr >= len)
            {
                ptr = 0;
                len = iStream.Read(buf, 0, 1024);
                if (len <= 0)
                {
                    eof = true;
                    return 0;
                }
            }
            return buf[ptr++];
        }
        private bool inSpan(byte c)
        {
            const byte lb = 33, ub = 126;
            return !(c >= lb && c <= ub);
        }
        private byte skip()
        {
            byte b = 0;
            do b = readByte();
            while (!eof && inSpan(b));
            return b;
        }
        public char Char()
        {
            return (char)skip();
        }
        public char[] Char(int n)
        {
            var a = new char[n];
            for (int i = 0; i < n; i++)
                a[i] = (char)skip();
            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()
        {

            const byte lb = 33, ub = 126;
            if (eof) throw new System.IO.EndOfStreamException();

            do
            {
                while (ptr < len && (buf[ptr] < lb || ub < buf[ptr]))
                {
                    ptr++;
                }
                if (ptr < len)
                    break;
                ptr = 0;
                len = iStream.Read(buf, 0, 1024);
                if (len <= 0)
                {
                    eof = true;
                    return null;
                }
                continue;
            } while (true);

            StringBuilder sb = null;
            do
            {
                var i = ptr;
                while (i < len)
                {
                    if (buf[i] < lb || ub < buf[i])
                    {
                        string s;
                        if (sb != null)
                        {
                            sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr));
                            s = sb.ToString();
                        }
                        else s = new string(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr));
                        ptr = i + 1;
                        return s;
                    }
                    i++;
                }
                i = len - ptr;
                if (sb == null) sb = new StringBuilder(i + 32);
                sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i));
                ptr = 0;
            } while ((len = iStream.Read(buf, 0, 1024)) > 0);
            eof = true;
            return sb.ToString();
        }
        public string[] Scan(int n)
        {
            var a = new string[n];
            for (int i = 0; i < n; i++)
                a[i] = Scan();
            return a;
        }
        public string ScanLine()
        {
            const byte el = 10, cr = 13;
            if (eof) throw new System.IO.EndOfStreamException();
            StringBuilder sb = null;
            do
            {
                var i = ptr;
                while (i < len)
                {
                    if (buf[i] == cr || buf[i] == el)
                    {
                        string s;
                        if (sb != null)
                        {
                            sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr));
                            s = sb.ToString();
                        }
                        else s = new string(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr));
                        if (buf[i] == cr) i++;
                        if (buf[i] == el) i++;
                        ptr = i;
                        return s;
                    }
                    i++;
                }
                i = len - ptr;
                if (sb == null) sb = new StringBuilder(i + 32);
                sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i));
                ptr = 0;
            } while ((len = iStream.Read(buf, 0, 1024)) > 0);
            eof = true;
            return sb.ToString();
        }
        public double Double()
        {
            return double.Parse(Scan(), System.Globalization.CultureInfo.InvariantCulture);
        }
        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()
        {
            var ret = 0;
            byte b = 0;
            bool isMynus = false;
            const byte zero = 48, nine = 57, mynus = 45;
            do b = readByte();
            while (!eof && !((b >= zero && b <= nine) || b == mynus));

            if (b == mynus)
            {
                isMynus = true;
                b = readByte();
            }
            while (true)
            {
                if (b >= zero && b <= nine)
                {
                    ret = ret * 10 + b - zero;
                }
                else return isMynus ? -ret : ret;
                b = readByte();
            }

        }
        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()
        {
            long ret = 0;
            byte b = 0;
            bool isMynus = false;
            const byte zero = 48, nine = 57, mynus = 45;
            do b = readByte();
            while (!eof && !((b >= zero && b <= nine) || b == mynus));
            if (b == '-')
            {
                isMynus = true;
                b = readByte();
            }
            while (true)
            {
                if (b >= zero && b <= nine)
                    ret = ret * 10 + (b - zero);
                else return isMynus ? -ret : ret;
                b = readByte();
            }

        }
        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> source)
        {
            return new string(source.ToArray());
        }
        static public string AsJoinedString<T>(this IEnumerable<T> source, string separator = " ")
        {
            return string.Join(separator, source);
        }
        static public T[] Enumerate<T>(this int n, Func<int, T> selector)
        {
            var res = new T[n];
            for (int i = 0; i < n; i++)
                res[i] = selector(i);
            return res;
        }
    }
}
#endregion


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

namespace CF_273_d {
  public class Program {

    public static int r;
    public static int g;
    public static int h;
    public static int cntRG;
    public static ulong[] a;
    public static ulong[] ap;
    public static int n;
    public static int c1;
    public static int c2;
    public static ulong max = 1000000007;
    //public static ulong max = 1000000000;
    public static ulong maxCnt = 0;

    public static void Main(string[] args) {

      string[] str = Console.ReadLine().Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries);
      r = int.Parse(str[0]);
      g = int.Parse(str[1]);

      ulong cnt = Func1();

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

    public static ulong Func1() {

      double d = 1 + 4 * (r + g) * 2;
      double x = (-1 + Math.Sqrt(d)) / 2;
      h = (int)x;
      cntRG = (h + 1) * h / 2;
      c1 = r;
      c2 = g;
      if(g < c1) {
        c1 = g;
        c2 = r;
      }

      a = new ulong[c1 + 1];
      ap = new ulong[c1 + 1];

      a[0] = 1;
      a[1] = 1;

      n = 1;
      Func2();

      ulong sumA = 0;
      for(int i = 0; i <= c1; i++) {
        sumA += a[i];
        if(sumA > max) {
          maxCnt+= sumA / max;
          sumA = sumA % max;
        }
      }

      return sumA;

    }

    public static void Func2() {

      while(n < h) {
        Array.Copy(a, ap, a.Length);
        n++;
        for(int i = 0; i <= c1; i++) {
          int k1 = i - n;
          ulong a1 = 0;
          if(k1 >= 0) a1 = ap[k1];

          int cnt = (n + 1) * n / 2;
          int gi = cnt - i;
          ulong a2 = 0;
          if(gi <= c2) {
            a2 = ap[i];
          }

          a[i] = a1 + a2;

          if(a[i] > max) {
            a[i] %= max;
          }
        }
      }
    }
  }
}


using System;

class Solution
{
    static void Main()
    {
        var count = 0;
        var input = Console.ReadLine();
        var friends = new string[] {"Danil", "Olya", "Slava", "Ann", "Nikita"};
        foreach (var friend in friends)
            if (input.Contains(friend))
                count++;
        Console.WriteLine((count == 1) ? "YES" : "NO");
    }
}