//package contest;

import java.util.*;

public class test {
    public static String num;

    public static void main(String[] args) {
        // Scanner sc = new Scanner(System.in);
        // String line = sc.nextLine();
        // String[] str = line.split(" ");
        // num = str[0];
        // int []sorted = new int[num.length()];
        // Arrays.sort(sorted);
        // int swaps = Integer.parseInt(str[1]);

        // int nextMax;
        // while (swaps != 0) {
        // int max =0;
        // int maxPos=0;
        // int start=0;
        // for (int i = start; i < num.length() && i < swaps; i++) {
        // int current = Integer.parseInt(num.charAt(i) + "");
        // if(current > max){
        // max = current;
        // maxPos=i;
        // }
        // }//end for.
        // int newSwaps = swap(maxPos,swaps);
        // int diff= swaps -newSwaps;
        // swaps = newSwaps;
        // start = maxPos-diff+1;
        // System.out.println(start);
        // }//end while.
        // System.out.println(num);

        // num ="12345678";
        // swap(7,8);
        // System.out.println(num);

        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] str = line.split(" ");
        num = str[0];
        int swaps = Integer.parseInt(str[1]);
        int biggestNumInRange ;

        if (num.length() == 1) {
            //special case.
            System.out.println(num);
        } else {
            int start = 0;
            while (swaps > 0 &&start!=(num.length()-1)) {
//               System.out.println("swaps = "+swaps);

                biggestNumInRange=getBiggestNumInRange(start,swaps);
                // System.out.println(next);
                int newSwaps = swap(biggestNumInRange, swaps);
                int diff = swaps - newSwaps;
                swaps = newSwaps;
                start = biggestNumInRange - diff + 1;
                // System.out.println("start = "+start);
            }
            System.out.println(num);
        }//end if special case.
    }// end main

    public static int swap(int pos, int swaps) {
        // System.out.println(pos +" , "+swaps );
        int number = Integer.parseInt(num.charAt(pos) + "");
        int newPos = pos - 1;
        while ((newPos >= 0)
                && Integer.parseInt(num.charAt(newPos) + "") < number
                && swaps > 0) {
            swaps--;
            newPos--;

        }
        String newNum = "";
        for (int j = 0; j <= newPos; j++) {
            newNum += num.charAt(j);
        }
        newNum += number;
        for (int j = newPos + 1; j < pos; j++) {
            newNum += num.charAt(j);
        }
        for (int j = pos + 1; j < num.length(); j++) {
            newNum += num.charAt(j);
        }
        num = newNum;
        return swaps;
    }//end method.

    public static int getBiggestNumInRange(int start  , int limit){
        int biggestNumInRange=0;
        int loopNum = 9;
        while (loopNum >= 0) {
            for (int i = start; i < num.length()
                    && i <= (limit + start); i++) {
                // System.out.println(i+"    /////////////////////");
                int number = Integer.parseInt(num.charAt(i) + "");
                if (number == loopNum) {
//                   System.out.println(num.charAt(i)+" , "+i);
                    biggestNumInRange=i;
                }
            }
            loopNum--;
        }// end while
        return biggetNumInRange
    }//end method.
}// end class


import java.util.Scanner;

public class PashaMaximizes {
	static Scanner sc;
	static int n , k , m , b;
	static int mas[];
	static StringBuilder s;

	static void swap(int indexFirst,int indexSecond){
		char first = s.charAt(indexFirst);
		char second = s.charAt(indexSecond);
		/*s.setCharAt(indexFirst, second);
		s.setCharAt(indexSecond, first);*/
		s.deleteCharAt(indexSecond);
		s.insert(indexFirst, second);
	}

	public static void main(String[] args){
		sc = new Scanner(System.in);
		s = new StringBuilder(sc.next());
		k = sc.nextInt();
		char max;
		int start = 0;
		int index = 0;
		while ((k > 0) && (start < s.length())) {
			max = s.charAt(start);
			index = start;
			for (int i = start; i < Math.min(s.length(), start + k + 1); i++) {
				if (s.charAt(i) > max) {
					max = s.charAt(i);
					index = i;
				}
				if (max == '9') {
					index = i;
					break;
				}
			}
			if (index != start) {
				k = k - (index - start);
				swap(start, index);
				start++;
			} else {
				start++;
			}
		}
		System.out.println(s.toString());
	}


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

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

    static class TaskC {
        public void solve( int testNumber, Scanner in, PrintWriter out ) {
            long sum = in.nextLong();
            long xor = in.nextLong();

            long result = 0;

            for( long i = 1; i < sum; i++ ) {
                if( ( i ^ ( sum - i ) ) == xor ) {
                    result++;
                }
            }

            out.println( result );

        }

    }
}


import javax.swing.plaf.synth.SynthLookAndFeel;
import java.io.*;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;
public class CP {
    static Scanner sc = new Scanner(System.in);
    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 int lowerBound
    (Integer[] array, int length, int value) {
        int l = 0;
        int r = length;
        while (l < r) {
            int mid = (l + r) / 2;
            if (value < array[mid]) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }
        return l;
    }
    public static long gcd(long a, long b){
        if (b == 0)
            return a;
        else return gcd(b, a % b);
    }
    public static void main(String [] args) {
       // int T = sc.nextInt();while (T--!=0)
        {
            solve();
        }
    }
   static long n,k;
    static long sum(long x ){
        return x*(x+1)/2;
    }
    static long subsum(long ans){
        return sum(k)-sum(ans)+1;
    }
    public static void solve(){
///////////////////////////////////////////////////////////////////////////////////////////
             n=sc.nextInt();k=sc.nextInt();
             n--; k--;
             if(sum(k)<n){
                 System.out.println(-1);
                 return;
             }
             n++;k++;
             if(n==k ) {
                 System.out.println(1);
                 return;
             }
       // System.out.println(sum(k));
             long low =2,hi=k;
             while(low<=hi){
                 long mid = (low + hi)/2;
                // System.out.println(subsum(2));
                 if(subsum(mid)>n){
                     hi = mid-1;
                 }
                 else if(subsum(mid)<n){
                     low =mid;
                 }
                 else {
                     System.out.println(mid);
                     break;
                 }
             }
////////////////////////////////////////////////////////////////////////////////////////////
    }

}


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

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        ArrayList<Integer> a = new ArrayList<>();
        double greatest = 0;
        int count = 0;

        for (int i = 0; i < 8; i++) {
            int list = Integer.valueOf(scan.nextInt());
            a.add(list);
        }
        int ml = (a.get(1) * a.get(2)) / a.get(6);
        int lime = a.get(3) * a.get(4);

        double salt = Math.floor((double)a.get(5) / a.get(7));

        double mldiv = Math.floor((double)ml / a.get(0));
        double saltdiv = Math.floor(salt / a.get(0));
        double limediv = Math.floor(lime / a.get(0))

        for (int i = 0; i < 3; i++) {
            if (mldiv > limediv && mldiv > saltdiv) {
                greatest = mldiv;
            }
            if (limediv > mldiv && limediv > saltdiv) {
                greatest = limediv;
            }
            if (saltdiv > limediv && saltdiv > mldiv) {
                greatest = saltdiv;
            }
        }

        for (int i = 0; i < greatest; i++) {
            if (mldiv != 0 && limediv != 0 && saltdiv != 0) {
                count++;
                mldiv--;
                limediv--;
                saltdiv--;

            }
        }
        System.out.println(count);

    }
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;

import java.util.StringTokenizer;

 public class Test
 {
     static PrintWriter pw = new PrintWriter(System.out);
     static ArrayList<Long> list = new ArrayList();

    public static void main(String[] args)throws Exception
    {
        Reader.init(System.in);
        long x = Reader.nextLong();
        long y = Reader.nextLong();
        long L = Reader.nextLong();
        long R = Reader.nextLong();

        ArrayList<Long> ar1 = new ArrayList();
        ArrayList<Long> ar2 = new ArrayList();
        long num = 1;

        while(num <= 1e18)
        {
            ar1.add(num);
            num *= x;
        }

        num = 1;

        while(num <= 1e18)
        {
            ar2.add(num);
            num *= y;
        }

        for(int i = 0 ; i<ar1.size() ; i++)
            for(int j = 0 ; j<ar2.size() ; j++)
            {
                long z = ar1.get(i) + ar2.get(j);
                if(z >= L && z<=R)
                    list.add(z);
            }

        Collections.sort(list);
        long res = 0;
        if(list.get(0) - L > res)
        {
            res = list.get(0) - L;

        }

        if(R - list.get(list.size() - 1) > res)
        {
            res = R - list.get(list.size() - 1);

        }

        for(int i = 0 ; i<list.size() - 1 ; i++)
        {
            long a = list.get(i);
            long b = list.get(i + 1);

            if(b - a - 1 > res)
                res = b - a - 1;
        }

        pw.print(res);
        pw.close();

    }

}

class Reader {

    static BufferedReader reader;
    static StringTokenizer tokenizer;

    public static int pars(String x) {
        int num = 0;
        int i = 0;
        if (x.charAt(0) == '-') {
            i = 1;
        }
        for (; i < x.length(); i++) {
            num = num * 10 + (x.charAt(i) - '0');
        }

        if (x.charAt(0) == '-') {
            return -num;
        }

        return num;
    }

    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input));
        tokenizer = new StringTokenizer("");
    }

    static void init(FileReader input) {
        reader = new BufferedReader(input);
        tokenizer = new StringTokenizer("");
    }

    static String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(
                    reader.readLine());
        }
        return tokenizer.nextToken();
    }

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

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

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


import java.util.*;

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

        long x = in.nextInt();
        long y = in.nextInt();
        long l = in.nextInt();
        long r = in.nextInt();

        TreeSet<Long> unhappyYears = new TreeSet<>();

        for (long a = 0; (long) (Math.pow(x, a)) <= r; ++a)
            for (long b = 0; (long) (Math.pow(x, a) + Math.pow(y, b)) <= r; ++b)
                unhappyYears.add((long) (Math.pow(x, a) + Math.pow(y, b)));

        //unhappyYears.forEach(System.out::println);

        long prevUnh = l - 1;
        long maxLength = 0;

        for (Long unh : unhappyYears) {
            if (unh < l) {
                continue;
            } else if (unh > r) {
                break;
            }

            long length = unh - prevUnh - 1;
            if (maxLength < length)
                maxLength = length;

            prevUnh = unh;
        }

        long length = r - prevUnh;
        if (maxLength < length)
            maxLength = length;

        System.out.println(maxLength);
    }
}


import java.util.*;

public class Solution {
    public void solve() {
        Scanner cin = new Scanner(System.in);
        int m = cin.nextInt();
        int b = cin.nextInt();
        System.out.println(this.maxRec(m,b));
    }

    public int maxRec(int m, int b) {
        int y = b;
        int x = 0;
        int ans = (x+y) * (1 + x) * (1 + y) / 2;
        int ret = 0;
        do {
            x += m;
            y = b - x/m;
            ret = (x+y) * (1 + x) * (1 + y) / 2;
            if (ret > ans) {
                ans = ret;
            }
//            System.out.println("x " + x + " y " + y + " = " + ret);
        } while (y > 0);
        return ans;
    }

//    public static void main(String[] args) {
//        Solution sol = new Solution();
//        int ans = sol.maxRec(1, 5);
//        System.out.println(ans);
//    }
}


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

public class Main {
	public static void main(String args[]) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int[] dirs = new int[4]; //0 L 1 R 2 D 3 U
		String inp = s.nextLine();
		for (int i = 0; i < n; i++) {
			if (inp.charAt(i) == 'L') {
				dirs[0]++;
			} else if (inp.charAt(i) == 'R') {
				dirs[1]++;
			} else if (inp.charAt(i) == 'D') {
				dirs[2]++;
			} else if (inp.charAt(i) == 'U') {
				dirs[3]++;
			}
		}
		int ans = (Math.min(dirs[0], dirs[1]) * 2) + (Math.min(dirs[2], dirs[3]) * 2);
		System.out.println(ans);
	}
}


import java.io.*;
import java.util.*;
import java.lang.*;
public class Solution
{
    public static void main(String args[])throws IOException
    {
        Scanner ob=new Scanner(System.in);
        int n=ob.nextInt();
        String s=ob.next();

        int u=0;
        int l=0;
        int r=0;
        int d=0;
        for(int i=0;i<n;i++)
        {
        char ch=ob.next().charAt(0);
        if(ch=='U')
        u++;
        if(ch=='L')
        l++;
        if(ch=='R')
        r++;
        if(ch=='D')
        d++;
        int x=(int)Math.min(u,l);
        int y=(int)Math.min(r,d);
        int z=(int)Math.min(x,y);
        System.out.print(z);
        }

    }
}


package CodeForces;

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

public class Problem_888B {
	static int n,dp[][][],inf=(int)1e9;
	static char[]c;
	static int dp(int i,int x,int y)
	{
		if(i==n)
		{
			if(x==100 && y==100)
				return 0;
			return -inf;
		}
		if(dp[i][x][y]!=-1)
		{
//			System.out.println(dp[i][x][y]);
//			return dp[i][x][y];
		}
		int leave=dp(i+1,x,y);
		switch(c[i])
		{
		case 'U':y++;break;
		case 'D':y--;break;
		case 'R':x++;break;
		case 'L':x--;
		}
		int take=dp(i+1,x,y);
		if(take>=leave)
			return dp[i][x][y]=take+1;
		else
			return dp[i][x][y]=leave;
	}
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		PrintWriter pw = new PrintWriter(System.out);
		n=sc.nextInt();
		c=sc.nextLine().toCharArray();
		dp=new int[n][301][301];
		for(int i=0;i<n;i++)
			for(int j=0;j<=300;j++)
				Arrays.fill(dp[i][j], -1);
		int ans=dp(0,100,100);
		pw.println(ans==-inf?0:ans);
		pw.close();
	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

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

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

	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;

public class acmp {

    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        int n = scanner.nextInt();
        int ans = 0;
        int[] map = new int[n];
        if (n > 2) {
            map[0] = scanner.nextInt();
            map[1] = scanner.nextInt();
            for (int i = 1; i < n-1; i++) {
                map[i+1] = scanner.nextInt();
                if (map[i] > map[i-1] && map[i] > map[i+1]) ans++;
                if (map[i] < map[i-1] && map[i] < map[i+1]) ans++;
            }
        }
        System.out.println(ans);
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

    }
}


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String in = sc.nextLine();
		int count = 0;
		for (int i = 0; i < in.length() - 1; i++) {
			for (int j = i + 1; j < in.length(); j++) {
				if (in.charAt(i) == in.charAt(j)) {
					count++;
					break;
				}
			}
		}
		System.out.println(in.length()-count);
	}
}


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner (System.in);
        String in = sc.nextLine();
        int ans = in.length();
        char a[][]= new char [ans][ans];

        for (int i = 0; i < ans; i++) {
        a[0][i]=in.charAt(i);
        }

        for (int i = 1; i < ans; i++) {
            for (int j = 0; j < ans; j++) {
                a[i][j]=a[0][(j+i)%ans];
            }

        }
      //  for (int i = 0; i < ans; i++) {
   //         System.out.println(Arrays.toString(a[i]));
    //    }
        int g=ans;
        for (int i = 0; i < g-1; i++) {
            if (a[i][0]!='-') {
            for (int j = i+1; j < g; j++) {
                if (a[i][0]==a[j][0]) {
                    boolean eq=true;
                    for (int k = 1; k < g; k++) {
                        if (a[i][k]!=a[j][k]) {
                            eq=false;
                            break;
                        }
                    }
                    if (eq) {
                        a[j][0]='-';
                        ans--;
                    }
                }}
            }
        }
        System.out.println(ans);
    }
}


import java.util.Scanner;
import java.util.HashSet;

public class Hongcow{
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        HashSet<String> words = new HashSet<>();
        char[] newWord = scan.next().toCharArray();

        words.add(new String(newWord));

        for(int i=0;i<newWord.length;i++){
            char[] nextWord = new char[newWord.length];

            for(int j=0;j<newLord.length;j++){
                nextWord[j] = newWord[(j+i)%newWord.length];
            }

            words.add(new String(nextWord));
        }

        System.out.println(words.size());
    }
}


import java.util.HashSet;
import java.util.Scanner;

public class A {

	public static void main(String[] args){

		Scanner s = new Scanner(System.in);

		while(s.hasNext()){
			HashSet<String> h = new HashSet<String>();
			String c = s.nextLine();
			String b = "";
			int count = 1;
			h.add(c);
			for(int i = 0; i< c.length(); i++){
				b = c.substring(1, c.length()) + c.charAt(0);
				if(!bbbh.contains(b)){
					count++;
				}
				c = b;
				h.add(c);
			}
			System.out.println(count);
		}

	}
}


import java.util.scanner;
public class Horses {
//Problem Code: HORSES
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int arr[]=new int[3];
		for(int i=0;i<3;i++) {
			arr[i]=in.nextInt();
		}
		Arrays.sort(arr);
		System.out.println((arr[1]-arr[0])+arr[2]-arr[1]);
		in.close();
	}

}


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

import java.util.Scanner;

/**
 *
 * @author asus
 */
public class sizemonitor {
    public static void main(String args[]){
        Scanner in =new Scanner(System.in);
        int size = in.nextInt();
        int width = Integer.MAX_VALUE;
        int height = Integer.MAX_VALUE;
        int raznica = Integer.MAX_VALUE;
        for(int i=1;i<=size;i++){
            for(int j=1;j<=size;j++){
                if(size==i*j){
                    int temp = raznica;
                    raznica = Math.min(raznica, Math.abs(i-j));
                    if(temp!=raznica){
                        height=Math.min(i,j);
                        width=Math.max(i,j);

                    }
                }
            }
        }
        System.out.println(height+" "+width);
    }
}


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

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

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

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

       int n = in.nextInt();
       int a = 2;
       int b = 0;

       while(a<= Math.sqrt(n)){
           if(n%a==0)b=n/a;
           a++;
       }
        System.out.println(n/b+" "+b);

    }

}


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

public class DisplaySize {
	public static void main(String[] args) {
		InputReader in = new StreamInputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		run(in, out);
	}

	public static void run(InputReader in, PrintWriter out) {
		Solver solver = new TaskB();
		solver.solve(1, in, out);
		Exit.exit(in, out);
	}
}

abstract class InputReader {
	@SuppressWarnings("unused")
	private boolean finished = false;

	public abstract int read();

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

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		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;
	}

	public void setFinished(boolean finished) {
		this.finished = finished;
	}

	public abstract void close();
}

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

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

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

	public void close() {
		try {
			stream.close();
		} catch (IOException ignored) {
		}
	}
}

class Exit {
	private Exit() {
	}

	public static void exit(InputReader in, PrintWriter out) {
		in.setFinished(true);
		in.close();
		out.close();
	}
}

interface Solver {
	public void solve(int testNumber, InputReader in, PrintWriter out);
}

class GeometryUtils {
	public static double epsilon = 1e-8;

	}

class TaskB implements Solver {

	static int N = 1_000_000;

	public void solve(int testNumber, InputReader in, PrintWriter out) {

		int[] f = new int[N];
		for(int i=2; i<N; i++){
			if(f[i]==0) {
				for(int j=1; i*j<N; j++) if(f[i*j]==0) f[i*j]=i;
			}
		}

		List<Integer> fact = new ArrayList<>(N);
		List<Integer> divs = new ArrayList<>(N);
		int t = in.readInt();
		if(t==1) {out.print("1 1"); return;}
		while(f[t]!=0){
			fact.add(f[t]);
			t /= f[t];
		}

		divs.add(1);
		for(int n:fact){
			int s = divs.size();
			for(int k=0; k<s; k++)
				divs.add(n*divs.get(k));
		}
		Collections.sort(divs);

		int m = divs.size()/2;
		out.println(divs.get(m-1)+" "+divs.get(m));

		return;
	}
}


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

public class twins {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		ArrayList<Character> A = new ArrayList<Character>();
		ArrayList<Integer> check = new ArrayList<Integer>();
		A.add('h');
		A.add('e');
		A.add('l');
		A.add('l');
		A.add('o');

		String s = sc.nextLine();
		while(A.size()!=0){
		    int i = 0;
		    while(i < s.length()){
		        if(s.charAt(i)==A.get(0)){
		            check.add(i);
		            A.remove(0);
		        }
		    }
		}
		ArrayList<Integer> check1 = new ArrayList<Integer>(check);
		Collections.sort(check);
		if(check.equals(check1)){
		    System.out.println("YES");
		}
		else{
		    System.out.println("NO");
		}

	}
}


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

public class CodeforcesB {
    static long printNcR(int n, int r) {
        long p = 1, k = 1;
        if (n - r < r) {
            r = n - r;
        }

        if (r != 0) {
            while (r > 0) {
                p *= n;
                k *= r;
                long m = __gcd(p, k);
                p /= m;
                k /= m;

                n--;
                r--;
            }
        } else {
            p = 1;
        }
        return p;
    }

    static long __gcd(long n1, long n2) {
        long gcd = 1;
        for (int i = 1; i <= n1 && i <= n2; ++i) {
            if (n1 % i == 0 && n2 % i == 0) {
                gcd = i;
            }
        }
        return gcd;
    }

    public void solve()throws IOException{
        FastScanner fs = new FastScanner();
        StringBuilder ans = new StringBuilder("");
        int n = fs.nextInt();
        int t = fs.nextInt();
        if( n < 2*t+1 ){
            ans.append("0\n");
        }else{
            ans.append(printNcR(n,t)).append("\n");
        }
        System.out.println(ans);
    }
    public static void main(String[]args)throws IOException{
       try {
           new CodeforcesB().solve();
       }catch (Exception e){
           e.printStackTrace();

       }
    }
    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }
        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }
}


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

public class E
{

	public static void main(String[] args)
	{
		new E();
	}

	int N;
	int T;

	int[][][][][] memo = new int[25][15][15][5][3];

	E()
	{
		Scanner in=new Scanner(System.in);
		N=in.nextInt();
		T=in.nextInt();

		for (int[][][][] memoo : memo)
			for (int[][][] mem : memoo)
				for (int[][] me : mem)
					for (int[] m : me)
						Arrays.fill(m, -1);

		int res=0;
		for (int i=1; i<=3; ++i)
			res+=go(2,0,0,i,0);
		System.out.println(res);
	}

	int go(int at, int h, int v, int prev, int dir)
	{
		if (at==N)
		{
			if (h==T&&v==T-1)
				return prev-1;
			return 0;
		}
		if (memo[at][h][v][prev][dir]>-1)
			return memo[at][h][v][prev][dir];

		int res=0;

		if (at==2)
		{
			for (int i=1; i<=4; ++i)
				if (i>prev)
					res+=go(at+1,h,v,i,0);
		}
		else
		{
			for (int i=1; i<=4; ++i)
				if (i!=prev)
				{
					if (i>prev && dir==0)
						res+=go(at+1,h,v,i,0);
					else if (i>prev && dir==1)
						res+=go(at+1,h,v+1,i,0);
					else if (i<prev && dir==0)
						res+=go(at+1,h+1,v,i,1);
					else if (i<prev && dir==1)
						res+=go(at+1,h,v,i,1);
					else
						System.err.println("huh?");
				}
		}

		return memo[at][h][v][prev][dir]=res;
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Arrays;

public class CT14E {

	static StreamTokenizer in;
	static PrintWriter out;

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

	static String nextString() throws IOException {
		in.nextToken();
		return in.sval;
	}

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

		for (int t = nextInt(); t > 0; t--) {
			n = nextInt();
			k = nextInt();

			long ans = 0;
			for (int a = 0; a < 4; a++)
				for (int b = 0; b < 4; b++)
					if (a != b)
						ans += solve(n-2, k, k-1, a, b);

			out.println(ans);
		}

		out.flush();
	}

	static int n, k;
	static long[][][][][] memo = new long[20][11][11][4][4];
	static {
		for (long[][][][] a : memo)
			for (long[][][] b : a)
				for (long[][] c : b)
					for (long[] d : c)
						Arrays.fill(d, -1);
	}

	static long solve(int x, int q, int p, int a, int b) {
		if (x == 0) return q == 0 && p == 0 ? 1 : 0;
		if (q < 0 || p < 0) return 0;
		if (memo[x][q][p][a][b] != -1) return memo[x][q][p][a][b];

		int res = 0;
		for (int i = 0; i < 4; i++)
			if (i < a && a > b) res += solve(x-1, q-1, p, i, a);
			else if (i > a && a < b) res += solve(x-1, q, p-1, i, a);
			else if (i != a) res += solve(x-1, q, p, i, a);

		return memo[x][q][p][a][b] = res;
	}
}


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

public class E {
    static int n;
    static int t;
    static int[][][][][] visited;
    public static int work(int index , int humps , int prev , int now  , int bel) {
        //System.out.println(s + "    "+humps + "     " + bel);
        if(index == n-1) {
            if(humps == t  && bel == t-1) {
                //System.out.println(s + "    "+humps + "     " + bel + "   hi");
                return 1;
            }
            else return 0;
        }
        if(bel >t-1 || humps >t)
            return 0;

        if(visited[index][humps][prev][now][bel] !=-1) {

            return visited[index][humps][prev][now][bel];
        }

        int result = 0;

        for(int i = 1 ; i<=4 ; i++) {
            if(now == i)
                continue;
            result += work(index +1 , (now>prev && now >i && prev !=0? humps+1:humps) , now , i , (now<prev && now <i && prev !=0? bel+1:bel));
        }
        return visited[index][humps][prev][now][bel] = result;

    }
    public static void main(String[] args) throws Exception {
        parsee in = new parsee(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int k = (int)in.nextLong();
        int[][] dp = new int[21][11];

        /*dp[3][1]=14;
        dp[3][2]=0;
        dp[3][3]=0;
        dp[3][4]=0;
        dp[3][5]=0;
        dp[3][6]=0;
        dp[3][7]=0;
        dp[3][8]=0;
        dp[3][9]=0;
        dp[3][10]=0;
        dp[4][1]=22;
        dp[4][2]=0;
        dp[4][3]=0;
        dp[4][4]=0;
        dp[4][5]=0;
        dp[4][6]=0;
        dp[4][7]=0;
        dp[4][8]=0;
        dp[4][9]=0;
        dp[4][10]=0;
        dp[5][1]=16;
        dp[5][2]=70;
        dp[5][3]=0;
        dp[5][4]=0;
        dp[5][5]=0;
        dp[5][6]=0;
        dp[5][7]=0;
        dp[5][8]=0;
        dp[5][9]=0;
        dp[5][10]=0;
        dp[6][1]=6;
        dp[6][2]=232;
        dp[6][3]=0;
        dp[6][4]=0;
        dp[6][5]=0;
        dp[6][6]=0;
        dp[6][7]=0;
        dp[6][8]=0;
        dp[6][9]=0;
        dp[6][10]=0;
        dp[7][1]=1;
        dp[7][2]=380;
        dp[7][3]=353;
        dp[7][4]=0;
        dp[7][5]=0;
        dp[7][6]=0;
        dp[7][7]=0;
        dp[7][8]=0;
        dp[7][9]=0;
        dp[7][10]=0;
        dp[8][1]=0;
        dp[8][2]=396;
        dp[8][3]=1786;
        dp[8][4]=0;
        dp[8][5]=0;
        dp[8][6]=0;
        dp[8][7]=0;
        dp[8][8]=0;
        dp[8][9]=0;
        dp[8][10]=0;
        dp[9][1]=0;
        dp[9][2]=284;
        dp[9][3]=4500;
        dp[9][4]=1782;
        dp[9][5]=0;
        dp[9][6]=0;
        dp[9][7]=0;
        dp[9][8]=0;
        dp[9][9]=0;
        dp[9][10]=0;
        dp[10][1]=0;
        dp[10][2]=142;
        dp[10][3]=7414;
        dp[10][4]=12122;
        dp[10][5]=0;
        dp[10][6]=0;
        dp[10][7]=0;
        dp[10][8]=0;
        dp[10][9]=0;
        dp[10][10]=0;
        dp[11][1]=0;
        dp[11][2]=48;
        dp[11][3]=8849;
        dp[11][4]=41160;
        dp[11][5]=8997;
        dp[11][6]=0;
        dp[11][7]=0;
        dp[11][8]=0;
        dp[11][9]=0;
        dp[11][10]=0;
        dp[12][1]=0;
        dp[12][2]=10;
        dp[12][3]=8028;
        dp[12][4]=92226;
        dp[12][5]=76878;
        dp[12][6]=0;
        dp[12][7]=0;
        dp[12][8]=0;
        dp[12][9]=0;
        dp[12][10]=0;
        dp[13][1]=0;
        dp[13][2]=1;
        dp[13][3]=5658;
        dp[13][4]=152140;
        dp[13][5]=328222;
        dp[13][6]=45425;
        dp[13][7]=0;
        dp[13][8]=0;
        dp[13][9]=0;
        dp[13][10]=0;
        dp[14][1]=0;
        dp[14][2]=0;
        dp[14][3]=3112;
        dp[14][4]=195420;
        dp[14][5]=928494;
        dp[14][6]=467292;
        dp[14][7]=0;
        dp[14][8]=0;
        dp[14][9]=0;
        dp[14][10]=0;
        dp[15][1]=0;
        dp[15][2]=0;
        dp[15][3]=1322;
        dp[15][4]=201744;
        dp[15][5]=1947581;
        dp[15][6]=2402980;
        dp[15][7]=229347;
        dp[15][8]=0;
        dp[15][9]=0;
        dp[15][10]=0;
        dp[16][1]=0;
        dp[16][2]=0;
        dp[16][3]=422;
        dp[16][4]=170444;
        dp[16][5]=3213988;
        dp[16][6]=8205152;
        dp[16][7]=2758896;
        dp[16][8]=0;
        dp[16][9]=0;
        dp[16][10]=0;
        dp[17][1]=0;
        dp[17][2]=0;
        dp[17][3]=96;
        dp[17][4]=118912;
        dp[17][5]=4322956;
        dp[17][6]=20852648;
        dp[17][7]=16594160;
        dp[17][8]=1157954;
        dp[17][9]=0;
        dp[17][10]=0;
        dp[18][1]=0;
        dp[18][2]=0;
        dp[18][3]=14;
        dp[18][4]=68640;
        dp[18][5]=4846524;
        dp[18][6]=41920210;
        dp[18][7]=66357900;
        dp[18][8]=15946870;
        dp[18][9]=0;
        dp[18][10]=0;
        dp[19][1]=0;
        dp[19][2]=0;
        dp[19][3]=1;
        dp[19][4]=32632;
        dp[19][5]=4594423;
        dp[19][6]=69183464;
        dp[19][7]=197939352;
        dp[19][8]=109824208;
        dp[19][9]=5846414;
        dp[19][10]=0;
        dp[20][1]=0;
        dp[20][2]=0;
        dp[20][3]=0;
        dp[20][4]=12628;
        dp[20][5]=3715462;
        dp[20][6]=96046590;
        dp[20][7]=468541040;
        dp[20][8]=503245466;
        dp[20][9]=90700276;
        dp[20][10]=0;*/

        for(int tt = 0 ; tt<k; tt++) {
            n = (int)in.nextLong();
            t = (int)in.nextLong();
            visited = new int[n][t+1][5][5][t];
            for(int i = 0 ; i<visited.length ; i++) {
                for(int j = 0 ; j<visited[i].length ; j++) {
                    for(int kk = 0 ; kk<visited[i][j].length ; kk++) {
                        for(int l = 0 ; l<visited[i][j][kk].length ; l++)
                            Arrays.fill(visited[i][j][kk][l], -1);
                    }
                }
            }
            int res = work(0 , 0 , 0 , 1 ,0);

            res += work(0 , 0 , 0 , 2 , 0);

            res += work(0 , 0 , 0 , 3,0);

            res += work(0 , 0 , 0 , 4 , 0);
            out.println(res);

        }
        out.flush();
    }
}


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

public class E {
    static int n;
    static int t;
    static int[][][][][] visited;
    public static int work(int index , int humps , int prev , int now  , int bel) {
        //System.out.println(s + "    "+humps + "     " + bel);
        if(index == n-1) {
            if(humps == t  && bel == t-1) {
                //System.out.println(s + "    "+humps + "     " + bel + "   hi");
                return 1;
            }
            else return 0;
        }
        if(bel >t-1 || humps >t)
            return 0;

        if(visited[index][humps][prev][now][bel] !=-1) {

            return visited[index][humps][prev][now][bel];
        }

        int result = 0;

        for(int i = 1 ; i<=4 ; i++) {
            if(now == i)
                continue;
            result += work(index +1 , (now>prev && now >i && prev !=0? humps+1:humps) , now , i , (now<prev && now <i && prev !=0? bel+1:bel));
        }
        return visited[index][humps][prev][now][bel] = result;

    }
    public static void main(String[] args) throws Exception {
        parsee in = new parsee(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int k = (int)in.nextLong();
        int[][] dp = new int[21][11];

        /*dp[3][1]=14;
        dp[3][2]=0;
        dp[3][3]=0;
        dp[3][4]=0;
        dp[3][5]=0;
        dp[3][6]=0;
        dp[3][7]=0;
        dp[3][8]=0;
        dp[3][9]=0;
        dp[3][10]=0;
        dp[4][1]=22;
        dp[4][2]=0;
        dp[4][3]=0;
        dp[4][4]=0;
        dp[4][5]=0;
        dp[4][6]=0;
        dp[4][7]=0;
        dp[4][8]=0;
        dp[4][9]=0;
        dp[4][10]=0;
        dp[5][1]=16;
        dp[5][2]=70;
        dp[5][3]=0;
        dp[5][4]=0;
        dp[5][5]=0;
        dp[5][6]=0;
        dp[5][7]=0;
        dp[5][8]=0;
        dp[5][9]=0;
        dp[5][10]=0;
        dp[6][1]=6;
        dp[6][2]=232;
        dp[6][3]=0;
        dp[6][4]=0;
        dp[6][5]=0;
        dp[6][6]=0;
        dp[6][7]=0;
        dp[6][8]=0;
        dp[6][9]=0;
        dp[6][10]=0;
        dp[7][1]=1;
        dp[7][2]=380;
        dp[7][3]=353;
        dp[7][4]=0;
        dp[7][5]=0;
        dp[7][6]=0;
        dp[7][7]=0;
        dp[7][8]=0;
        dp[7][9]=0;
        dp[7][10]=0;
        dp[8][1]=0;
        dp[8][2]=396;
        dp[8][3]=1786;
        dp[8][4]=0;
        dp[8][5]=0;
        dp[8][6]=0;
        dp[8][7]=0;
        dp[8][8]=0;
        dp[8][9]=0;
        dp[8][10]=0;
        dp[9][1]=0;
        dp[9][2]=284;
        dp[9][3]=4500;
        dp[9][4]=1782;
        dp[9][5]=0;
        dp[9][6]=0;
        dp[9][7]=0;
        dp[9][8]=0;
        dp[9][9]=0;
        dp[9][10]=0;
        dp[10][1]=0;
        dp[10][2]=142;
        dp[10][3]=7414;
        dp[10][4]=12122;
        dp[10][5]=0;
        dp[10][6]=0;
        dp[10][7]=0;
        dp[10][8]=0;
        dp[10][9]=0;
        dp[10][10]=0;
        dp[11][1]=0;
        dp[11][2]=48;
        dp[11][3]=8849;
        dp[11][4]=41160;
        dp[11][5]=8997;
        dp[11][6]=0;
        dp[11][7]=0;
        dp[11][8]=0;
        dp[11][9]=0;
        dp[11][10]=0;
        dp[12][1]=0;
        dp[12][2]=10;
        dp[12][3]=8028;
        dp[12][4]=92226;
        dp[12][5]=76878;
        dp[12][6]=0;
        dp[12][7]=0;
        dp[12][8]=0;
        dp[12][9]=0;
        dp[12][10]=0;
        dp[13][1]=0;
        dp[13][2]=1;
        dp[13][3]=5658;
        dp[13][4]=152140;
        dp[13][5]=328222;
        dp[13][6]=45425;
        dp[13][7]=0;
        dp[13][8]=0;
        dp[13][9]=0;
        dp[13][10]=0;
        dp[14][1]=0;
        dp[14][2]=0;
        dp[14][3]=3112;
        dp[14][4]=195420;
        dp[14][5]=928494;
        dp[14][6]=467292;
        dp[14][7]=0;
        dp[14][8]=0;
        dp[14][9]=0;
        dp[14][10]=0;
        dp[15][1]=0;
        dp[15][2]=0;
        dp[15][3]=1322;
        dp[15][4]=201744;
        dp[15][5]=1947581;
        dp[15][6]=2402980;
        dp[15][7]=229347;
        dp[15][8]=0;
        dp[15][9]=0;
        dp[15][10]=0;
        dp[16][1]=0;
        dp[16][2]=0;
        dp[16][3]=422;
        dp[16][4]=170444;
        dp[16][5]=3213988;
        dp[16][6]=8205152;
        dp[16][7]=2758896;
        dp[16][8]=0;
        dp[16][9]=0;
        dp[16][10]=0;
        dp[17][1]=0;
        dp[17][2]=0;
        dp[17][3]=96;
        dp[17][4]=118912;
        dp[17][5]=4322956;
        dp[17][6]=20852648;
        dp[17][7]=16594160;
        dp[17][8]=1157954;
        dp[17][9]=0;
        dp[17][10]=0;
        dp[18][1]=0;
        dp[18][2]=0;
        dp[18][3]=14;
        dp[18][4]=68640;
        dp[18][5]=4846524;
        dp[18][6]=41920210;
        dp[18][7]=66357900;
        dp[18][8]=15946870;
        dp[18][9]=0;
        dp[18][10]=0;
        dp[19][1]=0;
        dp[19][2]=0;
        dp[19][3]=1;
        dp[19][4]=32632;
        dp[19][5]=4594423;
        dp[19][6]=69183464;
        dp[19][7]=197939352;
        dp[19][8]=109824208;
        dp[19][9]=5846414;
        dp[19][10]=0;
        dp[20][1]=0;
        dp[20][2]=0;
        dp[20][3]=0;
        dp[20][4]=12628;
        dp[20][5]=3715462;
        dp[20][6]=96046590;
        dp[20][7]=468541040;
        dp[20][8]=503245466;
        dp[20][9]=90700276;
        dp[20][10]=0;*/

        for(int tt = 0 ; tt<k; tt++) {
            n = (int)in.nextLong();
            t = (int)in.nextLong();
            visited = new int[n][t+1][5][5][t];
            for(int i = 0 ; i<visited.length ; i++) {
                for(int j = 0 ; j<visited[i].length ; j++) {
                    for(int kk = 0 ; kk<visited[i][j].length ; kk++) {
                        for(int l = 0 ; l<visited[i][j][kk].length ; l++)
                            Arrays.fill(visited[i][j][kk][l], -1);
                    }
                }
            }
            int res = work(0 , 0 , 0 , 1 ,0);

            res += work(0 , 0 , 0 , 2 , 0);

            res += work(0 , 0 , 0 , 3,0);

            res += work(0 , 0 , 0 , 4 , 0);
            out.println(res);

        }
        out.flush();
    }
}
class parsee
{
   final private int BUFFER_SIZE = 1 << 16;

   private DataInputStream din;
   private byte[] buffer;
   private int bufferPointer, bytesRead;

   public parsee(InputStream in)
   {
      din = new DataInputStream(in);
      buffer = new byte[BUFFER_SIZE];
      bufferPointer = bytesRead = 0;
   }

   public long nextLong() throws Exception
   {
      long ret = 0;
      byte c = read();
      while (c <= ' ') c = read();
      boolean neg = c == '-';
      if (neg) c = read();
      do
      {
         ret = ret * 10 + c - '0';
         c = read();
      } while (c > ' ');
      if (neg) return -ret;
      return ret;
   }

   private void fillBuffer() throws Exception
   {
      bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
      if (bytesRead == -1) buffer[0] = -1;
   }

   private byte read() throws Exception
   {
      if (bufferPointer == bytesRead) fillBuffer();
      return buffer[bufferPointer++];
   }
}


public class PrimeAndMultiplication
{
	static LinkedList<Integer> primes=new LinkedList<>();
	static int MOD=(int)1e9+7;

	public static void main(String[] args)
	{

		InputStream is=System.in;
		OutputStream out=System.out;

		FastScanner input=new FastScanner(is);
		FastPrinter output=new FastPrinter(out);
		int x=input.nextInt();
		long n=input.nextLong();
		prime(x );
        output.println(f(n));
        output.flush();
	}

	static long f(long n)
	  {
		long ans=1;
				for(int off:primes)
				{
				   long pow=0;
				   long primeFactor=off;
				   while(true)
				    {
					    pow+=(n/primeFactor);
					     if((n/primeFactor)<off)
					     {
					    	 break;
					     }
					     primeFactor=primeFactor*off;
				    }
				   System.out.println(off+" "+pow);
				   ans=  (ans*power(off,pow))%MOD;
				   System.out.println(ans);
				}
		return ans;
	  }

	public static long power(long p,long k)
	  {
		long res=1;
		p%=MOD;
		while(k>0)
		{
			if((k&1)==1)
			{
				res=(res*p)%MOD;
			}
			p=(p*p)%MOD;
			k>>=1;
		}
		return res;
	  }

	static void prime(int x)
	  {
		for(int i=2;i*i<=x;i++)
		{
			if(x%i==0)
			{
				primes.add(i);
				while(x%i==0)
				{
					x/=i;
				}
			}
		}
		if(x>1)
		{
			primes.add(x);
		}
	 }
}

class FastPrinter extends PrintWriter
   {
	 public FastPrinter(OutputStream out)
	 {
		super(out);
	 }
	 public FastPrinter(Writer out)
	 {
		super(out);
	 }
   }

class FastScanner
{
	BufferedReader br;
	StringTokenizer st;
   public FastScanner(InputStream is)
    {
	  br=new BufferedReader(new InputStreamReader(is));
    }

   public FastScanner(File f)
   {
	   try
	    {
		 br=new BufferedReader(new FileReader(f));
     	}
	   catch (FileNotFoundException e)
	    {
    		e.printStackTrace();
	    }
   }

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

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


package Main;
import java.util.*;
public class akram {
public static void main(String[]args) {
	Scanner ak=new Scanner(System.in);
	int n=ak.nextInt();
	int c=0;
	String b="";
    //int[] a=new int[n+1];
	for(int i=1;i<=n;i++) {
		for(int j=1;j<=n;j++) {
			if((i^j)>0 && (i^j)<=n && i+j>(i^j) && i+(i^j)>j && j+(i^j)>i &&  !(b.contains(""+i+j+(i^j))))
				{c++;
				b+=""+i+j+(i^j)+j+i+(i^j)+i+(i^j)+j+j+(i^j)+i+(i^j)+i+j+(i^j)+j+i;
//				a[i]++;
//				a[j]++;
//				a[(i^j)]++;
				}
		}
	}
	System.out.println(c);
}
public static boolean aaa(int x,int y) {
	if(y-1>x)
		return false;
	if(y==1 && x>0)
		return false;
	x=x-y+1;
	if(x%2==0)
		return true;
	else
		return false;
}
}


/**
 * Created by Khoi on 22/10/2017
 * For learning purpose
 */

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;

    void solve() {
        int n = ni() - 1;
        int k = ni();
        int count = 0;
        boolean[] arr = new boolean[k+1];

        while (n >= k && k >= 2 && n >= 0) {
            n = n - k + 1;
            count += 1;
            k -= 1;
        }

        if (n == 0)
            out.print(count);
        else if (n < k)
            out.print(count + 1);
        else
            out.print(-1);
    }

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

        long s = System.currentTimeMillis();
        solve();
        out.flush();
        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 boolean isEndLine(int c) {
        return c < 32;
    }

    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 nsl() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isEndLine(b))) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    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 && !(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 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 boolean oj = System.getProperty("ONLINE_JUDGE") != null;
    private boolean oj = true;

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


import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

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

class CF_55D {

	void run() {
		Scanner cin = new Scanner(new BufferedInputStream(System.in));
		PrintWriter cout = new PrintWriter(new BufferedOutputStream(System.out));
		int t = cin.nextInt() ;
		while(t-- > 0){
			long l = cin.nextLong() , r = cin.nextLong() ;
			cout.println(calculation(r) - calculation(l - 1));
		}
        cout.flush();
	}

	long calculation(long val){
		int bit = 0 ;
		while(val > 0){
			dight[bit++] = (int) (val % 10) ;
			val /= 10 ;
		}
		return dfs(bit-1, 0, 1, true) ;
	}

	long dfs(int pos, int sum, int lcm, Boolean isEnd) {
		if (pos < 0)
			return sum % lcm == 0 ? 1L : 0L;
		if (!isEnd && dp[pos][sum][hash[lcm]] != -1)
			return dp[pos][sum][hash[lcm]];
		int end = isEnd ? dight[pos] : 9;
		long res = 0L;
		for (int i = 0; i <= end; i++) {
			res += dfs(pos - 1, (sum * 10 + i) % N, lcm(lcm, i), isEnd && i == end);
		}
        if(! isEnd) dp[pos][sum][hash[lcm]] = res ;
        return res ;
	}

	final int N = 2520;
	long[][][] dp = new long[18][N][48];
	int[] dight = new int[18];

	int[] hash = new int[N + 8];
	{
		int cnt = 0;
		for (int i = 1; i <= N; i++) {
			if (N % i == 0)
				hash[i] = cnt++;
		}
		for(int i = 0 ; i < 18 ; i++){
			for(int j = 0 ; j < N ; j++)
				Arrays.fill(dp[i][j], -1) ;
		}
	}

	int gcd(int x, int y) {
		return y == 0 ? x : gcd(y, x % y);
	}

	int lcm(int x, int y) {
		if(x == 0) return y ;
		if(y == 0) return x ;
		return x / gcd(x, y) * y;
	}

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Map;
import java.util.Scanner;
import java.util.HashMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author heifrank
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        int testCount = Integer.parseInt(in.next());
        for (int i = 1; i <= testCount; i++)
            solver.solve(i, in, out);
        out.close();
    }

    static class TaskD {
        long[][][] dp = new long[20][50][3005];
        int[] bits = new int[20];
        Map<Integer, Integer> ds = new HashMap<>();
        int cnt = 0;
        final int MOD = 2520;

        int gcd(int a, int b) {
            return b == 0 ? a : gcd(b, a % b);
        }

        void dfs2(int p, int pren) {
            if (p == 0) {
                if (!ds.containsKey(pren)) {
                    ds.put(pren, ++cnt);
                }
                return;
            }
            dfs2(p - 1, pren * p / gcd(pren, p));
            dfs2(p - 1, pren);
        }

        public TaskD() {
            for (int i = 0; i < dp.length; i++)
                for (int j = 0; j < dp[0].length; j++) {
                    Arrays.fill(dp[i][j], -1);
                }
            dfs2(9, 1);
        }

        public long dfs(int p, int lcm, int mod, boolean limit) {
            if (p == -1) {
                return mod % lcm == 0 ? 1 : 0;
            }
            int id = ds.get(lcm);
            if (!limit && dp[p][id][mod] != -1) {
                return dp[p][id][mod];
            }
            long ans = 0;
            int end = limit ? bits[p] : 9;
            for (int i = 0; i <= end; i++) {
                ans += dfs(p - 1, i == 0 ? lcm : lcm * i / gcd(lcm, i), (mod * 10 + i) % MOD, limit && i == end);
            }
            if (!limit) {
                dp[p][lcm][mod] = ans;
            }
            return ans;
        }

        public long calc(long n) {
            int len = 0;
            while (n > 0) {
                Long t = n % 10;
                bits[len++] = t.intValue();
                n /= 10;
            }
            return dfs(len - 1, 1, 0, true);
        }

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long x = in.nextLong();
            long y = in.nextLong();
            out.println(calc(y) - calc(x - 1));
        }

    }
}


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 code{
	public static void main (String[] args) throws java.lang.Exception
	{
	   Scanner obj = new Scanner(System.in);
	   String s = obj.next();
	   String t = "hello";
	   Vector<Character> arr = new Vector<Character>();
	   for(int i=0;i<t.length();i++){
	    arr.add(t.charAt(i));
	   }
	   int j=0;
	    for(int i=0;i<s.length();i++){
	    while(!arr.isEmpty()){
	     if(s.charAt(i)==arr.get(j)){
	      arr.remove(j);
	     }
	    }
	   }
	   if(arr.isEmpty()){
	    System.out.println("YES");
	   }
	   else{
	     System.out.println("NO");
	   }

	}
}


//package Indiahacks2016;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class BeerAndThreeBalls {
     public static void main(String args[]) throws NumberFormatException, IOException{
    	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    	int n=Integer.parseInt(br.readLine());
    	int a[]=new int[n];
    	String s1[]=br.readLine().split(" ");
    	for(int i=0;i<n;i++){
    		a[i]=Integer.parseInt(s1[i]);
    	}
    	int flag=0;
    	Arrays.sort(a);
    	for(int i=0;i<n-2;i++){
    		if(a[i+1]==(a[i]+1) && a[i+2]==(a[i]+2)){
    			flag=1;
    			break
    		}
    	}
    	if(flag==1){
    		System.out.println("YES");
    	}
    	else{
    		System.out.println("NO");
    	}
     }
}


import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = sc.nextInt();

		for (int i = 0; i < n; i++) {
			int c1 = 0;
			int c2 = 0;
			for (int j = i + 1, t1 = 0, t2 = 0; j < n; j++) {

				if (a[i] - a[j] == 1) {
					c1++;
					for (int j = i + 1; j < n; j++) {
						if (a[i] - a[j] == 2) {
							c1++;
							break;
						}
					}
					break;
				}
				if (a[j] - a[i] == 1) {
					c2++;
					for (int j = i + 1; j < n; j++) {
						if (a[j] - a[i] == 2) {
							c2++;
							break;
						}
					}
					break;
				}

			}
			if (c1 == 1 && c2 == 1) {
				System.out.println("YES");
				break;
			}

			if (c1 == 2 || c2 == 2) {
				System.out.println("YES");
				break;
			}

			if (i == n - 1 && c1 == 0 && c2 == 0)
				System.out.println("NO");

		}

	}
}


import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = sc.nextInt();

		for (int i = 0; i < n; i++) {
			int c = 0;
			for (int j = i + 1, t1 = 0, t2 = 0; j < n; j++) {

				if (a[j] != t1 && a[j] != t2) {
					if (a[i] - a[j] == 1) {
						c++;
						t1 = a[j];
						for (int k = i + 1; k < n; k++) {
							if (a[i] - a[k] == 2) {
								c++;
								break;
							}
						}
					}

					if (a[j] - a[i] == 1) {
						c++;
						t2 = a[j];
						for (int k = i + 1; k < n; k++) {
							if (a[k] - a[i] == 2) {
								c++;
								break;
							}
						}
					}

				}
				if (c >= 2)
					break;
			}
			if (c >= 2) {
				System.out.println("YES");
				break;
			}

			if (i == n - 1 && c1 == 0 && c2 == 0)
				System.out.println("NO");

		}

	}
}


import java.util.*;

public class CodeForces_1321C_L1600_FucksGiven {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args){
        int Size = sc.nextInt();
        sc.nextLine();
        String line = sc.nextLine();
        int biggestChar = 'a';
        for (int i = 0; i < line.length(); i++) {
            char currentChar = line.charAt(i);
            if(currentChar > biggestChar){
                biggestChar = currentChar;
            }
        }
        int FucksGiven = 0;
        for (int i = biggestChar; i > 'a' ; i--) {
            for (int j = 0; j < line.length(); j++) {
                if(line.charAt(j) == i){
                    if(j == 0){
                        if(line.charAt(1) == i-1){
                            line = line.substring(j+1);
                            j--;
                            FucksGiven++;
                        }
                    }
                    else if(j == line.length()-1){
                        if(line.charAt(j-1) == i-1){
                            line = line.substring(0,j);
                            j-=2;
                            FucksGiven++;
                        }
                    }
                    else if(line.charAt(j-1) == i-1 || line.charAt(j+1) == i-1 ){
                        line = line.substring(0,j)+line.substring(j+1);
                        j-=2;
                        FucksGiven++;
                    }

                }
            }
        }
        System.out.println(FucksGiven);

    }

}


/* package whatever; // don't place package name! */

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 Ideone
{
    public static void main (String[] args) throws java.lang.Exception
    {
        Scanner sc = new Scanner(System.in);
        long r = sc.nextLong();
        long x = sc.nextLong();
        long y = sc.nextLong();
        long xx = sc.nextLong();
        long yy = sc.nextLong();
        long d = (x-xx)*(x-xx)+(y-yy)*(y-yy);
        int k = 0;
        while(4*k*k*r*r<d){
            k++;
        }
        System.out.println(k);
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.io.BufferedReader;

public class C {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskF solver = new TaskF();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskF {
		private Set<Integer> prime(int n) {
			Set<Integer> s = new HashSet<>();
			for (int i = 2; i <= n; i++) {
				if (n % i == 0) {
					s.add(i);
					while (n > 0 && n % i == 0) {
						n = n / i;
					}
				}
			}
			return s;
		}

		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int x = in.nextInt();
			long n = in.nextLong();
			Set<Integer> fac = prime(x);
			long ans = 1;
			long mod = 1000000007;
			for (Integer f : fac) {
				long t = n;
				long div = t / f;
				while (div > 0) {
					ans = (ans * (power(f, div)) % mod) % mod;
					t /= f;
					div = t / f;
				}
			}
			out.println(ans);
		}

		private long power(long x, long y) {
			long res = 1;
			long mod = 1000000007;
			while (y > 0) {
				if (y % 2 == 1)
					res = (res * x) % mod;
				y = y >> 1;
				x = (x * x) % mod;
			}
			return res;
		}

	}

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

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

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

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

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


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

public class CodeforcesC {
    static long M = 1000000007;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int x = scanner.nextInt();
        long n = scanner.nextLong();
        List<Integer> primes = getPrimes(x);
        long result = 1;
        for (Integer p : primes) {
            long power = 0;
            long nn=n;
            while (nn > 1) {
                power += nn / p;
                nn /= p;
            }
            long pwr = p;
            while (power > 0) {
                if ((power & 1) != 0) {
                    result = result * pwr % M;
                }
                pwr = pwr * pwr % M;
                power /= 2;
            }
        }
        System.out.println(result);
    }

    private static List<Integer> getPrimes(int x) {
        List<Integer> primes = new ArrayList<>();
        List<Integer> result = new ArrayList<>();
        primes.add(2);
        if (x % 2 == 0) {
            result.add(2);
            while (x % 2 == 0) x /= 2;
        }
        for (int i = 3; i * i < x; i += 2) {
            boolean isPrime = true;
            for (Integer p : primes) {
                if (i % p == 0) {
                    isPrime = false;
                    break;
                }
            }
            if (isPrime) {
                primes.add(i);
                if (x % i == 0) {
                    result.add(i);
                    while (x % i == 0) x /= i;
                }
            }
        }
        if (!result.contains(x)) result.add(x);
        return result;
    }
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] num = get(n);

        // dp[i][j][m][k] i means the ith ,and j mean the have the one number or
        // two number,k means equals num or not
        int[][][][] dp = new int[10][10][10][2];
        for (int i = 0; i < num[0]; i++)
            dp[1][i][i][0]++;
        dp[1][num[0]][num[0]][1]++;

        for (int i = 2; i <= num.length; i++) {
            for (int j = 0; j < 10; j++)
                for (int k = 0; k < 10; k++) {
                    if (dp[i - 1][j][k][0] > 0) {
                        if (j == k) {
                            for (int p = 0; p < 10; p++) {
                                if (j == 0)
                                    dp[i][p][p][0] += dp[i - 1][j][k][0];
                                else {
                                    dp[i][p][j][0] += dp[i - 1][j][k][0];
                                }
                            }
                        } else {
                            dp[i][j][k][0] += 2 * dp[i - 1][j][k][0];
                        }
                    }

                    if (dp[i - 1][j][k][1] > 0) {
                        if (j == k) {
                            if (j == 0)
                                dp[i][num[i - 1]][num[i - 1]][1] += dp[i - 1][j][k][1];
                            else
                                dp[i][j][num[i - 1]][1] += dp[i - 1][j][k][1];
                            for (int p = 0; p < num[i - 1]; p++) {
                                if (j == 0)
                                    dp[i][p][p][0] += dp[i - 1][j][k][1];
                                else {
                                    dp[i][j][p][0] += dp[i - 1][j][k][1];
                                }
                            }
                        } else {
                            if (num[i - 1] == j || num[i - 1] == k)
                                dp[i][j][k][1] += dp[i - 1][j][k][1];
                            if (j < num[i - 1])
                                dp[i][j][k][0] += dp[i - 1][j][k][1];
                            if (k < num[i - 1])
                                dp[i][j][k][0] += dp[i - 1][j][k][1];
                        }
                    }
                }
        }

        int sum = 0;
        for (int j = 0; j < 10; j++)
            for (int k = 0; k < 10; k++) {
                sum += dp[num.length][j][k][0] + dp[num.length][j][k][1];
            }

        System.out.println((sum - 1));
    }

    static int[] get(int n) {
        int[] ans = new int[20];
        int len = 0;
        while (n / 10 != 0) {
            ans[len++] = n % 10;
            n = n / 10;
        }

        ans[len++] = n;

        int[] rev = new int[len];
        for (int i = 0; i < len; i++) {
            rev[i] = ans[len - i - 1];
        }

        return rev;
    }
}


import java.util.Hashtable;
import java.util.Scanner;

public class B {

    static Hashtable<Integer, Integer> ht = new Hashtable<Integer, Integer>();

    public static StringBuilder fit(String s, int n) {
        String s1 = s;
        int l = s1.length();
        for (int i = 0; i < n - l; i++) {
            s1 = "0" + s1;
        }
        return new StringBuilder(s1);
    }

    public static int test(int n, int x, int y, long max) {
        int count = 0;
        for (int i = 0; i < 2 << n; i++) {
            StringBuilder s = fit(Integer.toBinaryString(i), n);
            StringBuilder s2 = new StringBuilder("");
            for (int j = 0; j < s.length(); j++) {
                if (s.charAt(j) - '0' == 0)
                    s2.append(x);
                else
                    s2.append(y);
            }
            int num = Integer.parseInt(s2.toString());
            if (!ht.containsKey(num) && num <= max&&num!=0) {
                count++;
                ht.put(num, num);
//              System.out.println(num);
            }
        }
        return count;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // int count=0;
        // for(int i=1000;i<10001;i++){
        // if(i%10!=0){
        // String s=i+"";
        // int c=0;
        // boolean []a=new boolean[10];
        // for(int j=0;j<s.length();j++){
        // if(!a[s.charAt(j)-'0']){
        // c++;
        // a[s.charAt(j)-'0']=true;
        // }
        // if(c>2)
        // break;
        // }
        // if(c<=2)
        // count++;
        // }
        // }
        // System.out.println(count);
        int n = in.nextInt();
        String s = Integer.toString(n);
        int res = 0;
        for (int i = 0; i < 10; i++) {
            for (int j = i + 1; j < 10; j++) {
                for (int k = 1; k < s.length()+1; k++) {
                    res += test(k, i, j, n);
                }
            }
        }
        System.out.println(res);
    }

}


package LIS;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class A {

	static int BFS(long n){
		Queue<Long> Q = new LinkedList<Long>();
		int cont = 0;

		for(int i=1;i<=9;i++) {
			if(i<=n) {
				Q.add((long)i);
				cont++;
			}
		}

		while(!Q.isEmpty()){
			long now = Q.remove();
			for(int i=0;i<=9;i++){

				if(now*10+i<=n) {
					Q.add(now*10+i);
					Q.add(now);
					if(i==now){
						Q.add((long)(-1));
					}
					else Q.add((long)i);
				}
			}

			if(now==9) break;
		}

		while(!Q.isEmpty()){
			long now = Q.remove();
			long uno = Q.remove();
			long dos = Q.remove();

			if(now>n) continue;

			cont++;

			if(dos==-1) {
				for(int i=0;i<=9;i++){
					if(now*10+i<=n){
						Q.add(now*10+i);
						Q.add(uno);
						if(i==uno){
							Q.add((long)(-1));
						}
						else Q.add((long)i);
					}
				}
			}else{

				Q.add(now*10+uno);
				Q.add(uno);
				Q.add(dos);

				Q.add(now*10+dos);
				Q.add(uno);
				Q.add(dos);
			}

		}

		return cont;

	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long n = in.nextLong();
		System.out.println(BFS(n));
	}

}


import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

/**
 *
 * @author Hidayat
 */
public class B245 {

    public static void main(String args[]) {

        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), k = in.nextInt(), x = in.nextInt();

        List<Integer> a = new LinkedList<Integer>();
        int b[] = new int[101];
        for (int i = 1; i <= n; i++) {
            int col = in.nextInt();
            a.add(col);
            b[i - 1] = col;
        }

        int result = 0;

        for (int i = 1; i <= n - 1; i++) {

            a = new LinkedList<Integer>();
            for (int idx = 0; idx < n; idx++) {
                a.add(b[idx]);
            }
            a.add(i, x);
            boolean removed = false;

            do {
                if (a.size() < 3) {
                    removed = false;
                } else {
                    int countg = 1;
                    int size = a.size();
                    for (int j = 1; j < size; j++) {
                        if (a.get(j) == a.get(j - 1)) {
                            countg++;
                        } else {
                            if (countg >= 3) {

                                for (int idx = j - 1; idx >= j - countg; idx--) {
                                    a.remove(idx);
                                }
                                removed = true;
                                countg = 1;
                                break;
                            }
                            countg = 1;
                        }
                    }
                    if (countg >= 3) {
                        int sz = a.size();
                        for (int idx = sz - 1; idx >= sz - countg; idx--) {
                            a.remove(idx);
                        }
                    }

                }

            } while (removed);
            if (a.size() < n) {
                result = Math.max(result, n - a.size());
            }
        }
        System.out.println(result);

    }
}


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

public class BallsGame {

	public static void main(String[] args) throws IOException {
		BallsGame main = new BallsGame();
		main.solve();
	}

	void solve() throws IOException {
		ReaderBallsGame reader = new ReaderBallsGame();
		reader.Init(System.in);
		int n = reader.NextInt();
		int k = reader.NextInt();
		int x = reader.NextInt();
		int[] balls = new int[n];
		for (int i = 0; i < n; i++) {
			balls[i] = reader.NextInt();
		}
		int res = 0;
		int max = Integer.MIN_VALUE;
		int temp = 0;
		for (int i = 0; i < n; i++) {
			if (balls[i] == x) {
				res = 0;
				temp++;
				int j = i;
				int l = i - 1;
				do {
					if (temp >= 3) {
						res += temp;
						temp = 0;
					}
					for (; j < n; j++) {
						if (balls[j] == x) {
							temp++;
						} else {

							break;
						}

					}
					for (; l >= 0; l--) {
						if (balls[l] == x) {
							temp++;
						} else {

							break;
						}
					}
					if (l >= 0 && j < n) {
						x = balls[j];
					}
				} while (temp >= 3);
				if (res - 1 > max) {
					max = res-1;
				}
			}
		}
		if(max == -1 )
		{
			max =0;
		}
		System.out.print(max);
	}
}

class ReaderBallsGame {
	static BufferedReader reader;
	static StringTokenizer tokenizer;

	static void Init(InputStream input) {
		reader = new BufferedReader(new InputStreamReader(input));
		tokenizer = new StringTokenizer("");
	}

	static String Next() throws IOException {
		while (!tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}

	static int NextInt() throws IOException {
		return Integer.parseInt(Next());
	}

	static long NextLong() throws IOException {
		return Long.parseLong(Next());
	}

	static Double NextDouble() throws IOException {
		return Double.parseDouble(Next());
	}
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class CF_245B {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int x = sc.nextInt();

        int[] b = new int[n];
        for(int i=0; i<n; i++) b[i] = sc.nextInt();

        if(n<=1){
            System.out.println(0);
            return;
        }

        int max = 0;

        for(int i=1; i<n; i++){
            int l=i-1;
            int r=i;
            int[] col = new int[k];
            int count = 0;
            if (b[l]==b[r] && b[r]==x){
                int act = 3;
                while(l>=0 && r<n && b[l]==b[r]){
                    while(l>0 && b[l-1]==b[l]){
                        l--;
                        act++;
                    }
                    while(r<n-1 && b[r+1]==b[r]){
                        r++;
                        act++;
                    }
                    if(act>=3) {
                        count+=act;
                        act = 2;
                    }
                    l--;
                    r++;

                }
            } else continue;
            max = Math.max(max,count-1);
        }

        System.out.println(max);

    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

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

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

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

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

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

}


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

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

    static class TaskD {
        private final int MOD = (int) 1e9 + 7;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt(), m = in.nextInt();

            long ans = 0;
            for (int i = 0; i <= n; ++i) {
                for (int j = 0; j <= m; ++j) {
                    int eveni = n % 2 == 1 ? (n + 1) / 2 : n / 2 + (i + 1) % 2;
                    int evenj = m % 2 == 1 ? (m + 1) / 2 : m / 2 + (j + 1) % 2;

                    int oddi = n - eveni + 1;
                    int oddj = m - evenj + 1;

                    int odd = oddi * oddj;
                    int all = (n + 1) * (m + 1);
                    int even = all - odd;

                    ans += (long) even * even % MOD;
                    ans += (long) odd * odd % MOD;
                    ans %= MOD;
                }
            }

            int[] dp;
            dp = new int[n + 1];
            for (int i = 1; i <= n; ++i) {
                dp[i] = dp[i - 1] + i;
                ans = (ans - 6L * (m + 1) * dp[i]) % MOD;
            }
            dp = new int[m + 1];
            for (int i = 1; i <= m; ++i) {
                dp[i] = dp[i - 1] + i;
                ans = (ans - 6L * (n + 1) * dp[i]) % MOD;
            }

            dp = new int[m + 1];

            for (int i = 1; i <= n; ++i) {
                int[] ndp = new int[m + 1];
                //ndp[0] = dp[0] + i;
                //ans = (ans - 6L * ndp[0]) % MOD;
                for (int j = 1; j <= m; ++j) {
                    ndp[j] = (dp[j] + ndp[j - 1]) % MOD;
                    ndp[j] = (ndp[j] - dp[j - 1]) % MOD;
                    ndp[j] = (ndp[j] + gcd(i, j)) % MOD;
                    ans = (ans - 12L * ndp[j]) % MOD;

                    //int sub = (i + 1) * (j + 1) - 1;
                    //ans = (ans - 6L * sub) % MOD;
                }
                dp = ndp;
            }

            ans -= (n + 1) * (m + 1);
            ans %= MOD;
            if (ans < 0) ans += MOD;

            out.println(ans);
        }

        private int gcd(int a, int b) {
            int c;
            while (b != 0) {
                c = a % b;
                a = b;
                b = c;
            }
            return a;
        }

    }

    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.math.BigInteger;
import static java.math.BigInteger.*;

import java.util.*;

public class Solution{

    long mod=1000000007;
    void solve()throws Exception
    {
        long res=0;
        int w=nextInt();
        int h=nextInt();
        for(int x1=0;x1<2;x1++)
            for(int x2=0;x2<2;x2++)
                for(int x3=0;x3<2;x3++)
                    for(int y1=0;y1<2;y1++)
                        for(int y2=0;y2<2;y2++)
                            for(int y3=0;y3<2;y3++)
                            {
                                int[]x=new int[]{x1,x2,x3};
                                int rem=Math.abs((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1));
                                if(rem%2!=0)
                                    continue;
                                long a=count(x,w);
                                long b=count(new int[]{y1,y2,y3},h);
                                res+=a*b;
                                res%=mod;
                            }
        int[][][]a1=get(w);
        int[][][]a2=get(h);
        for(int i=0;i<2;i++)
            for(int a=0;a<=w && a<=h;a++)
                for(int b=0;b<=w&& b<=h;b++)
                {
                    res-=(long)a1[i][a][b]*a2[i][a][b];
                    res%=mod;
                    if(res<0)
                        res+=mod;
                }
        for(int x1=0;x1<=w;x1++)
            for(int y1=0;y1<=h;y1++)
            {
                long cur=h+1+w+1-1;
                res-=cur*cur;
                res%=mod;
                if(res<0)
                    res+=mod;
            }
        System.out.println(res);

    }

    private int[][][] get(int n) {
        int[][]gcd=new int[n+1][n+1];
        int[][][]res=new int[2][n+1][n+1];
        for(int i=0;i<=n;i++)
            for(int j=0;j<=n;j++)
            {
                if(i==0 || j==0)
                    gcd[i][j]=i+j;
                else if(i>=j)
                    gcd[i][j]=gcd[i-j][j];
                else
                    gcd[i][j]=gcd[i][j-i];
            }
        for(int a=-n;a<=n;a++)
            for(int b=-n;b<=n;b++)
            {
                if(a==0 || b==0)
                    continue;
                int g=gcd[Math.abs(a)][Math.abs(b)];
                int[]x1=getRange(a,n);
                int[]x2=getRange(b,n);
                int com=getCom(x1,x2);
                int A=a;
                int B=b;
                A/=g;
                B/=g;
                if(A*B<0)
                {
                    A=Math.abs(A);
                    B=Math.abs(B);
                    res[1][A][B]+=com;
                }
                else
                {
                    A=Math.abs(A);
                    B=Math.abs(B);
                    res[0][A][B]+=com;
                }

            }
        return res;
    }

    private int getCom(int[] x1, int[] x2) {
        Arrays.sort(x1);
        Arrays.sort(x2);
        if(x1[0]>x2[1])
            return 0;
        if(x2[0]>x1[1])
            return 0;
        return Math.min(x2[1],x1[1])-Math.max(x1[0],x2[0])+1;
    }

    private int[] getRange(int a, int n) {
        if(a>=0)
            return new int[]{0,n-a};
        else
        {
            return new int[]{-a,n};
        }
    }

    private long count(int[] x, int w) {
        long res=1;
        long[]num=new long[2];
        num[0]=1+w/2;
        num[1]=w+1-num[0];
        for(int X: x)
        {
            res*=num[X];
            res%=mod;
        }
        return res;

    }

    ////////////
    BufferedReader reader;
    PrintWriter writer;
    StringTokenizer stk;
    void run()throws Exception
    {

        reader=new BufferedReader(new InputStreamReader(System.in));
        // reader=new BufferedReader(new FileReader("input.txt"));
        stk=null;
        writer=new PrintWriter(new PrintWriter(System.out));
        //writer=new PrintWriter(new FileWriter("output.txt"));
        solve();
        reader.close();
        writer.close();
    }
    int nextInt()throws Exception
    {
        return Integer.parseInt(nextToken());
    }

    long nextLong()throws Exception
    {
        return Long.parseLong(nextToken());

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

    }

    String nextString()throws Exception
    {
        return nextToken();
    }
    String nextLine()throws Exception
    {
        return reader.readLine();
    }
    String nextToken()throws Exception
    {
        if(stk==null || !stk.hasMoreTokens())
        {
            stk=new StringTokenizer(nextLine());
            return nextToken();

        }
        return stk.nextToken();
    }

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

}


import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.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 {
    int n;
    int m;
    final int M = 1000000007;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        n = in.nextInt();
        m = in.nextInt();
        int ans = 0;
        for (int y = 0; y <= n; y++)
            for (int x = 0; x <= m; x++) {
                ans += calculateFitTriples(x, y);
                if (ans >= M)
                    ans -= M;
            }
        ans -= calculateBadTriples();
        if (ans < 0)
            ans += M;
        // Fix a strange bug :)
        ans += (n + 1) * (m + 1);
        if (ans >= M)
            ans -= M;
        out.println(ans);
    }

    int calculateFitTriples(int x, int y) {
        int ret = 0;
        int x0 = x % 2, y0 = y % 2;
        for (int x1 = 0; x1 <= 1; x1++)
            for (int y1 = 0; y1 <= 1; y1++)
                for (int x2 = 0; x2 <= 1; x2++)
                    for (int y2 = 0; y2 <= 1; y2++) {
                        int ax = (2 + x1 - x0) % 2;
                        int ay = (2 + y1 - y0) % 2;
                        int bx = (2 + x2 - x0) % 2;
                        int by = (2 + y2 - y0) % 2;
                        int areaMod2 = (2 + ax * by - ay * bx) % 2;
                        if (areaMod2 != 0) continue;
                        long X1 = getPointsOnSegmentWithParity(m, x1);
                        long Y1 = getPointsOnSegmentWithParity(n, y1);
                        long X2 = getPointsOnSegmentWithParity(m, x2);
                        long Y2 = getPointsOnSegmentWithParity(n, y2);
                        ret += (((((X1 * Y1) % M) * X2) % M) * Y2) % M;
                        if (ret >= M)
                            ret -= M;
                    }
        return ret;
    }

    int getPointsOnSegmentWithParity(int len, int par) {
        if (par == 0)
            return (len / 2) + 1;
        else
            return (len + 1) / 2;
    }

    int calculateBadTriples() {
        int ret = 0;
        for (int dn = 0; dn <= n; dn++)
            for (int dm = 0; dm <= m; dm++) {
                if (dn == 0 && dm == 0) {
                    ret += (n + 1) * (m + 1) * 2;
                    if (ret >= M)
                        ret -= M;
                    continue;
                }
                int times = (n - dn + 1) * (m - dm + 1);
                int innerPoints = gcd(dn, dm) - 1;
                int permutations = 6 * innerPoints + 6;
                long add = (long) permutations * times;
                if (dn != 0 && dm != 0)
                    add *= 2;
                ret += add % M;
                if (ret >= M)
                    ret -= M;
            }
        return ret;
    }

    int gcd(int a, int b) {
        return b != 0 ? gcd(b, a % b) : a;
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

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

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

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


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

public class A {
	public static void main(String[] args) throws IOException {
		st = new StringTokenizer(rd.readLine());
		M = Integer.parseInt(st.nextToken());
		N = Integer.parseInt(st.nextToken());
		F[0] = 1;
	//	for(int i=0; i<=4000; i++) for(int j=0; j<=4000; j++) g[i][j] = gcd(i, j);
		for(int i=1; i<F.length; i++) F[i] = (F[i-1]*i)%Q;
		for(int i=0; i<IF.length; i++) IF[i] = pow(F[i], Q-2);
		long[] X = new long[4];
		long numEven1 = N/2+1, numOdd1 = N+1-numEven1, numEven2 = M/2+1, numOdd2 = M+1-numEven2;
		X[0] = numEven1*numEven2;
		X[1] = numEven1*numOdd2;
		X[2] = numOdd1*numEven2;
		X[3] = numOdd1*numOdd2;
	//	System.out.println(Arrays.toString(X));
		P = new Point[4];
		P[0] = new Point(0, 0);
		P[1] = new Point(0, 1);
		P[2] = new Point(1, 0);
		P[3] = new Point(1, 1);
		long res = 0;
		for(int i=0; i<4; i++){
			for(int j=0; j<4; j++){
				for(int k=0; k<4; k++){
					if(isOk(i, j, k)){
						if(i!=j && j!=k && i!=k){
							res = (res + ((X[i]*X[j])%Q)*X[k])%Q;
						}
						else if(i!=j && j!=k && i==k){
							res = (res + (X[i]>0? ((X[i]*X[j])%Q)*(X[i]-1): 0))%Q;
						}
						else if(i!=j && j==k && i!=k){
							res = (res + (X[j]>0? ((X[i]*X[j])%Q)*(X[j]-1): 0))%Q;
						}
						else if(i!=j && j==k && i==k){
							//
						}
						else if(i==j && j!=k && i!=k){
							res = (res + (X[i]>0? ((X[i]*(X[i]-1))%Q)*X[k]: 0))%Q;
						}
						else if(i==j && j!=k && i==k){
							//
						}
						else if(i==j && j==k && i!=k){
							//
						}
						else if(i==j && j==k && i==k){
							res = (res + (X[i]>1? ((X[i]*(X[i]-1))%Q)*(X[i]-2): 0))%Q;
						}
					}
				}
			}
		}
		pw.println((res-numOnLine()+Q)%Q);
		int r = 0;
		pw.flush();
		if(r==0) return;
		for(int x1=0; x1<=M; x1++){
			for(int x2=0; x2<=M; x2++){
				for(int x3=0; x3<=M; x3++){
					for(int y1=0; y1<=N; y1++){
						for(int y2=0; y2<=N; y2++){
							for(int y3=0; y3<=N; y3++){
								int s = Math.abs(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2));
								if(s!=0 && s%2==0) r++;
							}
						}
					}
				}
			}
		}
//		System.out.println(r);
	}

	static int numOnLine(){
		long res = 0;
		for(int m=0; m<=M; m++){
			for(int n=0; n<=N; n++){
				long mult = (M-m+1)*(N-n+1);
				if(m==0 || n==0){
					int s = m+n;
					if(s>=2){
						res = (res + mult*(s-1)*6)%Q;
		//				System.out.println("XAZI");
					}
				}
				else{
					int d = gcd(m, n);
					int t = n/d;
					int num = n/t+1;
					if(num>=3){
				//		if(m<2 && n<2) System.out.println("TY");
		//				System.out.println("diagonali");
						res = (res + mult*(num-2)*12)%Q;
					}
				}
			}
		}
		return (int) res;
	}

	static int gcd1(int x, int y){
		if(x==0 || y==0) return x+y;
		if(x==1 || y==1) return 1;
		if(x>y) return gcd1(x%y, y);
		return gcd1(x, y%x);
	}

	static long getA(int x, int y){
		return F[x]*IF[x-y];
	}

	static long[] F = new long[4001], IF = new long[4001];

	static long pow(long x, long y){
		if(y==0) return 1;
		if(y==1) return x%Q;
		long sq = pow(x, y>>1);
		return y%2==0? (sq*sq)%Q: (((sq*sq)%Q)*x)%Q;
	}

	static int gcd(int x, int y){
		if(x>y) return gcd(y, x);
		if(x==0 || y==0) return x+y;
		if(x==1 || y==1) return 1;
		if((x&1)==0 && (y&1)==0) return 2*gcd(x>>1, y>>1);
		if((x&1)==0) return gcd(x>>1, y);
		if((y&1)==0) return gcd(x, y>>1);
		return gcd(x, (y-x)>>1);
	}

	static int[][] g = new int[4001][4001];

	static int Q = 1000000007;

	static Point[] P;

	static boolean isOk(int i, int j, int k){
		Point a = new Point(P[i].x, P[i].y), b = new Point(P[j].x, P[j].y), c = new Point(P[k].x, P[k].y);
		int mult = a.x*(b.y-c.y)+b.x*(c.y-a.y)+c.x*(a.y-b.y)+1000;
		return mult%2==0;
	}

	static int M, N;

	static BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter pw = new PrintWriter(System.out);
	static StringTokenizer st;

}

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

	public int x, y;

}