// ReSharper disable RedundantUsingDirective
// ReSharper disable JoinDeclarationAndInitializer
// ReSharper disable MemberCanBeMadeStatic.Local
// ReSharper disable PossibleNullReferenceException
// ReSharper disable ArrangeTypeMemberModifiers
// ReSharper disable SuggestVarOrType_BuiltInTypes
// ReSharper disable SuggestVarOrType_Elsewhere
// ReSharper disable InvertIf
// ReSharper disable InconsistentNaming
// ReSharper disable ConvertIfStatementToSwitchStatement
// ReSharper disable UseObjectOrCollectionInitializer
// ReSharper disable TailRecursiveCall
// ReSharper disable RedundantUsingDirective
// ReSharper disable InlineOutVariableDeclaration
// ReSharper disable FunctionRecursiveOnAllPaths
// ReSharper disable UnusedMember.Global
// ReSharper disable MemberCanBeMadeStatic.Global
// ReSharper disable UnusedMember.Local
// ReSharper disable NonReadonlyMemberInGetHashCode
#pragma warning disable
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using static System.Math;
using static AtCoder.Input;
using static AtCoder.Methods;

namespace AtCoder
{
    #region Templete

    [System.Diagnostics.DebuggerDisplay("({first}, {second})")]
    public class Pair<T1, T2> : IComparable<Pair<T1, T2>>, IEquatable<Pair<T1, T2>>
        where T1 : IComparable<T1>
        where T2 : IComparable<T2>
    {
        public Pair(T1 first, T2 second)
        {
            this.first = first;
            this.second = second;
        }

        public T1 first;
        public T2 second;

        public int CompareTo(Pair<T1, T2> other)
        {
            if (ReferenceEquals(this, other)) return 0;
            if (ReferenceEquals(null, other)) return 1;
            var firstComparison = first.CompareTo(other.first);
            return firstComparison != 0 ? firstComparison : second.CompareTo(other.second);
        }

        public override string ToString() => $"({first}, {second})";

        public bool Equals(Pair<T1, T2> other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return EqualityComparer<T1>.Default.Equals(first, other.first) && EqualityComparer<T2>.Default.Equals(second, other.second);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            return obj.GetType() == this.GetType() && Equals((Pair<T1, T2>)obj);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                return (EqualityComparer<T1>.Default.GetHashCode(first) * 397) ^ EqualityComparer<T2>.Default.GetHashCode(second);
            }
        }
    }

    [System.Diagnostics.DebuggerDisplay("Value = {" + nameof(_value) + "}")]
    public struct ModInt : IEquatable<ModInt>, IComparable<ModInt>
    {
        private long _value;

        public const int MOD = (int)1e9 + 7;

        public static readonly ModInt Zero = new ModInt(0);

        public static readonly ModInt One = new ModInt(1);

        public ModInt(long value) { _value = value % MOD; }

        private ModInt(int value) { _value = value; }

        public int Value => (int)_value;

        public ModInt Invert => ModPow(this, MOD - 2);

        public static ModInt operator -(ModInt value)
        {
            value._value = MOD - value._value;
            return value;
        }

        public static ModInt operator +(ModInt left, ModInt right)
        {
            left._value += right._value;
            if (left._value >= MOD) left._value -= MOD;
            return left;
        }

        public static ModInt operator -(ModInt left, ModInt right)
        {
            left._value -= right._value;
            if (left._value < 0) left._value += MOD;
            return left;
        }

        public static ModInt operator *(ModInt left, ModInt right)
        {
            left._value = left._value * right._value % MOD;
            return left;
        }

        public static ModInt operator /(ModInt left, ModInt right) => left * right.Invert;

        public static ModInt operator ++(ModInt value)
        {
            if (value._value == MOD - 1) value._value = 0;
            else value._value++;
            return value;
        }

        public static ModInt operator --(ModInt value)
        {
            if (value._value == 0) value._value = MOD - 1;
            else value._value--;
            return value;
        }

        public static bool operator ==(ModInt left, ModInt right) => left.Equals(right);

        public static bool operator !=(ModInt left, ModInt right) => !left.Equals(right);

        public static implicit operator ModInt(int value) => new ModInt(value);

        public static implicit operator ModInt(long value) => new ModInt(value);

        public static ModInt ModPow(ModInt value, long exponent)
        {
            var r = new ModInt(1);
            for (; exponent > 0; value *= value, exponent >>= 1)
                if ((exponent & 1) == 1) r *= value;
            return r;
        }

        public static ModInt ModFact(int value)
        {
            var r = new ModInt(1);
            for (var i = 2; i <= value; i++) r *= value;
            return r;
        }

        public bool Equals(ModInt other) => _value == other._value;

        public override bool Equals(object obj)
        {
            return obj != null && this.Equals((ModInt)obj);
        }

        public override int GetHashCode() => _value.GetHashCode();

        public override string ToString() => _value.ToString();

        public int CompareTo(ModInt other)
        {
            return _value.CompareTo(other._value);
        }
    }

    public static class Methods
    {
        public static readonly int[] dx = { -1, 0, 0, 1 };

        public static readonly int[] dy = { 0, 1, -1, 0 };

        /*
        public static Comparison<T> greater<T>()
            where T : IComparable<T>
            => (a, b) => b.CompareTo(a);
        */
        public static void Print<T>(T t) => Console.WriteLine(t);

        public static void PrintBool(bool val, string yes = "Yes", string no = "No")
            => Console.WriteLine(val ? yes : no);

        public static void PrintYn(bool val) => PrintBool(val);
        public static void PrintYN(bool val) => PrintBool(val, "YES", "NO");
        public static void PrintPossible(bool val) => PrintBool(val, "Possible", "Impossible");
        public static void PrintYay(bool val) => PrintBool(val, "Yay!", ":(");

        public static void PrintDebug(params object[] args)
            => Console.Error.WriteLine(string.Join(" ", args));

        public static string JoinWith<T>(this IEnumerable<T> source, string s) => string.Join(s, source.ToArray());

        ///
        /// <see cref="Pair{T1, T2}"/> クラスのインスタンスを作成します。
        ///
        /// <typeparam name="T1">firstの型</typeparam>
        /// <typeparam name="T2">secondの型</typeparam>
        /// <param name="first">firstの値</param>
        /// <param name="second">secondの値</param>
        /// <returns>作成した<see cref="Pair{T1, T2}"/> クラスのインスタンス</returns>
        public static Pair<T1, T2> make_pair<T1, T2>(T1 first, T2 second)
            where T1 : IComparable<T1>
            where T2 : IComparable<T2>
            => new Pair<T1, T2>(first, second);

        /// aとbをスワップします。に
        public static void Swap<T>(ref T a, ref T b) where T : struct
        {
            var tmp = b;
            b = a;
            a = tmp;
        }

        /// aとbの最大公約数を求めます。
        /// <returns>aとbの最大公約数</returns>
        public static long Gcd(long a, long b)
        {
            if (a < b) Swap(ref a, ref b);
            return a % b == 0 ? b : Gcd(b, a % b);
        }

        /// aとbの最小公倍数を求めます。
        /// <returns>aとbの最小公倍数</returns>
        public static long Lcm(long a, long b) => a / Gcd(a, b) * b;

        ///
        /// <see cref="a"/> ^ <see cref="b"/> (mod <see cref="p"/>) を求める
        ///
        /// <returns><see cref="a"/> ^ <see cref="b"/> (mod <see cref="p"/>) の値</returns>
        public static long PowMod(long a, long b, long p)
        {
            long res = 1;
            while (b > 0)
            {
                if (b % 2 != 0) res = res * a % p;
                a = a * a % p;
                b >>= 1;
            }

            return res;
        }

        ///
        /// mod pにおけるaの逆元を求めます。
        ///
        /// <param name="a"></param>
        /// <param name="mod">法</param>
        /// <returns></returns>
        public static long ModInv(long a, long p)
            => PowMod(a, p - 2, p);

        public static int DivCeil(int left, int right)
            => left / right + (left % right == 0 ? 0 : 1);

        public static long DivCeil(long left, long right)
            => left / right + (left % right == 0L ? 0L : 1L);

        ///
        /// src の順列を求めます。
        ///
        /// <typeparam name="T">型</typeparam>
        /// <param name="src">順列を求める配列</param>
        /// <returns>src の順列</returns>
        public static IEnumerable<T[]> Permutations<T>(IEnumerable<T> src)
        {
            var ret = new List<T[]>();
            Search(ret, new Stack<T>(), src.ToArray());
            return ret;
        }

        private static void Search<T>(ICollection<T[]> perms, Stack<T> stack, T[] a)
        {
            int N = a.Length;
            if (N == 0) perms.Add(stack.Reverse().ToArray());
            else
            {
                var b = new T[N - 1];
                Array.Copy(a, 1, b, 0, N - 1);
                for (int i = 0; i < a.Length; ++i)
                {
                    stack.Push(a[i]);
                    Search(perms, stack, b);
                    if (i < b.Length) b[i] = a[i];
                    stack.Pop();
                }
            }
        }

        ///
        /// 指定した条件を満たす最小の数値を返します。
        ///
        /// <param name="low">検索する数値の最小値</param>
        /// <param name="high">検索する数値の最大値</param>
        /// <param name="expression">条件</param>
        /// <returns>条件を満たす最小の数値</returns>
        public static int BinarySearch(int low, int high, Func<int, bool> expression)
        {
            while (low < high)
            {
                int middle = (high - low) / 2 + low;
                if (expression(middle))
                    high = middle;
                else
                    low = middle + 1;
            }

            return high;
        }

        ///
        /// 指定した値以上の先頭のインデクスを返します。
        ///
        /// <typeparam name="T">比較する値の型</typeparam>
        /// <param name="arr">対象の配列（※ソート済みであること）</param>
        /// <param name="start">開始インデクス [inclusive]</param>
        /// <param name="end">終了インデクス [exclusive]</param>
        /// <param name="value">検索する値</param>
        /// <param name="comparer">比較関数(インターフェイス)</param>
        /// <returns>指定した値以上の先頭のインデクス</returns>
        public static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer)
        {
            int low = start;
            int high = end;
            while (low < high)
            {
                var mid = ((high - low) >> 1) + low;
                if (comparer.Compare(arr[mid], value) < 0)
                    low = mid + 1;
                else
                    high = mid;
            }

            return low;
        }

        ///
        /// 指定した値以上の先頭のインデクスを返します。
        ///
        /// <typeparam name="T">比較する値の型</typeparam>
        /// <param name="arr">対象の配列（※ソート済みであること）</param>
        /// <param name="value">検索する値</param>
        /// <returns>指定した値以上の先頭のインデクス</returns>
        public static int LowerBound<T>(T[] arr, T value) where T : IComparable
        {
            return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default);
        }

        ///
        /// 指定した値より大きい先頭のインデクスを返します。
        ///
        /// <typeparam name="T">比較する値の型</typeparam>
        /// <param name="arr">対象の配列（※ソート済みであること）</param>
        /// <param name="start">開始インデクス [inclusive]</param>
        /// <param name="end">終了インデクス [exclusive]</param>
        /// <param name="value">検索する値</param>
        /// <param name="comparer">比較関数(インターフェイス)</param>
        /// <returns>指定した値より大きい先頭のインデクス</returns>
        public static int UpperBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer)
        {
            int low = start;
            int high = end;
            while (low < high)
            {
                var mid = ((high - low) >> 1) + low;
                if (comparer.Compare(arr[mid], value) <= 0)
                    low = mid + 1;
                else
                    high = mid;
            }

            return low;
        }

        ///
        /// 指定した値より大きい先頭のインデクスを返します。
        /// Z
        /// <typeparam name="T">比較する値の型</typeparam>
        /// <param name="arr">対象の配列（※ソート済みであること）</param>
        /// <param name="value">検索する値</param>
        /// <returns>指定した値より大きい先頭のインデクス</returns>
        public static int UpperBound<T>(T[] arr, T value)
        {
            return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default);
        }

        public static IEnumerable<TResult> SelectNotNull<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> func)
            => source.Where(val => val != null).Select(func);

        public static IEnumerable<TSource> WhereNotNull<TSource>(this IEnumerable<TSource> source)
            => source.Where(val => val != null);
        ///
        /// 文字の配列を文字列に変換します。
        ///
        /// <param name="source">文字の配列</param>
        /// <returns>変換した文字列</returns>
        public static string AsString(this IEnumerable<char> source) => new string(source.ToArray());

        ///
        /// <see cref="source"/> の累積和を返します。
        ///
        /// <returns><see cref="source"/> の累積和</returns>
        public static IEnumerable<long> CumSum(this IEnumerable<long> source)
        {
            long sum = 0;
            foreach (var item in source)
                yield return sum += item;
        }

        ///
        /// <see cref="source"/> の累積和を返します。
        ///
        /// <returns><see cref="source"/> の累積和</returns>
        public static IEnumerable<int> CumSum(this IEnumerable<int> source)
        {
            int sum = 0;
            foreach (var item in source)
                yield return sum += item;
        }
        ///
        /// <see cref="value"/>が l以上 r未満の範囲に含まれているかを返します。
        ///
        /// <typeparam name="T">要素の型</typeparam>
        /// <param name="value">判定する値</param>
        /// <param name="l">下限の値 (含まれる)</param>
        /// <param name="r">下限の値 (含まれない)</param>
        /// <returns><see cref="value"/> が指定した範囲に含まれているか</returns>
        public static bool IsIn<T>(this T value, T l, T r)
            where T : IComparable<T>
        {
            if (l.CompareTo(r) > 0) throw new ArgumentException();
            return l.CompareTo(value) <= 0 && value.CompareTo(r) < 0;
        }

        ///
        /// <see cref="start"/> 以上 <see cref="end"/> 未満の値を <see cref="step"/> ずつ増やした結果を列挙します。
        ///
        /// <param name="start">値の下限 (含まれる)</param>
        /// <param name="end">値の上限 (含まれない)</param>
        /// <param name="step">1要素ごとに増やす値</param>
        /// <returns>範囲の結果</returns>
        public static IEnumerable<int> Range(int start, int end, int step = 1)
        {
            for (var i = start; i < end; i += step) yield return i;
        }

        ///
        /// 0 以上 <see cref="end"/> 未満の値を 1 ずつ増やした結果を列挙します。
        ///
        /// <param name="end">値の上限 (含まれない)</param>
        /// <returns>範囲の結果</returns>
        public static IEnumerable<int> Range(int end) => Range(0, end);

        ///
        /// <see cref="start"/> 以上 <see cref="end"/> 未満の値を <see cref="step"/> ずつ増やした結果を逆順に列挙します。
        ///
        /// <param name="start">値の下限 (含まれる)</param>
        /// <param name="end">値の上限 (含まれない)</param>
        /// <param name="step">1要素ごとに増やす値</param>
        /// <returns>範囲の結果</returns>
        public static IEnumerable<int> RangeReverse(int start, int end, int step = 1)
        {
            for (var i = end - 1; i >= start; i -= step) yield return i;
        }

        ///
        /// 0 以上 <see cref="end"/> 未満の値を 1 ずつ増やした結果を逆順に列挙します。
        ///
        /// <param name="end">値の上限 (含まれない)</param>
        /// <returns>範囲の結果</returns>
        public static IEnumerable<int> RangeReverse(int end) => RangeReverse(0, end);

        ///
        /// valueを素因数分解し、素因数を列挙します。
        ///
        /// <param name="value">素因数分解する値</param>
        /// <returns>素因数の集合</returns>
        public static IEnumerable<int> Factorize(int value)
        {
            for (int i = 2; i * i < value; i++)
            {
                while (value % i == 0)
                {
                    value /= i;
                    yield return i;
                }
            }

            if (value > 1)
                yield return value;
        }
        ///
        /// valueを素因数分解し、素因数を列挙します。
        ///
        /// <param name="value">素因数分解する値</param>
        /// <returns>素因数の集合</returns>
        public static IEnumerable<long> Factorize(long value)
        {
            for (int i = 2; i * i < value; i++)
            {
                while (value % i == 0)
                {
                    value /= i;
                    yield return i;
                }
            }

            if (value > 1)
                yield return value;
        }
        ///
        /// valueを素因数分解し、素因数とその個数の連想配列を返します。
        ///
        /// <param name="value">素因数分解する値</param>
        /// <returns>素因数の連想配列</returns>
        public static Dictionary<long, int> FactorizeAsMap(long value)
        {
            var dict = new Dictionary<long, int>();

            for (int i = 2; i * i < value; i++)
            {
                if (value % i > 0) continue;
                int cnt = 0;
                while (value % i == 0)
                {
                    value /= i;
                    cnt++;
                }
                dict.Add(i, cnt);
            }

            if (value > 1) dict.Add(value, 1);
            return dict;
        }

        ///
        /// valueを素因数分解し、素因数とその個数の連想配列を返します。
        ///
        /// <param name="value">素因数分解する値</param>
        /// <returns>素因数の連想配列</returns>
        public static Dictionary<int, int> FactorizeAsMap(int value)
        {
            var dict = new Dictionary<int, int>();

            for (int i = 2; i * i < value; i++)
            {
                if (value % i > 0) continue;
                int cnt = 0;
                while (value % i == 0)
                {
                    value /= i;
                    cnt++;
                }
                dict.Add(i, cnt);
            }

            if (value > 1) dict.Add(value, 1);
            return dict;
        }
        ///
        /// valueの約数の個数を求めます。
        ///
        /// <param name="value">約数の個数を求める数</param>
        /// <returns>valueの約数の個数</returns>
        public static long Divisors(long value)
        {
            var fact = FactorizeAsMap(value);
            return fact.Select(x => x.Value + 1L).Aggregate((m, x) => m * x);
        }

        public static bool IsEven(this int x) => x % 2 == 0;
        public static bool IsOdd(this int x) => x % 2 != 0;
        public static bool IsEven(this long x) => x % 2 == 0;
        public static bool IsOdd(this long x) => x % 2 != 0;
        public static double Log2(double x) => Log(x, 2);

        public static bool chmin(ref int a, int b)
        {
            if (a > b)
            {
                a = b;
                return true;
            }

            return false;
        }

        public static bool chmax(ref int a, int b)
        {
            if (a  b)
            {
                a = b;
                return true;
            }

            return false;
        }

        public static bool chmax(ref long a, long b)
        {
            if (a < b)
            {
                a = b;
                return true;
            }

            return false;
        }

        public static T Min<T>(params T[] col) => col.Min();
        public static T Max<T>(params T[] col) => col.Max();

    }

    public static class Input
    {
        private const char _separator = ' ';
        private static readonly Queue<string> _input = new Queue<string>();
        private static readonly StreamReader sr =
#if FILE
            new StreamReader("in.txt");
#else
            new StreamReader(Console.OpenStandardInput());
#endif

        public static string Rs => ReadStr;
        public static int Ri => ReadInt;
        public static long Rl => ReadLong;
        public static string[] Rsa => StrArray();
        public static int[] Ria => IntArray();
        public static long[] Rla => LongArray();
        public static string ReadLine => sr.ReadLine();
        public static string ReadStr => Read;

        public static string Read
        {
            get {
                if (_input.Count != 0) return _input.Dequeue();

                // ReSharper disable once PossibleNullReferenceException
                var tmp = sr.ReadLine().Split(_separator);
                foreach (var val in tmp)
                {
                    _input.Enqueue(val);
                }

                return _input.Dequeue();
            }
        }

        public static int ReadInt => int.Parse(Read);
        public static long ReadLong => long.Parse(Read);
        public static double ReadDouble => double.Parse(Read);
        public static string[] StrArray() => ReadLine.Split(' ');
        public static int[] IntArray() => ReadLine.Split(' ').Select(int.Parse).ToArray();
        public static long[] LongArray() => ReadLine.Split(' ').Select(long.Parse).ToArray();

        public static string[] StrArray(long n)
        {
            var ret = new string[n];
            for (long i = 0; i < n; ++i) ret[i] = Read;
            return ret;
        }

        public static int[] IntArray(long n, bool sorted = false)
        {
            var ret = StrArray(n).Select(int.Parse).ToArray();
            if (sorted) Array.Sort(ret);
            return ret;
        }

        public static long[] LongArray(long n, bool sorted = false)
        {
            var ret = StrArray(n).Select(long.Parse).ToArray();
            if (sorted) Array.Sort(ret);
            return ret;
        }

        static bool TypeEquals<T, U>() => typeof(T) == typeof(U);
        static T ChangeType<T, U>(U a) => (T)System.Convert.ChangeType(a, typeof(T));

        static T Convert<T>(string s) => TypeEquals<T, int>() ? ChangeType<T, int>(int.Parse(s))
            : TypeEquals<T, long>() ? ChangeType<T, long>(long.Parse(s))
            : TypeEquals<T, double>() ? ChangeType<T, double>(double.Parse(s))
            : TypeEquals<T, char>() ? ChangeType<T, char>(s[0])
            : ChangeType<T, string>(s);

        public static bool In<T>(out T a)
        {
            try
            {
                a = Convert<T>(Read);
                return true;
            }
            catch
            {
                a = default(T);
                return false;
            }
        }

        public static bool In<T, U>(out T a, out U b)
        {
            try
            {
                var ar = StrArray(2);
                a = Convert<T>(ar[0]);
                b = Convert(ar[1]);
                return true;
            }
            catch
            {
                a = default(T);
                b = default(U);
                return false;
            }
        }

        public static bool In<T, U, V>(out T a, out U b, out V c)
        {
            try
            {
                var ar = StrArray(3);
                a = Convert<T>(ar[0]);
                b = Convert(ar[1]);
                c = Convert<V>(ar[2]);
                return true;
            }
            catch
            {
                a = default(T);
                b = default(U);
                c = default(V);
                return false;
            }
        }

        public static bool In<T, U, V, W>(out T a, out U b, out V c, out W d)
        {
            try
            {
                var ar = StrArray(4);
                a = Convert<T>(ar[0]);
                b = Convert(ar[1]);
                c = Convert<V>(ar[2]);
                d = Convert<W>(ar[3]);
                return true;
            }
            catch
            {
                a = default(T);
                b = default(U);
                c = default(V);
                d = default(W);
                return false;
            }
        }

        public static bool In<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e)
        {
            try
            {
                var ar = StrArray(5);
                a = Convert<T>(ar[0]);
                b = Convert(ar[1]);
                c = Convert<V>(ar[2]);
                d = Convert<W>(ar[3]);
                e = Convert<X>(ar[4]);
                return true;
            }
            catch
            {
                a = default(T);
                b = default(U);
                c = default(V);
                d = default(W);
                e = default(X);
                return false;
            }
        }
        ///
        /// 要素数 (a, b) の、defaultValue で満たされた配列を作成します。
        ///
        /// <typeparam name="T">配列の型</typeparam>
        /// <param name="a">1次元の要素数</param>
        /// <param name="b">2次元の要素数</param>
        /// <param name="defaultValue">デフォルト値</param>
        /// <returns>指定した条件で初期化された配列</returns>
        public static T[][] Array2D<T>(int a, int b, T defaultValue = default(T))
        {
            var ret = new T[a][];
            for (int i = 0; i < a; i++)
            {
                ret[i] = Enumerable.Repeat(defaultValue, b).ToArray();
            }

            return ret;
        }
    }

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

    #endregion

    public class Solver
    {
        private const int MOD = (int)1e9 + 7,
            INF = 1000000010;

        public void Solve()
        {
            int N = ReadInt;
            int K = ReadInt;

            if (N == 1 && K == 1)
            {
                Console.WriteLine(0);
                return;
            }

            long now = 1;
            int i = 1;
            while (true)
            {
                now += ++i;
                if (now < K) continue;

                int actionCount = i;
                long mustEatCount = now - K;
                if (actionCount + mustEatCount == N ) break;
            }

            Console.WriteLine(now - K );

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
// you can also use other imports, for example:
// using System.Collections.Generic;

// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");

class Solution
{
    public class Obj: IComparable<Obj>
    {
        public int a, b;
        public Obj(int aa)
        {
            this.a = aa;
        }

        int IComparable<Obj>.CompareTo(Obj other)
        {
            if (a <= other.a)
                return -1;
            else return 1;
        }
    }
    static int MyPartition(List<int> list, int left, int right)
    {
        int start = left;
        int pivot = list[start];
        left++;
        right--;

        while (true)
        {
            while (left <= right && list[left] <= pivot)
                left++;

            while (left <= right && list[right] > pivot)
                right--;

            if (left > right)
            {
                list[start] = list[left - 1];
                list[left - 1] = pivot;

                return left;
            }

            int temp = list[left];
            list[left] = list[right];
            list[right] = temp;

        }
    }

    static void MyQuickSort(List<int> list, int left, int right)
    {
        if (list == null || list.Count <= 1)
            return;

        if (left < right)
        {
            int pivotIdx = MyPartition(list, left, right);
            //Console.WriteLine("MQS " + left + " " + right);
            //DumpList(list);
            MyQuickSort(list, left, pivotIdx - 1);
            MyQuickSort(list, pivotIdx, right);
        }
    }
    public int solution(int[] A)
    {
        List<int> a = new List<int>(A);
        MyQuickSort(a, 0, a.Count);
        int run = 1;
        for (int i = 0; i < a.Count; i++)
            if (a[i] < run)
                continue;
            else if (a[i] == run)
                run++;
            else
                return run;
        return run;
    }
    static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');
        long res = long.Parse(s[0]) - (long)(-3 + Math.Sqrt(9 + 8 * (long.Parse(s[0]) + long.Parse(s[1])))) / 2;
        Console.WriteLine(res);
       // Console.ReadKey();
    }
}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] array = new int[2];
            string str = Console.ReadLine();
            string s = "";
            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] == ' ')
                {
                    array[0] = Convert.ToInt32(s);
                    s = "";
                }
                else
                {
                    s += str[i];
                }
            }
            array[1] = Convert.ToInt32(s);

            int l = 1;
            int r = array[0];
            int mid = 0;
            while (l < r)
            {
                mid = (l + r) / 2;
                if ((1 + mid) * mid / 2 - (array[0] - mid) < array[1])
                {
                    l = mid + 1;
                }

                if ((1 + mid) * mid / 2 - (array[0] - mid) > array[1])
                {
                    r = mid - 1;
                }
                if ((1 + mid) * mid / 2 - (array[0] - mid) == array[1])
                {
                    break;
                }

            }
            if (l == r)
            {
                mid = l;
            }
            Console.WriteLine(array[0] - mid);
     //  Console.Read();

        }
    }

}


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

using static System.Console;

public class Test
{
    static int Sum(int n)
    {
        return (2 + n - 1) * n / 2;
    }

    static int Res(int i, int n)
    {
        return Sum(i) - n + i;
    }

    static int Mid(int left, int right)
    {
        return (int)Math.Floor((double)(left + right) / (double)2);
    }

    public static void Main()
	{
        var line1 = ReadLine().Split();
        int n = int.Parse(line1[0]);
        int k = int.Parse(line1[1]);

        int left = 1;
        int right = n;
        int mid = Mid(left, right);
        while(Res(mid, n) != k)
        {
            if(Res(mid, n) > k)
            {
                right = mid;
            }
            else
            {
                left = mid;
            }
            if(mid == Mid(left, right))
                break;
            mid = Mid(left, right);
        }

        WriteLine(Sum(mid) - k);
	}
}


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

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            var nk = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt32);
            int n = nk[0], k = nk[1];
            int kq = 0;
            int ts = n * n + n - 2 * k;
            while (true)
            {
                if(ts%(2*n+3-kq)==0)
                {
                    Console.WriteLine(kq);
                    break;
                }
                kq++;
            }

        }
    }
}


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

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            var nk = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt64);
            long n = nk[0], k = nk[1];
            int kq = 0;
            long ts = n * n + n - 2 * k;
            while (true)
            {
                if(ts%(2*n+3-kq)==0)
                {
                    Console.WriteLine(kq);
                    break;
                }
                kq++;
            }

        }
    }
}


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

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            var nk = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt64);
            long n = nk[0], k = nk[1];
            int t = (int)Math.Sqrt(8 * n + 8 * k + 9);
            Console.WriteLine((2 * n + 3 - t) / 2 > 0 ? (2 * n + 3 - t) / 2 : (2 * n + 3 + t) / 2);

        }
    }
}


using System;

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

            int[] groups = new int[n];

            for(int i = 0; i < n; i++)
            {
                groups[i] = Convert.ToInt32(str_numbers[i]);
            }

            Array.Sort(groups);

            int result = 0;

            int left = 0;

            for(int i = n - 1; i >= 0; i--)
            {
                if(groups[i] == 4)
                {
                    result++;
                }
                else if(groups[i] == 3)
                {
                    if(left == i) { result++; break; }
                    if(groups[left] == 1)
                    {
                        left++;
                        result++;
                    }
                    else
                    {
                        result++;
                    }
                }
                else if(groups[i] == 2)
                {
                    if (left == i) { result++; break; }
                    if (groups[left] == 1)
                    {
                        if(groups[left + 1] == 1 && left + 1 != i)
                        {
                            left += 2;
                            result++;
                        }
                        else
                        {
                            result++;
                            left++;
                        }
                    }
                }
                else if(groups[i] == 1)
                {
                    if (left == i) { result++; break; }

                    for(int j = left; j < 4; j++)
                    {

                        if (left == i) { result++; break; }
                        if (j == i)
                        {
                            result++;
                            break;
                        }
                        else
                        {
                            left++;

                        }
                    }

                    result++;
                }
            }

            Console.WriteLine(result);

        }
    }
}


using System;
using System.Text;

namespace ConsoleApp21
{
    class Program
    {
        static void Main(string[] args)
        {
            string inp = Console.ReadLine();
            string [] inp_mas = inp.Split(' ');
            int n = int.Parse(inp_mas[0]);
            int k = int.Parse(inp_mas[1]);
            int ans = 0;
            int add = 1;
            int chk = 0;
            for (int i = 0; i < n; i++)
            {
                if (chk <= k)
                {
                    chk += add;
                    add++;
                }
                else if (chk > k)
                {
                    chk--;
                    ans++;
                 }
            }
            Console.WriteLine(ans);
            Console.ReadKey();
        }
    }
}


using System;
using System.Linq;

namespace CSharp
{
    class _592A
    {
        public static void Main()
        {
            var board = Enumerable.Range(0, 8).Select(i => Console.ReadLine()).ToArray();

            int a = 8;
            int b = 8;

            for (int c = 0; c < 8; c++)
            {
                for (int r = 0; r < 8; r++)
                {
                    if (board[r][c] != '.')
                    {
                        if (board[r][c] == 'W')
                        {
                            a = Math.Min(a, r);
                        }

                        break;
                    }
                }

                for (int r = 7; r >= 0; r--)
                {
                    if (board[r][c] != '.')
                    {
                        if (board[r][c] == 'B')
                        {
                            b = Math.Min(a, 7 - r);
                        }

                        break;
                    }
                }
            }

            Console.WriteLine(a <= b ? 'A' : 'B');
        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = new string[8];
            for (int i = 0; i < 8; i++)
            {s[i]=Console.ReadLine(); }
            int mina = 9;
            int maxb = 0;
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    if (s[i][j] == 'W'&&i<mina)
                    {
                        bool a = true;
                        for (int w = i; w >= 0; w--)
                        {
                            if (s[w][j] == 'B')
                            { a = false; break; }
                        }
                        if (a) { mina = i+1; }
                    }
                    if (s[i][j] == 'B' && i > maxb)
                    {
                        bool a = true;
                        for (int w = i; w < 8; w++)
                        {
                            if (s[w][j] == 'W')
                            { a = false; break; }
                        }
                        if (a) { maxb = i+1; }
                    }
                }
            }
            if ((8 - maxb) < (mina - 1)) { Console.WriteLine("B"); }
            else { Console.WriteLine("A"); }
        }
    }
}


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

namespace _329a
{
	class Program
	{
		static void Main(string[] args)
		{
			//Console.SetIn(File.OpenText("in.txt"));
			var d = new int[8, 8];
			for (int i = 0; i < 8; i++)
			{
				var st = Console.ReadLine();
				for (int j = 0; j < 8; j++)
				{
					var ch = st[j];
					if (ch == '.')
					{
						d[i, j] = 0;
					}
					else if (ch == 'W')
					{
						d[i, j] = 1;
					}
					else if (ch == 'B')
					{
						d[i, j] = 2;
					}
				}
			}

			var min1 = 100;
			var min2 = 100;
			for (int i = 0; i < 8; i++)
			{
				var c1 = -1;
				var c2 = -1;
				for (int j = 0; j < 8; j++)
				{
					if (d[j, i] == 2)
					{
						c2 = j;
					}

				}

				for (int j = 7; j >= 0; j--)
				{
					if (d[j, i] == 1)
					{
						c1 = j;
					}
				}

				var cant1 = false;
				var cant2 = false;
				if (c1 != -1 && c2 != -1)
				{
					var w = c1;
					//var cant = false;
					for (int k = w; k <= 0; k--)
					{
						if (d[k, i] == 2)
						{
							cant1 = true;
							break;
						}
					}
					//if (cant1)
					//{
					//	continue;
					//}

					//cant = false;
					for (int k = c2; k < 8; k++)
					{
						if (d[k, i] == 1)
						{
							cant2 = true;
							break;
						}
					}

					//if (cant2)
					//{
					//	continue;
					//}
				}

				if (c1 == -1 && c2 == -1)
				{
					continue;
				}

				if (c1 != -1 && !cant1)
				{
					var cmin1 = c1;
					if (cmin1 < min1)
					{
						min1 = cmin1;
					}
				}

				if (c2 != -1 && !cant2)
				{
					var cmin2 = 7 - c2;
					if (cmin2 < min2)
					{
						min2 = cmin2;
					}
				}
			}

			if (min1 <= min2)
			{
				Console.WriteLine("A");
			}
			else if (min2 < min1)
			{
				Console.WriteLine("B");
			}
		}
	}
}


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

namespace _329a
{
	class Program
	{
		static void Main(string[] args)
		{
			//Console.SetIn(File.OpenText("in.txt"));
			var d = new int[8, 8];
			for (int i = 0; i < 8; i++)
			{
				var st = Console.ReadLine();
				for (int j = 0; j < 8; j++)
				{
					var ch = st[j];
					if (ch == '.')
					{
						d[i, j] = 0;
					}
					else if (ch == 'W')
					{
						d[i, j] = 1;
					}
					else if (ch == 'B')
					{
						d[i, j] = 2;
					}
				}
			}

			var min1 = 100;
			var min2 = 100;
			for (int i = 0; i < 8; i++)
			{
				var c1 = -1;
				var c2 = -1;
				for (int j = 0; j < 8; j++)
				{
					if (d[j, i] == 1)
					{
						c1 = j;
					}

					if (d[j, i] == 2)
					{
						c2 = j;
					}
				}

				if (c1 != -1 && c2 != -1 && (c2 < c1))
				{
					continue;
				}

				if (c1 == -1 && c2 == -1)
				{
					continue;
				}

				if (c1 != -1)
				{
					var cmin1 = c1;
					if (cmin1 < min1)
					{
						min1 = cmin1;
					}
					continue;
				}

				if (c2 != -1)
				{
					var cmin2 = 7 - c2;
					if (cmin2 < min2)
					{
						min2 = cmin2;
					}
					continue;
				}
			}

			if (min1 <= min2)
			{
				Console.WriteLine("A");
			}
			else if (min2 < min1)
			{
				Console.WriteLine("B");
			}
		}
	}
}


using System;
class Program
    {
        public static void Main(string[] args)
        {
            string[] input = Console.In.ReadToEnd().Split(new char[] { '\n', '\r'}, StringSplitOptions.RemoveEmptyEntries);
            bool beforeW=false;
            int shortestWayW = int.MaxValue;
            int shortestWayB = shortestWayW;
            for(int i = 0, currShortB = int.MaxValue; i<8; ++i)
            {
                for(int j=0; j<8; j++)
                {
                    if(input[j][i]!='.')
                    {
                        if(input[j][i]=='W')
                        {
                            if(!beforeW)
                            {
                                if (shortestWayW > j) shortestWayW = j;
                                beforeW = true;
                            }
                            currShortB = int.MaxValue;
                        }
                        else
                        {
                            beforeW = true;
                            currShortB = 8 - j;
                        }
                    }
                }
                if (currShortB < shortestWayB) shortestWayB = currShortB;
                beforeW = false;
            }
            Console.WriteLine(shortestWayB < shortestWayW ? 'B' : 'A');
        }
    }


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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    void Solve()
    {
        var a = ReadLines(8);

        int ca = 8, cb = 8;
        for (int i = 0; i < 8; i++)
        {
            for (int j = 0; j < 8; j++)
                if (a[j][i] == 'W')
                    ca = Math.Min(ca, j);
                else if (a[j][i] == 'B')
                    break;
            for (int j = 7; j >= 0; j--)
                if (a[j][i] == 'B')
                    cb = Math.Min(cb, 7 - j);
                else if (a[j][i] == 'W')
                    break;
        }

        Write(ca > cb ? "B" : "A");
    }

    #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("figures.in");
        //writer = new StreamWriter("figures.out");
#endif
        try
        {
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
            new Solver().Solve();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
#if DEBUG
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

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


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

namespace ConsoleApplication19
{
    class Program
    {
        static void Main(string[] args)
        {
            char[,] a=new char[8,8];
            int w = int.MaxValue;
            int b = int.MaxValue;
            for (int i = 0; i < 8; i++)
            {
                char[] tmp = Console.ReadLine().ToCharArray();
                for (int j = 0; j < 8; j++)
                {
                    a[i, j] = tmp[j];
                }
            }
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    if (a[i, j] == 'W')
                    {
                        bool k;
                        if (i - 1 == -1)
                            k = true;
                        else
                        {
                            k = true;
                            for (int m = i - 1; m >= 0; m--)
                            {
                                if (a[m, j] != '.')
                                    k = false;
                            }
                        }
                        if (k)
                        {
                            if (w > i)
                                w = i;
                        }

                    }
                    if (a[i, j] == 'B')
                    {
                        bool k;
                        if (i + 1 == 8)
                            k = true;
                        else
                        {
                            k = true;
                            for (int m = i + 1; m <= 7; m++)
                            {
                                if (a[m, j] != '.')
                                    k = false;
                            }
                        }
                        if (k)
                        {
                            if (b>(7 - i))
                                b = 7- i;
                        }
                    }
                }
            }
            if (w>b)
                Console.WriteLine("B");
            else
            {
                Console.WriteLine("A");
            }
        }
    }
}


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

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

        void Solve()
        {
            int minA=10, minB=10;
            var arr = new char[8,8];
            //var arrB = new bool[8, 8];
            for (int i = 0; i < 8; ++i)
            {
                var s = Console.ReadLine().ToCharArray();
                for (int j = 0; j < 8; j++)
                {
                    arr[i, j] = s[j];
                }
            }
            for (int j = 0; j < 8; ++j)
            {
                bool empty = true;
                int i = 0;
                while(empty && i<8)
                {
                    if (arr[i, j] != '.')
                    {
                        if (arr[i, j] == 'W')
                            minA = Math.Min(minA, i);
                        empty = false;
                    }
                    i++;
                }
                i = 7;
                empty = true;
                while (empty && i >=0)
                {
                    if (arr[i, j] != '.')
                    {
                        if (arr[i, j] == 'B')
                            minB = Math.Min(minB, 7-i);
                        empty = false;
                    }
                    i--;
                }
            }
            var winner = minA <= minB ? "A" : "B";
            Console.WriteLine(winner);
            //Console.ReadLine();
        }

        static void Main(string[] args)
        {
            var p = new Program();
            p.Solve();
            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();
        }
    }
}


using System;

using System.Text;

namespace Task1
{
    class Program

    {
        static string[] s = new string[8];
        static int getW(int i, int j)
        {
            i--;
        int k =0;
            for (k=0;i>=0; i--, k++)
                if (s[i][j]!='.'){return 9;}
            return k;
        }

        static int getB(int i, int j)
        {
            i++;
            int k = 0;
            for (k = 0; i <8; i++, k++)
                if (s[i][j] != '.') { return 9; }
            return k;
        }
        static void Main(string[] args)
        {

            for (int i = 0; i < 8; i++)
              s[i]= Console.ReadLine();
            int minW = 9, minB = 9;
            for(int i = 0; i< 8; i++)
                for (int j = 0; j < 8; j++)
                    if (s[i][j]=='W') minW = Math.Min(minW, getW(i,j));
                    else if (s[i][j]=='B') minB = Math.Min(minB, getB(i,j));
            if (minB >= minW) Console.WriteLine("A");
            else Console.WriteLine("B");

        }
    }
}


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

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

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

        string[] tokens;
        int pointer;

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

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

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

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

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

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

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

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

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

    class Program
    {
        MyIo io = new MyIo();

        enum State
        {
            Empty = 0,
            OwnerOnly = 1,
            WithGuest = 2
        }

        int R, C;

        State[,] map;

        Dictionary<long, int> memo;

        long makeConfig(int r, int c)
        {
            long cfg = 0;
            int lowR = Math.Max(0, r - 1);
            int highR = Math.Min(R - 1, r + 1);

            int abs = r * C + c;

            int lowAbs = Math.Max(0, abs - C);
            int highAbs = Math.Min(R * C - 1, abs + C);

            for (int curAbs = lowAbs; curAbs <= highAbs; curAbs++)
            {
                int curR = curAbs / C;
                int curC = curAbs % C;

                cfg <<= 2;
                cfg |= (uint)map[curR, curC];
            }
            cfg <<= 6;
            cfg |= (uint)r;
            cfg <<= 6;
            cfg |= (uint)c;

            return cfg;
        }

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

        int xfx(int r, int c)
        {
            if (r == R)
            {
                return 0;
            }
            if (c == C)
            {
                return xfx(r + 1, 0);
            }

            long cfg = makeConfig(r, c);
            if (memo.ContainsKey(cfg))
            {
                return memo[cfg];
            }

            if (map[r, c] == State.Empty)
            {
                return xfx(r, c + 1);
            }

            if (map[r, c] == State.WithGuest)
            {
                return xfx(r, c + 1);
            }

            int ans = xfx(r, c + 1); // no move

            map[r, c] = State.Empty;

            foreach (int[] d in dirs)
            {
                int nR = r + d[0];
                int nC = c + d[1];

                if (nR >= 0 && nR < R && nC >= 0 && nC < C)
                {
                    var oldState = map[nR, nC];
                    int curAns = oldState == State.Empty ? 0 : 1;

                    map[nR, nC] = State.WithGuest;

                    curAns += xfx(r, c + 1);
                    map[nR, nC] = oldState;

                    ans = Math.Max(ans, curAns);
                }
            }

            map[r, c] = State.OwnerOnly;

            memo[cfg] = ans;

            return ans;
        }

        void Solve()
        {
            memo = new Dictionary<long, int>();

            R = io.NextInt();
            C = io.NextInt();

            if (C > R)
            {
                R += C;
                C = R - C;
                R = R - C;
            }

            map = new State[R, C];

            for (int r = 0; r < R; r++)
            {
                for (int c = 0; c < C; c++)
                {
                    map[r, c] = State.OwnerOnly;
                }
            }

            int ans = xfx(0, 0);
            io.Print(ans);
        }

        static void Main(string[] args)
        {
            var p = new Program();
            p.Solve();
            p.io.Close();
        }
    }
}


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

namespace c1cs
{
    class Program
    {
        static void Main()
        {
            int ans = 0;
            string[] ss = Console.ReadLine().Split();
            int n = int.Parse(ss[0]);
            int m = int.Parse(ss[1]);
            if (n > m)
            {
                int a = n;
                n = m;
                m = a;
            }
            if (n == 1) ans = ((m - 1) / 3 + 1);
            if (n == 2) ans = m / 2 + 1;
            if (n == 3)
            {
                if (m < 5) ans = m;
                else
                {
                    int mo = (m - 5) / 4 + 1;
                    ans = m - mo;
                }
            }
            if (n == 4)
            {
                   if (m % 2 == 0) ans = m;
                   else ans = m + 1;
                   if (m == 6) ans = 7;
                   if (m == 7) ans = 7;
            }
            if (n == 5)
            {
                if (m == 5) ans = 7;
                if (m == 6) ans = 8;
                if (m == 7) ans = 9;
                if (m == 8) ans = 11;
            }
            if (n == 6) ans = (10);
            Console.WriteLine(n * m - ans);
        }
    }
}


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

namespace ProgrammingContest.Codeforces.Round85 {
    class C {
        static int[] ReadInts() { return Array.ConvertAll(Console.ReadLine().Split(' '), sss => int.Parse(sss)); }

        static int popcount(int n) { int res = 0; for (; n > 0; n &= n - 1)res++; return res; }

        static int n, m;
        static bool check(int v, int j) {
            int mask = (1 << m) - 1;
            return ((v | (v << 1) | (v >> 1) | j) & mask) == mask;
        }

        static void Main() {
            var xs = ReadInts();
            n = xs.Max();
            m = xs.Min();

            if (m == 1 && false) {
                Console.WriteLine(n == (n + 1) / 2);
                return;
            }

            var dp = new int[][,] { new int[1 << m, 1 << m], new int[1 << m, 1 << m] };

            for (int v = 0; v < 1 << m; v++)
                for (int j = 0; j < 1 << m; j++)
                    dp[0][v, j] = 1 << 29;

            dp[0][(1 << m) - 1, 0] = 0;

            int a = 0;
            for (int i = 0; i <= n; i++, a ^= 1) {
                var cur = dp[a];
                var next = dp[a ^ 1];

                for (int v = 0; v < 1 << m; v++)
                    for (int j = 0; j < 1 << m; j++)
                        next[v, j] = 1 << 29;

                for (int v = 0; v < 1 << m; v++) {
                    for (int j = 0; j < 1 << m; j++) {
                        for (int k = 0; k < 1 << m; k++) {
                            if (check(v, j | k)) {
                                next[v, k] = Math.Min(cur[j, v] + popcount(k), next[v, k]);
                            }
                        }
                    }
                }
            }

            int res = 1000000000;
            for (int v = 0; v < 1 << m; v++)
                for (int j = 0; j < 1 << m; j++)
                    res = Math.Min(res, dp[a][v, j]);
            Console.WriteLine(n * m - res);
        }
    }
}


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

namespace c1cs
{
    class Program
    {
        static void Main()
        {
            int ans = 0;
            string[] ss = Console.ReadLine().Split();
            int n = int.Parse(ss[0]);
            int m = int.Parse(ss[1]);
            if (n > m)
            {
                int a = n;
                n = m;
                m = a;
            }
            if (n == 1) ans = ((m - 1) / 3 + 1);
            if (n == 2) ans = m / 2 + 1;
            if (n == 3)
            {
                ans = (m / 5 * 4) + m % 5;
            }
            if (n == 4)
            {
                if (m % 4 == 0) ans = (m);
                else ans = (m + 1);
            }
            if (n == 5)
            {
                ans = (m + 2);
            }
            if (n == 6) ans = (10);
            Console.WriteLine(n * m - ans);
        }
    }
}


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

namespace c1cs
{
    class Program
    {
        static void Main()
        {
            int ans = 0;
            string[] ss = Console.ReadLine().Split();
            int n = int.Parse(ss[0]);
            int m = int.Parse(ss[1]);
            if (n > m)
            {
                int a = n;
                n = m;
                m = a;
            }
            if (n == 1) ans = ((m - 1) / 3 + 1);
            if (n == 2) ans = m / 2 + 1;
            if (n == 3)
            {
                if (m < 5) ans = m;
                else
                {
                    int mo = (m - 5) / 4 + 1;
                    ans = m - mo;
                }
            }
            if (n == 4)
            {
                   if (m % 2 == 0) ans = m;
                   else ans = m + 1;
                   if (m == 6) ans = 7;
            }
            if (n == 5)
            {
                if (m == 5) ans = 7;
                if (m == 6) ans = 8;
                if (m == 7) ans = 9;
                if (m == 8) ans = 11;
            }
            if (n == 6) ans = (10);
            Console.WriteLine(n * m - ans);
        }
    }
}


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

namespace c1cs
{
    class Program
    {
        static void Main()
        {
            string[] ss = Console.ReadLine().Split();
            int n = int.Parse(ss[0]);
            int m = int.Parse(ss[1]);
            if (n > m)
            {
                int a = n;
                n = m;
                m = a;
            }
            if (n == 1) Console.WriteLine((m - 1) / 3 + 1);
            if (n == 2) Console.WriteLine((m - 1) / 2 + 1);
            if (n == 3) Console.WriteLine(m);
            if (n == 4)
            {
                if (m % 4 == 0) Console.WriteLine(m);
                else Console.WriteLine(m + 1);
            }
            if (n == 5)
            {
                Console.WriteLine(m + 2);
            }
            if (n == 6) Console.WriteLine(10);
        }
    }
}


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

namespace ProgrammingContest.Codeforces.Round85 {
    class C {
        static int[] ReadInts() { return Array.ConvertAll(Console.ReadLine().Split(' '), sss => int.Parse(sss)); }

        static int popcount(int n) { int res = 0; for (; n > 0; n &= n - 1)res++; return res; }

        static int n, m;
        static bool check(int v, int j) {
            int mask = (1 << m) - 1;
            return ((v | (v << 1) | (v >> 1) | j) & mask) == mask;
        }

        static void Main() {
            var xs = ReadInts();
            n = xs.Max();
            m = xs.Min();

            if (m == 1) {
                Console.WriteLine((n + 1) / 2);
                return;
            }

            var dp = new int[][,] { new int[1 << m, 1 << m], new int[1 << m, 1 << m] };

            for (int v = 0; v < 1 << m; v++)
                for (int j = 0; j < 1 << m; j++)
                    dp[0][v, j] = 1 << 29;

            dp[0][(1 << m) - 1, 0] = 0;

            int a = 0;
            for (int i = 0; i <= n; i++, a ^= 1) {
                var cur = dp[a];
                var next = dp[a ^ 1];

                for (int v = 0; v < 1 << m; v++)
                    for (int j = 0; j < 1 << m; j++)
                        next[v, j] = 1 << 29;

                for (int v = 0; v < 1 << m; v++) {
                    for (int j = 0; j < 1 << m; j++) {
                        for (int k = 0; k < 1 << m; k++) {
                            if (check(v, j | k)) {
                                next[v, k] = Math.Min(cur[j, v] + popcount(k), next[v, k]);
                            }
                        }
                    }
                }
            }

            int res = 1000000000;
            for (int v = 0; v < 1 << m; v++)
                for (int j = 0; j < 1 << m; j++)
                    res = Math.Min(res, dp[a][v, j]);
            Console.WriteLine(n * m - res);
        }
    }
}


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

namespace Codeforces
{
    class D
    {
        static double[,] memo;
        static double Memo(int w, int b)
        {
            if (memo[w, b] < 0)
            {
                if (b == 2 && w == 1) memo[w, b] = 1.0 / 3;
                else if (w == 0) memo[w, b] = 0;
                else if (b == 0) memo[w, b] = 1;
                else if (b == 1) memo[w, b] = 1.0 * w / (w + 1);
                else if (b == 2 && w > 1) memo[w, b] = 1.0 * w / (w + 2) + 2.0 / (w + 2) * 1.0 / (w + 1);
                else
                {
                    double s = 1.0 * w / (w + b);
                    s += (1 - s) * (b - 1) / (w + b - 1) * (Memo(w, b - 3) * (b - 2) / (w + b - 2) + Memo(w - 1, b - 2) * w / (w + b - 2));
                    memo[w, b] = s;
                }
            }

            return memo[w, b];
        }

        private static object Go()
        {
            int w = GetInt();
            int b = GetInt();

            memo = new double[w+1,b+1];
            for (int i = 0; i < w+1; i++)
            {
                for (int j = 0; j < b+1; j++)
                {
                    memo[i, j] = -1f;
                }
            }

            return Memo(w, b).ToString(CultureInfo.InvariantCulture);
        }

        #region Template

        private static double err = 0.000000001;

        public static void Main(string[] args)
        {
            object output = Go();
            if (output != null)
                Wl<string>(output.ToString());
        }

        private static IEnumerator<string> ioEnum;
        private static string GetString()
        {
            while (ioEnum == null || !ioEnum.MoveNext())
            {
                ioEnum = Console.ReadLine().Split().AsEnumerable().GetEnumerator();
            }

            return ioEnum.Current;
        }

        private static int GetInt()
        {
            return int.Parse(GetString());
        }

        private static long GetLong()
        {
            return long.Parse(GetString());
        }

        private static double GetDouble()
        {
            return double.Parse(GetString());
        }

        private static void Wl<T>(T o)
        {
            Console.WriteLine(o.ToString());
        }

        private static void Wl<T>(IEnumerable<T> enumerable)
        {
            Wl(string.Join(" ", enumerable.Select(e => e.ToString()).ToArray()));
        }

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

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

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

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

            public override string ToString()
            {
                return "(" + Item1 + " " + Item2 + ")";
            }
        }

        #endregion
    }
}


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

namespace Codeforces
{
    internal class Program
    {
        private static string Read()
        {
            return Console.ReadLine();
        }
        private static string[] ReadArray()
        {
            return Console.ReadLine().Split(' ');
        }
        private static int ReadInt()
        {
            return Int32.Parse(Console.ReadLine());
        }
        private static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static int ReadNextInt(string[] input, int index)
        {
            return Int32.Parse(input[index]);
        }

        private static void Main()
        {
            var input = ReadArray();
            var w = ReadNextInt(input, 0);
            var b = ReadNextInt(input, 1);
            var dp = new double[w + 1,b + 1];
            for (int i = 1; i < w + 1; i++)
            {
                dp[i, 0] = 1;
            }
            for (int i = 1; i < w + 1; i++)
            {
                for (int j = 1; j < b + 1; j++)
                {
                    dp[i, j] = (double) i/(i + j);
                    dp[i, j] += (double) j/(i + j)*(j - 1)/(i + j - 1)
                                *
                                ((double) (j - 2)/(i + j - 2)*dp[i, Math.Max(0, j - 3)] +
                                 (double)(i) / (i + j - 2) * dp[i - 1, Math.Max(0, j - 2)]);
                }
            }
            Console.WriteLine(dp[w,b]);
        }

    }
}


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

namespace ConsoleApplication1
{
  class Program
  {

    static double[,] dp;

    static double solve(int w, int b)
    {
      if (dp[w,b] == -1)
      {
        dp[w, b] = (double) w / (w + b);
        if (b > 1)
          dp[w, b] += ((double)b / (w + b)) * ((double)(b - 1) / (w + b - 1)) * ((double)(w) / (w + b - 2)) * solve(w - 1, b - 2);
        if (b > 2)
          dp[w, b] += ((double)b / (w + b)) * ((double)(b - 1) / (w + b - 1)) * ((double)(b - 2) / (w + b - 2)) * solve(w, b - 3);
      }
      return dp[w,b];
    }

    static void Main(string[] args)
    {
      string[] readen = Console.ReadLine().Split(' ');
      int w = int.Parse(readen[0]);
      int b = int.Parse(readen[1]);
      dp = new double[w+1, b+1];
      for (int i = 0; i <= w; i++)
        for (int j = 0; j <= b; j++)
          dp[i, j] = -1;
      for (int i = 0; i <= w; i++)
        dp[i, 0] = 1;
      for (int i = 0; i <= b; i++)
        dp[0, i] = 0;
      Console.WriteLine(solve(w, b));
    }
  }
}


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

public class Program
{
    int N;
    string S;
    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        S = sc.Next();
        int l = S.Length;

        int cnt = 0;
        int min = 0;
        for (int i = 0; i < l; i++)
        {
            if (S[i] == '(') cnt++;
            else cnt--;
            min = Math.Min(min, cnt);
        }

        // i番目まで入れた
        // カウンタ
        // Sを入れたか?
        var dp = new ModInt[2 * N + 1, 201, 2];
        dp[0, 0, 0] = 1;
        for (int i = 0; i < 2 * N; i++)
        {
            for (int j = 0; j <= 200; j++)
            {
                // (を追加
                if (j + 1 <= 200)
                {
                    dp[i + 1, j + 1, 0] += dp[i, j, 0];
                    dp[i + 1, j + 1, 1] += dp[i, j, 1];
                }
                // )
                if (j - 1 >= 0)
                {
                    dp[i + 1, j - 1, 0] += dp[i, j, 0];
                    dp[i + 1, j - 1, 1] += dp[i, j, 1];
                }

                // s
                if (i + l <= 2 * N && j + min >= 0 && j + cnt <= 200)
                {
                    dp[i + l, j + cnt, 1] += dp[i, j, 0];
                }
            }
        }

        Console.WriteLine(dp[2 * N, 0, 1]);
    }

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

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

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

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

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

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

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

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

// https://bitbucket.org/camypaper/complib
namespace CompLib.Mathematics
{
    #region ModInt
    /// <summary>
    /// [0,<see cref="Mod"/>) までの値を取るような数
    /// </summary>
    public struct ModInt
    {
        /// <summary>
        /// 剰余を取る値．
        /// </summary>
        public const long Mod = (int)1e9 + 7;

        /// <summary>
        /// 実際の数値．
        /// </summary>
        public long num;
        /// <summary>
        /// 値が <paramref name="n"/> であるようなインスタンスを構築します．
        /// </summary>
        /// <param name="n">インスタンスが持つ値</param>
        /// <remarks>パフォーマンスの問題上，コンストラクタ内では剰余を取りません．そのため，<paramref name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/> を渡してください．このコンストラクタは O(1) で実行されます．</remarks>
        public ModInt(long n) { num = n; }
        /// <summary>
        /// このインスタンスの数値を文字列に変換します．
        /// </summary>
        /// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10 進表記したもの．</returns>
        public override string ToString() { return num.ToString(); }
        public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; }
        public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; }
        public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); }
        public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); }

        /// <summary>
        /// 与えられた 2 つの数値からべき剰余を計算します．
        /// </summary>
        /// <param name="v">べき乗の底</param>
        /// <param name="k">べき指数</param>
        /// <returns>繰り返し二乗法により O(N log N) で実行されます．</returns>
        public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }

        /// <summary>
        /// 与えられた 2 つの数値からべき剰余を計算します．
        /// </summary>
        /// <param name="v">べき乗の底</param>
        /// <param name="k">べき指数</param>
        /// <returns>繰り返し二乗法により O(N log N) で実行されます．</returns>
        public static ModInt Pow(long v, long k)
        {
            long ret = 1;
            for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
                if ((k & 1) == 1) ret = ret * v % Mod;
            return new ModInt(ret);
        }
        /// <summary>
        /// 与えられた数の逆元を計算します．
        /// </summary>
        /// <param name="v">逆元を取る対象となる数</param>
        /// <returns>逆元となるような値</returns>
        /// <remarks>法が素数であることを仮定して，フェルマーの小定理に従って逆元を O(log N) で計算します．</remarks>
        public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
    }
    #endregion
    #region Binomial Coefficient
    public class BinomialCoefficient
    {
        public ModInt[] fact, ifact;
        public BinomialCoefficient(int n)
        {
            fact = new ModInt[n + 1];
            ifact = new ModInt[n + 1];
            fact[0] = 1;
            for (int i = 1; i <= n; i++)
                fact[i] = fact[i - 1] * i;
            ifact[n] = ModInt.Inverse(fact[n]);
            for (int i = n - 1; i >= 0; i--)
                ifact[i] = ifact[i + 1] * (i + 1);
            ifact[0] = ifact[1];
        }
        public ModInt this[int n, int r]
        {
            get
            {
                if (n < 0 || n >= fact.Length || r < 0 || r > n) return 0;
                return fact[n] * ifact[n - r] * ifact[r];
            }
        }
        public ModInt RepeatedCombination(int n, int k)
        {
            if (k == 0) return 1;
            return this[n + k - 1, k];
        }
    }
    #endregion
}


using System;
using System.Linq;
using CompLib.Util;
using System.Threading;
using CompLib.Mathematics;

public class Program
{
    int N;
    string S;
    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        S = sc.Next();

        int cnt = 0;
        int min = 0;
        foreach (var c in S)
        {
            if (c == '(') cnt++;
            else cnt--;
            min = Math.Min(min, cnt);
        }
        /*
         * Sを部分文字列に含むカッコ列の個数
         */

        // i文字目まで作る、カウンタ、Sより前、Sより後
        var dp = new ModInt[2 * N + 1, N + 1, 2];
        dp[0, 0, 0] = 1;
        for (int i = 0; i < 2 * N; i++)
        {
            for (int j = 0; j <= N; j++)
            {
                // (
                if (j + 1 <= N)
                {
                    dp[i + 1, j + 1, 0] += dp[i, j, 0];
                    dp[i + 1, j + 1, 1] += dp[i, j, 1];
                }

                // )
                if (j - 1 >= 0)
                {
                    dp[i + 1, j - 1, 0] += dp[i, j, 0];
                    dp[i + 1, j - 1, 1] += dp[i, j, 1];
                }

                if (i + S.Length <= 2 * N && j + min >= 0 && j + cnt <= N)
                {
                    dp[i + S.Length, j + cnt, 1] += dp[i, j, 0];
                    dp[i + S.Length, j + cnt, 0] -= dp[i, j, 0];
                }
            }
        }

        Console.WriteLine(dp[2 * N, 0, 1]);
    }

    public static void Main(string[] args) => new Program().Solve();
    // public static void Main(string[] args) => new Thread(new Program().Solve, 1 << 27).Start();
}

// https://bitbucket.org/camypaper/complib
namespace CompLib.Mathematics
{
    #region ModInt
    /// <summary>
    /// [0,<see cref="Mod"/>) までの値を取るような数
    /// </summary>
    public struct ModInt
    {
        /// <summary>
        /// 剰余を取る値．
        /// </summary>
        public const long Mod = (int)1e9 + 7;
        // public const long Mod = 998244353;

        /// <summary>
        /// 実際の数値．
        /// </summary>
        public long num;
        /// <summary>
        /// 値が <paramref name="n"/> であるようなインスタンスを構築します．
        /// </summary>
        /// <param name="n">インスタンスが持つ値</param>
        /// <remarks>パフォーマンスの問題上，コンストラクタ内では剰余を取りません．そのため，<paramref name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/> を渡してください．このコンストラクタは O(1) で実行されます．</remarks>
        public ModInt(long n) { num = n; }
        /// <summary>
        /// このインスタンスの数値を文字列に変換します．
        /// </summary>
        /// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10 進表記したもの．</returns>
        public override string ToString() { return num.ToString(); }
        public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; }
        public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; }
        public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); }
        public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); }

        /// <summary>
        /// 与えられた 2 つの数値からべき剰余を計算します．
        /// </summary>
        /// <param name="v">べき乗の底</param>
        /// <param name="k">べき指数</param>
        /// <returns>繰り返し二乗法により O(N log N) で実行されます．</returns>
        public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }

        /// <summary>
        /// 与えられた 2 つの数値からべき剰余を計算します．
        /// </summary>
        /// <param name="v">べき乗の底</param>
        /// <param name="k">べき指数</param>
        /// <returns>繰り返し二乗法により O(N log N) で実行されます．</returns>
        public static ModInt Pow(long v, long k)
        {
            long ret = 1;
            for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
                if ((k & 1) == 1) ret = ret * v % Mod;
            return new ModInt(ret);
        }
        /// <summary>
        /// 与えられた数の逆元を計算します．
        /// </summary>
        /// <param name="v">逆元を取る対象となる数</param>
        /// <returns>逆元となるような値</returns>
        /// <remarks>法が素数であることを仮定して，フェルマーの小定理に従って逆元を O(log N) で計算します．</remarks>
        public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
    }
    #endregion
    #region Binomial Coefficient
    public class BinomialCoefficient
    {
        public ModInt[] fact, ifact;
        public BinomialCoefficient(int n)
        {
            fact = new ModInt[n + 1];
            ifact = new ModInt[n + 1];
            fact[0] = 1;
            for (int i = 1; i <= n; i++)
                fact[i] = fact[i - 1] * i;
            ifact[n] = ModInt.Inverse(fact[n]);
            for (int i = n - 1; i >= 0; i--)
                ifact[i] = ifact[i + 1] * (i + 1);
            ifact[0] = ifact[1];
        }
        public ModInt this[int n, int r]
        {
            get
            {
                if (n < 0 || n >= fact.Length || r < 0 || r > n) return 0;
                return fact[n] * ifact[n - r] * ifact[r];
            }
        }
        public ModInt RepeatedCombination(int n, int k)
        {
            if (k == 0) return 1;
            return this[n + k - 1, k];
        }
    }
    #endregion
}

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

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

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

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

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

            return _line[_index++];
        }

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

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

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

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