Iahub and Iahubina went to a picnic in a forest full of trees. Less than 5 minutes passed before Iahub remembered of trees from programming. Moreover, he invented a new problem and Iahubina has to solve it, otherwise Iahub won't give her the food. Iahub asks Iahubina: can you build a rooted tree, such that  each internal node (a node with at least one son) has at least two sons;  node i has ci nodes in its subtree? Iahubina has to guess the tree. Being a smart girl, she realized that it's possible no tree can follow Iahub's restrictions. In this way, Iahub will eat all the food. You need to help Iahubina: determine if there's at least one tree following Iahub's restrictions. The required tree must contain n nodes.

The first line of the input contains integer n (1 ≤ n ≤ 24). Next line contains n positive integers: the i-th number represents ci (1 ≤ ci ≤ n).

Output on the first line "YES" (without quotes) if there exist at least one tree following Iahub's restrictions, otherwise output "NO" (without quotes).

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

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

        private static readonly StreamWriter writer =
            new StreamWriter(Console.OpenStandardOutput(1024 * 10), Encoding.ASCII, 1024 * 10);

        private static void Main(string[] args)
        {
            int n = int.Parse(reader.ReadLine());

            string[] ss = reader.ReadLine().Split(' ');
           int[] nn = new int[n];
            for (int i = 0; i < n; i++)
            {
                nn[i] = int.Parse(ss[i]);
            }

            Array.Sort(nn);

            bool[] used = new bool[n];
bool ok = n==nn[n-1];
            if (ok)
                for (int i = 0; i < n; i++)
            {
                if (nn[i]>1)
                {
                    int count = nn[i] - 1;
                    int p = 0;
                    for (int j = i; j >=0; j--)
                    {
                        if (!used[j] && nn[j]<=count)
                        {
                            if (p == 0 && nn[j] == count)
                                continue;
                            used[j] = true;
                            count -= nn[j];
                            p++;
                        }
                        if (count==0)
                            break;
                    }
                    if (count!=0)
                    {
                        ok = false;
                        break;
                    }
                }
            }

            writer.WriteLine("{0}", ok ? "YES" : "NO");
            writer.Flush();
        }
    }
}

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

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

        private static readonly StreamWriter writer =
            new StreamWriter(Console.OpenStandardOutput(1024 * 10), Encoding.ASCII, 1024 * 10);

        private static void Main(string[] args)
        {
            int n = int.Parse(reader.ReadLine());

            string[] ss = reader.ReadLine().Split(' ');
           int[] nn = new int[n];
            for (int i = 0; i < n; i++)
            {
                nn[i] = int.Parse(ss[i]);
            }

            Array.Sort(nn);

            bool[] used = new bool[n];
bool ok = true;
            for (int i = 0; i < n; i++)
            {
                if (nn[i]>1)
                {
                    int count = nn[i] - 1;
                    int p = 0;
                    for (int j = i; j >=0; j--)
                    {
                        if (!used[j] && nn[j]<=count)
                        {
                            if (p == 0 && nn[j] == count)
                                continue;
                            used[j] = true;
                            count -= nn[j];
                            p++;
                        }
                        if (count==0)
                            break;
                    }
                    if (count!=0)
                    {
                        ok = false;
                        break;
                    }
                }
            }

            writer.WriteLine("{0}", ok ? "YES" : "NO");
            writer.Flush();
        }
    }
}


Ayoub had an array $$$a$$$ of integers of size $$$n$$$ and this array had two interesting properties:   All the integers in the array were between $$$l$$$ and $$$r$$$ (inclusive).  The sum of all the elements was divisible by $$$3$$$. Unfortunately, Ayoub has lost his array, but he remembers the size of the array $$$n$$$ and the numbers $$$l$$$ and $$$r$$$, so he asked you to find the number of ways to restore the array. Since the answer could be very large, print it modulo $$$10^9 + 7$$$ (i.e. the remainder when dividing by $$$10^9 + 7$$$). In case there are no satisfying arrays (Ayoub has a wrong memory), print $$$0$$$.

The first and only line contains three integers $$$n$$$, $$$l$$$ and $$$r$$$ ($$$1 \le n \le 2 \cdot 10^5 , 1 \le l \le r \le 10^9$$$) — the size of the lost array and the range of numbers in the array.

Print the remainder when dividing by $$$10^9 + 7$$$ the number of ways to restore the array.

NoteIn the first example, the possible arrays are : $$$[1,2], [2,1], [3, 3]$$$.In the second example, the only possible array is $$$[2, 2, 2]$$$.

using System;
using System.Linq;

namespace CSharp
{
    class _1105C
    {
        public static void Main()
        {
            const int mod = 1000000007;

            var tokens = Console.ReadLine().Split();

            int n = int.Parse(tokens[0]);
            int l = int.Parse(tokens[1]);
            int r = int.Parse(tokens[2]);

            var count = new long[20][];

            count[0] = new long[]
            {
                (r + 3) / 3 - (l + 2) / 3,
                (r + 2) / 3 - (l + 1) / 3,
                (r + 1) / 3 - (l + 0) / 3
            };

            for (int i = 1; i < count.GetLength(0); i++)
            {
                count[i] = new long[]
                {
                    (count[i - 1][0] * count[i - 1][0] + count[i - 1][1] * count[i - 1][2] + count[i - 1][2] * count[i - 1][ 1]) % mod,
                    (count[i - 1][0] * count[i - 1][1] + count[i - 1][1] * count[i - 1][0] + count[i - 1][2] * count[i - 1][ 2]) % mod,
                    (count[i - 1][0] * count[i - 1][2] + count[i - 1][1] * count[i - 1][1] + count[i - 1][2] * count[i - 1][ 0]) % mod
                };
            }

            Console.WriteLine(
                Enumerable
                    .Range(0, count.GetLength(0))
                    .Where(i => ((1 << i) & n) != 0)
                    .Select(i => count[i])
                    .Aggregate(
                        new long[] { 1, 0, 0 },
                        (x, y) => new long[]
                        {
                            (x[0] * y[0] + x[1] * y[2] + x[2] * y[ 1]) % mod,
                            (x[0] * y[1] + x[1] * y[0] + x[2] * y[ 2]) % mod,
                            (x[0] * y[2] + x[1] * y[1] + x[2] * y[ 0]) % mod
                        })
                        [0]);
        }
    }
}

using System;
using System.Linq;

namespace ProblemC
{
    /// <summary>
    /// http://codeforces.com/problemset/problem/1105/C
    /// </summary>
    public class Program
    {
        private const long Modulo = 1000000007;

        private static long[] s;

        public static long Solve(long n, long l, long r)
        {
            Init_s(l);

            long f0 = f(0, r), f1 = f(1, r), f2 = f(2, r);

            long[] prev = new long[3], cur = new long[3];
            cur[0] = f0;
            cur[1] = f1;
            cur[2] = f2;

            for (int i = 0; i < n; i++)
            {
                if (i > 0)
                {
                    cur[0] = ((prev[0] * f0) % Modulo + (prev[1] * f2) % Modulo + (prev[2] * f1) % Modulo) % Modulo;
                    cur[1] = ((prev[0] * f1) % Modulo + (prev[1] * f0) % Modulo + (prev[2] * f2) % Modulo) % Modulo;
                    cur[2] = ((prev[0] * f2) % Modulo + (prev[1] * f1) % Modulo + (prev[2] * f0) % Modulo) % Modulo;
                }

                prev[0] = cur[0];
                prev[1] = cur[1];
                prev[2] = cur[2];
            }

            return cur[0];
        }

        private static long f(long k, long r)
        {
            long l = s[k];

            if (l > r) return 0;

            return (1 + (r - l) / 3) % Modulo;
        }

        private static void Init_s(long l)
        {
            s = new long[3];

            switch (l % 3)
            {
                case 0:
                    s[0] = l % Modulo;
                    s[1] = (l + 1) % Modulo;
                    s[2] = (l + 2) % Modulo;
                    break;
                case 1:
                    s[0] = (l + 2) % Modulo;
                    s[1] = l % Modulo;
                    s[2] = (l + 1) % Modulo;
                    break;
                case 2:
                    s[0] = (l + 1) % Modulo;
                    s[1] = (l + 2) % Modulo;
                    s[2] = l % Modulo;
                    break;
            }
        }

        public static void Main(string[] args)
        {
            int[] inputs = Console.ReadLine().Split(' ').Select(Int32.Parse).ToArray();

            int n = inputs[0], l = inputs[1], r = inputs[2];

            Console.WriteLine(Solve(n, l, r));
        }
    }
}

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		int N = I[0], l = I[1], r = I[2];
		var mx = new int[3];
		mx[0] = (r + 3) / 3 - (l + 2) / 3;
		mx[1] = (r + 2) / 3 - (l + 1) / 3;
		mx[2] = (r + 1) / 3 - l / 3;
		var dp = new long[N + 1, 3];
		dp[0, 0] = 1;
		for (var n = 1; n <= N; n++)
			for (var m = 0; m < 3; m++)
				for (var x = 0; x < 3; x++)
					dp[n, m] = (dp[n, m] + mx[x] * dp[n - 1, (m - x + 3) % 3] % MOD) % MOD;
		WriteLine(dp[N, 0]);
	}
}

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

namespace codeforces
{
    public class Program
    {
        private static int MOD = 1000 * 1000 * 1000 + 7;

        private static int f(int c, int r)
        {
            if (r == 0)
            {
                return c / 3;
            }
            int count = c / 3;
            if (r == 1 && c % 3 == 0 || (r == 2 && c % 3 != 2))
            {
                count--;
            }
            count++;
            return count;
        }

        private static int Add(int a, int b)
        {
            a += b;
            if (a >= MOD)
            {
                a -= MOD;
            }
            return a;
        }

        private static int Mult(int a, int b)
        {
            return (int)(1L * a * b % MOD);
        }

        private static void Main(string[] args)
        {
            var values = Console.ReadLine().Split(' ');
            int n = Convert.ToInt32(values[0]);
            int l = Convert.ToInt32(values[1]);
            int r = Convert.ToInt32(values[2]);

            var cnt = new int[3] { f(r, 0) - f(l - 1, 0), f(r, 1) - f(l - 1, 1), f(r, 2) - f(l - 1, 2) };
            var dp = new int[n + 1, 3];
            dp[0, 0] = 1;
            for (int i = 1; i <= n; ++i)
            {
                for (int rest = 0; rest < 3; ++rest)
                {
                    for (int j = 0; j < 3; ++j)
                    {
                        int p = (rest - j + 3) % 3;
                        dp[i, rest] = Add(dp[i, rest], Mult(dp[i - 1, j], cnt[p]));
                    }
                }
            }
            Console.WriteLine(dp[n, 0]);
        }
    }
}

using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		long N = long.Parse(str[0]);
		long L = long.Parse(str[1]);
		long R = long.Parse(str[2]);
		long ans = 1;
		long mod = 1000000007;
		long[,]A = new long[N+1,3];
		long a1 = (R+2)/3 - (L+1)/3;
		long a2 = (R+1)/3 - L/3;
		long a3 = R/3 - (L-1)/3;
		A[0,0] = a1;
		A[0,1] = a2;
		A[0,2] = a3;
		for(var i=0;i<N;i++){
			A[i+1,0] = A[i,0]*a3+A[i,1]*a2+A[i,2]*a1;
			A[i+1,0] %= mod;
			A[i+1,1] = A[i,0]*a1+A[i,1]*a3+A[i,2]*a2;
			A[i+1,1] %= mod;
			A[i+1,2] = A[i,0]*a2+A[i,1]*a1+A[i,2]*a3;
			A[i+1,2] %= mod;
		}
		Console.WriteLine(A[N-1,2]);
	}
}

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

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

        private static void Main(string[] args)
        {
            writer.WriteLine(Solve(args));
            writer.Flush();
        }

        private static long Solve(string[] args)
        {
            int n = Next();
            int l = Next();
            int r = Next();

            var nn = new int[3];
            for (int i = 0; i < 3; i++)
            {
                nn[(l + i)%3] = Math.Max(0, (r - (l + i) + 3)/3);
            }
            const int mod = 1000000007;

            var dp = new long[3];
            dp[0] = 1;
            for (int ii = 0; ii < n; ii++)
            {
                var next = new long[3];

                next[0] = (dp[0]*nn[0] + dp[1]*nn[2] + dp[2]*nn[1])%mod;
                next[1] = (dp[0]*nn[1] + dp[1]*nn[0] + dp[2]*nn[2])%mod;
                next[2] = (dp[0]*nn[2] + dp[1]*nn[1] + dp[2]*nn[0])%mod;

                dp = next;
            }

            return dp[0]%mod;
        }

        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;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        const long MOD = 1000000007;
        static int before(int x, int ost)
        {
            if (x < ost)
                return 0;
            return (x - ost) / 3 + 1;
        }
        static void Main(string[] args)
        {
            int n, l, r;
            string[] input = Console.ReadLine().Split();
            n = int.Parse(input[0]);
            l = int.Parse(input[1]);
            r = int.Parse(input[2]);
            long[,] dp = new long[n, 3];
            dp[0, 0] = before(r, 0) - before(l - 1, 0);
            dp[0, 1] = before(r, 1) - before(l - 1, 1);
            dp[0, 2] = before(r, 2) - before(l - 1, 2);
            for (int i = 1; i < n; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    int pred0 = j;
                    int pred1 = j - 1;
                    int pred2 = j - 2;
                    if (pred1 < 0)
                        pred1 += 3;
                    if (pred2 < 0)
                        pred2 += 3;
                    dp[i, j] += dp[i - 1, pred0] * dp[0, 0];
                    dp[i, j] %= MOD;
                    dp[i, j] += dp[i - 1, pred1] * dp[0, 1];
                    dp[i, j] %= MOD;
                    dp[i, j] += dp[i - 1, pred2] * dp[0, 2];
                    dp[i, j] %= MOD;
                }
            }
            /*for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < 3; j++)
                    Console.Write($"{dp[i, j]} ");
                Console.WriteLine();
            }*/
            Console.WriteLine((dp[n - 1, 0])%MOD);
        }
    }
}

#if DEBUG
using System.Reflection;
using System.Threading.Tasks;
#endif

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

#if DEBUG
using System.Diagnostics;
#endif

namespace _533c
{
    class Program
    {
        static string _inputFilename = "input.txt";
        static string _outputFilename = "output.txt";
        static bool _useFileInput = false;
        const string _delim = "!";

        static void Main(string[] args)
        {
            StreamWriter file = null;
#if DEBUG
            var testNumber = 0;
            var timer = new Stopwatch();
            foreach (var test in GetTests())
            {

                timer.Start();

                var defaultColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine($"<!-- TEST #{testNumber} -->");
                Console.ForegroundColor = defaultColor;
                Console.SetIn(test);

#else
            if (_useFileInput)
            {
                Console.SetIn(File.OpenText(_inputFilename));
                file = new StreamWriter(_outputFilename);
                Console.SetOut(file);
            }
#endif

            try
            {
#if DEBUG
                Solution(testNumber);
#else
                Solution(0);
#endif
            }
            finally
            {
#if DEBUG
#else
                if (_useFileInput)
                {
                    file.Close();
                }
#endif
            }

#if DEBUG
                timer.Stop();

                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine($"<!-- TEST #{testNumber} FINISHED IN {timer.Elapsed.ToString(@"ss\:fff")}-->");
                Console.ForegroundColor = defaultColor;

                timer.Reset();
                testNumber++;
            }
#endif
        }

        static void Solution(int testNumber)
        {
            #region SOLUTION
            var d = ReadIntArray();

            var n = d[0];
            var l = d[1] - 1;
            var r = d[2];
            var mod = 1000 * 1000 * 1000 + 7;
            var dp = new long[n, 3];

            var cs = new long[3];
            cs[0] = r / 3 - l / 3;
            cs[1] = r / 3;
            if (r % 3 > 0)
            {
                cs[1]++;
            }

            cs[1] -= l / 3;
            if (l % 3 > 0)
            {
                cs[1]--;
            }

            cs[2] = r / 3;
            if (r % 3 > 1)
            {
                cs[2]++;
            }
            cs[2] -= l / 3;
            if (l % 3 > 1)
            {
                cs[2]--;
            }

            dp[0, 0] = cs[0];
            dp[0, 1] = cs[1];
            dp[0, 2] = cs[2];
            for (int i = 1; i < n; i++)
            {
                // 0
                dp[i, 0] += (dp[i - 1, 0] * cs[0]) % mod;
                dp[i, 0] %= mod;

                dp[i, 0] += (dp[i - 1, 1] * cs[2]) % mod;
                dp[i, 0] %= mod;

                dp[i, 0] += (dp[i - 1, 2] * cs[1]) % mod;
                dp[i, 0] %= mod;

                // 1
                dp[i, 1] += (dp[i - 1, 0] * cs[1]) % mod;
                dp[i, 1] %= mod;

                dp[i, 1] += (dp[i - 1, 1] * cs[0]) % mod;
                dp[i, 1] %= mod;

                dp[i, 1] += (dp[i - 1, 2] * cs[2]) % mod;
                dp[i, 1] %= mod;

                // 2
                dp[i, 2] += (dp[i - 1, 0] * cs[2]) % mod;
                dp[i, 2] %= mod;

                dp[i, 2] += (dp[i - 1, 1] * cs[1]) % mod;
                dp[i, 2] %= mod;

                dp[i, 2] += (dp[i - 1, 2] * cs[0]) % mod;
                dp[i, 2] %= mod;
            }

            Console.WriteLine(dp[n - 1, 0]);
            //var n = readInt();
            //var m = readInt();

            //var a = readIntArray();
            //var b = readIntArray();
            #endregion
        }

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

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

        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => int.Parse(i)).ToArray();
        }

        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => long.Parse(i)).ToArray();
        }

#if DEBUG
        static IEnumerable<TextReader> GetTests()
        {
            var tests = new List<string>();
            var resName = Assembly.GetCallingAssembly().GetManifestResourceNames()[0];
            using (var resource = new StreamReader(Assembly.GetCallingAssembly().GetManifestResourceStream(resName)))
            {
                while (true)
                {
                    var nextText = new StringBuilder();
                    var endOfFile = false;
                    while (true)
                    {
                        var line = resource.ReadLine();

                        endOfFile = line == null;
                        if (endOfFile)
                        {
                            break;
                        }

                        if (line.Equals(_delim, StringComparison.Ordinal))
                        {
                            break;
                        }

                        nextText.AppendLine(line);
                    }

                    yield return new StringReader(nextText.ToString());

                    if (endOfFile)
                    {
                        break;
                    }
                }
            }
        }
#endif
    }
}

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

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

class Sol{
	const long mod = (long) 1e9 + 7;
	public void Solve(){

		long[] cnt = new long[3];
		cnt[0] = (R / 3 - (L - 1) / 3);
		cnt[1] = (R / 3 + ((R % 3 > 0) ? 1 : 0)) - ((L - 1) / 3 + ((L - 1) % 3 > 0 ? 1 : 0));
		cnt[2] = (R / 3 + ((R % 3 > 1) ? 1 : 0)) - ((L - 1) / 3 + ((L - 1) % 3 > 1 ? 1 : 0));

		if(N == 1){
			Console.WriteLine(cnt[0]);
			return;
		}

		mlong[] dp = new mlong[3];
		for(int i=0;i<3;i++) dp[i] = cnt[i];
		for(int i=1;i<N;i++){
			var ndp = new mlong[3];
			for(int j=0;j<3;j++){
				for(int k=0;k<3;k++){
					ndp[(j + k) % 3] += dp[j] * cnt[k];
				}
			}
			dp = ndp;
		}

		Console.WriteLine(dp[0]);

	}
	int N;
	long L,R;
	public Sol(){
		var d = ria();
		N = d[0]; L = d[1]; R = d[2];
	}

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

struct mlong {

	const long mod = (long) 1e9 + 7;
	long V;

	public mlong(long _v = 0){
		V = _v;
	}

	public static mlong operator+(mlong a, mlong b){
		var v0 = a.V + b.V; if(v0 >= mod) v0 -= mod;
		return new mlong(v0);
	}
	public static mlong operator-(mlong a, mlong b){
		var v0 = mod + a.V - b.V; if(v0 >= mod) v0 -= mod;
		return new mlong(v0);
	}
	public static mlong operator*(mlong a, mlong b){
		var v0 = a.V * b.V; if(v0 >= mod) v0 %= mod;
		return new mlong(v0);
	}
	public static mlong operator/(mlong a, mlong b){
		var v0 = a.V * inv(b.V).V; if(v0 >= mod) v0 %= mod;
		return new mlong(v0);
	}

	public static mlong inv(long x){
		long a = 0, b = 0, c = 0;
		ExtGCD(x, mod, ref a, ref b, ref c);
		return (mlong)((a + mod) % mod);
	}

	public static void ExtGCD(long x, long y, ref long a, ref long b, ref long c){
		long r0 = x; long r1 = y;
		long a0 = 1; long a1 = 0;
		long b0 = 0; long b1 = 1;
		long q1, r2, a2, b2;
		while(r1 > 0){
			q1 = r0 / r1;
			r2 = r0 % r1;
			a2 = a0 - q1 * a1;
			b2 = b0 - q1 * b1;
			r0 = r1; r1 = r2;
			a0 = a1; a1 = a2;
			b0 = b1; b1 = b2;
		}
		c = r0;
		a = a0;
		b = b0;
	}

	public static mlong ModPow(mlong a, long k){
		if(k == 0) return (mlong) 1;
		if(a == 0) return (mlong) 0;
		mlong x = a;
		mlong ret = 1;
		while(k > 0){
			if(k % 2 == 1) ret *= x;
			x *= x;
			k >>= 1;
		}
		return ret;
	}

	public static bool operator == (mlong a, mlong b){
		 return a.Equals(b);
	}
	public static bool operator != (mlong a, mlong b){
		 return !(a == b);
	}

	public override bool Equals(System.Object obj){
		if(obj  ==  null) return false;
		mlong p  =  (mlong) obj;
		if((System.Object) p  ==  null) return false;
		return p.V  ==  V;
	}
	public override int GetHashCode(){
		return V.GetHashCode();
	}

	public static implicit operator mlong(long n){
		return new mlong(n);
	}
	public static implicit operator mlong(int n){
		return new mlong(n);
	}
	public static explicit operator long(mlong n){
		return n.V;
	}

	public override String ToString(){
		return V.ToString();
	}

}

/*
csc -debug C.cs && mono --debug C.exe <<< "2 1 3"
*/

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

public class HelloWorld {
    public static void SolveCodeForces() {
        var n = cin.NextInt();
        var l = cin.NextInt();
        var r = cin.NextInt();

        const ulong MOD = 1000000007ul;
        var S = Helpers.CreateArray(n+1, _ => new ulong[3]);

        var d0 = (ulong)( r/3 - (l-1)/3 );
        var d1 = (ulong)( (r+2)/3 - (l+1)/3 );
        var d2 = (ulong)( (r+1)/3 - l/3 );

        S[1] = new ulong[] {
            d0 % MOD,
            d1 % MOD,
            d2 % MOD
        };

        for (var i = 2; i <= n; i++) {
            S[i] = new ulong[] {
                ( d0 * S[i-1][0] + d1 * S[i-1][2] + d2 * S[i-1][1] ) % MOD,
                ( d0 * S[i-1][1] + d1 * S[i-1][0] + d2 * S[i-1][2] ) % MOD,
                ( d0 * S[i-1][2] + d1 * S[i-1][1] + d2 * S[i-1][0] ) % MOD
            };
        }

        // for (var i = 1; i <= n; i++)
        //     System.Console.WriteLine(string.Join(" ", S[i]));

        System.Console.WriteLine(S[n][0]);
    }

    static Scanner cin = new Scanner();
    static StringBuilder cout = new StringBuilder();

    static public void Main () {
        SolveCodeForces();
        // System.Console.Write(cout.ToString());
    }
}

public static class Helpers {
    public static T[] CreateArray<T>(int length, Func<int, T> itemCreate) {
        var result = new T[length];
        for (var i = 0; i < result.Length; i++)
            result[i] = itemCreate(i);
        return result;
    }

    public static IEnumerable<int> IndicesWhere<T>(this IEnumerable<T> seq, Func<T, bool> cond) {
        var i = 0;
        foreach (var item in seq) {
            if (cond(item)) yield return i;
            i++;
        }
    }
}

public class Scanner
{
    private string[] line = new string[0];
    private int index = 0;

    public string Next() {
        if (line.Length <= index) {
            line = Console.ReadLine().Split(' ');
            index = 0;
        }
        var res = line[index];
        index++;
        return res;
    }

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

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

    public ulong NextUlong() {
        return ulong.Parse(Next());
    }

    public string[] Array() {
        line = Console.ReadLine().Split(' ');
        index = line.Length;
        return line;
    }

    public int[] IntArray(int emptyPrefixLen = 0) {
        var array = Array();
        var result = new int[emptyPrefixLen + array.Length];
        for (int i = 0; i < array.Length; i++)
            result[emptyPrefixLen + i] = int.Parse(array[i]);
        return result;
    }

    public long[] LongArray() {
        var array = Array();
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = long.Parse(array[i]);
        return result;
    }

    public ulong[] UlongArray() {
        var array = Array();
        var result = new ulong[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = ulong.Parse(array[i]);
        return result;
    }
}

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

namespace prC {
    class Program {
#if ONLINE_JUDGE
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);
#else
        private static readonly StreamWriter writer = new StreamWriter(@"..\..\output");
        private static readonly StreamReader reader = new StreamReader(@"..\..\input");
#endif

        static void Main(string[] args) {
            int n = NextInt();
            int l = NextInt();
            int r = NextInt();
            var d = (r - l + 1) / 3;
            ulong[] c = {(ulong) d, (ulong) d, (ulong) d};
            for (int i = d * 3 + l; i <= r; i++) {
                c[i % 3]++;
            }
            const ulong m = 1000000000 + 7;
            ulong[] dp = new[] {c[0], c[1], c[2]};
            for (int i = 1; i < n; i++) {
                ulong[] dp1 = new ulong[3];
                for (int j = 0; j < 3; j++) {
                    dp1[j] = (dp[j] * c[0]) % m + (dp[(j + 1) % 3] * c[2]) % m + (dp[(j + 2) % 3] * c[1]) % m;
                    dp1[j] %= m;
                }
                dp = dp1;
            }
            writer.WriteLine(dp[0]);

            writer.Flush();
#if !ONLINE_JUDGE
            writer.Close();
#endif
        }
        private static int NextInt() {
            int c;
            int res = 0;
            do {
                c = reader.Read();
                if(c == -1)
                    return res;
            } while(c != '-' && (c < '0' || c > '9'));
            int sign = 1;
            if(c == '-') {
                sign = -1;
                c = reader.Read();
            }
            res = c - '0';
            while(true) {
                c = reader.Read();
                if(c < '0' || c > '9')
                    return res * sign;
                res *= 10;
                res += c - '0';
            }
        }
        private static long NextLong() {
            int c;
            long res = 0;
            do {
                c = reader.Read();
                if(c == -1)
                    return res;
            } while(c != '-' && (c < '0' || c > '9'));
            int sign = 1;
            if(c == '-') {
                sign = -1;
                c = reader.Read();
            }
            res = c - '0';
            while(true) {
                c = reader.Read();
                if(c < '0' || c > '9')
                    return res * sign;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

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

class Solution
{
	static int modEqual (int max, int mod)
	{
		int result = max / 3;
		if (max % 3 >= mod)
			result++;
		return result;
	}

	public static void Main (string[] args)
	{
		int[] nums = Console.ReadLine ().Split (' ').Select (int.Parse).ToArray ();
		int n = nums [0], l = nums [1], r = nums [2];

		long[] factors = {
			modEqual (r, 0) - modEqual (l - 1, 0),
			modEqual (r, 1) - modEqual (l - 1, 1),
			modEqual (r, 2) - modEqual (l - 1, 2)
		};

		long[] freq = new long[] { 1, 0, 0 };

		for (int i = 0; i < n; i++) {
			long[] next = new long[3];
			for (int a = 0; a < 3; a++) {
				for (int b = 0; b < 3; b++) {
					next [(a + b) % 3] += freq [a] * factors [b];
				}
			}
			for (int k = 0; k < 3; k++) {
				freq [k] = next [k] % ((int)1e9 + 7);
			}
		}

		Console.WriteLine (freq[0]);
	}
}

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

public class Example
{
    public static void Main(string[] args)
    {
        var elements = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);

        var elementCount = elements[0];
        var elementMin = elements[1];
        var elementMax = elements[2];

        var nearestMin = (elementMin / 3) * 3 + (elementMin % 3 == 0 ? 0 : 3);
        var nearestMax = (elementMax / 3) * 3;
        var quantity = (nearestMax - nearestMin) / 3;

        var remainder = new Dictionary<long, long>
        {
            [0] = quantity,
            [1] = quantity,
            [2] = quantity
        };

        for (long element = elementMin; element < nearestMin; ++element)
        {
            ++remainder[element % 3];
        }

        for (long element = nearestMax; element <= elementMax; ++element)
        {
            ++remainder[element % 3];
        }

        var ways = new Dictionary<long, Dictionary<long, long>>
        {
            [1] = new Dictionary<long, long>
            {
                [0] = remainder[0],
                [1] = remainder[1],
                [2] = remainder[2]
            }
        };

        long modulo = 1000000007;
        for (long n = 2; n <= elementCount; ++n)
        {
            ways.Add(n, new Dictionary<long, long>
            {
                [0] = 0,
                [1] = 0,
                [2] = 0
            });

            ways[n][0] = (ways[n - 1][0] * remainder[0] + ways[n - 1][1] * remainder[2] + ways[n - 1][2] * remainder[1]) % modulo;
            ways[n][1] = (ways[n - 1][0] * remainder[1] + ways[n - 1][1] * remainder[0] + ways[n - 1][2] * remainder[2]) % modulo;
            ways[n][2] = (ways[n - 1][0] * remainder[2] + ways[n - 1][1] * remainder[1] + ways[n - 1][2] * remainder[0]) % modulo;
        }

        Console.WriteLine(ways[elementCount][0] % modulo);
    }
}

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

namespace ConsoleApp2
{
    class Program
    {
        const long MOD = 1000000009;
        static int before(int x, int ost)
        {
            if (x < ost)
                return 0;
            return (x - ost) / 3 + 1;
        }
        static void Main(string[] args)
        {
            int n, l, r;
            string[] input = Console.ReadLine().Split();
            n = int.Parse(input[0]);
            l = int.Parse(input[1]);
            r = int.Parse(input[2]);
            long[,] dp = new long[n, 3];
            dp[0, 0] = before(r, 0) - before(l - 1, 0);
            dp[0, 1] = before(r, 1) - before(l - 1, 1);
            dp[0, 2] = before(r, 2) - before(l - 1, 2);
            for (int i = 1; i < n; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    int pred0 = j;
                    int pred1 = j - 1;
                    int pred2 = j - 2;
                    if (pred1 < 0)
                        pred1 += 3;
                    if (pred2 < 0)
                        pred2 += 3;
                    dp[i, j] += dp[i - 1, pred0] * dp[0, 0];
                    dp[i, j] %= MOD;
                    dp[i, j] += dp[i - 1, pred1] * dp[0, 1];
                    dp[i, j] %= MOD;
                    dp[i, j] += dp[i - 1, pred2] * dp[0, 2];
                    dp[i, j] %= MOD;
                }
            }
            /*for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < 3; j++)
                    Console.Write($"{dp[i, j]} ");
                Console.WriteLine();
            }*/
            Console.WriteLine((dp[n - 1, 0])%MOD);
        }
    }
}


Two best friends Serozha and Gena play a game.Initially there is one pile consisting of n stones on the table. During one move one pile should be taken and divided into an arbitrary number of piles consisting of a1 > a2 > ... > ak > 0 stones. The piles should meet the condition a1 - a2 = a2 - a3 = ... = ak - 1 - ak = 1. Naturally, the number of piles k should be no less than two.The friends play in turns. The player who cannot make a move loses. Serozha makes the first move. Who will win if both players play in the optimal way?

The single line contains a single integer n (1 ≤ n ≤ 105).

If Serozha wins, print k, which represents the minimal number of piles into which he can split the initial one during the first move in order to win the game. If Gena wins, print "-1" (without the quotes).

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

namespace cs_console
{
    class _73_2_E
    {
        //nim
        //game
        public static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] grundy = new int[n + 1];
            int[] ans = new int[n + 1];
            grundy[1] = 0;
            ans[1] = -1;
            for (int i = 2; i <= n; i++)
            {
                grundy[i] = 0;
                ans[i] = -1;
                bool ok = false;
                Dictionary<int, int> used = new Dictionary<int, int>();
                for (int len = 2; len * (len + 1) / 2 <= i; len++)
                {
                    if (i * 2 % len == 0)
                    {
                        int aa = i * 2 / len - len + 1;
                        if (aa % 2 == 0 && aa > 0)
                        {
                            int x = aa / 2;
                            //valid split (x, x + 1, ..., x + k - 1)
                            int ng = 0;
                            for (int k = 0; k < len; k++)
                            {
                                ng ^= grundy[x + k];
                            }
                            if(!ok && ng == 0)
                            {
                                //good
                                ok = true;
                                ans[i] = len;
                            }
                            used[ng] = 1;
                        }
                    }
                }
                //find the min value not used -- grundy value
                for (int j = 0; ; j++)
                {
                    if (!used.ContainsKey(j))
                    {
                        grundy[i] = j;
                        break;
                    }
                }
                if (!ok)
                {
                    ans[i] = -1;
                }
            }
            //for (int i = 0; i < n; i++)
            //{
            //Console.WriteLine(i + " " + ans[i] + " " + grundy[i]);
            //}
            Console.WriteLine(ans[n]);
        }
    }
}

using System;

namespace Codeforces
{
    class Program
    {
        static void Main()
        {
            var N = Int32.Parse(Console.ReadLine().Trim());

            int[] grandi = new int[N+1];
            int[] numGrandi = new int[N+1];
            int nim;
            int[] answ = new int[N+1];

            for (int i = 0; i < N + 1; i++)
            {
                numGrandi[i] = -1;
                answ[i] = -1;
            }
            for (int n = 0; n <= N; n++)
            {
                for (int count = 2; (count * (count + 1)) / 2 <= n; count++)
                {
                    if ((2 * n - count * (count - 1)) % (2 * count) != 0)
                        continue;
                    int a = (2 * n - count * (count - 1)) / (2 * count);
                    if (a < 1)
                        break;

                    nim = 0;
                    for (int j = 0; j < count; j++)
                        nim ^= grandi[a + j];

                    if (answ[n] == -1)
                    {
                        if (nim == 0)
                            answ[n] = count;
                        else
                            answ[n] = -1;
                    }
                    numGrandi[nim] = n;
                }
                for (int i = 0; i <= N; i++)
                {
                    if (numGrandi[i] != n)
                    {
                        grandi[n] = i;
                        break;
                    }
                }
            }

            Console.WriteLine(answ[N]);
        }
    }
}

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

class ProblemE
{
    static int?[] GrundyLookup = new int?[100001];
    static int[] NLookup = new int[100001];

    static int Find(int n)
    {
        if (GrundyLookup[n].HasValue)
        {
            return GrundyLookup[n].Value;
        }
        else
        {
            int count = n % 2 == 1 ? 2 : 3;
            HashSet<int> results = new HashSet<int>();
            while (count <= n)
            {
                if ((2 * n) % count == 0)
                {
                    int twoa1 = (2 * n) / count - (count - 1);
                    if (twoa1 % 2 == 0 && twoa1 > 0)
                    {
                        int a1 = twoa1 / 2;
                        int result = 0;
                        for (int i = a1; i < a1 + count; i++)
                        {
                            result ^= Find(i);
                        }
                        results.Add(result);
                        if (result == 0 && NLookup[n] == 0)
                            NLookup[n] = count;
                    }
                }
                count++;
            }
            int j = 0;
            while (results.Contains(j))
            {
                j++;
            }
            GrundyLookup[n] = j;
            return j;
        }
    }

    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        if (Find(n) == 0)
        {
            Console.WriteLine(-1);
        }
        else
        {
            Console.WriteLine(NLookup[n]);
        }
    }
}

using System;

namespace ConsoleApplication1
{
    public class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();
            var n = Int32.Parse(str);

            var fi = new int[n + 1];
            var used = new int[3 * n];
            var kucha = new int[n + 1];

            for (int i = 3; i <= n; ++i)
            {
                for (int k = 2; k <= 4 * (int)Math.Sqrt(i); ++k)
                {
                    var delta = i - (k*(k - 1))/2;
                    if (delta <= 0)
                        break;

                    if (delta % k != 0)
                        continue;

                    var c = delta/k;
                    var curFi = 0;
                    for (int j = 0; j < k; ++j)
                    {
                        curFi = curFi ^ fi[c + j];
                    }
                    used[curFi] = i;
                    if (curFi == 0 && kucha[i] == 0)
                    {
                        kucha[i] = k;
                    }
                }

                if (kucha[i] > 0)
                {
                    for (int j = 0; j <= n; ++j)
                    {
                        if (used[j] != i)
                        {
                            fi[i] = j;
                            break;
                        }
                    }
                }
            }
            if (fi[n] == 0)
            {
                Console.WriteLine(-1);
            }
            else
            {
                Console.WriteLine(kucha[n]);
            }
        }
    }
}

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

namespace cs_console
{
    class _73_2_E
    {
        public static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] b = new int[n + 1];
            b[1] = -1;
            for (int i = 2; i <= n; i++)
            {
                b[i] = -1;
                for (int len = 2; len * (len + 1) / 2 <= i; len++)
                {
                    if (i * 2 % len == 0)
                    {
                        int aa = i * 2 / len - len + 1;
                        if (aa % 2 == 0 && aa > 0)
                        {
                            int x = aa / 2;
                            //(x, len)
                            bool ok = true;
                            for (int k = 0; k < len; k++)
                            {
                                if (b[x + k] >= 0)
                                {
                                    ok = !ok;
                                }
                            }
                            if (ok)
                            {
                                b[i] = len;
                                break;
                            }
                        }
                    }
                }
            }
            //for (int i = 0; i < n; i++)
            //{
            //    Console.WriteLine(i + " " + b[i]);
            //}
            Console.WriteLine(b[n]);
        }
    }
}

using System;

namespace Codeforces
{
    class Program
    {
        static void Main()
        {
            var N = Int32.Parse(Console.ReadLine().Trim());

            int[] grandi = new int[N+1];
            int[] numGrandi = new int[N+1];
            int nim;
            int[] answ = new int[N+1];

            for (int i = 0; i < N + 1; i++)
                numGrandi[i] = -1;
            for (int n = 0; n <= N; n++)
            {
                for (int count = 2; (count * (count + 1)) / 2 <= n; count++)
                {
                    if ((2 * n - count * (count - 1)) % (2 * count) != 0)
                        continue;
                    int a = (2 * n - count * (count - 1)) / (2 * count);
                    if (a < 1)
                        break;

                    nim = 0;
                    for (int j = 0; j < count; j++)
                        nim ^= grandi[a + j];

                    if (answ[n] <= 0)
                    {
                        if (nim == 0)
                            answ[n] = count;
                        else
                            answ[n] = -1;
                    }
                    numGrandi[nim] = n;
                }
                for (int i = 0; i <= N; i++)
                {
                    if (numGrandi[i] != n)
                    {
                        grandi[n] = i;
                        break;
                    }
                }
            }
            Console.WriteLine(answ[N]);
        }
    }
}

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

class ProblemE
{
    static int[] Lookup = new int[10001];

    static int Find(int n)
    {
        if (Lookup[n] != 0)
        {
            return Lookup[n];
        }
        else
        {
            int count = n % 2 == 1 ? 2 : 3;
            while (count * count / 2 <= n)
            {
                if ((2 * n) % count == 0)
                {
                    int twoa1 = (2 * n) / count - (count - 1);
                    if (twoa1 % 2 == 0 && twoa1 > 0)
                    {
                        int a1 = twoa1 / 2;
                        int countsuccess = 0;
                        for (int i = a1; i < a1 + count; i++)
                        {
                            if (Find(i) != -1)
                                countsuccess++;
                        }
                        if (countsuccess % 2 == 0)
                        {
                            Lookup[n] = count;
                            return count;
                        }
                    }
                }
                count++;
            }
            Lookup[n] = -1;
            return -1;
        }
    }

    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        Console.WriteLine(Find(n));
    }
}