using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    ReadData re;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        re = new ReadData();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        int N = re.i();
        int K = re.i();
        long M = re.i();
        long[] A = re.la();
        Array.Sort(A);
        long sum = 0;
        for(int i=0;i<K;i++){
            sum += A[i];
        }
        long count = 0;
        for(int i=0;i<=N;i++){
            if(i*sum > M){
                break;
            }
            long rest = M - i*sum;
            long c = i*(K+1);
            for(int j=0;j<K;j++){
                for(int k=0;k<N-i;k++){
                    if(rest >= A[j]){
                        c++;
                        rest -= A[j];
                    }
                }
            }
            count = Math.Max(c,count);
        }
        sb.Append(count+"\n");
    }
}
class ReadData{
    string[] str;
    int counter;
    public ReadData(){
        counter = 0;
    }
    public string s(){
        if(counter == 0){
            str = Console.ReadLine().Split(' ');
            counter = str.Length;
        }
        counter--;
        return str[str.Length-counter-1];
    }
    public int i(){
        return int.Parse(s());
    }
    public long l(){
        return long.Parse(s());
    }
    public double d(){
        return double.Parse(s());
    }
    public int[] ia(int N){
        int[] ans = new int[N];
        for(int j=0;j<N;j++){
            ans[j] = i();
        }
        return ans;
    }
    public int[] ia(){
        str = Console.ReadLine().Split(' ');
        counter = 0;
        int[] ans = new int[str.Length];
        for(int j=0;j<str.Length;j++){
            ans[j] = int.Parse(str[j]);
        }
        return ans;
    }
    public long[] la(int N){
        long[] ans = new long[N];
        for(int j=0;j<N;j++){
            ans[j] = l();
        }
        return ans;
    }
    public long[] la(){
        str = Console.ReadLine().Split(' ');
        counter = 0;
        long[] ans = new long[str.Length];
        for(int j=0;j<str.Length;j++){
            ans[j] = long.Parse(str[j]);
        }
        return ans;
    }
    public double[] da(int N){
        double[] ans = new double[N];
        for(int j=0;j<N;j++){
            ans[j] = d();
        }
        return ans;
    }
    public double[] da(){
        str = Console.ReadLine().Split(' ');
        counter = 0;
        double[] ans = new double[str.Length];
        for(int j=0;j<str.Length;j++){
            ans[j] = double.Parse(str[j]);
        }
        return ans;
    }
    public List<int>[] g(int N,int[] f,int[] t){
        List<int>[] ans = new List<int>[N];
        for(int j=0;j<N;j++){
            ans[j] = new List<int>();
        }
        for(int j=0;j<f.Length;j++){
            ans[f[j]].Add(t[j]);
            ans[t[j]].Add(f[j]);
        }
        return ans;
    }
    public List<int>[] g(int N,int M){
        List<int>[] ans = new List<int>[N];
        for(int j=0;j<N;j++){
            ans[j] = new List<int>();
        }
        for(int j=0;j<M;j++){
            int f = i()-1;
            int t = i()-1;
            ans[f].Add(t);
            ans[t].Add(f);
        }
        return ans;
    }
    public List<int>[] g(){
        int N = i();
        int M = i();
        List<int>[] ans = new List<int>[N];
        for(int j=0;j<N;j++){
            ans[j] = new List<int>();
        }
        for(int j=0;j<M;j++){
            int f = i()-1;
            int t = i()-1;
            ans[f].Add(t);
            ans[t].Add(f);
        }
        return ans;
    }
}


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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    long[,] MatMult(long[,] a, long[,] b, int n, int mod)
    {
        var ret = new long[n, n];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                for (int k = 0; k < n; k++)
                    ret[i, j] = (ret[i, j] + a[i, k] * b[k, j]) % mod;
        return ret;
    }

    long[,] MatPow(long[,] a, int n, long p, int mod)
    {
        var ret = new long[n, n];
        for (int i = 0; i < n; i++)
            ret[i, i] = 1;
        while (p > 0)
        {
            if ((p & 1) == 1)
                ret = MatMult(ret, a, n, mod);
            a = MatMult(a, a, n, mod);
            p >>= 1;
        }
        return ret;
    }

    public void Solve()
    {
        int n = ReadInt();
        var v = new long[] { ReadInt() - 1, ReadInt() - 1, (ReadInt() % n + n) % n, (ReadInt() % n + n) % n, 0, 1 };
        long t = ReadLong();

        var a = new long[,]
        {
            { 2, 1, 1, 0, 1, 2 },
            { 1, 2, 0, 1, 1, 2 },
            { 1, 1, 1, 0, 1, 2 },
            { 1, 1, 0, 1, 1, 2 },
            { 0, 0, 0, 0, 1, 1 },
            { 0, 0, 0, 0, 0, 1 }
        };

        a = MatPow(a, 6, t, n);
        var ans = new long[2];
        for (int i = 0; i < 2; i++)
            for (int j = 0; j < 6; j++)
                ans[i] = (ans[i] + a[i, j] * v[j]) % n;

        Write(ans[0] + 1, ans[1] + 1);
    }

    #region Main

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

    #endregion

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


using System;

namespace CSharp
{
    class _735C
    {
        public static void Main()
        {
            long n = long.Parse(Console.ReadLine());
            long max = 1;

            long fp = 1;
            long fc = 2;

            do
            {
                fc = fp + fc;
                fp = fc - fp;

                if (fc <= n)
                {
                    max++;
                }
            } while (fc <= n);

            Console.WriteLine(max);
        }
    }
}


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

namespace contest
{

    class contest
    {

        static void Main(string[] args)
        {

            //int n = int.Parse(Console.ReadLine());
            //var input = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();

            long n = long.Parse(Console.ReadLine());

            var fib = new long[90];
            fib[0] = 1;
            fib[1] = 2;

            for(int i=2; i<90; i++)
            {
                fib[i] = fib[i - 1] + fib[i - 2];
            }

            int ans = 0;
            for(int i=0; i<89; i++)
            {
                if(fib[i+1]>n)
                {
                    ans = i;
                    break;
                }
            }

            Console.WriteLine(ans);

        }

    }

}


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

class Program
{
	int[][] c;
	int n, m;
	int mod = 1000000007;
	int add(int x, int y)
	{
		x += y;
		return x < mod ? x : x - mod;
	}
	int mul(int x, int y)
	{
		return Convert.ToInt32(Convert.ToInt64(x) * y % mod);
	}
	int[][] newMatrix(int m)
	{
		int[][] ret = new int[m][];
		for (int i = 0; i < m; i++)
			ret[i] = new int[m];
		return ret;
	}
	void calcSum(ref int[][] sum, int[][] a)
	{
		for (int i = 1; i <= m; i++)
			for (int j = 1; j <= m; j++)
				sum[i][j] = add(sum[i - 1][j], a[i][j]);
		for (int i = 1; i <= m; i++)
			for (int j = 1; j <= m; j++)
				sum[i][j] = add(sum[i][j - 1], sum[i][j]);
	}
	int regionSum(int[][] sum, int lx, int rx, int ly, int ry)
	{
		--lx; --ly;
		return add(add(sum[lx][ly],sum[rx][ry]), mod - add(sum[lx][ry],sum[rx][ly]));
	}
	void run()
	{
		String[] str = Console.ReadLine().Split(' ');
		n = Convert.ToInt32(str[0]);
		m = Convert.ToInt32(str[1]);
		int[][][] dp11 = new int[n + 1][][],
			dp10 = new int[n + 1][][],
			dp01 = new int[n + 1][][],
			dp00 = new int[n + 1][][];
		dp11[1] = newMatrix(m + 1);
		dp10[1] = newMatrix(m + 1);
		dp01[1] = newMatrix(m + 1);
		dp00[1] = newMatrix(m + 1);
		for (int i = 1; i <= m; i++)
			for (int j = i; j <= m; j++)
				dp11[1][i][j] = 1;
		int[][] sum = newMatrix(m + 1);
		for (int i = 2; i <= n; i++)
		{
			dp11[i] = newMatrix(m + 1);
			dp10[i] = newMatrix(m + 1);
			dp01[i] = newMatrix(m + 1);
			dp00[i] = newMatrix(m + 1);
			calcSum(ref sum, dp11[i - 1]);
			for (int j = 1; j <= m; j++)
				for (int k = j; k <= m; k++)
				{
					dp11[i][j][k] = add(dp11[i][j][k], regionSum(sum, j, k, j, k));
					dp10[i][j][k] = add(dp10[i][j][k], regionSum(sum, j, k, k + 1, m));
					dp01[i][j][k] = add(dp01[i][j][k], regionSum(sum, 1, j - 1, j, k));
					dp00[i][j][k] = add(dp00[i][j][k], regionSum(sum, 1, j - 1, k + 1, m));
				}
			calcSum(ref sum, dp10[i - 1]);
			for (int j = 1; j <= m; j++)
				for (int k = j; k <= m; k++)
				{
					dp10[i][j][k] = add(dp10[i][j][k], regionSum(sum, j, k, k, m));
					dp00[i][j][k] = add(dp00[i][j][k], regionSum(sum, 1, j - 1, k, m));
				}
			calcSum(ref sum, dp01[i - 1]);
			for (int j = 1; j <= m; j++)
				for (int k = j; k <= m; k++)
				{
					dp01[i][j][k] = add(dp01[i][j][k], regionSum(sum, 1, j, j, k));
					dp00[i][j][k] = add(dp00[i][j][k], regionSum(sum, 1, j, k + 1, m));
				}
			calcSum(ref sum, dp00[i - 1]);
			for (int j = 1; j <= m; j++)
				for (int k = j; k <= m; k++)
				{
					dp00[i][j][k] = add(dp00[i][j][k], regionSum(sum, 1, j, k, m));
				}
		}
		int res = 0;
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= m; j++)
				for (int k = 1; k <= m; k++)
					res = add(res, mul(n - i + 1, add(add(dp00[i][j][k],dp01[i][j][k]), add(dp10[i][j][k],dp11[i][j][k]))));
		Console.WriteLine(res);
	}
	static void Main(String[] args)
	{
		new Program().run();
	}
}


using System;

class cf
{
    public static void Main()
    {
        var n = long.Parse(Console.ReadLine());

        if(n % 2 == 0)
        {
            Console.WriteLine(n / 2);
        }
        else
        {
            long i = 2;

            while(i * i <= n)
            {
                if(n % i == 0)
                {
                    break;
                }

                i++;
            }

            if(i * i > n)
            {
                Console.WriteLine(1);
            }
            else
            {
                n = n - i;

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

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading;
using System.Runtime.CompilerServices;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Template;
using SC = Scanner;

public partial class Solver
{
    public void Solve()
    {
        var N = sc.Long;
        var f = Factorize(N);
        var res = 0L;
        N -= f.Keys.Min();res++;
        res += N / 2; Console.WriteLine(res);
    }

    public static Dictionary<long, int> Factorize(long N)
    {
        var dic = new Dictionary<long, int>();
        for (long i = 2; i * i <= N; i++)
        {
            var ct = 0;
            while (N % i == 0)
            {
                ct++;
                N /= i;
            }
            if (ct != 0) dic[i] = ct;
        }
        if (N != 1) dic[N] = 1;
        return dic;
    }
}

#region Template
public partial class Solver
{
    public SC sc = new SC();
    static void Main(string[] args)
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        var sol = new Solver();
        int testcase = 1;
        //testcase = sol.sc.Int;
        //var th = new Thread(sol.Solve, 1 << 26);th.Start();th.Join();
        while (testcase-- > 0)
            sol.Solve();
        Console.Out.Flush();
    }
}
public static class Template
{
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) > 0) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; }
    public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; }
    public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; }
    public static void Out<T>(this IList<T> A, out T a) => a = A[0];
    public static void Out<T>(this IList<T> A, out T a, out T b) { a = A[0]; b = A[1]; }
    public static void Out<T>(this IList<T> A, out T a, out T b, out T c) { A.Out(out a, out b); c = A[2]; }
    public static void Out<T>(this IList<T> A, out T a, out T b, out T c, out T d) { A.Out(out a, out b, out c); d = A[3]; }
    public static string Concat<T>(this IEnumerable<T> A, string sp) => string.Join(sp, A);
    public static char ToChar(this int s, char begin = '0') => (char)(s + begin);
    public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid());
    public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; }
    public static string ToStr<T>(this T[][] A) => A.Select(a => a.Concat(" ")).Concat("\n");
    public static int ArgMax<T>(this IList<T> A, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; }
    public static T PopBack<T>(this List<T> A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; }
    public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }
}
public class Scanner
{
    public string Str => Console.ReadLine().Trim();
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
    public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
    public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
    public int[] ArrInt1D(int n) => Create(n, () => Int);
    public long[] ArrLong1D(int n) => Create(n, () => Long);
    public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
    public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
    private Queue<string> q = new Queue<string>();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }
    public void Make<T1>(out T1 v1) => v1 = Next<T1>();
    public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); }
    public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); }
    public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); }
    public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); }
    public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); }
    public void Make<T1, T2, T3, T4, T5, T6, T7>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6, out T7 v7) { Make(out v1, out v2, out v3, out v4, out v5, out v6); v7 = Next<T7>(); }
    public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, v2); }
    public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, out T3 v3); return (v1, v2, v3); }
    public (T1, T2, T3, T4) Make<T1, T2, T3, T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, v3, v4); }
}

#endregion


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

namespace ReadWriteTemplate
{
    public static class Solver
    {
        private static void SolveCase()
        {
            const long MOD = 1000000000 + 7;

            int n = ReadInt();
            long k = ReadLong();
            int[] a = ReadIntArray();

            int m = a.Sum();

            if (m == n)
            {
                Writer.WriteLine(1);
                return;
            }

            long[,] b = new long[m + 1, m + 1];
            for (int i = 0; i < m + 1; i++)
            {
                long l = Math.Max(0, 2 * i * (n + i - 2 * m));
                long r = 2 * (m - i) * (m - i);
                long e = n * (n - 1) - l - r;
                long inv = Inv(n * (n - 1), MOD);
                if (l > 0)
                {
                    b[i, i - 1] = l * inv % MOD;
                }
                b[i, i] = e * inv % MOD;
                if (r > 0)
                {
                    b[i, i + 1] = r * inv % MOD;
                }
            }

            long[,] c = MatrixBinPower(m + 1, b, k, MOD);

            int st = 0;
            for (int i = 0; i < m; i++)
            {
                st += a[n - i - 1];
            }

            long ans = c[st, m];

            Writer.WriteLine(ans);
        }

        public static long Inv(long a, long mod)
        {
            return BinPower(a, mod - 2, mod);
        }

        public static long BinPower(long a, long n, long mod)
        {
            long result = 1;

            while (n > 0)
            {
                if ((n & 1) != 0)
                {
                    result = (result * a) % mod;
                }

                a = (a * a) % mod;
                n >>= 1;
            }

            return result;
        }

        public static long[,] MatrixBinPower(int n, long[,] a, long p, long mod)
        {
            long[,] result = new long[n, n];
            for (int i = 0; i < n; i++)
            {
                result[i, i] = 1;
            }

            while (p > 0)
            {
                if ((p & 1) != 0)
                {
                    result = MatrixMult(n, result, a, mod);
                }

                a = MatrixMult(n, a, a, mod);
                p >>= 1;
            }

            return result;
        }

        public static long[,] MatrixMult(int n, long[,] a, long[,] b, long mod)
        {
            long[,] c = new long[n, n];

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    for (int k = 0; k < n; k++)
                    {
                        c[i, j] = (c[i, j] + a[i, k] * b[k, j]) % mod;
                    }
                }
            }

            return c;
        }

        public static void Solve()
        {
#if DEBUG
            var sw = Stopwatch.StartNew();
#endif

            SolveCase();

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

#if DEBUG
            sw.Stop();
            Console.WriteLine($"{sw.ElapsedMilliseconds} ms");
#endif
        }

        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();
            Thread thread = new Thread(Solve, 64 * 1024 * 1024);
            thread.CurrentCulture = CultureInfo.InvariantCulture;
            thread.Start();
            thread.Join();

            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();
            Shuffle(result);
            return result;
        }

        private static void Shuffle<T>(IList<T> array)
        {
            Random rnd = new Random();
            for (int i = array.Count - 1; i >= 1; i--)
            {
                int k = rnd.Next(i + 1);
                T tmp = array[k];
                array[k] = array[i];
                array[i] = tmp;
            }
        }

        #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.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System;
using System.Numerics;

class Solution
{
    public class GCD
    {
        public static int Euclidean(int n1, int n2)
        {
            if (n1 == n2) return n1;
            else if (n1 < n2)
            {
                var tmp = n1;
                n1 = n2;
                n2 = tmp;
            }

            while (n1 % n2 > 0)
            {
                var tmp = n2;
                n2 = n1 % n2;
                n1 = tmp;
            }
            return n2;
        }
        public static long Euclidean(long n1, long n2)
        {
            if (n1 == n2) return n1;
            else if (n1 < n2)
            {
                var tmp = n1;
                n1 = n2;
                n2 = tmp;
            }

            while (n1 % n2 > 0)
            {
                var tmp = n2;
                n2 = n1 % n2;
                n1 = tmp;
            }
            return n2;
        }

        public static long Inverse(long a, long n)
        {
            long x, y = 0;
            EuclideanExt(a, n, out x, out y);
            return x < 0 ? n + x : x;
        }

        public static long EuclideanExt(long n1, long n2, out long x, out long y)
        {
            x = 0;
            y = 1;

            bool r = false;
            if (n1 == n2) return n1;

            else if (n1 < n2)
            {
                r = true;
                var tmp = n1;
                n1 = n2;
                n2 = tmp;
            }
            long q = 0;
            long xl = 1;
            long yl = 0;

            while (n2 > 0)
            {
                q = n1 / n2;

                var tmp = n2;
                n2 = n1 % n2;
                n1 = tmp;

                tmp = x;
                x = xl - q * x;
                xl = tmp;

                tmp = y;
                y = yl - q * y;
                yl = tmp;

            }
            x = xl;
            y = yl;
            if (r)
            {
                x = yl;
                y = xl;
            }
            return x * n1 + y * n2;
        }
    }

    public static Tuple<long, long>[,] multiply(Tuple<long, long>[,] m1, Tuple<long, long>[,] m2)
    {
        Tuple<long, long>[,] ret = new Tuple<long, long>[m1.GetLength(0), m2.GetLength(1)];
        for (int i = 0; i < ret.GetLength(0); i++)
            for (int j = 0; j < ret.GetLength(1); j++)
            {
                ret[i, j] = new Tuple<long, long>(0, 0);
                for (int k = 0; k < m1.GetLength(1); k++)
                    ret[i, j] = sum(ret[i, j], prod(m1[i, k], m2[k, j]));
            }
        return ret;
    }

    public static Tuple<long, long>[,] recPow(Tuple<long, long>[,] m, long pow)
    {
        if (pow == 1)
            return m;

        var powered = recPow(m, pow / 2);
        var mult = multiply(powered, powered);
        if (pow % 2 == 1)
        {

            mult = multiply(mult, m);
        }
        return mult;
    }

    static Tuple<long, long> sum(Tuple<long, long> a, Tuple<long, long> b)
    {
        if (a.Item1 == 0)
            return b;
        if (b.Item1 == 0)
            return a;
        return Tuple.Create(
            ((a.Item1 * b.Item2) % mod + (b.Item1 * a.Item2) % mod) % mod,
            (a.Item2 * b.Item2) % mod
        );
    }

    static Tuple<long, long> prod(Tuple<long, long> a, Tuple<long, long> b)
    {
        return Tuple.Create(
            (a.Item1 * b.Item1) % mod,
            (a.Item2 * b.Item2) % mod
        );
    }

    static Tuple<long, long> PInOneSide(long cnt, long totalcnt)
    {
        return Tuple.Create(
            cnt * (cnt - 1) + (totalcnt - cnt) * (totalcnt - cnt - 1),
            totalcnt * (totalcnt - 1)
        );
    }

    static Tuple<long, long> PIncreaseLeftA(long leftCnt, long leftACnt, long totalcnt)
    {
        return Tuple.Create(
             (leftCnt - leftACnt) * (leftCnt - leftACnt),
            (totalcnt * (totalcnt - 1)) / 2
        );
    }

    static Tuple<long, long> PDecreaseLeftA(long leftCnt, long leftACnt, long totalcnt)
    {
        return Tuple.Create(
            leftACnt * (totalcnt - 2 * leftCnt + leftACnt),
            (totalcnt * (totalcnt - 1)) / 2
        );
    }

    static void CalcCashe(long lowerBnd, long leftCnt, long totalcnt)
    {
        PInOneSideCache = PInOneSide(leftCnt, totalcnt);

        PIncreaseLeftACache = new Tuple<long, long>[leftCnt - lowerBnd + 1];
        PDecreaseLeftACache = new Tuple<long, long>[leftCnt - lowerBnd + 1];
        PSameInBothSideCache = new Tuple<long, long>[leftCnt - lowerBnd + 1];

        for (long i = lowerBnd; i <= leftCnt; i++)
        {
            PIncreaseLeftACache[(int)(i - lowerBnd)] = PIncreaseLeftA(leftCnt, i, totalcnt);
            PDecreaseLeftACache[(int)(i - lowerBnd)] = PDecreaseLeftA(leftCnt, i, totalcnt);
            PSameInBothSideCache[(int)(i - lowerBnd)] = PSameInBothSide(leftCnt, i, totalcnt);
        }
    }
    static Tuple<long, long> PInOneSideCache;
    static Tuple<long, long>[] PSameInBothSideCache;
    static Tuple<long, long>[] PIncreaseLeftACache;
    static Tuple<long, long>[] PDecreaseLeftACache;
    static Tuple<long, long> PSameInBothSide(long leftCnt, long leftACnt, long totalcnt)
    {

        return Tuple.Create(
             (leftCnt - leftACnt) * (totalcnt + 2 * leftACnt - 2 * leftCnt),
            (totalcnt * (totalcnt - 1)) / 2
        );
    }

    const long mod = 1000000007L;
    static void Main(string[] args)
    {

        // var n = int.Parse( Console.ReadLine());
        var tmp = Array.ConvertAll(Console.ReadLine().Trim().Split(), Convert.ToInt64);
        var n = (long)tmp[0];
        var k = tmp[1];

        var arr = Array.ConvertAll(Console.ReadLine().Trim().Split(), Convert.ToByte);

        var leftcnt = (long)arr.Count(el => el == 0);
        var leftAcnt = (long)arr.Where((el, i) => el == 0 && i < leftcnt).Count();
        if (k < (leftcnt - leftAcnt))
        {
            Console.WriteLine("0");
            return;
        }
        if (leftcnt == n || leftcnt == 0)
        {
            Console.WriteLine("1");
            return;
        }

        var lowerBnd = (long)Math.Max(0, (int)(2 * (int)leftcnt - (int)n));

        Tuple<long, long>[,] A = new Tuple<long, long>[(int)(leftcnt - lowerBnd + 1), (int)(leftcnt - lowerBnd + 1)];

        CalcCashe(lowerBnd, leftcnt, n);

        for (int i = 0; i < A.GetLength(0); i++)
        {
            for (int j = 0; j < A.GetLength(0); j++)
            {
                if (i == j)
                {
                    A[i, j] = sum(PInOneSideCache, PSameInBothSideCache[i]);
                }
                else if (i == j + 1)
                {
                    A[i, j] = PIncreaseLeftACache[i - 1];
                }
                else if (i == j - 1)
                {
                    A[i, j] = PDecreaseLeftACache[i + 1];
                }
                else
                {
                    A[i, j] = Tuple.Create<long, long>(0, 0);
                }
            }
        }

        A = recPow(A, k);

        Tuple<long, long>[,] F = new Tuple<long, long>[leftcnt - lowerBnd + 1, 1];
        for (int i = 0; i < F.GetLength(0); i++)
        {
            if (i == leftAcnt - lowerBnd)
            {
                F[i, 0] = Tuple.Create(1l, 1L);
            }
            else
            {
                F[i, 0] = new Tuple<long, long>(0, 0);
            }
        }
        F = multiply(A, F);
        var tpl = F[F.GetLength(0) - 1, 0];
        if (tpl.Item1 == 0)
        {
            Console.WriteLine("0");
            return;
        }
        var gcd = GCD.Euclidean(tpl.Item1, tpl.Item2);
        var ret = Tuple.Create(tpl.Item1 / gcd, tpl.Item2 / gcd);

        var ret2 = ((long)ret.Item1 * GCD.Inverse((long)ret.Item2, (long)mod)) % (long)mod;

        Console.WriteLine($"{ret2}");

    }
}


using System;

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

            int[] size = new int[3];

            size[0] = int.Parse(inputArgs[0]);
            size[1] = int.Parse(inputArgs[1]);
            size[2] = int.Parse(inputArgs[2]);
            int k = int.Parse(inputArgs[3]);

            Array.Sort(size);

            int[] beats = new int[3];

            for (int i = 0; i < 3; i++)
            {
                beats[i] = (k / (3 - i) > size[i] - 1) ? size[i] - 1 : k / (3 - i);
                k -= beats[i];
            }

            ulong result = (((ulong)beats[0] + 1) * ((ulong)beats[1] + 1) * ((ulong)beats[2] + 1));

            Console.WriteLine(result);
        }
    }
}


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

namespace ProgrammingContest.Codeforces.Round66
{
    class A
    {
        public static void Main()
        {
            var xs = Array.ConvertAll(Console.ReadLine().Split(' '), sss=>long.Parse(sss));
            long k = xs[3];
            Array.Sort(xs, 0, 3);
            long[] ys = new long[3];
            for (int i = 0; i < 3; i++)
            {
                ys[i] = 1 + Math.Min((k + 2-i) / (3-i), xs[i] - 1);
                k -= ys[i] - 1;
                //Console.WriteLine("{0} {1} {2}", k, i, ys[i]);
            }
            Console.WriteLine(ys[0]*ys[1]*ys[2]);
        }
    }
}


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

namespace DimaAndHorses
{
    class Program
    {
        private static List<int>[] war;
        private static bool[] p;

        private static bool Check(int i)
        {
            return war[i].Count(e => p[e] == p[i]) <= 1;
        }

        private static void Fix(int i)
        {
            p[i] = !p[i];

            foreach (var e in war[i])
            {
                if (p[e] == p[i] && !Check(e))
                {
                    Fix(e);
                }
            }
        }

        private static void FixAll()
        {
            for (int i = 0; i < p.Length; i++)
            {
                if (!p[i] && !Check(i))
                {
                    Fix(i);
                }
            }
        }

        static void Main(string[] args)
        {
            // var fin = File.OpenText("test.txt");
            // Console.SetIn(fin);

            string[] nm = Console.ReadLine().Split(' ');
            int n = int.Parse(nm[0]);
            int m = int.Parse(nm[1]);

            war = new List<int>[n];
            p = new bool[n];
            for (int i = 0; i < n; i++)
            {
                war[i] = new List<int>();
                p[i] = false;
            }

            for (int i = 0; i < m; i++)
            {
                string[] ab = Console.ReadLine().Split(' ');
                int a = int.Parse(ab[0]) - 1;
                int b = int.Parse(ab[1]) - 1;

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

            FixAll();
            Console.WriteLine(string.Concat(p.Select(x => x ? 1 : 0)));

            // fin.Close();
        }
    }
}


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

public class E167
{
    public static void Main()
    {
        new E167().Entry();
    }//Main

    void Entry()
    {
        int[] tmp = intSplit(' ');
        int n = tmp[0];
        int m = tmp[1];
        int[] type = new int[n];
        List<int>[] edges = new List<int>[n];
        for (int i = 0; i < n; i++)
            edges[i] = new List<int>();
        for (int i = 0; i < m; i++)
        {
            tmp = intSplit(' ');
            int a = tmp[0] - 1;
            int b = tmp[1] - 1;
            edges[a].Add(b);
            edges[b].Add(a);
        }//for i
        Queue<int> que = new Queue<int>();
        for (int i = 0; i < n; i++)
            que.Enqueue(i);
        while (que.Count!=0)
        {
            int deq = que.Dequeue();
            int cnt = 0;
            foreach (int item in edges[deq])
            {
                if (type[item] == type[deq])
                    cnt++;
            }//foreach item
            if (cnt>=2)
            {
                type[deq] ^= 1;
                foreach (int item in edges[deq])
                {
                    if (type[item] == type[deq])
                        que.Enqueue(item);
                }//foreach item
            }//if
        }//while
        StringBuilder sb = new StringBuilder();
        foreach (int item in type)
        {
            sb.Append(item);
        }//foreach item
        Console.WriteLine(sb.ToString());
    }

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

    int intRead()
    {
        return int.Parse(Console.ReadLine());
    }

    long longRead()
    {
        return long.Parse(Console.ReadLine());
    }

    double doubleRead()
    {
        return double.Parse(Console.ReadLine());
    }

    string[] strSplit(char a)
    {
        return Console.ReadLine().Split(a);
    }

    int[] intSplit(char a)
    {
        return Array.ConvertAll<string, int>(Console.ReadLine().Split(a), int.Parse);
    }

    long[] longSplit(char a)
    {
        return Array.ConvertAll<string, long>(Console.ReadLine().Split(a), long.Parse);
    }

    double[] doubleSplit(char a)
    {
        return Array.ConvertAll<string, double>(Console.ReadLine().ToString().Split('a'), double.Parse);
    }

}//Template


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

namespace DrawRubik1594E1
{
    class Program
    {
        static void Main(string[] args)
        {
            int k = Int32.Parse(Console.ReadLine());
            long result = 6;
            long mul = 16;
            while (k > 1)
            {
                result *= mul;
                result %= 1000000007;
                mul *= mul;
                mul %= 1000000007;
                --k;
            }
            Console.WriteLine(result);
        }
    }
}


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

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

        ModInt[] dp = new ModInt[N + 1];
        dp[1] = 1;
        for(int i = 2;i <= N; i++)
        {
            dp[i] = dp[i - 1] * dp[i - 1] * 16;
        }

        Console.WriteLine(dp[N] * 6);
    }

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

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

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

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

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

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

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

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

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

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

            return _line[_index++];
        }

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

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

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

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


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

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        Console.WriteLine(ModInt.Pow(27, n) - ModInt.Pow(7, n));
    }

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

#region ModInt

/// <summary>
/// [0,<see cref="Mod"/>) までの値を取るような数
/// </summary>
public struct ModInt
{
    /// <summary>
    /// 剰余を取る値．
    /// </summary>
    public const long Mod = (int) 1e9 + 7;

    /// <summary>
    /// 実際の数値．
    /// </summary>
    public long num;

    /// <summary>
    /// 値が <paramref name="n"/> であるようなインスタンスを構築します．
    /// </summary>
    /// <param name="n">インスタンスが持つ値</param>
    /// <remarks>パフォーマンスの問題上，コンストラクタ内では剰余を取りません．そのため，<paramref name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/> を渡してください．このコンストラクタは O(1) で実行されます．</remarks>
    public ModInt(long n)
    {
        num = n;
    }

    /// <summary>
    /// このインスタンスの数値を文字列に変換します．
    /// </summary>
    /// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10 進表記したもの．</returns>
    public override string ToString()
    {
        return num.ToString();
    }

    public static ModInt operator +(ModInt l, ModInt r)
    {
        l.num += r.num;
        if (l.num >= Mod) l.num -= Mod;
        return l;
    }

    public static ModInt operator -(ModInt l, ModInt r)
    {
        l.num -= r.num;
        if (l.num < 0) l.num += Mod;
        return l;
    }

    public static ModInt operator *(ModInt l, ModInt r)
    {
        return new ModInt(l.num * r.num % Mod);
    }

    public static implicit operator ModInt(long n)
    {
        n %= Mod;
        if (n < 0) n += Mod;
        return new ModInt(n);
    }

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

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

    /// <summary>
    /// 与えられた数の逆元を計算します．
    /// </summary>
    /// <param name="v">逆元を取る対象となる数</param>
    /// <returns>逆元となるような値</returns>
    /// <remarks>法が素数であることを仮定して，フェルマーの小定理に従って逆元を O(log N) で計算します．</remarks>
    public static ModInt Inverse(ModInt v)
    {
        return Pow(v, Mod - 2);
    }
}

#endregion

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

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

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

        return _line[_pos++];
    }

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

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

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}


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

namespace Task2
{
    class Program
    {
        static void Main(string[] args)
        {
            const long size = 1000000007;
            long n = long.Parse(Console.ReadLine());
            long x = 3;
            long y = 7;
            for (int i = 1; i < 3*n; i++)
            {
                x *= 3;
                if (x >= size) x %= size;
            }
            for (int i = 1; i < n; i++)
            {
                y *= 7;
                if (y >= size) y %= size;
            }
            if (x - y < 0) Console.WriteLine(x - y + size);
            else Console.WriteLine(x - y);
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;

namespace Program
{
    public static class ProblemD
    {
        static bool SAIKI = false;
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            var n = (int)NN;
            var m = (int)NN;
            var q = (int)NN;
            var pList = NNList(n);
            var ab = Repeat(0, m).Select(_ => new { a = (int)NN - 1, b = (int)NN - 1 }).ToArray();
            var query = Repeat(0, q).Select(_ => new { t = (int)NN, param = (int)NN }).ToArray();
            var graph = Repeat(0, n).Select(_ => new List<int>()).ToArray();
            var uf = new LIB_UnionFind(n);
            var deleted = new bool[m];
            foreach (var item in query)
            {
                if (item.t == 2) deleted[item.param - 1] = true;
            }
            var procTgtEdgeIndex = new bool[m];
            for (var i = 0; i < m; i++)
            {
                if (!deleted[i])
                {
                    if (uf.Unite(ab[i].a, ab[i].b))
                    {
                        graph[ab[i].a].Add(ab[i].b);
                        graph[ab[i].b].Add(ab[i].a);
                    }
                }
            }
            foreach (var item in query.Reverse())
            {
                if (item.t == 2)
                {
                    var i = item.param - 1;
                    if (uf.Unite(ab[i].a, ab[i].b))
                    {
                        procTgtEdgeIndex[i] = true;
                        graph[ab[i].a].Add(ab[i].b);
                        graph[ab[i].b].Add(ab[i].a);
                    }
                }
            }
            var param = new int[n];
            var qList = new List<LIB_PriorityQueue<int, int>>();
            var used = new bool[n];
            {
                var done = new bool[n];
                for (var i = 0; i < n; i++)
                {
                    if (!done[i])
                    {
                        var c = qList.Count();
                        var tmpq = new LIB_PriorityQueue<int, int>(false);
                        qList.Add(tmpq);
                        var que = new Queue<int>();
                        que.Enqueue(i);
                        done[i] = true;
                        param[i] = c;
                        while (que.Count > 0)
                        {
                            var v = que.Dequeue();
                            foreach (var item in graph[v])
                            {
                                if (done[item]) continue;
                                done[item] = true;
                                param[item] = c;
                                que.Enqueue(item);
                            }
                        }
                    }
                    qList[param[i]].Push((int)pList[i], i);
                }
            }
            var leftVs = new List<int>();
            var rightVs = new List<int>();
            var leftQ = new Queue<(int, int)>();
            var rightQ = new Queue<(int, int)>();
            foreach (var item in query)
            {
                if (item.t == 1)
                {
                    var v = item.param - 1;
                    var p = param[v];
                    var que = qList[p];
                    var value = 0L;
                    while (que.Count > 0)
                    {
                        if (used[que.Peek.Value] || p != param[que.Peek.Value]) que.Pop();
                        else
                        {
                            used[que.Peek.Value] = true;
                            value = que.Pop().Key;
                            break;
                        }
                    }
                    Console.WriteLine(value);
                }
                else
                {
                    var leftV = ab[item.param - 1].a;
                    var rightV = ab[item.param - 1].b;
                    if (!procTgtEdgeIndex[item.param - 1]) continue;
                    leftQ.Clear();
                    rightQ.Clear();
                    var color = param[leftV];
                    var lidx = 0;
                    var ridx = 0;
                    var lv = leftV;
                    var rv = rightV;
                    var lp = rightV;
                    var rp = leftV;
                    var exit = false;
                    leftVs.Clear();
                    rightVs.Clear();
                    leftVs.Add(lv);
                    rightVs.Add(rv);
                    var procVs = leftVs;
                    while (true)
                    {
                        var leftOK = false;
                        while (true)
                        {
                            while (graph[lv].Count > lidx)
                            {
                                var v = graph[lv][lidx++];
                                if (v == lp) continue;
                                if (color != param[v]) continue;
                                leftQ.Enqueue((v, lv));
                                leftVs.Add(v);
                                leftOK = true;
                                break;
                            }
                            if (leftOK) break;
                            if (leftQ.Count == 0)
                            {
                                exit = true;
                                break;
                            }
                            var pop = leftQ.Dequeue();
                            lv = pop.Item1;
                            lp = pop.Item2;
                            lidx = 0;
                        }
                        if (exit) break;
                        var rightOK = false;
                        while (true)
                        {
                            while (graph[rv].Count > ridx)
                            {
                                var v = graph[rv][ridx++];
                                if (v == rp) continue;
                                if (color != param[v]) continue;
                                rightQ.Enqueue((v, rv));
                                rightVs.Add(v);
                                rightOK = true;
                                break;
                            }
                            if (rightOK) break;
                            if (rightQ.Count == 0)
                            {
                                procVs = rightVs;
                                exit = true;
                                break;
                            }
                            var pop = rightQ.Dequeue();
                            rv = pop.Item1;
                            rp = pop.Item2;
                            ridx = 0;
                        }
                        if (exit) break;
                    }
                    var procColorTo = qList.Count;
                    var tmpq = new LIB_PriorityQueue<int, int>(false);
                    qList.Add(tmpq);
                    foreach (var item2 in procVs)
                    {
                        if (!used[item2]) tmpq.Push((int)pList[item2], item2);
                        param[item2] = procColorTo;
                    }
                }
            }
        }
        class Printer : StreamWriter
        {
            public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
            public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }
            public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }
        }
        static LIB_FastIO fastio = new LIB_FastIODebug();
        static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } if (SAIKI) { var t = new Thread(Solve, 134217728); t.Start(); t.Join(); } else Solve(); Console.Out.Flush(); }
        static long NN => fastio.Long();
        static double ND => fastio.Double();
        static string NS => fastio.Scan();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static IOrderedEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift);
        static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x.OrderByRand(), e => e);
        static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderBy(x.OrderByRand(), selector);
        static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) => Enumerable.OrderByDescending(x.OrderByRand(), e => e);
        static IOrderedEnumerable<T1> OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderByDescending(x.OrderByRand(), selector);
        static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByRand().OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderByDescending(selector, StringComparer.OrdinalIgnoreCase);
        static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x);
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
        static bool Chmax<T>(this ref T lhs, T rhs) where T : struct, IComparable<T> { if (lhs.CompareTo(rhs) < 0) { lhs = rhs; return true; } return false; }
        static bool Chmin<T>(this ref T lhs, T rhs) where T : struct, IComparable<T> { if (lhs.CompareTo(rhs) > 0) { lhs = rhs; return true; } return false; }
    }
}
namespace Library {
    class LIB_UnionFind<T>
    {
        int[] d;
        T[] v;
        Func<T, T, T> f;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_UnionFind(IEnumerable<T> s, Func<T, T, T> func)
        {
            v = s.ToArray();
            d = Enumerable.Repeat(-1, v.Length).ToArray();
            f = func;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public bool Unite(long x, long y)
        {
            x = Root(x);
            y = Root(y);
            if (x != y)
            {
                d[x] = d[x] + d[y];
                v[x] = f(v[x], v[y]);
                d[y] = (int)x;
            }
            return x != y;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public bool IsSame(long x, long y) => Root(x) == Root(y);
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public long Root(long x) => d[x] < 0 ? x : d[x] = (int)Root(d[x]);
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public long Count(long x) => -d[Root(x)];
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public T Calc(long x) => v[Root(x)];
    }
    class LIB_UnionFind : LIB_UnionFind<int>
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_UnionFind(long n) : base(Enumerable.Repeat(0, (int)n), (x, y) => x + y) { }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        new private void Calc(long x) { }
    }
    class LIB_FastIO
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_FastIO() { str = Console.OpenStandardInput(); }
        readonly Stream str;
        readonly byte[] buf = new byte[2048];
        int len, ptr;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        byte read()
        {
            if (ptr >= len)
            {
                ptr = 0;
                if ((len = str.Read(buf, 0, 2048)) <= 0)
                {
                    return 0;
                }
            }
            return buf[ptr++];
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        char Char()
        {
            byte b = 0;
            do b = read();
            while (b < 33 || 126 < b);
            return (char)b;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        virtual public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        virtual public long Long()
        {
            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 << 3) + (ret << 1) + b - '0';
            }
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); }
    }
    class LIB_FastIODebug : LIB_FastIO
    {
        Queue<string> param = new Queue<string>();
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_FastIODebug() { }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override string Scan() => NextString();
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override long Long() => long.Parse(NextString());
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override double Double() => double.Parse(NextString());
    }
    class LIB_PriorityQueue
    {
        long[] heap;
        int[] dat;
        public (long, int) Peek => (heap[0], dat[0]);
        public long Count
        {
            get;
            private set;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue()
        {
            heap = new long[16];
            dat = new int[16];
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void Push(long key, int val)
        {
            if (Count == heap.Length) Expand();
            var i = Count++;
            heap[i] = key;
            dat[i] = val;
            while (i > 0)
            {
                var ni = (i - 1) / 2;
                if (key <= heap[ni]) break;
                heap[i] = heap[ni];
                dat[i] = dat[ni];
                i = ni;
            }
            heap[i] = key;
            dat[i] = val;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public KeyValuePair<long, int> Pop()
        {
            var ret = new KeyValuePair<long, int>(heap[0], dat[0]);
            var key = heap[--Count];
            var val = dat[Count];
            if (Count == 0) return ret;
            var i = 0; while ((i << 1) + 1 < Count)
            {
                var i1 = (i << 1) + 1;
                var i2 = (i << 1) + 2;
                if (i2 < Count && heap[i1] < heap[i2]) i1 = i2;
                if (key >= heap[i1]) break;
                heap[i] = heap[i1];
                dat[i] = dat[i1];
                i = i1;
            }
            heap[i] = key;
            dat[i] = val;
            return ret;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        void Expand()
        {
            var tmp = new long[Count << 1];
            for (var i = 0; i < heap.Length; ++i) tmp[i] = heap[i];
            heap = tmp;
            var tmp2 = new int[Count << 1];
            for (var i = 0; i < dat.Length; ++i) tmp2[i] = dat[i];
            dat = tmp2;
        }
    }
    class LIB_PriorityQueue<T>
    {
        T[] heap;
        Comparison<T> comp;
        public T Peek => heap[0];
        public long Count
        {
            get;
            private set;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(long cap, Comparison<T> cmp, bool asc = true)
        {
            heap = new T[cap];
            comp = asc ? cmp : (x, y) => cmp(y, x);
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(Comparison<T> cmp, bool asc = true)
        {
            heap = new T[16];
            comp = asc ? cmp : (x, y) => cmp(y, x);
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(long cap, bool asc = true) : this(cap, Comparer<T>.Default.Compare, asc) { }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(bool asc = true) : this(Comparer<T>.Default.Compare, asc) { }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void Push(T val)
        {
            if (Count == heap.Length) Expand();
            var i = Count++;
            heap[i] = val;
            while (i > 0)
            {
                var ni = (i - 1) / 2;
                if (comp(val, heap[ni]) >= 0) break;
                heap[i] = heap[ni];
                i = ni;
            }
            heap[i] = val;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public T Pop()
        {
            var ret = heap[0];
            var val = heap[--Count];
            if (Count == 0) return ret;
            var i = 0; while ((i << 1) + 1 < Count)
            {
                var i1 = (i << 1) + 1;
                var i2 = (i << 1) + 2;
                if (i2 < Count && comp(heap[i1], heap[i2]) > 0) i1 = i2;
                if (comp(val, heap[i1]) <= 0) break;
                heap[i] = heap[i1]; i = i1;
            }
            heap[i] = val;
            return ret;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        void Expand()
        {
            var tmp = new T[Count << 1];
            for (var i = 0; i < heap.Length; ++i) tmp[i] = heap[i];
            heap = tmp;
        }
    }
    class LIB_PriorityQueue<TK, TV>
    {
        LIB_PriorityQueue<KeyValuePair<TK, TV>> q;
        public KeyValuePair<TK, TV> Peek => q.Peek;
        public long Count => q.Count;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(long cap, Comparison<TK> cmp, bool asc = true)
        {
            q = new LIB_PriorityQueue<KeyValuePair<TK, TV>>(cap, (x, y) => cmp(x.Key, y.Key), asc);
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(Comparison<TK> cmp, bool asc = true)
        {
            q = new LIB_PriorityQueue<KeyValuePair<TK, TV>>((x, y) => cmp(x.Key, y.Key), asc);
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(long cap, bool asc = true) : this(cap, Comparer<TK>.Default.Compare, asc) { }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(bool asc = true) : this(Comparer<TK>.Default.Compare, asc) { }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void Push(TK k, TV v) => q.Push(new KeyValuePair<TK, TV>(k, v));
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public KeyValuePair<TK, TV> Pop() => q.Pop();
    }
}


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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    static List<int[]> g;

    class Dsu
    {
        public readonly List<int> parent;

        public Dsu(int n)
        {
            parent = Enumerable.Range(0, n).ToList();
            g = new List<int[]>();
            for (int i = 0; i < n; i++)
                g.Add(new int[] { -1, -1 });
        }

        public int FindSet(int v)
        {
            if (v == parent[v])
                return v;
            return parent[v] = FindSet(parent[v]);
        }

        public void UnionSets(int a, int b)
        {
            a = FindSet(a);
            b = FindSet(b);
            if (a != b)
            {
                parent[a] = parent[b] = parent.Count;
                g.Add(new[] { a, b });
                parent.Add(parent.Count);
            }
        }
    }

    int[] c;
    int[] tree;

    int Cmp(int l, int r)
    {
        return c2[l] > c2[r] ? l : r;
    }

    void Build(int x, int xl, int xr)
    {
        if (xl == xr)
        {
            tree[x] = xl;
            return;
        }
        int xm = (xl + xr) / 2;
        Build(x * 2, xl, xm);
        Build(x * 2 + 1, xm + 1, xr);
        tree[x] = Cmp(tree[2 * x], tree[2 * x + 1]);
    }

    void Set(int x, int xl, int xr, int idx)
    {
        if (xl == xr)
        {
            c2[xl] = 0;
            return;
        }

        int xm = (xl + xr) / 2;
        if (idx <= xm)
            Set(x * 2, xl, xm, idx);
        else
            Set(x * 2 + 1, xm + 1, xr, idx);
        tree[x] = Cmp(tree[2 * x], tree[2 * x + 1]);
    }

    int Query(int x, int xl, int xr, int l, int r)
    {
        if (l == xl && r == xr)
            return tree[x];
        int xm = (xl + xr) / 2;
        if (r <= xm)
            return Query(x * 2, xl, xm, l, r);
        if (l > xm)
            return Query(x * 2 + 1, xm + 1, xr, l, r);
        return Cmp(Query(x * 2, xl, xm, l, xm), Query(x * 2 + 1, xm + 1, xr, xm + 1, r));
    }

    int n;
    bool[] vis;
    int[] tin, tout, c2;
    int timer;
    void Dfs(int x)
    {
        if (x < n)
            c2[timer] = c[x];
        vis[x] = true;
        tin[x] = timer++;
        foreach (int e in g[x])
            if (e != -1)
                Dfs(e);
        tout[x] = timer;
    }

    public void Solve()
    {
        n = ReadInt();
        int m = ReadInt();
        int q = ReadInt();
        c = ReadIntArray();
        var a = ReadIntMatrix(m);
        var b = ReadIntMatrix(q);

        //n = 200000;
        //m = 199999;
        //q = 500000;
        //c = new int[n];
        //var rnd = new Random(13);
        //for (int i = 0; i < n; i++)
        //    c[i] = rnd.Next(n) + 1;
        //a = new int[m][];
        //for (int i = 0; i < m; i++)
        //    a[i] = new[] { i + 1, i + 2 };
        //b = new int[q][];
        //int cnt = 1;
        //for (int i = 0; i < q; i++)
        //{
        //    b[i] = new int[2];
        //    b[i][0] = rnd.Next(2) + 1;
        //    if (cnt > m)
        //        b[i][0] = 1;
        //    if (b[i][0] == 1)
        //    {
        //        b[i][1] = rnd.Next(n) + 1;
        //    }
        //    else
        //    {
        //        b[i][1] = cnt++;
        //    }
        //}

        var f = new bool[m];
        for (int i = 0; i < q; i++)
        {
            b[i][1]--;
            if (b[i][0] == 2)
                f[b[i][1]] = true;
        }

        var dsu = new Dsu(n);
        for (int i = 0; i < m; i++)
        {
            a[i][0]--;
            a[i][1]--;
            if (!f[i])
                dsu.UnionSets(a[i][0], a[i][1]);
        }

        for (int i = q - 1; i >= 0; i--)
        {
            if (b[i][0] == 1)
            {
                b[i][1] = dsu.FindSet(b[i][1]);
            }
            else
            {
                dsu.UnionSets(a[b[i][1]][0], a[b[i][1]][1]);
            }
        }

        int n2 = dsu.parent.Count;
        tin = new int[n2];
        tout = new int[n2];
        vis = new bool[n2];
        c2 = new int[n2];
        for (int i = n2 - 1; i >= 0; i--)
            if (!vis[i])
                Dfs(i);

        tree = new int[4 * n2];
        Build(1, 0, n2 - 1);
        for (int i = 0; i < q; i++)
            if (b[i][0] == 1)
            {
                int x = Query(1, 0, n2 - 1, tin[b[i][1]], tout[b[i][1]] - 1);
                Write(c2[x]);
                Set(1, 0, n2 - 1, x);
            }
    }

    #region Main

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

    #endregion

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