import java.io.*;
import java.util.*;
public class Solution
{
    static int N,M;
    static long K;
    static Quad A[];
    static long dp[][][];
    static StringBuilder sb=new StringBuilder();
    public static void main(String ag[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int i,j,k;

        String ip1[]=br.readLine().split(" ");

        N=Integer.parseInt(ip1[0]);
        M=Integer.parseInt(ip1[1]);
        K=Integer.parseInt(ip1[2]);

        A=new Quad[M];
        for(i=0;i<M;i++)
        {
            String ip2[]=br.readLine().split(" ");
            A[i]=new Quad(Long.parseLong(ip2[0]),Long.parseLong(ip2[1]),Integer.parseInt(ip2[2]),i+1);
        }
        Arrays.sort(A,new Tcomp());
        dp=new long[N+1][M][101];
        for(i=0;i<=N;i++)
        for(j=0;j<M;j++)
        for(k=0;k<101;k++)
        dp[i][j][k]=-1;

        long ans=-(long)1e18;
        for(i=0;i<M;i++)
        {
            for(long jj=A[i].a;jj<=A[i].b;jj++)
            {
                ans=Math.max(ans,jj+find(1,i,(int)(jj-A[i].a)));
            }
        }
        if(ans<0)
        {
            System.out.println("NO");
            return;
        }
        boolean flag=false;
        for(i=0;i<M;i++)
        {
            for(long jj=A[i].a;jj<=A[i].b;jj++)
            {
                if(ans==(jj+find(1,i,(int)(jj-A[i].a))))
                {
                    sb.append(A[i].id+" "+jj+"\n");
                    trace(1,i,(int)(jj-A[i].a));
                    flag=true;
                    break;
                }
            }
            if(flag)
            break;
        }
        System.out.println("YES");
        System.out.println(sb);
    }
    public static long find(int day,int currId,int diff)
    {
        if(day==N)
        return 0L;

        if(dp[day][currId][diff]!=-1)
        return dp[day][currId][diff];

        long currValue=diff+A[currId].a;
        long total=-(long)1e18;
        for(int i=currId+1;i<M;i++)
        {
            if(A[currId].c==A[i].c)
            continue;
            if(currValue*K>=A[i].a&&currValue*K<=A[i].b)
            total=Math.max(total,currValue*K+find(day+1,i,(int)(currValue*K-A[i].a)));
            if(currValue+K>=A[i].a&&currValue+K<=A[i].b)
            total=Math.max(total,currValue+K+find(day+1,i,(int)(currValue+K-A[i].a)));
        }
        return dp[day][currId][diff]=total;
    }
    public static void trace(int day,int currId,int diff)
    {
        if(day==N)
        return;

        long currValue=diff+A[currId].a;
        long total=-(long)1e18;

        for(int i=currId+1;i<M;i++)
        {
            if(A[currId].c==A[i].c)
            continue;
            if(currValue*K>=A[i].a&&currValue*K<=A[i].b)
            total=Math.max(total,currValue*K+find(day+1,i,(int)(currValue*K-A[i].a)));
            if(currValue+K>=A[i].a&&currValue+K<=A[i].b)
            total=Math.max(total,currValue+K+find(day+1,i,(int)(currValue+K-A[i].a)));
        }

        for(int i=currId+1;i<M;i++)
        {
            if(A[currId].c==A[i].c)
            continue;
            if(currValue*K>=A[i].a&&currValue*K<=A[i].b&&total==currValue*K+find(day+1,i,(int)(currValue*K-A[i].a)))
            {
                sb.append(A[i].id+" "+(currValue*K)+"\n");
                trace(day+1,i,(int)(currValue*K-A[i].a));
                return;
            }
            if(currValue+K>=A[i].a&&currValue+K<=A[i].b&&total==currValue+K+find(day+1,i,(int)(currValue+K-A[i].a)))
            {
                sb.append(A[i].id+" "+(currValue+K)+"\n");
                trace(day+1,i,(int)(currValue+K-A[i].a));
                return;
            }
        }
    }
}
class Quad
{
    long a,b;
    int c,id;
    Quad(long S,long E,int C,int ID)
    {
        a=S;
        b=E;
        c=C;
        id=ID;
    }
}
class Tcomp implements Comparator<Quad>
{
    public int compare(Quad P,Quad Q)
    {
        return P.c-Q.c;
    }
}


//package javaCode.exercise;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Send {
	long a, b;

	public Send(long a, long b) {
		this.a = a;
		this.b = b;
	}

	public Send() {

	}

	public static void end() {
		System.exit(0);
	}

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		if(n==1){
			System.out.println("Yes");
			end();
		}
		char[] arr = sc.nextLine().toCharArray();
		Map<Character, Integer> m = new HashMap<Character, Integer>();
		for(int i=0;i<n;i++){
			if(m.containsKey(arr[i])){
				m.put(arr[i], m.get(arr[i])+1);
			}else{
				m.put(arr[i], 1);
			}
		}
		int cnt = 0;
		for(char ch : m.keySet()){
			if(m.get(ch)>=2){
				cnt++;
			}
		}
		if(cnt!=0)
		System.out.println("Yes");
		else
	    System.out.println("No");
		sc.close();

	}

}


import java.util.List;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.util.Collections;
import java.io.InputStream;

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

class TaskE {
	public void solve(int testNumber, InputReader in, OutputWriter out) {
		int n = in.readInt();
		int d = in.readInt();
		int s = in.readInt();
		int[] c = new int[n];
		int[] f = new int[n];
		int[] l = new int[n];
		ArrayList<Pair<Integer, Integer>> a = new ArrayList<Pair<Integer, Integer>>();
		ArrayList<Pair<Integer, Integer>> b = new ArrayList<Pair<Integer, Integer>>();
		ArrayList<Pair<Integer, Integer>> t = new ArrayList<Pair<Integer, Integer>>();
		for (int i = 0; i < n; i ++) {
			c[i] = in.readInt();
			f[i] = in.readInt();
			l[i] = in.readInt();
			if (c[i] > 0 || l[i] < d) a.add(new Pair<Integer, Integer>(c[i], i));
			if (l[i] >= d && c[i] > 0) b.add(new Pair<Integer, Integer>(f[i], i));
			if (l[i] >= d && c[i] == 0) t.add(new Pair<Integer, Integer>(f[i], i));
		}
		Collections.sort(a);
		Collections.sort(b);
		Collections.sort(t);
		long[] tt = new long[t.size() + 1];
		tt[0] = 0;
		for (int i = 0; i < t.size(); i ++)
			tt[i + 1] = tt[i] + t.get(i).first;
		int cnt = 0, sum = 0;
		long left = 0;
		boolean[] choose = new boolean[n];
		Arrays.fill(choose, false);
		int p = a.size() - 1;
		int q = 0, sumT = 0;
		while (q < t.size() && sumT + t.get(q).first <= s) {
			sumT += t.get(q).first;
			q ++;
		}
		Pair<Integer, Integer> ans = new Pair<Integer, Integer>(q, -sumT);
		for (int i = 0; i < b.size(); i ++) {
			Pair<Integer, Integer> now = b.get(i);
			if (sum + now.first > s) break;
			sum += now.first;
			if (! choose[now.second]) {
				choose[now.second] = true;
				left += c[now.second];
				cnt ++;
			} else {
				left ++;
			}
			while (p >= 0) {
				if (! choose[a.get(p).second]) {
					if (left == 0) break;
					cnt ++;
					left --;
					choose[a.get(p).second] = true;
					left += a.get(p).first;
				}
				p --;
			}
			while (sum + sumT > s) {
				q --;
				sumT -= t.get(q).first;
			}
			long tmp = Math.min(left, (long)t.size());
			if (q + tmp > t.size()) {
				Pair<Integer, Integer> u = new Pair<Integer, Integer>(cnt + t.size(), -(sum + (int)tt[t.size() - (int)tmp]));
				if (u.compareTo(ans) > 0) ans = u;
			} else {
				Pair<Integer, Integer> u = new Pair<Integer, Integer>(cnt + q + (int)tmp, -(sum + sumT));
				if (u.compareTo(ans) > 0) ans = u;
			}
		}
		out.printLine(ans.first, -ans.second);
	}
}

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

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

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

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

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

class OutputWriter {
	private final PrintWriter writer;

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

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

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

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

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

class Pair<T1 extends Comparable<T1>, T2 extends Comparable<T2>> implements Comparable<Pair<T1, T2>> {
	public T1 first;
	public T2 second;

	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;

		Pair pair = (Pair) o;

		if (!first.equals(pair.first)) return false;
		if (!second.equals(pair.second)) return false;

		return true;
	}

	public int hashCode() {
		int result = first.hashCode();
		result = 31 * result + second.hashCode();
		return result;
	}

	public Pair(T1 first, T2 second) {
		this.first = first;
		this.second = second;
	}

	public int compareTo(Pair<T1, T2> o) {
		if (first.compareTo(o.first) != 0) return first.compareTo(o.first);
		return second.compareTo(o.second);
	}
}


// LUOGU_RID: 92601310
import java.util.Scanner;

public class CF1749D {

    private static long MAX = 998244353;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        long b = scanner.nextLong();
        long ans = 0;
        long total = b;
        long last = 0;
        long min = 1;
        boolean flag = true;
        for (int i = 1;i <= a;i++) {
            if (i == 1) {
                last = b % MAX;
                ans += last;
                ans %= MAX;
            } else {
                if (flag) {
                    // 计算新的min
                    if (zhi(i)) {
                        if (min * i <= b) {
                            min *= i;
                        } else {
                            flag = false;
                            total = ((total % MAX) * (b % MAX) + b) % MAX;
                            continue;
                        }
                    }
                    last = (((b / min) % MAX) * last) % MAX;
                    ans += last;
                    ans %= MAX;
                }
                total = ((total % MAX) * (b % MAX) + b) % MAX;
            }
        }

        // 2^n - ans
        System.out.println(((total - ans) % MAX + MAX) % MAX);
    }

    private static boolean zhi(int i) {
        for (int j = 2;j * j <= i;j++) {
            if (i % j == 0) {
                return false;
            }
        }
        return true;
    }
}


import javax.management.DynamicMBean;
import javax.print.DocFlavor;
import javax.print.attribute.HashAttributeSet;
import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.net.Inet4Address;
import java.nio.file.attribute.FileAttribute;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.temporal.TemporalAdjusters;
import java.util.List;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
import java.util.Arrays;
import java.util.concurrent.Callable;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.temporal.TemporalAdjusters;

public class Main {

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

    public static void main(String[] args) {
        FastReader sc = new FastReader();
        long u=sc.nextLong();
        long v=sc.nextLong();
        HashSet<Long> set=new HashSet<>();
        if(v<u || (v%2!=0 && u%2==0) || (v%2==0 && u%2!=0) ){
            System.out.println(-1);

        }
        else if(u==v && v!=0){
            System.out.println(1);
            System.out.println(u);
        }
        else if(v==u && v==0){
            System.out.println(0);
        }
        else{
            set.add(u);
            long value=(v-u)/2;
            if((u&value)!=0){
                System.out.println(3);
                System.out.print(u+" "+value+" "+value);
            }
            else{
                System.out.println(2);
                System.out.print((u+value)+" "+value);

            }
        }

    }

}


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

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt(),d=sc.nextInt();
		 int m=(a-c)+(b-c)+c;
		 if((a-c)<=d && (b-c)<=d && (a-c)>=0 && (b-c)>=0 && m>=0 && m<d)
		 System.out.println(d-m);
		 else
		 System.out.println("-1");
	}
}


import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Problem315C {
    public static boolean[] primes = new boolean[2000000];
    public static int numPrimes;
    public static int numPals;
    public static boolean[] pals = new boolean[2000000];

    public static int sieve(double p, double q){

        Arrays.fill(primes, true);
        primes[0]=false;
        primes[1]=false;
        int i = 2;
        int max = 1;
        for(;i<2000000;i++){
            if(isPalindrome(i))
                numPals++;
            if(primes[i]){
                for(int j=2;j*i<2000000;j++){
                    primes[i*j]=false;
                }
            //  System.out.println(i + "  is Prime");
                numPrimes++;
            }

            if(numPrimes <= numPals*p/q){
                max = i;
        //      System.out.println( (double)numPrimes/ numPals);
            }

        }
        return max;
    }

    public static boolean isPalindrome(int a){
        String s  = ""+a;
        for(int i =0;i<=s.length()-1;i++){
            if(s.charAt(i) != s.charAt(s.length()-1-i))
                return false;
        }
    //  System.out.println(a + " is Palindrome");
        return true;
    }

    public static void main (String[] args)throws IOException{
        Scanner in = new Scanner(System.in);
        int p = in.nextInt();
        int q = in.nextInt();
        numPrimes = 0;
        numPals = 1;
        Arrays.fill(primes,true);
        System.out.println(sieve(p,q));

    }
}


import java.util.*;
public class Main{
    public static void  factorize(Map<Integer,Integer> map,int n){
        for(int i=2;i<=Math.sqrt(n);i++){
            while(n%i==0){
                if(map.containsKey(i)){
                    int x=map.get(i);
                    map.put(i,x+1);
                }else{
                    map.put(i,1);
                }
                n=n/i;
            }
        }
        if(n!=1){
            map.put(n,1);
        }
    }
    public static void main(String[] args){
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        Map<Integer,Integer> map=new HashMap<>();
        factorize(map,n);
        int max=0;
        long k=1;
        for(Map.Entry<Integer,Integer> entry:map.entrySet()){
            int x=entry.getValue();
            k=k*entry.getKey();
            // System.out.println(x);
            if(x>max) max=x;
        }
        int num=1,i=1;
        while(i<31){
            num=1<<i;
            if(max/num <=1) break;
            i++;

        }
        if(max%num!=0) i=i+1;
        // System.out.println(max+" "+i);
        boolean shit=true;
        for(Map.Entry<Integer,Integer> entry:map.entrySet()){
            int x=entry.getValue();

            if(x!=max) shit=false;
        }
        if(!shit || max%num!=0) i=i+1;
        if(k==n) i=0;
        System.out.println(k+" "+i);
    }
}


import java.util.*;
import java.util.LinkedList;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class tmp {
    public static void main(String [] args) throws Exception{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(in.readLine());
        StringBuilder sb = new StringBuilder();

        String s = st.nextToken();
        String t = in.readLine();

        int len = s.length(),ind=0;
        boolean ok = false;
        for(int i=0; i<len; i++){

            if(t.charAt(i) - s.charAt(i) > 1){
                System.out.println(s.substring(0,i) + (char)(s.charAt(i)+1) + s.substring(i+1));
                return;
            }else if(t.charAt(i) - s.charAt(i) > 0 && !ok){
                ok = true;
                ind = i;
            }else if(ok && s.charAt(i) < 'z'){
                System.out.println(s.substring(0,i) + "z" + s.substring(i+1));
                return;
            }else if(ok && t.charAt(i) > 'a'){
                System.out.println(t.substring(0,ind) + t.charAt(ind) + t.substring(ind+1,i) + "a" + t.substring(i+1));
                return;
            }
        }
        System.out.println("No such string");

    }

}

class P implements Comparable<P>{
    int val, idx;
    public P(int val, int idx){
        this.val = val;
        this.idx = idx;
    }

    public int compareTo(P other){
        if (this.val != other.val) return -this.val + other.val;
        return this.idx - other.idx;
    }
}


import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {

	InputStream is;
	PrintWriter out;
	String INPUT = "";

	private static final long M = 1000000007L;

	void solve() {
		int n = ni();
		int[] a = na(n);
		int ans = 0;
		int MAX = Integer.MAX_VALUE / 200;
		int[][] d = new int[][] { { 0, 3, 4 }, { 3, 0, MAX }, { 4, MAX, 0 }, };
		for (int i = 1; i < n && ans < MAX; i++) {
			ans += d[a[i] - 1][a[i - 1] - 1];
			if (i >= 2 && a[i] == 2 && a[i-1] == 1 && a[i-2] == 3)
				ans--;
		}
		if (ans >= MAX)
			out.println("Infinite");
		else {
			out.println("Finite");
			out.println(ans);
		}
	}

	void run() throws Exception {
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if (!INPUT.isEmpty())
			tr(System.currentTimeMillis() - s + "ms");
	}

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

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = is.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}

	private double nd() {
		return Double.parseDouble(ns());
	}

	private char nc() {
		return (char) skip();
	}

	private String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != '
									// ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n) {
			if (!(isSpaceChar(b)))
				buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}

	private int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private int[][] na(int n, int m) {
		int[][] a = new int[n][];
		for (int i = 0; i < n; i++)
			a[i] = na(m);
		return a;
	}

	private int ni() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private static void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
}


import java.util.Scanner;

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

        String s = in.next();
        StringBuilder sb = new StringBuilder();

        char c = 'a';

        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) > c || c > 'z') {
                sb.append(s.charAt(i));
            } else {
                sb.append(c);
                c++;
            }
        }

        if (c > 'z')
            System.out.println(sb);
        else
            System.out.println(-1);

    }
}


import java.util.Scanner;

public class Solution
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        long k = sc.nextLong();
        long square = 1;

        if (k > (n + m - 2))
        {
            System.out.println(-1);
            return;
        }

        long stepOneCut = 0;
        long stepTwoCut = 0;

        if ((k < n ) && (k < m))
        {
            stepOneCut = m / (k + 1) * n;
            stepTwoCut = n / (k + 1) * m;
            if (stepOneCut > stepTwoCut)
                System.out.println(stepOneCut);
            else
                System.out.println(stepTwoCut);
            return;
        }

        if ((k >= n ) && (k >= m))
        {
            stepOneCut = m / (k + 2 - n);
            stepTwoCut = n / (k + 2 - m);
            if (stepOneCut > stepTwoCut)
                System.out.println(stepOneCut);
            else
                System.out.println(stepTwoCut);
            return;
        }

        if (k >= n)
        {
            stepOneCut = m / (k + 2 - n);
            stepTwoCut = m / (k + 1) * n;
        }
        else
        {
            stepOneCut = n / (k + 2 - m);
            stepTwoCut = n / (k + 1) * m;
        }
        if (stepOneCut > stepTwoCut)
            System.out.println(stepOneCut);
        else
            System.out.println(stepTwoCut);
        return;

    }
}


//codeforces 700
        import java.io.*;
        import java.util.*;
        import java.util.Arrays;
        import static java.lang.System.out;
        public class Key_races
        {
            public static void main(String args[])
            {
                Scanner sc=new Scanner(System.in);
                int s=sc.nextInt();
                int v1=sc.nextInt();
                int v2=sc.nextInt();
                int t1=sc.nextInt();
                int t2=sc.nextInt();
                out.println((2*t1 + v1*s) == (2*t2 + v2*s)? "Friendship" :((2*t1 + v1*s) > (2*t2 + v2*s)) ?"Second":"First");

            }//main ends
        }//class ends


import java.math.BigInteger;
import java.util.Scanner;

public class CF630I{
    static BigInteger choose(int a, int b){
        BigInteger ret = BigInteger.ONE;
        for (int i=0; i<b; i++){
            ret = ret.multiply(BigInteger.valueOf(a-i));
        }
        for (int i=1; i<=b; i++){
            ret = ret.divide(BigInteger.valueOf(i));
        }
        return ret;
    }

    public static void main(String[] args){
        Scanner scn = new Scanner(System.in);
        while (scn.hasNext()){
            int n = scn.nextInt();
            BigInteger ans = BigInteger.valueOf(6).multiply(BigInteger.valueOf(4).pow(n-2));
            if (n>3){
                ans = ans.add(BigInteger.valueOf(n-3).multiply(BigInteger.valueOf(9)).multiply(BigInteger.valueOf(4).pow(n-3)));
            }
            System.out.println(ans);
        }
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class ComputerGame3 {

	static double[][] identity;
	static double INF = 1e18D;
	static int MAXPOW = 39;
	public static void main(String[] args) {
		FS in = new FS();
		PrintWriter out = new PrintWriter(System.out);
		int N = in.nextInt();
		long T = in.nextLong();
		double[] A = new double[N];
		double[] B = new double[N];
		double[] P = new double[N];
		double[] PA = new double[N];
		double V = 0;
		for(int i = 0; i < N; i++) {
			A[i] = in.nextDouble();
			B[i] = in.nextDouble();
			P[i] = in.nextDouble();
			PA[i] = P[i]*A[i];
			V = Math.max(V, P[i]*B[i]);
		}

		ConvexHullLinear cht = new ConvexHullLinear(N, -1, 0, true);
		Integer order[] = new Integer[N];
		for(int i = 0; i < N; i++) order[i] = i;
		Arrays.sort(order, (a,b) -> {
			if(P[a] == P[b]) return -Double.compare(PA[a], PA[b]);
			return Double.compare(P[a], P[b]);
		});
		for(int i = N-1; i >= 0; i--) {
			int id = order[i];
			cht.add(P[id], PA[id], id);
		}
		identity = identity(3);

//		for(int i = 0; i <= cht.s; i++) System.out.print(cht.is[i]+" ");
//		System.out.println();

		double vec[][] = new double[][]{{0}, {0}, {1}}; //prevDp, prevT, prev1
		for(int l = cht.s; l >= 0; l--) {
			double stopAt = l == 0 ? INF : cht.intersect(l, l-1);
			int id = cht.is[l];

			double mat[][] = new double[][] {
				{1-P[id], P[id]*V, P[id]*A[id]},
				{0, 1, 1},
				{0, 0, 1},
			};

			double matToPowerOf2[][][] = new double[MAXPOW][][];
			matToPowerOf2[0] = identity;
			matToPowerOf2[1] = mat;
			for(int i = 2; i < MAXPOW; i++) matToPowerOf2[i] = mult(matToPowerOf2[i-1], matToPowerOf2[i-1]);

			// Find how long we will use this line for
			double cur[][] = identity;
			for(int i = MAXPOW-1; i >= 0; i--) {
				double next[][] = mult(cur, matToPowerOf2[i]);
				double nextVec[][] = mult(next, vec);

				long t = (long)(Math.round(nextVec[1][0]));
				double dpt = nextVec[0][0];
				double prevDp = (dpt-P[id]*V*(t-1)-P[id]*A[id])/(1-P[id]);
				double lastQuery = V*(t-1)-prevDp;

				boolean bad = (t > T) || (lastQuery > stopAt);
				if(!bad) {
					// Take this expo
					cur = next;
				}
			}
			vec = mult(cur, vec);
		}
		System.out.println(vec[0][0]);
	}

	static void print(double a[][]) {
		for(int i = 0; i < a.length; i++) {
			System.out.println(Arrays.toString(a[i]));
		}
		System.out.println();
	}

	static double [][] pow(double m[][], long p) {
		if(p == 0) return identity;
		if(p == 1) return m;
		if((p&1) == 0) {
			double res[][] = pow(m, p>>1);
			return mult(res,res);
		}
		else {
			return mult(m, pow(m, p-1));
		}
	}

	static double[][] mult(double a[][], double b[][]){
		double res[][] = new double[a.length][b[0].length];
		for(int i = 0; i < a.length; i++) {
			for(int j = 0; j < b[0].length; j++) {
				for(int k = 0; k < a[i].length; k++) {
					res[i][j] += a[i][k]*b[k][j];
				}
			}
		}
		return res;
	}
	static double[][] identity(int sz) {
		double res[][] = new double[sz][sz];
		for(int i = 0; i < sz; i++) res[i][i] = 1;
		return res;
	}

	/*Linear version of Convex hull optimization. Written by Joshua Fair
	Constructor(a, b, c, d):
	a = max number of lines that will be added
	b = 1 if lines are added in increasing order and -1 if added in decreasing order
	c =
		-1 if points are queried in order from large X to small X
		0 if the query points are in no specific order
		1 if the points are queries in order from small X to large X
	d = true if the queries are max, and false if the queries are min
	!!! If you add lines in one order and query points in the opposite order, it will only be linear if all lines are
	added before any points are queried !!!
	*/
	static class ConvexHullLinear{
		boolean upd, isMin;
		int type, inc, s, p;
		double[] ms,bs;
		int[] is;
		public ConvexHullLinear(int numLines, int ii, int tt, boolean mm) {
			s = -1;
			p = 0;
			ms = new double[numLines];
			bs = new double[numLines];
			is = new int[numLines];
			inc = ii;
			type = tt;
			isMin = !mm;
			upd = false;
			if(isMin) inc = -inc;
		}
		public void add(double m, double b, int i) {
			if(isMin) { m=-m; b=-b; }
			upd = true;
			s++;
			ms[s] = m;
			bs[s] = b;
			is[s] = i;
			while((s > 0 && ms[s] == ms[s-1] && bs[s] >= bs[s-1])
					|| (s-2 >= 0 && bad(s-2,s-1,s))) {
				ms[s-1] = m;
				bs[s-1] = b;
				is[s-1] = i;
				s--;
			}
		}
		public boolean bad(int l1, int l2, int l3) {
			if(inc == 1) return intersect(l2,l3) <= intersect(l1,l2);
			return intersect(l2,l3) >= intersect(l1,l2);
		}
		public boolean eqq(int l1, int l2) {
			return eq(ms[l1], ms[l2]) && eq(bs[l1], bs[l2]);
		}
		public boolean eq(double a, double b) {
			return Math.abs(a-b) < 1e-10;
		}
		public double intersect(int l1, int l2) {
			return (double)(bs[l2]-bs[l1])/(double)(ms[l1]-ms[l2]);
		}
		public double eval(int l1, double x) {
			return ms[l1]*x + bs[l1];
		}
	}

	static class FS{
		BufferedReader br;
		StringTokenizer st;
		public FS() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {
			while(st == null || !st.hasMoreElements()) {
				try { st = new StringTokenizer(br.readLine());}
				catch(Exception e) { throw null;}
			}
			return st.nextToken();
		}
		int nextInt() { return Integer.parseInt(next());}
		double nextDouble() { return Double.parseDouble(next());}
		long nextLong() { return Long.parseLong(next());}
	}

}


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

public class Main
{

    static class InputReader {

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, 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 ni() {
			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 long nl() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

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

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

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

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

	}

    static long mod=1000000007;
    static BigInteger bigInteger = new BigInteger("1000000007");
    static int n = (int)1e6;
    static boolean[] prime;
    static ArrayList<Integer> as;
    static void sieve() {
			Arrays.fill(prime	, true);
			prime[0] = prime[1] = false;
			for(int i = 2 ; i * i <= n ; ++i) {
				if(prime[i]) {
					for(int k = i * i; k< n ; k+=i) {
						prime[k] = false;
					}
				}
			}

		}

    public static void main(String[] args)
    {

        InputReader sc = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);

        //prime  = new boolean[n + 1];
		//sieve();
		//prime[1] = false;
		/*
		as = new ArrayList<>();
		for(int i=2;i<=1000000;i++)
		{
		    if(prime[i])
		    as.add(i);
		}
		*/

       /*

	long a = sc.nl();

            BigInteger ans = new BigInteger("1");
            for (long i = 1; i < Math.sqrt(a); i++) {
                if (a % i == 0) {
                    if (a / i == i) {
                        ans = ans.multiply(BigInteger.valueOf(phi(i)));

                    } else {
                        ans = ans.multiply(BigInteger.valueOf(phi(i)));
                        ans = ans.multiply(BigInteger.valueOf(phi(a / i)));

                    }

                }
            }
            w.println(ans.mod(bigInteger));

            */
        long m = sc.nl();
        int one = 0;
        long res = 0;
        int temp = 0;
        int zero = 0;
        for(long i = m;i>=1;i--)
        {
            if(m % i == 0)
            {
                one = 0;
                zero = 0;
                temp = 0;
               String s = Long.toBinaryString(i);
               for(int j=0;j<s.length();j++)
               {
                   if(s.charAt(j)=='1')
                   {
                       one++;
                   }

                   else
                   {
                       temp = j;
                       break;
                   }

               }
               for(int j=temp;j<s.length();j++)
               {
                   if(s.charAt(j)=='0')
                   {
                       zero++;
                   }

                   else
                   {

                       break;
                   }

               }

               if(one + zero == s.length() && one == zero+1)
               {
                   res = i;
                   break;
               }

            }

        }
        w.println(res);

w.close();

    }

     public static long modMultiply(long one, long two) {

		return (one % mod * two % mod) % mod;
	}
    static long fx(int m)
    {
        long re = 0;
        for(int i=1;i<=m;i++)
        {
            re += (long) (i / gcd(i,m));
        }
        return re;
    }
     static long gcd(long a, long b)
    {
	 if (a == 0)
	  return b;

	return gcd(b%a, a);
    }

     static long phi(long nx)
    {
        // Initialize result as n
        double result = nx;

        // Consider all prime factors of n and for
        // every prime factor p, multiply result
        // with (1 - 1/p)
        for (int p = 0; as.get(p) * as.get(p) <= nx; ++p)
        {
            // Check if p is a prime factor.
            if (nx % as.get(p) == 0)
            {
                // If yes, then update n and result
                while (nx % as.get(p) == 0)
                    nx /= as.get(p);
                result *= (1.0 - (1.0 / (double) as.get(p)));
            }
        }

        // If n has a prime factor greater than sqrt(n)
        // (There can be at-most one such prime factor)
        if (nx > 1)
            result *= (1.0 - (1.0 / (double) nx));

        return (long)result;

        //return(phi((long)result,k-1));

    }

    public static int primeFactors(int n)
    {
        int sum = 0;
        // Print the number of 2s that divide n
        while (n%2==0)
        {
            sum = 1;
            //System.out.print(2 + " ");
            n /= 2;
        }

        // n must be odd at this point.  So we can
        // skip one element (Note i = i +2)
        for (int i = 3; i <= Math.sqrt(n); i+= 2)
        {
            // While i divides n, print i and divide n
            while (n%i == 0)
            {

               // System.out.print(i + " ");
                n /= i;
            }
            sum++;
        }

        // This condition is to handle the case whien
        // n is a prime number greater than 2
        if (n > 2)
            sum++;
            return sum;
    }
    static int digitsum(int x)

    {

        int sum = 0;
        while(x > 0)
        {
            int temp = x % 10;
            sum += temp;
            x /= 10;
        }
        return sum;

    }
    static int countDivisors(int n)
    {
        int cnt = 0;
        for (int i = 1; i*i <=n; i++)
        {
             if (n % i == 0 && i<=1000000)
             {
                // If divisors are equal,
                // count only one
                if (n / i == i)
                   cnt++;

                else // Otherwise count both
                    cnt = cnt + 2;
             }
         }
        return cnt;
    }

    static boolean isprime(int n)
    {

    if(n == 2)
        return true;
    if(n == 3)
        return true;
    if(n % 2 == 0)
        return false;
    if(n % 3 == 0)
        return false;

    int i = 5;
   int w = 2;

    while(i * i <= n)
    {
        if(n % i == 0)
            return false;

        i += w;
        w = 6 - w;
    }

    return true;
    }

    static long log2(long value) {
    return Long.SIZE-Long.numberOfLeadingZeros(value);
}

    static int binarysearch(int []arr,int p,int n)
    {

        int st = 0;
        int end = n-1;
        int mid = (st + end)/2;
        int temp = 0;
        while(st < end)
        {
            mid = (st + end)/2;

            if(p > arr[mid])
            {
                st = mid+1;

            }
            else if(p < arr[mid])
            {
                end = mid;

            }
            else if(p == arr[mid])
            {
            temp = mid;
            break;
            }

        }
        if(st == end)
        temp = st;

        return temp;
    }

    static class Student
    {

        int floor;
        int time;
        Student(int floor,int time)
        {
            this.floor = floor;
            this.time = time;

        }

    }

    public static int ip(String s){
		return Integer.parseInt(s);
	}
	 public static String ips(int s){
		return Integer.toString(s);
	}

}


import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

public class Main {
    static BufferedReader newInput() throws IOException {
        return new BufferedReader(new InputStreamReader(System.in));
    }
    static PrintWriter newOutput() throws IOException {
        return new PrintWriter(System.out);
    }
    public static void main(String[] args) throws IOException {
        BufferedReader in = newInput();
        PrintWriter out = newOutput();
        function(in, out);
        out.flush();
    }
    public static void function(BufferedReader in, PrintWriter out) throws IOException {
        //StringTokenizer t = new StringTokenizer(in.readLine());
        String[] nk = in.readLine().split(" ");
        long n = Integer.parseInt(nk[0]);
        long k = Long.parseLong(nk[1]);

        ArrayList<Integer> nums = new ArrayList<>();
        for (int i = Math.max(1, (int)n-13); i <= (int)n; i++) {
            nums.add(i);
        }

        long fact = factorial(Math.min(n, 14));
        long x = Math.min(n, 14);
        int lucks = lucks(Math.max(1, (int)n-13));

        for (int i = Math.max(1, (int)n-13); i <= n; i++) {
            fact /= x;
            x--;
            int b = (int)((k-1)/fact);
            if (b >= n){
                out.println("-1");
                return;
            }
            k -= (b*fact);
            int num = nums.get(b);
            nums.remove(b);
            if (isLucky(num) && isLucky(i)){
                lucks++;
            }
        }
        out.println(lucks);
    }
    public static long factorial(long num){
        long x = num;
        num--;
        for (;num != 0; num--) {
            x *= num;
        }
        return x;
    }
    public static boolean isLucky(int x){
        for (; x != 0; x /= 10) {
            int b = x % 10;
            if (b != 7 && b != 4){
                return false;
            }
        }
        return true;
    }
    public static int lucks(int max){
        int lucks = 0;
        ArrayList<Integer> luckys = new ArrayList<>();
        luckys.add(4);
        luckys.add(7);
        for (int i = 0; i < 8; i++) {
            luckys = add(luckys);
        }
        for (int i : luckys) {
            if (i < max){
                lucks++;
            }
        }
        return lucks;
    }
    public static int prev = 0;
    public static ArrayList<Integer> add(ArrayList<Integer> lucks){
        int len = lucks.size();
        for (int i = prev; i < len; i++) {
            lucks.add(lucks.get(i)+(int)(4*Math.pow(10, String.valueOf(lucks.get(i)).length())));
        }
        for (int i = prev; i < len; i++) {
            lucks.add(lucks.get(i)+(int)(7*Math.pow(10, String.valueOf(lucks.get(i)).length())));
        }
        prev = len;
        return lucks;
    }
}


import java.util.Scanner;

public class T1 {

	public static void main(String[] args) {
		Scanner jk=new Scanner(System.in);
		int n=jk.nextInt();
		int[] arr=new int[100];
		for (int i=0;i<n;i++){
			int tmp=jk.nextInt();
			arr[tmp-1]++;
		}
		boolean flag=false;
		int res1=0;
		int res2=0;
		for (int i=0;i<100;i++){
			for (int j=0;j<100;j++){
				if ((arr[i]==arr[j])&&(arr[i]!=0)&&(i!=j)){
					flag=true;
					res1=i+1;
					res2=j+1;
					break;

				}
			}
		}
		jk.close();

		if (flag){
			if (arr[res1-1]+arr[res2-1]!=n)
			{
				System.out.println("NO");
			}
			else
		{
			System.out.println("YES");
			System.out.println(res1+" "+res2);}}
		else{
			System.out.println("NO");
		}
	}

}


import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

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

	long n,k;

	public Main() throws Exception{
		Scanner sc = new Scanner(System.in);
//		Scanner sc = new Scanner(new FileReader("input"));
		n = sc.nextLong();
		k = sc.nextLong();
		if ( k==0){
			System.out.println("0 0");
			sc.close();
			return;
		}

		System.out.println( Math.min(1, n-k) + " " + Math.min(k*2, n-k));

        sc.close();
	}

	static long gcd(long a, long b)
	{
	    while (b > 0)
	    {
	        long temp = b;
	        b = a % b;
	        a = temp;
	    }
	    return a;
	}

	static long lcm(long a, long b) {
	    return a * (b / gcd(a, b));
	}

}


import java.util.Scanner;

//import TetraHedron.Scanner;

public class SquaresandSegements {

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

		Scanner input = new Scanner(System.in);
		long n = input.nextLong();
		long val = (long)Math.sqrt(n);
		long total = 2*val;
	//	System.out.println(total);
		long rem = n - (long)Math.pow((long)Math.sqrt(n),2);
		///System.out.println(rem);
		total += (long)Math.ceil(rem/Math.sqrt(n));
		System.out.println(total);
	}

}


import java.util.Scanner;

/**
 * B. File Name
 * @author satyam
 *uxxxxxlmexxxxxxxwnxxexxxxxcxxfydxxxxxxvmdxxxxxxisxxxxxxxxidkxxxpxxxxxxxxmnuxxxxjxxxqcxxwmxxxxxxxxmrx
 */
public class CodeForces16 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a= Integer.parseInt(sc.nextLine());
		String str=sc.nextLine();
		int res=0,counter=0;
		for(int i=0;i<a;i++) {
			if(str.charAt(i)=='x') {
				counter++;
			}else if(counter>2){
				res+=(counter-2);
				counter=0;
			}else {
				counter=0;
			}
		}
		if(counter>2) res+=(counter-2);
		System.out.println(res);
	}
}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String s = sc.next();

        char[] c = s.toCharArray();

        char a = 'a';

        int total = 0;

        for (int i = 0; i < c.length; i++) {
            if (Math.abs(c[i] - a) <= 13) {
                total += Math.abs(c[i] - a);
                a = c[i];
            }else{
                total += 26 - Math.abs((c[i] - a));
                a = c[i];
            }
        }

        System.out.println(total);

    }
}

//https://codeforces.com/problemset/problem/731/A


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

import static java.lang.Math.*;

public class Main implements Runnable {

	int s;
	int c3 = 0, c4 = 0, c5 = 0;

	int f(int k3, int k4) {
		int k5 = (s - k3 * c3 - k4 * c4) / c5;
		return abs(c3 * k3 - c4 * k4) + abs(c4 * k4 - c5 * k5);
	}

	void solve() throws Exception {
		int n = sc.nextInt();
		s = sc.nextInt();
		for (int i = 0; i < n; i++) {
			int mark = sc.nextInt();
			if (mark == 3) {
				c3++;
			} else if (mark == 4) {
				c4++;
			} else if (mark == 5) {
				c5++;
			}
		}
		ArrayList<Integer>[] may = new ArrayList[c5];
		for (int i = 0; i < c5; i++) {
			may[i] = new ArrayList<Integer>();
			for (int j = 0; j < c5; j++) {
				if ((c3 * i + c4 * j) % c5 == s % c5) {
					may[i].add(j);
				}
			}
		}
		int bestk3 = -1, bestk4 = -1, bestk5 = -1;
		int bestf = Integer.MAX_VALUE / 2;
		for (int k3 = 0; k3 * c3 <= s; k3++) {
			if (may[k3 % c5].size() == 0) {
				continue;
			}
			ArrayList<Integer> cmay = may[k3 % c5];
			int ll = -1, rr = 500000;
			while (rr - ll > 1) {
				int mm = (ll + rr) / 2;
				int valm = cmay.get(mm % cmay.size()) + mm / cmay.size() * c5;
				if (valm < k3) {
					ll = mm;
				} else {
					rr = mm;
				}
			}
			int l = rr;
			ll = -1;
			rr = 500000;
			while (rr - ll > 1) {
				int mm = (ll + rr) / 2;
				long valm = cmay.get(mm % cmay.size()) + mm / cmay.size() * c5;
				if ((s - k3 * c3 - valm * c4) >= c5 * valm) {
					ll = mm;
				} else {
					rr = mm;
				}
			}
			int r = ll;
			if (l > r) {
				continue;
			}
			while (r - l >= 3) {
				int m1 = l + (r - l) / 3;
				int m2 = r - (r - l) / 3;
				int f1 = f(k3, cmay.get(m1 % cmay.size()) + m1 / cmay.size() * c5);
				int f2 = f(k3, cmay.get(m2 % cmay.size()) + m2 / cmay.size() * c5);
				if (f1 >= f2) {
					l = m1;
				} else {
					r = m2;
				}
			}
			for (int i = l; i <= r; i++) {
				int k4 = cmay.get(i % cmay.size()) + i / cmay.size() * c5;
				int k5 = (s - k3 * c3 - k4 * c4) / c5;
				int fi = f(k3, k4);
				if (fi < bestf) {
					bestk3 = k3;
					bestk4 = k4;
					bestk5 = k5;
					bestf = fi;
				}
			}
		}
		if (bestk3 != -1) {
			out.println(bestk3 + " " + bestk4 + " " + bestk5);
		} else {
			out.println(-1);
		}
	}

	BufferedReader in;
	PrintWriter out;
	FastScanner sc;

	static Throwable uncaught;

	@Override
	public void run() {
		try {
			//System.setOut(new PrintStream("test.txt"));
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			sc = new FastScanner(in);
			solve();
		} catch (Throwable t) {
			Main.uncaught = t;
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) throws Throwable {
		Thread t = new Thread(null, new Main(), "", 128 * 1024 * 1024);
		t.start();
		t.join();
		if (uncaught != null) {
			throw uncaught;
		}
	}

}

class FastScanner {

	BufferedReader reader;
	StringTokenizer strTok;

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

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

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

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

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

}


import java.io.*;
import java.util.*;
public class wolf{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		sc.nextLine();
		char arr[][]=new char[15][15];
		for(int i=0;i<n;i++)
		{
			String data=sc.nextLine();
			for(int j=0;j<m;j++)
			{
				arr[i][j]=data.charAt(j);
				//sc.nextLine();
			}
		}
		int k=0;

		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				if(arr[i][j]=='W')
				{
					if( i>0 &&arr[i-1][j]=='P'  )
					{
						arr[i-1][j]='.';
						k++;
					}
					else if((i+1)<n&& arr[i+1][j]=='P')
					{
						arr[i+1][j]='.';
						k++;
					}
					else if(j>0&&arr[i][j-1]=='P' )
					{
						arr[i][j-1]='.';
						k++;
					}
					else if((j+1)<m&&arr[i][j+1]=='P' )
					{
						arr[i][j+1]='.';
						k++;
					}
				}
			}
		}
		System.out.println(k);
	}
}


import java.util.*;
import java.io.*;
import java.io.File;
import java.util.AbstractSet;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class Hello {

  public static void main(String[] args) {
    //try {
    //  FileInputStream fis = new FileInputStream("data.txt");
    //  System.setIn(fis);
      Scanner in = new Scanner(System.in);

      int n = in.nextInt();
      System.out.println(n / 2 + 1);

    //} catch (FileNotFoundException e){
    //  System.out.println("error");
    //}
  }
}


import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.HashMap;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Random;
import java.util.TreeSet;
import java.util.StringTokenizer;
import java.util.Collections;
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);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskD {
    static class Point {
        int x;
        int y;
        int index;

        Point(int x, int y, int index) {
            this.x = x;
            this.y = y;
            this.index = index;
        }
    }

    static class GraphNode implements Comparable<GraphNode> {
        int sideId;
        int x;
        double y;
        double distance = 1e100;
        boolean mark = false;

        List<GraphNode> outgo = new ArrayList<GraphNode>();

        GraphNode(int sideId, int x) {
            this.sideId = sideId;
            this.x = x;
        }

        public boolean equals(Object o) {
            if (this == o) return true;
            GraphNode graphNode = (GraphNode) o;

            if (sideId != graphNode.sideId) return false;
            if (x != graphNode.x) return false;

            return true;
        }

        public int hashCode() {
            int result = sideId;
            result = 31 * result + x;
            return result;
        }

        public int compareTo(GraphNode graphNode) {
            int z = sideId - graphNode.sideId;
            if (z != 0) return z;
            return x - graphNode.x;
        }
    }

    List<GraphNode> nodes = new ArrayList<GraphNode>();
    Map<GraphNode, GraphNode> canonical = new HashMap<GraphNode, GraphNode>();

    static class Edge implements Comparable<Edge> {
        Point v1;
        Point v2;
        int isUpper;

        Edge(Point v1, Point v2) {
            if (v1.x > v2.x) {
                Point tmp = v1;
                v1 = v2;
                v2 = tmp;
            }
            this.v1 = v1;
            this.v2 = v2;
        }

        public int compareTo(Edge edge) {
            int minx = Math.max(v1.x, edge.v1.x);
            int maxx = Math.min(v2.x, edge.v2.x);
            if (minx >= maxx) {
                throw new RuntimeException();
            }
            //if (this.v1 == edge.v1 && this.v2 == edge.v2) return 0;
            int mid = (minx + maxx) / 2;
            long diff = ((mid - v1.x) * (long) (v2.y - v1.y) + v1.y * (long) (v2.x - v1.x)) * (edge.v2.x - edge.v1.x)
                    - ((mid - edge.v1.x) * (long) (edge.v2.y - edge.v1.y) + edge.v1.y * (long) (edge.v2.x - edge.v1.x)) * (v2.x - v1.x);
            return Long.signum(diff);
        }
    }

    int n;

	public void solve(int testNumber, InputReader in, PrintWriter out) {
        Random random = new Random(5943715431L);
        n = in.nextInt();
        Point[] poly = new Point[n];
        for (int i = 0; i < n; ++i) {
            int x = in.nextInt();
            int y = in.nextInt();
            poly[i] = new Point(x * 2, y * 2, i);
        }
        for (int i = 0; i < poly.length; ++i) {
            Edge e1 = new Edge(poly[i], poly[(i + 1) % poly.length]);
            Edge e2 = new Edge(poly[i], poly[(i + poly.length - 1) % poly.length]);
            addTransition(e1, e2, poly[i].x);
            addTransition(e2, e1, poly[i].x);
        }
        int s = in.nextInt() - 1;
        int t = in.nextInt() - 1;
        TreeSet<Edge> picture = new TreeSet<Edge>();
        Point[] polyByX = poly.clone();
        for (int i = 0; i < polyByX.length; ++i) {
            int j = i + random.nextInt(polyByX.length - i);
            Point tmp = polyByX[i];
            polyByX[i] = polyByX[j];
            polyByX[j] = tmp;
        }
        Arrays.sort(polyByX, new Comparator<Point>() {
            public int compare(Point a, Point b) {
                int z = Integer.signum(a.x - b.x);
                if (z != 0) return z;
                return Integer.signum(a.y - b.y);
            }
        });
        for (int pi = 0; pi < polyByX.length;) {
            int pj;
            Point prevP = null;
            for (pj = pi; pj < polyByX.length && polyByX[pj].x == polyByX[pi].x; ++pj) {
                Point p = polyByX[pj];
                Point a = poly[(p.index + 1) % poly.length];
                Point b = poly[(p.index + poly.length - 1) % poly.length];
                if (a.x > b.x || (a.x == b.x && a.y > b.y)) {
                    Point tmp = a;
                    a = b;
                    b = tmp;
                }
                if (a.x < p.x && b.x < p.x) {
                    if ((a.x - p.x) * (long) (b.y - p.y) - (a.y - p.y) * (long) (b.x - p.x) < 0) {
                        Point tmp = a;
                        a = b;
                        b = tmp;
                    }
                    Edge bEdge = picture.floor(new Edge(b, p));
                    if (bEdge.isUpper == 2) {
                        Edge dest = picture.lower(bEdge);
                        double destY = addTransition(bEdge, dest, p.x);
                        if (prevP != null) {
                            if (prevP.y > destY) {
                                getNodeFor(poly, p.index).outgo.add(getNodeFor(poly, prevP.index));
                            }
                        }
                    }
                    Edge aEdge = picture.floor(new Edge(a, p));
                    if (aEdge.isUpper == 1) {
                        Edge dest = picture.higher(aEdge);
                        addTransition(dest, aEdge, p.x);
                    }
                } else if (a.x < p.x && b.x > p.x) {
                    Edge aEdge = picture.floor(new Edge(a, p));
                    if (aEdge.isUpper == 1) {
                        Edge dest = picture.higher(aEdge);
                        addTransition(dest, aEdge, p.x);
                    } else {
                        Edge dest = picture.lower(aEdge);
                        double destY = addTransition(aEdge, dest, p.x);
                        if (prevP != null) {
                            if (prevP.y > destY) {
                                getNodeFor(poly, p.index).outgo.add(getNodeFor(poly, prevP.index));
                            }
                        }
                    }
                } else if (a.x < p.x && b.x == p.x) {
                    Edge aEdge = picture.floor(new Edge(a, p));
                    if (aEdge.isUpper == 1 && b.y < p.y) {
                        Edge dest = picture.higher(aEdge);
                        addTransition(dest, aEdge, p.x);
                    } else if (aEdge.isUpper == 2 && b.y > p.y) {
                        Edge dest = picture.lower(aEdge);
                        double destY = addTransition(aEdge, dest, p.x);
                        if (prevP != null) {
                            if (prevP.y > destY) {
                                getNodeFor(poly, p.index).outgo.add(getNodeFor(poly, prevP.index));
                            }
                        }
                    }
                }
                prevP = p;
            }
            for (pj = pi; pj < polyByX.length && polyByX[pj].x == polyByX[pi].x; ++pj) {
                Point p = polyByX[pj];
                Point a = poly[(p.index + 1) % poly.length];
                Point b = poly[(p.index + poly.length - 1) % poly.length];
                if (a.x < p.x) {
                    Edge toRemove = new Edge(a, p);
                    if (!picture.remove(toRemove)) throw new RuntimeException();
                }
                if (b.x < p.x) {
                    Edge toRemove = new Edge(b, p);
                    if (!picture.remove(toRemove)) {
                        throw new RuntimeException();
                    }
                }
            }
            for (pj = pi; pj < polyByX.length && polyByX[pj].x == polyByX[pi].x; ++pj) {
                Point p = polyByX[pj];
                Point a = poly[(p.index + 1) % poly.length];
                Point b = poly[(p.index + poly.length - 1) % poly.length];
                if ((a.x - p.x) * (long) (b.y - p.y) - (a.y - p.y) * (long) (b.x - p.x) < 0) {
                    Point tmp = a;
                    a = b;
                    b = tmp;
                }
                if (a.x > p.x) {
                    Edge toAdd = new Edge(a, p);
                    Edge prev = picture.lower(toAdd);
                    if (prev == null)
                        toAdd.isUpper = 1;
                    else
                        toAdd.isUpper = 3 - prev.isUpper;
                    if (!picture.add(toAdd)) throw new RuntimeException();
                }
                if (b.x > p.x) {
                    Edge toAdd = new Edge(b, p);
                    Edge prev = picture.lower(toAdd);
                    if (prev == null)
                        toAdd.isUpper = 1;
                    else
                        toAdd.isUpper = 3 - prev.isUpper;
                    if (!picture.add(toAdd)) throw new RuntimeException();
                }
            }
            prevP = null;
            for (pj = pi; pj < polyByX.length && polyByX[pj].x == polyByX[pi].x; ++pj) {
                Point p = polyByX[pj];
                Point a = poly[(p.index + 1) % poly.length];
                Point b = poly[(p.index + poly.length - 1) % poly.length];
                if (a.x > b.x || (a.x == b.x && a.y > b.y)) {
                    Point tmp = a;
                    a = b;
                    b = tmp;
                }
                if (a.x > p.x && b.x > p.x) {
                    if ((a.x - p.x) * (long) (b.y - p.y) - (a.y - p.y) * (long) (b.x - p.x) > 0) {
                        Point tmp = a;
                        a = b;
                        b = tmp;
                    }
                    Edge bEdge = picture.floor(new Edge(b, p));
                    if (bEdge.isUpper == 2) {
                        Edge dest = picture.lower(bEdge);
                        double destY = addTransition(bEdge, dest, p.x);
                        if (prevP != null) {
                            if (prevP.y > destY) {
                                getNodeFor(poly, p.index).outgo.add(getNodeFor(poly, prevP.index));
                            }
                        }
                    }
                    Edge aEdge = picture.floor(new Edge(a, p));
                    if (aEdge.isUpper == 1) {
                        Edge dest = picture.higher(aEdge);
                        addTransition(dest, aEdge, p.x);
                    }
                } else if (a.x == p.x && b.x > p.x) {
                    Edge bEdge = picture.floor(new Edge(b, p));
                    if (bEdge.isUpper == 1 && a.y < p.y) {
                        Edge dest = picture.higher(bEdge);
                        addTransition(dest, bEdge, p.x);
                    } else if (bEdge.isUpper == 2 && a.y > p.y) {
                        Edge dest = picture.lower(bEdge);
                        double destY = addTransition(bEdge, dest, p.x);
                        if (prevP != null) {
                            if (prevP.y > destY) {
                                getNodeFor(poly, p.index).outgo.add(getNodeFor(poly, prevP.index));
                            }
                        }
                    }
                }
                prevP = p;
            }
            pi = pj;
        }
        GraphNode start = getNodeFor(poly, s);
        GraphNode finish = getNodeFor(poly, t);
        Collections.sort(nodes);
        for (int i = 0; i + 1 < nodes.size(); ++i) {
            GraphNode n1 = nodes.get(i);
            GraphNode n2 = nodes.get(i + 1);
            if (n1.sideId == n2.sideId) {
                n1.outgo.add(n2);
                n2.outgo.add(n1);
            }
        }
        TreeSet<Reach> reaches = new TreeSet<Reach>();
        start.distance = 0;
        reaches.add(new Reach(start, 0));
        while (true) {
            Reach first = reaches.pollFirst();
            if (first.dest.mark) continue;
            first.dest.mark = true;
            if (first.dest == finish) {
                out.println(first.dest.distance / 2.0);
                return;
            }
            for (GraphNode other : first.dest.outgo) {
                double dx = first.dest.x - other.x;
                double dy = first.dest.y - other.y;
                double dd = Math.sqrt(dx * dx + dy * dy);
                double nd = first.dest.distance + dd;
                if (nd < other.distance - 1e-10) {
                    other.distance = nd;
                    reaches.add(new Reach(other, other.distance));
                }
            }
        }
	}

    private GraphNode getNodeFor(Point[] poly, int s) {
        GraphNode start;
        {
            Point sp = poly[s];
            Point spa = poly[(s + 1) % poly.length];
            Point spb = poly[(s + poly.length - 1) % poly.length];
            if (spa.x != sp.x || spa.y > sp.y) {
                start = createNode(new Edge(sp, spa), sp.x);
            } else {
                start = createNode(new Edge(sp, spb), sp.x);
            }
        }
        return start;
    }

    static class Reach implements Comparable<Reach> {
        GraphNode dest;
        double d;

        Reach(GraphNode dest, double d) {
            this.dest = dest;
            this.d = d;
        }

        public int compareTo(Reach reach) {
            if (d != reach.d) return Double.compare(d, reach.d);
            return dest.compareTo(reach.dest);
        }
    }

    private double addTransition(Edge top, Edge bottom, int x) {
        GraphNode src = createNode(top, x);
        GraphNode dst = createNode(bottom, x);
        src.outgo.add(dst);
        return dst.y;
    }

    private GraphNode createNode(Edge top, int x) {
        GraphNode src;
        {
            int i1 = top.v1.index;
            int i2 = top.v2.index;
            int i;
            if (i1 + 1 == i2 || i1 + 1 == i2 + n) {
                i = i1;
            } else if (i2 + 1 == i1 || i2 + 1 == i1 + n) {
                i = i2;
            } else {
                throw new RuntimeException();
            }
            src = new GraphNode(i, x);
            GraphNode canonicalSrc = canonical.get(src);
            if (canonicalSrc == null) {
                canonical.put(src, src);
                nodes.add(src);
                if (top.v1.x == top.v2.x)
                    src.y = Math.min(top.v1.y, top.v2.y);
                else
                    src.y = (x - top.v1.x) / (double) (top.v2.x - top.v1.x) * (top.v2.y - top.v1.y) + top.v1.y;
            } else {
                src = canonicalSrc;
            }
        }
        return src;
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        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.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.StringTokenizer;
import java.util.TreeMap;

/**
 *
 *
 *
 * @author pttrung
 */
public class D {

    public static long MOD = 1000000007;
    public static ArrayList<Integer> p;

    public static void main(String[] args) {
        Scanner in = new Scanner();
        PrintWriter out = new PrintWriter(System.out);
        long a = in.nextLong();
        long b = in.nextLong();
        long k = in.nextLong();
        boolean[] prime = new boolean[10000000];
        p = new ArrayList();
        ArrayList<Integer> list = new ArrayList();
        for (int i = 2; i < prime.length; i++) {
            if (!prime[i]) {
                p.add( i);
                if (i < k) {
                    list.add(i);
                }
                for (int j = i * i; j < prime.length; j += i) {
                    if (j < 0) {
                        break;
                    }
                    prime[j] = true;

                }
            }
        }
        boolean ok = true;
        if (k < prime.length) {
            if (prime[(int) k]) {
                out.println(0);
                ok = false;
            }
        } else {
            if (!isPrime(k)) {
                out.println(0);
                ok = false;
            }
        }
//        for(long val : p){
//            System.out.println("Prime " + val);
//        }
        // p.add(k);
        if (ok) {
            long left = cal(list.size() - 1, list, b/k);
            long right = cal(list.size() - 1, list, (a - 1)/k);
            //out.println(left + " " + right);
            out.println((left - right));
        }
        out.close();
    }

    public static boolean isPrime(long val) {
        int index = 1;
        int prime = p.get(0);
        while(prime*prime <= val && index < p.size()){
            if(val% prime == 0){
                return false;
            }
            prime = p.get(index ++);
        }
        return true;
    }

    public static long cal(int index, ArrayList<Integer> val, long n) {

        if (n == 0 || index == -1) {
            return n;
        }
        return cal(index - 1, val, n) - cal(index - 1, val, n / val.get(index));
    }

    public static class Edge implements Comparable<Edge> {

        int x, y;

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

        @Override
        public int compareTo(Edge o) {
            if (x != o.x) {
                return x - o.x;
            } else {
                return y - o.y;
            }
        }
    }

    public static class FT {

        int[] data;

        FT(int n) {
            data = new int[n];
        }

        public void update(int index, int value) {
            while (index < data.length) {
                data[index] += value;
                index += (index & (-index));
            }
        }

        public int get(int index) {
            int result = 0;
            while (index > 0) {
                result += data[index];
                index -= (index & (-index));
            }
            return result;

        }
    }

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

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

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

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

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

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

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}


import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int aa = in.nextInt(), bb = in.nextInt();
        int cc = in.nextInt(), dd = in.nextInt();
        boolean a = aa == 1 ? true : false;
        boolean b = bb == 1 ? true : false;
        boolean c = cc == 1 ? true : false;
        boolean d = dd == 1 ? true : false;
        boolean one = a ^ b;
        boolean two = c | d;
        boolean three = b & c;
        boolean four = a ^ d;
        boolean five = one & two;
        boolean six = three | four;
        System.out.println(five ^ six ? 1 : 0);

        in.close();
    }
}


import java.util.Scanner;

public  final class ThreeGarlandsCF {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int k1=sc.nextInt();
        int k2=sc.nextInt();
        int k3=sc.nextInt();
        if(k1==1 || k2==1 || k3==1){
            System.out.println("YES");
        }else{
            int twoCount=0;
            int  threeCount=0;
            int fourCount=0;

            if(k1==2)
                twoCount++;
            else if(k1==3)
                threeCount++;
            else if(k1==4)
                fourCount++;

            if(k2==2)
                twoCount++;
            else if(k2==3)
                threeCount++;
            else if(k2==4)
                fourCount++;

            if(k3==2)
                twoCount++;
            else if(k3==3)
                threeCount++;
            else if(k3==4)
                fourCount++;

            if(twoCount>=2 || threeCount==3 || (twoCount==1 && fourCount==2))
                System.out.println("YES");
            else
                System.out.println("NO");
        }
    }
}


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

/**
 * stescobedo
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        FNezzarAndChocolateBars solver = new FNezzarAndChocolateBars();
        solver.solve(1, in, out);
        out.close();
    }

    static class FNezzarAndChocolateBars {
        static final int MAXN = 2048;
        static final int modulo = 998244353;

        public int add(int x, int y) {
            x += y;
            if (x >= modulo) x -= modulo;
            return x;
        }

        public int subtract(int x, int y) {
            x -= y;
            if (x < 0) x += modulo;
            return x;
        }

        public int multiply(int x, int y) {
            return (int) ((x * 1L * y) % modulo);
        }

        public int power(int x, long y) {
            int ans = 1;
            for (; y > 0; y >>= 1, x = (int) ((x * 1L * x) % modulo))
                if (y % 2 == 1) ans = (int) ((ans * 1L * x) % modulo);
            return ans;
        }

        public int inverse(int x) {
            return power(x, modulo - 2);
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int[] fact = new int[MAXN];
            int[] ifact = new int[MAXN];
            fact[0] = ifact[0] = 1;
            for (int i = 1; i < MAXN; i++) {
                fact[i] = multiply(fact[i - 1], i);
                ifact[i] = inverse(fact[i]);
            }
            int n = in.nextInt(), k = in.nextInt();
            int[] l = in.readIntArray(n);
            int[][][] dp = new int[2][MAXN][n + 1];
            dp[1][0][0] = 1;
            int s = 0;

            for (int p = 0; p < n; p++) {
                int L = l[p];
                int invL = inverse(L);
                int[] coeffs = new int[L / k + 1];
                int[] coeffs2 = new int[L / k + 1];
                for (int i = 0; i <= L / k; i++) {
                    if (k * i == L) continue;
                    int z = ifact[i];
                    if (i % 2 == 1) z = subtract(0, z);
                    coeffs[i] = multiply(z, power(L - k * i, i));

                    if (i >= 1) {
                        coeffs2[i] = multiply(z, multiply(i, power(L - k * i, i - 1)));
                    }
                }
                int r = p & 1;
                int h = r ^ 1;
                for (int i = 0; i <= s / k; i++) Arrays.fill(dp[r][i], 0);
                for (int i = 0; i <= s / k; i++)
                    for (int j = 0; j <= p; j++)
                        if (dp[h][i][j] != 0) {
                            int value = dp[h][i][j];
                            for (int t = 0; t <= L / k; t++) {
                                dp[r][i + t][j] = add(dp[r][i + t][j], multiply(value, coeffs[t]));
                                if (t > 0) {
                                    dp[r][i + t - 1][j + 1] = add(dp[r][i + t - 1][j + 1], multiply(value, coeffs2[t]));
                                }
                            }
                        }
                s += L;
            }
            int answer = 0;
            for (int i = 0; i <= s / k; i++)
                for (int r = 0; r <= n; r++) {
                    int value = dp[(n - 1) & 1][i][r];
                    int j = i + r;
                    if (j == 0) continue;
                    int temp = multiply(fact[i], inverse(power(k * j, i + 1)));
                    answer = add(answer, multiply(value, temp));
                }
            out.println(multiply(subtract(0, s), answer));
        }

    }

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

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

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

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

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

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

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

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

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

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

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

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

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

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

    }
}


import java.io.*;
import java.util.*;
import java.lang.*;
    public class templ {
    int binarySearch(int arr[], int l, int r, int x)
    {
        if (r >= l)
        {
            int mid = l + (r - l)/2;
            if (arr[mid] == x)
            return mid;
            if (arr[mid] > x)
            return binarySearch(arr, l, mid-1, x);
            return binarySearch(arr, mid+1, r, x);
        }
        return -1;
    }
    int partition(int arr[], int low, int high)
    {
        int pivot = arr[high];
        int i = (low-1); // index of smaller element
        for (int j=low; j<high; j++)
        {
            if (arr[j] <= pivot)
            {
                i++;
                int temp = arr[i];
                arr[i] = arr[j];
                arr[j] = temp;
            }
        }
        int temp = arr[i+1];
        arr[i+1] = arr[high];
        arr[high] = temp;
        return i+1;
    }
    void sort(int arr[], int low, int high)
    {
        if (low < high)
        {
            int pi = partition(arr, low, high);
            sort(arr, low, pi-1);
            sort(arr, pi+1, high);
        }
    }
    public static void main(String[] args) throws FileNotFoundException {
     try
     {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        templ ob=new templ();
        int n=in.nextInt();
        int a=in.nextInt();
        int odd[]=new int[n/2];
        int even[]=new int[n/2];
        int k=0;
        for(int i=1;i<=n;i=i+2)
        {
            odd[k]=i;
            k++;
        }
        k=0;
        for(int i=n;i>=2;i-=2)
        {
            even[k]=i;
            k++;
        }
        if(a%2==0)
        {
            int x=0;
            for(int i=0;i<n/2;i++)
            {
                if(even[i]==a)
                {
                    x=i;
                    break;
                }
            }
            out.println(x+1);
        }
        else
        {
            int x=0;
            for(int i=0;i<n/2;i++)
            {
                if(odd[i]==a)
                {
                    x=i;
                    break;
                }
            }
            out.println(x+1);
        }
        out.close();
    }
        catch(Exception e){
        return;
    }
    }
    static class InputReader {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;

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

        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 long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long 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 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 String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

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

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

    }
}


import java.util.*;
import java.lang.Math;
public class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s =sc.next();
	    int u=0;
	    int l=0;
	    int r=0;
	    int d=0;
	    for(int i=0;i<s.length();i++){
	        if(s.charAt(i)=='U') u++;
	        if(s.charAt(i)=='L') l++;
	        if(s.charAt(i)=='D') d++;
	        if(s.charAt(i)=='R') r++;
	    }

	    System.out.println(2*Math.min(l,r) + 2*Math.min(u,d));
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.util.ArrayDeque;
import java.io.InputStream;

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

    static class CGregAndFriends {
        long mod = 1000000007;
        long INF = (long) 1e18 + 1;
        PrintWriter out;
        InputReader in;
        long[][] nCr = new long[100][100];

        long f(long p, int a, int b, int c, int d) {
            p *= nCr[a][b];
            p %= mod;
            p *= nCr[c][d];
            p %= mod;
            return p;
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            int n = ni();
            int K = ni();
            int cnt1 = 0, cnt2 = 0;
            int i = 0, j = 0, k = 0;
            for (i = 0; i < 100; i++) {
                for (j = 0; j <= i; j++) {
                    if (j == 0 || j == i)
                        nCr[i][j] = 1;
                    else
                        nCr[i][j] = (nCr[i - 1][j] + nCr[i - 1][j - 1]) % mod;
                }
            }
            for (i = 0; i < n; i++) {
                if (ni() == 50)
                    cnt1++;
                else
                    cnt2++;
            }
            long[][][] dist = new long[200][200][2];
            long[][][] dp = new long[200][200][2];
            for (i = 0; i < 200; i++) {
                for (j = 0; j < 200; j++)
                    Arrays.fill(dist[i][j], INF);
            }
            dist[0][0][0] = 0;
            dp[0][0][0] = 1;
            ArrayDeque<Tuple> pq = new ArrayDeque<>();
            pq.add(new Tuple(0, 0, 0, 0));
            while (pq.size() > 0) {
                Tuple curr = pq.poll();
                int x = curr.x;
                int y = curr.y;
                int z = curr.z;
                long d = dist[x][y][z];
                if (z == 0) {
                    int rem_x = cnt1 - x;
                    int rem_y = cnt2 - y;
                    for (i = 0; i <= rem_x; i++) {
                        for (j = 0; j <= rem_y; j++) {
                            if (i + j == 0)
                                continue;
                            if (i * 50 + j * 100 > K)
                                break;
                            if (dist[i + x][j + y][z ^ 1] >= d + 1) {
                                if (dist[i + x][j + y][z ^ 1] > d + 1) {
                                    dist[i + x][j + y][z ^ 1] = d + 1;
                                    pq.add(new Tuple(dist[i + x][j + y][z ^ 1], i + x, j + y, z ^ 1));
                                    dp[i + x][j + y][z ^ 1] += f(dp[x][y][z], rem_x, i, rem_y, j);
                                    dp[i + x][j + y][z ^ 1] %= mod;
                                } else {
                                    dp[i + x][j + y][z ^ 1] += f(dp[x][y][z], rem_x, i, rem_y, j);
                                    dp[i + x][j + y][z ^ 1] %= mod;
                                }
                            }
                        }
                    }
                } else {
                    int rem_x = x;
                    int rem_y = y;
                    for (i = 0; i <= rem_x; i++) {
                        for (j = 0; j <= rem_y; j++) {
                            if (i + j == 0)
                                continue;
                            if (i * 50 + j * 100 > K)
                                break;
                            if (dist[x - i][y - j][z ^ 1] >= d + 1) {
                                if (dist[x - i][y - j][z ^ 1] > d + 1) {
                                    dist[x - i][y - j][z ^ 1] = d + 1;
                                    pq.add(new Tuple(dist[x - i][y - j][z ^ 1], x - i, y - j, z ^ 1));
                                    dp[x - i][y - j][z ^ 1] += f(dp[x][y][z], rem_x, i, rem_y, j);
                                    dp[x - i][y - j][z ^ 1] %= mod;
                                } else {
                                    dp[x - i][y - j][z ^ 1] += f(dp[x][y][z], rem_x, i, rem_y, j);
                                    dp[x - i][y - j][z ^ 1] %= mod;
                                }
                            }
                        }
                    }
                }
            }
            if (dist[cnt1][cnt2][1] == INF)
                pn(-1);
            else
                pn(dist[cnt1][cnt2][1]);
            pn(dp[cnt1][cnt2][1]);
        }

        int ni() {
            return in.nextInt();
        }

        void pn(long zx) {
            out.println(zx);
        }

        class Tuple {
            long d;
            int x;
            int y;
            int z;

            Tuple(long d, int x, int y, int z) {
                this.d = d;
                this.x = x;
                this.y = y;
                this.z = z;
            }

        }

    }

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

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

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

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

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

            return res.toString();
        }

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

    }
}


import java.io.*;
import java.util.*;
public class D9 {
	static long[][] ans;
	public static void main(String[] args) throws IOException	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ans = new long[36][36];
		for(int i = 0; i < 36; i++)
			Arrays.fill(ans[i], -1);
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int h = Integer.parseInt(st.nextToken());
		long ret = 0;
		for(int a = h; a <= n; a++)
			ret += solve(n,a);
		System.out.println(ret);
	}
	public static long solve(int n, int h)	{
		if(n < h || n >= (1L << h))
			return 0;
		if(n == 0 && h == 0)
			return 1;
		if(n == h){
			return 1L << (h-1);
		}
		if(ans[n][h] != -1)
			return ans[n][h];
		long ret = 0;
		for(int left = 0; left < n; left++)	{
			int right = n-1-left;
			for(int leftH = 0; leftH < h-1; leftH++)
				ret += solve(left, leftH) * solve(right, h-1);
			for(int rightH = 0; rightH < h-1; rightH++)
				ret += solve(left, h-1) * solve(right, rightH);
			ret += solve(left, h-1) * solve(right, h-1);
		}
		ans[n][h] = ret;
		return ret;
	}
}
// 27 11 should return 61162698256896
// initial returned    167110392320