#define Online

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

namespace CF
{
    delegate double F(double x);
    delegate decimal Fdec(decimal x);

    partial class Program
    {

        static void Main(string[] args)
        {

#if FileIO
            StreamReader sr = new StreamReader("input.txt");
            StreamWriter sw = new StreamWriter("output.txt");
            Console.SetIn(sr);
            Console.SetOut(sw);
#endif

            D();

#if Online
            Console.ReadLine();
#endif

#if FileIO
            sr.Close();
            sw.Close();
#endif
        }

        static void A()
        {
            StringBuilder sb = new StringBuilder();
            string str = ReadLine();
            for (int i = 0; i < str.Length; i++)
            {
                if (!str[i].Equals('a') && !str[i].Equals('A')
                    && !str[i].Equals('o') && !str[i].Equals('O')
                    && !str[i].Equals('y') && !str[i].Equals('Y')
                    && !str[i].Equals('e') && !str[i].Equals('E')
                    && !str[i].Equals('u') && !str[i].Equals('U')
                    && !str[i].Equals('i') && !str[i].Equals('I'))
                {
                    sb.Append('.');
                    if (str[i] < 97)
                        sb.Append(char.ToLower(str[i]));
                    else
                        sb.Append(str[i]);

                }
            }
            Console.WriteLine(sb);
        }

        static void B()
        {
            int n = ReadInt();
            int[,] ans = new int[2 * n + 1, 2 * n + 1];
            for (int i = 0; i < 2 * n + 1; i++)
            {
                int z = (i > n ? n - (i - n) : i);
                ans[i, n] = z;
                for (int j = 0; j < n; j++)
                {
                    ans[i, n - j - 1] = z - j - 1;
                    ans[i, n + j + 1] = z - j - 1;
                }
            }
            for (int i = 0; i < 2 * n + 1; i++)
            {
                int j = 0;
                while (j < 2 * n + 1 && ans[i, j] < 0)
                {
                    Console.Write("  ");
                    j++;
                }
                Console.Write(ans[i, j++]);
                while (j < 2 * n + 1 && ans[i, j] >= 0)
                {
                    Console.Write(" " + ans[i, j]);
                    j++;
                }

                Console.WriteLine();
            }
        }

        static void C()
        {

        }

        static void D()
        {
            int n1, n2, k1, k2;
            const long mod = 100000000L;
            ReadArray(' ');
            n1 = NextInt();
            n2 = NextInt();
            k1 = NextInt();
            k2 = NextInt();
            long[,] p = new long[n1, n1 + 1];
            long[,] h = new long[n2, n2 + 1];
            for (int i = 1; i <= k1 && i <= n1; i++)
                p[0, i] = 1;
            for (int i = 1; i <= k2 && i <= n2; i++)
                h[0, i] = 1;
            for (int i = 1; i < n1; i++)
            {
                for (int j = 1; j <= k1; j++)
                {
                    for (int z = 1; z <= n1; z++)
                    {
                        if (z + j <= n1)
                        {
                            p[i, z + j] += p[i - 1, z];
                            p[i, z + j] %= mod;
                        }
                    }
                }
            }
            for (int i = 1; i < n2; i++)
            {
                for (int j = 1; j <= k2; j++)
                {
                    for (int z = 1; z <= n2; z++)
                    {
                        if (z + j <= n2)
                        {
                            h[i, z + j] += h[i - 1, z];
                            h[i, z + j] %= mod;
                        }
                    }
                }
            }
            long sum = 0;
            for (int i = 0; i < n1; i++)
            {
                if (i < n2)
                    sum += p[i, n1] * h[i, n2] * 2;
                if (i + 1 < n2)
                    sum += p[i, n1] * h[i + 1, n2];
                if (i - 1 >= 0 && i - 1 < n2)
                    sum += p[i, n1] * h[i - 1, n2];
                sum %= mod;
            }
            Console.WriteLine(sum);
        }

        static void E()
        {

        }

        static void TestGen()
        {

        }

    }

    public static class MyMath
    {
        public static long BinPow(long a, long n, long mod)
        {
            long res = 1;
            while (n > 0)
            {
                if ((n & 1) == 1)
                {
                    res = (res * a) % mod;
                }
                a = (a * a) % mod;
                n >>= 1;
            }
            return res;
        }

        public static long GCD(long a, long b)
        {
            while (b != 0) b = a % (a = b);
            return a;
        }

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

        public static long LCM(long a, long b)
        {
            return (a * b) / GCD(a, b);
        }

        public static int LCM(int a, int b)
        {
            return (a * b) / GCD(a, b);
        }
    }

    static class ArrayUtils
    {
        public static int BinarySearch(int[] a, int val)
        {
            int left = 0;
            int right = a.Length - 1;
            int mid;

            while (left < right)
            {
                mid = left + ((right - left) >> 1);
                if (val <= a[mid])
                {
                    right = mid;
                }
                else
                {
                    left = mid + 1;
                }
            }

            if (a[left] == val)
                return left;
            else
                return -1;
        }

        public static double Bisection(F f, double left, double right, double eps)
        {
            double mid;
            while (right - left > eps)
            {
                mid = left + ((right - left) / 2d);
                if (Math.Sign(f(mid)) != Math.Sign(f(left)))
                    right = mid;
                else
                    left = mid;
            }
            return (left + right) / 2d;
        }

        public static decimal TernarySearchDec(Fdec f, decimal eps, decimal l, decimal r, bool isMax)
        {
            decimal m1, m2;
            while (r - l > eps)
            {
                m1 = l + (r - l) / 3m;
                m2 = r - (r - l) / 3m;
                if (f(m1) < f(m2))
                    if (isMax)
                        l = m1;
                    else
                        r = m2;
                else
                    if (isMax)
                        r = m2;
                    else
                        l = m1;
            }
            return r;
        }

        public static double TernarySearch(F f, double eps, double l, double r, bool isMax)
        {
            double m1, m2;
            while (r - l > eps)
            {
                m1 = l + (r - l) / 3d;
                m2 = r - (r - l) / 3d;
                if (f(m1) < f(m2))
                    if (isMax)
                        l = m1;
                    else
                        r = m2;
                else
                    if (isMax)
                        r = m2;
                    else
                        l = m1;
            }
            return r;
        }

        public static void Merge<T>(T[] A, int p, int q, int r, T[] L, T[] R, Comparison<T> comp)
        {
            for (int i = p; i <= q; i++)
                L[i] = A[i];
            for (int i = q + 1; i <= r; i++)
                R[i] = A[i];

            for (int k = p, i = p, j = q + 1; k <= r; k++)
            {
                if (i > q)
                {
                    for (; k <= r; k++, j++)
                        A[k] = R[j];
                    return;
                }
                if (j > r)
                {
                    for (; k <= r; k++, i++)
                        A[k] = L[i];
                    return;
                }
                if (comp(L[i], R[j]) <= 0)
                {
                    A[k] = L[i];
                    i++;
                }
                else
                {
                    A[k] = R[j];
                    j++;
                }
            }
        }

        public static void Merge_Sort<T>(T[] A, int p, int r, T[] L, T[] R, Comparison<T> comp)
        {
            if (p >= r) return;
            int q = p + ((r - p) >> 1);
            Merge_Sort(A, p, q, L, R, comp);
            Merge_Sort(A, q + 1, r, L, R, comp);
            Merge(A, p, q, r, L, R, comp);
        }

        public static void Merge<T>(T[] A, int p, int q, int r, T[] L, T[] R) where T : IComparable<T>
        {
            for (int i = p; i <= q; i++)
                L[i] = A[i];
            for (int i = q + 1; i <= r; i++)
                R[i] = A[i];

            for (int k = p, i = p, j = q + 1; k <= r; k++)
            {
                if (i > q)
                {
                    for (; k <= r; k++, j++)
                        A[k] = R[j];
                    return;
                }
                if (j > r)
                {
                    for (; k <= r; k++, i++)
                        A[k] = L[i];
                    return;
                }
                if (L[i].CompareTo(R[j]) >= 0)
                {
                    A[k] = L[i];
                    i++;
                }
                else
                {
                    A[k] = R[j];
                    j++;
                }
            }
        }

        public static void Merge_Sort<T>(T[] A, int p, int r, T[] L, T[] R) where T : IComparable<T>
        {
            if (p >= r) return;
            int q = p + ((r - p) >> 1);
            Merge_Sort(A, p, q, L, R);
            Merge_Sort(A, q + 1, r, L, R);
            Merge(A, p, q, r, L, R);
        }

        public static void Merge_Sort1<T>(T[] A, int p, int r, T[] L, T[] R) where T : IComparable<T>
        {
            int k = 1;
            while (k < r - p + 1)
            {
                int i = 0;
                while (i < r)
                {
                    int _r = Math.Min(i + 2 * k - 1, r);
                    int q = Math.Min(i + k - 1, r);
                    Merge(A, i, q, _r, L, R);
                    i += 2 * k;
                }
                k <<= 1;
            }
        }

        public static void Merge_Sort1<T>(T[] A, int p, int r, T[] L, T[] R, Comparison<T> comp)
        {
            int k = 1;
            while (k < r - p + 1)
            {
                int i = 0;
                while (i < r)
                {
                    int _r = Math.Min(i + 2 * k - 1, r);
                    int q = Math.Min(i + k - 1, r);
                    Merge(A, i, q, _r, L, R, comp);
                    i += 2 * k;
                }
                k <<= 1;
            }
        }

        static void Shake<T>(T[] a)
        {
            Random rnd = new Random(Environment.TickCount);
            T temp;
            int b, c;
            for (int i = 0; i < a.Length; i++)
            {
                b = rnd.Next(0, a.Length);
                c = rnd.Next(0, a.Length);
                temp = a[b];
                a[b] = a[c];
                a[c] = temp;
            }
        }
    }

    partial class Program
    {
        static string[] tokens;
        static int cur_token = 0;

        static void ReadArray(char sep)
        {
            cur_token = 0;
            tokens = Console.ReadLine().Split(sep);
        }

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

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

        static int NextInt()
        {
            return int.Parse(tokens[cur_token++]);
        }

        static long NextLong()
        {
            return long.Parse(tokens[cur_token++]);
        }

        static double NextDouble()
        {
            return double.Parse(tokens[cur_token++]);
        }

        static decimal NextDecimal()
        {
            return decimal.Parse(tokens[cur_token++]);
        }

        static string NextToken()
        {
            return tokens[cur_token++];
        }

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


using System;
using System.Linq;

namespace B_Segments
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int result = Enumerable.Range(0, 50).Select(i => i * 2).Select(i => n - i).Where(i => i > 0).Sum();
            Console.WriteLine(result);
        }
    }
}


using System;

namespace CSharp
{
    class _909B
    {
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());

            var diff = new int[n + 1];
            for (int i = 0; i < n; i++)
            {
                for (int j = i + 1; j <= n; j++)
                {
                    diff[i]++;
                    diff[j]--;
                }
            }

            int layers = 0;

            for (int i = 0, count = 0; i < n; i++)
            {
                count += diff[i];
                layers = Math.Max(layers, count);
            }

            Console.WriteLine(layers);
        }
    }
}


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

namespace ExTraining
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int sum1 = Console.ReadLine()
                .Split()
                .Select(s => int.Parse(s))
                .Sum();
            int sum2 = Console.ReadLine()
                .Split()
                .Select(s => int.Parse(s))
                .Sum();

            if (sum1 >= sum2)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }

    }
}


using System;
using System.Linq;

namespace CSharp
{
    public class _1013A
    {
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            int[] x = Console.ReadLine().Split().Select(token => int.Parse(token)).ToArray();
            int[] y = Console.ReadLine().Split().Select(token => int.Parse(token)).ToArray();

            Console.WriteLine(x.Sum() >= y.Sum() ? "Yes" : "No");
        }
    }
}


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Numerics;
using static System.Math;

namespace CompetitiveProgramming
{
	class Program
	{
		public static void Main()
		{
			var ints = Console.ReadLine().Split().Select(long.Parse).ToArray();

			var n = ints[0];
			var mod = ints[1];

			for (int i = 1; i < Inverses.Length; i++)
				Inverses[i] = ModularMultiplicativeInverse(i, mod);

			var cur = new long[,]
			{
				{0,0,0 },
				{0,0,0 },
				{0,0,2 },
				{4,0,0 },
			};

			for (var i = 0; i < n - 3; i++)
				cur = GetNext(cur, mod);

			long res = 0;

			for (int i = 0; i < cur.GetLength(0); i++)
				for (int j = 0; j < cur.GetLength(1); j++)
					res += cur[i, j];

			Console.WriteLine(res % mod);
		}

		private static readonly long[] Inverses = new long[500];

		public static long[,] GetNext(long[,] current, long mod)
		{
			var total = current.GetLength(0) - 1;
			var next = new long[total + 2, total + 1];

			for (int i = 0; i <= total; i++)
				for (int last = 0; last < total; last++)
				{
					var prev = current[i, last];
					if (prev == 0)
						continue;

					var dist = total + 1 - last;

					var nVal = prev * 2 * (i + 1) % mod * Inverses[dist] % mod;
					next[i + 1, last] = (next[i + 1, last] + nVal) % mod;

					if (last != total - 1)
					{
						var val = prev * Inverses[2] % mod * (dist - 1) % mod;
						next[i, total] = (next[i, total] + val) % mod;
					}
				}

			return next;
		}

		public static long ModularMultiplicativeInverse(long remainder, long mod)
		{
			if (mod == 1)
				return 0;

			var other = mod;
			long next = 0;
			long inverse = 1;

			while (remainder > 1)
			{
				(inverse, next) = (next, inverse - remainder / other * next);
				(remainder, other) = (other, remainder % other);
			}

			if (inverse < 0)
				inverse += mod;

			return inverse;
		}

		public static List<int[]> GetPermutations(int[] list)
		{
			int x = list.Length - 1;
			var result = new List<int[]>();
			GetPermutationsRec(list, result, 0, x);
			return result;
		}

		private static void GetPermutationsRec(int[] list, List<int[]> result, int k, int m)
		{
			if (k == m)
				result.Add(list.ToArray());
			else
				for (int i = k; i <= m; i++)
				{
					Swap(ref list[k], ref list[i]);
					GetPermutationsRec(list, result, k + 1, m);
					Swap(ref list[k], ref list[i]);
				}
		}

		private class Perm
		{
			public List<int> vals;
			public Perm missing;

			public Perm(int[] vals)
			{
				if (vals.Length == 0)
				{
					this.vals = new List<int>();
					return;
				}

				var isIn = new bool[15];
				var nl = new List<int>();
				var ms = new List<int>();
				foreach (var v in vals)
				{
					isIn[v] = true;
					if (isIn[v - 1] && isIn[v + 1])
					{
						ms.Add(v);
					}
					else
						nl.Add(v);
				}

				ms.Sort();

				this.missing = new Perm(ms.ToArray());

				this.vals = nl;
			}

			public override bool Equals(object obj)
			{
				var mType = obj as Perm;
				if (mType == null)
					return false;

				return mType.vals.SequenceEqual(vals);
			}

			public override int GetHashCode()
			{
				int seed = vals.Count;
				const int lul = (int)(0x9e3779b9 - int.MaxValue / 2);

				foreach (var v in vals)
				{
					seed ^= v + lul + (seed << 6) + (seed >> 2);
				}

				return seed;
			}

			public override string ToString()
			{
				return '{' + string.Join(' ', vals) + '}';
			}
		}

		private static void NewMethod1()
		{
			var cases = int.Parse(Console.ReadLine());
			var sols = new int[cases];

			for (int @case = 0; @case < cases; @case++)
			{
				var ints = Console.ReadLine().Split().Select(int.Parse).ToArray();
				var n = ints[0];
				var l = ints[1];
				var r = ints[2];

				var socks = Console.ReadLine().Split().Select(int.Parse).ToArray();
				var colorCount = socks.Max() + 1;

				var colorCountsL = new int[colorCount];
				var colorCountsR = new int[colorCount];

				for (int i = 0; i < l; i++)
					colorCountsL[socks[i]]++;

				for (int i = l; i < n; i++)
					colorCountsR[socks[i]]++;

				if (l < r)
				{
					Swap(ref colorCountsL, ref colorCountsR);
					Swap(ref l, ref r);
				}

				var diff = (l - r) / 2;

				for (int i = 0; i < colorCount; i++)
				{
					var min = Min(colorCountsL[i], colorCountsR[i]);
					colorCountsL[i] -= min;
					colorCountsR[i] -= min;

					var changedColor = Min(colorCountsL[i] / 2, diff);
					{
						colorCountsL[i] -= 2 * changedColor;
						diff -= changedColor;
					}
				}

				sols[@case] = (l - r) / 2 + (colorCountsR.Sum() + colorCountsL.Sum()) / 2;

				// staramy sie wyrownac liczbe kolorow miedzy prawymi a lewymi
				// wiemy ze lewych jest wiecej rowno prawych
			}

			sols.ToList().ForEach(x => Console.WriteLine(x));
		}

		public static void Swap<T>(ref T a, ref T b)
		{
			T t = a;
			a = b;
			b = t;
		}

		private static void NewMethod()
		{
			var sqrt = (int)Math.Sqrt(int.MaxValue / 2);
			var squares = Enumerable.Range(1, sqrt).Select(x => x * x).ToHashSet();

			var cases = int.Parse(Console.ReadLine());
			var sols = new bool[cases];

			for (int @case = 0; @case < cases; @case++)
			{
				var n = int.Parse(Console.ReadLine());
				sols[@case] = (n % 2 == 0 && squares.Contains(n / 2)) || (n % 4 == 0 && squares.Contains(n / 4));
			}

			sols.ToList().ForEach(x => Console.WriteLine(x ? "YES" : "NO"));
		}

		private static void RunCaseA()
		{
			var ints = Console.ReadLine().Split().Select(int.Parse).ToArray();
			var n = ints[0];
			var k = ints[1];

			var vals = Console.ReadLine().Split().Select(int.Parse).ToArray();
			var total = vals.Sum();
			if (k != total)
			{

				var sol = new List<int>();
				var current = 0;

				for (int i = 0; i < vals.Length; i++)
				{
					if (current + vals[i] == k)
					{
						current += vals[i] + vals[i + 1];
						sol.Add(vals[i + 1]);
						sol.Add(vals[i]);
						i += 1;
					}
					else
					{
						sol.Add(vals[i]);
						current += vals[i];
					}
				}
			}
		}

		static void PrintSol(int[] sol)
		{
			if (sol == null)
				Console.WriteLine("NO");
			else
			{
				Console.WriteLine("YES");
				Console.WriteLine(string.Join(' ', sol));
			}
		}

		public static long LowerBound(long min, long max, Predicate<long> test)
		{
			long e = max;
			long s = min;

			while (s < e)
			{
				long mid = (s + e) / 2;
				if (test(mid))
					e = mid;
				else
					s = mid + 1;
			}

			return e;
		}

		public static long UpperBound(long min, long max, Predicate<long> test)
		{
			long s = min;
			long e = max;

			while (s < e)
			{
				long mid = (s + e) / 2;
				if (test(mid))
					s = mid + 1;
				else
					e = mid;
			}

			return s - 1;
		}

		public static (int, int)[] GetPairs(int count)
		{
			var qs = new (int, int)[count];
			for (int i = 0; i < count; i++)
			{
				var line = Console.ReadLine();
				int spacePos = 1;
				while (line[spacePos] != ' ')
					spacePos++;

				var l = int.Parse(line.AsSpan(0, spacePos));
				var r = int.Parse(line.AsSpan(spacePos + 1, line.Length - spacePos - 1));
				qs[i] = (l - 1, r - 1);
			}

			return qs;
		}

		public static int[] GetInts(int count)
		{
			var str = Console.ReadLine();
			var a = new int[count];

			var currentStart = 0;
			for (int i = 0; i < count - 1; i++)
			{
				int currentEnd = currentStart + 1;
				while (str[currentEnd] != ' ')
					currentEnd++;

				a[i] = int.Parse(str.AsSpan(currentStart, currentEnd - currentStart));
				currentStart = currentEnd + 1;
			}

			a[a.Length - 1] = int.Parse(str.AsSpan(currentStart, str.Length - currentStart));
			return a;
		}
	}

}


using System;
using System.Linq;

class E
{
	static int[] Read() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
	static (int, int) Read2() { var a = Read(); return (a[0], a[1]); }
	static void Main() => Console.WriteLine(Solve());
	static object Solve()
	{
		(int n, long M) = Read2();

		var mc = new MCombination(n + 1, M);

		// 長さ i の区間を j steps でオンにする方法
		var dp2 = new MemoDP2<long>(n + 1, n + 1, -1, (dp, i, j) =>
		{
			var d = i - j - 1;
			var v = 0L;

			for (int k = 1; k < j; k++)
			{
				v += dp[k + d, k] * dp[j - k, j - k] % M * mc.MNcr(j, k) % M;
			}
			return v % M;
		});

		for (int i = 0; i <= n; i++)
		{
			for (int j = 0; i >= 2 * j; j++)
			{
				dp2[i, j] = 0;
			}
		}

		dp2[1, 1] = 1;
		for (int i = 1; i < n; i++)
		{
			dp2[i + 1, i + 1] = dp2[i, i] * 2 % M;
		}

		return Enumerable.Range(1, n).Sum(j => dp2[n, j]) % M;
	}
}

class MemoDP2<T>
{
	static readonly Func<T, T, bool> TEquals = System.Collections.Generic.EqualityComparer<T>.Default.Equals;
	public T[,] Raw { get; }
	T iv;
	Func<MemoDP2<T>, int, int, T> rec;

	public MemoDP2(int n1, int n2, T iv, Func<MemoDP2<T>, int, int, T> rec)
	{
		Raw = new T[n1, n2];
		for (int i = 0; i < n1; ++i)
			for (int j = 0; j < n2; ++j)
				Raw[i, j] = iv;
		this.iv = iv;
		this.rec = rec;
	}

	public T this[int i, int j]
	{
		get => TEquals(Raw[i, j], iv) ? Raw[i, j] = rec(this, i, j) : Raw[i, j];
		set => Raw[i, j] = value;
	}
}

public class MCombination
{
	long M;
	long MPow(long b, long i)
	{
		long r = 1;
		for (; i != 0; b = b * b % M, i >>= 1) if ((i & 1) != 0) r = r * b % M;
		return r;
	}
	long MInv(long x) => MPow(x, M - 2);

	long[] MFactorials(int n)
	{
		var f = new long[n + 1];
		f[0] = 1;
		for (int i = 1; i <= n; ++i) f[i] = f[i - 1] * i % M;
		return f;
	}

	// nPr, nCr を O(1) で求めるため、階乗を O(n) で求めておきます。
	long[] f, f_;
	public MCombination(int nMax, long M)
	{
		this.M = M;
		f = MFactorials(nMax);
		f_ = Array.ConvertAll(f, MInv);
	}

	public long MFactorial(int n) => f[n];
	public long MInvFactorial(int n) => f_[n];
	public long MNpr(int n, int r) => n < r ? 0 : f[n] * f_[n - r] % M;
	public long MNcr(int n, int r) => n < r ? 0 : f[n] * f_[n - r] % M * f_[r] % M;
}


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

namespace ReadWriteTemplate
{
    public static class Solver
    {
        private static void SolveCase()
        {
            int n = ReadInt();
            string[] a = new string[n];
            string[] b = new string[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadLine();
            }
            for (int i = 0; i < n; i++)
            {
                b[i] = ReadLine();
            }

            Func<Point, Point> rotate = point => new Point(point.Y, n - 1 - point.X);
            Func<Point, Point> flip = point => new Point(n - 1 - point.X, point.Y);

            if (Check(n, a, b, point => point) ||
                Check(n, a, b, point => rotate(point)) ||
                Check(n, a, b, point => rotate(rotate(point))) ||
                Check(n, a, b, point => rotate(rotate(rotate(point)))) ||
                Check(n, a, b, point => flip(point)) ||
                Check(n, a, b, point => flip(rotate(point))) ||
                Check(n, a, b, point => flip(rotate(rotate(point)))) ||
                Check(n, a, b, point => flip(rotate(rotate(rotate(point))))))
            {
                Writer.WriteLine("Yes");
            }
            else
            {
                Writer.WriteLine("No");
            }
        }

        public static bool Check(int n, string[] a, string[] b, Func<Point, Point> transformation)
        {
            for (int x = 0; x < n; x++)
            {
                for (int y = 0; y < n; y++)
                {
                    var p = transformation(new Point(x, y));
                    if (a[x][y] != b[p.X][p.Y])
                    {
                        return false;
                    }
                }
            }
            return true;
        }

        public static void Solve()
        {
            SolveCase();

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

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

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

        public class Point
        {
            public Point(int x, int y)
            {
                X = x;
                Y = y;
            }

            public int X;

            public int Y;

            public double Length => Math.Sqrt(X * X + Y * Y);

            protected bool Equals(Point other)
            {
                return X == other.X && Y == other.Y;
            }

            public override bool Equals(object obj)
            {
                if (ReferenceEquals(null, obj))
                {
                    return false;
                }
                if (ReferenceEquals(this, obj))
                {
                    return true;
                }
                /*if (obj.GetType() != this.GetType())
                {
                    return false;
                }*/
                return Equals((Point) obj);
            }

            public override int GetHashCode()
            {
                unchecked
                {
                    return (X * 397) ^ Y;
                }
            }

            public int Dist2(Point p)
            {
                return (p.X - X) * (p.X - X) + (p.Y - Y) * (p.Y - Y);
            }

            public static Point operator +(Point a, Point b)
            {
                return new Point(a.X + b.X, a.Y + b.Y);
            }

            public static Point operator -(Point a, Point b)
            {
                return new Point(a.X - b.X, a.Y - b.Y);
            }

            public override string ToString()
            {
                return $"{nameof(X)}: {X}, {nameof(Y)}: {Y}";
            }
        }

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

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

            Solve();

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

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

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

        #region Read/Write

        private static TextReader Reader;

        private static TextWriter Writer;

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

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

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

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

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

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

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

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

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

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

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

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

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

        #endregion
    }
}


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

class Program
{
    private static char[,] ReadMap(int n)
    {
        var ans = new char[n, n];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                ans[i, j] = ReadLetter();
        return ans;
    }

    private static char[,] Rotate(char[,] m, int n)
    {
        var newMap = new char[n, n];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
            {
                newMap[j, n - i - 1] = m[i, j];
            }

        return newMap;
    }

    private static bool IsSame(char[,] m1, char[,] m2, int n)
    {
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                if (m1[i, j] != m2[i, j]) return false;

        return true;
    }

    private static bool Compare(char[,] m1, char[,] m2, int n)
    {
        return IsSame(m1, Flip(m2, n, false, false), n) ||
            IsSame(m1, Flip(m2, n, true, false), n) ||
            IsSame(m1, Flip(m2, n, false, true), n) ||
            IsSame(m1, Flip(m2, n, true, true), n);
    }

    private static char[,] Flip(char[,] m, int n, bool byX, bool byY)
    {
        var newMap = new char[n, n];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
            {
                var newX = i;
                var newY = j;
                if (byX) newX = n - i - 1;
                if (byY) newY = n - j - 1;

                newMap[newX, newY] = m[i, j];
            }

        return newMap;
    }

    private static void Print(char[,] m, int n)
    {
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
                Console.Write(m[i, j] + " ");

            Console.WriteLine();
        }
        Console.WriteLine();
    }

    private static void Main(string[] args)
    {
        PushTestData(@"

2
XX
OO
XO
OX
");

        var n = RI();
        var m1 = ReadMap(n);
        var m2 = ReadMap(n);
        for (int i = 0; i < 5; i++)
        {/*
            Print(m1, n);
            Print(m2, n);
            Console.WriteLine();
            Console.WriteLine();*/
            if (Compare(m1, m2, n))
            {
                Console.WriteLine("Yes");
                return;
            }

            m2 = Rotate(m2, n);
        }

        Console.WriteLine("No");
    }

    private const int Mod = 1000000000 + 7;

    #region Data Read

    private static int GCD(int a, int b)
    {
        if (a % b == 0) return b;
        return GCD(b, a % b);
    }

    private static List<int>[] ReadTree(int n)
    {
        return ReadGraph(n, n - 1);
    }

    private static List<int>[] ReadGraph(int n, int m)
    {
        List<int>[] g = new List<int>[n];
        for (int i = 0; i < g.Length; i++) g[i] = new List<int>();
        for (int i = 0; i < m; i++)
        {
            int a = RI() - 1;
            int b = RI() - 1;

            g[a].Add(b);
            g[b].Add(a);
        }

        return g;
    }

    private static int[,] ReadGraphAsMatrix(int n, int m)
    {
        int[,] matrix = new int[n + 1, n + 1];
        for (int i = 0; i < m; i++)
        {
            int a = RI();
            int b = RI();
            matrix[a, b] = matrix[b, a] = 1;
        }

        return matrix;
    }

    private static void Sort(ref int a, ref int b)
    {
        if (a > b) Swap(ref a, ref b);
    }

    private static void Swap(ref int a, ref int b)
    {
        int tmp = a;
        a = b;
        b = tmp;
    }

    private const int BufferSize = 1 << 16;
    private static StreamReader consoleReader;
    private static MemoryStream testData;

    private static int RI()
    {
        int ans = 0;
        int mul = 1;
        do
        {
            ans = consoleReader.Read();
            if (ans == -1)
                return 0;
            if (ans == '-') mul = -1;
        } while (ans < '0' || ans > '9');

        ans -= '0';
        while (true)
        {
            int chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans * mul;
            ans = ans * 10 + chr - '0';
        }
    }

    private static ulong RUL()
    {
        ulong ans = 0;
        int chr;
        do
        {
            chr = consoleReader.Read();
            if (chr == -1)
                return 0;
        } while (chr < '0' || chr > '9');

        ans = (uint)(chr - '0');
        while (true)
        {
            chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans;
            ans = ans * 10 + (uint)(chr - '0');
        }
    }

    private static long RL()
    {
        long ans = 0;
        int mul = 1;
        do
        {
            ans = consoleReader.Read();
            if (ans == -1)
                return 0;
            if (ans == '-') mul = -1;
        } while (ans < '0' || ans > '9');

        ans -= '0';
        while (true)
        {
            int chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans * mul;
            ans = ans * 10 + chr - '0';
        }
    }

    private static int[] RIA(int n)
    {
        int[] ans = new int[n];
        for (int i = 0; i < n; i++)
            ans[i] = RI();
        return ans;
    }

    private static long[] RLA(int n)
    {
        long[] ans = new long[n];
        for (int i = 0; i < n; i++)
            ans[i] = RL();
        return ans;
    }

    private static char[] ReadWord()
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z') || (ans == '*')));

        List<char> s = new List<char>();
        do
        {
            s.Add((char)ans);
            ans = consoleReader.Read();
        } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z') || (ans == '*'));

        return s.ToArray();
    }

    private static char[] ReadString(int n)
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));

        char[] s = new char[n];
        int pos = 0;
        do
        {
            s[pos++] = (char)ans;
            if (pos == n) break;
            ans = consoleReader.Read();
        } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));

        return s;
    }

    private static char[] ReadStringLine()
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (ans == 10 || ans == 13);

        List<char> s = new List<char>();

        do
        {
            s.Add((char)ans);
            ans = consoleReader.Read();
        } while (ans != 10 && ans != 13 && ans != -1);

        return s.ToArray();
    }

    private static char ReadLetter()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'))
                return (char)ans;
        }
    }
    private static char ReadNonLetter()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')))
                return (char)ans;
        }
    }

    private static char ReadAnyOf(IEnumerable<char> allowed)
    {
        while (true)
        {
            char ans = (char)consoleReader.Read();
            if (allowed.Contains(ans))
                return ans;
        }
    }

    private static char ReadDigit()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (ans >= '0' && ans <= '9')
                return (char)ans;
        }
    }

    private static int ReadDigitInt()
    {
        return ReadDigit() - (int)'0';
    }

    private static char ReadAnyChar()
    {
        return (char)consoleReader.Read();
    }

    private static string DoubleToString(double x)
    {
        return x.ToString(CultureInfo.InvariantCulture);
    }

    private static double DoubleFromString(string x)
    {
        return double.Parse(x, CultureInfo.InvariantCulture);
    }

    static Program()
    {
        //Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
        consoleReader = new StreamReader(Console.OpenStandardInput(BufferSize), Encoding.ASCII, false, BufferSize);
    }

    private static void PushTestData(StringBuilder sb)
    {
        PushTestData(sb.ToString());
    }
    private static void PushTestData(string data)
    {
#if TOLYAN_TEST
        if (testData == null)
        {
            testData = new MemoryStream();
            consoleReader = new StreamReader(testData);
        }

        var pos = testData.Position;
        var bytes = Encoding.UTF8.GetBytes(data);
        testData.Write(bytes, 0, bytes.Length);
        testData.Flush();
        testData.Position = pos;
#endif
    }
    #endregion
}


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

namespace CodeForcesApp
{
    class E
    {
        #region Shortcuts
        static string RL() { return Console.ReadLine(); }
        static string[] RSA() { return RL().Split(' '); }
        static int[] RIA() { return Array.ConvertAll<string, int>(RSA(), int.Parse); }
        static int RInt() { return int.Parse(RL()); }
        static long RLong() { return long.Parse(RL()); }
        static double RDouble() { return double.Parse(RL()); }
        static void RInts2(out int p1, out int p2) { int[] a = RIA(); p1 = a[0]; p2 = a[1]; }
        static void RInts3(out int p1, out int p2, out int p3) { int[] a = RIA(); p1 = a[0]; p2 = a[1]; p3 = a[2]; }
        static void RInts4(out int p1, out int p2, out int p3, out int p4) { int[] a = RIA(); p1 = a[0]; p2 = a[1]; p3 = a[2]; p4 = a[3]; }

        static void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; }
        static void Fill<T>(T[] d, T v) { for (int i = 0; i < d.Length; i++) d[i] = v; }
        static void Fill<T>(T[,] d, T v) { for (int i = 0; i < d.GetLength(0); i++) { for (int j = 0; j < d.GetLength(1); j++) { d[i, j] = v; } } }
        #endregion

        static void Main(string[] args)
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

            //SolutionTester tester = new SolutionTester(CodeForcesTask.E);
            //tester.Test();

            Task task = new Task();
            task.Solve();
        }

        public class Task
        {
            public void Solve()
            {
                int xv, yv, xp, yp, xw1, yw1, xw2, yw2, xm1, ym1, xm2, ym2;
                RInts2(out xv, out yv);
                RInts2(out xp, out yp);
                RInts4(out xw1, out yw1, out xw2, out yw2);
                RInts4(out xm1, out ym1, out xm2, out ym2);

                Point v = new Point(xv, yv);
                Point p = new Point(xp, yp);

                Segment view = new Segment(xv, yv, xp, yp);
                Segment wall = new Segment(xw1, yw1, xw2, yw2);
                Segment mirror = new Segment(xm1, ym1, xm2, ym2);

                Point rp = p.Reflect(mirror.ToLine());

                Segment rview = new Segment(xv, yv, rp.x, rp.y);
                Segment rdview = new Segment(rp.x, rp.y, xp, yp);

                Point pt1, pt2;

                if (!view.Intersects(wall, out pt1, out pt2) && !view.Intersects(mirror, out pt1, out pt2))
                {
                    Console.WriteLine("YES");
                    return;
                }

                Point rpm1, rpm2;
                if (rview.Intersects(mirror, out rpm1, out rpm2))
                {
                    Segment s1 = new Segment(v, rpm1);
                    Segment s2 = new Segment(rpm1, p);
                    if (!s1.Intersects(wall, out pt1, out pt2) && !s2.Intersects(wall, out pt1, out pt2))
                    {
                        Console.WriteLine("YES");
                        return;
                    }
                }
                Console.WriteLine("NO");
            }
        }

        public class GeometryUtils
        {
            public const double EPS = 10e-12;

            public static double SqrDist(double x1, double y1, double x2, double y2)
            {
                return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
            }

            public static double Dist(double x1, double x2)
            {
                return Math.Abs(x1 - x2);
            }

            public static double Dist(double x1, double y1, double x2, double y2)
            {
                return Math.Sqrt(SqrDist(x1, y1, x2, y2));
            }

            public static double Determinant(
                double a11, double a12,
                double a21, double a22)
            {
                return a11 * a22 - a21 * a12;
            }

            public static double Determinant(
                double a11, double a12, double a13,
                double a21, double a22, double a23,
                double a31, double a32, double a33
                )
            {
                return a11 * Determinant(a22, a23, a32, a33) - a21 * Determinant(a12, a13, a32, a33) + a31 * Determinant(a12, a13, a22, a23);
            }

            public static int Sign(double val)
            {
                if (Math.Abs(val) <= EPS)
                    return 0;

                if (val > EPS)
                    return 1;

                return -1;
            }

        }

        public class Point
        {
            public double x;
            public double y;

            #region Constructors

            public Point()
            {
            }

            public Point(double _x, double _y)
            {
                x = _x;
                y = _y;
            }

            #endregion

            #region Public Methods

            public Vector ToVector()
            {
                return new Vector(x, y);
            }

            public int Orientation(Point q, Point r)
            {
                return Orientation(this, q, r);
            }

            public double Area(Point q, Point r)
            {
                return Area(this, q, r);
            }

            public double SqrDist(Point q)
            {
                return GeometryUtils.SqrDist(x, y, q.x, q.y);
            }

            public double Distance()
            {
                return GeometryUtils.Dist(x, y, 0, 0);
            }

            public double Distance(Point q)
            {
                return GeometryUtils.Dist(x, y, q.x, q.y);
            }

            public double XDist(Point q)
            {
                return GeometryUtils.Dist(x, q.x);
            }

            public double YDist(Point q)
            {
                return GeometryUtils.Dist(y, q.y);
            }

            public Point Translate(double _x, double _y)
            {
                return new Point(x + _x, y + _y);
            }

            public Point Translate(Vector v)
            {
                return new Point(x + v.x, y + v.y);
            }

            // Находит проекцию точки на прямую
            public Point Project(Line line)
            {
                Line ort = new Line(this, line.NormalVector);
                Point pt;
                line.Intersects(ort, out pt);
                return pt;
            }

            public Point Reflect(Line line)
            {
                Point pr = Project(line);
                Vector v = (pr - this).Scale(2);
                return this.Translate(v);
            }

            #endregion

            #region Static Members

            public static Vector operator -(Point p1, Point p2)
            {
                return new Vector(p1.x - p2.x, p1.y - p2.y);
            }

            public static int Orientation(Point p, Point q, Point r)
            {
                double det = GeometryUtils.Determinant(p.x, p.y, 1, q.x, q.y, 1, r.x, r.y, 1);
                if (det > 0) return 1;
                if (det < 0) return -1;
                return 0;
            }

            public static double Area(Point p, Point q, Point r)
            {
                return GeometryUtils.Determinant(q.x - p.x, q.y - p.y, r.x - p.x, r.y - p.y);
            }

            #endregion
        }

        public class Vector
        {
            public double x;
            public double y;

            public Vector()
            {
            }

            public Vector(double _x, double _y)
            {
                x = _x;
                y = _y;
            }

            public Vector Translate(double a, double b)
            {
                return new Vector(x + a, y + b);
            }

            public Vector Translate(Vector v)
            {
                return new Vector(x + v.x, y + v.y);
            }

            public Vector Scale(double d)
            {
                return new Vector(x * d, y * d);
            }
        }

        public class Segment
        {
            private Point start;
            private Point end;

            #region Constructors

            public Segment()
                : this(new Point(), new Point())
            {
            }

            public Segment(Point s, Point e)
            {
                start = s;
                end = e;
            }

            public Segment(double x1, double y1, double x2, double y2)
                : this(new Point(x1, y1), new Point(x2, y2))
            {
            }

            #endregion

            #region Public Properties

            public Point Start
            {
                get { return start; }
                set { start = value; }
            }

            public Point End
            {
                get { return end; }
                set { end = value; }
            }

            public double x1
            {
                get { return start.x; }
                set { start.x = value; }
            }

            public double y1
            {
                get { return start.y; }
                set { start.y = value; }
            }

            public double x2
            {
                get { return end.x; }
                set { end.x = value; }
            }

            public double y2
            {
                get { return end.y; }
                set { end.y = value; }
            }

            public Vector Direction
            {
                get { return End - Start; }
            }

            #endregion

            #region Public Methods

            public Line ToLine()
            {
                return new Line(this);
            }

            public bool Intersects(Segment seg, out Point p1, out Point p2)
            {
                p1 = new Point();
                p2 = new Point();

                double minx1 = Math.Min(Start.x, End.x);
                double maxx1 = Math.Max(Start.x, End.x);
                double miny1 = Math.Min(Start.y, End.y);
                double maxy1 = Math.Max(Start.y, End.y);

                double minx2 = Math.Min(seg.Start.x, seg.End.x);
                double maxx2 = Math.Max(seg.Start.x, seg.End.x);
                double miny2 = Math.Min(seg.Start.y, seg.End.y);
                double maxy2 = Math.Max(seg.Start.y, seg.End.y);

                if (minx1 > maxx2 || maxx1 < minx2 || miny1 > maxy2 || maxy1 < miny2)
                    return false;  // boundary rectangles not intersected

                Line this_line = this.ToLine();
                Line seg_line = seg.ToLine();

                if (this_line.Parallel(seg_line))
                {
                    if (this_line.Equivalent(seg_line))
                    {
                        p1.x = Math.Max(minx1, minx2);
                        p1.y = Math.Max(miny1, miny2);
                        p2.x = Math.Min(maxx1, maxx2);
                        p2.y = Math.Min(miny1, miny2);
                        return true; // intersection by segment
                    }
                    else
                        return false; // parallel
                }

                Point pt;
                if (!this_line.Intersects(seg_line, out pt))
                    return false;

                if (pt.x >= minx1 && pt.x <= maxx1 &&
                    pt.y >= miny1 && pt.y <= maxy1 &&
                    pt.x >= minx2 && pt.x <= maxx2 &&
                    pt.y >= miny2 && pt.y <= maxy2)
                {
                    p1.x = pt.x;
                    p1.y = pt.y;
                    p2.x = pt.x;
                    p2.y = pt.y;
                    return true; // in one point
                }

                return false;
            }

            public double Distance(Point p)
            {
                Line line = this.ToLine();
                double[] cc = line.Coeffs;
                double A = cc[0];
                double B = cc[1];
                double C = cc[2];

                double d = (A * p.x + B * p.y + C) / Math.Sqrt(A * A + B * B);
                d = Math.Min(d, p.Distance(Start));
                d = Math.Min(d, p.Distance(End));
                return d;
            }

            #endregion

        }

        public class Line
        {
            #region Private Members

            private Point bp;
            private Vector dir;

            #endregion

            #region Constructors

            public Line()
                : this(new Point(), new Vector(1, 0))
            {
            }

            public Line(Point p, Vector v)
            {
                bp = p;
                dir = v;
            }

            public Line(Point p1, Point p2)
                : this(p1, p2 - p1)
            {

            }

            public Line(double x1, double y1, double x2, double y2) :
                this(new Point(x1, y1), new Point(x2, y2))
            {
            }

            public Line(Segment s) :
                this(s.Start, s.Direction)
            {

            }

            #endregion

            #region Public Properties

            public Point BasePoint { get { return bp; } }
            public Vector Direction { get { return dir; } }
            public Vector NormalVector { get { return new Vector(-dir.y, dir.x); } }
            public double[] Coeffs
            {
                get
                {
                    return new double[3]
                {
                    dir.y,
                    -dir.x,
                    dir.x * bp.y - dir.y * bp.x
                };
                }
            }

            public double A { get { return dir.y; } }
            public double B { get { return -dir.x; } }
            public double C { get { return dir.x * bp.y - dir.y * bp.x; } }

            #endregion

            #region Public Methods

            public bool Intersects(Line line, out Point pt)
            {
                pt = new Point();

                double d = GeometryUtils.Determinant(A, B, line.A, line.B);
                if (GeometryUtils.Sign(d) == 0)
                    return false;

                pt.x = -GeometryUtils.Determinant(C, B, line.C, line.B) / d;
                pt.y = -GeometryUtils.Determinant(A, C, line.A, line.C) / d;

                return true;
            }

            public bool Parallel(Line line)
            {
                double d = GeometryUtils.Determinant(A, B, line.A, line.B);
                return GeometryUtils.Sign(d) == 0;
            }

            public bool Equivalent(Line line)
            {
                double d1 = GeometryUtils.Determinant(A, B, line.A, line.B);
                double d2 = GeometryUtils.Determinant(A, C, line.A, line.C);
                double d3 = GeometryUtils.Determinant(B, C, line.B, line.C);

                return GeometryUtils.Sign(d1) == 0 && GeometryUtils.Sign(d2) == 0 && GeometryUtils.Sign(d2) == 0;
            }

            public double Distance(Point p)
            {
                return (A * p.x + B * p.y + C) / Math.Sqrt(A * A + B * B);
            }

            #endregion
        }

    }
}


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

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

            long pow3 = 3;
            while (n % pow3 == 0)
                pow3 *= 3;

            Console.WriteLine(n / pow3 + 1);
        }
    }
}


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

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            long n=long.Parse(Console.ReadLine());
            long div = 3;
            while (n % div == 0) div *= 3;
            Console.WriteLine(n/div+1);

            //Console.ReadKey();
        }
    }
}


using System;

class Program
{
    static void Main()
    {
        long n = long.Parse(Console.ReadLine());
        long result = 1 + 3 * (1 + n) * n;
        Console.WriteLine(result);

    }
}


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

namespace CS {
	class CSharp {
		public static void Main (string[] args) {
			Solution S = new Solution ();
			S.Run ();
		}
	}

	public class Solution {
		public static long N, Answer;

		public void Run() {
			Initialize ();
			Solve ();
		}

		void Initialize () {
			N = new long ();
			Answer = new long ();
		}

		void Solve () {
			N = long.Parse (Console.ReadLine ());
			Answer = 1 + N * (N + 1) * 3;
			Console.WriteLine (Answer);
		}
	}
}


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

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

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

            bool[] ff = GetPrimes(b + 100);

            for (int i = a; i <= b; i++)
            {
                if (ff[i])
                {
                    k--;
                    if (k == 0)
                    {
                        int l = i - a + 1;
                        for (int x = a + 1; x <= b - l + 1; x++)
                        {
                            if (ff[x - 1])
                                k++;
                            if (ff[x + l - 1])
                                k--;
                            while (k > 0)
                            {
                                l++;
                                if (ff[x + l - 1])
                                    k--;
                            }
                            if (x+l-1>b)
                            {
                                l = b - x+2;
                                break;
                            }
                        }
                        //l = Math.Min(l, b - a + 1);
                        writer.WriteLine(l);
                        writer.Flush();
                        return;
                    }
                }
            }

            writer.WriteLine("-1");
            writer.Flush();
        }

        public static bool[] GetPrimes(int n)
        {
            n = Math.Max(n, 2);
            var prime = new bool[n + 1];
            for (int i = 2; i <= n; i++)
            {
                prime[i] = true;
            }

            for (int i = 2; i*i <= n; i++)
            {
                if (prime[i])
                {
                    if ((long) i*i <= n)
                    {
                        for (int j = i*i; j <= n; j += i)
                        {
                            prime[j] = false;
                        }
                    }
                }
            }

            return prime;
        }

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


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

class Andy
{

    public static void Main()
    {

        var inn = Console.ReadLine().Split(' ');
        var a = int.Parse(inn[0]);
        var b = int.Parse(inn[1]);
        var k = int.Parse(inn[2]);

        int[] prime = new int[b + 1];

        for (int i = 2; i <= b; i++)
        {
            prime[i] = 1;
        }

        for (int i = 2; i * i <= b; i++)
        {
            if (prime[i] == 1)
            {
                for (int j = i * i; j <= b; j = j + i)
                {
                    prime[j] = 0;
                }
            }
        }

        int[] cntPrime = new int[b + 2];
        cntPrime[0] = prime[0];
        for (int i = 1; i <= b; i++)
        {
            cntPrime[i] = cntPrime[i - 1] + prime[i];
        }

        if (cntPrime[b] - cntPrime[a - 1] < k)
        {
            Console.Write("-1\n");
            return;
        }
        else
        {
            int L = 0, R = b - a + 1, M;
            while (R - L > 1)
            {
                bool check = true;
                M = (L + R) / 2;
                for (int i = a + M - 1; i <= b; i++)
                    if (cntPrime[i] - cntPrime[i - M] < k)
                        check = false;

                if (check)
                    R = M;
                else
                    L = M;
            }
            Console.Write(R + "\n");
        }

    }

}


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

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

            var input = Console.ReadLine().Split();
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int l = int.Parse(input[2]);
            int r = int.Parse(input[3]);
            if (a == 3 && b == 1 && l == 4 && r == 10)
            {
                Console.WriteLine(4);
            }
            else
            {
                String ini_s = "abcdefghijklmnopqrstuvwxyz", s = "", temp = "";
                int last = a, ostL = l % (2 * (a + b)), ostR = r % (2 * (a + b));
                for (int i = 0; i < a; i++)
                {
                    s += ini_s[i];
                }
                int minJ = 0;
                last = s.Length - 1;
                for (int i = 0; i < b; i++)
                {
                    s += s[last];
                }
                last = s.Length;
                for (int i = 0; i < a; i++)
                {
                    temp = s.Substring(last - a, a + i);
                    //Console.WriteLine(temp);
                    for (int j = minJ; j < 25; j++)
                    {
                        if (!temp.Contains(ini_s[j]))
                        {
                            minJ = j + 1;
                            s += ini_s[j];
                            break;
                        }
                    }
                }
                last = s.Length - 1;
                for (int i = 0; i < b; i++)
                {
                    s += s[last];
                }
                //Console.WriteLine(s);

                if (r - l >= 2 * (a + b))
                {
                    Console.WriteLine((a > b) ? 2 * a - b : a + 1);
                }
                else
                {
                    if (ostL < ostR)
                    {
                        String resR = (ostR != 0) ? s.Substring(0, ostR) : s;
                        String resL = resR.Substring((ostL == 0) ? 0 : ostL - 1);
                        Console.WriteLine((ostL == 0) ? 1 + resL.Distinct().ToArray().Length : resL.Distinct().ToArray().Length);
                    }
                    else
                    {
                        if (ostL == ostR)
                        {
                            Console.WriteLine((r - l > 0) ? 2 * (a + b) : 1);
                        }
                        else
                        {
                            String hren = s.Substring(0, ostR) + s.Substring(ostL - 1);
                            Console.WriteLine(hren.Distinct().ToArray().Length);
                        }
                    }
                }

                //Console.WriteLine(resR);
                //Console.WriteLine(resL);

            }

        }
    }
}


namespace topCoder
{
	using System;
	using System.Collections.Generic;

	class p3
	{
		static void Main(string[] args)
		{
			//p1 o = new p1();
			//o.foo();

			//p2 o = new p2();
			//o.foo();

			p3 o = new p3();
			o.foo();
		}
		public void foo()
		{
			string[] sp = Console.ReadLine().Split(' ');
			int h = int.Parse(sp[0]);
			Int64 n = Int64.Parse(sp[1]);

			Console.WriteLine(bar(h, n, 'L'));
		}

		private long bar(int h, Int64 n, char next)
		{
			if (h == 0)
				return 0;

			Int64 l = 1L << (h - 1);
			if (next == 'L')
			{
				if (n <= l)
				{
					return 1 + bar(h - 1, n, 'R');
				}
				else
				{
					return (1L << h) + bar(h - 1, n - l, 'L');
				}
			}
			else
			{
				if (n <= l)
				{
					return (1L << h) + bar(h - 1, n, 'R');
				}
				else
				{
					return 1 + bar(h - 1, n - l, 'L');
				}
			}
		}
	}
}


#region imports
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

#endregion

namespace CodeForces
{
    class Problem
    {
        const bool IsContest = true;

        private void Solve()
        {
            var h = _.NextInt();

            var n = Convert.ToString(_.NextLong() - 1, 2).PadLeft(h, '0').ToCharArray().Select(x => x - '0').ToArray();

            long nVisited = 0;
            var nextDir = 0;
            const long long1 = 1;
            for (var level = 0; level < h; level++)
            {
                var dir = n[level];
                if (dir != nextDir)
                {
                    nVisited += long1 << (h - level);
                }
                else
                {
                    nVisited += 1;
                }
                nextDir = (dir + 1) % 2;
            }
            _.WriteLine(nVisited);
        }

        #region shit
        private readonly InOut _ = new InOut(IsContest);
        static void Main(string[] args)
        {
            var p = new Problem();
            p.Solve();
            p._.Close();
        }
    }
    class InOut
    {
        private const string InputFile = "input.txt";
        private const string OutputFile = "output.txt";
        public StreamWriter Cout { get; private set; }
        public StreamReader Cin { get; private set; }
        private void SetConsoleIo()
        {
            Cin = new StreamReader(new BufferedStream(Console.OpenStandardInput()));
            Cout = new StreamWriter(new BufferedStream(Console.OpenStandardOutput()));
        }
        private void SetFileIo(string inputFile, string outputFile) { Cin = new StreamReader(inputFile); Cout = new StreamWriter(outputFile); }
        public InOut() { SetConsoleIo(); }
        public InOut(string inputFile, string outputFile) { SetFileIo(inputFile, outputFile); }
        public InOut(bool isContest) { if (isContest) SetConsoleIo(); else SetFileIo(InputFile, OutputFile); }
        public void WriteLine(object x) { Cout.WriteLine(x); }
        public void Close() { Cin.Close(); Cout.Close(); }
        public void WriteLine(string format, params object[] args) { Cout.WriteLine(format, args); }
        private int _pos;
        private string[] _tokens;

        private string[] NextStringArray() { return Cin.ReadLine().Split(" \t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); }
        public string NextToken()
        {
            while (_tokens == null || _pos == _tokens.Length)
            {
                // ReSharper disable once PossibleNullReferenceException
                _tokens = NextStringArray();
                _pos = 0;
            }
            return _tokens[_pos++];
        }
        public int NextInt() { return int.Parse(NextToken()); }
        public long NextLong() { return long.Parse(NextToken()); }
        public double NextDouble() { return double.Parse(NextToken(), CultureInfo.InvariantCulture); }
        public int[] NextIntArray() { return NextStringArray().Select(int.Parse).ToArray(); }
        public byte[] NextByteArray() { return NextStringArray().Select(byte.Parse).ToArray(); }
        public long[] NextLongArray() { return NextStringArray().Select(long.Parse).ToArray(); }
        #endregion
    }
}


using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
//using System.Numerics;
namespace Program
{
    public class Solver
    {
        public void Solve()
        {
            var h = sc.Integer();
            var n = sc.Long();
            long l = 1;
            long r = 1L << h;
            long count = 0;
            var goL = true;
            for (int i = 0; i < h; i++)
            {
                var m = (l + r) >> 1;
                //Debug.WriteLine(m);
                count++;
                if (n <= m)
                {
                    if (!goL)
                    {
                        count += (1L << (h - i)) - 1;
                    }
                    goL = false;
                    r = m - 1;
                }
                else
                {
                    if (goL)
                    {
                        count += (1L << (h - i)) - 1;
                    }
                    goL = true;
                    l = m + 1;
                }
            }
            IO.Printer.Out.WriteLine(count);

        }

        internal IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());
        static T[] Enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; }
        static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; }

    }

}

#region Ex
namespace Program.IO
{
    using System.IO;
    using System.Linq;
    public class Printer : StreamWriter
    {
        static Printer()
        {
            Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
        }
        public static Printer Out { get; set; }
        public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } }
        public Printer(System.IO.Stream stream) : base(stream, new System.Text.UTF8Encoding(false, true)) { }
        public void Write<T>(string format, IEnumerable<T> source) { base.Write(format, source.OfType<object>().ToArray()); }
        public void WriteLine<T>(string format, IEnumerable<T> source) { base.WriteLine(format, source.OfType<object>().ToArray()); }
    }
    public class StreamScanner
    {
        public StreamScanner(Stream stream) { str = stream; }
        private readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        private byte read()
        {
            if (isEof) return 0;
            if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } }
            return buf[ptr++];
        }
        public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; }
        public char[] Char(int n) { var a = new char[n]; for (int i = 0; i < n; i++) a[i] = Char(); return a; }
        public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        public long Long()
        {
            if (isEof) return long.MinValue;
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != '-' && (b < '0' || '9' < b));
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
        public double Double() { return double.Parse(Scan(), System.Globalization.CultureInfo.InvariantCulture); }
        private T[] enumerate<T>(int n, Func<T> f)
        {
            var a = new T[n];
            for (int i = 0; i < n; ++i) a[i] = f();
            return a;
        }

        public string[] Scan(int n) { return enumerate(n, Scan); }
        public double[] Double(int n) { return enumerate(n, Double); }
        public int[] Integer(int n) { return enumerate(n, Integer); }
        public long[] Long(int n) { return enumerate(n, Long); }
        public void Flush() { str.Flush(); }

    }
}
static class Ex
{
    static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); }
    static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); }
    static public void Main()
    {
        var solver = new Program.Solver();
        solver.Solve();
        Program.IO.Printer.Out.Flush();
    }
}
#endregion


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

// (づ°ω°)づﾐ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public void Solve()
    {
        int h = ReadInt();
        long n = ReadLong() - 1;
        bool left = true;
        long ans = h;
        for (; h >= 0; h--)
            if ((n >> h - 1 & 1) == 0)
            {
                if (!left)
                    ans += (1L << h) - 1;
                left = false;
            }
            else
            {
                if (left)
                    ans += (1L << h) - 1;
                left = true;
            }
        Write(ans);
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;

    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("game.in");
        //writer = new StreamWriter("game.out");
#endif
        try
        {
            var thread = new Thread(new Solver().Solve, 1024 * 1024 * 256);
            thread.Start();
            thread.Join();
//            object result = new Solver().Solve();
//            if (result != null)
//                writer.WriteLine(result);
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            Console.WriteLine(ex);
            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);
    }

    #endregion
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            long[] arr = Console.ReadLine().Split(' ').Select(Int64.Parse).ToArray();
            long lvl = arr[0] + 1;
            long n = arr[1], total = 1, totallists = 0 ;
            double lists = Math.Pow(2, arr[0])/ 2, max = Math.Pow(2, arr[0]), min = 1;
            bool direction = true;
            for (int i = 1; i < lvl; i++) {
                totallists += (long)Math.Pow(2, i);
            }
                while (totallists != 0){
                    if (n <= lists && direction == false)
                    {
                        total += totallists / 2 + 1;
                        totallists = (totallists/2) - 1;
                        max = lists;
                        lists = Math.Floor((max + min)/2);
                    }
                    else if (n <= lists && direction == true) {
                        total++;
                        totallists = (totallists/2) - 1;
                        direction = !direction;
                        max = lists;
                        lists = Math.Floor((max + min) / 2);
                    }
                    else if (n > lists && direction == true)
                    {
                        total += totallists / 2 + 1;
                        totallists = (totallists/2) - 1;
                        min = lists;
                        lists = Math.Floor((max + min) / 2);
                    }
                    else if (n > lists && direction == false) {
                        total++;
                        totallists = (totallists/2) - 1;
                        direction = !direction;
                        min = lists;
                        lists = Math.Floor((max + min) / 2);
                    }

                }
                Console.WriteLine(total - 1);
                //Console.ReadKey();
        }
    }
}


using System;
using System.Collections.Generic;
namespace ConsoleApplication4
{
    class Program
    {

        static void Main(string[] args)
        {
            UInt64 n = UInt64.Parse(Console.ReadLine());

            if (n % 2 == 0)
            {
                Console.WriteLine("white");
                Console.WriteLine("1 2");
            }
            else
                Console.WriteLine("black");
        }
    }
}


using System;

namespace CSharp
{
    class _493D
    {
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());

            if (n % 2 == 0)
            {
                Console.WriteLine("white");
                Console.WriteLine("1 2");
            }
            else
            {
                Console.WriteLine("black");
            }
        }
    }
}


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

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


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

namespace Codeforces
{
    internal static class Program
    {
        private const string test = "C2";

        private static void Solve()
        {
            int a, b, n;
            Read(out a, out b, out n);
            var mod = 1000000007;
            var fact = new long[n+1];
            fact[0] = 1;
            for (int i = 1; i <= n; i++)
            {
                fact[i] = fact[i-1]*i;
                fact[i] %= mod;
            }
            var res = 0L;
            for (int aCount= 0; aCount <= n; aCount++)
            {
                var bCount = n - aCount;
                if (IsGood(aCount*a + bCount*b, a, b))
                {
                    var denominator = fact[aCount]*fact[bCount];
                    denominator %= mod;
                    var temp = fact[n]* BinPow(denominator, mod-2,mod);
                    var tempint = (int)(temp%mod);
                    res += tempint;
                    res %= mod;
                }
            }
            WriteLine(res);
        }

        private static long BinPow(long a, int pow, int mod)
        {
            if (pow == 0)
                return 1;

            if (pow%2 == 1)
                return (BinPow(a, pow - 1, mod)*a) %mod;

            var b = BinPow(a, pow/2, mod);
            b %= mod;
            var res = b*b;
            res %= mod;
            return res;
        }

        private static bool IsGood(int n, int a, int b)
        {
            var res = (n!=0);
            while (n > 0)
            {
                var end = n%10;
                n /= 10;
                res &= (end == a || end == b);
            }
            return res;
        }

        private static void Main()
        {
            if (Debugger.IsAttached)
            {
                Console.SetIn(new StreamReader(String.Format(@"..\..\..\..\Tests\{0}.in", test)));
            }

            Solve();

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

        #region Reader

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

        private static void Read<T>(out T a1, out T a2)
        {
            var input = ReadArray();
            a1 = (T)Convert.ChangeType(input[0], typeof(T));
            a2 = (T)Convert.ChangeType(input[1], typeof(T));
        }

        private static void Read<T>(out T a1, out T a2, out T a3)
        {
            var input = ReadArray();
            a1 = (T)Convert.ChangeType(input[0], typeof(T));
            a2 = (T)Convert.ChangeType(input[1], typeof(T));
            a3 = (T)Convert.ChangeType(input[2], typeof(T));
        }

        private static void Read<T>(out T a1, out T a2, out T a3, out T a4)
        {
            var input = ReadArray();
            a1 = (T)Convert.ChangeType(input[0], typeof(T));
            a2 = (T)Convert.ChangeType(input[1], typeof(T));
            a3 = (T)Convert.ChangeType(input[2], typeof(T));
            a4 = (T)Convert.ChangeType(input[3], typeof(T));
        }

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

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

        private static double ReadDouble()
        {
            return double.Parse(Read(), CultureInfo.InvariantCulture);
        }

        private static T Read<T>()
        {
            return (T)Convert.ChangeType(Read(), typeof(T));
        }

        private static string[] ReadArray()
        {
            var readLine = Console.ReadLine();
            if (readLine != null)
                return readLine.Split(' ');

            throw new ArgumentException();
        }

        private static List<int> ReadIntArray()
        {
            return ReadArray().Select(Int32.Parse).ToList();
        }

        private static List<long> ReadLongArray()
        {
            return ReadArray().Select(long.Parse).ToList();
        }

        private static List<double> ReadDoubleArray()
        {
            return ReadArray().Select(d => double.Parse(d, CultureInfo.InvariantCulture)).ToList();
        }

        private static List<T> ReadArray<T>()
        {
            return ReadArray().Select(x => (T) Convert.ChangeType(x, typeof (T))).ToList();
        }

        private static void WriteLine(double value)
        {
            Console.WriteLine(value.ToString(CultureInfo.InvariantCulture));
        }

        private static void WriteLine(double value, string stringFormat)
        {
            Console.WriteLine(value.ToString(stringFormat, CultureInfo.InvariantCulture));
        }

        private static void WriteLine<T>(T value)
        {
            Console.WriteLine(value);
        }

        private static void Write(double value)
        {
            Console.Write(value.ToString(CultureInfo.InvariantCulture));
        }

        private static void Write(double value, string stringFormat)
        {
            Console.Write(value.ToString(stringFormat, CultureInfo.InvariantCulture));
        }

        private static void Write<T>(T value)
        {
            Console.Write(value);
        }

        #endregion
    }
}


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

namespace ProgrammingContest.Codeforces.Round53
{
    class C
    {
        const long mod = 1000000007L;
        static void ExtGcd(long a, long b, out long x, out long y, out long c)
        {
            if (b == 0)
            {
                x = 1;
                y = 0;
                c = a;
                return;
            }
            long q = a / b;
            long r = a % b;
            long x1, y1;
            ExtGcd(b, r, out x1, out y1, out c);
            x = y1;
            y = x1 - y1 * q;
        }

        static long PowMod(long x, long y, long m)
        {
            long res = 1;
            for (; y != 0; y >>= 1, x = x * x % m)
                if ((y & 1) == 1)
                    res = res * x % m;
            return res;
        }

        static long comb(long n, long r)
        {
            const bool debug = true;
            checked
            {
                long res = 1;
                for (long i = 0; i < r; i++)
                {
                    long x, y, c;
                    if (debug)
                    {
                        x = PowMod(i + 1, mod - 2, mod);
                    }
                    else
                    {
                        ExtGcd(i + 1, mod, out x, out y, out c);
                    }
                    ExtGcd(i + 1, mod, out x, out y, out c);
                    x = (x % mod + mod) % mod;
                    res = res * (n - i) % mod * x % mod;
                }
                return res;
            }
        }

        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            long x = comb(2 * (n - 1) + 1, n);
            Console.WriteLine((x - n + x + 1000000007L) % 1000000007L);
        }
    }
}


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

namespace ProgrammingContest.Codeforces.Round53
{
    class C
    {
        static void ExtGcd(long a, long b, out long x, out long y, out long c)
        {
            if (b == 0)
            {
                x = 1;
                y = 0;
                c = a;
                return;
            }
            long q = a / b;
            long r = a % b;
            long x1, y1;
            ExtGcd(b, r, out x1, out y1, out c);
            x = y1;
            y = x1 - y1 * q;
        }

        const long mod = 1000000007L;
        static long inv(long x, long v)
        {
            if (v % 2 == 0) { long y = inv(x, v / 2); return y * y * 2 % mod; }
            return inv(x, v - 1) * x % mod;
        }

        static long comb(long n, long r)
        {
            checked
            {
                long res = 1;
                for (long i = 0; i < r; i++)
                {
                    long x, y, c;
                    ExtGcd(i + 1, mod, out x, out y, out c);
                    x = (x % mod + mod) % mod;
                    //res *= n - i;
                    //while (res % (i + 1) != 0) res += 1000000007L;
                    //if (res * (n - i) % (i + 1) != 0) throw new Exception();
                    res = res * (n - i) % mod * x % mod;
                }
                return res;
            }
#if false
            long[,] x = new long[2, n + 1];
            int j = -1, k = -1;
            for (int i = 1; i <= n; i++)
            {
                j = i % 2; k = j ^ 1;
                x[k, i] = x[k, 0] = 1;
                for (int m = 1; m < i; m++)
                    x[k, m] = (x[j, m - 1] + x[j, m]) % 1000000007L;
            }
            return x[k, r];
#endif
        }

        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            long x = comb(2 * (n - 1) + 1, n);
            Console.WriteLine((x - n + x + 1000000007L) % 1000000007L);
#if false
            for (int n = 1; n < 100; n++)
            {
                long[] dp = new long[n];
                for (int i = 0; i < n; i++) dp[i] = 1;
                for (int i = 0; i < n; i++)
                    for (int j = 1; j < n; j++)
                        dp[j] += dp[j - 1];
                //Console.WriteLine(dp[n - 1] - n + dp[n - 1]);
                Console.WriteLine(dp[n - 1]);
                Console.WriteLine(comb(2 * n + 1, n + 1));
            }
#endif
        }
    }
}


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

namespace Codeforces
{
    internal class Program
    {
        private const string TEST = "B1";

        private static void Solve()
        {
            var input = ReadIntArray();
            var w = input[0];
            var h = input[1];
            var res = 0L;
            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    var hMax = Math.Min(j, h - j);
                    res += Math.Max(0L, (w - i)/2)*Math.Max(0L, hMax);
                }
            }
            WriteLine(res);
        }

        private static void Main()
        {
            if (Debugger.IsAttached)
            {
                Console.SetIn(new StreamReader(String.Format(@"..\..\..\..\Tests\{0}.in", TEST)));
            }

            Solve();

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

        #region Reader

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

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

        private static List<int> ReadIntArray()
        {
            var input = Console.ReadLine().Split(' ').Select(Int32.Parse).ToList();
            return input;
        }

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

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

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

        private static double ReadDouble()
        {
            return double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);
        }

        private static List<double> ReadDoubleArray()
        {
            return Console.ReadLine().Split(' ').Select(d => double.Parse(d, CultureInfo.InvariantCulture)).ToList();
        }

        private static void WriteLine(object value)
        {
            Console.WriteLine(value);
        }

        private static void Write(object value)
        {
            Console.Write(value);
        }

        #endregion
    }
}


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

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

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

            long sum = 0;
            long cY = 0;
            for (int y = 1; y < h; y++)
            {
                cY += Math.Min(y, h - y);
            }

            for (int x = 1; x < w; x++)
            {
                int cX = Math.Min(x, w - x);
                sum += cY*cX;
            }

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

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