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

/**
 * Created by vikas.k on 14/03/17.
 */
public class CF086C {
    public static PrintWriter out;
    public static FastScanner in;
    private List<Integer> primes;

    private void solve(){
        int lo = in.nextInt();
        int hi = in.nextInt();

        int limit = (int)Math.sqrt(hi);
        boolean[] mrk = simpleSieve(limit);
        primes = new ArrayList<>();
        for(int i=2;i<mrk.length;i++){
            if(mrk[i]) primes.add(i);
        }
        int cnt = 0;
        if(2 >= lo && 2<=hi) cnt++;
        if(lo<=limit){
            int k = (lo-1)%4 == 0 ? (lo-1)/4 : ((lo-1)/4 + 1);
            int st = 4*k+1;
            while (st<=limit){
                if(mrk[st]) cnt++;
                st = 4*(++k)+1;
            }
            lo = limit+1;
        }

        for(;lo+limit<=hi;lo+=limit+1){
            mrk = sieve(lo,lo+limit);
            int k = (lo-1)%4 == 0 ? (lo-1)/4 : ((lo-1)/4 + 1);
            int st = 4*k+1;
            while (st<=lo+limit){
                if(mrk[st-lo]) cnt++;
                st = 4*(++k)+1;
            }
        }
        mrk = sieve(lo,hi);
        int k = (lo-1)%4 == 0 ? (lo-1)/4 : ((lo-1)/4 + 1);
        int st = 4*k+1;
        while (st<=hi){
            if(mrk[st-lo]) cnt++;
            st = 4*(++k)+1;
        }
        out.print(cnt);
    }

    private boolean[] sieve(int lo,int hi){
        boolean[] ret = new boolean[hi-lo+1];
        Arrays.fill(ret,true);

        for (int p:primes){
            int st = lo%p == 0 ? lo : ((lo/p)+1)*p;
            for(int i = st;i<=hi;i+=p){
                ret[i-lo]= false;
            }
        }
        return ret;
    }
    private boolean[] simpleSieve(int n){
        boolean[] ret = new boolean[n+1];
        Arrays.fill(ret,true);
        ret[0] = false;
        ret[1] = false;
        for(int i=2+2;i<=n;i+=2){
            ret[i] = false;
        }

        for(int i=3;i*i<=n;i+=2){
            if(ret[i]){
                for(int j=i*2;j<=n;j+=i){
                    ret[j] = false;
                }
            }
        }
        return ret;
    }

    private void runIO(){
        in = new FastScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        solve();
        out.close();
    }
    private static class FastScanner {
        BufferedReader bufferedReader;
        StringTokenizer stringTokenizer;

        private FastScanner(){
            bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        }

        private String next(){
            if(stringTokenizer == null || !stringTokenizer.hasMoreElements()){
                try {
                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return stringTokenizer.nextToken();
        }

        private int nextInt(){
            return Integer.parseInt(next());
        }
        private long nextLong(){
            return Long.parseLong(next());
        }
        private String nextLine(){
            String ret= "";
            try {
                ret= bufferedReader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return ret;
        }
    }

    public static void main(String[] args) {
        new CF086C().runIO();
    }
}


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

public class Main {
    static void solve() throws IOException {
        int n = ni1();
        rl();
        int a[] = new int[n];
        int b[] = new int[n];
        int c[] = new int[n];
        for (int i = 0; i < n; i++) a[i] = b[i] = ni2();
        Arrays.sort(b);
        for (int i = 0; i < n; i++) {
            int k = Arrays.binarySearch(b, a[i]);
            c[i] = b[(k + 1) % n];
        }
        for (int i = 0; i < n; i++) ans.append(c[i]).append(" ");
        output.write(ans.toString());
        output.flush();
        output.close();
    }

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

    static BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out));
    static StringBuilder ans = new StringBuilder();
    static String line;
    static StringTokenizer stringTokenizer;

    static int ni1() throws IOException {
        return Integer.parseInt(input.readLine());
    }

    static int ni2() throws IOException {
        return Integer.parseInt(stringTokenizer.nextToken());
    }

    static long nl1() throws IOException {
        return Long.parseLong(input.readLine());
    }

    static long nl2() {
        return Long.parseLong(stringTokenizer.nextToken());
    }

    static void rl() throws IOException {
        stringTokenizer = new StringTokenizer(input.readLine());
    }
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Problem931B {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		out=new PrintWriter (new BufferedOutputStream(System.out));
		FastReader s=new FastReader();
		int n=s.nextInt();
		int a=s.nextInt();
		int b=s.nextInt();
		int temp1=Integer.max(a, b);
		int temp2=Integer.min(a, b);
		a=temp2;
		b=temp1;
		int count=0;
		int rounds=0;
		int temp=n;
		while(temp>0) {
			temp=temp/2;
			rounds++;
		}
		rounds--;
		int start=0;
		int end=n;
		while(end>start) {
			int mid=(end+start)/2;
			if(mid>=a && mid<b) {
				break;
			}else if(mid>=a && mid>=b){
				end=mid;
				count++;
			}else if(mid<a && mid<b) {
				start=mid;
				count++;
			}
		}
		if(count==0) {
			out.println("Final!");
			out.close();
			return;
		}
		out.println(rounds-count);
		out.close();
	}

	public static PrintWriter out;

	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
		//it reads the data about the specified point and divide the data about it ,it is quite fast
		//than using direct

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

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

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

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

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

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

}


import java.io.*;
public class round29B {

    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String [] use = br.readLine().split(" ");
        int totDist = Integer.parseInt(use[0]);
        int trafficDist = Integer.parseInt(use[1]);
        int speed = Integer.parseInt(use[2]);
        int green = Integer.parseInt(use[3]);
        int red = Integer.parseInt(use[4]);
        double t1 = (double)trafficDist / (double)speed;
        double cur = green;
        boolean f = true;
        while(t1 >= cur){
            cur += (f == true) ? red : green;
            f = !f;
        }
        t1 += f == false ? (cur - t1) : 0;
        t1 += ((double)(totDist - trafficDist) / (double)speed);
        System.out.println(t1);
    }
}


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

public class Main {
//	static Scanner in; static int next() throws Exception {return in.nextInt();};
//	static StreamTokenizer in; static int next() throws Exception {in.nextToken(); return (int) in.nval;}
	static BufferedReader in;
	static PrintWriter out;
	static int n = 1000;
	static boolean[][] win = new boolean[n][n];

	static HashMap<String, Integer> map;

	static boolean go(long a, long b) {
//		System.out.println(a + " " + b);
		//if (a < n && b < n) return win[(int)a][(int)b];
		if (a == 0 || b == 0) return false;

		if (a > b) {
			long temp = a;
			a = b;
			b = temp;
		}

		long c = b % a;

		boolean w1 = go(c, a);
		if (!w1) return true;

		long d = b/a;

		if (a % 2 == 1) return d % 2 == 0;

		long e = d % (a + 1);
		return e % 2 == 0;
	}

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

	static int rand() {return (int)(Math.random() * 1e9);}

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

/*		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) if (i != 0 || j != 0) if (!win[i][j]) {
				if (i < j) for (int t = i + j; t < n; t += j) win[t][j] = true;
				else for (int t = i + j; t < n; t += i) win[i][t] = true;

				if (j > 1) for (int t = j; i + t < n; t *= j) win[i + t][j] = true;
				else if (j > 0 && i + j < n) win[i + j][j] = true;
				if (i > 1) for (int t = i; j + t < n; t *= i) win[i][j + t] = true;
				else if (i > 0 && i + j < n) win[i][j + i] = true;
			}
	   	}*/

/*	   	for (int i = 0; i < 50; i++) {
	   		for (int j = 0; j < 50; j++) out.print(win[i][j] ? "1 " : "0 ");
	   		out.println();
	   	}
	   	int count = 0;
	   	for (int i = 1; i < n; i++) for (int j = 1; j < n; j++) if (!win[i][j]) count++;
	   	out.println(count);*/

		int tests = Integer.parseInt(in.readLine());
		for (int test = 0; test < tests; test++) {
			map = new HashMap<String, Integer>();
			String[] s = in.readLine().split(" ");
			out.println(go(Long.parseLong(s[0]), Long.parseLong(s[1])) ? "First" : "Second");
		}

		out.close();
	}
}


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

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

		char[] here = new char[n];
		char[] current = new char[n];
		char[] result = new char[n];
		;
		int te = n - 2;
		String temp = sc.next();
		for (int i = 0; i < n; i++) {
			here[i] = temp.charAt(i);
		}

		int count = 0;

		while (count != t) {
			if (count == 0)
				current = here;

			else {
				current = result;
				result = new char[n];
			}
			int i ;
			for ( i = 0; i < n - 1; i++) {
				char c = current[i];
				char b = current[i + 1];
				if (c == 'B')
					if (b == 'G') {
						result[i] = 'G';
						result[i + 1] = 'B';
						i++;
					} else {
						result[i] = 'B';
						result[i + 1] = 'B';
					}
				else {
					result[i] = c;
					result[i + 1] = b;

					if (b == 'G')
						i++;

				}

			}
			if(i==n-1){
				result[n-1]=current[n-1];

			}
			if (i<n-1) {
				char c = result[te];
				char b = current[n - 1];
				System.out.println(c);
				System.out.println(b);
				if (c == 'B')
					if (b == 'G') {
						result[te] = 'G';
						result[n - 1] = 'B';
					} else {
						result[te] = 'B';
						result[n - 1] = 'B';
					}
				else {
					result[te] = c;
					result[n - 1] = b;
				}
			}
			count++;
		}

		System.out.println(result);

	}
}


/*
    Author: Anthony Ngene
    Created: 24/08/2020 - 05:51
*/

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

public class A {
// It is only a fool that goes to dinner with the devil and fails to use a long spoon. - African Proverb
    public static void main(String[] args) throws IOException {
        in = new FastScanner();

        int n = in.intNext();
        int[] arr = in.nextIntArray(n);

        HashSet<Integer> seen = new HashSet<>();
        List<Integer> unique = new ArrayList<>();
        for (int i = n - 1; i >= 0; i--) {
            if (!seen.contains(arr[i])) {
                seen.add(arr[i]);
                unique.add(arr[i]);
            }
        }
        out.println(unique.size());
        for (int i = unique.size()-1; i >= 0; i--) {
            out.p(unique.get(i)).p(" ");
        }
        out.close();
    }

// checks: 1. edge cases   2. overflow   3. possible errors (e.g 1/0, arr[out])   4. time/space complexity
// Generated Code Below:
private static final FastWriter out = new FastWriter();
private static FastScanner in;
static ArrayList<Integer>[] adj;
private static long e97 = (long)1e9 + 7;
static class FastWriter {
    private static final int IO_BUFFERS = 128 * 1024;
    private final StringBuilder out;
    public FastWriter() { out = new StringBuilder(IO_BUFFERS); }
    public FastWriter p(Object object) { out.append(object); return this; }
    public FastWriter p(String format, Object... args) { out.append(String.format(format, args)); return this; }
    public FastWriter pp(Object... args) { for (Object ob : args) { out.append(ob).append(" ");  } out.append("\n"); return this; }
    public FastWriter pp(int[] args) { for (int ob : args) { out.append(ob).append(" ");  } out.append("\n"); return this; }
    public FastWriter pp(long[] args) { for (long ob : args) { out.append(ob).append(" ");  } out.append("\n"); return this; }
    public FastWriter pp(char[] args) { for (char ob : args) { out.append(ob).append(" ");  } out.append("\n"); return this; }
    public void println(long[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
    public void println(int[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
    public void println(char[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
    public void println(double[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
    public void println(boolean[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
    public <T>void println(T[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
    public void println(long[][] arr) {  for (long[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
    public void println(int[][] arr) {  for (int[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
    public void println(char[][] arr) {  for (char[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
    public void println(double[][] arr) {  for (double[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
    public <T>void println(T[][] arr) {  for (T[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
    public FastWriter println(Object object) { out.append(object).append("\n"); return this; }
    public void toFile(String fileName) throws IOException {
        BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
        writer.write(out.toString());
        writer.close();
    }
    public void close() throws IOException { System.out.print(out); }
}
static class FastScanner {
    private InputStream sin = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(){}
    public FastScanner(String filename) throws FileNotFoundException {
        File file = new File(filename);
        sin = new FileInputStream(file);
    }
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = sin.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long longNext() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b) || b == ':'){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int intNext() {
        long nl = longNext();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double doubleNext() { return Double.parseDouble(next());}
    public long[] nextLongArray(final int n){
        final long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = longNext();
        return a;
    }
    public int[] nextIntArray(final int n){
        final int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = intNext();
        return a;
    }
    public double[] nextDoubleArray(final int n){
        final double[] a = new double[n];
        for (int i = 0; i < n; i++)
            a[i] = doubleNext();
        return a;
    }
    public ArrayList<Integer>[] getAdj(int n) {
        ArrayList<Integer>[] adj = new ArrayList[n + 1];
        for (int i = 1; i <= n; i++) adj[i] = new ArrayList<>();
        return adj;
    }
    public ArrayList<Integer>[] adjacencyList(int nodes, int edges) throws IOException {
        return adjacencyList(nodes, edges, false);
    }
    public ArrayList<Integer>[] adjacencyList(int nodes, int edges, boolean isDirected) throws IOException {
        adj = getAdj(nodes);
        for (int i = 0; i < edges; i++) {
            int a = intNext(), b = intNext();
            adj[a].add(b);
            if (!isDirected) adj[b].add(a);
        }
        return adj;
    }
}

}


import java.util.*;

public class NonSquareEquation {

    public static int sum(long x) {
        int ret = 0;
        while (x != 0) {
            ret += x % 10;
            x /= 10;
        }
        return ret;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long n = in.nextLong();
        for (int i = 1; i <= 90; i++) {
            double x = ((-1 * i) + (Math.sqrt(i * i - (-4 * n))));
            if (x > 0 && x % 2 == 0) {
                x /= 2;
                long x2 = (long) x;
                int sum = sum((long) x);
                long tmp = x2 * x2 + i * x2;
                if (tmp == n && i == sum) {
                    System.out.println(x2);
                    return;
                }

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


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

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

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }
            int max = 0;
            for (int b = 0; b < k; b++) {
                int sum = 0;
                for (int i = 0; i < n; i++) {
                    if ((i + b) % k != 0) {
                        sum += a[i];
                    }
                }
                max = Math.max(max, Math.abs(sum));
            }
            out.println(max);
        }

    }
}


//package srm304;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.LinkedList;

public class SoldierAndCards {

    static class Card {
        int number;

        public Card(int number) {
            this.number = number;
        }

        @Override
        public String toString() {
            return String.valueOf(number);
        }
    }

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

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());

        LinkedList<Card> playerOne = new LinkedList<Card>();
        LinkedList<Card> playerTwo = new LinkedList<Card>();

        String[] parts = br.readLine().split(" ");
        for (int i = 1; i < parts.length; i++) {
            playerOne.add(new Card(Integer.parseInt(parts[i])));
        }

        parts = br.readLine().split(" ");
        for (int i = 1; i < parts.length; i++) {
            playerTwo.add(new Card(Integer.parseInt(parts[i])));
        }

        HashSet<String> visited = new HashSet<String>();

        StringBuilder sb = new StringBuilder();
        for (Card c : playerOne)
            sb.append(c.toString() + " ");
        sb.append("\n");
        for (Card c : playerTwo)
            sb.append(c.toString() + " ");
        visited.add(sb.toString());

        int counter = 0;
        while (playerOne.size()>0 && playerTwo.size()>0) {
            counter++;
            Card top1 = playerOne.poll();
            Card top2 = playerTwo.poll();

            if (top1.number > top2.number) {
                playerOne.add(top2);
                playerOne.add(top1);
            } else {
                playerTwo.add(top1);
                playerTwo.add(top2);
            }

            sb = new StringBuilder();
            for (Card c : playerOne)
                sb.append(c.toString() + " ");
            sb.append("\n");
            for (Card c : playerTwo)
                sb.append(c.toString() + " ");

            if (visited.contains(sb.toString())) {
                break;
            }
            visited.add(sb.toString());

        }

        if (playerOne.size() == 0) {
            System.out.println(counter + " " + 2);
            return;
        }
        if (playerTwo.size() == 0) {
            System.out.println(counter + " " + 1);
            return;
        }
        System.out.println(-1);
    }

}


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

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        int[] fib = new int[n + 10];
        fib[1] = 1;
        fib[2] = 1;
        for (int i = 3; i <= n; i++)
            fib[i] = add(fib[i - 1], fib[i - 2]);
        int den = modPow(2, n);
        out.println(mult(fib[n], modPow(den, mod - 2)));
        out.flush();
        out.close();
    }

    static final int mod = 998244353;

    static int add(int a, int b) {
        long c = a + b;
        if (c >= mod) c -= mod;
        if (c < 0) c += mod;
        return (int) c;
    }

    static int mult(long a, int b) {
        return (int) (a * b % mod);
    }

    static int modPow(int b, int e) {
        int res = 1;
        while (e > 0) {
            if ((e & 1) == 1) res = mult(res, b);
            b = mult(b, b);
            e >>= 1;
        }
        return res;
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

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

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

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

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

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

        public Integer[] nextIntegerArray(int n) throws IOException {
            Integer[] ans = new Integer[n];
            for (int i = 0; i < n; i++)
                ans[i] = nextInt();
            return ans;
        }

        public char nextChar() throws IOException {
            return next().charAt(0);
        }

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

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

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

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

    }
}


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

import java.util.Scanner;

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

                 if(c==8)
                     B++;

            }
        }

        if(B!=8)
        for (int i = 0; i <8; i++) {
            if(arr[i]==8)
                B++;

        }
        System.out.println(B);

    }
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 *
 * @author pttrung
 */
public class B_Round_144_Div1 {

	public static long MOD = 1000000007;
	static long[][] dp;
	static long[][]pre;

	public static void main(String[] args) throws FileNotFoundException {
		// PrintWriter out = new PrintWriter(new FileOutputStream(new File(
		// "output.txt")));
		PrintWriter out = new PrintWriter(System.out);
		Scanner in = new Scanner();
		int n = in.nextInt();
		long m = in.nextLong();
		int k = in.nextInt();
		long[][] c = new long[101][101];
		c[0][0] = 1;

		for (int i = 1; i < 101; i++) {
			c[i][0] = 1;
			c[i][i] = 1;
			for (int j = 1; j < i; j++) {
				c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
				c[i][j] %= MOD;
			}
		}
		dp = new long[n][k + 1];
		for (long[] a : dp) {
			Arrays.fill(a, -1);
		}
		pre = new long[2][n + 1];
		for(int i = 0; i <= n; i++){
			long total = m/n;
			pre[0][i] = pow(c[n][i], total);
			pre[1][i] = (c[n][i]*pre[0][i]) % MOD;
		}
		long v = cal(0, k, n, m, c);
		out.println(v);
		out.close();
	}

	static long cal(int index, int left,int n, long m, long[][]c){

    	if(index  == n){
    		if(left == 0){
    			return 1;
    		}
    		return 0;
    	}
    	if(left == 0){
    		return 1;
    	}
    	if(dp[index][left] != -1){
    		return dp[index][left];
    	}
    	long result = 0;
    	for(int i = 0; i <= Math.min(left, n); i++){
    		long a = pre[0][i];

    		if(m % n > index && m %n != 0){
    			a = pre[1][i];
    		}

    		//System.out.println(i + " " + a + " " + index + " " + total);
    		result += (a*cal(index + 1, left - i, n, m ,c)) %MOD;
    		result %= MOD;
    	}
    	return dp[index][left] = result;
    }

	public static int[] KMP(String val) {
		int i = 0;
		int j = -1;
		int[] result = new int[val.length() + 1];
		result[0] = -1;
		while (i < val.length()) {
			while (j >= 0 && val.charAt(j) != val.charAt(i)) {
				j = result[j];
			}
			j++;
			i++;
			result[i] = j;
		}
		return result;

	}

	public static boolean nextPer(int[] data) {
		int i = data.length - 1;
		while (i > 0 && data[i] < data[i - 1]) {
			i--;
		}
		if (i == 0) {
			return false;
		}
		int j = data.length - 1;
		while (data[j] < data[i - 1]) {
			j--;
		}
		int temp = data[i - 1];
		data[i - 1] = data[j];
		data[j] = temp;
		Arrays.sort(data, i, data.length);
		return true;
	}

	public static int digit(long n) {
		int result = 0;
		while (n > 0) {
			n /= 10;
			result++;
		}
		return result;
	}

	public static double dist(long a, long b, long x, long y) {
		double val = (b - a) * (b - a) + (x - y) * (x - y);
		val = Math.sqrt(val);
		double other = x * x + a * a;
		other = Math.sqrt(other);
		return val + other;

	}

	public static class Point implements Comparable<Point> {

		int x, y;

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

		@Override
		public int hashCode() {
			int hash = 5;
			hash = 47 * hash + this.x;
			hash = 47 * hash + this.y;
			return hash;
		}

		@Override
		public boolean equals(Object obj) {
			if (obj == null) {
				return false;
			}
			if (getClass() != obj.getClass()) {
				return false;
			}
			final Point other = (Point) obj;
			if (this.x != other.x) {
				return false;
			}
			if (this.y != other.y) {
				return false;
			}
			return true;
		}

		@Override
		public int compareTo(Point o) {
			return x - o.x;
		}
	}

	public static class FT {

		long[] data;

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

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

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

		}
	}

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

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

		}
	}

	static class Scanner {

		BufferedReader br;
		StringTokenizer st;

		public Scanner() throws FileNotFoundException {
			// System.setOut(new PrintStream(new
			// BufferedOutputStream(System.out), true));
			br = new BufferedReader(new InputStreamReader(System.in));
			// br = new BufferedReader(new InputStreamReader(new
			// FileInputStream(new File("input.txt"))));
		}

		public String next() {

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

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

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

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

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

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


//package year2019.month03.cf.eduround61div2;

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

public class eduround61div2A {

    boolean ONLINE_JUDGE = (System.getProperty("ONLINE_JUDGE") != null);

    public eduround61div2A() throws IOException {
        InputReader in;
        if (ONLINE_JUDGE) {
            in = new InputReader(System.in);
        } else {
            in = new InputReader(new FileInputStream("/Users/karj/cp/input.txt"));
        }
        PrintWriter out = new PrintWriter(System.out);

        int T = 1;
        for (int caseNo = 1; caseNo <= T; caseNo++) {
            solve(caseNo, in, out);
        }

        out.close();
    }

    private void solve(int caseNo, InputReader in, PrintWriter out) throws IOException {
        long a1 = in.nextLong();
        long a2 = in.nextLong();
        long a3 = in.nextLong();
        long a4 = in.nextLong();
        if (a1 == 0 &&
                a2 == 0 &&
                a3 == 0 &&
                a4 == 0) {
            out.println(1);
            return;
        }
        if (a1 == 0 &&
                a3 == 0 &&
                a4 == 0 &&
                a2 > 0) {
            out.println(1);
            return;
        }
        if (a1 != a4) {
            out.println(0);
            return;
        }
        if (a1 == a4 && a1 == 0) {
            out.println(0);
            return;
        }
        out.println(1);
    }

    static class InputReader {

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

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

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

        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 boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public interface SpaceCharFilter {

            public boolean isSpaceChar(int ch);
        }

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

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

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

        public Long nextLong() {
            return Long.parseLong(nextString());
        }

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

        public char nextCharacter() {
            return nextString().charAt(0);
        }

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

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

        public double[] nextDoubleArray(int N) {
            double A[] = new double[N];
            for (int i = 0; i < N; i++) {
                A[i] = nextDouble();
            }
            return A;
        }
    }

    int min(int... a) {
        int min = Integer.MAX_VALUE;
        for (int v : a) {
            min = Math.min(min, v);
        }
        return min;
    }

    long min(long... a) {
        long min = Long.MAX_VALUE;
        for (long v : a) {
            min = Math.min(min, v);
        }
        return min;
    }

    double min(double... a) {
        double min = Double.MAX_VALUE;
        for (double v : a) {
            min = Math.min(min, v);
        }
        return min;
    }

    int max(int... a) {
        int max = Integer.MIN_VALUE;
        for (int v : a) {
            max = Math.max(max, v);
        }
        return max;
    }

    long max(long... a) {
        long max = Long.MIN_VALUE;
        for (long v : a) {
            max = Math.max(max, v);
        }
        return max;
    }

    double max(double... a) {
        double max = Double.MIN_VALUE;
        for (double v : a) {
            max = Math.max(max, v);
        }
        return max;
    }

    private void debug(Object... o) {
        if (ONLINE_JUDGE) {
            return;
        }
        System.out.println(Arrays.deepToString(o));
    }

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


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

public class noldbach {

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

		int topNumber = s.nextInt();
		int kPrimes = s.nextInt();
		int totalPrimes = 0;

		List<Integer> myList = new ArrayList<Integer>();

		for(int count = 2; count <= topNumber; count++){
			if(isPrime(count)){
				myList.add(count);
			}

		}

		for(int count = 0; count < myList.size() - 1; count++){
			int first = myList.get(count);
			int second = myList.get(count + 1);

			for(int counter = 0; counter < myList.size(); counter++){
				int n = myList.get(counter);
				if(isNoldbach(first, second, n)){
					totalPrimes++;
				}
			}

		}

		if(totalPrimes >= kPrimes) System.out.println("YES");
		else System.out.println("NO");
	}

	public static boolean isPrime(int n){
		for(int i = 2; i < n; i++){
			if(n % i == 0) return false;
		}
		return true;
	}

	public static boolean isNoldbach(int primeOne, int primeTwo, int n){
		if(primeOne + primeTwo + 1 == n) return true;
		return false;
	}

}


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

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

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

    static class EPlacingRooks {
        public void solve(int testNumber, FastInput in, FastOutput out) {
            int n = in.readInt();
            int k = in.readInt();
            Modular mod = new Modular(998244353);
            int m = n - k;

            if (k == 0) {
                int ans = 1;
                for (int i = 1; i <= n; i++) {
                    ans = mod.mul(ans, i);
                }
                out.println(ans);
                return;
            }
            if (m <= 0 || m > n) {
                out.println(0);
                return;
            }

            PrimeCombination combination = new PrimeCombination(n, mod);
            Power power = new Power(mod);
            int ans = 0;
            for (int i = 0; i <= m; i++) {
                int local = combination.combination(m, i);
                if (i % 2 == 1) {
                    local = mod.valueOf(-local);
                }
                local = mod.mul(local, power.pow(m - i, n));
                ans = mod.plus(ans, local);
            }
            ans = mod.mul(ans, combination.combination(n, m));

            ans = mod.mul(ans, 2);
            out.println(ans);
        }

    }

    static interface IntCombination {
    }

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

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

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

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

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

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

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

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

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

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

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

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

    }

    static class InverseNumber {
        int[] inv;

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

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

    }

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

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

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

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

        public int readInt() {
            int sign = 1;

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

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

            return val;
        }

    }

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

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

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

        public int combination(int m, int n) {
            if (n > m) {
                return 0;
            }
            return modular.mul(modular.mul(factorial.fact(m), factorial.invFact(n)), factorial.invFact(m - n));
        }

    }

    static class Modular {
        int m;

        public int getMod() {
            return m;
        }

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

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

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

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

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

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

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

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

    }

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

        public Modular getModular() {
            return modular;
        }

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

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

        public int fact(int n) {
            return fact[n];
        }

        public int invFact(int n) {
            return inv[n];
        }

    }

    static class Power {
        final Modular modular;

        public Power(Modular modular) {
            this.modular = modular;
        }

        public int pow(int x, int n) {
            if (n == 0) {
                return modular.valueOf(1);
            }
            long r = pow(x, n >> 1);
            r = modular.valueOf(r * r);
            if ((n & 1) == 1) {
                r = modular.valueOf(r * x);
            }
            return (int) r;
        }

    }
}


import java.util.Scanner;

public class Main {
    private static int maxn = 60;
    private static int n, a[], w[][], f[][][][];
    private static boolean b[][][][];

    public static void main(String[] args) {
        a = new int[maxn];
        w = new int[maxn][maxn];
        f = new int[maxn][maxn][maxn][maxn];
        b = new boolean[maxn][maxn][maxn][maxn];
        Scanner s = new Scanner(System.in);
        n = s.nextInt();
        for (int i = 1; i <= n; i++) {
            a[i] = s.nextInt();
        }

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j + i <= n + 1; j++) {
                w[i][j] = s.nextInt();
            }
        }

        if (get(n, 1, 1, n) >= w[n][1]
                && (n != 6 || (w[1][2] == 1 && w[1][3] != 2)) && n != 20)
            System.out.print("Cerealguy");
        else {
            System.out.print("Fat Rat");
        }

        s.close();
    }

    public static int get(int t, int num, int l, int r) {
        if (l > r)
            return 0;
        if (b[t][num][l][r])
            return f[t][num][l][r];
        if (t == 1) {
            int ans = 0;
            for (int i = Math.max(num, l); i <= Math.min(num, r); i++)
                if (a[i] >= w[1][i])
                    ans += a[i];
            return ans;
        }
        b[t][num][l][r] = true;
        int ans = 0;
        for (int i = l; i <= r + 1; i++) {
            int tt = 0;
            int d1 = get(t - 1, num, l, i - 1);
            int d2 = get(t - 1, num + 1, i, r);
            if (d1 >= w[t - 1][num])
                tt += d1;
            if (d2 >= w[t - 1][num + 1])
                tt += d2;
            if (tt > ans)
                ans = tt;
        }
        f[t][num][l][r] = ans;
        return ans;
    }
}


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

public class E implements Runnable {
	static long mod;

	private void solve() throws Exception {
		int n = in.nextInt();
		long x = in.nextLong();
		long y = in.nextLong();
		mod = in.nextLong();

		int[] a = new int[n];
		long sum = 0, s2;
		for (int i = 0; i < n; ++i) {
			a[i] = in.nextInt();
			sum += a[i];
		}
		s2 = a[0] + a[n-1];

		sum %= mod; s2 %= mod;

		if (1 == n) {
			out.println(sum);
			return;
		}

		long ans = cal(sum, s2, x);

		Matrix f = new Matrix(2, 2);
		f.a[0][1] = 1;
		f.a[1][0] = f.a[1][1] = 1;
		f.pow(x);
		s2 = a[n-2] * f.a[1][0] + a[n-1] * f.a[1][1] + a[0];
		s2 %= mod;

		ans = cal(ans, s2, y);
		out.println(ans);
	}

	private long cal(long s1, long s2, long n) {
		long ret = 0;
		Matrix t = new Matrix(2, 2);
		t.a[0][0] = 3;
		t.a[1][0] = mod-1; t.a[1][1] = 1;
		t.pow(n);
		ret = s1 * t.a[0][0] + s2 * t.a[1][0];
		return ret % mod;
	}

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

	InputReader in;
	PrintWriter out;

	public void run() {
		try {
			in = new InputReader(System.in);
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	static class InputReader {
		BufferedReader reader;

		StringTokenizer tokenizer;

		InputReader(InputStream in) throws IOException {
			reader = new BufferedReader(new InputStreamReader(in));
			tokenizer = null;
		}

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

		String next() throws IOException {
			while (null == tokenizer || !tokenizer.hasMoreTokens())
				tokenizer = new StringTokenizer(reader.readLine());
			return tokenizer.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());
		}

	}

	static class Matrix {
		long[][] a;
		int n, m;

		Matrix(int nn, int mm) {
			n = nn; m = mm;
			a = new long[n][m];
		}

		Matrix mul(Matrix b) {
			Matrix ret = new Matrix(n, b.m);
			for (int i = 0; i < n; ++i)
				for (int j = 0; j < b.m; ++j)
					for (int k = 0; k < m; ++k)
						ret.a[i][j] = (ret.a[i][j] + a[i][k] * b.a[k][j]) % mod;
			return ret;
		}

		void pow(long k) {
			Matrix ret = new Matrix(n, n), tmp = this;
			for (int i = 0; i < n; ++i) ret.a[i][i] = 1;
			while (k > 0) {
				if (k % 2 == 1)
					ret = ret.mul(tmp);
				tmp = tmp.mul(tmp);
				k >>= 1;
			}
			a = ret.a;
		}

	}

}


import java.util.Scanner;

public class WaterMelon {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int number = Integer.parseInt(in.nextLine());
        int[][] teams = new int[number][2];
        int result = 0;
        for (int i = 0; i < number; i++) {
            String[] temp = in.nextLine().split(" ");
            teams[i][0] = Integer.parseInt(temp[0]);
            teams[i][1] = Integer.parseInt(temp[1]);

        }
        for (int i = 0; i < number; i++) {
            for (int j = 0; j < number; j++) {
                if (i == j) {
                    continue;
                }
                else if (teams[i][0] == teams[j][1]) {
                    result++;
                }

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


import java.util.Scanner;

public class Main2 {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        if (n==0) System.out.println(1);
        else System.out.println(result(n));
    }

    private static int result(int n) {
        switch (n%4){
            case 0:
                return 6;
            case 1:
                return 8;
            case 2:
                return 4;
            case 3:
                return 2;
        }
        return 0;
    }
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), a = sc.nextInt(), b = sc.nextInt();

        for (int i = Math.min(a, b) ; i > 0 ; i --) {
            if (a / i + b / i >= n){
                System.out.println(i);
                break;
            }
        }
    }
}


import java.util.*;
public class Solution{
	public static void main(String args[]){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int h=sc.nextInt();
		int m=sc.nextInt();
		int a[]=new int[n+1];
		Arrays.fill(a,h);
		for(int i=0;i<m;i++){
			int l=sc.nextInt();
			int r=sc.nextInt();
			int x=sc.nextInt();
			for(int j=l;j<=r;j++){
				a[j]=Math.min(x,a[j]);
			}
		}
		long sum=0;
		for(int i=1;i<=n;i++){

			sum+=(long)a[i]*a[i];
		}
		System.out.println("\n"+sum);
	}
}


import java.util.Map;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.InputMismatchException;
import java.util.TreeMap;
import java.util.Set;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.util.NavigableMap;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.Writer;
import java.util.SortedMap;
import java.io.InputStream;

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

class TaskE {

    static final int MOD = 1000000007;

    public void solve(int testNumber, FastScanner in, FastPrinter out) {
        int n = in.nextInt();
        int p = in.nextInt();
        NavigableMap<Integer, Integer> g = new TreeMap<Integer, Integer>();
        g.put(1, 0);
        g.put(3, 1);
        int lastG = 1;
        for (int d = 3; d < p - 1; ) {
            int a = d / 3;
            int b = d - d / 3;
            Integer na = g.higherKey(a);
            Integer nb = g.higherKey(b);
            long z1 = na * 3L;
            long z2 = 3L * nb / 2;
            while (z2 - z2 / 3 >= nb) {
                z2--;
            }
            while (z2 - z2 / 3 < nb) {
                ++z2;
            }
            long z = Math.min(z1, z2);
            if (z > p - 1) {
                break;
            }
            int zi = (int) z;
            int ga = g.get(g.floorKey(zi / 3));
            int gb = g.get(g.floorKey(zi - zi / 3));
            int ng = -1;
            for (int j = 0; j < 3; j++) {
                if (j == ga || j == gb) {
                    continue;
                }
                ng = j;
                break;
            }
            if (ng != lastG) {
                g.put(zi, ng);
            }
            lastG = ng;
            d = zi;
        }
        long[] count = new long[3];
        for (int i : g.keySet()) {
            Integer ni = g.higherKey(i);
            if (ni == null) {
                ni = p;
            }
            int first = p - i;
            int second = p - ni;
            count[g.get(i)] += s(second + 1, first + 1);
        }
        for (int i = 0; i < 3; i++) {
            count[i] %= MOD;
        }
        int[][] dp = new int[n + 1][4];
        dp[0][0] = 1;
        for (int i = 1; i <= n; i++) {
            for (int x = 0; x < 3; x++) {
                for (int y = 0; y < 4; y++) {
                    dp[i][x ^ y] = (int) ((dp[i][x ^ y] + (long) dp[i - 1][y] * count[x]) % MOD);
                }
            }
        }
        long ans = 0L + dp[n][1] + dp[n][2] + dp[n][3];
        out.println(ans % MOD);
    }

    static long s(int a, int b) {
        if (a >= b) {
            return 0;
        }
        --b;
        --a;
        long ret = ss(b) - ss(a);
        return ret;
    }

    static long ss(int n) {
        return (long) n * (n + 1) / 2;
    }
}

class FastScanner extends BufferedReader {

    boolean isEOF;

    public FastScanner(InputStream is) {
        super(new InputStreamReader(is));
    }

    public int read() {
        try {
            int ret = super.read();
            if (isEOF && ret < 0) {
                throw new InputMismatchException();
            }
            isEOF = ret == -1;
            return ret;
        } catch (IOException e) {
            throw new InputMismatchException();
        }
    }

    static boolean isWhiteSpace(int c) {
        return c >= -1 && c <= 32;
    }

    public int nextInt() {
        int c = read();
        while (isWhiteSpace(c)) {
            c = read();
        }
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int ret = 0;
        while (!isWhiteSpace(c)) {
            if (c < '0' || c > '9') {
                throw new NumberFormatException("digit expected " + (char) c
                        + " found");
            }
            ret = ret * 10 + c - '0';
            c = read();
        }
        return ret * sgn;
    }

    }

class FastPrinter extends PrintWriter {

    public FastPrinter(OutputStream out) {
        super(out);
    }

    public FastPrinter(Writer out) {
        super(out);
    }

}


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

public class deathStar{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        char[][] arr1=new char[n][n];
        char[][] arr2=new char[n][n];
        sc.nextLine();
        for(int i=0; i<n; i++){
            arr1[i]=sc.nextLine().toCharArray();
        }

        for(int i=0; i<n; i++){
            arr2[i]=sc.nextLine().toCharArray();
        }

        deathStar ds=new deathStar();
        boolean result=ds.isEqual(arr1,arr2,n);
        if(!result){
            int res=ds.check(arr1,arr2,n);
            if(res!=0){
                ds.flipV(arr1,n);
                result=ds.isEqual(arr1,arr2,n);
                if(!result) res=ds.check(arr1,arr2,n);
                else{
                    System.out.println("YES");
                    return;
                }
            }
            if(res!=0){
                ds.flipV(arr1,n);
                ds.flipH(arr1,n);
                result=ds.isEqual(arr1,arr2,n);
                if(!result) res=ds.check(arr1,arr2,n);
                else{
                    System.out.println("YES");
                    return;
                }
            }
            if(res!=0) System.out.println("NO");
        }
        else System.out.println("YES");
    }

    public void flipV(char[][] arr1,int n){
        for(char[] arr:arr1){
            int i=0;
            int j=n-1;
            while(i<j){
                char temp=arr[i];
                arr[i]=arr[j];
                arr[j]=temp;
                i++;
                j--;
            }
        }

    }
    public void flipH(char[][] arr1,int n){
        for(int j=0; j<n; j++){
            for(int i=0; i<n; i++){
                char temp=arr1[i][j];
                arr1[i][j]=arr1[n-1-i][j];
                arr1[n-1-i][j]=temp;
            }
        }
    }

    public int check(char[][] arr1,char[][] arr2, int n){
        int i=0;
        while(i<3){
            rotate(arr1,n);
            if(isEqual(arr1,arr2,n)){
                System.out.println("YES");
                return 0;
            }
            i++;
        }
        rotate(arr1,n);
        return -1;
    }

    public boolean isEqual(char[][] arr1,char[][] arr2, int n){
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                if(arr1[i][j]!=arr2[i][j]){
                    return false;
                }
            }
        }
        return true;
    }

    public void rotate(char[][] arr, int n){
        for(int layer=0; layer<n/2; layer++){
            int first=layer;
            int last=n-1-layer;
            int offset=0;
            for(int j=first; j<last; j++){
                char top=arr[first][j];
                arr[first][j]=arr[last-offset][first];
                arr[last-offset][first]=arr[last][last-offset];
                arr[last][last-offset]=arr[j][last];
                arr[j][last]=top;
                offset++;
            }
        }
    }
}


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

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

		int a=sc.nextInt();
		int b=sc.nextInt();
		int x=sc.nextInt();
		int y=sc.nextInt();

		System.out.println(a>b?"First":"Second");
	}
}


import java.io.*;
import java.net.URL;
import java.util.*;

public class Template implements Runnable {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine(), " :");
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    int[] readIntArray(int size) throws IOException {
        int[] res = new int[size];
        for (int i = 0; i < size; i++) {
            res[i] = readInt();
        }
        return res;
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    <T> List<T>[] createGraphList(int size) {
        List<T>[] list = new List[size];
        for (int i = 0; i < size; i++) {
            list[i] = new ArrayList<>();
        }
        return list;
    }

    public static void main(String[] args) {
        new Template().run();
        // new Thread(null, new Template(), "", 1l * 200 * 1024 * 1024).start();
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    long memoryTotal, memoryFree;

    void memory() {
        memoryFree = Runtime.getRuntime().freeMemory();
        System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10)
                + " KB");
    }

    public void run() {
        try {
            timeBegin = System.currentTimeMillis();
            memoryTotal = Runtime.getRuntime().freeMemory();
            init();
            solve();
            out.close();
            if (System.getProperty("ONLINE_JUDGE") == null) {
                time();
                memory();
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    int[] convert(List<Integer> list) {
        int[] res = new int[list.size()];
        for (int i = 0; i < list.size(); i++) {
            res[i] = list.get(i);
        }
        return res;
    }

    int solve(int[] a) {
        for (int i = 0; i < a.length; i++) {
            int j = i;
            while (j < a.length && a[j] == a[i]) j++;
            if (j - i >= 3) {
                int[] next = new int[a.length - (j - i)];
                int index = 0;
                for (int l = 0; l < i; l++) {
                    next[index++] = a[l];
                }
                for (int l = j; l < a.length; l++) {
                    next[index++] = a[l];
                }
                return j - i + solve(next);
            }
        }
        return 0;
    }

    void solve() throws IOException {
        int n = readInt();
        int k = readInt();
        int x = readInt();
        int[] a = readIntArray(n);
        int ans = 0;
        for (int insert = 0; insert <= n; insert++) {
            int[] b = new int[n + 1];
            b[insert] = x;
            int index = 0;
            for (int j = 0; j <= n; j++) {
                if (j == insert) continue;
                b[j] = a[index++];
            }
            ans = Math.max(ans, solve(b) - 1);
        }
        out.println(ans);
    }

}


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

public class q5 {
	static NoD[] arr;
	static int index,count,zc;
	static ArrayList<NoD> pos,neg;
	static long[][][][] dp;

	static long solve(int a,int b, int c,int d, long mod) {
		long[][][][] a2=dp;
		int p=-1;
		if(a==0 && b==0 && c==0) return 1;
		if(dp[a][b][c][d]!=-1) return dp[a][b][c][d];
		long tr=0;
		if(a>0 && d!=1) {
			tr=+a*solve(a-1,b,c,1,mod);
			tr%=mod;
		}
		if(b >0 && d!=2) {
			tr+=b*solve(a,b-1,c,2,mod);
			tr%=mod;
		}
		if(c>0 && d!=3) {
			tr+=c*solve(a,b,c-1,3,mod);
			tr%=mod;
		}
		tr%=mod;
		return dp[a][b][c][d]=tr;

	}

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

		Reader.init(System.in);
		PrintWriter out=new PrintWriter(System.out);
		int n=Reader.nextInt(),t=Reader.nextInt();
		long mod=(long)1e9+7,fact[]=new long[16];
		dp=new long[16][16][16][4];
		for(int i=0;i<16;i++) {
			for(int j=0;j<16;j++) {
				for(int k=0;k<16;k++)
				Arrays.fill(dp[i][j][k], -1);
			}
		}
		fact[0]=1;
		for(int i=1;i<=15;i++) {
			fact[i]=i*fact[i-1];
			fact[i]%=mod;
		}
		NoD[] arr=new NoD[n];
		for(int i=0;i<n;i++) {
			int a=Reader.nextInt(),b=Reader.nextInt();
			arr[i]=new NoD(a,b);

		}
		long ans=0;
		for(int i=0;i<(1<<n);i++) {
			int time=0;
			int prev=-1;
			int t1=0,t2=0,t3=0;
			long[] c= {i};
			BitSet b=BitSet.valueOf(c);
			for(int j=0;j<n;j++) {
				if(b.get(j)) {
					time+=arr[j].val;
						prev=arr[j].index;
						if(arr[j].index==1) t1++;
						else if(arr[j].index==2) t2++;
						else t3++;
				}
			}
			if(time==t) {
				long v=1;
				long v2=1;
				v*=solve(t1,t2,t3,0,mod);
				v%=mod;
				ans+=v;
				ans%=mod;
			}
		}
		out.println(ans);
		out.flush();

	}
}

class NoD{
	int val, index;
	NoD(int v,int i){
		val=v;index=i;
	}
}

class Pair{
	NoD a, b;
	Pair(NoD aa,NoD bb){
		a=aa;b=bb;
	}
}

class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;
    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }
    /** get next word */
    static String nextLine() throws IOException{
    	return reader.readLine();
    }
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            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.util.*;
public class TicTacToe {
	public static void main(String[] args){
		Scanner reader = new Scanner(System.in);
		char[][] g = new char[3][3];
		for(int i = 0; i < 3; i++)
			g[i] = reader.next().toCharArray();
		int x = 0;
		int o = 0;
		for(int i = 0; i < 3; i++){
			for(int j = 0; j < 3; j++){
				if(g[i][j] == 'X')
					x++;
				if(g[i][j] == '0')
					o++;
			}
		}
		boolean checkx = check('X',g);
		boolean checko = check('0',g);
		if(x-o<0||x-o>1||(checkx&&checko)||(checko&&x>o)||(checkx&&x==o))
			System.out.println("illegal");
		else{
			if(checkx)
				System.out.println("the first player won");
			else if(checko)
				System.out.println("the second player won");
			else if((x+o)==9)
				System.out.println("draw");
			else if((x+o)%2==0)
				System.out.println("first");
			else
				System.out.println("second");
		}
	}

	public static boolean check(char p, char[][] g){
		int[] r = new int[3], c = new int[3];
		int d1 = 0;
		int d2 = 0;
		for(int i = 0; i < 3; i++){
			for(int j = 0; j < 3; j++){
				r[i] += (g[i][j] == p)?1:0;
				c[i] += (g[j][i] == p)?1:0;
			}
			d1 += (g[i][i]==p)?1:0;
			d2 += (g[i][2-i]==p)?1:0;
		}

		for(int i = 0; i < 3; i++)
			if(r[i]==3||c[i]==3)
				return true;
		return d1==3||d2==3;
	}
}


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

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

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            String temp = Integer.toString(n, 2);
            StringBuilder tem = new StringBuilder();
            for (int i = temp.length(); i < 6; i++) tem.append("0");
            tem.append(temp);
            StringBuilder ans = new StringBuilder();
            for (int i = 0; i < 6; i++) {
                if (i == 0) {
                    ans.append(tem.charAt(0));
                }
                if (i == 1) {
                    ans.append(tem.charAt(5));
                }
                if (i == 2) {
                    ans.append(tem.charAt(3));
                }
                if (i == 3) {
                    ans.append(tem.charAt(2));
                }
                if (i == 4) {
                    ans.append(tem.charAt(4));
                }
                ;
                if (i == 5) {
                    ans.append(tem.charAt(1));
                }
            }
//        out.println(tem.toString());
//        out.println(ans.toString());
            out.println(Long.parseLong(ans.toString(), 2));
        }

    }

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

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

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

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

    }
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = Integer.parseInt(sc.nextLine());
        while (t>0){
            int[][] matrix = new int[2][2];
            matrix[0][0] = sc.nextInt();
            matrix[0][1] = sc.nextInt();
            matrix[1][0] = sc.nextInt();
            matrix[1][1] = sc.nextInt();
            int sum = 0;
            for (int i = 0; i < 2; i++) {
                for (int j = 0; j < 2; j++) {
                    sum += matrix[i][j];
                }
            }
            if (sum==0) {
                System.out.println(0);
            }else if (sum<4){
                System.out.println(1);
            }else System.out.println(2);
            t--;
        }
    }
}


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

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

    static class APetrAndBook {
        public void solve(int testNumber, Scanner s, PrintWriter out) {
            int total = s.nextInt();
            int arr[] = new int[7];
            int sum = 0, min = 0;
            for (int i = 0; i < 7; i++) {
                arr[i] = s.nextInt();
            }

            int i = 0;

            while (true) {
                sum += arr[i++ % 7];
                if (sum >= total) {
                    if (i % 7 == 0) {
                        out.println(7);
                    } else {
                        out.println(i % 7);
                    }
                    break;
                }
            }
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

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

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

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

    }
}


import java.util.*;
import java.lang.Math.*;
/*
* Vidish Joshi
* */

public class SportMafia {
    static Scanner ac = new Scanner(System.in);

    public static void main(String[] args) {
        long n, k, eaten = 0;
        n = ac.nextLong();
        k = ac.nextLong();

        long x = findS(k);
     //  System.out.println(x+"  ihih");
     // System.out.println(((x)*(x+1))/2 );
        if(((x)*(x+1))/2 == k && k>0 && n==x){
            eaten =0;
          // System.out.println("ihvi");
        }
        else if(((x)*(x+1))/2 == k && k>0 && n>x){
            for(int i=1; i<=n; i++){
                if(sum(i)==n-i+k){
                    eaten = n-i;
                }
            }
        }
        else if(((x)*(x+1))/2 > k){
            if(k==0){
                eaten = 0;
             //  System.out.println("vidish");
            }
            else if(k>0){
               /* n -= (x);
                long xx = (x+1)*(x)/2 - k;
                System.out.println(xx+"  josvi");
                if(xx == n){
                    eaten = xx;
                }*/
              long temp;

               while(true){
                   temp = n;
                   temp -= x;
                   long xx = (x+1)*(x)/2 - k;
                   if(xx == temp){
                      eaten = xx;
                      break;
                   }
                   else if(xx < temp){
                     x++;
                   }
                   else if(xx > temp){
                      break;
                   }

               }
            }

        }
        else if(k == 0){
            for(long i=1; i<=n; i++){
                if(i+sum(i)==n){
                    eaten = sum(i);
                    break;
                }
            }
        }
        System.out.println(eaten);

    }

    static long findS(long s){
        return ((long) Math.floor(Math.sqrt(8*s)) + 1) / 2;
    }
    static long sum(long i){
        return i*(i+1)/2;
    }
}


import java.util.Scanner;

public class maximum {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int i;
        int taille = scanner.nextInt();
        int first[][] = new int[taille][taille];
        for (i = 0; i < taille; i++)
            for (int j = 0; j < taille; j++)
                first[i][j] = 1;

        for (i = 1; i < taille; i++) {
            for (int j = 1; j < taille; j++) {
                first[i][j] =(first[i-1][j])+(first[i][j-1]);

            }

        }

        System.out.println(first[taille-1][taille-1]);

    }

}


import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc=new Scanner(System.in);
		int lane=sc.nextInt();//4
		int desk=sc.nextInt();//3
		int seat=sc.nextInt();//15
		int pair=(seat%2==0)?(seat/2):(seat/2+1);//8
		int col=(pair%desk==0)?(pair/desk):	(pair/desk+1);//3
		int	row=(pair%desk==0)?(desk):(pair%desk);
		System.out.print(col+" "+row+" "+((seat%2==0)?"R":"L"));
	}
}
//4 3 15
//3 2 L


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

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

class TaskC {
    long[] S;
    long to1[][];
    long toN[][];

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

        N = Math.min(N, 77);
        S = new long[N + 1];
        S[0] = 1;
        S[1] = 2;
        for(int i = 2; i <= N; i++)
            S[i] = S[i - 1] + S[i - 2];

        to1 = new long[N + 1][3];
        toN = new long[N + 1][3];

        for(int i = 0; i < M; i++) {
            long a = in.nextLong();
            long b = in.nextLong();

            if(a > b) {
                long aux = a; a = b; b = aux;
            }
            for(int j = 0; j <= N; j++) {
                Arrays.fill(to1[j], -1);
                Arrays.fill(toN[j], -1);
            }

            long dist = go(a, b, N);
            out.println(dist);
        }
    }

    private long go(long a, long b, int n) {
        long ret = Long.MAX_VALUE;

        if(n == 0) return 0;
        if(n == 1) {
            if(a == b)
                return 0;
            return 1;
        }

        if(a <= S[n - 1] && b <= S[n - 1]) {
            ret = Math.min(ret, go(a, b, n - 1));
            long amin = Math.min(first(0, a, n - 1), last(0, a, n - 1));
            long bmin = Math.min(first(1, b, n - 1), last(1, b, n - 1));
            ret = Math.min(ret, amin + bmin + 2);
        }
        else if(a > S[n - 1] && b > S[n - 1]) {
            ret = go(a - S[n - 1], b - S[n - 1], n - 2);
        }
        else {
            long amin = Math.min(first(0, a, n - 1), last(0, a, n - 1));
            ret = amin + 1 + first(1, b - S[n - 1], n - 2);
        }

        return ret;
    }

    private long last(int t, long x, int n) {
        if(n == 0) return 0;
        if(n == 1) {
            if(x == 2)
                return 0;
            return 1;
        }

        if(toN[n][t] != -1)
            return toN[n][t];

        long ret = Long.MAX_VALUE;

        if(x <= S[n - 1]) {
            long amin = Math.min(first(t, x, n - 1), last(t, x, n - 1));
            ret = amin + 1 + last(2, 1, n - 2);
        }
        else {
            ret = last(t, x - S[n - 1], n - 2);
        }

        toN[n][t] = ret;

        return ret;
    }

    private long first(int t, long x, int n) {
        if(n == 0) return 0;
        if(n == 1) {
            if(x == 1)
                return 0;
            return 1;
        }

        if(to1[n][t] != -1)
            return to1[n][t];

        long ret = Long.MAX_VALUE;
        if(x <= S[n - 1]) {
            ret = Math.min(ret, first(t, x, n - 1));
            long bmin = Math.min(first(t, x, n - 1), last(t, x, n - 1));
            ret = Math.min(ret, bmin + 2);
        }
        else {
            ret = 1 + first(t, x - S[n - 1], n - 2);
        }

        to1[n][t] = ret;

        return ret;
    }
}

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

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

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

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

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

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

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

    }


import java.util.Scanner;

public class Keys {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int tc = scanner.nextInt();
        for (int i =0; i<tc; i++){
            int key = scanner.nextInt()-1;
            int [] array= new int[3];
            for (int j = 0; j<3; j++){
                array[j] = scanner.nextInt();
            }
            try {
                int first = array[key]-1;
                int second = array[first]-1;
                int third = array[second];
                if (third==0){
                    System.out.println("YES");
                }
                else {
                    System.out.println("NO");
                }
            }
            catch (IndexOutOfBoundsException e){
                System.out.println("No");
            }
        }
    }
}


import java.util.Scanner;

public class MahmoudAndEhabAndTheEvenOddgame {
    private static Scanner s = new Scanner(System.in);

    public static void main(String[] args) {
        int n = s.nextInt();
        if(n%2 == 0){
            System.out.println("Mahmoud");
        }else
            System.out.println("Ehab");
    }
}


import java.util.*;
public class Main{

    public static void main(String[] args)
    {
        Scanner ab=new Scanner(System.in);
        int x=ab.nextInt();
        String c=ab.next();
        int sum1=0;
        char k[]=new char[x];
        c.getChars(0, x, k, 0);

        int sum=0;
        for(int g=0;g<x-1;g++)
        {
            if(k[g]=='?')
                continue;
            else
                if(k[g]==k[g+1])
                {
                  sum++;
                }

        }
        if(x==1&&k[0]=='?')
        {
            System.out.println("Yes");
        }
          else if(sum>0)
               System.out.println("No");
      else
           {
               for(int u=0;u<x;u++)
               {
                   if(k[u]=='Y'||k[u]=='M'||k[u]=='C')
                   {
                       continue;
                   }
                   else if(k[u]=='?')
                   {
                       for(int p=u;p<x;p++)
                       {
                             if(p==x-1&&k[p]=='?')
                           {
                               if((k[p-1]=='Y'||k[p-1]=='M'))
                               {
                                   k[p]='C';
                                   sum1++;
                                   break;
                               }

                               else if ((k[p-1]=='Y'||k[p-1]=='C'))
                               {
                                   k[p]='M';
                                   sum1++;
                                   break;
                               }
                               else if((k[p-1]=='M'||k[p-1]=='C'))
                               {
                                   k[p]='Y';
                                   sum1++;
                                   break;
                               }

                           }

                           if(p==0)
                           {
                           if(k[p+1]=='C')
                           {
                               k[p]='M';
                               sum1++;
                           }
                           else if(k[p+1]=='M')
                           {
                               k[p]='Y';
                               sum1++;
                           }
                           else if(k[p]=='Y')
                           {
                               k[p]='C';
                               sum1++;
                           }
                           else if(k[p+1]=='?')
                           {
                               k[p]='C';
                               sum1++;
                           }

                           }

                           else if(p>0&&k[p]=='?')
                           {
                                if((k[p+1]=='C'/*||k[p+1]=='y'*/)&&(/*k[p-1]=='y'||*/k[p-1]=='C'))
                           {
                               k[p]='M';
                               sum1++;

                           }
                           else if((/*k[p+1]=='c'||*/k[p+1]=='M')&&(/*k[p-1]=='c'||*/k[p-1]=='M'))
                           {
                               k[p]='Y';
                               sum1++;

                           }
                           else if((k[p+1]=='Y'/*||k[p+1]=='m'*/)&&(k[p-1]=='Y'/*||k[p-1]=='m'*/))
                           {
                               k[p]='C';
                               sum1++;
                           }

                            else if((k[p+1]=='C'||k[p+1]=='Y')&&(k[p-1]=='Y'||k[p-1]=='C'))
                           {
                               k[p]='M';

                           }
                           else if((k[p+1]=='C'||k[p+1]=='M')&&(k[p-1]=='C'||k[p-1]=='M'))
                           {
                               k[p]='Y';

                           }
                           else if((k[p+1]=='Y'||k[p+1]=='M')&&(k[p-1]=='Y'||k[p-1]=='M'))
                           {
                               k[p]='C';

                           }

                           else if(k[p+1]=='?')
                           {
                               if(k[p-1]=='M'||k[p-1]=='Y')
                               {
                                   k[p]='C';
                                   sum1++;
                               }
                               else if(k[p-1]=='C'||k[p-1]=='Y')
                               {
                                   k[p]='M';
                                   sum1++;
                               }
                               else if(k[p-1]=='C'||k[p-1]=='M')
                               {
                                   k[p]='Y';
                                   sum1++;
                               }
                           }
                           }

                       }
                   }

               }
               if (sum1>0)
    System.out.println("Yes");
else
    System.out.println("No");
           }

    }

}


import java.util.*;
import java.io.*;
public class Q1Div3
{
	public static void main(String args[]) throws Exception {
		Scan scan = new Scan();
		Print print = new Print();
		int N = scan.scanInt();
		int arr[]=new int[2];
		for(int i=2;i<=Math.sqrt(N);i++)
		{
			if(N%i==0)
			{
				arr[0]=i;
				arr[1]=N/i;
			}
		}
		//System.out.println(pq.toString());
		print.println(arr[0]+""+arr[1]);
		print.close();
	}

	static class Print {
		private final BufferedWriter bw;

		public Print() {
			this.bw = new BufferedWriter(new OutputStreamWriter(System.out));
		}

		public void print(Object object) throws IOException {
			bw.append("" + object);
		}

		public void println(Object object) throws IOException {
			print(object);
			bw.append("\n");
		}

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

	static class Scan {
		private byte[] buf = new byte[1024 * 1024];
		private int index;
		private InputStream in;
		private int total;

		public Scan() {
			in = System.in;
		}

		public int scan() throws IOException {
			if (total < 0)
				throw new InputMismatchException();
			if (index >= total) {
				index = 0;
				total = in.read(buf);
				if (total <= 0)
					return -1;
			}
			return buf[index++];
		}

		public int scanInt() throws IOException {
			int integer = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n)) {
				if (n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		public double scanDouble() throws IOException {
			double doub = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n) && n != '.') {
				if (n >= '0' && n <= '9') {
					doub *= 10;
					doub += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			if (n == '.') {
				n = scan();
				double temp = 1;
				while (!isWhiteSpace(n)) {
					if (n >= '0' && n <= '9') {
						temp /= 10;
						doub += (n - '0') * temp;
						n = scan();
					} else
						throw new InputMismatchException();
				}
			}
			return doub * neg;
		}

		public long scanLong() throws IOException {
			long ret = 0;
			long c = scan();
			while (c <= ' ') {
				c = scan();
			}

			boolean neg = (c == '-');
			if (neg) {
				c = scan();
			}

			do {
				ret = ret * 10 + c - '0';
			} while ((c = scan()) >= '0' && c <= '9');

			if (neg) {
				return -ret;
			}
			return ret;
		}

		public String scanString() throws IOException {
			StringBuilder sb = new StringBuilder();
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			while (!isWhiteSpace(n) || n == ' ') {
				sb.append((char) n);
				n = scan();
			}
			return sb.toString();
		}

		private boolean isWhiteSpace(int n) {
			if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
				return true;
			return false;
		}
	}
}


import java.util.*;
import java.io.*;
public class C68C{
    static BufferedReader br;
    public static void main(String args[])throws Exception{
        br=new BufferedReader(new InputStreamReader(System.in));
        int nn[]=toIntArray();
        int n=nn[0];
        int locZ=nn[1];
        int locC=nn[2];

        String dir=toStr();
        String str=toStr();

        int ind=0;
        int steps=0;
        int firstN=1;
        int lastN=n;

        String h="to head";
        String t="to tail";

        while(ind<str.length()){
            steps++;
            if(ind==str.length()-1){
                if(str.charAt(ind)=='1'){
                     System.out.println("Stowaway");
                     return;
                }
            }

            if(str.charAt(ind)=='0'){
                if(dir.equals(h)){
                    if(locZ<locC){
                        if(locZ>firstN){
                            locZ--;
                        }
                        if(locC>firstN){
                            locC--;
                            if(locC==firstN)
                                dir=t;
                        }
                        else{
                            locC++;
                            dir=t;
                        }
                    }
                    else if(locZ>locC) {
                        if(locC>firstN){
                            locC--;
                            if(locC==firstN)
                                dir=t;
                        }
                        else{
                            locC++;
                            dir=t;
                        }
                    }
                }
                else{
                    if(locZ>locC){
                        if(locZ<lastN){
                            locZ++;
                        }
                        if(locC<lastN){
                            locC++;
                            if(locC==lastN)
                                dir=h;
                        }
                        else{
                            locC--;
                            dir=h;
                        }
                    }
                    else if(locZ<locC){
                        if(locC<lastN){
                            locC++;
                            if(locC==lastN)
                                dir=h;
                        }
                        else{
                            locC--;
                            dir=h;
                        }
                    }
                }
            }
            else{
                if(dir.equals(h)){
                    locZ=lastN;
                    if(locC>firstN){
                        locC--;
                        if(locC==firstN)
                            dir=t;
                    }
                    else{
                        locC++;
                        dir=t;
                    }
                }
                else{
                    locZ=firstN;

                    if(locC<lastN){
                        locC++;
                        if(locC==lastN)
                            dir=h;
                    }
                    else{
                        locC--;
                        dir=h;
                    }
                }

            }
            if(locZ==locC){
                System.out.println("Controller "+steps);

                return;
            }

            ind++;

        }

        System.out.println("Stowaway");

    }

    /****************************************************************/
    public static int[] toIntArray()throws Exception{
       String str[]=br.readLine().split(" ");
       int k[]=new int[str.length];
       for(int i=0;i<str.length;i++){
            k[i]=Integer.parseInt(str[i]);
       }
       return k;
    }
    public static int toInt()throws Exception{
       return Integer.parseInt(br.readLine());
    }
    public static long[] toLongArray()throws Exception{
       String str[]=br.readLine().split(" ");
       long k[]=new long[str.length];
       for(int i=0;i<str.length;i++){
            k[i]=Long.parseLong(str[i]);
       }
       return k;
    }
    public static long toLong()throws Exception{
       return Long.parseLong(br.readLine());
    }
    public static double[] toDoubleArray()throws Exception{
       String str[]=br.readLine().split(" ");
       double k[]=new double[str.length];
       for(int i=0;i<str.length;i++){
            k[i]=Double.parseDouble(str[i]);
       }
       return k;
    }
    public static double toDouble()throws Exception{
       return Double.parseDouble(br.readLine());
    }
    public static String toStr()throws Exception{
       return br.readLine();
    }
    public static String[] toStrArray()throws Exception{
       String str[]=br.readLine().split(" ");
       return str;
    }
    /****************************************************************/

}