import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Vadim Semenov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskG solver = new TaskG();
        solver.solve(1, in, out);
        out.close();
    }

    static final class TaskG {
        public void solve(int __, InputReader in, PrintWriter out) {
            int qty = in.nextInt();
            long targetGcd = in.nextLong();
            long targetLcm = in.nextLong();
            long[] rangs = in.nextLongArray(qty);
            if (targetLcm % targetGcd != 0) {
                out.println(0);
                return;
            }
            long[] primes = getPrimes(targetLcm, rangs);
            int[] lcmFactorization = factorize(targetLcm, primes);
            int[] gcdFactorization = factorize(targetGcd, primes);
            int primesQty = 0;
            for (int i = 0; i < primes.length; ++i) {
                if (lcmFactorization[i] > gcdFactorization[i]) {
                    primes[primesQty] = primes[i];
                    lcmFactorization[primesQty] = lcmFactorization[i];
                    gcdFactorization[primesQty] = gcdFactorization[i];
                    ++primesQty;
                }
            }
            if (primesQty < primes.length) {
                primes = Arrays.copyOfRange(primes, 0, primesQty);
                lcmFactorization = Arrays.copyOfRange(lcmFactorization, 0, primesQty);
                gcdFactorization = Arrays.copyOfRange(gcdFactorization, 0, primesQty);
            }
            boolean[] possibleGcd = new boolean[qty];
            boolean[] possibleLcm = new boolean[qty];
            int[] maskGcd = new int[qty];
            int[] maskLcm = new int[qty];
            for (int i = 0; i < qty; ++i) {
                long rang = rangs[i];
                possibleGcd[i] = rang % targetGcd == 0;
                possibleLcm[i] = targetLcm % rang == 0;
                if (!possibleGcd[i] && !possibleLcm[i]) continue;
                int[] factorization = factorize(rang, primes);
                for (int j = 0; j < primes.length; ++j) {
                    if (factorization[j] > gcdFactorization[j]) {
                        maskGcd[i] |= 1 << j;
                    }
                    if (factorization[j] < lcmFactorization[j]) {
                        maskLcm[i] |= 1 << j;
                    }
                }
            }
            int totalMask = (1 << primes.length) - 1;
            int[] count = new int[totalMask + 1];
            for (int i = 0; i < qty; ++i) {
                if (possibleGcd[i]) {
                    count[maskGcd[i]]++;
                }
            }
            for (int mask = totalMask; mask > 0; --mask) {
                for (int subMask = (mask - 1) & mask; subMask > 0; subMask = (subMask - 1) & mask) {
                    count[mask] += count[subMask];
                }
                count[mask] += count[0];
            }
            long answer = 0;
            for (int i = 0; i < qty; ++i) {
                if (possibleLcm[i]) {
                    answer += count[totalMask ^ maskLcm[i]];
                }
            }
            out.println(answer);
        }

        private int[] factorize(long number, long[] primes) {
            int[] powers = new int[primes.length];
            for (int i = 0; i < primes.length; ++i) {
                while (number % primes[i] == 0) {
                    powers[i]++;
                    number /= primes[i];
                }
            }
            return powers;
        }

        private long[] getPrimes(long number, long[] rangs) {
            List<Long> primes = new ArrayList<>();
            for (int p = 2; p <= Math.min(1_000_000, 10 + Math.sqrt(number)); ++p) {
                if (number % p == 0) {
                    primes.add((long) p);
                    while (number % p == 0) {
                        number /= p;
                    }
                }
            }
            if (number > 1) {
                for (long rang : rangs) {
                    long gcd = gcd(rang, number);
                    if (gcd != 1 && gcd != number) {
                        long div = number / gcd;
                        primes.add(Math.min(gcd, div));
                        if (gcd != div) {
                            primes.add(Math.max(gcd, div));
                        }
                    }
                }
            }
            long[] result = new long[primes.size()];
            for (int i = 0; i < primes.size(); ++i) {
                result[i] = primes.get(i);
            }
            return result;
        }

        private static long gcd(long a, long b) {
            while (b != 0) {
                long tmp = a % b;
                a = b;
                b = tmp;
            }
            return a;
        }

    }

    static class InputReader {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public long[] nextLongArray(int size) {
            long[] array = new long[size];
            for (int i = 0; i < size; ++i) {
                array[i] = nextLong();
            }
            return array;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(readLine());
            }
            return tokenizer.nextToken();
        }

        public String readLine() {
            String line;
            try {
                line = reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }

    }
}


import java.util.*;
public class d {
	public static void main(String[] arg) {
		new d();
	}
	public d() {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] smallestPrime = new int[n+1];
		boolean[] isPrime = new boolean[n+1];
		Arrays.fill(isPrime, true);
		isPrime[0] = isPrime[1] = false;
		for(int i = 2; i < isPrime.length; i++) {
			if(isPrime[i]) {
				smallestPrime[i] = i;
				for(int j = i+i; j < isPrime.length; j+=i) {
					isPrime[j] = false;
					if(smallestPrime[j] == 0) smallestPrime[j] = i;
				}
			}
		}
		long[] numP = new long[n+1];
		for(int i = 2; i <= n; i++) {
			numP[smallestPrime[i]]++;
		}
		long[] cum = new long[n+1];
		cum[0] = numP[0];
		for(int i = 1; i <= n; i++) {
			cum[i] += cum[i-1]+numP[i];
		}
		long count2 = 1L * n * (n - 1) / 2 - (n - 1);
		long ans = 0;
		/*
		for(int i = 2; i <= n; i++) {
			int p = smallestPrime[i];
			int other = i/p;
			if(isPrime[other] && other > p) {
//				System.out.println(i + " " + other + " " + numP[p] + " " + numP[other]);
				long temp = numP[p]*numP[other];
				for(int j = p; j <= n; j+=p) {
					if(j % other == 0 && smallestPrime[j] == p)
						temp -= numP[other];
				}
				ans += 2*temp;
			}
		}*/
		outer:
		for(int i = 2; i <= n; i++) {
			long count = 0;
			int sign = -1;
			int x = i;
			while(x > 1) {
				int y = smallestPrime[x];
				x /= y;
				if(smallestPrime[x] == y) {
					continue outer;
				}
				sign *= -1;
			}
			for(int j = i; j <= n; j += i) {
				count++;
			}
			count2 -= sign*(count*(count-1)/2);
			ans += sign*(count*(count-1)/2);
		}
		for(int i = 2; i <= n; i++) {
			if(!isPrime[i]) continue;
			if(n / 2 <= i) continue;
			long c = cum[n / 2];
			c -= cum[Math.max(n / i, i)];
			ans += numP[i]*c*3;
			count2 -= numP[i]*c;
		}
		//System.err.println(count2);
		long numSpec = 0;
		for (int i = 2; i <= n; i++) {
			if (smallestPrime[i] * 2 > n) {
				numSpec++;
			}
		}
		count2 -= (n - 2) * numSpec;
		count2 += numSpec * (numSpec - 1) / 2;
		//System.err.println(count2);
		ans += count2 * 2;
		System.out.println(ans);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class E {
    static long mod = 1000000007;
    static long[][] ways = new long[1001][1001];
    static int k;

    public static long getTotal(String x) {
        long ans = 0;
        for (int i = 0; i < x.length(); i++)
            ans = (10 * ans + x.charAt(i) - '0') % mod;
        return ans;
    }

    public static long get(String x, int index, int cantPut47) {
        if (index == x.length())
            return 1;
        int maxDigit = x.charAt(index) - '0';
        long ans = 0;
        for (int i = 0; i <= maxDigit; i++) {
            if ((i == 4 || i == 7) && cantPut47 > 0)
                continue;
            if (i == 4 || i == 7)
                if (i < maxDigit)
                    ans = (ans + ways[x.length() - index - 1][k]) % mod;
                else
                    ans = (ans + get(x, index + 1, k)) % mod;
            else if (i < maxDigit)
                ans = (ans + ways[x.length() - index - 1][Math.max(
                        cantPut47 - 1, 0)]) % mod;
            else
                ans = (ans + get(x, index + 1, Math.max(cantPut47 - 1, 0)))
                        % mod;
        }
        return ans;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] S = in.readLine().split(" ");
        int t = Integer.parseInt(S[0]);
        k = Integer.parseInt(S[1]);
        for (int i = 0; i < 1001; i++)
            ways[0][i] = 1;
        for (int i = 1; i < 1001; i++)
            for (int j = 0; j < 1001; j++)
                if (j == 0)
                    ways[i][j] = (8 * ways[i - 1][0] + 2 * ways[i - 1][k])
                            % mod;
                else
                    ways[i][j] = (8 * ways[i - 1][j - 1]) % mod;
        for (int i = 0; i < t; i++) {
            S = in.readLine().split(" ");
            String left = "" + (new BigInteger(S[0]).subtract(BigInteger.ONE));
            String right = S[1];
            long tot = (getTotal(right) - getTotal(left) + mod) % mod;
            long bad = (get(right, 0, 0) - get(left, 0, 0) + mod) % mod;
            long ans = (tot - bad + mod) % mod;
            System.out.println(ans);
        }
    }
}


import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author George Marcus
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskE solver = new TaskE();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskE {
    char[][] A;
    int[] ans;
    ArrayList<Integer>[] B;
    int[] inGroup;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int N = in.nextInt();
        A = new char[N][];
        for (int i = 0; i < N; i++) {
            A[i] = in.nextString().toCharArray();
        }

        ans = new int[N + 1];
        B = new ArrayList[N];
        for (int i = 0; i < N; i++) {
            B[i] = new ArrayList<Integer>();
            for (int j = 0; j < N; j++) {
                if (A[i][j] == '1') {
                    B[i].add(j);
                }
            }
        }

        ArrayList<Integer> rows = new ArrayList<Integer>();
        ArrayList<Integer> cols = new ArrayList<Integer>();
        for (int i = 0; i < N; i++) {
            if (!B[i].isEmpty()) {
                rows.add(i);
            }
            cols.add(i);
        }

        inGroup = new int[N];
        if (go(rows, cols)) {
            out.println("YES");
            for (int i = 0; i < N; i++) {
                for (int j = 1; j <= N; j++) {
                    out.print(A[i][ans[j]]);
                }
                out.println();
            }
        }
        else {
            out.println("NO");
        }
    }

    private boolean go(ArrayList<Integer> rows, ArrayList<Integer> cols) {
        if (rows.isEmpty()) {
            for (int col : cols) {
                ans[++ans[0]] = col;
            }
            return true;
        }

        int pmax = 0;
        for (int i = 1; i < rows.size(); i++) {
            if (B[rows.get(i)].size() > B[rows.get(pmax)].size()) {
                pmax = i;
            }
        }
        rows.remove(pmax);

        ArrayList<ArrayList<Integer>> groups = new ArrayList<ArrayList<Integer>>();
        ArrayList<Integer> ones = new ArrayList<Integer>();
        ArrayList<Integer> zeros = new ArrayList<Integer>();
        split(pmax, cols, ones, zeros);
        groups.add(ones);
        groups.add(zeros);

        if (rows.isEmpty()) {
            for (ArrayList<Integer> gcols : groups) {
                for (int gcol : gcols) {
                    ans[++ans[0]] = gcol;
                }
            }
            return true;
        }
        if (ones.isEmpty() || zeros.isEmpty()) {
            return go(rows, cols);
        }

        int p = -1;
        int special = groups.get(groups.size() - 1).size();
        while ((p = find(groups, rows)) != -1) {
            rows.remove((Integer) p);

            int state = 0;
            boolean maybe = false;
            ArrayList<ArrayList<Integer>> ngroups = new ArrayList<ArrayList<Integer>>();
            for (int i = 0; i < groups.size(); i++) {
                ArrayList<Integer> group = groups.get(i);
                ones = new ArrayList<Integer>();
                zeros = new ArrayList<Integer>();
                split(p, group, ones, zeros);

                if (state == 0) {
                    if (!zeros.isEmpty()) ngroups.add(zeros);
                    if (!ones.isEmpty()) {
                        ngroups.add(ones);
                        state = 1;
                    }
                }
                else if (state == 1) {
                    if (!ones.isEmpty()) ngroups.add(ones);
                    if (!zeros.isEmpty()) {
                        ngroups.add(zeros);
                        state = 2;
                    }
                }
                else if (state == 2) {
                    if (!zeros.isEmpty()) ngroups.add(zeros);
                    if (!ones.isEmpty()) {
                        if (i + 1 < groups.size() || special == 0) {
                            return false;
                        }
                        else {
                            maybe = true;
                        }
                    }
                }
                if (i == groups.size() - 1) {
                    special -= ones.size();
                }
            }

            if (maybe) {
                ngroups = new ArrayList<ArrayList<Integer>>();
                state = 0;
                for (int i = 0; i < groups.size(); i++) {
                    ArrayList<Integer> group = groups.get(i);
                    ones = new ArrayList<Integer>();
                    zeros = new ArrayList<Integer>();
                    split(p, group, ones, zeros);

                    if (i == groups.size() - 1) {
                        if (!ones.isEmpty()) ngroups.add(0, ones);
                        if (!zeros.isEmpty()) ngroups.add(zeros);
                        continue;
                    }
                    if (!ones.isEmpty()) {
                        if (state == 1) return false;
                        ngroups.add(ones);
                    }
                    if (!zeros.isEmpty()) {
                        if (state == 0) state = 1;
                        ngroups.add(zeros);
                    }
                }
            }

            groups = ngroups;
        }

        ArrayList<Integer>[] groupRows = new ArrayList[groups.size()];
        for (int i = 0; i < groups.size(); i++) {
            groupRows[i] = new ArrayList<Integer>();
        }
        for (int r : rows) {
            int f = B[r].get(0);
            int g = inGroup[f];
            groupRows[g].add(r);
        }
        for (int i = 0; i < groups.size(); i++) {
            ArrayList<Integer> group = groups.get(i);
            if (!go(groupRows[i], group)) {
                return false;
            }
        }
        return true;
    }

    private int find(ArrayList<ArrayList<Integer>> groups, ArrayList<Integer> rows) {
        for (int i = 0; i < groups.size(); i++) {
            ArrayList<Integer> group = groups.get(i);
            for (int col : group) {
                inGroup[col] = i;
            }
        }
        for (int r : rows) {
            for (int j = 1; j < B[r].size(); j++) {
                if (inGroup[ B[r].get(j - 1) ] != inGroup[ B[r].get(j) ]) {
                    return r;
                }
            }
        }
        return -1;
    }

    private void split(int row, ArrayList<Integer> cols, ArrayList<Integer> ones, ArrayList<Integer> zeros) {
        for (int col : cols) {
            if (A[row][col] == '1') {
                ones.add(col);
            }
            else {
                zeros.add(col);
            }
        }
    }
}

class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int nextInt() {
        return Integer.parseInt(nextString());
    }

    public String nextString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));

        return res.toString();
    }

    private boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

}


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;

public class magic2 {
	public static void main(String[] args) throws Exception{
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		if(N<2000)out.println("1");
		else if(N<=3000)out.println("2");
		else out.println("3");
		out.close();
	}

	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(InputStream in) throws Exception{
			br = new BufferedReader(new InputStreamReader(in));
			st = new StringTokenizer(br.readLine().trim());
		}
		public int numTokens() throws Exception {
			if(!st.hasMoreTokens()){
				st = new StringTokenizer(br.readLine().trim());
				return numTokens();
			}
			return st.countTokens();
		}
		public boolean hasNext() throws Exception{
			if(!st.hasMoreTokens()){
				st = new StringTokenizer(br.readLine().trim());
				return hasNext();
			}
			return true;
		}
		public String next() throws Exception {
			if(!st.hasMoreTokens()){
				st = new StringTokenizer(br.readLine().trim());
				return next();
			}
			return st.nextToken();
		}
		public double nextDouble() throws Exception{
			return Double.parseDouble(next());
		}
		public float nextFloat() throws Exception{
			return Float.parseFloat(next());
		}
		public long nextLong() throws Exception{
			return Long.parseLong(next());
		}
		public int nextInt() throws Exception{
			return Integer.parseInt(next());
		}
		public String nextLine() throws Exception{
			return br.readLine();
		}
	}

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collection;
import java.io.IOException;
import java.util.Deque;
import java.util.ArrayList;
import java.io.UncheckedIOException;
import java.util.List;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.ArrayDeque;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            FWrapAround solver = new FWrapAround();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class FWrapAround {
        ACAutomaton.Node end;
        ACAutomaton.Node begin;
        int n;
        char[] s;
        ACAutomaton.Node[] nodes;
        ACAutomaton at;

        public void solve(int testNumber, FastInput in, FastOutput out) {
            n = in.readInt();
            s = in.readString().toCharArray();
            at = new ACAutomaton('0', '1');
            at.beginBuilding();
            for (char c : s) {
                at.build(c);
            }
            at.endBuilding();
            end = at.getBuildLast();
            nodes = at.getAllNodes().toArray(new ACAutomaton.Node[0]);
            begin = nodes[0];

            long ans = 0;
            for (int i = 0; i < n; i++) {
                ans += way(i);
            }

            out.println(ans);
        }

        public long pow(long x, long n) {
            if (n == 0) {
                return 1;
            }
            long ans = pow(x, n / 2);
            ans *= ans;
            if (n % 2 == 1) {
                ans *= x;
            }
            return ans;
        }

        public long way(int offset) {
            char[] data = new char[1 + 2 * n];
            for (int i = 0; i < s.length; i++) {
                data[1 + i + offset] = s[i];
                data[1 + (i + offset) % n] = s[i];
            }
            int dpLen = offset + s.length;
            long[][] dp = new long[dpLen + 1][nodes.length];
            dp[0][begin.getId()] = 1;
            for (int i = 0; i < dpLen; i++) {
                for (int j = 0; j < nodes.length; j++) {
                    if (dp[i][j] == 0 || j == end.getId()) {
                        continue;
                    }
                    if (data[i + 1] == 0) {
                        dp[i + 1][nodes[j].next[0].getId()] += dp[i][j];
                        dp[i + 1][nodes[j].next[1].getId()] += dp[i][j];
                    } else {
                        dp[i + 1][nodes[j].next[data[i + 1] - '0'].getId()] += dp[i][j];
                    }
                }
            }
            long ans = dp[dpLen][end.getId()];
            if (offset + s.length < n) {
                ans *= pow(2, n - offset - s.length);
            }
            return ans;
        }

    }

    static class FastOutput implements AutoCloseable, Closeable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput println(long c) {
            cache.append(c);
            println();
            return this;
        }

        public FastOutput println() {
            cache.append(System.lineSeparator());
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class FastInput {
        private final InputStream is;
        private StringBuilder defaultStringBuf = new StringBuilder(1 << 13);
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

        public String readString(StringBuilder builder) {
            skipBlank();

            while (next > 32) {
                builder.append((char) next);
                next = read();
            }

            return builder.toString();
        }

        public String readString() {
            defaultStringBuf.setLength(0);
            return readString(defaultStringBuf);
        }

    }

    static class ACAutomaton {
        private final int MIN_CHARACTER;
        private final int MAX_CHARACTER;
        private final int RANGE;
        private ACAutomaton.Node root;
        private ACAutomaton.Node buildLast;
        private List<ACAutomaton.Node> allNodes = new ArrayList();

        public ACAutomaton.Node getBuildLast() {
            return buildLast;
        }

        public List<ACAutomaton.Node> getAllNodes() {
            return allNodes;
        }

        private ACAutomaton.Node addNode() {
            ACAutomaton.Node node = new ACAutomaton.Node(RANGE);
            node.id = allNodes.size();
            allNodes.add(node);
            return node;
        }

        public ACAutomaton(int minCharacter, int maxCharacter) {
            MIN_CHARACTER = minCharacter;
            MAX_CHARACTER = maxCharacter;
            RANGE = maxCharacter - minCharacter + 1;
            root = addNode();
        }

        public void beginBuilding() {
            buildLast = root;
        }

        public void endBuilding() {
            Deque<ACAutomaton.Node> deque = new ArrayDeque(allNodes.size());
            for (int i = 0; i < RANGE; i++) {
                if (root.next[i] != null) {
                    deque.addLast(root.next[i]);
                }
            }

            while (!deque.isEmpty()) {
                ACAutomaton.Node head = deque.removeFirst();
                ACAutomaton.Node fail = visit(head.father.fail, head.index);
                if (fail == null) {
                    head.fail = root;
                } else {
                    head.fail = fail.next[head.index];
                }
                head.preSum = head.cnt + head.fail.preSum;
                for (int i = 0; i < RANGE; i++) {
                    if (head.next[i] != null) {
                        deque.addLast(head.next[i]);
                    }
                }
            }

            for (int i = 0; i < RANGE; i++) {
                if (root.next[i] != null) {
                    deque.addLast(root.next[i]);
                } else {
                    root.next[i] = root;
                }
            }
            while (!deque.isEmpty()) {
                ACAutomaton.Node head = deque.removeFirst();
                for (int i = 0; i < RANGE; i++) {
                    if (head.next[i] != null) {
                        deque.addLast(head.next[i]);
                    } else {
                        head.next[i] = head.fail.next[i];
                    }
                }
            }
        }

        public ACAutomaton.Node visit(ACAutomaton.Node trace, int index) {
            while (trace != null && trace.next[index] == null) {
                trace = trace.fail;
            }
            return trace;
        }

        public void build(char c) {
            int index = c - MIN_CHARACTER;
            if (buildLast.next[index] == null) {
                ACAutomaton.Node node = addNode();
                node.father = buildLast;
                node.index = index;
                buildLast.next[index] = node;
            }
            buildLast = buildLast.next[index];
        }

        public static class Node {
            public ACAutomaton.Node[] next;
            ACAutomaton.Node fail;
            ACAutomaton.Node father;
            int index;
            int id;
            int cnt;
            int preSum;

            public int getId() {
                return id;
            }

            public Node(int range) {
                next = new ACAutomaton.Node[range];
            }

        }

    }
}


import java.io.*;
import java.util.*;

public class cf401e {
  static FastIO in = new FastIO(), out = in;

  static double EPS = 1e-9;
  static int MAX = 100100;
  static long n,m,l,r,p;
  public static void main(String[] args) {
    boolean[] isPrime = new boolean[MAX];
    int[] mu = new int[MAX];
    Arrays.fill(isPrime, true);
    Arrays.fill(mu, 1);
    mu[0] = 0;
    isPrime[0] = isPrime[1] = false;
    for(int i=0; i<MAX; i++)
      if(isPrime[i]) {
        mu[i] = -1;
        for(int j=i+i; j<MAX; j+=i) {
          isPrime[j] = false;
          mu[j] *= -1;
          if(j%(i*1L*i) == 0) mu[j] = 0;
        }
      }

    n = in.nextLong();
    m = in.nextLong();
    l = in.nextLong();
    r = in.nextLong();
    p = in.nextLong();

    long ans = 0;
    for(long d=1; d<=Math.min(n,m); d++)
      for(long x=1; x<=n/d; x++) {
        long tmp = go(d,x,r*r) - go(d,x,l*l - 1);
        tmp = (tmp*mu[(int) d]*((n-d*x+1)%p))%p;
        ans = (ans + tmp)%p;
      }
    if(l == 1) ans = (ans + 2*n*m + n + m)%p;
    out.println((ans+p)%p);
    out.close();
  }
  static long go(long d, long x, long v) {
    if(v < d*x*d*x) return 0;
    long tmp = Math.min(m/d, (long)Math.floor(Math.sqrt(v - d*x*d*x)+EPS)/d);
    long ret = (2*m - d*(tmp+1) + 2)%p;
    return (ret*tmp)%p;
  }

  static class FastIO extends PrintWriter {
    BufferedReader br;
    StringTokenizer st;

    public FastIO() {
      this(System.in, System.out);
    }

    public FastIO(InputStream in, OutputStream out) {
      super(new BufferedWriter(new OutputStreamWriter(out)));
      br = new BufferedReader(new InputStreamReader(in));
      scanLine();
    }

    public void scanLine() {
      try {
        st = new StringTokenizer(br.readLine().trim());
      } catch (Exception e) {
        throw new RuntimeException(e.getMessage());
      }
    }

    public int numTokens() {
      if (!st.hasMoreTokens()) {
        scanLine();
        return numTokens();
      }
      return st.countTokens();
    }

    public String next() {
      if (!st.hasMoreTokens()) {
        scanLine();
        return next();
      }
      return st.nextToken();
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }
  }
}


import java.io.*;
import java.util.*;

public class C {

    static int SIZE = 62; // sub2: 16, sub3: 32, sub4: 62
    static long MOD = 998244353;

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

        int N = Integer.parseInt(in.readLine());
        long[][][] words = new long[11][SIZE][SIZE];
        TreeSet<String> ts = new TreeSet<String>();
        for(int n = 0; n < N; n++) {
            String w = in.readLine();
            if(ts.contains(reverse(w))) continue;
            ts.add(w);
            int a = charToInt(w.charAt(0));
            int b = charToInt(w.charAt(w.length()-1));
            words[w.length()][a][b]++;
            if(!isPal(w)) words[w.length()][b][a]++;
        }

        long sum = 0;

        for(int LEN = 3; LEN <= 10; LEN++) {
            long[][][] dyn = new long[SIZE][SIZE][SIZE];
            for(int a = 0; a < SIZE; a++) {
                for(int b = a; b < SIZE; b++) {
                    for(int c = b; c < SIZE; c++) {
                        for(int x = 0; x < SIZE; x++) {
                            long add = (words[LEN][a][x]*words[LEN][b][x])%MOD;
                            add = (add*words[LEN][c][x])%MOD;
                            dyn[a][b][c] += add;
                            dyn[a][b][c] %= MOD;
                        }
                        dyn[a][c][b] = dyn[a][b][c];
                        dyn[b][a][c] = dyn[a][b][c];
                        dyn[b][c][a] = dyn[a][b][c];
                        dyn[c][a][b] = dyn[a][b][c];
                        dyn[c][b][a] = dyn[a][b][c];
                    }}}
            for(int a = 0; a < SIZE; a++) {
                for(int b = a; b < SIZE; b++) {
                    for(int c = b; c < SIZE; c++) {
                        for(int d = c; d < SIZE; d++) {
                            long add = (dyn[a][b][c]*dyn[b][c][d])%MOD;
                            add *= (dyn[a][c][d]*dyn[a][b][d])%MOD;
                            add %= MOD;
                            //if(add > 0) {
                            //    System.err.print(a+", "+b+", "+c+", "+d+"  ");
                            //    System.err.print(add+" -> ");
                            //}
                            if(a == b && b == c && c == d)
                                add *= 1;
                            else if((a == b && b == c) || // d
                                    (a == b && b == d) || // c
                                    (a == c && c == d) || // b
                                    (b == c && c == d))   // a
                                add *= 4;
                            else if(a == b || b == c || c == d) {
                                if(c == d)
                                    add *= 6;
                                else
                                    add *= 12;
                            }
                            else
                                add *= 24;
                            //if(add > 0)
                            //    System.err.println(add);
                            sum += add;
                            sum %= MOD;
                        }}}}

        }

        System.out.println(sum);

        in.close();
    }

    static int charToInt(char c) {
        if('a' <= c && c <= 'z')
            return c-'a';
        else if('A' <= c && c <= 'Z')
            return (SIZE==62 ? 26 : 16) + c-'A';
        else
            return 2*26+c-'0';
    }

    static boolean isPal(String s) {
        int n = s.length();
        for(int i = 0; i <= n/2; i++)
            if(s.charAt(i) != s.charAt(n-1-i))
                return false;
        return true;
    }

    static String reverse(String s) {
        StringBuilder sb = new StringBuilder();
        for(int i = s.length()-1; i >= 0; i--)
            sb.append(s.charAt(i));
        return sb.toString();
    }
}


import java.io.*;
import java.util.*;

public class Main implements Runnable{
    public static void main(String[] args){
        //new Thread(null,new Main(),"Thread-1",1024*1024*10).start();
        new Main().run();
    }
    int mod=1000000007;
    int n,k,m;
    private void solve() throws Exception {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        n=in.nextInt();k=in.nextInt();m=in.nextInt();
        int[][]ma=new int[(k+1)*(1<<m)][(k+1)*(1<<m)];
        for(int i=0;i<=k;i++) {
            for (int j = 0; j < (1 << m); j++) {
                ma[trans(i,j>>1)][trans(i,j)]=1;
                if(i<k)ma[trans(i+1,j>>1|(1<<m-1))][trans(i,j)]=Integer.bitCount(j)+1;
            }
        }
        ma=FastPowMod(ma,n);
        long ans=0;
        for(int i=trans(k,0);i<ma.length;i++)ans+=ma[i][0];
        out.println(ans%mod);
        out.flush();
    }
    public int[][] FastPowMod(int[][] a,int b){
        int[][] ans=new int[a.length][a.length];
        for(int i=0;i<a.length;i++)ans[i][i]=1;
        while(b>0){
            if((b&1)==1)
                ans=modMul(ans,a);
            a=modMul(a,a);
            b>>=1;
        }
        return ans;
    }
    public int[][] modMul(int[][]a,int[][]b){
        int row=a.length,column=b[0].length;
        int len=b.length;
        int[][] ans=new int[row][column];
        for(int i=0;i<row;i++){
            for(int j=0;j<len;j++){
                if(a[i][j]==0)continue;//稀疏矩阵优化
                for(int k=0;k<column;k++){
                    ans[i][k]+=(long)a[i][j]*b[j][k]%mod;
                    ans[i][k]%=mod;
                }
            }
        }
        return ans;
    }

    int trans(int x,int y){
        return x*(1<<m)+y;
    }
    @Override
    public void run() {
        try {
            solve();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    void shuffle(int[]a,int l,int r){
        Random rnd=new Random();
        for (int i=r; i>l+1; i--) {
            int j=rnd.nextInt(i),tmp=a[j];
            a[j]=a[i-1];
            a[i-1]=tmp;
        }
    }
    void shuffle(Object[]a,int l,int r){
        Random rnd=new Random();
        for (int i=r; i>l+1; i--) {
            int j=rnd.nextInt(i);
            Object tmp=a[j];
            a[j]=a[i-1];
            a[i-1]=tmp;
        }
    }
    void shuffle(long[]a,int l,int r){
        Random rnd=new Random();
        for (int i=r; i>l+1; i--) {
            int j=rnd.nextInt(i);
            long tmp=a[j];
            a[j]=a[i-1];
            a[i-1]=tmp;
        }
    }
    class InputReader{
        StreamTokenizer tokenizer;
        public InputReader(InputStream stream){
            tokenizer=new StreamTokenizer(new BufferedReader(new InputStreamReader(stream)));
            tokenizer.ordinaryChars(33,126);
            tokenizer.wordChars(33,126);
        }
        public String next() throws IOException {
            tokenizer.nextToken();
            return tokenizer.sval;
        }
        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }
        public boolean hasNext() throws IOException {
            int res=tokenizer.nextToken();
            tokenizer.pushBack();
            return res!=tokenizer.TT_EOF;
        }
    }
}


// package c1626;

import java.io.File;
import java.lang.invoke.MethodHandles;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
import java.util.TreeSet;

//
// Educational Codeforces Round 121 (Rated for Div. 2) 2022-01-16 06:35
// F. A Random Code Problem
// https://codeforces.com/contest/1626/problem/F
// time limit per test 3 seconds; memory limit per test 512 megabytes
// public class Pseudo for 'Source should satisfy regex [^{}]*public\s+(final)?\s*class\s+(\w+).*'
//
// You are given an integer array a_0, a_1, ..., a_{n - 1}, and an integer k. You perform the
// following code with it:

//
// Your task is to calculate the expected value of the variable ans after performing this code.
//
// Note that the input is generated according to special rules (see the input format section).
//
// Input
//
// The only line contains six integers n, a_0, x, y, k and M (1 <= n <= 10^7; 1 <= a_0, x, y < M <=
// 998244353; 1 <= k <= 17).
//
// The array a in the input is constructed as follows:
//  * a_0 is given in the input;
//  * for every i from 1 to n - 1, the value of a_i can be calculated as a_i = (a_{i - 1} * x + y)
//    mod M.
//
// Output
//
// Let the expected value of the variable ans after performing the code be E. It can be shown that E
// * n^k is an integer. You have to output this integer modulo 998244353.
//
// Example
/*
input:
3 10 3 5 13 88

output:
382842030

input:
2 15363 270880 34698 17 2357023

output:
319392398
*/
// Note
//
// The array in the first example test is [10, 35, 22]. In the second example, it is [15363,
// 1418543].
//
public class C1626F {
  static final int MOD = 998244353;
  static final Random RAND = new Random();

  static int solve(int[] a, int k) {
    int n = a.length;
    // We are asked to compute the sum of ans across all n^k cases ---
    // make k idx selections each time from [0,n).
    // i = 1: Total n^1 cases at the level with each a[idx] added into ans n^0 times,
    //        contribute to n^(k-1) final cases. Then a[idx] remains the same.
    // i = 2: Total n^2 cases at the level with each a[idx] added into ans n^1 times
    //        contribute to n^(k-2) final cases. Then a[idx] is trimmed to be even.
    // i = 3: Total n^3 cases at the level with each a[idx] added into ans n^2 times,
    //        contribute to n^(k-3) final cases. Then a[idx] is trimmed to be multiple of 3.
    // ...
    // i = k: Total n^k cases at the level with each a[idx] added into ans n^0 times,
    //        contribute to n^0 final cases. Then a[idx] is trimmed to be multiple of k.

    // Compute pows[i] = (n^i % MOD)
    long[] pows = new long[k+1];
    pows[0] = 1;
    for (int i = 1; i <= k; i++) {
      pows[i] = (pows[i-1] * n) % MOD;
    }

    //
    // To be efficient, here we use array instead of Map<Long, Long>.
    // For k = 17, the largest value range observed is 110, like for 59980733.
    final int[] mrs = {0, 1, 2, 4, 6, 10, 12, 18, 24, 30, 38, 48, 54, 66, 78, 84, 94, 110};
    final int maxRange = mrs[k] + 1;
    long[] curr = new long[maxRange];
    long[] next = new long[maxRange];

    long ans = 0;
    for (long v : a) {
      Arrays.fill(curr, 0L);
      curr[0] = 1L;
      for (int i = 1; i <= k; i++) {
        // For each incidence of cv, it is chosen once and not chosen n - 1 times.
        // Once chosen it contribute to ans n^(k-i) times.
        Arrays.fill(next, 0L);
        for (int d = 0; d < maxRange; d++) {
          if (curr[d] == 0) {
            continue;
          }
          // current value and count
          long cv = v - d;
          long count = curr[d] % MOD;

          // chosen once:
          ans = (ans + ((cv * count) % MOD) * pows[k-i]) % MOD;
          long nv = cv - cv % i;
          if (nv != 0) {
            myAssert(v - nv < maxRange);
            next[(int) (v-nv)] += count;
          }

          // not chose (n-1) times:
          long nc = (count * (n-1)) % MOD;
          if (nc != 0) {
            next[d] += nc;
          }
        }
        long[] tmp = curr;
        curr = next;
        next = tmp;
      }
    }
    return (int) ans;
  }

  public static int modInverse(long a, int p) {
    return power(a, p - 2, p);
  }

  // To compute x^y modulo m
  public static int power(long x, long y, int p) {
    x %= p;
    if (y == 0) {
      return 1;
    }
    long w = power(x, y / 2, p);
    w = (w * w) % p;
    return (int) (y % 2 == 0 ? w : (w * x) % p);
  }

  static int solveNaive(int[] a, int k) {
    // System.out.format("%s %d\n", Arrays.toString(a), k);
    // Note that the problem asks (E * n^k) % MOD, not E itself
    int n = a.length;
    int[] pows = new int[k+1];
    pows[0] = 1;
    for (int i = 1; i <= k; i++) {
      pows[i] = (pows[i-1] * n) % MOD;
    }
    return solveNaive(a, k, 1, pows);
  }

  static int index = 0;
  static int solveNaive(int[] a, int k, int i, int[] pows) {
    if (i > k) {
      return 0;
    }
    long sum = 0;
    for (int v : a) {
      sum += v;
    }
    // System.out.format("  %7d i:%2d %s\n", ++index, i, Arrays.toString(a));
    int n = a.length;
    // Each number at this level contribute to pows[k - i] overall cases
    long ans = ((sum % MOD) * pows[k - i]) % MOD;

    // Each idx in [0,n-1] has equal probability to be chosen
    for (int idx = 0; idx < n; idx++) {
      int[] b = new int[n];
      System.arraycopy(a, 0, b, 0, n);
      b[idx] -= b[idx] % i;
      ans = (ans + solveNaive(b, k, i + 1, pows)) % MOD;
    }

    return (int) (ans % MOD);
  }

  static void doTest() {
    long t0 = System.currentTimeMillis();
    // show maxRange of around 110
    if ("show".isEmpty()) {
      int[] maxes = new int[18];
      for (int k = 1; k <= 17; k++) {
        int max = 0;
        for (int t = 0; t < 1000000; t++) {
          int v = 1 + RAND.nextInt(MOD);
          TreeSet<Integer> curr = new TreeSet<>();
          curr.add(v);
          for (int i = 1; i <= k; i++) {
            TreeSet<Integer> next = new TreeSet<>();
            for (int w : curr) {
              next.add(w);
              next.add(w - w % i);
            }
            curr = next;
          }
          int len = v - curr.first() + 1;
          if (len > max) {
            // System.out.format("  %9d -> %3d %s\n", v, len, Utils.traceCollInt(curr));
            max = Math.max(max, len);
          }
        }
        maxes[k] = max;
        System.out.format("  k:%2d max:%d\n", k, max);
      }
      System.out.format("maxes: %s\n", Arrays.toString(maxes));
      System.exit(0);
    }
    {
      // 10000000 235 125 236 2 2356723
      int n = 10000000;
      int[] a = new int[n];
      a[0] = 235;
      int x = 125;
      int y = 236;
      int k = 2;
      int M = 2356723;
      for (int i = 1; i < n; i++) {
        a[i] = (int) (((long)a[i - 1] * x + y) % M);
      }
      System.out.format("%d msec\n", System.currentTimeMillis() - t0);
      int ans = solve(a, k);
      System.out.println(ans);
      System.out.format("%d msec\n", System.currentTimeMillis() - t0);
      System.exit(0);
    }

    int[] a = {10, 35, 22};
    // int[] a = {432859723, 9873427};
    for (int k = 1; k <= 17; k++) {
      int ans = solve(a, k);
      int n = a.length;
      if (n < 4 || (n < 10 && k < 6)) {
        int exp = solveNaive(a, k);
        System.out.format("a:%s k:%2d -> %9d%s\n",
            Arrays.toString(a), k, ans, exp == ans ? "":" Expected " + exp);
      } else {
        System.out.format("a:%s k:%2d -> %9d\n", Arrays.toString(a), k, ans);
      }
    }
    System.out.println(Arrays.toString(a));
    System.out.format("%d msec\n", System.currentTimeMillis() - t0);
    System.exit(0);
  }

  public static void main(String[] args) {
    // doTest();
    Scanner in = getInputScanner();
    int n = in.nextInt();
    int[] a = new int[n];
    a[0] = in.nextInt();
    int x = in.nextInt();
    int y = in.nextInt();
    int k = in.nextInt();
    int M = in.nextInt();

    for (int i = 1; i < n; i++) {
      a[i] = (int) (((long)a[i - 1] * x + y) % M);
    }
    int ans = solve(a, k);
    System.out.println(ans);
    in.close();
  }

  static Scanner getInputScanner() {
    try {
      final String USERDIR = System.getProperty("user.dir");
      final String CNAME = MethodHandles.lookup().lookupClass().getSimpleName();
      final File fin = new File(USERDIR + "/io/c" + CNAME.substring(1,5) + "/" + CNAME + ".in");
      return fin.exists() ? new Scanner(fin) : new Scanner(System.in);
    } catch (Exception e) {
      return new Scanner(System.in);
    }
  }

  static void output(int[] a) {
    if (a == null) {
      System.out.println("-1");
      return;
    }
    StringBuilder sb = new StringBuilder();
    for (int v : a) {
     sb.append(v);
      sb.append(' ');
      if (sb.length() > 500) {
        System.out.print(sb.toString());
        sb.setLength(0);
      }
    }
    System.out.println(sb.toString());
  }

  static void myAssert(boolean cond) {
    if (!cond) {
      throw new RuntimeException("Unexpected");
    }
  }
}


import java.awt.AWTPermission;
import java.io.*;
import java.util.*;

public class E {

  public static void main(String[] args) throws Exception {
    reader = new MyReader(System.in);
    writer = System.out;
    new E().go();
  }

  static MyReader reader;
  static PrintStream writer;

  void go() {
    int n = reader.readInt();
    int k = reader.readInt();
    circles = new Circle[n];
    for(int i=0;i<n;++i) circles[i] = readCircle();
    long mc = maxCut();
    long res = n + k * (mc + mc + k - 1) / 2;
    System.out.println(res);
  }

  private int maxCut() {
    int res = 1;
    for(int i=0;i<circles.length;i++) res = Math.max(res, maxCut(i));
    return res;
  }

  private static final double EPSILON = 1e-10;

  private int maxCut(int a) {
    Circle A = circles[a];
    ArrayList<Angle> angles = new ArrayList<Angle>();
    int cnt = 1;
    int best = 1;
    for(int b=0;b<circles.length;b++) {
      if(b==a) continue;
      Circle B = circles[b];
      if(B.r < A.r) continue;
      double alpha = Math.atan2(B.y - A.y, B.x - A.x);
      double beta = Math.atan2(B.r - A.r, Math.hypot(B.y-A.y, B.x-A.x)) - EPSILON;
      double gamma = Math.atan2(B.r + A.r, Math.hypot(B.y-A.y, B.x-A.x)) - EPSILON;
      double a1 = modulo(alpha-beta);
      double a2 = modulo(alpha+gamma);
      double b1 = modulo(alpha-gamma+Math.PI);
      double b2 = modulo(alpha+beta+Math.PI);
      if(a1 > a2) ++cnt;
      if(b1>b2) ++cnt;
      angles.add(new Angle(a1, 1));
      angles.add(new Angle(a2, -1));
      angles.add(new Angle(b1, 1));
      angles.add(new Angle(b2, -1));
    }
    Collections.sort(angles);
    for(Angle angle : angles) {
      cnt += angle.d;
      best = Math.max(best, cnt);
    }
    return best;
  }

  private static double modulo(double a) {
    while(a>2*Math.PI) a -= 2*Math.PI;
    while(a<0) a += 2*Math.PI;
    return a;
  }

  private static class Angle implements Comparable<Angle> {
    double a;
    int d;
    Angle(double a, int d) { this.a = a; this.d = d; }
    public int compareTo(Angle o) {
      if(a < o.a) return -1;
      else if(a > o.a) return 1;
      else return 0;
    }
  }

  private Circle readCircle() {
    Circle c = new Circle();
    c.x = reader.readInt();
    c.y = reader.readInt();
    c.r = reader.readInt();
    return c;
  }

  Circle[] circles;

  private static class Circle {
    int x,y,r;
  }

  private static class MyReader {
    private InputStream in;
    private byte[] buf;
    private int bufSize,bufPos;
    private int nextChar;

    public MyReader(InputStream in) {
      this.in = in;
      buf = new byte[16<<10];
      bufSize=0;
      bufPos=0;
      move();
    }

    private void move() {
      if (bufPos==bufSize) {
        try {
          bufSize = in.read(buf);
        } catch(IOException ex) {
          throw new RuntimeException(ex);
        }
        bufPos = 0;
        if (bufSize == -1) {
          nextChar = -1;
          return;
        }
      }
      nextChar = buf[bufPos++];
    }

    public int readInt() {
      skipWhitespace();
      int res = 0;
      while(nextChar >= '0' && nextChar <= '9') {
        res = 10*res + (nextChar-'0');
        move();
      }
      return res;
    }

    public long readLong() {
      skipWhitespace();
      long res = 0;
      while(nextChar >= '0' && nextChar <= '9') {
        res = 10*res + (nextChar-'0');
        move();
      }
      return res;
    }

    public String readString() {
      StringBuilder b = new StringBuilder();
      skipWhitespace();
      while(nextChar >= 33) {
        b.append((char)nextChar);
        move();
      }
      return b.toString();
    }

    public void skipWhitespace() {
      while(nextChar==' ' || nextChar=='\n' || nextChar=='\t' || nextChar=='\r') move();
    }
  }

}


import java.util.*;
import java.io.*;
public class F2 {

	static long mod = 998244353;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();

		String[] s = new String[n];
		for(int i = 0; i < n; i++) {
			s[i] = sc.next();
		}

		HashSet<String> suffs = new HashSet<>();
		for(int i = 0; i < n; i++){
			for(int j = 1; j < s[i].length(); j++){
				suffs.add(s[i].substring(j));
			}
		}
		suffs.add("");
		HashSet<Pair> nodes = new HashSet<>();
		for(String a: suffs){
			for(String b: suffs){
				if(isPref(a, b)) {
					nodes.add(new Pair(a, b));
				}
			}
		}
		int N = nodes.size();
//		System.out.println(N);
		HashMap<Pair, Integer> code = new HashMap<>();
		Pair[] decode = new Pair[N];
		int count = 0;
		for(Pair p: nodes) {
			decode[count] = p;
			code.put(p, count++);
		}
		int[][] aut = new int[N][N];
		Pair p0 = new Pair("","");
		for(String t: s) {
			for(String u: s) {
				if(isPref(t, u)) {
					String a = t.substring(1);
					String b = u.substring(1);
					Pair p = new Pair(a, b);
					aut[code.get(p0)][code.get(p)]++;
				}
				else if(isPref(u, t)) {
					String a = u.substring(1);
					String b = t.substring(1);
					Pair p = new Pair(a, b);
					aut[code.get(p0)][code.get(p)]++;
				}
			}
		}
		for(Pair p: nodes) {
			Pair q = next(p);
			if(p.equals(p0)){
				continue;
			}
			else if(q != null) {
				aut[code.get(p)][code.get(q)]++;
			}
			else {
				for(String t: s) {
					q = next(p, t);
					if(q != null && nodes.contains(q)) {
						aut[code.get(p)][code.get(q)]++;
					}
				}
			}
		}
		Matrix mat = new Matrix(aut);
		Matrix matp = pow(mat, m);
		System.out.println(matp.mat[code.get(p0)][code.get(p0)]);
	}
	static Pair next(Pair p, String s) {
		if(p.a.equals("")) {
			if(isPref(s, p.b)) {
				String a = s.substring(1);
				String b = p.b.substring(1);
				return new Pair(a, b);
			}
			else if(isPref(p.b, s)) {
				String a = p.b.substring(1);
				String b = s.substring(1);
				return new Pair(a, b);
			}
			else return null;
		}
		else return null;
	}
	static Pair next(Pair p) {
		if(p.a.equals("")) return null;
		String a = p.a.substring(1);
		String b = p.b.substring(1);
		return new Pair(a, b);
	}
	static boolean isPref(String a, String b) { //a of b
		if(a.length() > b.length()) return false;
		else return b.substring(0, a.length()).equals(a);
	}
	static class Pair {
		String a, b;
		public Pair(String a, String b) {
			this.a = a; this.b = b;
		}
		@Override
		public int hashCode() {
			return a.hashCode() + b.hashCode();
		}
		@Override
		public boolean equals(Object o) {
			Pair p = (Pair)o;
			return a.equals(p.a) && b.equals(p.b);
		}
		public String toString() {
			return "'"+a+"' '"+b;
		}
	}

	static Matrix pow(Matrix m, int exp) {
		Matrix res = new Matrix(m.n);
		Matrix mapow = m;
		while(exp > 0) {
			if((exp & 1) == 1) {
				res = res.mult(mapow);
			}
			mapow = mapow.mult(mapow);
			exp >>= 1;
		}
		return res;
	}
	static class Matrix{
		int[][] mat; int n;
		public Matrix(int[][] mat) {
			n = mat.length;
			this.mat = mat;
		}
		public Matrix(int n) {
			mat = new int[n][n];
			this.n = n;
			for(int i = 0; i < n; i++) mat[i][i] = 1;
		}
		Matrix mult(Matrix m) {
			int[][] res = new int[n][n];
			for(int k = 0; k < n; k++) {
				for(int i = 0; i < n; i++) {
					for(int j = 0; j < n; j++) {
						long a = mat[i][k];
						long b = m.mat[k][j];
						long c = res[i][j];
						res[i][j] = (int)((c + a*b%mod)%mod);
					}
				}
			}
			return new Matrix(res);
		}
		public String toString(){
			StringBuilder sb = new StringBuilder();
			for(int i = 0; i < n; i++) {
				sb.append(Arrays.toString(mat[i])+"\n");
			}
			return sb.toString();
		}
	}

}


import java.io.*;
import java.util.*;
public class SlimeCombiningLinear {
  private static InputReader in;
  private static PrintWriter out;
  public static double EPS = 1e-15;
  public static int maxp = 50;

  public static void main (String[] args) {
    in = new InputReader(System.in);
    out = new PrintWriter(System.out, true);

    int n = in.nextInt();
    int p = in.nextInt();

    double p2 = p / 1000000000., p4 = 1 - p2;
    double[][] a = new double[maxp][maxp];
    double[][] b = new double[maxp][maxp];
    for (int len = 1; len < maxp; len++) {
      for (int pow = 1; pow < maxp; pow++) {
        if (pow == 1) a[len][pow] += p2;
        if (pow == 2) {
          a[len][pow] += p4;
          b[len][pow] += p4;
        }
        a[len][pow] += a[len-1][pow-1] * a[len][pow-1];
        b[len][pow] += a[len-1][pow-1] * b[len][pow-1];
      }
    }
    for (int len = maxp - 1; len >= 1; len--) {
      for (int pow = 1; pow < maxp; pow++) {
        a[len][pow] *= 1 - a[len-1][pow];
        b[len][pow] *= 1 - a[len-1][pow];
      }
    }

    // value of a slime that has been merged i times
    long[] vals = new long[maxp];
    for (int i = 0; i < maxp; i++) vals[i] = i;//1l << i;
    // manually do first few cases
    int maxn = 1000;
    double[][] dp = new double[maxn][maxp];
    double[][] sum = new double[maxn][maxp];
    for (int cur = 1; cur < maxp; cur++)
      dp[maxn-1][cur] = vals[cur];

    // manual dp
    for (int i = maxn-2; i >= 0; i--) {
      for (int cur = 1; cur < maxp; cur++) {
        for (int next = 1; next < maxp; next++) {
          if (cur == next) continue;
          if (cur == 1) {
            int id = Math.min(maxp-1, maxn-i-1);
            dp[i][cur] += b[id][next] * dp[i+1][next];
            sum[i][cur] += b[id][next];
          } else {
            if (cur < next) continue;
            int id = Math.min(maxp-1, maxn-i-1);
            dp[i][cur] += a[id][next] * dp[i+1][next];
            sum[i][cur] += a[id][next];
          }
        }
      }
      for (int cur = 1; cur < maxp; cur++) {
        dp[i][cur] = vals[cur] + dp[i][cur] / sum[i][cur];
      }
    }
    if (n <= maxn) {
      int k = (int)n;
      int w = Math.min(maxp-1, k);
      double exp = 0;
      for (int i = 1; i < maxp; i++) {
        exp += a[w][i] * dp[maxn-k][i];
      }
      out.printf("%.15f\n", exp);
      out.close();
      System.exit(0);
    }

    double exp1 = 0;
    double exp2 = 0;
    for (int i = 1; i < maxp; i++) {
      exp1 += a[maxp-1][i] * dp[0][i];
      exp2 += a[maxp-1][i] * dp[1][i];
    }
    out.printf("%.15f\n", exp2 + (exp1 - exp2) * (long)(n - maxn + 1));
    out.close();
    System.exit(0);
  }
  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }
  }
}


//package com.company;

import java.io.*;
import java.util.*;

public class Main {
    public static class Task {
        boolean[] on;

        int gcd(int x, int y) {
            return y == 0 ? x: gcd(y, x % y);
        }
        long lcm(int x, int y) {
            int g = gcd(x, y);
            return (long) x * y / g;
        }

        public void solve(Scanner sc, PrintWriter pw) throws IOException {
            int N = 100000;
            on = new boolean[N + 1];
            Arrays.fill(on, true);
            int n = sc.nextInt();
            int[] a  = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = sc.nextInt();
            }
            Arrays.sort(a);
            List<Integer> alive = new ArrayList<>();
            for (int i = n - 1; i >= 0; i--) {
                int x = a[i];
                if (!on[x] || (i < n - 1 && a[i + 1] == x)) continue;
                alive.add(x);
                for (int j = 1; j * j <= x; j++) {
                    if (x % j == 0) {
                        on[j] = on[x / j] = false;
                    }
                }
            }
            Collections.reverse(alive);
            long m = 0;
            if (alive.size() > 2000) {
                Collections.shuffle(alive);
                for (int i = 0; i < 1000; i++) {
                    for (int j = i + 1; j < 2000; j++) {
                        m = Math.max(m, lcm(alive.get(i), alive.get(j)));
                    }
                }
                Collections.sort(alive);
            }
            int commonGcd = 0;
            for (int i = alive.size() - 1; i >= 0; i--) {
                int x = alive.get(i);
                commonGcd = gcd(x, commonGcd);
                m = Math.max(m, x);
                int lo = i + 1, hi = alive.size() - 1;
                while (lo < hi) {
                    int mid = (lo + hi) >> 1;
                    if ((long) x * alive.get(mid) <= (long) m * commonGcd) {
                        lo = mid + 1;
                    } else {
                        hi = mid;
                    }
                }
                for (int j = lo; j < alive.size(); j++) {
                    m = Math.max(m, lcm(x, alive.get(j)));
                }
            }
            pw.println(m);
        }
    }

    static long TIME_START, TIME_END;

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
//        Scanner sc = new Scanner(new FileInputStream("input"));
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
//        PrintWriter pw = new PrintWriter(new FileOutputStream("input"));

        Runtime runtime = Runtime.getRuntime();
        long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
        TIME_START = System.currentTimeMillis();
        Task t = new Task();
        t.solve(sc, pw);
        TIME_END = System.currentTimeMillis();
        long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
        pw.close();
        System.err.println("Memory increased: " + (usedMemoryAfter - usedMemoryBefore) / 1000000);
        System.err.println("Time used: " + (TIME_END - TIME_START) + ".");
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader s) throws FileNotFoundException {
            br = new BufferedReader(s);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {
	static final long MOD = 998244353;
	static int[] primes;
	static int P;
    public static void main(String[] args) throws IOException {
        FastScanner sc=new FastScanner();
        int N = sc.nextInt();
        int K = sc.nextInt();
        primes = new int[78498];
        primes[0] = 2;
        P = 1;
        long t1 = System.currentTimeMillis();
        for (int num = 3; num <= N; num++) {
        	boolean prime = true;
        	for (int i = 0; i < P; i++) {
        		if (num % primes[i] == 0) {
        			prime = false;
        			break;
        		}
        		if (primes[i]*primes[i] > num) {
        			break;
        		}
        	}
        	if (prime) {
        		primes[P] = num;
        		P++;
        	}
        }
        long t2 = System.currentTimeMillis();
        int[][] totients = new int[N+1][2];
        HashMap<Integer,Integer> getT = new HashMap<Integer,Integer>();
        getT.put(1,1);
        getT.put(2,1);
        for (int i = 0; i <= N; i++) {
        	if (i < 3) {
        		totients[i][0] = Integer.MAX_VALUE;
        		continue;
        	}
        	totients[i][0] = totient(i);
        	totients[i][1] = i;
        	getT.put(i,totients[i][0]);
        }
        long t3 = System.currentTimeMillis();
        Arrays.sort(totients, new Comparator<int[]>() {
        	  @Override
        	  public int compare(int[] arr1, int[] arr2) {
        	    return arr1[0]-arr2[0];
        	    //Ascending order.
        	  }
        });
        long t4 = System.currentTimeMillis();
        HashSet<Integer> divisors = new HashSet<Integer>();
        long iterations = 0;
        for (int i = 0; i < K; i++) {
        	for (int factor = 1; factor * factor <= N; factor++) {
        		iterations++;
        		if (totients[i][1] % factor == 0) {
        			divisors.add(factor);
        			divisors.add(totients[i][1]/factor);
        		}
        	}
        }
        System.out.println("Iterations:" + iterations);
        long t5 = System.currentTimeMillis();
        long ans = 0;
        for (int div: divisors) {
        	ans += getT.get(div);
        }
        System.out.println(ans);
        long t6 = System.currentTimeMillis();
        System.out.println(t2-t1);
        System.out.println(t3-t2);
        System.out.println(t4-t3);
        System.out.println(t5-t4);
        System.out.println(t6-t5);
    }

    public static int totient(int n) {
    	//From Geeks4Geeks
        int result = n;
        for (int p: primes) {
        	if (p == 0 || p * p > n) {
        		break;
        	}
            if (n % p == 0) {
                while (n % p == 0)
                    n /= p;
                result -= result / p;
            }
        }
        if (n > 1)
            result -= result / n;
        return result;
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}

class Node {
	public int n;
	public HashSet<Node> children;

	public Node(int n) {
		this.n = n;
		children = new HashSet<Node>();
	}

	public void addChild(Node node) {
		children.add(node);
	}

	public void removeChild(Node node) {
		children.remove(node);
	}
}

class BinaryIndexedTree {
	  public long[] arr;

	  public BinaryIndexedTree (int N) {
	    arr = new long[N+1];
	    arr[0] = 0;
	  }

	  //add k to the i-th element.
	  public void add(long k, int i) {
	    int node = i+1;
	    while (node < arr.length) {
	      arr[node] += k;
	      node += node & (-node);
	    }
	  }

	  //sum up the elements from input[s_i] to input[e_i], from [s_i,e_i).
	  public long sum(int s_i, int e_i) {
	    return sum(e_i) - sum(s_i);
	  }

	  public long sum(int i) {
	    long total = 0;
	    int node = i;
	    while (node > 0) {
	      total += arr[node];
	      node -= node & (-node);
	    }
	    return total;
	  }
}


import java.io.*;
import java.util.*;
import java.math.*;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	final static int PERIOD = 60;
	final static int POWER = 13;

	long fib(long n, long mod) {
		long[][] mat = new long[2][2];
		mat[0][1] = mat[1][0] = mat[1][1] = 1;
		Matrix v = new Matrix(mat);
		v = v.power(n, mod);
		return v.mat[0][1];
	}

	void run() {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);

		long num = in.nextInt(), mod = 10, per = PERIOD;
		ArrayList<Long> valid = new ArrayList<Long>();
		for (int i = 0; i < PERIOD; ++i)
			if (fib(i, mod) == num % mod)
				valid.add((long)i);

		for (int i = 1; i < POWER; ++i) {
			mod *= 10;
			long rem = num % mod;
			ArrayList<Long> nv = new ArrayList<Long>();
			for (int j = 0; j < 10; ++j)
				for (int k = 0; k < valid.size(); ++k) {
					if (fib(j * per + valid.get(k), mod) == rem)
						nv.add(j * per + valid.get(k));
				}
			valid = nv;
			per *= 10;
		}

		if (valid.size() == 0)
			out.println(-1);
		else
			out.println(valid.get(0));
		out.close();
	}
}

class Matrix {
	long[][] mat;
	final static Matrix ONE = new Matrix(new long[][] {{1, 0}, {0, 1}});
	Matrix(long[][] mat) {
		this.mat = mat;
	}
	long add(long a, long b, long mod) {
		if (a + b >= mod)
			return a + b - mod;
		return a + b;
	}
	long multiply(long a, long b, long mod) {
		long ret = 0;
		while (a > 0) {
			if ((a & 1) == 1)
				ret = add(ret, b, mod);
			b = add(b, b, mod);
			a >>= 1;
		}
		return ret;
	}
	Matrix multiply(Matrix o, long mod) {
		long[][] ret = new long[2][2];
		for (int i = 0; i < 2; ++i)
			for (int j = 0; j < 2; ++j)
				for (int k = 0; k < 2; ++k)
					ret[i][j] = add(ret[i][j], multiply(mat[i][k], o.mat[k][j], mod), mod);
		return new Matrix(ret);
	}
	Matrix power(long p, long mod) {
		if (p == 0) {
			return Matrix.ONE;
		}
		Matrix ret = power(p / 2, mod);
		ret = ret.multiply(ret, mod);
		if ((p & 1) == 1)
			ret = ret.multiply(this, mod);
		return ret;
	}
}

class InputReader {
	BufferedReader buff;
	StringTokenizer tokenizer;

	InputReader(InputStream stream) {
		buff = new BufferedReader(new InputStreamReader(stream));
		tokenizer = null;
	}
	boolean hasNext() {
		while (tokenizer == null || !tokenizer.hasMoreTokens())
			try {
				tokenizer = new StringTokenizer(buff.readLine());
			}
			catch (Exception e) {
				return false;
			}
		return true;
	}
	String next() {
		if (!hasNext())
			throw new RuntimeException();
		return tokenizer.nextToken();
	}
	int nextInt() { return Integer.parseInt(next()); }
	long nextLong() { return Long.parseLong(next()); }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            DSingerHouse solver = new DSingerHouse();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class DSingerHouse {
        Debug debug = new Debug(true);

        public void solve(int testNumber, FastInput in, FastOutput out) {
            int n = in.readInt();
            int m = n + 2;
            int[][] dp = new int[n + 1][m + 1];

            Modular mod = new Modular(1e9 + 7);
            Combination comb = new Combination(10000, mod);

            dp[0][0] = 1;
            for (int i = 1; i <= n; i++) {
                for (int j = 0; j <= m; j++) {
                    if (dp[i - 1][j] == 0) {
                        continue;
                    }
                    for (int k = 0; k <= m; k++) {
                        if (dp[i - 1][k] == 0) {
                            continue;
                        }
                        int way = mod.mul(dp[i - 1][j], dp[i - 1][k]);
                        if (j + k <= m) {
                            //not appear
                            int next = j + k;
                            dp[i][next] = mod.plus(dp[i][next], way);
                        }
                        if (j + k - 1 <= m && j + k - 1 >= 0) {
                            //appear, and concatenate
                            int next = j + k - 1;
                            int local = mod.mul(way, (j + k) * (j + k - 1));
                            dp[i][next] = mod.plus(dp[i][next], local);
                        }
//                    if (j + k - 1 <= m && j >= 1) {
//                        //appear, and concatenate left side
//                        int next = j - 1 + k;
//                        int local = mod.mul(way, j);
//                        local = mod.mul(local, j);
//                        dp[i][next] = mod.plus(dp[i][next], local);
//                    }
//                    if (j + k - 1 <= m && k >= 1) {
//                        //appear, and concatenate right side
//                        int next = j - 1 + k;
//                        int local = mod.mul(way, k);
//                        local = mod.mul(local, k);
//                        dp[i][next] = mod.plus(dp[i][next], local);
//                    }
                        if (j + k <= m) {
                            //appear, but only appear on one side
                            int next = j + k;
                            int local = mod.mul(way, 2 * (j + k));
                            dp[i][next] = mod.plus(dp[i][next], local);
                        }
                        if (j + k + 1 <= m) {
                            //appear, with new in/out
                            int next = j + k + 1;
                            dp[i][next] = mod.plus(dp[i][next], way);
                        }
                    }
                }
                dp[i][0] = 1;
            }

            debug.debug("dp", dp);
            int ans = dp[n][1];
            out.println(ans);
        }

    }

    static class Debug {
        private boolean offline;
        private PrintStream out = System.err;
        static int[] empty = new int[0];

        public Debug(boolean enable) {
            offline = enable && System.getSecurityManager() == null;
        }

        public Debug debug(String name, Object x) {
            return debug(name, x, empty);
        }

        public Debug debug(String name, Object x, int... indexes) {
            if (offline) {
                if (x == null || !x.getClass().isArray()) {
                    out.append(name);
                    for (int i : indexes) {
                        out.printf("[%d]", i);
                    }
                    out.append("=").append("" + x);
                    out.println();
                } else {
                    indexes = Arrays.copyOf(indexes, indexes.length + 1);
                    if (x instanceof byte[]) {
                        byte[] arr = (byte[]) x;
                        for (int i = 0; i < arr.length; i++) {
                            indexes[indexes.length - 1] = i;
                            debug(name, arr[i], indexes);
                        }
                    } else if (x instanceof short[]) {
                        short[] arr = (short[]) x;
                        for (int i = 0; i < arr.length; i++) {
                            indexes[indexes.length - 1] = i;
                            debug(name, arr[i], indexes);
                        }
                    } else if (x instanceof boolean[]) {
                        boolean[] arr = (boolean[]) x;
                        for (int i = 0; i < arr.length; i++) {
                            indexes[indexes.length - 1] = i;
                            debug(name, arr[i], indexes);
                        }
                    } else if (x instanceof char[]) {
                        char[] arr = (char[]) x;
                        for (int i = 0; i < arr.length; i++) {
                            indexes[indexes.length - 1] = i;
                            debug(name, arr[i], indexes);
                        }
                    } else if (x instanceof int[]) {
                        int[] arr = (int[]) x;
                        for (int i = 0; i < arr.length; i++) {
                            indexes[indexes.length - 1] = i;
                            debug(name, arr[i], indexes);
                        }
                    } else if (x instanceof float[]) {
                        float[] arr = (float[]) x;
                        for (int i = 0; i < arr.length; i++) {
                            indexes[indexes.length - 1] = i;
                            debug(name, arr[i], indexes);
                        }
                    } else if (x instanceof double[]) {
                        double[] arr = (double[]) x;
                        for (int i = 0; i < arr.length; i++) {
                            indexes[indexes.length - 1] = i;
                            debug(name, arr[i], indexes);
                        }
                    } else if (x instanceof long[]) {
                        long[] arr = (long[]) x;
                        for (int i = 0; i < arr.length; i++) {
                            indexes[indexes.length - 1] = i;
                            debug(name, arr[i], indexes);
                        }
                    } else {
                        Object[] arr = (Object[]) x;
                        for (int i = 0; i < arr.length; i++) {
                            indexes[indexes.length - 1] = i;
                            debug(name, arr[i], indexes);
                        }
                    }
                }
            }
            return this;
        }

    }

    static interface IntCombination {
    }

    static class Modular {
        int m;

        public int getMod() {
            return m;
        }

        public Modular(int m) {
            this.m = m;
        }

        public Modular(long m) {
            this.m = (int) m;
            if (this.m != m) {
                throw new IllegalArgumentException();
            }
        }

        public Modular(double m) {
            this.m = (int) m;
            if (this.m != m) {
                throw new IllegalArgumentException();
            }
        }

        public int valueOf(int x) {
            x %= m;
            if (x < 0) {
                x += m;
            }
            return x;
        }

        public int valueOf(long x) {
            x %= m;
            if (x < 0) {
                x += m;
            }
            return (int) x;
        }

        public int mul(int x, int y) {
            return valueOf((long) x * y);
        }

        public int plus(int x, int y) {
            return valueOf(x + y);
        }

        public String toString() {
            return "mod " + m;
        }

    }

    static class Factorial {
        int[] fact;
        int[] inv;
        Modular modular;

        public Modular getModular() {
            return modular;
        }

        public Factorial(int[] fact, int[] inv, InverseNumber in, int limit, Modular modular) {
            this.modular = modular;
            this.fact = fact;
            this.inv = inv;
            fact[0] = inv[0] = 1;
            for (int i = 1; i <= limit; i++) {
                fact[i] = modular.mul(fact[i - 1], i);
                inv[i] = modular.mul(inv[i - 1], in.inv[i]);
            }
        }

        public Factorial(int limit, Modular modular) {
            this(new int[limit + 1], new int[limit + 1], new InverseNumber(limit, modular), limit, modular);
        }

    }

    static class Combination implements IntCombination {
        final Factorial factorial;
        final Modular modular;

        public Combination(Factorial factorial) {
            this.factorial = factorial;
            this.modular = factorial.getModular();
        }

        public Combination(int limit, Modular modular) {
            this(new Factorial(limit, modular));
        }

    }

    static class InverseNumber {
        int[] inv;

        public InverseNumber(int[] inv, int limit, Modular modular) {
            this.inv = inv;
            inv[1] = 1;
            int p = modular.getMod();
            for (int i = 2; i <= limit; i++) {
                int k = p / i;
                int r = p % i;
                inv[i] = modular.mul(-k, inv[r]);
            }
        }

        public InverseNumber(int limit, Modular modular) {
            this(new int[limit + 1], limit, modular);
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            return this;
        }

        public FastOutput append(int c) {
            cache.append(c);
            return this;
        }

        public FastOutput println(int c) {
            return append(c).println();
        }

        public FastOutput println() {
            cache.append(System.lineSeparator());
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }
}


// submission outside of the contest found in editorial:
// http://codeforces.com/blog/entry/51685

// this is the only code I've found that passes all test cases

// http://codeforces.com/contest/793/submission/26669894
// ext .cpp to increase idea compilation time

import static java.lang.Double.parseDouble;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.exit;
import static java.util.Arrays.fill;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class GFast {

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	static int n, len;
	static long edges[][];
	static int matchingL[], matchingR[];
	static int hkQueue[];
	static long hkSet[], hkSet2[][];

	static final int BIT_INDEX[] = {
		0, 1, 2, 7, 3, 13, 8, 19, 4, 25, 14, 28, 9, 34, 20, 40,
		5, 17, 26, 38, 15, 46, 29, 48, 10, 31, 35, 54, 21, 50, 41, 57,
		63, 6, 12, 18, 24, 27, 33, 39, 16, 37, 45, 47, 30, 53, 49, 56,
		62, 11, 23, 32, 36, 44, 52, 55, 61, 22, 43, 51, 60, 42, 59, 58};

	static int bitIndex(long x) {
		return BIT_INDEX[(int) ((x * 0x218a392cd3d5dbfL) >>> 58)];
	}

	static int hopcroftKarp() {
		fill(matchingL, -1);
		fill(matchingR, -1);
		int size = 0;
		while (true) {
			fill(hkSet, -1L);
			int queueHead = 0, queueTail = 0;
			for (int i = 0; i < n; i++) {
				if (matchingL[i] < 0) {
					hkQueue[queueTail++] = i;
					hkQueue[queueTail++] = 0;
				}
			}
			int resDist = -1;
			while (queueHead < queueTail) {
				int cur = hkQueue[queueHead++];
				int cdist = hkQueue[queueHead++];
				if ((cdist + Integer.MIN_VALUE) > (resDist + Integer.MIN_VALUE)) {
					break;
				}
				long ecur[] = edges[cur], curSet2[] = hkSet2[cdist];
				for (int nextBlock = 0; nextBlock < len; nextBlock++) {
					long v = hkSet[nextBlock], w = ecur[nextBlock] & v;
					if (w == 0) {
						continue;
					}
					hkSet[nextBlock] = v ^ w;
					curSet2[nextBlock] |= w;
					do {
						long x = w & -w;
						w ^= x;
						int next = (nextBlock << 6) + bitIndex(x);
						int next2 = matchingR[next];
						if (next2 < 0) {
							resDist = cdist;
						} else {
							hkQueue[queueTail++] = next2;
							hkQueue[queueTail++] = cdist + 1;
						}
					} while (w != 0);
				}
			}
			if (resDist == -1) {
				return size;
			}
			for (int i = 0; i < n; i++) {
				if (matchingL[i] < 0 && hopcroftKarpDfs(i, 0)) {
					++size;
				}
			}
			for (int i = 0; i <= resDist; i++) {
				fill(hkSet2[i], 0);
			}
		}
	}

	static boolean hopcroftKarpDfs(int cur, int cdist) {
		long ecur[] = edges[cur], curSet2[] = hkSet2[cdist];
		for (int nextBlock = 0; nextBlock < len; nextBlock++) {
			long v = curSet2[nextBlock], w = ecur[nextBlock] & v;
			if (w == 0) {
				continue;
			}
			v ^= w;
			do {
				long x = w & -w;
				w ^= x;
				int next = (nextBlock << 6) + bitIndex(x);
				int next2 = matchingR[next];
				if (next2 < 0 || hopcroftKarpDfs(next2, cdist + 1)) {
					matchingR[next] = cur;
					matchingL[cur] = next;
					curSet2[nextBlock] = v ^ w;
					return true;
				}
			} while (w != 0);
			curSet2[nextBlock] = v;
		}
		return false;
	}

	static void solve() throws Exception {
		n = nextInt();
		int q = nextInt();
		len = (n + 63) >> 6;
		edges = new long[n][len];
		matchingL = new int[n];
		matchingR = new int[n];
		hkQueue = new int[2 * n];
		hkSet = new long[len];
		hkSet2 = new long[n][len];
		for (int x = 0; x < n; x++) {
			for (int y = 0; y < n >> 6; y++) {
				edges[x][y] = -1L;
			}
			if ((n & 63) != 0) {
				edges[x][n >> 6] = (1L << n) - 1;
			}
		}
		for (int i = 0; i < q; i++) {
			int x1 = nextInt() - 1;
			int y1 = nextInt() - 1;
			int x2 = nextInt();
			int y2 = nextInt();
			if (y1 >> 6 == y2 >> 6) {
				long mask = ~((1L << y2) - (1L << y1));
				for (int x = x1; x < x2; x++) {
					edges[x][y1 >> 6] &= mask;
				}
			} else {
				for (int x = x1; x < x2; x++) {
					edges[x][y1 >> 6] &= ~(-1L << y1);
					for (int y = (y1 >> 6) + 1; y < y2 >> 6; y++) {
						edges[x][y] = 0;
					}
					if ((y2 & 63) != 0) {
						edges[x][y2 >> 6] &= -1L << y2;
					}
				}
			}
		}
		out.print(hopcroftKarp());
	}

	static int nextInt() throws IOException {
		return parseInt(next());
	}

	static long nextLong() throws IOException {
		return parseLong(next());
	}

	static double nextDouble() throws IOException {
		return parseDouble(next());
	}

	static String next() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new OutputStreamWriter(System.out));
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}


import java.util.Scanner;

public class E {

    static double e = 1e-8, R, phi0;
    static int x,y,r,v,vp;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int xp = sc.nextInt();
        int yp = sc.nextInt();
        vp = sc.nextInt();
        x = sc.nextInt();
        y = sc.nextInt();
        v = sc.nextInt();
        r = sc.nextInt();
        R = Math.sqrt(xp*xp+yp*yp);
        phi0 = Math.acos(xp / R);
        double left = 0, right = 1e9;
        for(;;) {
            double middle = (left+right) / 2;
            if (reache(middle) && !reache(middle-e)) {
                System.out.println(middle);
                return;
            }
            if (reache(middle))
                right = middle-e;
            else
                left = middle+e;
        }
    }

    private static boolean reache(double t) {
        double x2 = R*Math.cos(vp/R*t+phi0);
        double y2 = R*Math.sin(vp/R*t+phi0);
        double x1 = x, y1 = y;
        double a = y1-y2, b = x2-x1, c = x1*y2-x2*y1;
        double d = Math.abs(c)/Math.sqrt(a*a+b*b);
        double reach_time = 0;
        a = dis(x1, y1, 0, 0);
        b = dis(x2, y2, 0, 0);
        c = dis(x1, y1, x2, y2);
        if (d >= r || Math.abs(Math.sqrt(a*a-d*d)+Math.sqrt(b*b-d*d)-c) > e) {
            reach_time = c / v;
        }
        else {
            double alfa = Math.acos((x1*x2+y1*y2) / (a*b))-Math.acos(r/a)-Math.acos(r/b);
            reach_time = (r*alfa+Math.sqrt(a*a-r*r)+Math.sqrt(b*b-r*r)) / v;
        }
        return reach_time <= t;
    }

    private static double dis(double x1, double y1, double x2, double y2) {
        return Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
    }
}


import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.io.PrintStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Random;
import java.io.Writer;
import java.util.Collection;
import java.util.List;
import java.util.BitSet;
import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.util.NoSuchElementException;
import java.util.TreeSet;
import java.math.BigInteger;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author ogiekako
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		MyScanner in = new MyScanner(inputStream);
		MyPrintWriter out = new MyPrintWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskD {
    int MOD = 777777777;
    long[][] C = MathUtils.generateCombination(257, MOD);
    public void solve(int testNumber, MyScanner in, MyPrintWriter out) {
        int n = in.nextInt(), k = in.nextInt();
        long[][] dp = new long[k+1][n-k+1];
        dp[0][0] = 1;
        for(int i=1;i<=n;i++){
            long[][] nxt = new long[k+1][n-k+1];
            for(int lie=0;lie<k+1;lie++)for(int hon=0;hon<n-k+1;hon++)if(dp[lie][hon]>0){
                int rest = n - lie - hon;
                for(int use=0;use<=rest;use++){
                    if(use==i && hon + use < n-k+1){
                        nxt[lie][hon+use] = (nxt[lie][hon+use] + dp[lie][hon] * C[rest][use]) % MOD;
                    }else if(use!=i && lie+use<k+1){
                        nxt[lie+use][hon] = (nxt[lie+use][hon] + dp[lie][hon] * C[rest][use]) % MOD;
                    }
                }
            }
            dp = nxt;
        }
        out.println(dp[k][n-k]);
    }
}

class MathUtils {

    public static long[][] generateCombination(int n, int modulus) {
        long[][] C = new long[n][n];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < i + 1; j++) {
                C[i][j] = j == 0 ? 1 : C[i - 1][j - 1] + C[i - 1][j];
                if (C[i][j] >= modulus) C[i][j] -= modulus;
            }
        return C;
    }

    }

class MyScanner {
    private final InputStream in;

    public MyScanner(InputStream in) {
        this.in = in;
    }

    int bufLen;
    int bufPtr;
    byte[] buf = new byte[1024];

    public int read() {
        if (bufLen == -1)
            throw new InputMismatchException();
        if (bufPtr >= bufLen) {
            bufPtr = 0;
            try {
                bufLen = in.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (bufLen <= 0)
                return -1;
        }
        return buf[bufPtr++];
    }

    public int nextInt() {
        try {
            int c = read();
            if (c == -1) return c;
            while (c != '-' && (c < '0' || '9' < c)) {
                c = read();
                if (c == -1) return c;
            }
            if (c == '-') return -nextInt();
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while ('0' <= c && c <= '9');
            return res;
        } catch (Exception e) {
            return -1;
        }
    }

    }

class MyPrintWriter {
    PrintWriter out;

    public MyPrintWriter(OutputStream outputStream) {
        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public MyPrintWriter(Writer writer) {
        out = new PrintWriter(writer);
    }

    public void println(Object... os) {
        for (int i = 0; i < os.length - 1; i++) {
            out.print(os[i]);
            out.print(' ');
        }
        out.println(os[os.length - 1]);
    }

    public void close() {
        out.close();
    }

    }


import java.util.Scanner;

public class Main {
   static boolean f = false,flag = false;
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String a = "", c = "";

        String s = scan.next();
        char[] sArray = s.toCharArray();
        if (sArray.length < 100) {

                if (sArray.length % 2 != 0) {
                    for (int i = sArray.length / 2 + 1; i < sArray.length; i++) {
                        for (int y = 0; y < i; y++) {
                            c = c + sArray[y];
                            a = sArray[sArray.length - 1 - y] + a;
                        }
                        if (a.equals(c)) {
                            f = true;
                            break;
                        }
                    }
                }
                if (sArray.length % 2 == 0) {
                    for (int i = sArray.length / 2 ; i < sArray.length - 1 ; i++) {
                            for (int y = 0; y < i + 1; y++) {
                                a = a + sArray[y];
                            }
                            for (int y = sArray.length - i - 1; y < sArray.length ;y++){
                                c = c + sArray[y];
                            }
                        if (a.equals(c)) {
                            f = true;break;
                        }
                        a = "";
                        c = "";

                    }

                }

                 {
                  String m = c;
                    c = "";
                    a = "";
                    for (int y = sArray.length / 2; y < sArray.length; y++) {
                        c = c + sArray[y];
                        a = sArray[sArray.length - 1 - y] + a;

                    }
                    if (a.equals(c)) {
                        flag = true;

                    }
                    if ((!f && !flag) || (!f && flag)){
                        System.out.print("NO");
                    }
                     if ((f) || (f && !flag)){
                         System.out.print("YES\n" + m);

                     }
                }
            }
        }
    }