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

public class Main {
	static InputReader in = new InputReader(System.in);
	static long powers[] = new long[22];
	public static void main(String args[]) {
		int n = in.readInt();
		String s=in.readString();
		long dp[][]=new long[n][1<<20];
		for(int i=0;i<n;i++) {
			int b=0;
			for(int j=i;j>=0;j--) {
				b+=(s.charAt(j)-'0')<<(i-j);
				if(b>20) break;
				if(b>0)
					dp[i][1<<(b-1)]++;
			}
		}
		for(int i=0;i<n;i++) {
			int b=0;
			for(int j=i;j>=0;j--) {
				b+=(s.charAt(j)-'0')<<(i-j);
				if(b>20) break;
				if(b==0) continue;
				for(int k=0;k<1<<20;k++) {
					if(j==0);
					else {
						int o=1<<(b-1);
						dp[i][k|o]+=dp[j-1][k];
						if(dp[i][k|o]>=1000000007)
							dp[i][k|o]-=1000000007;
					}
				}
			}
		}
		long ans=0;
		for(int i=0;i<n;i++) {
			for(int k=0;k<1<<20;k++) {
				if(((k+1)&k)==0) {
					ans+=dp[i][k];
					if(ans>=1000000007)
						ans-=1000000007;

				}
			}
		}
		System.out.println(ans);
	}
}
	/*
class dir{
	boolean l,r,u,d;
}
class Node extends ArrayList<Node>{

	private static final long serialVersionUID = 1L;
	double x,y;
	int i;
	boolean visited=false;
	Node(int x,int y,int i){
		this.x = x;
		this.y = y;
		this.i=i;
	}
	void reset(){
		visited = false;
	}
	boolean dfs(dir d,double mid,double w,double h,double [][]dists,double cmpr){
		visited = true;
		if(x+mid>=w)
			d.r=true;
		if(x-mid<=0.0)
			d.l=true;
		if(y+mid>=h)
			d.u=true;
		if(y-mid<=0.0)
			d.d=true;
		if((d.l && d.d) || (d.u && d.r)
				|| (d.l && d.r) || (d.u && d.d)) {
			return true;
		}
		for(Node n : this) {
			if(!n.visited) {
				boolean fl=false;
				if(dists[i][n.i]<=cmpr)
					fl|=n.dfs(d,mid,w,h,dists,cmpr);
				if(fl) return fl;
			}
		}
		return false;
	}
	double dist(Node n1,Node n2) {
		return sq(n1.x-n2.x)+sq(n1.y-n2.y);
	}
	double sq(double a) {
		return a*a;
	}
}
class ChristmasBinaryTree{
    public int count(long d, int[] left, int[] right) {
    	int n = left.length;
    	int dp[][][]=new int[120][120][64];
    	for(int i=0;i<n;i++) {
    		dp[i][left[i]][0]=1;
    		dp[i][right[i]][0]=1;
    	}
    	while(d>0) {
    		long k=0;
    		for(;1<<k<=d;k++) {
    			for(int i=0;i<n;i++) {
    				for(int j=0;j<n;j++) {
    					for(int l=0;l<n;l++) {
    						dp[i][l][(int)k+1]+=
    								dp[i][j][(int)k]*dp[j][l][(int)k];

    					}
    				}
    			}
    		}
        	int ndp[][][]=new int[120][120][64];
    		for(int i=0;i<n;i++) {
    			for(int j=0;j<n;j++) {
    				ndp[i][j][0]=dp[i][j][(int)k];
    			}
    		}
    		dp=ndp;
    		d-=1<<(k-1);
    	}
    	int cn=0;
    	for(int i=0;i<n;i++) {
    		for(int j=0;j<n;j++) {
    			cn+=dp[i][j][0]*dp[i][j][0];
    		}
    	}
    	return cn;
    }
}
/*
public class Main {
	private static InputReader in = new InputReader(System.in);
	public static void main(String args[]) {
		StringBuilder s = new StringBuilder();
		int t = in.readInt();
		while(t>0) {

			t--;
		}
		System.out.println(s);
	}

	/*public static int solve(String s, int i,int j,
    		int dp[][],boolean visited[][]) {
    	if(i>j) return 0;
    	if(i==j) return dp[i][j]=1;
    	if(visited[i][j]) return dp[i][j];
    	visited[i][j]=true;
    	solve(s,i+1,j,dp,visited);
    	solve(s,i,j-1,dp,visited);
    	if(s.charAt(i)==s.charAt(j)) {
    		if(i+1==j)
    			return dp[i][j]=2;
    		else {
    			return dp[i][j]=dp[i+1][j]+dp[i][j-1]-dp[i+1][j-1]+1;
    		}
    	}else {
    		if(i+1==j) return dp[i][j]=1;
    		return dp[i][j]=dp[i+1][j]+dp[i][j-1]-dp[i+1][j-1];
    	}
    }*/
	/*
    public static void main(String args[]) {
    	int t = in.nextInt();
    	while(t>0) {
    		int m = in.nextInt(), n = in.nextInt();
    		long p = in.nextLong();
    		long dp[][][]=new long[11][300][300];

    		for(int i=1;i<=m;i++)
    			dp[1][i][i]=1;
    		for(int i=1;i<n;i++) {
    			for(int j=1;j<m;j++) {
    				for(int k=1;k<=j;k++) {
    					for(int l=k;l>=1;l--) {
    						if(j+l<=m)
    							dp[i+1][j+l][l]+=dp[i][j][k];
    					}
    				}
    			}
    		}
    		System.out.println(dp[n][m-1][2]);
    		for(int i=n;i>0;i--) {
    			for(int j=1;j<=m;j++) {
    				if(dp[i][m-j][j]>=p) {
    					//System.out.print(j+" ");
    					m-=j;
    					break;
    				}else {
    					p-=dp[i][m-j][j];
    					System.out.print(p+" ");
    				}
    			}
    		}
    		System.out.println();
    		t--;
    	}

    }*/

class sh implements Comparable<sh>{
	int h,w,i;
	sh(int a,int b,int c){
		w=a;
		h=b;
		i=c;
	}
	@Override
	public int compareTo(sh o) {
		if(w==o.w) return h-o.h;
		return w-o.w;
	}

}

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 byte 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 String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

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

class IOUtils {

	public static int[] readIntArray(InputReader in, int size) {
		int[] array = new int[size];
		for (int i = 0; i < size; i++)
			array[i] = in.readInt();
		return array;
	}
}


import com.sun.deploy.util.ArrayUtil;

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

public class Main {
    static int  n;
    static int m;
    static int[]a;
    static int start;
    static int end;
    static int ans;
    public static void main(String[] args) throws Exception
    {
        Scanner in = new Scanner(System.in);
        OutputWriter out = new OutputWriter(System.out);
         n  = in.nextInt();
        a = new int[n];
         m = in.nextInt();
        for (int i =0;i<n;i++)
            a[i]=in.nextInt();
       Arrays.sort(a);
      reverse(a);
       ans=-1;
       binarySearch();
       out.printLine(ans);
        out.flush();
    }
    static void reverse(int[]array)
    {
        for(int i=0; i<array.length/2; i++){ int temp = array[i]; array[i] = array[array.length -i -1]; array[array.length -i -1] = temp; }

    }
    static void binarySearch()
    {
         start = 1;
         end = n;
        while (end>start)
        {
            int mid = (end+start)/2;
            if (f(mid))
            {
                ans=mid;
                end=mid-1;
            }
            else
                start=mid+1;
        }

    }
    static boolean f(int y)
    {
        int ans=0;
        for (int i=0;i<n;i++)
            ans+=Math.max(0,a[i]-i/y);
        if (ans>=m)
            return true;
        return false;
    }
    static void MergeSort(int[] a, int p, int r)
    {
        if (p < r)
        {
            int q = (r + p) / 2;
            MergeSort(a,   p, q);
            MergeSort(a,  q + 1, r);
            Merge(a,  p, q, r);
        }
    }
    static void Merge(int[] a,int p, int q, int r)
    {
        int n1 = q - p + 1;
        int n2 = r - q;
        int[] R = new int[n1 + 1];
        int[] L = new int[n2 + 1];

        for (int i = 0; i < n1; i++)
        {
            R[i] = a[p + i];

        }
        R[n1] = Integer.MAX_VALUE;
        for (int i = 0; i < n2; i++)
        {
            L[i] = a[q + i + 1];

        }
        L[n2] =Integer.MAX_VALUE;
        int n = a.length;
        int j = 0;
        int k = 0;
        for (int i = p; i <= r; i++)
        {
            if (L[j] < R[k])
            {
                a[i] = L[j];

                j++;
            }
            else
            {
                a[i] = R[k];

                k++;
            }

        }
    }
}
class Graph {

    int n;
    ArrayList<Integer>[] adjList;

    public Graph(int n) {
        this.n = n;
        adjList = new ArrayList[n];
        for (int i = 0; i < n; i++)
            adjList[i] = new ArrayList<>();
    }

}
class pair  implements Comparable
{

    int key;
    int value;
    int id;
    public pair(Object key, Object value,Object id) {

        this.key = (int)key;
        this.value=(int)value;
        this.id=(int)id;
    }

    @Override
    public int compareTo(Object o) {
        pair temp =(pair)o;
        if (key!=temp.key)
            return  key-temp.key;
        else return id-temp.id;
    }
}
class Scanner {

    StringTokenizer st;
    BufferedReader br;

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

    public Scanner (FileReader f) {
        br = new BufferedReader(f);
    }

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

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

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

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

    public double nextDouble() throws IOException {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if (x.charAt(0) == '-') {
            neg = true;
            start++;
        }
        for (int i = start; i < x.length(); i++)
            if (x.charAt(i) == '.') {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            } else {
                sb.append(x.charAt(i));
                if (dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg ? -1 : 1);
    }

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

    public boolean nextEmpty() throws IOException {
        String s = nextLine();
        st = new StringTokenizer(s);
        return s.isEmpty();
    }
}
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();
    }

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

}


import java.util.ArrayList;
import java.util.Scanner;

public class DoubleCola {

    public static void main(String[] args) {
           ArrayList<String> names = new ArrayList<String>();
           Scanner in = new Scanner(System.in);
           int n = in.nextInt();
           String s = "Sheldon";
           String l = "Leonard";
           String p= "Penny";
           String r ="Rajesh";
           String h = "Howard";
           names.add(s);
           names.add(l);
           names.add(p);
           names.add(r);
           names.add(h);
           for(int i=0;i<n;i++){
               names.add(names.get(i));
               names.add(names.get(i));
           }

           System.out.print(names.get(n-1));

    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

/**
 * @author Don Li
 */
public class Pollywog {

    long INF = (long) 2e18;

    void solve() {
        int x = in.nextInt(), k = in.nextInt(), n = in.nextInt(), q = in.nextInt();
        int[] c = new int[k + 1];
        for (int i = 1; i <= k; i++) c[i] = in.nextInt();

        int[][] stones = new int[q + 1][2];
        for (int i = 0; i < q; i++) {
            int p = in.nextInt() - 1, w = in.nextInt();
            stones[i][0] = p;
            stones[i][1] = w;
        }
        stones[q][0] = n; stones[q][1] = 0;
        Arrays.sort(stones, Comparator.comparingInt(a -> a[0]));

        int id = 0;
        int[] state_to_id = new int[1 << k];
        int[] id_to_state = new int[1 << k];
        for (int i = 0; i < 1 << k; i++) {
            if (Integer.bitCount(i) == x) {
                id_to_state[id] = i;
                state_to_id[i] = id;
                id++;
            }
        }

        long[][][] basepow = new long[60][id][id];
        fill(basepow, INF);
        for (int i = 0; i < id; i++) {
            int state = id_to_state[i];
            if ((state & 1 << (k - 1)) == 0) {
                basepow[0][i][state_to_id[state << 1]] = 0;
                continue;
            }
            for (int j = 1; j <= k; j++) {
                int nstate = state ^ 1 << (k - 1);
                nstate <<= 1;
                if ((nstate & 1 << (k - j)) > 0) continue; // skip when this position is occupied
                basepow[0][i][state_to_id[nstate | 1 << (k - j)]] = c[j];
            }
        }
        for (int level = 1; level < basepow.length; level++) {
            basepow[level] = mult(basepow[level - 1], basepow[level - 1]);
        }

        long[][] cost = new long[id][id];
        fill(cost, INF);
        int start = (1 << k) - (1 << (k - x));
        cost[state_to_id[start]][state_to_id[start]] = 0;

        int cpos = 0, sidx = 0;
        while (cpos < n - x) {
            while (cpos > stones[sidx][0]) sidx++;

            if (cpos + k >= stones[sidx][0]) {
                long[][] base = new long[id][id];
                fill(base, INF);
                for (int i = 0; i < id; i++) {
                    int state = id_to_state[i];
                    if ((state & 1 << (k - 1)) == 0) {
                        base[i][state_to_id[state << 1]] = 0;
                        continue;
                    }
                    for (int j = 1; j <= k; j++) {
                        int nstate = state ^ 1 << (k - 1);
                        nstate <<= 1;
                        if ((nstate & 1 << (k - j)) > 0) continue;
                        int tcost = c[j];
                        for (int a = 0; a < k; a++) {
                            if (sidx + a < stones.length && cpos + j == stones[sidx + a][0]) {
                                tcost += stones[sidx + a][1];
                            }
                        }
                        base[i][state_to_id[nstate | 1 << (k - j)]] = tcost;
                    }
                }
                cost = mult(cost, base);
                cpos++;
            } else {
                long dist = (stones[sidx][0] - k) - cpos;
                for (int i = 0; i < 60; i++) {
                    if ((dist & (1L << i)) > 0) {
                        cost = mult(cost, basepow[i]);
                    }
                }
                cpos += dist;
            }
        }

        out.println(cost[state_to_id[start]][state_to_id[start]]);
    }

    long[][] mult(long[][] a, long[][] b) {
        int n = a.length;
        long[][] c = new long[n][n];
        fill(c, INF);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                for (int k = 0; k < n; k++) {
                    c[i][j] = Math.min(c[i][j], a[i][k] + b[k][j]);
                }
            }
        }
        return c;
    }

    void fill(long[][][] a, long val) {
        for (long[][] x : a) fill(x, val);
    }

    void fill(long[][] a, long val) {
        for (long[] x : a) Arrays.fill(x, val);
    }

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new Pollywog().solve();
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

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

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

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

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

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


public class ACMICPC {

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

		Scanner in= new Scanner(System.in);

		int a[]=new int[6];
		int sum=0;
		for(int i=0;i<6;i++) {
			a[i]=in.nextInt();
			sum+=a[i];
		}

		if(res(a,sum)==true) {
			System.out.println("yes");
		}
		else {
			System.out.println("NO");
		}

	}

	static boolean res(int a[], int sum) {
		boolean f= false;
		for(int i=0;i<4;i++) {
			for(int j=i+1;j<5;j++) {
				for(int k=j+1;k<6;k++) {
					if(a[i]+a[j]+a[k]==sum/2) {
						return true;
					}
				}
			}
		}

		return false;
	}

}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package codeforce;

import java.util.Scanner;

/**
 *
 * @author a
 */
public class Number7 {
    public static void main(String[] args) {
        Scanner l=new Scanner (System.in);
        int B=0;
        for (int i = 0; i < 8; i++) {
            String ch=l.next();
            for (int j = 0; j < 8; j++) {
                if(ch.charAt(j)=='B')
                    B++;

            }
        }
        if(B%8==0)
            System.out.println(B/8);
        else
            System.out.println((B/8)+1);
    }
}


import java.io.Scanner;
public class TestClass{
    public static void main(String args[]){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        System.out.print(n%2);
    }
}


public class ninefivetwoA {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        if(a<10 || a>999){
            System.out.println("Incorrect");

        }else if (a % 2 == 0){
            System.out.println("0");
        }else {
            System.out.println("1");

        }
    }
}


import java.io.*;
import java.lang.*;
import java.util.*;
import java.text.*;

public class Main {

	public static void main(String[] args) throws IOException {

		//BufferedReader cin = new BufferedReader(new FileReader("test.txt"));
		 BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));

		String line;
		StringTokenizer st;

		line = cin.readLine();
		st = new StringTokenizer(line);

		int n = Integer.parseInt(st.nextToken());
		//int a = Integer.parseInt(st.nextToken());
		//int b = Integer.parseInt(st.nextToken());

		//ArrayList<Integer> list = new ArrayList<Integer>(n);
		//int[] list = new int[n];
		int[][] mat=new int[n][4];//x1,y1,x2,y2

		int max=0;
		int t;
		for(int i=0;i<n;i++){
			line = cin.readLine();
			st = new StringTokenizer(line);
			for(int j=0;j<4;j++){
				t=Integer.parseInt(st.nextToken());
				if(t>max)max=t;
				mat[i][j]=t;
			}
		}

		int[][] res = new int[max][max];
		for(int[]row:res)
			Arrays.fill(row, 0);

		for(int i=0;i<n;i++){//loop over n rectangles
			for(int p=mat[i][0];p<mat[i][2];p++)
				for(int q=mat[i][1];q<mat[i][3];q++){
					res[p][q]=1;
				}
		}
		String ans = "YES";
		for(int p=0;p<max;p++)
			for(int q=0;q<max;q++){
				if(res[p][q]!=1){
					ans="NO";
					break;
				}
			}

		System.out.println(ans);

		cin.close();
	}

	static class Pair {

		int ind;
		int val;

		Pair(int ind, int val){
			this.ind=ind;
			this.val=val;
		}
	}

	static class Comp implements Comparator<Pair>{

		public int compare(Pair a, Pair b) {
			// TODO Auto-generated method stub
			return (a.val-b.val);
		}

	}

}


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

/**
 * @author kperikov
 */
public class C implements Runnable {

    PrintWriter out;
    BufferedReader br;
    StringTokenizer st;

    public static void main(String[] args) throws IOException {
        new Thread(new C()).start();
    }

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

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

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

    public void run() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new BufferedOutputStream(System.out));
            solve();
            out.close();
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    }

    public void solve() throws IOException {
        int r = nextInt();
        int h = nextInt();
        int ans = 0;
        double left;
        double d1 = r;
        double d2 = (2.0d * r) / (Math.sqrt(2.0d)) + r;
        if (Math.floor(h / d1) * 2 > Math.floor(h / d2) * 5) {
            ans += Math.floor(h / d1) * 2;
            left = h - d1 * Math.floor(h / d1);
        } else {
            ans += Math.floor(h / d2) * 5;
            left = h - d2 * Math.floor(h / d2);
        }
        if (Math.abs(left) <= 1e-7) {
            ans++;
        } else if (left >= r / 2.0d && left <= r / Math.sqrt(2.0d) + r) {
            ans += 2;
        } else if (left >= r / Math.sqrt(2.0d) + r) {
            ans += 3;
        }
        out.println(ans);
    }
}


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

public class E {

    private static final long modulo = 1000000007;

    private static void solve() {
        int a = in.nextInt();
        int b = in.nextInt();

        int upperBoundSquareRoot = (int) Math.sqrt(b);
        boolean[] isComposite = new boolean[b + 1];
        for (int m = 2; m <= upperBoundSquareRoot; m++) {
            if (!isComposite[m]) {
                for (int k = m * m; k <= b; k += m)
                    isComposite[k] = true;
            }
        }

        int res = 0;

        if (2 >= a && b >= 2) res++;

        for (int i = 5; i <= b; i += 4) {
            if (i >= a && !isComposite[i]) {
                res++;
            }
        }

        out.println(res);
    }

    private static long inverse(long a) {
        long result = 1;
        int n = (int) modulo - 2;
        while (n != 0) {
            if ((n & 1) == 1)
                result = (result * a) % modulo;
            a = (a * a) % modulo;
            n >>= 1;
        }
        return result;
    }

    private static long pow(long a, long n) {
        if (n == 0) return 1;
        if (n % 2 == 0) {
            long ans = pow(a, n / 2);
            return ans * ans;
        } else {
            return a * pow(a, n - 1);
        }
    }

    public static void main(String[] args) {
        solve();
        closeStreams();
    }

    private static void closeStreams() {
        in.close();
        out.close();
    }

    private static final FastScanner in = new FastScanner();
    private static final PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

    public static class FastScanner {

        private BufferedReader br;
        private StringTokenizer st;

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

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

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

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

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

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

        void close() {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}


import java.math.*;
import java.io.*;
import java.util.*;
public class C586E{
   public static long[] cAr, div;
   public static int N,M,K;
   public static int[] numCycle;
   public static Map<Integer,Set<Integer>> map;
   public static long MOD = 1000000007;
   public static void main(String[] args) throws IOException{
      InputReader in=new InputReader(new InputStreamReader(System.in));
      PrintWriter out=new PrintWriter(new BufferedOutputStream(System.out));
      long[] ar=in.nextLongAr();
      long A=ar[0]; long B=ar[1];
      if(gcd(A,B)!=1) System.out.println("Impossible");
      else{
         while(A+B>1){
            if((A-1)/B > 0){ System.out.print(((A-1)/B)+"A");
            A%=B;}
            if((B-1)/A > 0){ System.out.print(((B-1)/A)+"B");
            B%=A;}
         }
      }
   }

   public static long gcd(long x,long y){
      BigInteger a = BigInteger.valueOf(x);
      BigInteger b = BigInteger.valueOf(y);
      BigInteger gcd = a.gcd(b);
      return gcd.longValue();
   }

   public static void setUpChoose(int t){
      cAr=new long[t+1];
      div=new long[t+1];
      cAr[0]=1;
      div[0]=1;

      for(int x=1;x<=t;x++){
         cAr[x]=(x*cAr[x-1])%(MOD);
         div[x]=pow(cAr[x],MOD-2);}
   }

   public static long choose(int x,int y){
      long a=cAr[x+y];
      long b=div[x];
      long c=div[y];
      a=(a*b)%MOD;
      a=(a*c)%MOD;
      return a;
   }

   public static long pow(long a,long b){
      if(b==1)
         return a;
      long c=b/2;
      long temp=pow(a,c)%MOD;
      temp=(temp*temp)%MOD;
      if(b%2==1) temp=temp*a;
      return temp%MOD;
   }
}

class InputReader{
   private BufferedReader br;
   public InputReader(InputStreamReader in){
      br=new BufferedReader(in);
   }
   public int nextInt(){
      try{
         return Integer.parseInt(br.readLine());}
      catch(IOException e){throw new InputMismatchException();}
   }
   public int[] nextIntAr(){
      try{
         String[] s=br.readLine().split(" ");
         int[] ret=new int[s.length];
         for(int x=0;x<s.length;x++)
            ret[x]=Integer.parseInt(s[x]);
         return ret;}

      catch(IOException e){throw new InputMismatchException();}
   }

   public long nextLong(){
      try{
         return Long.parseLong(br.readLine());}
      catch(IOException e){throw new InputMismatchException();}
   }
   public long[] nextLongAr(){
      try{
         String[] s=br.readLine().split(" ");
         long[] ret=new long[s.length];
         for(int x=0;x<s.length;x++)
            ret[x]=Long.parseLong(s[x]);
         return ret;}

      catch(IOException e){throw new InputMismatchException();}
   }

   public String[] nextStringAr(){
      try{
         return br.readLine().split(" ");}

      catch(IOException e){throw new InputMismatchException();}
   }

   public String nextString(){
      try{
         return br.readLine();}

      catch(IOException e){throw new InputMismatchException();}
   }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeSet;

public final class CF_325_AliceBob {

	void log(int[] X){
		int L=X.length;
		for (int i=0;i<L;i++){
			logWln(X[i]+" ");
		}
		log("");
	}

	void log(long[] X){
		int L=X.length;
		for (int i=0;i<L;i++){
			logWln(X[i]+" ");
		}
		log("");
	}
	void log(Object[] X){
		int L=X.length;
		for (int i=0;i<L;i++){
			logWln(X[i]+" ");
		}
		log("");
	}

	void log(Object o){
		logWln(o+"\n");
	}

	void logWln(Object o){
		System.out.print(o);
		//outputWln(o);

	}
	void info(Object o){
		System.out.println(o);
		//output(o);
	}

	void output(Object o){

		outputWln(""+o+"\n");

	}

	void outputWln(Object o){
		// System.out.print(o);

		try {
			out.write(""+ o);
		} catch (Exception e) {

		}
	}

	class Composite implements Comparable<Composite>{
		int x;
		int y;

		public int compareTo(Composite X){
			if (x!=X.x)
				return x-X.x;
			return y-X.y;
		}

		public Composite(int x, int y) {
			this.x = x;
			this.y = y;
		}

	}

	long pgcd(long a,long b){
		if (b>a)
			return pgcd(b,a);
		while (b>0){
			long c=b;
			b=a%b;
			a=c;
		}
		return a;
	}

	String solve(long x,long y){
		long p=pgcd(x,y);
		if (p!=1)
			return "Impossible";

		String res="";
		int cnt=0;
		char cur='Z';
		while (x>0 && y>0 && x!=y){

			if (y>x){

				y-=x;
				if (cur!='B'){
					if (cur=='A')
						res+=cnt+""+'A';
					cnt=1;
					cur='B';
				} else {
					cnt++;
				}

			} else {
				x-=y;
				if (cur!='A'){
					if (cur=='B')
						res+=cnt+""+'B';
					cnt=1;
					cur='A';
				} else {
					cnt++;
				}

			}

		}
		res+=cnt+""+cur;
		return res;
	}

	void simulate(){
		TreeSet<Composite> list=new TreeSet<Composite>();
		int LEN=5;
		int m=1<<LEN;
		for (int i=0;i<m;i++){
			int u=1,v=0,x=0,y=1;
			String st="";
			for (int e=0;e<LEN;e++){
				int mask=(1<<e)&i;
				if (mask==0){
					u+=x;
					v+=y;
					st+="A";
				} else {
					x+=u;
					y+=v;
					st+="B";
				}
				log((x+u)+" "+(v+y)+" "+st+" ///"+solve(x+u,v+y));
				list.add(new Composite(x+u,v+y));
			}
		}
		/*
		for (Composite X:list){
			log(X.x+" "+X.y);
		}
		 */
	}

	BufferedWriter out;

	void process() throws Exception {

		out = new BufferedWriter(new OutputStreamWriter(System.out));
		InputReader reader=new InputReader(System.in);

		long u=reader.readLong();

		long v=reader.readLong();

		output(solve(u,v));

		//simulate();
		/*
		long a=1,b=0;
		long x=0;y=1;
		boolean goon=true;
		while (goon){
			String s=reader.readString();
			if (s.charAt(0)=='A'){
				x+=a;
				y+=b;
			} else {
				a+=x;
				b+=y;
			}
			log("Alice:"+a+" "+b+" // Bob:"+x+" "+y+" // total :"+(a+x)+" "+(b+y));
		}
		 */
		try {
			out.close();
		}
		catch (Exception e){}

	}

	public static void main(String[] args) throws Exception {
		CF_325_AliceBob J=new CF_325_AliceBob();

		J.process();

	}

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

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

		private int read() throws IOException {
			if (curChar >= numChars) {
				curChar = 0;
				numChars = stream.read(buf);
				if (numChars <= 0) {
					return -1;
				}
			}
			return buf[curChar++];
		}

		public final String readString() throws IOException {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res=new StringBuilder();
			do {
				res.append((char)c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public final int readInt() throws IOException {
			int c = read();
			boolean neg=false;
			while (isSpaceChar(c)) {
				c = read();
			}
			char d=(char)c;
			//log("d:"+d);
			if (d=='-') {
				neg=true;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			//log("res:"+res);
			if (neg)
				return -res;
			return res;

		}

		public final long readLong() throws IOException {
			int c = read();
			boolean neg=false;
			while (isSpaceChar(c)) {
				c = read();
			}
			char d=(char)c;
			//log("d:"+d);
			if (d=='-') {
				neg=true;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			//log("res:"+res);
			if (neg)
				return -res;
			return res;

		}

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

}


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

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);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {

        private static final int MIN = -50000;
        private static final int MAX = 50000;

        void solve(InputReader in, PrintWriter out) {
            int n = in.nextInt(), m = in.nextInt();
            int ans = 0;
            for (int a = MIN; a <= MAX; a++) {
                for (int b = MIN; b <= MAX; b++) {
                    if (a * a + b == m && a + b * b == n)
                        ans++;
                }
            }
            out.print(ans);
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

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

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

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

    }
}


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

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

		String sss=c.readLine();
		StringTokenizer st = new StringTokenizer(sss);

		int n=Integer.parseInt(st.nextToken());
		int q=Integer.parseInt(st.nextToken());

		String lang=c.readLine();

		for(int t=0;t<q;t++)
			{
			 sss=c.readLine();
			 st = new StringTokenizer(sss);

			 int[] p=new int[10];

			int l=Integer.parseInt(st.nextToken());
			int r=Integer.parseInt(st.nextToken());

			String lan=lang.substring(l-1,r);

			lan="@"+lan+"@";

			int dp=1;
			int cp=1;

			while(lan.charAt(cp)!='@')
				{
			//	System.out.println("whhiel");
				if(lan.charAt(cp)!='<' && lan.charAt(cp)!='>')
					{
						if(lan.charAt(cp)=='0')
							{
							p[0]++;
							cp+=dp;
							lan=removeCharAt(lan, cp-dp);
							//System.out.println("delete");
							}
						else
							{
							//System.out.println((int)(lan.charAt(cp)-'0')+" "+lan.charAt(cp));
							p[(int)(lan.charAt(cp)-'0')]++;
							lan=replaceCharAt(lan, cp,(char)(lan.charAt(cp)-1));
							cp+=dp;
							}

					}

				else if(lan.charAt(cp)=='<')
					{
					if(lan.charAt(cp-dp)=='<' || lan.charAt(cp-dp)=='>')
						{
						lan=removeCharAt(lan, (cp-dp));
						cp=(cp-dp);
						}
					else
						{
						dp=-1;
						cp+=dp;
						}
					}
				else if(lan.charAt(cp)=='>')
					{
					if(lan.charAt(cp-dp)=='<' || lan.charAt(cp-dp)=='>')
						{
						lan=removeCharAt(lan, (cp-dp));
						cp=(cp-dp);
						}
					else
						{
						dp=1;
						cp+=dp;
						}
					}
				}

			for(int i=0;i<10;i++)
				{
				System.out.print(p[i]+" ");
				}
			System.out.println("");
			}
		}

	public static String replaceCharAt(String s, int pos, char c)
		{
		StringBuffer buf = new StringBuffer( s );
		buf.setCharAt( pos, c );
		return buf.toString( );
		}

	public static String removeCharAt(String s, int pos)
		{
		StringBuffer buf = new StringBuffer( s.length() - 1 );
		buf.append( s.substring(0,pos) ).append( s.substring(pos+1) );
		return buf.toString();
		}
	}

//must declare new classes here


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

public class RoutineProblem {
    public static int gcd(int n, int m){
        int x = n;
        int y = m;
        while(x!=y)
            if(x>y)
                x = x-y;
            else
                y = y-x;
        return x;
    }
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(bf.readLine());

        int a = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        int c = Integer.parseInt(st.nextToken());
        int d = Integer.parseInt(st.nextToken());

        int p = Math.max(a*d, b*c) - Math.min(a*d, b*c);
        int q = Math.max(a*d, b*c);

        int x = gcd(p,q);
        System.out.println(p/x + "/" + q/x);
    }
}


import java.util.ArrayList;
import java.util.Scanner;
import java.lang.Integer;

public class FlowGraph {
	int[][] graph;
	int[][] flow;
	int[] path;
	int[][] capacity;
	int size;
	int maxFlow = 0;

	public FlowGraph(int[][] capacity){
		//Scanner scanner = new Scanner(System.in);
		size = capacity.length;
		flow = new int[size][size];
		graph= new int[size][size];
		this.capacity = capacity;

	}

	int edmundKarp(){
		path = new int[size];
		for(int i = 0; i < size;  i++){
			path[i] = -1;
		}
		while(hasPath()){
			int cMin = 200000;
			int v = size - 1;
			while(v != 0){
				int u = path[v];
				if(capacity[u][v] - flow[u][v] < cMin ) cMin = capacity[u][v] - flow[u][v];
				v = u;

			}
			v = size - 1;
			while(v != 0){
				int u = path[v];

				flow[u][v] += cMin;
				flow[v][u] -= cMin;
				v = u;

			}

		}
		int maxFlow = 0;
		for(int i = 0; i < size; ++i){
			maxFlow += flow[i][size - 1];

		}
		return maxFlow;

	}
	boolean hasPath(){
		boolean[] visited = new boolean[size];
		ArrayList<Integer> o = new ArrayList<>();
		o.add(0);
		visited[0] = true;
		int v = 0;
		while(!o.isEmpty() && v != size - 1){
			int u = o.remove(o.size()-1);
			for(int i = 0; i < size;++i){
				if(capacity[u][i] - flow[u][i] > 0 && !visited[i]){
					path[i] = u;
					visited[i] = true;
					o.add(0,i);
					v = i;
					if(v == size - 1) break;
				}

			}

		}
		if(o.isEmpty()) return false;
		return true;

	}

	int findMaxFlow(){
		for(int i = 1; i < size; ++i){
			maxFlow += flow[i][size - 1];
		}
		return maxFlow;

	}

}

public class Labs {

	static void paths(int[][]graph,int n){
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < n; ++j){
				if(graph[i][j] == 0 && i != j) graph[i][j] = 1000;

			}

		}

		for(int k = 0; k < n; ++k ){
			for(int i = 0; i < n; ++i){
				for(int j = 0; j < n; ++j){
					if(graph[i][k] + graph[k][j] < graph[i][j]) graph[i][j] = graph[i][k]+graph[k][j];
				}
			}
		}

	}

	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int t = scanner.nextInt();
		int[][] lab = new int[n*n][n*n];
		int[][] flow = new int[n*n+2][n*n+2];
		String[] map = new String[n];
		int z = -1;
		scanner.nextLine();
		ArrayList<Integer> caps= new ArrayList<>();
		for(int i = 0; i < n; ++i){
			map[i] = scanner.nextLine();

		}

		for(int i = 0; i <n; ++i){
			for(int j = 0; j < n ; ++j){
				if(map[i].charAt(j)  == 'Z' || map[i].charAt(j) <= '9' && map[i].charAt(j) >= 0){
					if(map[i].charAt(j) != 'Z') flow[0][i*n+j+1] =(int) map[i].charAt(j) - 48;
						if(map[i].charAt(j)  == 'Z' ) z = i*n + j;

						if(i > 0 && map[i-1].charAt(j) <= '9' && map[i-1].charAt(j) >= '0'){
							if(map[i].charAt(j)  != 'Z') lab[(i-1)*n+j][i*n+j] = 1;
							lab[i*n+j][(i-1)*n+j] = 1;
						}
						if(i < n - 1 && map[i+1].charAt(j) <= '9' && map[i+1].charAt(j) >= '0'){
							lab[i*n+j][(i+1)*n+j] = 1;
							if(map[i].charAt(j)  != 'Z') lab[(i+1)*n+j][i*n+j] = 1;
						}
						if(j > 0 && map[i].charAt(j-1) <= '9' && map[i].charAt(j-1) >= '0'){
							if(map[i].charAt(j)  != 'Z') lab[(i)*n+j - 1][i*n+j] = 1;
							 lab[i*n+j][(i)*n+j-1] = 1;
						}
						if(j < n-1 && map[i].charAt(j+1) <= '9' && map[i].charAt(j+1) >= '0'){
							if(map[i].charAt(j)  != 'Z') lab[(i)*n+j+1][i*n+j] = 1;
							lab[i*n+j][(i)*n+j+1] = 1;
						}
				}

			}

		}
		paths(lab,n*n);
		scanner.nextLine();
		for(int i =0; i < n; ++i){
			String s = scanner.nextLine();
			for(int j = 0; j < n ; ++j){
				if(s.charAt(j) <= '9' && s.charAt(j) >= '1'){
					caps.add(i*n+j);
					flow[i*n+j+1][n*n+1] = (int) s.charAt(j) - 48;

				}
			}
		}
		for(int i = 0; i < n*n; ++i){
			if(i!= z){
			for(int j = 0; j < caps.size(); ++j){
				int c = caps.get(j);
				boolean neigh = false;
				for(int k = 0; k < n*n; ++k){
					if(lab[c][k] == 1){
						if(lab[i][k] < lab[z][k] && lab[i][k] <= t) neigh = true;
					}
				}
				if(lab[i][c] <= t && (lab[i][c] < lab[z][c] || lab[z][c] == 0 || neigh)){
					flow[i+1][c+1] = 10000;
				}

			}
			}

		}
		FlowGraph g = new FlowGraph(flow);
		g.edmundKarp();
		System.out.println(g.findMaxFlow());

	}

}


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

public class Main {

    StreamTokenizer in;
    PrintWriter out;

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

    public void run() throws Exception {
        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(new OutputStreamWriter(System.out));
        Locale.setDefault(Locale.US);
        solve();
        out.flush();
    }

    int nextInt() throws Exception {
        in.nextToken();
        return (int) in.nval;
    }

    String next() throws Exception {
        in.nextToken();
        return in.sval;
    }

    boolean used[] = new boolean [6];
    int a[][] = new int [6][6];
    boolean cycle=false;
    int count=0;

    void dfs(int i)
    {
        used[i]=true;
        for (int j=1;j<6;j++)
        {
            if (a[i][j]==1&&used[j])
                cycle=true;
            if (a[i][j]==1&&!used[j])
            {
                a[i][j]=0;
                a[j][i]=0;
                count++;
                dfs(j);
            }
        }
    }

    public void solve() throws Exception {
        int m=nextInt();
        for (int i=0;i<m;i++)
        {
            int q= nextInt();
            int w= nextInt();
            a[q][w]=1;
            a[w][q]=1;
        }
        dfs(1);
            if (cycle) out.println("FAIL");
            else out.println("WIN");
    }
}


import java.io.*;
import java.util.*;
public class Problem548C
{
   public static void main(String[] args)
   {
      Scanner s = new Scanner(System.in);
      int m=s.nextInt();
      int h1=s.nextInt();
      int a1=s.nextInt();
      int x1=s.nextInt();
      int y1=s.nextInt();
      int h2=s.nextInt();
      int a2=s.nextInt();
      int x2=s.nextInt();
      int y2=s.nextInt();
      int[] arr1=new int[m];
      int[] arr2=new int[m];
      populateArray(arr1,h1,x1,y1,m);
      populateArray(arr2,h2,x2,y2,m);

      int stepsFirst1=-1;
      int stepsSecond1=-1;
      int stepsFirst2=-1;
      int stepsSecond2=-1;
      //xaniar
      int curr11=h1;
      int curr21=arr1[a1];
      //abol
      int curr12=h2;
      int curr22=arr2[a2];
      for(int i=0; i<2*m; i++)
      {
         //xaniar
         if(curr11==a1 && stepsFirst1==-1){
            stepsFirst1=i;
         }
         if(curr21==a1 && stepsSecond1==-1){
            stepsSecond1=i+1;
         }
         //abol
         if(curr12==a2 && stepsFirst2==-1){
            stepsFirst2=i;
         }
         if(curr22==a2 && stepsSecond2==-1){
            stepsSecond2=i+1;
         }
         //xaniar
         curr11=arr1[curr11];
         curr21=arr1[curr21];
         //abol
         curr12=arr2[curr12];
         curr22=arr2[curr22];
      }
      int t=-1;
      int xanX=stepsFirst1;
      int abolX=stepsFirst2;
      int xanM = stepsSecond1;
      int abolM = stepsSecond2;
      if(xanX==-1 || abolX==-1) System.out.println(-1);
      else
      {
         int[] timesXan = new int[m*m];
         int[] timesAbol = new int[m*m];
         for(int i=0; i<m*m; i++)
         {
            timesXan[i]=xanX;
            timesAbol[i]=abolX;
            xanX+=xanM;
            abolX+=abolM;
         }
         int indexXan=0;
         int indexAbol=0;
         for(int i=0; i<m*m; i++)
         {
            if(indexXan>=m || indexXan>=m) break;
            int tX=timesXan[indexXan];
            int tA=timesAbol[indexAbol];
            if(tX==tA){
               t=tX;
               break;
            }
            if(tX<tA)indexXan++;
            if(tX>tA)indexAbol++;
         }
         System.out.println(t);
      }
   }
   public static void populateArray(int[] arr, int h, int x, int y,int m)
   {
      for(int i=0; i<arr.length; i++)
      {
         arr[i]=(i*x+y)%m;
      }
   }
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;

import Task127A.Solution;

public class Task125A {

	public static void main(String... args) throws NumberFormatException,
			IOException {
		Solution.main(System.in, System.out);
	}

	static class Scanner {

		private final BufferedReader br;
		private String[] cache;
		private int cacheIndex;

		Scanner(InputStream is) {
			br = new BufferedReader(new InputStreamReader(is));
			cache = new String[0];
			cacheIndex = 0;
		}

		int nextInt() throws IOException {
			if (cacheIndex >= cache.length) {
				cache = br.readLine().split(" ");
				cacheIndex = 0;
			}
			return Integer.parseInt(cache[cacheIndex++]);
		}

		long nextLong() throws IOException {
			if (cacheIndex >= cache.length) {
				cache = br.readLine().split(" ");
				cacheIndex = 0;
			}
			return Long.parseLong(cache[cacheIndex++]);
		}

		String next() throws IOException {
			if (cacheIndex >= cache.length) {
				cache = br.readLine().split(" ");
				cacheIndex = 0;
			}
			return cache[cacheIndex++];
		}

		void close() throws IOException {
			br.close();
		}

	}

	static class Solution {

		public static void main(InputStream is, OutputStream os)
				throws NumberFormatException, IOException {
			PrintWriter pw = new PrintWriter(os);
			Scanner sc = new Scanner(is);

			int n = (sc.nextInt() + 1) / 3;

			pw.print(n / 12);
			pw.print(" ");
			pw.print(n % 12);
			pw.flush();
			sc.close();
		}
	}

}


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

public class Main{
static BigInteger pow2(BigInteger a, long x, BigInteger modulo)
{
    long b = x; BigInteger c = BigInteger.ONE;
    while (b>0)
    {
        if (b%2==0)
        {
            a = a.multiply(a);
            a = a.mod(modulo);
            b/=2;
        } else
        {
            c = c.multiply(a);
            c = c.mod(modulo);
            b--;
        }
    }
    return c;

}
static int needBit(long x)
{
    int k = 0;
    while (x>0) {k++;x/=2;}
    return k;
}
  public static void main(String[] argv) {
      Scanner sc = new Scanner(System.in);

    long n,k,l,m;

    n = sc.nextLong();
    k = sc.nextLong();
    l = sc.nextLong();
    m = sc.nextLong();
    long kk = k;
    if (l<needBit(kk)) { System.out.println(0); return;}
    int key;
    BigInteger answer = BigInteger.ONE, ger;
    BigInteger Fx = BigInteger.ONE;
    BigInteger Fy = BigInteger.ONE;
    BigInteger TWO = BigInteger.ONE.multiply(new BigInteger("2"));
    BigInteger x = BigInteger.ONE; BigInteger y = BigInteger.ONE;
    //3 3 2 10
    for (int i=1;i<n;i++)
    {
        y = y.add(x);
        x = y.subtract(x);
    }
    BigInteger M = new BigInteger(m+ "");
    BigInteger pn = pow2(TWO, n, M);
    BigInteger gen1 = pow2(TWO, n, M).subtract(y.add(x));
    BigInteger gen0 = y.add(x);
    int one = 0, zero = 0;
    for (long  i=0;i<l;i++)
    {
        if ((k  & (1 << i) )> 0) key = 1; else key = 0;
        if (key == 0)
        {
            zero++;
        } else
        {

            one++;
        }

    }
    answer = answer.multiply(pow2(gen1, one, M));
    answer = answer.multiply(pow2(gen0,zero, M));
    answer = answer.mod(M);
    System.out.println(answer);
}
}


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

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

class TaskD {
    private long ONE;
    public void solve(final int testNumber, final InputReader in, final PrintWriter out) {
        long counter = in.nextLong();
        long target = in.nextLong();
        int bits = in.nextInt();
        int modulo = in.nextInt();
        ONE = 1 % modulo;
        long answer = ONE;
        long total = ONE;
        for (int i = 0; i < counter; ++i) {
            total = (total * 2) % modulo;
        }
        long[] fibs = power(new long[]{ONE, ONE, ONE, 0}, counter + 1, modulo);
        long zero = fibs[0];
        long one = (total + (modulo - zero)) % modulo;
        for (int bit = 0; bit < bits; ++bit) {
            if ((target >>> bit & 1) == 1) {
                target -= (1L << bit);
                answer = (answer * one) % modulo;
            } else {
                answer = (answer * zero) % modulo;
            }
        }
        out.println(target == 0 ? answer : 0);
    }

    private long[] power(long[] base, long power, int modulo) {
        long[] result = new long[]{ONE, 0, 0, ONE};
        while (power > 0) {
            if ((power & 1) == 1) {
                result = multiply(result, base, modulo);
            }
            base = multiply(base, base, modulo);
            power >>>= 1;
        }
        return result;
    }

    private long[] multiply(long[] first, long[] second, int modulo) {
        long[] result = new long[4];
        for (int i = 0; i < 2; ++i) {
            for (int j = 0; j < 2; ++j) {
                for (int k = 0; k < 2; ++k) {
                    result[2 * i + j] = (result[2 * i + j] + first[i * 2 + k] * second[k * 2 + j]) % modulo;
                }
            }
        }
        return result;
    }
}

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

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

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

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

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

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


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main2 {

    static long mod = 1000000007L;

    static int[] primes = {2,      3,      5 ,     7,     11,     13,     17,     19,     23,     29,
            31,     37,     41,     43,     47,     53,     59,     61,     67,     71,
            73 ,    79 ,    83 ,    89,     97,    101,    103,    107,    109,    113,
            127,    131,    137,    139,    149,    151,    157,    163,    167,    173,
            179,    181,    191,    193,    197,    199,    211,    223 ,   227,    229,
            233,    239,    241,    251,    257,    263,    269,    271 ,   277,    281,
            283,    293,    307,    311,    313,    317,    331};

    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        int n = scanner.nextInt();
        int[] a = new int[6];
        for (int i = 0; i < n; i++) {
            a[scanner.nextInt()]++;
        }
        int[] b = new int[6];
        for (int i = 0; i < n; i++) {
            b[scanner.nextInt()]++;
        }

        int sum = 0;
        int toChange = 0;
        for (int i = 1; i <= 5; i++) {
            int r = a[i] - b[i];
            if (a[i] > b[i]) {
                toChange += r;
            }
            if (r % 2 == 1) {
                System.out.println("-1");
                return;
            }
            sum += r;
        }
        if (sum == 0) {
            System.out.println(toChange / 2);
        } else {
            System.out.println("-1");
        }
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

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

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            try {
                return br.readLine();
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException();
            }
        }

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

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

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


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

public class forSolve {

    void solve(PrintWriter out, FastInput in) throws IOException {
        int n  = in.nextInt();
        int[] a = in.readIntArray(n);
        int[] b = in.readIntArray(n);

        int[] gradA = new int[6];
        int[] gradB = new int[6];

        for(int i = 0; i<n; i++){
            gradA[a[i]]++;
            gradB[b[i]]++;
        }

        int ans = 0;

        for(int i = 1; i<6; i++)
            ans+= Math.abs(gradA[i]-gradB[i]);

        if(ans%4==0)
            out.print(ans/4);
        else
            out.print(-1);
    }

    void run() throws IOException {
        try (PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); FastInput in = new FastInput()) {
            solve(out, in);
        }
    }

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

    class FastInput implements AutoCloseable {
        StringTokenizer st;
        BufferedReader br;

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

        int nextInt() throws IOException {
            return Integer.parseInt(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] = nextInt();
            return a;
        }

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

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

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

        public void close() throws IOException {
            br.close();
        }
    }

}


import java.util.Scanner;

public class ProblemC {

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

		int x = in.nextInt();
		int y = in.nextInt();
		int z = in.nextInt();

		int a0 = in.nextInt();
		int a1 = in.nextInt();
		int a2 = in.nextInt();

		int a3 = in.nextInt();
		int a4 = in.nextInt();
		int a5 = in.nextInt();

		int sum = 0;
		//FROM BOTTOM
		if ( ky < 0 ) {
			sum += a0;
		}
		//FROM TOP
		if ( ky > y ) {
			sum += a1;
		}

		//TWO SIDES
		if ( kx < 0 && kz < 0 ) {
			sum += a2+a4;
		}
		//TWO SIDES
		if ( kx < 0 && kz > z ) {
			sum += a3+a4;
		}
		//TWO SIDES
		if ( kx > x && kz > z ) {
			sum += a3+a5;
		}
		//TWO SIDES
		if ( kx > x && kz < 0 ) {
			sum += a2+a5;
		}

		//one SIDE
		if ( (kx >= 0 && kx <= x) && kz < 0 ) {
			sum += a2;
		}
		//one SIDES
		if ( (kx >= 0 && kx <= x) && kz > z ) {
			sum += a3;
		}
		//one SIDES
		if ( kx > x && (kz >= 0 && kz <= z) ) {
			sum += a5;
		}
		//TWO SIDES
		if ( kx > 0 && (kz >= 0 && kz <= z) ) {
			sum += a4;
		}

		System.out.println(sum);

	}

}


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

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

    static class atskb {
        int[][] vis;
        int[][][][] dp;
        int[] lev;
        int max;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            lev = in.nextIntArray(n);
            vis = new int[500][500];
            dp = new int[500][500][n + 1][8];

            max = n;
            solve(150, 150, 0, 0);
            int ct = 0;
            for (int i = 0; i < 300; i++) {
                for (int j = 0; j < 300; j++) {
                    if (vis[j][i] != 0) {
                        ct++;
                    }
                }
            }
            out.print(ct);

        }

        public void solve(int acx, int acy, int level, int direction) {
            if (level == max) {
                return;
            }
            if (dp[acx][acy][level][direction] != 0) {
                return;
            }
            int x = acx;
            int y = acy;
            if (direction == 0) {
                for (int i = 0; i < lev[level]; i++) {
                    y++;
                    vis[x][y] = 1;

                }
            }
            if (direction == 1) {
                for (int i = 0; i < lev[level]; i++) {

                    y++;
                    x--;
                    vis[x][y] = 1;
                }
            }
            if (direction == 2) {
                for (int i = 0; i < lev[level]; i++) {
                    // vis[x][y]=1;
                    x--;
                    vis[x][y] = 1;
                }
            }
            if (direction == 3) {
                for (int i = 0; i < lev[level]; i++) {
                    //vis[x][y]=1;
                    x--;
                    y--;
                    vis[x][y] = 1;
                }
            }
            if (direction == 4) {
                for (int i = 0; i < lev[level]; i++) {
                    // vis[x][y]=1;
                    y--;
                    vis[x][y] = 1;
                }
            }
            if (direction == 5) {
                for (int i = 0; i < lev[level]; i++) {
                    // vis[x][y]=1;
                    x++;
                    y--;
                    vis[x][y] = 1;
                }
            }
            if (direction == 6) {
                for (int i = 0; i < lev[level]; i++) {
                    //vis[x][y]=1;
                    x++;
                    vis[x][y] = 1;
                }
            }
            if (direction == 7) {
                for (int i = 0; i < lev[level]; i++) {
                    // vis[x][y]=1;
                    x++;
                    y++;
                    vis[x][y] = 1;
                }
            }
            int v1 = (direction + 1) % 8;
            int v2 = (direction - 1) % 8;
            if (v2 < 0) {
                v2 += 8;
            }
            solve(x, y, level + 1, v1);
            solve(x, y, level + 1, v2);
            dp[acx][acy][level][direction] = 1;
            return;
        }

    }

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

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

        public int read() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 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 {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

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

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

    }
}


import java.util.*;

public class Main
{
    public static long spaces = 0;
    public static HashSet<Long> set;
    public static int[][] dirs;

    public static long encode(long x, long y) {
        long xx = x >= 0 ? x * 2 : x * -2 - 1;
        long yy = y >= 0 ? y * 2 : y * -2 - 1;

        return (xx >= yy) ? (xx * xx + xx + yy) : (yy * yy + xx);
    }

    public static void solveBranch(int[] spaces, int spaceLen, long x, long y, int indexDir, int index) {
        int incX = dirs[indexDir][0];
        int incY = dirs[indexDir][1];

        int incAmt = spaces[index];

        long newX = x + incX*incAmt;
        long newY = y + incY*incAmt;

        long enc = encode(newX, newY);

        for (int i = 1; i <= incAmt; i++) {
            set.add(encode(x + incX*i, y + incY*i));
        }

        if (index == spaceLen - 1) return;

        int leftDir = indexDir == 0 ? 7 : indexDir - 1;
        int rightDir = (indexDir + 1) % 8;

        solveBranch(spaces, spaceLen, newX, newY, leftDir, index + 1);
        solveBranch(spaces, spaceLen, newX, newY, rightDir, index + 1);
    }

    public static long solve(int depth, int[] spaces) {
        int maxSize = 0;

        for (int i = 0; i < depth; i++) {
            maxSize += spaces[i]*Math.pow(2, i);
        }

        set = new HashSet<Long>(maxSize);

        solveBranch(spaces, depth, 0, 0, 0, 0);

        return set.size();
    }
	public static void main(String[] args) {
	    dirs = new int[][]{
	        {0, 1},
	        {1, 1},
	        {1, 0},
	        {1, -1},
	        {0, -1},
	        {-1, -1},
	        {-1, 0},
	        {-1, 1}
	    };

	    Scanner scan = new Scanner(System.in);

	    int depth = scan.nextInt();
	    int[] spaces = new int[depth];

	    for (int i = 0; i < depth; i++) {
	        spaces[i] = scan.nextInt();
	    }

	    System.out.println(solve(depth, spaces));
	}
}


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

public class Solution {

    public static void solve(InputReader in, PrintWriter out, DebugWriter debug) throws IOException {
        Point[] points_1 = new Point[4];
        points_1[0] = new Point(in.nextInt(), in.nextInt());
        points_1[1] = new Point(in.nextInt(), in.nextInt());
        points_1[2] = new Point(in.nextInt(), in.nextInt());
        points_1[3] = new Point(in.nextInt(), in.nextInt());

        Point[] points_2 = new Point[4];
        points_2[0] = new Point(in.nextInt(), in.nextInt());
        points_2[1] = new Point(in.nextInt(), in.nextInt());
        points_2[2] = new Point(in.nextInt(), in.nextInt());
        points_2[3] = new Point(in.nextInt(), in.nextInt());

        Polygon p1 = new Polygon();
        for(int i=0; i<4; i++) p1.addPoint(points_1[i].x, points_1[i].y);

        Polygon p2 = new Polygon();
        for(int i=0; i<4; i++) p2.addPoint(points_2[i].x, points_2[i].y);

        if (coll(p1, p2)){
            out.println("YES");
        } else {
            out.println("NO");
        }
    }

    public static boolean coll(Polygon p1, Polygon p2) {
        Point p1_mid = new Point(0, 0);
        for(int i=0; i<p1.npoints; i++){
            p1_mid.x += p1.xpoints[i];
            p1_mid.y += p1.ypoints[i];
        }
        p1_mid.x /= 4;
        p1_mid.y /= 4;

        Point p2_mid = new Point(0, 0);
        for(int i=0; i<p2.npoints; i++){
            p2_mid.x += p2.xpoints[i];
            p2_mid.y += p2.ypoints[i];
        }
        p2_mid.x /= 4;
        p2_mid.y /= 4;

        if (p1.contains(p2_mid)) return true;
        if (p2.contains(p1_mid)) return true;

        for (int i = 0; i < p1.npoints; i++) {
            for (int j = 0; j < p2.npoints; j++) {
                if (p1.xpoints[i] == p2.xpoints[j] && p1.ypoints[i] == p2.ypoints[j]) return true;
            }
        }

        for (int i = 0; i < p2.npoints; i++) {
            Point point = new Point(p2.xpoints[i], p2.ypoints[i]);
            if (p1.contains(point)) return true;
        }

        for (int i = 0; i < p1.npoints; i++) {
            Point point = new Point(p1.xpoints[i], p1.ypoints[i]);
            if (p2.contains(point)) return true;
        }

        return false;
    }

    public static final String NAME = "";

    public static void main(String[] args) throws IOException{
        InputReader in;
        PrintWriter out;
        DebugWriter debug;

        if (args.length > 0 && args[0].equals("file")) {
            in = new InputReader(new BufferedReader(new FileReader("input.txt")));
            out = new PrintWriter(new FileWriter("output.txt"));
            debug = new DebugWriter(true);

            int sampleNumber = 1;
            do {
                String nextSample = "Sample #" + sampleNumber++ + ": ";
                out.println(nextSample);
                debug.println(nextSample);

                solve(in, out, debug);

                out.println("");
                debug.println("");
            } while (in.reader.readLine() != null);
        } else {
            if (NAME.length() > 0) {
                in = new InputReader(new BufferedReader(new FileReader(NAME + ".in")));
                out = new PrintWriter(new FileWriter(NAME + ".out"));
            } else {
                in = new InputReader(new BufferedReader(new InputStreamReader(System.in)));
                out = new PrintWriter(new OutputStreamWriter(System.out));
            }

            debug = new DebugWriter(false);
            solve(in, out, debug);
        }

        in.reader.close();
        out.close();
    }

    public static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(BufferedReader reader) {
            this.reader = reader;
            tokenizer = null;
        }

        public String next() throws IOException{
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }

            return tokenizer.nextToken();
        }

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

        public int[] nextIntArray(int n) throws IOException{
            int[] array = new int[n];
            for (int i=0; i<n; i++){
                array[i] = nextInt();
            }

            return array;
        }
    }

    public static class DebugWriter {
        public boolean enable;

        public DebugWriter(boolean enable){
            this.enable = enable;
        }

        public void print(Object o){
            if (enable) System.out.print(o);
        }

        public void println(Object o){
            if (enable) System.out.println(o);
        }
    }

}


import java.util.*;
import java.io.*;
public class GameWithSticks
{
    public static void main(String[] args)throws IOException
    {
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer dates=new StringTokenizer(in.readLine());
        int n=Integer.parseInt(dates.nextToken());
        int m=Integer.parseInt(dates.nextToken());
        if(n==1||m==1)
            System.out.println("Akshat");
        else
        {
            int aux=n*m;
            int cont=0;
            while(aux>0)
            {
                aux-=(n+m)-1;
                n=((n+m)-1)/2;
                m=((n+m)-1)/2;
                cont++;
            }
            if(cont%2==0)
                System.out.println("Malvika");
            else
                System.out.println("Akshat");
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class CodeForces {

	public static void main(String[] args) throws IOException,NumberFormatException{
		try {
			FastScanner sc=new FastScanner();
			char c=sc.next().charAt(0);
			char a[]=sc.next().toCharArray();
			String s[]=new String[3];
			s[0]="qwertyuiop";
			s[1]="asdfghjkl;";
			s[2]="zxcvbnm,./";
			if(c=='R') {
				for(int i=0;i<a.length;i++) {
					System.out.print(solve(s,a[i],c));
				}
			}

		}
		catch(Exception e) {
			return ;
		}

	}
	public static char solve(String[] s,char a,char c) {
		char ch='0';
		for(int i=0;i<s.length;i++) {
			for(int j=0;j<s[i].length();j++) {
				if(a==s[i].charAt(j)) {
				if(c=='L') {
					ch=s[i].charAt(j+1);
					break;
				}
				else {
					ch=s[i].charAt(j-1);
					break;
				}
				}
			}
		}
		return ch;
	}
	public static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
                                      st=new StringTokenizer(br.readLine());
                              } catch (IOException e) {}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		char nextChar() {
			return Character.parseChar(next);
		}
	}
}


//app.は全部けす

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

//流す前にfinalにする
public final class EcRound35CApplication {

	public static void main(String[] args) {

		//実インプット部　appだけけす
		Input input = new Input();
		input = SystemInput();
		String result = run(input);
		System.out.print(result);
		//実インプット部ここまで

	}

	//流す前にstaticにする
	private static void tester(Integer no,Integer KFirst,Integer KSecond , Integer KThird,String answer) {
		Input input = new Input();
		input.setInput(KFirst,KSecond,KThird);
		String result = run(input);

		if(result == answer) {
			System.out.println("No." + no + ":OK");
		}
		else {
			System.out.println("No." + no + ":failed");
			System.out.println("result:" + result);
			System.out.println("answer:" + answer);
		}
	}

	//流す前にstaticにする
	private static Input SystemInput() {
		Input input = new Input();
		Scanner sc = new Scanner(System.in);
		Integer first = sc.nextInt();
		Integer second = sc.nextInt();
		Integer third = sc.nextInt();
		input.setInput(first,second,third);
		sc.close();
		return input;
	}

	//流す前にstaticにする
	private static String run(Input input) {
		String result = "NO";

		//どれが1なら議論の余地もなくYES
		if(input.oneCheck()) {
			return "YES";
		}

		//6パターン検証してどっかで引っかかれば良い
		//starter:1秒目に光るやつ
		//follower:次を埋めるやつ
		//matcher:最後に当てはまるか検証するやつ
		//inputを(A,B,Cとして)

		//A,B,C
		result = checker(input.getKFirst(),input.getKSecond(),input.getKThird(),result);
		//A,C,B
		result = checker(input.getKFirst(),input.getKThird(),input.getKSecond(),result);
		//B,A,C
		result = checker(input.getKSecond(),input.getKFirst(),input.getKThird(),result);
		//B,C,A
		result = checker(input.getKSecond(),input.getKThird(),input.getKFirst(),result);
		//C,A,B
		result = checker(input.getKThird(),input.getKFirst(),input.getKSecond(),result);
		//C,B,A
		result = checker(input.getKThird(),input.getKSecond(),input.getKFirst(),result);

		return result;
	}

	private static String checker(Integer starter,Integer follower,Integer matcher,String result) {

		//既にresultがYESになってたら処理を飛ばす
		if(result == "YES") {
			return result;
		}

		//パターン出しのためユークリッド互除法を利用して最小公倍数を出しておく
		Integer LCM = starter*follower/euclidean(starter,follower);

		//遅延秒数管理
		Integer followerDelay;

		//遅延秒数をずらしてどっかでビンゴしないか試す
		for(followerDelay = 0; followerDelay < starter; followerDelay++){
			//最小公倍数+ずれ分足しとけばだいたいパターン網羅できるっしょ的な
			Integer pattarnLength = LCM * 2 + followerDelay;

			//starterとfollowerで光らないやつ数え上げ
			List<Integer> needToMatchList = new ArrayList<Integer>();
			for(Integer pattarn = 1; pattarn <= pattarnLength ; pattarn++) {
				//starterが光るかチェック（starterは1秒目点灯なのでかならず余り1になる）
				if(pattarn % starter == 1) {
					continue;
				}
				//followerが光るかチェック
				//丁度割り切れる場合があるのでfollowerで割った余りを検証に使う
				if(pattarn % follower == (1+followerDelay)%follower) {
					continue;
				}
				//ヒットしなければリストに加える
				needToMatchList.add(pattarn);
			}

			//リストの長さが0ならまずOK
			if(needToMatchList.size() == 0) {
				return "YES";
			}

			//一つだけある場合は、リストにLCM足したやつを加える
			//（パターンをもう一つ分増やす）
			else if(needToMatchList.size() == 1) {
				needToMatchList.add(needToMatchList.get(0)+LCM);
			}
			//2つ以上ある場合は値間が全てmatcherに一致しているかチェック
			if(needToMatchList.size() >= 2) {
				for(Integer k = 0; k < needToMatchList.size() - 1; k++) {
					Integer between = needToMatchList.get(k+1) - needToMatchList.get(k);
					if(between == matcher) {
						result = "YES";
					}
					else {
						result = "NO";
						break;
					}
				}
			}
		}
		return result;
	}

	private static Integer euclidean(Integer a,Integer b) {
		Integer r;

		//大小逆転解消
		if(a<b) {
			Integer tmp;
			tmp = a;
			a = b;
			b = tmp;
		}

		r = a % b;
		if(r == 0) {
			return b;
		}
		else {
			return euclidean(b,r);
		}

	}

	//流す前にstaticにする
	private static class Input{
		private Integer kFirst;
		private Integer kSecond;
		private Integer kThird;

		public void setInput(Integer kFirst,Integer kSecond , Integer kThird) {
			this.kFirst = kFirst;
			this.kSecond = kSecond;
			this.kThird = kThird;

		}

		public Integer getKFirst() {
			return kFirst;
		}

		public void setKFirst(Integer kFirst) {
			this.kFirst = kFirst;
		}

		public Integer getKSecond() {
			return kSecond;
		}

		public void setKSecond(Integer kSecond) {
			this.kSecond = kSecond;
		}

		public Integer getKThird() {
			return kThird;
		}

		public void setKThird(Integer kThird) {
			this.kThird = kThird;
		}

		public boolean oneCheck() {
			if(kFirst == 1 || kSecond == 1 || kThird == 1) {
				return true;
			}
			else {
				return false;
			}
		}

	}
}


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

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

    static class ThreePieces {
        int[][][][][] dp = new int[201][10][10][100][3];
        int INF = (int) (1e9);
        ArrayList<int[]>[][][] move = new ArrayList[10][10][3];
        int N;
        int[] moveR = new int[]{-2, -1, 1, 2};
        int[] moveC = new int[]{-2, -1, 1, 2};

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            N = in.nextInt();
            int[][] loc = new int[N * N][2];
            int[][] arr = new int[N][N];
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < N; j++) {
                    int a = in.nextInt() - 1;
                    loc[a] = new int[]{i, j};
                    arr[i][j] = a;
                    move[i][j][0] = posKnight(i, j);
                    move[i][j][1] = posBishop(i, j);
                    move[i][j][2] = posRook(i, j);
                }
            }
            for (int i = 0; i <= 200; i++) {
                for (int j = 0; j < 10; j++) {
                    for (int k = 0; k < 10; k++) {
                        for (int d = 0; d < 100; d++) {
                            for (int z = 0; z < 3; z++) {
                                dp[i][j][k][d][z] = INF;
                            }
                        }
                    }
                }
            }
            Arrays.fill(dp[0][loc[0][0]][loc[0][1]][0], 0);
            for (int i = 0; i < 200; i++) {
                for (int j = 0; j < N; j++) {
                    for (int k = 0; k < N; k++) {
                        for (int d = 0; d < N * N; d++) {
                            for (int m = 0; m < 3; m++) {
                                for (int next = 0; next < 3; next++) {
                                    for (int[] c : move[j][k][next]) {
                                        if (arr[c[0]][c[1]] == d + 1) {
                                            dp[i + 1][c[0]][c[1]][d + 1][next] = Math.min(dp[i + 1][c[0]][c[1]][d + 1][next], dp[i][j][k][d][m] + (m == next ? 0 : 1));
                                        } else {
                                            dp[i + 1][c[0]][c[1]][d][next] = Math.min(dp[i + 1][c[0]][c[1]][d][next], dp[i][j][k][d][m] + (m == next ? 0 : 1));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            int resT = INF;
            int resP = INF;
            for (int i = 2; i <= 200; i++) {
                for (int v : dp[i][loc[N * N - 1][0]][loc[N * N - 1][1]][N * N - 1]) {
                    if (resT + resP >= v + i) {
                        if (resT + resP == v + i) {
                            if (v < resP) {
                                resT = i;
                                resP = v;
                            }
                        } else {
                            resT = i;
                            resP = v;
                        }
                    }
                }
            }
            out.println((resT + resP) + " " + resP);
        }

        boolean isValid(int r, int c) {
            return r >= 0 && r < N && c >= 0 && c < N;
        }

        ArrayList<int[]> posKnight(int r, int c) {
            ArrayList<int[]> pos = new ArrayList<>();
            for (int rM : moveR) {
                for (int cM : moveC) {
                    if (Math.abs(rM) != Math.abs(cM)) {
                        int newR = r + rM;
                        int newC = c + cM;
                        if (isValid(newR, newC)) {
                            pos.add(new int[]{newR, newC});
                        }
                    }
                }
            }
            return pos;
        }

        ArrayList<int[]> posRook(int r, int c) {
            ArrayList<int[]> pos = new ArrayList<>();
            for (int i = 0; i < N; i++) {
                pos.add(new int[]{r, i});
                pos.add(new int[]{i, c});
            }
            return pos;
        }

        ArrayList<int[]> posBishop(int r, int c) {
            ArrayList<int[]> pos = new ArrayList<>();
            for (int k = 1; k < N; k++) {
                int[] mR = new int[]{k, -k, k, -k};
                int[] mC = new int[]{k, k, -k, -k};
                for (int i = 0; i < 4; i++) {
                    int newR = r + mR[i];
                    int newC = c + mC[i];
                    if (isValid(newR, newC)) {
                        pos.add(new int[]{newR, newC});
                    }
                }
            }
            return pos;
        }

    }

    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.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Created by timur on 28.03.15.
 */

public class TaskD {
    boolean eof;
    BufferedReader br;
    StringTokenizer st;
    PrintWriter out;

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

    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return "-1";
            }
        }
        return st.nextToken();
    }

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

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

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

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

    void run() throws IOException {
        InputStream input = System.in;
        PrintStream output = System.out;
        try {
            File f = new File("a.in");
            if (f.exists() && f.canRead()) {
                input = new FileInputStream(f);
                output = new PrintStream("a.out");
            }
        } catch (Throwable e) {
        }
        br = new BufferedReader(new InputStreamReader(input));
        out = new PrintWriter(output);
        solve();
        br.close();
        out.close();
    }

    long gcd(long a, long b) {
        if (b == 0)
            return a;
        else
            return gcd(b, a % b);
    }

    class Pair implements Comparable<Pair> {
        int move, change, num;

        public Pair(int move, int change, int num) {
            this.move = move;
            this.change = change;
            this.num = num;

        }

        @Override
        public int compareTo(Pair o) {
            int r = move - o.move;
            if (r == 0)
                r = this.change - o.change;
            return r;
        }

        public Pair up() {
            return new Pair(move + 1, change + 1, num);
        }
    }

    Pair min(Pair a, Pair b) {
        if (a == null)
            return b;
        if (b == null)
            return a;
        if (b.compareTo(a) < 0)
            return b;
        return a;
    }

    Pair numin(Pair a, Pair b) {
        if (a == null)
            return b;
        if (b == null)
            return a;
        if (a.num > b.num)
            return a;
        if (a.num < b.num)
            return b;
        return min(a, b);
    }

    class map {
        Pair[][] m;

        public map() {
            m = new Pair[n][n];
        }
    }

    int n, k;

    void solve() {
        n = nextInt();
        k = n * n;
        int[] x = new int[k + 1];
        int[] y = new int[k + 1];
        int u;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                u = nextInt() - 1;
                x[u] = i;
                y[u] = j;
            }
        }
        int inf = k * 2 + 5;
        map[] h = new map[inf];
        map[] s = new map[inf];
        map[] l = new map[inf];
        for (int i = 0; i < inf; i++) {
            h[i] = new map();
            s[i] = new map();
            l[i] = new map();
        }
        h[0].m[x[0]][y[0]] = new Pair(0, 0, 1);
        l[0].m[x[0]][y[0]] = new Pair(0, 0, 1);
        s[0].m[x[0]][y[0]] = new Pair(0, 0, 1);

        int[] dxh = {-2, -2, -1, 1, 2, 2, 1, -1};
        int[] dyh = {-1, 1, 2, 2, 1, -1, -2, -2};

        int[] dxs = {-1, -1, 1, 1};
        int[] dys = {-1, 1, 1, -1};

        int[] dxl = {-1, 0, 1, 0};
        int[] dyl = {0, 1, 0, -1};

        int nx, ny;
        Pair np;
        Pair cp;

        Pair ans = null;
        for (int i = 0; i < inf - 3; i++) {
            for (int xx = 0; xx < n; xx++) {
                for (int yy = 0; yy < n; yy++) {
                    cp = h[i].m[xx][yy];
                    if (cp != null) {
                        for (int j = 0; j < 8; j++) {
                            nx = xx + dxh[j];
                            ny = yy + dyh[j];
                            if (nx >= 0 && ny >= 0 && nx < n && ny < n) {
                                np = new Pair(cp.move + 1, cp.change, cp.num);
                                if (cp.num < k && nx == x[cp.num] && ny == y[cp.num]) {
                                    np = new Pair(cp.move + 1, cp.change, cp.num + 1);
                                }
                                h[i + 1].m[nx][ny] = numin(h[i + 1].m[nx][ny], np);
                                s[i + 2].m[nx][ny] = numin(s[i + 1].m[nx][ny], np.up());
                                l[i + 2].m[nx][ny] = numin(l[i + 1].m[nx][ny], np.up());
                                ans = numin(ans, np);
                            }
                        }
                    }
                    cp = s[i].m[xx][yy];
                    if (cp != null) {
                        for (int j = 0; j < 4; j++) {
                            for (int mul = 1; mul < n + 1; mul++) {
                                nx = xx + dxs[j] * mul;
                                ny = yy + dys[j] * mul;
                                if (nx >= 0 && ny >= 0 && nx < n && ny < n) {
                                    np = new Pair(cp.move + 1, cp.change, cp.num);
                                    if (cp.num < k && nx == x[cp.num] && ny == y[cp.num]) {
                                        np = new Pair(cp.move + 1, cp.change, cp.num + 1);
                                    }
                                    s[i + 1].m[nx][ny] = numin(s[i + 1].m[nx][ny], np);
                                    h[i + 2].m[nx][ny] = numin(h[i + 1].m[nx][ny], np.up());
                                    l[i + 2].m[nx][ny] = numin(l[i + 1].m[nx][ny], np.up());
                                    ans = numin(ans, np);
                                } else {
                                    break;
                                }
                            }
                        }
                    }
                    cp = l[i].m[xx][yy];
                    if (cp != null) {
                        for (int j = 0; j < 4; j++) {
                            for (int mul = 1; mul < n + 1; mul++) {
                                nx = xx + dxl[j] * mul;
                                ny = yy + dyl[j] * mul;
                                if (nx >= 0 && ny >= 0 && nx < n && ny < n) {
                                    np = new Pair(cp.move + 1, cp.change, cp.num);
                                    if (cp.num < k && nx == x[cp.num] && ny == y[cp.num]) {
                                        np = new Pair(cp.move + 1, cp.change, cp.num + 1);
                                    }
                                    l[i + 1].m[nx][ny] = numin(l[i + 1].m[nx][ny], np);
                                    s[i + 2].m[nx][ny] = numin(s[i + 1].m[nx][ny], np.up());
                                    h[i + 2].m[nx][ny] = numin(h[i + 1].m[nx][ny], np.up());
                                    ans = numin(ans, np);
                                } else {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }

        out.print(ans.move + " " + ans.change);
        /*

        for (int i = 1; i < k; i++) {
            if (x[i] == x[i - 1] || y[i] == y[i - 1]) {
                l[i] = l[i - 1] + 1;
            } else {
                l[i] = l[i - 1] + 2;
            }
            zl[i] = zl[i - 1];
            s[i] = l[i] + 1;
            zs[i] = zl[i - 1] + 1;
            h[i] = l[i] + 1;
            zh[i] = zl[i - 1] + 1;
            if ((x[i] + y[i]) % 2 == (x[i - 1] + y[i - 1]) % 2) {
                if ((x[i] - y[i] == x[i - 1] - y[i - 1]) ||
                    (x[i] + y[i] == x[i - 1] + y[i - 1])) {
                    s[i] = s[i - 1] + 1;
                } else {
                    s[i] = s[i - 1] + 2;
                    if (s[i] + 1 < l[i] || (s[i] + 1 == l[i] && zs[i] + 1 < zl[i])) {
                        l[i] = s[i] + 1;
                        zl[i] = zs[i] + 1;
                    }
                    if (s[i] + 1 < h[i] || (s[i] + 1 == h[i] && zs[i] + 1 < zh[i])) {
                        h[i] = s[i] + 1;
                        zh[i] = zs[i] + 1;
                    }
                }
            }
            int mv = inf;
            Queue<Integer> xx = new ArrayDeque<>();
            Queue<Integer> yy = new ArrayDeque<>();
            Queue<Integer> c = new ArrayDeque<>();
            xx.add(x[i - 1]);
            yy.add(y[i - 1]);
            c.add(0);
            boolean[][] vis = new boolean[n][n];
            vis[x[i - 1]][y[i - 1]] = true;
            while (!xx.isEmpty()) {
                cx = xx.poll();
                cy = yy.poll();
                cc = c.poll();
                for (int j = 0; j < 8; j++) {
                    nx = cx + dx[j];
                    ny = cy + dy[j];
                    if (nx >= 0 && ny >= 0 && nx < n && ny < n) {
                        if (nx == x[i] && ny == y[i]) {
                            mv = cc + 1;
                            xx.clear();
                            break;
                        }
                        if (!vis[nx][ny]) {
                            xx.add(nx);
                            yy.add(ny);
                            c.add(cc + 1);
                            vis[nx][ny] = true;
                        }
                    }
                }
            }
            if (h[i - 1] + mv < h[i] || (h[i - 1] + mv == h[i] && zh[i] > zh[i - 1])) {
                h[i] = h[i - 1] + mv;
                zh[i] = zh[ i - 1];
            }
            if (h[i] + 1 < l[i] || (h[i] + 1 == l[i] && zh[i] + 1 < zl[i])) {
                l[i] = h[i] + 1;
                zl[i] = zh[i] + 1;
            }
            if (h[i] + 1 < s[i] || (h[i] + 1 == s[i] && zh[i] + 1 < zs[i])) {
                s[i] = h[i] + 1;
                zs[i] = zh[i] + 1;
            }
        }
        Pair lll = new Pair(l[k - 1], zl[k - 1]);
        Pair hhh = new Pair(h[k - 1], zh[k - 1]);
        Pair sss = new Pair(s[k - 1], zs[k - 1]);
        Pair res = lll;
        if (res.compareTo(hhh) > 0) {
            res = hhh;
        }
        if (res.compareTo(sss) > 0) {
            res = sss;
        }
        out.print(res.l + " " + res.change);
        */
    }

}


package org.example.test;

import java.util.Scanner;

public class SimpleMath {

	public static void main(String[] args) {
		int n = 21, k = 73;

		Scanner scanner = new Scanner(System.in);

		n = scanner.nextInt();
		k = scanner.nextInt();
		int x = k - (2 * n);
		while (x > n){
			x = x - n;
		}

		int res = n - x;
		System.out.println(res);

	}

}


import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class d {

    static ArrayList<Long> lucky = new ArrayList<>();

    public static void main(String args[]) {
        Scanner console = new Scanner(System.in);
        long l = console.nextInt(), r = console.nextInt(), ans = 0;
        lucky(0, l, r);
        Collections.sort(lucky);
        for (int i = 0; l <= r; l++) {
            if (lucky.get(i) < l && i < lucky.size()-1)
                i++;
            ans += lucky.get(i);
        }
        System.out.println(ans);
    }

    static void lucky(long  num, long l, long r) {
        if (num > 10e9)
            return;
        if (num >= l)
            lucky.add(num);
        lucky(4 + num * 10, l, r);
        lucky(7 + num * 10, l, r);

    }
}


import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    static void solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> resArr = new ArrayList<>();
        int[] bArr = new int[n+1];
        //bArr[0] = 1;
        for(int i=1;i<=n;i++){
            int val = 0;
            int t = i;
            int ost = i%10;
            if(ost == 0){
                while(t%10==0){
                    t=t/10;
                }
                val = bArr[t];
            }
            else
                val = ost+(bArr[i-ost]);
            //sum(i);
            bArr[i] = val;
            int sum = i+val;
            if(sum == n){
                resArr.add(i);
            }
        }
        Collections.sort(resArr);
        System.out.println(resArr.size());
        for (int i=0;i<resArr.size();i++){
            System.out.print(resArr.get(i)+" ");
        }
    }

    static int sum(int n, int[]arr){
        int sum = 0;
        while(n>=1){
            int ost = n%10;
            sum+=ost;
            n = n-ost;
            n = n/10;
        }
        return sum;
    }

    public static void main(String[] args) {
	// write your code here
        solve();
    }
}


import java.util.*;

public class codeForces_441_A {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		long i=n;
		long c=0;
		ArrayList<Long> a = new ArrayList<Long>();
		while(i>0)
		{
			long k = i;
			long sum = i;
			while(k>0)
			{
				long rem = k%10;
				sum = sum + rem;
				k=k/10;
			}
			if(sum == n)
			{
				c++;
				a.add(i);
			}
			i--;
		}
		System.out.println(c);
		for(int z = a.size()-1;z>=0;z--)
			System.out.println(a.get(z));
	}

}


import java.util.*;

public class A714 {
    public static long getDays(long a, long b, long k) {
        int cant = a <= k && k <= b ? 1 : 0;
        return b - a + 1 - cant;
    }

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		long l1 = scan.nextLong();
		long r1 = scan.nextLong();
		long l2 = scan.nextLong();
		long r2 = scan.nextLong();
		long k = scan.nextLong();

		long lm = l1;
		long rm = r1;
		long lb = l2;
		long rb = r2;

		if (l1 > l2) {
		    lm = l2;
    		rm = r2;
    		lb = l1;
    		rb = r1;
		}

		if (rm < lb) {
		    System.our.print("0");
		    System.exit(0);
		}
		if (rm > rb) {
		    System.our.print(getDays(lb, rb, k));
		    System.exit(0);
		}

		System.our.print(getDays(lb, rm, k));
		System.exit(0);
	}
}