import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class TaskD {
        final long big = (long) 1e18 + 1;
        long[] fact;
        long[] dp;
        int[] ans;

        public long add(long a, long b) {
            if (a <= big - b)
                return a + b;
            else
                return big;
        }

        public long mult(long a, long b) {
            if (a <= big / b)
                return a * b;
            else
                return big;
        }

        public void get_perm(int n, int pos, int pl, long k) {
            if (n == 1) {
                ans[pos] = 0 + pl;
                return;
            }
            if (n == 2) {
                ans[pos] = 1 + pl;
                ans[pos + 1] = 0 + pl;
                return;
            }
            for (int i = 0; i < n; i++)
                ans[pos + i] = -1;
            boolean[][] used = new boolean[n][n];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    used[i][j] = (i == j);
            for (int i = 0; i < n; i++)
                used[i][n - 1] = true;
            for (int i = 1; i < n; i++) {
                int cnt = (int) (k / (n - i >= 2 ? fact[n - i - 2] : 1));
                for (int j = 0; j < n; j++)
                    if (!used[i][j]) {
                        if (cnt == 0) {
                            ans[pos + i] = j + pl;
                            for (int t = 0; t < n; t++)
                                used[t][j] = true;
                            int to = j + pl;
                            while (ans[to - pl + pos] != -1)
                                to = ans[to - pl + pos];
                            for (int t = 0; t < n; t++)
                                used[to - pl][t] |= used[i][t];
                            break;
                        }
                        cnt--;
                    }
                k %= (n - i >= 2 ? fact[n - i - 2] : 1);
            }
            ans[pos] = (n - 1) + pl;
        }

        public void get_ans(int n, int pos, int pl, long k) {
            for (int i = 1; i <= n; i++)
                if (mult((i >= 2 ? fact[i - 2] : 1), dp[n - i]) > k) {
                    get_perm(i, pos, pl, k / dp[n - i]);
                    get_ans(n - i, pos + i, pl + i, k % dp[n - i]);
                    break;
                } else {
                    k -= mult((i >= 2 ? fact[i - 2] : 1), dp[n - i]);
                }
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            long k = in.nextLong();
            k--;
            fact = new long[n + 1];
            fact[0] = 1;
            for (int i = 1; i <= n; i++)
                fact[i] = mult(fact[i - 1], i);
            dp = new long[n + 1];
            dp[0] = 1;
            for (int i = 1; i <= n; i++) {
                dp[i] = 0;
                for (int j = 1; j <= i; j++)
                    dp[i] = add(dp[i], mult((j >= 2 ? fact[j - 2] : 1), dp[i - j]));
            }
            ans = new int[n];
            get_ans(n, 0, 0, k);
            for (int i = 0; i < n; i++)
                ans[i]++;
            out.println(ans);
        }

    }

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

        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() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(int[] array) {
            for (int i = 0; i < array.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(array[i]);
            }
        }

        public void println(int[] array) {
            print(array);
            writer.println();
        }

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

    }
}


package Round_FirstApril_2013;

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

import static java.lang.Math.*;

public class C {

    void solve () throws IOException {
        int n = in.nextInt();
        if (n == 0){
            out.println(0);
            return;
        }
        double sum = 0;
        for (int i = 0; i<n; i++)
            sum += in.nextDouble();
        out.println(sum / n);

    }

    String input = "";
    String output = "";

    FastScanner in;
    PrintWriter out;

    void run () {
        try {
            BufferedReader bf;
            if (input.length() == 0)
                bf = new BufferedReader(new InputStreamReader(
                        System.in));
            else
                bf = new BufferedReader(new FileReader(input));
            in = new FastScanner(bf);

            if (output.length() == 0)
                out = new PrintWriter(System.out);
            else
                out = new PrintWriter(new File(output));

            solve();

            out.close();
        } catch (Exception ex) {
            out.close();
            ex.printStackTrace();
        }
    }

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

    class FastScanner {
        BufferedReader bf;
        StringTokenizer st;

        FastScanner(BufferedReader bf) {
            this.bf = bf;
        }

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

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

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

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

        int[] readIntArray (int n) throws IOException {
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] readLongArray (int n) throws IOException {
            long a[] = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


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

public class Main {
	public static BufferedReader in;
	public static PrintWriter out;

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

		boolean showLineError = true;
		if (showLineError) {
			solve();
			out.close();
		} else {
			try {
				solve();
			} catch (Exception e) {
			} finally {
				out.close();
			}
		}

	}

	static void debug(Object... os) {
		out.println(Arrays.deepToString(os));
	}
	private static int comp;

	private static void solve() throws IOException {
		int n = Integer.parseInt(in.readLine());
		int m1 = Integer.parseInt(in.readLine());
		List<Integer>[] g = (List<Integer>[]) new List[n];
		for(int i =0;i<n;i++)
			g[i]= new ArrayList<Integer>();
		for(int i =0;i<m1;i++){
			String[] line = in.readLine().split(" ");
			int u = Integer.parseInt(line[0])-1;
			int v = Integer.parseInt(line[1])-1;
			g[u].add(v);
			g[v].add(u);
		}
		int[] ok =new int[n];
		Arrays.fill(ok, -1);
		List<Integer> size=new ArrayList<Integer>();
		for(int i =0;i<n;i++)
			if(ok[i]==-1){
				ok[i]=comp;
				size.add(dfs(g,ok,i));
				comp++;
			}
		int m2 = Integer.parseInt(in.readLine());
		for(int i =0;i<m2;i++){
			String[] line = in.readLine().split(" ");
			int u = Integer.parseInt(line[0])-1;
			int v = Integer.parseInt(line[1])-1;

			if(ok[u]==ok[v])
				size.set(ok[u], 0);
		}
		int ret= 0;
		for(int a : size)
			ret = Math.max(ret, a);
		out.println(ret);
	}

	private static int dfs(List<Integer>[] g, int[] ok, int u) {
		int ret=1;
		for(int v : g[u]){
			if(ok[v]==-1){
				ok[v]=comp;
				ret+=dfs(g,ok,v);
			}
		}
		return ret;
	}

}


public class codeforce {

	public static void main(String[] args) {
		 Scanner scn=new Scanner(System.in);
		 int a=scn.nextInt();
		 ArrayList<Integer> vec=new ArrayList<>();
		 int sum=0;
		 for(int i=0;i<a;i++)
		 {
			 int temp=scn.nextInt();
			 if(temp>0)
				 sum+=temp;
			 else
				 sum-=temp;
		 }
		 System.out.println(sum);
	}

}


public class PerfectNumber1100 {
    public int findKSolution(int k) {
        int counter = 0;
        int i = 0;
        while (counter != k) {
            if (quersumme(i) == 10) {
                counter+=1;
            }
            i++;
        }
        return i-1;
    }

    public int quersumme(int number) {
        int newNumber = 0;
        while (number != 0) {
            newNumber += number%10;
            number = number/10;
        }
        return newNumber;
    }

    public static void main(String[] args) {
        PerfectNumber1100 p = new PerfectNumber1100();
        Scanner s = new Scanner(System.in);
        int imput = s.nextInt();
        System.out.println(p.findKSolution(imput));
    }
}


import java.io.*;
import java.util.*;
public class Solution
{
    static ArrayList<Integer> adj[];
    static boolean visited[];
    static int N;
    static int color[];
    public static void main(String ag[])
    {
        Scanner sc=new Scanner(System.in);
        int i,j,k;

        int N=sc.nextInt();
        char A[]=sc.next().toCharArray();

        visited=new boolean[N];
        color=new int[N];
        adj=new ArrayList[N];
        for(i=0;i<N;i++)
        adj[i]=new ArrayList<>();

        for(i=0;i<N;i++)
        {
            for(j=0;j<i;j++)
            {
                if(A[j]>A[i])
                {
                    adj[j].add(i);
                    adj[i].add(j);
                }
            }
        }

        boolean flag=true;
        for(i=0;i<N;i++)
        {
            if(!visited[i]&&adj[i].size()>0)
            {
                flag=BFS(i);
                if(!flag)
                break;
            }
        }
        if(!flag)
        System.out.println("NO");
        else
        {
            System.out.println("YES");
            for(i=0;i<N;i++)
            System.out.print(color[i]);
        }
    }
    public static boolean BFS(int node)
    {
        Queue<Integer> q=new LinkedList<>();
        q.add(node);
        color[node]=1;
        while(!q.isEmpty())
        {
            int curr=q.poll();
            visited[curr]=true;
            Iterator<Integer> itr=adj[curr].iterator();
            while(itr.hasNext())
            {
                int next=itr.next();
                if(!visited[next])
                {
                    color[next]=1-color[curr];
                    q.add(next);
                }
                else
                {
                    if(color[next]==color[curr])
                    return false;
                }
            }
        }
        return true;
    }

}


import java.util.Scanner;
import java.util.TreeMap;
import  java.math.*;

/**
 * Created by drproduck on 3/3/17.
 */
public class E {
    static long md = 1000000007;
    static long[] prime = new long[1000001];
    static long[] cach = new long[1000000007];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long n = in.nextLong();
        long k = in.nextLong();
        priming();
        TreeMap<Integer, Integer> map = new TreeMap<>();
        k = (k>>1)+(k&1);
        long res = n;
        for (int i = 0; i < k; i++) {
            res = phi(res);
        }
        System.out.println(res%md);
    }

    static long mul(long a, long b) {
        return (a % md) * (b % md) % md;
    }

    static void priming() {
        for (int i = 2; i < prime.length; i++) {
            if (i == 0) {
                for (int j = i; j < prime.length; j+=i) {
                    prime[j] = 1;
                }
            }
        }
    }

    static long phi(long n) {
        if (n < 1e9 && cach[(int)n] != 0) {
            return cach[(int)n];
        }
        int root = (int) Math.sqrt(n);
        long res = 1;
        for (int i = 2; i <= root; i++) {
            if (prime[i] == 0 && n % i == 0) {
                long fact = 1;
                while (n % i == 0) {
                    fact *= i;
                    n /= i;
                }
                res = res * fact / i * (i-1);
            }
        }
        if (n>1) res = res * (n - 1);
        if (n < 1e9) {
            cach[(int)n] = res;
        }
        return res;
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            int n = in.nextInt();
            boolean[] vis = new boolean[10000];
            int[][] arr = new int[n][6];
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < 6; ++j) {
                    arr[i][j] = in.nextInt();

                    vis[arr[i][j]] = true;
                }
            }

            for (int i = 0; i < 6; ++i) {
                if (n > 1)
                    for (int j = 0; j < 6; ++j) {
                        int a = arr[0][i] * 10 + arr[1][j];
                        int b = arr[0][i] * 10 + arr[2][j];
                        int c = arr[1][i] * 10 + arr[2][j];
                        vis[a] = vis[b] = vis[c] = true;
                        a = arr[1][i] * 10 + arr[0][j];
                        b = arr[2][i] * 10 + arr[1][j];
                        c = arr[2][i] * 10 + arr[0][j];
                        vis[a] = vis[b] = vis[c] = true;
                        if (n > 2)
                            for (int k = 0; k < 6; ++k) {

                                a = arr[0][i] * 100 + 10 * arr[1][j] + arr[2][k];
                                b = arr[0][i] * 100 + 10 * arr[2][j] + arr[1][k];
                                c = arr[1][i] * 100 + 10 * arr[0][j] + arr[2][k];
                                vis[a] = vis[b] = vis[c] = true;
                                a = arr[1][i] * 100 + arr[2][j] * 10 + arr[0][k];
                                b = arr[2][i] * 100 + arr[1][j] * 10 + arr[0][k];
                                c = arr[2][i] * 100 + arr[0][j] * 10 + arr[1][k];
                                vis[a] = vis[b] = vis[c] = true;
                            }
                    }
            }

            for (int i = 1; i <= 999; ++i) {
                if (!vis[i]) {
                    out.println(i - 1);
                    return;
                }
            }

            out.println(999);
        }

    }
}


/**
 * Created by IntelliJ IDEA.
 * User: андрей
 * Date: 12.04.2010
 * Time: 0:38:12
 * To change this template use File | Settings | File Templates.
 */
import java.util.*;
import java.io.*;

public class Main {
    StreamTokenizer in;
    PrintWriter out;
    public static void main(String[] args) throws IOException{
        new Main().run();
    }
    void run() throws IOException{
        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(new OutputStreamWriter(System.out));

        solve();

        out.flush();
    }
    long dp[][];
    boolean fil[][];
    void solve() throws IOException{
        int n = ni(), h = ni();
        long res =0 ;
        dp = new long[n*2][h*2];
        fil = new boolean[n*2][h*2];
           for(int i = h; i <= n; ++i)
            res += brute(n,i);
        out.print(res);
    }
    long brute(int n, int h){
        if ( n == 1 && h == 1) return 1;
        if ( n == 0 && h == 0 ) return 1;
        if ( n < 0 || h < 0 ) return 0;
        if ( n == 0 && h != 0 ) return 0;
        //if ( n < h ) return 0;
        if ( fil[n][h] ) return dp[n][h];
        long res = 0;
        for(int i = 0; i < n; ++i) {
            for(int hei = 0; hei <= h - 1; ++hei)
                res += brute(i, hei) * brute(n - i - 1, h - 1) ;
            for(int hei = 0; hei <= h - 1; ++hei)
                res += brute(i, h - 1) * brute(n - i - 1, hei) ;
            res -= brute(i, h - 1) * brute(n - i - 1, h - 1);
        }
        fil[n][h] = true;
        dp[n][h] = res;
        return dp[n][h];
    }
    int ni() throws IOException{
        in.nextToken();
        return (int)in.nval;
    }
}


public class Solution {

    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int h = cin.nextInt();
        long leaf = cin.nextLong() - 1;
        System.out.println(countNodes(h, leaf));
        cin.close();
    }

    private static long countNodes(long h, long leaf) {
        long low = 0, high = (1 << h) - 1;
        long count = 0;
        boolean goLeft = true;
        while (low < high) {
            long mid = low + (high - low) / 2;
            if (goLeft != (low <= leaf && leaf <= mid)) {
                count += (1 << h) - 1;
                goLeft = !goLeft;
            }
            if (low <= leaf && leaf <= mid) {
                high = mid;
            } else {
                low = mid + 1;
            }
            goLeft = !goLeft;
            count++;
            --h;
        }
        return count;
    }
}


import java.util.Arrays;
import java.util.Scanner;

/**
 *
 * @author adrian
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       Scanner l = new Scanner(System.in);

       int r = l.nextInt();
       int g = l.nextInt();
       int b = l.nextInt();

       P[] arr = new P[3];

       arr[0] = new P(0, r);
       arr[1] = new P(1, g);
       arr[2] = new P(2, b);

       Arrays.sort(arr);

        System.out.println(30 + (arr[0].cant / 2) + arr[0].color + 1);
    }

}

class P implements Comparable<P>{
    int color,cant;

    public P(int color, int cant) {
        this.color = color;
        this.cant = cant;
    }

    public int compareTo(P p) {
        if(cant - p.cant > 1 || (Math.abs(cant - p.cant) <= 1 && color > p.color))
            return -1;
        else
            return 1;
    }


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author kessido
 */
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);
        BRomanDigits solver = new BRomanDigits();
        solver.solve(1, in, out);
        out.close();
    }

    static class BRomanDigits {
        long easySolve(int i) {
            int[] dp = new int[]{0, 4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292, 341, 390, 439, 488, 537, 586, 635, 684, 733, 782, 831, 880, 929, 978, 1027, 1076, 1125, 1174};
            if (i < dp.length) {
                return dp[i];
            } else {
                long[] y = new long[]{782, 831, 880, 929};
                long[] x = new long[]{21, 22, 23, 24};
                return LagrangeInterpolation.interpolate(x, y, i, MathExtensions.MAXIMUM_OK_MOD);
            }
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int i = in.NextInt();
            out.println(easySolve(i));
        }

    }

    static class LagrangeInterpolation {
        public static long interpolate(long[] x, long[] y, long xi, long MOD_Prime) {
            long result = 0;
            final int n = x.length;
            for (int i = 0; i < n; i++) {
                long term = y[i] % MOD_Prime;
                for (int j = 0; j < n; j++) {
                    if (j != i)
                        term = (term * (xi - x[j]) % MOD_Prime) * MathExtensions.modInverse_For_M_Prime(x[i] - x[j], MOD_Prime) % MOD_Prime;
                }
                result = (result + term) % MOD_Prime;
            }
            return result;
        }

    }

    static class InputReader {
        BufferedReader reader;
        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(), " \t\n\r\f,");
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }

    static class MathExtensions {
        public static final long MAXIMUM_OK_MOD = 3_012_017_609L;

        public static long modInverse_For_M_Prime(final long a, final long m) {
            return powerMod(a, m - 2, m);
        }

        public static long powerMod(final long x, final long y, final long m) {
            if (y == 0)
                return 1;

            long p = powerMod(x, y / 2, m) % m;
            p = (p * p) % m;

            if (y % 2 == 0)
                return p;
            else
                return (x * p) % m;
        }

    }
}


import java.util.*;
public class chess_secapproach{

    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();

        int allblack = 0 , allwhite= 0;

        int[] arr = new int[n/2];

        for(int i = 0;i < n/2;i++){
            arr[i] = s.nextInt();
        }

        for(int i = 0 ;i < n/2;i++){

            allblack += (Math.abs(arr[i] - (2*i + 1 )))s;
            allwhite += (Math.abs(arr[i] - (2*i + 2 )));
        }

        System.out.println(Math.min(allblack , allwhite ));

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Walker
 */
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);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.readInt();
        char[] board = in.readLine().toCharArray();
        for(int i = 0; i < board.length; i++){
            int curr = i;
            for(int jump = 1; jump < 100; jump++){
                int count = 0;
                int next = curr + jump;
                while(count < 4 && next < n && board[next] == '*'){
                    curr = next;
                    count++;
                    next = curr + jump;
                }
                if(count == 4){
                    out.print("yes");
                    return;
                }
            }
        }
        out.print("no");
    }
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	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 readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return isWhitespace(c);
	}

	public static boolean isWhitespace(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	private String readLine0() {
		StringBuilder buf = new StringBuilder();
		int c = read();
		while (c != '\n' && c != -1) {
			if (c != '\r')
				buf.appendCodePoint(c);
			c = read();
		}
		return buf.toString();
	}

	public String readLine() {
		String s = readLine0();
		while (s.trim().length() == 0)
			s = readLine0();
		return s;
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


import java.util.Scanner;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author madi
 */
public class Round44H {
    static int res = 0;
    static String in;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        in = sc.nextLine();

        if (in.length() == 1) {
            System.out.println(9);
            return;
        }

        int p = 1;
        int r = Integer.parseInt(in.charAt(0) + "");
        for (int i = 1; i < in.length(); i++) {
            int q = Integer.parseInt(in.charAt(i) + "");
            if ((r + q) % 2 == 0) {
                if ((r + q) / 2 != q) {
                    p = 0;
                    break;
                }
            } else {
                if ((r + q) / 2 != q && (r + q) / 2 + 1 != q) {
                    p = 0;
                    break;
                }
            }
            r = q;
        }

        for (int i = 0; i < 10; i++) {
            res++;
            count(i, 1);
        }

        System.out.println(res - p);

    }

    private static void count(int a, int i) {
        int k = Integer.parseInt(in.charAt(i) + "");
        if ((a + k) % 2 != 0) {
            res++;
            if (i < in.length() - 1) {
                count((a + k) / 2, i + 1);
                count((a + k) / 2 + 1, i + 1);
            }
        } else {
            if (i < in.length() - 1) {
                count((a + k) / 2, i + 1);
            }
        }
    }

}


package javaapplication4;

import java.util.Scanner;

public class JavaApplication4 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        String l=sc.next();
        char a[]=new char[n];
        for(int i=0;i<n;i++)
        a[i]=l.charAt(i);
        int i=0,c=0,max=0,ans=0;
        boolean x=false,y=true;
        while(i<n)
        {
            if(a[i]=='(')
            {y=false;
            i++;
            max=Math.max(c, max);c=0
            continue;}
            if (a[i]=='_')
            {
                i++;
                max=Math.max(c, max);
                c=0;
                continue;
            }
            if(a[i]==')')
            {
                i++;
                c=0;
                y=true;
                continue;
            }
            if(y==true)
            {c++;max=Math.max(c, max);}i++;
        }

        for(int j=0;j<n;j++)
        {
            if(a[j]=='(')
            {
                x=true;
                if(a[j+1]!='_'&&a[j+1]!=')')
                    ans++;}

            if(a[j]=='_'&&j<n-1)
                if(a[j+1]!='_'&&a[j+1]!=')'&&x==true)
                    ans++;
            if(a[j]==')')
                x=false;
        }
        System.out.println(max+" "+ans);
}
}


import javax.swing.plaf.basic.BasicButtonUI;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(System.in);
        int min = 1001, max =0, kupil, prod, ost;
        int utr[] = new int[30];
        int vetr[] = new int[30];
        int n = scannernextInt();
        int m = scanner.nextInt();
        int r = scanner.nextInt();

        for(int i =0; i < n; i++){
            utr[i] = scanner.nextInt();
            if(utr[i] < min)
                min = utr[i];
        }

        for(int i = 0; i < m; i++){
            vetr[i] = scanner.nextInt();
            if(vetr[i] > max)
                max = vetr[i];
        }

        if(min > r){
            System.out.println(r);
            return 0;
        }

        kupil = r / min;
        ost = r % min;

        prod = kupil * max + ost;

        if(prod <= r){
            System.out.println(r);
        }
        System.out.println(prod);

    }
}


public final class Solve {
    public static main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int w1 = sc.nextInt();
        int h1 = sc.nextInt();
        int w2 = sc.nextInt();
        int h2 = sc.nextInt();

        int res = 2 * w1 + 2 * h1 + w2 + 2 * h2 + 4 + (w2 < w1 ? 1 : 0);
        System.out.println(res);
    }
}


 public class Main{
    public static void main (String args[])  {
        int x1=sc.nextInt();
        int y1=sc.nextInt();
        int x2=sc.nextInt();
        int y2=sc.nextInt();
     System.out.println((1+(y2-y1)/2)*(1+(x2-x1)/2)+((y2-y1)/2)*((x2-x1)/2));
    }
 }


public class Permutation
{
    public static void main(String args[])
    {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt(); //number of fixed spots

        int counter = 1;

        if(k >= 2){
            counter += n*(n-1)/2;
        }

        if(k >= 3){
            counter += n*(n-1)*(n-2)/3;
        }

        if(k >= 4){
            counter += 3*n*(n-1)*(n-2)*(n-3)/8;
        }

        SYstem.out.println(counter);
    }
}


/*
 * ACM Code => cf110d.java
 * Written by Sam X
 * Date: 三月, 08, 2019
 * Time: 14:27
 */
import java.util.*;
import java.math.*;

public class cf110d
{
    static ArrayList<Long> vec = new ArrayList<>();
    static void dfs(long x)
    {
        if(x>1e9) return;
        vec.add(x*10+4);
        vec.add(x*10+7);
        dfs(x*10+4);
        dfs(x*10+7);
    }
    static final long contain(long x1, long y1, long x2, long y2)
    {
        return Math.max(Math.min(y1,y2)-Math.max(x1,x2)+1,0l);
    }
    public static void main(String args[])
    {
        Scanner cin = new Scanner(System.in);
        long pl = cin.nextLong(),
             pr = cin.nextLong(),
             vl = cin.nextLong(),
             vr = cin.nextLong(),
             k = cin.nextLong();

        dfs(0);
        vec.add(0l);
        vec.add((long)1e9);

        Collections.sort(vec);

        long ans=0;

        for(int i=1; i<=vec.size()-k+1; ++i)
        {
            int j=i+k-1;
            ans+=contain(vec.get(i-1)+1, vec.get(i), pl, pr)*contain(vec.get(j), vec.get(j+1)-1, vl, vr);
            if(vec.get(i)>pr) break;
        }

        for(int i=1; i<=vec.size()-k+1; ++i)
        {
            int j=i+k-1;
            ans+=contain(vec.get(i-1)+1, vec.get(i), vl, vr)*contain(vec.get(j), vec.get(j+1)-1, pl, pr);
            if(vec.get(i)>vr) break;
        }

        if(k==1)
        {
            for(int i=0; i<vec.size(); ++i)
            {
                if(contain(vec.get(i), vec.get(i), pl, pr)!=0 &&
                   contain(vec.get(i), vec.get(i), vl, vr)!=0) ans--;
            }
        }

        System.out.printf("%.12f\n", (double)ans/(vr-vl+1)/(pr-pl+1));
        cin.close();
    }
}


import java.util.*;

public class IvanTheFool {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();

		long[]arr=new long[m];

		arr[0]=2;
		arr[1]=4;

		for(int i=2;i<arr.length;i++) {
			arr[i]=arr[i-1]+arr[i-2];
			arr[i]=arr[i]%1000000007;
		}

		long ans=arr[arr.length-1];
		long ans2=(n-1)*2;
		ans=(ans+ans2)%1000000007;
		System.out.println(ans);
	}

}


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

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

class TaskD {
    boolean visited[];
    String s;
    int k;
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int n=in.nextInt(),k=in.nextInt();
        int i;
        this.k=k;
        visited=new boolean[k];
        long c=0;
        for(i=(int)Math.pow(k,k)-1;i>=0;i--)
        {
            s=Integer.toString(i,k);
            Arrays.fill(visited,false);

            while (s.length()<k) s="0"+s;
            for(int j=0;j<k;j++)
            {
                if(s.charAt(j)=='0')
                    dfs(j);
            }
            boolean status=true;
            for(int j=0;j<k;j++)
            {
                if(!visited[j])
                {
                    status=false;
                    break;
                }
            }
            //DebugUtils.print(s,status);
            if(status)
                c++;
        }
        long mod=(long)Math.pow(10,9)+7;
        long p= IntegerUtils.bigMod(n-k,n-k,mod);
        long ans=(p*c)%mod;
        out.printLine(ans);
    }
    public void dfs(int index)
    {

        visited[index]=true;
        for(int i=0;i<k;i++)
        {
            if(!visited[i]&&s.charAt(i)==index+'0')
                dfs(i);
        }
    }
}

class InputReader
{
    BufferedReader in;
    StringTokenizer tokenizer=null;

    public InputReader(InputStream inputStream)
    {
        in=new BufferedReader(new InputStreamReader(inputStream));
    }
    public String next()
    {
        try{
            while (tokenizer==null||!tokenizer.hasMoreTokens())
            {
                tokenizer=new StringTokenizer(in.readLine());
            }
            return tokenizer.nextToken();
        }
        catch (IOException e)
        {
            return null;
        }
    }
    public int nextInt()
    {
        return Integer.parseInt(next());
    }
    }

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(Object...objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void printLine(Object...objects) {
		print(objects);
		writer.println();
	}

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

class IntegerUtils {

    public static long bigMod(long a,long b,long mod)
    {
        if(b==0)
            return 1;
        else if(b%2==0)
        {
            long x=bigMod(a,b/2,mod)%mod;
            return (x*x)%mod;
        }
        else  return ((a%mod)*bigMod(a,b-1,mod))%mod;
    }

}


import java.util.*;
import java.io.*;
public class d {
	public static void main(String[] arg) {
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		char[] ss = in.next().toCharArray();
		char[] tt = in.next().toCharArray();
		int ns = ss.length;
		int nt = tt.length;
		int[] as = new int[ns];
		for (int i = 0; i < as.length; i++) {
			if (ss[i] != 'A') as[i] = 1;
		}
		int[] at = new int[nt];
		for (int i = 0; i < at.length; i++) {
			if (tt[i] != 'A') at[i] = 1;
		}
		int[] sums = new int[ns + 1];
		int[] sumt = new int[nt + 1];
		for (int i = 0; i < ns; i++) {
			sums[i + 1] = sums[i] + as[i];
		}
		for (int i = 0; i < nt; i++) {
			sumt[i + 1] = sumt[i] + at[i];
		}

		int[] trails = new int[ns];
		int[] trailt = new int[nt];
		for (int i = 0; i < ns; i++) {
			int prev = 0;
			if (i > 0) prev = trails[i - 1];
			prev++;
			if (as[i] != 0) prev = 0;
			trails[i] = prev;
		}
		for (int i = 0; i < nt; i++) {
			int prev = 0;
			if (i > 0) prev = trailt[i - 1];
			prev++;
			if (at[i] != 0) prev = 0;
			trailt[i] = prev;
		}

		int nq = in.nextInt();
		for (int qi = 0; qi < nq; qi++) {
			int a = in.nextInt() - 1, b = in.nextInt() - 1;
			int c = in.nextInt() - 1, d = in.nextInt() - 1;
			int lena = b - a + 1;
			int lenb = d - c + 1;
			int AS = Math.min(lena, trails[b]);
			int AT = Math.min(lenb, trailt[d]);
			int BS = sums[b + 1] - sums[a];
			int BT = sumt[d + 1] - sumt[c];
			//System.err.println(AS + " " + BS + "    " + AT + " " + BT);
			out.print(good(AS, AT, BS, BT) ? '1' : '0');
		}
		out.println();
		out.close();
	}
	static boolean good(int as, int at, int bs, int bt) {
		if (as < at) return false;
		if (bs > bt) return false;
		//if (at == 0) return true;
		int need = 0;
		int am = as % 3;
		int bm = at % 3;
		if (am == bm) need = 0;
		else if ((am + 2) % 3 == bm && as - 1 >= at) need = 1;
		else if ((am + 1) % 3 == bm && as - 2 >= at) need = 2;
		else return false;
		if (need == 0 && bs == 0 && bt != 0) {
			need = 3;
			if (as - need < at) return false;
		}
		boolean sameMod = (bs % 2) == (bt % 2);
		//if (need == 0) {
		//	return bs <= bt && sameMod;
		//}
		bs += Math.min(1, need) * 2;
		//System.err.println("hi  " + bs + " " +bt);
		if (bs > bt) return false;
		return (bs % 2) == (bt % 2);
		//return true;
	}
}


//package com.example.practice.codeforces.sc2900.prac;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.StringTokenizer;

//G. Long Binary String
public class Solution1 {
    // https://abcdxyzk.github.io/blog/2018/04/16/isal-erase-3/
    // https://zhuanlan.zhihu.com/p/132603308
    public static void main (String [] args) throws IOException {
        // Use BufferedReader rather than RandomAccessFile; it's much faster
        final BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        // input file name goes above
        //StringTokenizer st = new StringTokenizer(input.readLine());
        //int n = Integer.parseInt(st.nextToken()), a = Integer.parseInt(st.nextToken()), b = Integer.parseInt(st.nextToken()), k = Integer.parseInt(st.nextToken());
        long[] res = calc(input.readLine());
        if (res==null){
            out.println(-1);
        }else {
            printArray(res, out);
        }
        out.close();       // close the output file
    }

    private static long[] calc(final String s) {
        long px = 0, v = 1;
        int p = s.length()-1, tem = 0, highest = 0, first = 0, c = 0;
        while (p>=0 && s.charAt(p)=='0'){
            p--;
        }
        if (p<0)return null;
        while (p>=0){
            if (s.charAt(p)=='1'){
                px |= 1L << tem;
                highest = tem;
                first = p;
                c++;
            }
            tem++;
            p--;
        }
        if (c==1)return new long[]{first+1, first+2};
        final long m = (long) Math.sqrt(1L<<highest) + 1;
        HashMap<Long, Long> map = new HashMap<>();
        for (int i=1;i<=m;++i){
            v = v << 1;
            if ((v & (1L<<highest)) != 0){
                v = v ^ px;
            }
            if (v == 1){
                return new long[]{first+1, first+1+i};
            }
            if (i<m){
                map.put(v, (long)i);
            }
        }
        final long d = v;
        for (int i=2;i<=m;++i){
            v = multi(px, v, d, highest);
            if (v==1){
                return new long[]{first + 1, first + 1 + m * i};
            }
            Long j = map.get(v);
            if (j != null){
                return new long[]{first + 1, first + 1 + m * i - j};
            }
        }
        return null;
    }

    private static long multi(final long px, final long v, final long d, final int highest){
        long res = 0;
        for (int i=0;i<highest;++i){
            if ((d & (1L<<i)) != 0) {
                int t = i;
                long v2 = v;
                while (t > 0) {
                    v2 = v2 << 1;
                    if ((v2 & (1L<<highest)) != 0){
                        v2 = v2 ^ px;
                    }
                    t--;
                }
                res = res ^ v2;
            }
        }
        return res;
    }

    private static void printArray(long[] ns, final PrintWriter out){
        for (int i=0;i<ns.length;++i){
            out.print(ns[i]);
            if (i+1<ns.length)out.print(" ");
            else out.println();
        }
    }

    private static void printArrayInt(int[] ns, final PrintWriter out){
        for (int i=0;i<ns.length;++i){
            out.print(ns[i]);
            if (i+1<ns.length)out.print(" ");
            else out.println();
        }
    }

    private static void printArrayVertical(long[] ns, final PrintWriter out){
        for (long a : ns){
            out.println(a);
        }
    }

    private static void printArray2D(long[][] ns, final int len, final PrintWriter out){
        int cnt = 0;
        for (long[] kk : ns){
            cnt++;
            if (cnt > len)break;
            for (int i=0;i<kk.length;++i){
                out.print(kk[i]);
                if (i+1<kk.length)out.print(" ");
                else out.println();
            }
        }
    }

    private static void printArray2DInt(int[][] ns, final int len, final PrintWriter out){
        int cnt = 0;
        for (int[] kk : ns){
            cnt++;
            if (cnt > len)break;
            for (int i=0;i<kk.length;++i){
                out.print(kk[i]);
                if (i+1<kk.length)out.print(" ");
                else out.println();
            }
        }
    }

    private static long[] readArray(final int n, final BufferedReader input) throws IOException{
        long[] ns = new long[n];
        StringTokenizer st = new StringTokenizer(input.readLine());
        for (int i=0;i<n;++i){
            ns[i] = Long.parseLong(st.nextToken());
        }
        return ns;
    }

    private static int[] readArrayInt(final int n, final BufferedReader input) throws IOException{
        int[] ns = new int[n];
        StringTokenizer st = new StringTokenizer(input.readLine());
        for (int i=0;i<n;++i){
            ns[i] = Integer.parseInt(st.nextToken());
        }
        return ns;
    }

    private static long[] readArrayVertical(final int n, final BufferedReader input) throws IOException{
        long[] ns = new long[n];
        for (int i=0;i<n;++i){
            ns[i] = Long.parseLong(input.readLine());
        }
        return ns;
    }

    private static long[][] readArray2D(final int n, final int len, final BufferedReader input) throws IOException{
        long[][] ns = new long[len][];
        for (int i=0;i<n;++i){
            StringTokenizer st = new StringTokenizer(input.readLine());
            ArrayList<Long> al = new ArrayList<>();
            while (st.hasMoreTokens()){
                al.add(Long.parseLong(st.nextToken()));
            }
            long[] kk = new long[al.size()];
            for (int j=0;j<kk.length;++j){
                kk[j] = al.get(j);
            }
            ns[i] = kk;
        }
        return ns;
    }

    private static int[][] readArray2DInt(final int n, final int len, final BufferedReader input) throws IOException{
        int[][] ns = new int[len][];
        for (int i=0;i<n;++i){
            StringTokenizer st = new StringTokenizer(input.readLine());
            ArrayList<Integer> al = new ArrayList<>();
            while (st.hasMoreTokens()){
                al.add(Integer.parseInt(st.nextToken()));
            }
            int[] kk = new int[al.size()];
            for (int j=0;j<kk.length;++j){
                kk[j] = al.get(j);
            }
            ns[i] = kk;
        }
        return ns;
    }

    static class SegTree{
        int st;
        int en;
        int mid;
        int val1;
        int val2;
        SegTree left;
        SegTree right;
        public SegTree(int l, int r, int d){
            st = l;
            en = r;
            mid = (st + en) >> 1;
            val1 = val2 = d;
            if (st<en){
                left = new SegTree(st, mid, d);
                right = new SegTree(mid+1, en, d);
            }else {
                left = right = null;
            }
        }

        public SegTree(int l, int r, int[] ns){
            st = l;
            en = r;
            mid = (st + en) >> 1;
            if (st==en){
                val1 = val2 = ns[st];
            }else {
                left = new SegTree(l, mid, ns);
                right = new SegTree(mid+1, r, ns);
                val1 = Math.min(left.val1, right.val1);
                val2 = Math.max(left.val2, right.val2);
            }
        }

        void update(int idx, int v){
            if (st==en){
                val1 = val2 = v;
            }else {
                if (idx <= mid){
                    left.update(idx, v);
                }else {
                    right.update(idx, v);
                }
                val1 = Math.min(left.val1, right.val1);
                val2 = Math.max(left.val2, right.val2);
            }
        }

        int getMin(int l, int r){
            if (st==en || (l==st && r==en))return val1;
            if (r<=mid){
                return left.getMin(l, r);
            }
            if (l>mid){
                return right.getMin(l, r);
            }
            return Math.min(left.getMin(l, mid), right.getMin(mid+1, r));
        }

        int getMax(int l, int r){
            if (st==en || (l==st && r==en))return val2;
            if (r<=mid){
                return left.getMax(l, r);
            }
            if (l>mid){
                return right.getMax(l, r);
            }
            return Math.max(left.getMax(l, mid), right.getMax(mid+1, r));
        }
    }

    static class SparseTable{
        int[][] minTable;
        int[][] maxTable;
        int[] log2;
        int n;
        public SparseTable(final int[] ns){
            n = ns.length;
            int m = 0, pre = 0;
            while (1<<m < n){
                m++;
            }
            m++;
            minTable = new int[n][m];
            maxTable = new int[n][m];
            log2 = new int[n+1];
            for (int i=0;i<n;++i){
                minTable[i][0] = ns[i];
                maxTable[i][0] = ns[i];
                if ((1<<(pre+1)) == i+1){
                    pre++;
                }
                log2[i+1] = pre;
            }
            for (int i=1;i<m;++i){
                for (int j=0;j<n;++j){
                    int r = Math.min(n-1, j+(1<<i)-1);
                    if (r-(1<<(i-1))+1 <= j){
                        minTable[j][i] = minTable[j][i-1];
                        maxTable[j][i] = maxTable[j][i-1];
                    }else {
                        minTable[j][i] = Math.min(minTable[j][i-1], minTable[r-(1<<(i-1))+1][i-1]);
                        maxTable[j][i] = Math.max(maxTable[j][i-1], maxTable[r-(1<<(i-1))+1][i-1]);
                    }
                }
            }
        }

        int getMin(final int l, final int r){
            int d = log2[r-l+1];
            return Math.min(minTable[l][d], minTable[r-(1<<d)+1][d]);
        }

        int getMax(final int l, final int r){
            int d = log2[r-l+1];
            return Math.max(maxTable[l][d], maxTable[r-(1<<d)+1][d]);
        }
    }
}


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

public class Main {
    static final long MOD = 1000000007L;
    static int n;
    static int search(int pos, int[][] map, boolean[][] depend, boolean[] finished, int count) {
        int res = 0;
        for (int i = 0; i < map[pos].length; i++) {
            int val = map[pos][i];
            if (finished[val]) {
                continue;
            }
            boolean check = true;
            for (int j = 0; j < n; j++) {
                if (depend[val][j] && !finished[j]) {
                    check = false;
                    break;
                }
            }
            if (check) {
                finished[val] = true;
                count++;
                res++;
            }
        }
        if (count == n) {
            return res;
        }
        else {
            return res + 1 + search((pos + 1) % 3, map, depend, finished, count);
        }
    }

    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        n = scan.nextInt();
        int[] require = new int[n];
        int[] count = new int[3];
        for (int i = 0; i < n; i++) {
            require[i] = scan.nextInt() - 1;
            count[require[i]]++;
        }
        final boolean[][] depend = new boolean[n][n];
        for (int i = 0; i < n; i++) {
            int k = scan.nextInt();
            for (int j = 0; j < k; j++) {
                depend[i][scan.nextInt() - 1] = true;
            }
        }
        int[][] map = new int[3][];
        for (int i = 0; i < 3; i++) {
            map[i] = new int[count[i]];
            for (int j = 0, k = 0; j < n; j++) {
                if (require[j] == i) {
                    map[i][k++] = j;
                }
            }
        }
        for (int i = 0; i < 3; i++) {
            int[] temp = new int[map[i].length];
            HashSet<Integer> checker = new HashSet<Integer>();
            for (int j = 0; j < temp.length; j++) {
                int res = -1;
                for (int k = 0; k < n; k++) {
                    if (require[k] != i || checker.contains(k)) {
                        continue;
                    }
                    if (res == -1 || depend[res][k]) {
                        res = k;
                    }
                }
                temp[j] = res;
                checker.add(res);
            }
            for (int j = 0; j < temp.length; j++) {
                map[i][j] = temp[j];
            }
            for (int j = 0; j < temp.length; j++) {
                for (int k = j + 1; k < temp.length; k++) {
                    if (depend[temp[j]][temp[k]]) {
                        throw new Exception();
                    }
                }
            }
        }

        int result = Integer.MAX_VALUE;
        for (int i = 0; i < 3; i++) {
            result = Math.min(result, search(i, map, depend, new boolean[n], 0));
        }
        System.out.println(result);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
public class Main
{
  static boolean prime[] = new boolean[1000001];
  static int parent[];
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            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;
        }
    }
  static  void sieveOfEratosthenes(int n)
 {
     // Create a boolean array "prime[0..n]" and initialize
     // all entries it as true. A value in prime[i] will
     // finally be false if i is Not a prime, else true.

     for(int i=0;i<n;i++)
         prime[i] = true;

     for(int p = 2; p*p <=n; p++)
     {
         // If prime[p] is not changed, then it is a prime
         if(prime[p] == true)
         {
             // Update all multiples of p
             for(int i = p*2; i <= n; i += p)
                 prime[i] = false;
         }
     }

 }

    static long power(long x, long y, long p)
       {

           long res = 1;

           // Update x if it is more
           // than or equal to p
           x = x %p;

           while (y > 0)
           {
               // If y is odd, multiply x
               // with result
               if((y & 1)==1)
                   res = (res * x) %p;

               // y must be even now
               // y = y / 2
               y = y >> 1;
               x = (x * x)%p ;
           }
           return res;
       }
       static long fun(long n, long r) {

        // p holds the value of n*(n-1)*(n-2)...,
        // k holds the value of r*(r-1)...
        long p = 1, k = 1;

        // C(n, r) == C(n, n-r),
        // choosing the smaller value
        if (n - r < r) {
            r = n - r;
        }

        if (r != 0) {
            while (r > 0) {
                p *= n;
                k *= r;

                // gcd of p, k
                long m = __gcd(p, k);

                // dividing by gcd, to simplify product
                // division by their gcd saves from the overflow
                p /= m;
                k /= m;

                n--;
                r--;
            }

            // k should be simplified to 1
            // as C(n, r) is a natural number
            // (denominator should be 1 ) .
        } else {
            p = 1;
        }

        // if our approach is correct p = ans and k =1
        return p;
    }

    static long __gcd(long n1, long n2) {
        long gcd = 1;

        for (int i = 1; i <= n1 && i <= n2; ++i) {
            // Checks if i is factor of both integers
            if (n1 % i == 0 && n2 % i == 0) {
                gcd = i;
            }
        }
        return gcd;
    }

    public static void main(String[] args)
    {
        FastReader sc=new FastReader();
        long n=sc.nextLong();
        int p=sc.nextInt();
        long min=111111111;
        for( int i=1;i<=31;i++)
        {
          long q=n-i*p;
          int x=0;int f=0;
          while(q>0)
          {
            x+=q%2;
            q/=2;
            f=1;
          }
          if(x<=i&&f==1)
          {
            min=Math.min(min,i);
          }

        }
        if(min==111111111)
        System.out.println(-1);
        else
        System.out.println(min);

    }
}
class MergeSort
{
    // Merges two subarrays of arr[].
    // First subarray is arr[l..m]
    // Second subarray is arr[m+1..r]
    void merge(long arr[], int l, int m, int r)
    {
        // Find sizes of two subarrays to be merged
        int n1 = m - l + 1;
        int n2 = r - m;

        /* Create temp arrays */
        long L[] = new long [n1];
        long R[] = new long [n2];

        /*Copy data to temp arrays*/
        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];

        /* Merge the temp arrays */

        // Initial indexes of first and second subarrays
        int i = 0, j = 0;

        // Initial index of merged subarry array
        int k = l;
        while (i < n1 && j < n2)
        {
            if (L[i] <= R[j])
            {
                arr[k] = L[i];
                i++;
            }
            else
            {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        /* Copy remaining elements of L[] if any */
        while (i < n1)
        {
            arr[k] = L[i];
            i++;
            k++;
        }

        /* Copy remaining elements of R[] if any */
        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    // Main function that sorts arr[l..r] using
    // merge()
    void sort(long arr[], int l, int r)
    {
        if (l < r)
        {
            // Find the middle point
            int m = (l+r)/2;

            // Sort first and second halves
            sort(arr, l, m);
            sort(arr , m+1, r);

            // Merge the sorted halves
            merge(arr, l, m, r);
        }
    }

    /* A utility function to print array of size n */
    static void printArray(int arr[])
    {
        int n = arr.length;
        for (int i=0; i<n; ++i)
            System.out.print(arr[i] + " ");
        System.out.println();
    }
}


import java.util.Scanner;

public class sample{
    public static void main(String args[]){
    Scanner s=new Scanner(System.in);
    int a=s.nextInt(),b=s.nextInt(),c=s.nextInt(),d=s.nextInt();
    int ans=Math.ceil(Math.ceil(a*(b/s))/d);
    System.out.println(ans);
    }
}


import java.util.Scanner;

public class file {
	public static void main(String[] args) {
		Scanner s=new Scanner (System.in);
		String pre=s.next();
		String post=s.next();
		int h1=(pre.charAt(0)-48)*10+(pre.charAt(1)-48);
		int m1=(pre.charAt(3)-48)*10+(pre.charAt(4)-48);
		int h2=(post.charAt(0)-48)*10+(post.charAt(1)-48);
		int m2=(post.charAt(3)-48)*10+(post.charAt(4)-48);
		int minTime=(m2>=m1)?m2-m1:(m2+60-m1);
		if (m2<m1)
			h2=h2-1;
		minTime=(minTime+(h2-h1)*60)/2;
		m1=m1+minTime;
		h1=h1+(m1/60);
		m1=m1%60;
		System.out.print(h1+":"+m1);
		s.close();
	}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Abhilash
 */
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);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            TaskB.Node table[][] = new TaskB.Node[3][3];
            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                    table[i][j] = new TaskB.Node();
                }
            }

            for (int i = 0; i < 9; i++) {
                for (int j = 0; j < 3; j++) {
                    String s = in.next();
                    table[i / 3][j].fill(s, i % 3);
                }
            }

            int x = in.nextInt() - 1;
            int y = in.nextInt() - 1;

            int p = x % 3;
            int q = y % 3;

            int count = table[p][q].fill2();

            if (count == 0) {
                for (int i = 0; i < 3; i++) {
                    for (int j = 0; j < 3; j++) {
                        if (i != p || j != q) {
                            table[i][j].fill2();
                        }
                    }
                }
            }

            for (int i = 0; i < 9; i++) {
                for (int j = 0; j < 3; j++) {
                    out.print(table[i / 3][j].sarr[i % 3] + " ");
                }
                out.println();
                if (i % 3 == 2)
                    out.println();
            }
        }

        static class Node {
            public char arr;
            public String sarr;

            public Node() {
                arr = new char[3][3];
                sarr = new String[3];
            }

            public void fill(String s, int idx) {
                for (int i = 0; i < 3; i++) {
                    arr[idx][i] = s.charAt(i);
                }
                sarr[idx] = s;
            }

            public int fill2() {
                int count = 0;
                for (int i = 0; i < 3; i++) {
                    for (int j = 0; j < 3; j++) {
                        if (arr[i][j] == '.') {
                            arr[i][j] = '!';
                            count += 1;
                        }
                    }
                    sarr[i] = arr[i][0] + "" + arr[i][1] + arr[i][2];
                }
                return count;
            }

        }

    }

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

    }
}


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

public class Solution {

    private static final String checkerSolutionOutput = System.getProperty("user.dir") + "\\src\\_checker.solution.out";
    private static final String checkerInput = System.getProperty("user.dir") + "\\src\\_checker.in";
    private static final String checkerBruteforcesOutput = System.getProperty("user.dir") + "\\src\\_checker.bruteforces.out";
    private static final String fileInput = System.getProperty("user.dir") + "\\src\\_in";
    private static final String fileOutput = System.getProperty("user.dir") + "\\src\\_in";

    private static class Config {
        static final boolean useInputFile = false;
        static final boolean useOutputFile = false;
        static final String inputFile = checkerInput;
        static final String outputFile = checkerSolutionOutput;
    }

    public static void main(String[] args) throws Exception {
        run();
    }

    public static void run() throws Exception {
        FastScanner sc = new FastScanner();
        int t = 1;
        BufferedWriter writer = getWriter();
        for (int i = 0; i < t; i++)
            solve(sc, writer);
        writer.flush();
    }

    public static void solve(FastScanner sc, BufferedWriter writer) throws Exception {
        int n = sc.nextInt();
        long k = sc.nextLong();
        long[] dp = new long[n + 1];
        long sum = 1;
        dp[1] = 1;
        dp[2] = 2;
        for (int x = 3; x <= n; x++) {
            sum += dp[x - 1];
            sum %= k;
            dp[x] += sum;
            for (int z = 2; z <= (int) (Math.ceil(Math.sqrt(x))); z++) {
                dp[x] += dp[Math.floorDiv(x, z)];
                dp[x] %= k;
            }
            for (int z = (int) (Math.ceil(Math.sqrt(x)) + 1); z <= x; z++) {
                dp[x] += dp[Math.floorDiv(x, z)];
                dp[x] %= k;
            }
        }

        writer.write(dp[n] + "\n");
    }

    private static class FastScanner {

        BufferedReader br;
        StringTokenizer st;

        private FastScanner() throws FileNotFoundException {
            if (Config.useInputFile)
                this.br = new BufferedReader(new InputStreamReader(new FileInputStream(Config.inputFile)));
            else
                this.br = new BufferedReader(new InputStreamReader(System.in));
            this.st = new StringTokenizer("");
        }

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

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

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

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

    private static BufferedWriter getWriter() throws Exception {
        if (Config.useOutputFile)
            return getFileWriter();
        return getConsoleWriter();
    }

    private static BufferedWriter getFileWriter() throws Exception {
        PrintWriter writer = new PrintWriter(Config.outputFile);
        writer.print("");
        writer.close();
        return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(Config.outputFile)));
    }

    private static BufferedWriter getConsoleWriter() {
        return new BufferedWriter(new OutputStreamWriter(System.out));
    }
}


import java.io.*;

public class CF506E {

    final static int MOD = 10007;

    static int[][] mul(int[][] a, int[][] b) {
        int[][] c = new int[a.length][a.length];
        for (int i = 0; i < a.length; ++i) {
            for (int j = i; j < a.length; ++j) {
                long sum = 0;
                for (int k = i; k <= j; ++k) {
                    sum += a[i][k] * b[k][j];
                }
                c[i][j] = (int) (sum % MOD);
            }
        }
        return c;
    }

    static int[][] pow(int[][] a, long pow) {
        int[][] r = new int[a.length][a.length];
        for (int i = 0; i < a.length; ++i) {
            r[i][i] = 1;
        }
        while (pow > 0) {
            if (pow % 2 == 1) {
                r = mul(r, a);
            }
            pow /= 2;
            a = mul(a, a);
        }
        return r;
    }

    public static void solve(Input in, PrintWriter out) throws IOException {
        String s = in.next();
        int n = s.length();
        int k = n + in.nextInt();
        int ans = solveFast(s, k);
        out.println(ans);
    }

    private static int solveFast(String s, int k) {
        int n = s.length();
        int[][][] d = new int[n + 1][n + 1][n + 1];
        d[0][n][0] = 1;
        for (int len = n; len > 0; --len) {
            for (int i = 0; i + len <= n; ++i) {
                for (int u = 0; u <= n; ++u) {
                    if (d[i][i + len][u] != 0) {
                        if (s.charAt(i) == s.charAt(i + len - 1)) {
                            d[i + 1][i + len - 1][u + 1] = (d[i + 1][i + len - 1][u + 1] + d[i][i + len][u]) % MOD;
                        } else {
                            d[i + 1][i + len][u] = (d[i + 1][i + len][u] + d[i][i + len][u]) % MOD;
                            d[i][i + len - 1][u] = (d[i][i + len - 1][u] + d[i][i + len][u]) % MOD;
                        }
                    }
                }
            }
        }
        int[][] d1 = new int[n + 1][n + 1];
        int[][] d2 = new int[n + 1][n + 1];
        for (int i = 0; i < n; ++i) {
            for (int u = 0; 2 * u <= n; ++u) {
                d1[u][n - 2 * u] += d[i][i][u];
                if (2 * u <= n - 1) {
                    d2[u][n - 2 * u - 1] += d[i][i + 1][u];
                }
            }
        }
        int ans = 0;
        int[][] a0 = new int[3 * n + 1][3 * n + 1];
        for (int i = 0; i < n; ++i) {
            a0[i][i] = 25;
            a0[i][i + 1] = 1;
            if (i + 1 == n) {
                a0[i][2 * n] = 1;
            }
        }
        for (int i = n; i < 2 * n; ++i) {
            a0[i][i] = 24;
            if (i + 1 != 2 * n) {
                a0[i][i + 1] = 1;
            }
            a0[i][n + i + 1] = 1;
        }
        for (int i = 2 * n; i <= 3 * n; ++i) {
            a0[i][i] = 26;
        }
        int[][] a0low = pow(a0, k / 2);
        int[][] a0high = k % 2 == 1 ? mul(a0low, a0) : a0low;
        for (int u = 0; u <= n; ++u) {
            for (int v = 0; v <= n; ++v) {
                if (d1[u][v] != 0) { // aa
                    int cur = a0low[n - u][2 * n + v];
                    if (k % 2 == 1) {
                        cur = cur * 26 % MOD;
                    }
                    ans = (ans + d1[u][v] * cur) % MOD;
//                    System.err.println("d1: " + u + " " + v + " " + d1[u][v] + " " + cur);
                }
                if (d2[u][v] != 0) { // a
                    int cur = a0high[n - u - 1][2 * n + v];
                    ans = (ans + d2[u][v] * cur) % MOD;
//                    System.err.println("d2: " + u + " " + v + " " + d2[u][v] + " " + cur);
                }
            }
        }
        return ans;
    }

    private static int solveSlow(String s, int k) {
        int n = s.length();
        int[][] d = new int[n + 1][n + 1];
        d[0][n] = 1;
        for (int it = 0; it < k / 2; ++it) {
            int[][] d1 = new int[n + 1][n + 1];
            for (int len = n; len > 0; --len) {
                for (int i = 0; i + len <= n; ++i) {
                    if (d[i][i + len] != 0) {
                        if (s.charAt(i) == s.charAt(i + len - 1)) {
                            d1[Math.min(i + 1, i + len - 1)][i + len - 1] = (d1[Math.min(i + 1, i + len - 1)][i + len - 1] + d[i][i + len]) % MOD;
                            d1[i][i + len] = (d1[i][i + len] + d[i][i + len] * 25) % MOD;
                        } else {
                            d1[i + 1][i + len] = (d1[i + 1][i + len] + d[i][i + len]) % MOD;
                            d1[i][i + len - 1] = (d1[i][i + len - 1] + d[i][i + len]) % MOD;
                            d1[i][i + len] = (d1[i][i + len] + d[i][i + len] * 24) % MOD;
                        }
                    }
                }
            }
            for (int i = 0; i <= n; ++i) {
                d1[i][i] = (d1[i][i] + d[i][i] * 26) % MOD;
            }
            d = d1;
        }
        int ans = 0;
        for (int i = 0; i < n; ++i) {
            if (k % 2 == 0) {
                ans += d[i][i];
            } else {
                ans += d[i][i] * 26 + d[i][i + 1];
            }
        }
        return ans % MOD;
    }

    /*
0 78
0 76
6624 57
8739 55
0 123
0 93
0 99
1871 122
6968 75
8247 1
0 79
3404 10
0 19
0 85
4715 23
8609 1
1910 86
721 113
4055 12
659 82
0 115
0 53
944 57
9422 11

     */

    public static void main(String[] args) throws IOException {
        PrintWriter out = new PrintWriter(System.out);
//        Random rnd = new Random(42);
//        while (rnd != null) {
//            int n = rnd.nextInt(10) + 1;
//            StringBuilder sb = new StringBuilder();
//            for (int i = 0; i < n; ++i) {
//                sb.append((char)('a' + rnd.nextInt(5)));
//            }
//            int k = rnd.nextInt(100) + 1;
//            int ans1 = solveSlow(sb.toString(), k);
//            int ans2 = solveFast(sb.toString(), k);
//            if (ans1 != ans2) {
//                System.err.println(sb + " " + k);
//                System.err.println(ans1 + " " + ans2);
//                throw new AssertionError();
//            }
////            sb.append("\n");
////            sb.append(rnd.nextInt(100));
////            solve(new Input(sb.toString()), out);
////            return;
//        }
        solve(new Input(new BufferedReader(new InputStreamReader(System.in))), out);
        out.close();
    }

    static class Input {
        BufferedReader in;
        StringBuilder sb = new StringBuilder();

        public Input(BufferedReader in) {
            this.in = in;
        }

        public Input(String s) {
            this.in = new BufferedReader(new StringReader(s));
        }

        public String next() throws IOException {
            sb.setLength(0);
            while (true) {
                int c = in.read();
                if (c == -1) {
                    return null;
                }
                if (" \n\r\t".indexOf(c) == -1) {
                    sb.append((char)c);
                    break;
                }
            }
            while (true) {
                int c = in.read();
                if (c == -1 || " \n\r\t".indexOf(c) != -1) {
                    break;
                }
                sb.append((char)c);
            }
            return sb.toString();
        }

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

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

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


import javax.print.attribute.IntegerSyntax;
import java.io.*;
import java.util.*;

/**
 * A simple template for competitive programming problems.
 */
public class Banana {
    final InputReader in = new InputReader(System.in);
    final PrintWriter out = new PrintWriter(System.out);

    final long mod = 998244353;

    final boolean DEBUG = false;
    void solve() {

        int n = in.nextInt();
        List<Map<Integer, Long>> dp = new ArrayList<>(n);

        dp.add(new HashMap<>());
        Map<Integer, Long> firstMap = new HashMap<>();
        firstMap.put(1, 1L);
        dp.add(firstMap);

        for(int i=2; i<=n; i++) {
            Map<Integer, Long> map = new HashMap<>();
            dp.add(map);
            int maxDiff = findMaxDiff(i);
            int minVal = (i-maxDiff-1)/2;
            for(int j=minVal; j<=minVal+maxDiff; j++) {
                long val = 0;
                Map<Integer, Long> leftMap = dp.get(j);
                Map<Integer, Long> rightMap = dp.get(i-1-j);
                if(leftMap.isEmpty()) {
                    for(Integer right : rightMap.keySet()) {
                        if(right%2!=0) continue;
                        long mul = rightMap.get(right) % mod;
                        val = (val+mul) % mod;
                    }
                } else if(rightMap.isEmpty()) {
                    for(Integer left : leftMap.keySet()) {
                        if(left%2==(j+1)%2) continue;
                        long mul = leftMap.get(left) % mod;
                        val = (val+mul) % mod;
                    }
                } else {
                    for(Integer left : leftMap.keySet()) {
                        if(left%2==(j+1)%2) continue;
                        for(Integer right : rightMap.keySet()) {
                            if(right%2!=0) continue;
                            long mul = leftMap.get(left)*rightMap.get(right) % mod;
                            val = (val+mul) % mod;
                        }
                    }
                }
                map.put(j+1, val);
            }
        }

        out.println(sumVal(dp.get(n)));
    }

    private long sumVal(Map<Integer, Long> map) {
        long val = 0;
        for(long mapVal : map.values()) {
            val = (val + mapVal) % mod;
        }
        return val;
    }

    private int findMaxDiff(int i) {
        int log = 31 - Integer.numberOfLeadingZeros(i);
        int deepestNodesCount = i - (1<<log) + 1;
        int deepestEmptyNodesCount = (1<<log) - deepestNodesCount;
        return Math.min(deepestEmptyNodesCount, deepestNodesCount);
    }

    public static void main(String[] args) throws FileNotFoundException { Banana s = new Banana(); s.solve(); s.out.close(); }

    public Banana() throws FileNotFoundException { }

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

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

        InputReader(String fileName) {
            InputStream stream = null;
            try {
                stream = new FileInputStream(fileName);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
            this.stream = stream;
        }

        int[] nextArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++)
                arr[i] = nextInt();
            return arr;
        }

        int[][] nextMatrix(int n, int m) {
            int[][] matrix = new int[n][m];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                    matrix[i][j] = nextInt();
            return matrix;
        }

        String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        String nextString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

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

        private 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++];
        }

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

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

}


import java.io.*;
import java.util.*;
public class G{
    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.flush();out.close();
    }
        static class TaskE {
        class MinCostMaxFlow{
                ArrayList<Edge> al[];
                Edge ja[][];
                int d[]; // shortest distances
                int N , S , T , maxFlow ; int minCost;
                final int gmax = Integer.MAX_VALUE / 100;

                int edges = 0;

                class Edge{
                    int u , flow, rid, cost;
                    Edge(int a, int b, int c, int d){u = a; flow = b; cost = c; rid = d;}
                }

                void addEdge(int u , int v , int flow , int cost){
                    int lu = al[u].size(), lv = al[v].size();
                    al[u].add(new Edge(v, flow, cost, lv));
                    al[v].add(new Edge(u, 0, -cost, lu));
                }

                void convertToArray(){
                    ja = new Edge[N][];
                    for(int i = 0; i < N; i++){
                        int sz = al[i].size();
                        ja[i] = new Edge[sz];
                        for(int j = 0; j < sz; j++){
                            ja[i][j] = al[i].get(j);
                        }
                        al[i].clear();
                    }
                }

                MinCostMaxFlow(int n , int source , int sink){
                    N = n; S = source; T = sink; maxFlow = 0; minCost = 0;
                    al = new ArrayList[N];
                    d = new int[N];
                    for(int i = 0; i < N; i++){
                        al[i] = new ArrayList<>();
                    }
                }

                boolean BellmanFord(boolean check){
                    d[0] = 0;
                    for(int i = 0; i < N - 1; i++){
                        for(int j = 0; j < N; j++){
                            for(Edge e : ja[j]){
                                if(e.flow == 0)continue; // not to consider reverse edges
                                d[e.u] = Math.min(d[e.u] , d[j] + e.cost);
                            }
                        }
                    }
                    if(check){// check for negative cycles
                        for(int j = 0; j < N; j++){
                            for(Edge e : ja[j]){
                                if(e.flow == 0)continue;
                                if(d[j] + e.cost < d[e.u]) return false;
                            }
                        }
                    }return true;
                }

                int node[]; // present node

                int visit[]; // 0 -> not added 1 -> not removed 2 -> removed
                int prv[], prve[]; // previous node for augmentation
                int dist[]; // min dist

                boolean simple(){
                    node = new int[N];
                    visit = new int[N];
                    prv = new int[N];
                    prve = new int[N];
                    dist = new int[N];   Arrays.fill(dist , gmax);

                    node[0] = S; dist[0] = 0;
                    int front = 1, back = 0;
                    while(front != back){
                        int u = node[back++]; int distu = dist[u];
                        if(back == N)back = 0;
                        visit[u] = 2;
                        for(int i = 0; i < ja[u].length; i++){
                            Edge e = ja[u][i];
                            if(e.flow == 0)continue;
                            int cdist = distu + e.cost; // no need of reduced cost
                            if(cdist < dist[e.u]){
                                if(visit[e.u] == 0){
                                    node[front] = e.u;
                                    if(++front == N)front = 0;
                                }else if(visit[e.u] == 2){
                                    if(--back == -1)back += N;
                                    node[back] = e.u;
                                }
                                visit[e.u] = 1;
                                prve[e.u] = i; prv[e.u] = u; dist[e.u] = cdist;
                            }
                        }
                    }
                    return visit[T] != 0;
                }

                class pair{
                    int F; int S;
                    pair(int a, int b){F = a; S = b;}
                }

                boolean dijkstra(){
                    visit = new int[N];
                    prv = new int[N];
                    prve = new int[N];
                    dist = new int[N]; Arrays.fill(dist, gmax);
                    PriorityQueue<pair> pq = new PriorityQueue<>((A, B) -> Double.compare(A.S , B.S));

                    pq.add(new pair(S , 0)); dist[0] = 0;
                    o : while(!pq.isEmpty()){
                        pair p = pq.poll();
                        while(dist[p.F] < p.S){
                            if(pq.isEmpty()) break o; // had a better val
                            p = pq.poll();
                        }
                        visit[p.F] = 2;
                        for(int i = 0; i < ja[p.F].length; i++){
                            Edge e = ja[p.F][i];
                            if(e.flow == 0)continue; // important
                            int cdist = p.S + (e.cost + d[p.F] - d[e.u]); // reduced cost
                            if(cdist < dist[e.u]){
                                if(visit[e.u] == 2) return false;
                                pq.add(new pair(e.u , cdist));
                                dist[e.u] = cdist; prv[e.u] = p.F; prve[e.u] = i;
                                visit[e.u] = 1;
                            }
                        }
                    }
                    return visit[T] != 0;
                }

                int augment(){
                    int p = T; int min = gmax;
                    while(p != 0){
                        int pp = prv[p], pe = prve[p];
                        int val = ja[pp][pe].flow;
                        min = Math.min(min , val);
                        p = pp;
                    }
                    p = T;
                    while(p != 0){
                        int pp = prv[p], pe = prve[p];
                        ja[pp][pe].flow -= min;
                        ja[p][ja[pp][pe].rid].flow += min;
                        p = pp;
                    }
                    maxFlow += min;
                    return min;
                }

                // if(dist[T] >= 0)return true; // non contributing flow
                boolean calSimple(){
                    // uncomment to check for negative cycles
                    /* boolean possible = BellmanFord(true);
                     if(!possible) return false; */
                    while(simple()){
                        /*if(dist[T] >= 0)return true;*/
                        minCost += dist[T] * augment();
                    }
                    return true;
                }

                void updPotential(){
                    for(int i = 0; i < N; i++){
                        if(visit[i] != 0){
                            d[i] += dist[i] - dist[S];
                        }
                    }
                }
                boolean calWithPotential(){
                    // set true to check for negative cycles
                    // boolean possible = BellmanFord(false);
                    // if(!possible) return false;
                    while(dijkstra()){
                        int min = dist[T] + d[T] - d[S]; // getting back the original cost
                        /*if(dist[T] >= 0)return true;*/
                        minCost += min * augment();
                        updPotential();
                    }
                    return true;
                }
            }
            int n , m, k, c, d, a[], f[];
           public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt(); m = in.nextInt(); k = in.nextInt(); c = in.nextInt(); d= in.nextInt();
            // S + n
            int maxl = n + k, T = n * maxl + 1;
            MinCostMaxFlow ans = new MinCostMaxFlow(T + 1, 0, T);
            a = new int[k + 1]; f = new int[n + 1];
            for(int i = 1; i <= k; i++){
                a[i] = in.nextInt();
                f[a[i]]++;
            }
            for(int i = 1; i <= n; i++){
                if(f[i] == 0)continue;
                ans.addEdge(0 , i , f[i], 0);
            }
            for(int i = 2; i <= n; i++){
                for(int l = 0; l < maxl - 1; l++){
                    ans.addEdge(l * n + i , (l + 1) * n + i, k, c);
                }
            }
            for(int i = 1; i <= m; i++){
                int a = in.nextInt(), b = in.nextInt();
                for(int l = 0; l < maxl - 1; l++){
                    for(int p = 1; p <= k; p++){
                        if(a != 1)
                            ans.addEdge(n * l + a, n * (l + 1) + b, 1, d * (2 * p - 1) + c);
                        if(b != 1)
                            ans.addEdge(n * l + b, n * (l + 1) + a, 1, d * (2 * p - 1) + c);
                    }
                }
            }
            for(int l = 1; l < maxl; l++){
                ans.addEdge(l * n + 1, T, k, 0);
            }
            ans.convertToArray();
            ans.calWithPotential();
            // ans.calSimple();
            if(ans.maxFlow != k){
                out.println("BUG");
            }else{
                out.println((int)ans.minCost);
            }
          }
    }
    static class InputReader {
        BufferedReader br;
        StringTokenizer st;
        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

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

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}


import java.util.Arrays;
import java.util.Scanner;

public class E {
    static double DP[][][][];
    static double p;
    static int screen = (1 << 8) - 1;

    public static double get(int index, int mask, int ninth, int cnt) {
        if (index == 0) {
            int res = 0;
            while ((mask & 1) == 0 && res < 8) {
                res++;
                mask >>= 1;
            }
            if (res == 8 && ninth == 0)
                res += cnt;
            return res;
        }
        if (DP[index][mask][ninth][cnt] != -1)
            return DP[index][mask][ninth][cnt];
        double res = 0;
        int nextBit = (mask & (1 << 7)) == 0 ? 0 : 1;
        int nextCnt = nextBit == ninth ? (cnt + 1) : 1;
        int nextMask = (mask << 1);
        res += p * get(index - 1, nextMask & screen, nextBit, nextCnt);

        nextMask = mask + 1;
        nextBit = (nextMask & (1 << 8)) == 0 ? ninth : ((1 + ninth) & 1);
        nextCnt = nextBit == 0 || ninth == 1 ? cnt : 1;
        res += (1 - p) * get(index - 1, nextMask & screen, nextBit, nextCnt);
        return DP[index][mask][ninth][cnt] = res;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();
        int k = in.nextInt();
        p = in.nextDouble() / 100;
        DP = new double[k + 1][1 << 8][2][210];
        for (int i = 0; i < DP.length; i++)
            for (int j = 0; j < DP[0].length; j++)
                for (int l = 0; l < DP[0][0].length; l++)
                    Arrays.fill(DP[i][j][l], -1);
        int mask = x & screen;
        int ninth = (x & (1 << 8)) == 0 ? 0 : 1;
        int cnt = 0;
        x >>= 8;
        while ((x & 1) == ninth && x > 0) {
            cnt++;
            x >>= 1;
        }
        System.out.println(get(k, mask, ninth, cnt));
    }
}