//package com.example.practice.codeforces;

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

public class Solution {
    public static void main (String [] args) throws IOException {
        // Use BufferedReader rather than RandomAccessFile; it's much faster
        final BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        // input file name goes above
        //StringTokenizer st = new StringTokenizer(input.readLine());
        //int n = Integer.parseInt(st.nextToken()), a = Integer.parseInt(st.nextToken()), b = Integer.parseInt(st.nextToken()), k = Integer.parseInt(st.nextToken());
        long[] res = calc(input.readLine());
        if (res==null){
            out.println(-1);
        }else {
            printArray(res, out);
        }
        out.close();       // close the output file
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


import java.util.Scanner;

public class Cifera {
    static void solve(int k, int l){
        long r=k;
        int i=0;
        while(r<l){
            i++;
            r*=k;
        }
        if(r==l)
            System.out.println("YES\n"+i);
        else
            System.out.println("NO");
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int k= in.nextInt();
        int l= in.nextInt();
        solve(k,l);
    }

}


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

public class A implements Runnable {
	public static void main (String[] args) {new Thread(null, new A(), "_cf", 1 << 28).start();}

	int n;
	ArrayList<Integer>[] adj;
	int[][][] dp;

	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("");

		n = fs.nextInt();
		adj = new ArrayList[n];
		for(int i = 0; i < n; i++) adj[i] = new ArrayList<>();
		for(int i = 0; i < n-1; i++) {
			int u = fs.nextInt()-1;
			int v = fs.nextInt()-1;
			adj[u].add(v); adj[v].add(u);
		}

		dp = new int[2][2][n];
		for(int i = 0; i < 2; i++)
			for(int j = 0; j < 2; j++)
				Arrays.fill(dp[i][j], -1);
		ways1 = new int[n];
		ways2 = new int[n];
		int res = solve(0, 0, 1, -1);
		System.out.println(res);

		out.close();
	}

	int[] ways1, ways2;
	int solve(int node, int matched, int solo, int par) {
		int ret = dp[solo][matched][node];
		if(ret != -1) return ret;
		int allWays = 1, allWays2 = 1;

		int[] ways1 = new int[adj[node].size()];
		int[] ways2 = new int[adj[node].size()];
		boolean leaf = true;
		for(int i = 0; i < adj[node].size(); i++) {
			int v = adj[node].get(i);
			if(par == v) continue;
			leaf = false;
			int f1 = solve(v, 0, 0, node); //don't cut
			int f2 = solve(v, 0, 1, node); //do cut
			ways1[i] = f1; ways2[i] = f2;
			allWays = mult(allWays, add(ways1[i], ways2[i]));
			allWays2 = mult(allWays2, ways2[i]);
		}
		if(leaf) {
			int val = dp[solo][matched][node] = solo == 1 || matched == 1 ? 1 : 0;
			return val;
		}

		if(matched == 1) {
			return dp[solo][matched][node] = allWays;
		}
		else {
			int res = solo == 1 ? allWays2 : 0;
			for(int i = 0; i < adj[node].size(); i++) {
				int v = adj[node].get(i);
				if(v == par) continue;
				int left = div(allWays, add(ways1[i], ways2[i]));
				int get = solve(v, 1, 0, node);
				left = mult(left, get);
				res = add(res, left);
			}
			return dp[solo][matched][node] = res;
		}
	}

	int MOD = 998244353;
	int add(int a, int b) {
		a += b;
		if(a >= MOD) a -= MOD;
		return a;
	}
	int mult(long a, long b) {
		a *= b;
		if(a >= MOD) a %= MOD;
		return (int)a;
	}
	int div(int a, int b) {
		return mult(a, pow(b, MOD-2));
	}
	int pow(int base, int expo) {
		if(expo == 0) return 1;
		if(expo == 1) return base;
		if((expo&1) == 0) {
			int res = pow(base, expo>>1);
			return mult(res, res);
		}
		else {
			int res = pow(base, expo-1);
			return mult(res, base);
		}
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) {
			try {
				in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
			}
			catch (Exception e) {
				in = new BufferedInputStream(System.in, BS);
			}
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}

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

	}

}


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

public class Main{
	static int mul(int x,int y,int mod){
		return (int)((x*1l*y)%mod);
	}
	static int add(int x,int y,int mod){
		int ans=x+y;
		if(ans>=mod)ans-=mod;
		return ans;
	}
	static void main() throws Exception{
		int n=sc.nextInt(),m=sc.nextInt();
		int[]ans=new int[n+1];
		int[]pref=new int[n+1];
		ans[1]=1;
		pref[1]=1;
		for(int i=2;i<=n;i++){
			for (int j = 1, la; j <= i; j = la + 1) {
				la = i / (i / j);
				//i / x yields the same value for j <= x <= la.
				ans[i]=add(ans[i],mul(ans[i/j],la-j+1,m),m);
			}
			ans[i]=add(ans[i],pref[i-1],m);
			pref[i]=add(ans[i],pref[i-1],m);
		}
		pw.println(ans[n]);
	}
	public static void main(String[] args) throws Exception{
		sc=new MScanner(System.in);
//		sc=new MScanner(".in");
		pw = new PrintWriter(System.out);
		int tc=1;
//        tc=sc.nextInt();
		for(curt=1;curt<=tc;curt++) {
//			pw.printf("Case #%d: ", i);
			main();
		}

		pw.flush();
	}
	static int curt;
	static PrintWriter pw;
	static MScanner sc;
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
			int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
			return in;
		}
		public long[] longArr(int n) throws IOException {
			long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
			return in;
		}
		public int[] intSortedArr(int n) throws IOException {
			int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
			shuffle(in);
			Arrays.sort(in);
			return in;
		}
		public long[] longSortedArr(int n) throws IOException {
			long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
			shuffle(in);
			Arrays.sort(in);
			return in;
		}
		public Integer[] IntegerArr(int n) throws IOException {
			Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
			return in;
		}
		public Long[] LongArr(int n) throws IOException {
			Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
			return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}

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

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

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

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

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

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}

	}
	static void dbg(int[]in) {
		System.out.println(Arrays.toString(in));
	}
	static void dbg(long[]in) {
		System.out.println(Arrays.toString(in));
	}
	static void sort(int[]in) {
		shuffle(in);
		Arrays.sort(in);
	}
	static void sort(long[]in) {
		shuffle(in);
		Arrays.sort(in);
	}
	static void shuffle(int[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			int tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static void shuffle(long[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			long tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
}


import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
import java.text.*;
/*
 * @IO : BufferedReader, InputStreamReader, IOException.
 * @Util : Scanner, Arrays, ArrayList, StringTokenizer, TreeSet.
 * @Util : Collections, HashMap, HashSet.
 * @Lang : StringBuilder, StringBuffer.
 * @Math : BigInteger, BigDecimal.
 * @Text : DecimalFormat.
 * @System : System.currentTimeMillis(); , System.nanoTime();
 * @Custom I/O : new PrintWriter(new BufferedOutputStream(System.out))
 */

public class Main
{
    // Custom I/O Routine
    public static PrintWriter out = new PrintWriter(System.out);
    public static Reader in = new Reader();

    // Intializations of Values
    static byte UNCAL = -1;
    static int INF = (int) 1e6;

    // Intializations of Data Structures & Graphs

    public static void main(String[] args) throws IOException
    {
        //---------------------Solution Start---------------------//
		int n = in.nextInt();
		int k = in.nextInt();

		TreeMap<Character, Integer> ballons = new TreeMap<>();

		char[] types = in.next().toCharArray();

		for (int i = 0; i < n; i++)
		{
			if (!ballons.containsKey(types[i]))
			{
				ballons.put(types[i], 1);
			}
			else
			{
				ballons.put(types[i], ballons.get(types[i]) + 1);
			}

		}

		int max = 0;
		for (Map.Entry<Character, Integer>  e : ballons.entrySet())
			max = Math.max(max, e.getValue());

		out.println(max > k ? "NO" : "YES");
        //---------------------Solution  End---------------------//
        out.flush();
        out.close();
    }
}

class Reader
{
    BufferedReader bufferedReader;
    StringTokenizer stringTokenizer;

    public Reader(){
        bufferedReader = new BufferedReader(new InputStreamReader(System.in));
    }

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

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

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

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

    public String nextLine(){
        String str = "";
        try{
            str = bufferedReader.readLine();
        }
        catch (IOException Ex){
            Ex.printStackTrace();
        }
        return str;
    }

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

class Graph
{
    int vertices;

    ArrayList<Integer>[] adjList;
    boolean[] visited;

    public Graph(int vertices)
    {
        this.vertices = vertices;

        adjList = new ArrayList[vertices];
        for (int i = 0 ; i < vertices ; i++)
            adjList[i] = new ArrayList<>();

        visited = new boolean[vertices];
    }

    public void addEdge(int u, int v)
    {
        adjList[u].add(v);
    }

	 public void removeEdge(int u, int v)
    {
        adjList[u].remove(v);
    }

    public boolean visit(int v)
    {
        return visited[v] = true;
    }

    public void clearVisit()
    {
        Arrays.fill(visited, false);
    }

    public boolean isVisited(int v)
    {
        return visited[v];
    }

    public ArrayList<Integer> edgeList(int v)
    {
		return adjList[v];
	}
}


import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Locale;
import java.util.Scanner;

public class CF4 {

	public static BigInteger gcd (BigInteger a, BigInteger b) {
		return b.compareTo(BigInteger.ZERO)!=0 ? gcd (b, a.mod(b)) : a;
	}

	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		PrintWriter cout = new PrintWriter(System.out);
		BigInteger N = cin.nextBigInteger(), a = cin.nextBigInteger(), b = cin.nextBigInteger();
		BigInteger step = a.multiply(b).divide(a.gcd(b));
		BigInteger res = N.divide(step);
		BigInteger mod = a.min(b);
		BigInteger rr = res.multiply(mod);
		rr = rr.add(N.subtract(res.multiply(step)).add(BigInteger.ONE).min(mod)).subtract(BigInteger.ONE);
		BigInteger gcd = rr.gcd(N);
		cout.println(rr.divide(gcd)+"/"+N.divide(gcd));
		cout.flush();
	}

}


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

public class Main {
	private static final String TASKNAME = "a";

	int[][] lists = new int[4][20];
	int[] sz = new int[4];

	int[] size;
	boolean[] rev;

	void hanoiTowers(int quantity, int from, int to, int buf, boolean end) {
		if (quantity == 0) {
			return;
		}
		int lowest = lists[from][sz[from] - quantity];
		if (end && size[lowest] > 1 && !rev[lowest]) {
			if (quantity > 1) {
				hanoiTowers(quantity - 1, from, to, buf, false);
				move(from, buf);
				hanoiTowers(quantity - 1, to, from, buf, false);
				move(buf, to);
				hanoiTowers(quantity - 1, from, to, buf, end);
			} else {
				int t = lists[from][sz[from] - 1];
				--sz[from];
				lists[to][sz[to]] = t;
				++sz[to];
				rev[t] = !rev[t];

				for (int i = 0; i < size[t] - 1; ++i) {
					ansA.add(from);
					ansB.add(buf);
				}
				ansA.add(from);
				ansB.add(to);
				for (int i = 0; i < size[t] - 1; ++i) {
					ansA.add(buf);
					ansB.add(to);
				}
			}
		} else {
			hanoiTowers(quantity - 1, from, buf, to, false);
			move(from, to);
			hanoiTowers(quantity - 1, buf, to, from, end);
		}
	}

	ArrayList<Integer> ansA = new ArrayList<Integer>();
	ArrayList<Integer> ansB = new ArrayList<Integer>();

	private void move(int from, int to) {
		int t = lists[from][sz[from] - 1];
		--sz[from];
		lists[to][sz[to]] = t;
		++sz[to];
		rev[t] = !rev[t];

		for (int i = 0; i < size[t]; ++i) {
			ansA.add(from);
			ansB.add(to);
		}
	}

	private void solve() throws Exception {
		int n = nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; ++i) {
			a[i] = nextInt();
		}
		size = new int[n];
		rev = new boolean[n];

		for (int i = 0; i <= n; ++i) {
			boolean b = false;
			if (i == n || i > 0 && a[i] != a[i - 1]) {
				lists[1][sz[1]] = sz[1];
				++sz[1];
				// b = true;
			}
			if (i == n) {
				break;
			}
			if (!b) {
				++size[sz[1]];
			}
		}

		// System.err.println(sz[1] + " " + Arrays.toString(lists[1]));
		// System.err.println(Arrays.toString(size));

		hanoiTowers(sz[1], 1, 3, 2, true);

		println(ansA.size());
		for (int i = 0; i < ansA.size(); ++i) {
			println(ansA.get(i) + " " + ansB.get(i));
		}
	}

	private void run() {
		try {
			reader = new BufferedReader(new InputStreamReader(System.in));
			writer = new PrintWriter(System.out);
			// reader = new BufferedReader(new FileReader(TASKNAME + ".in"));
			// writer = new PrintWriter(new BufferedWriter(new
			// FileWriter(TASKNAME + ".out")));

			solve();

			reader.close();
			writer.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(13);
		}
	}

	public static void main(String[] args) {
		long time = System.currentTimeMillis();
		Locale.setDefault(Locale.US);
		new Main().run();
		System.err.printf("%.3f\n", (System.currentTimeMillis() - time) * 1e-3);
	}

	private StringTokenizer tokenizer;
	private PrintWriter writer;
	private BufferedReader reader;

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

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

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

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

	private void print(Object o) {
		writer.print(o);
	}

	private void println(Object o) {
		writer.println(o);
	}

	private void printf(String format, Object... args) {
		writer.printf(format, args);
	}
}


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

public class Main
{
    public static int min(int a, int b)
    {
        return a>b? b:a;
    }
    public static int max(int a, int b)
    {
        return a>b? a:b;
    }
    public static boolean nextPermutation(int[] p)
    {
        for(int a=p.length-2;a>=0;a--)
            if(p[a]<p[a+1])
                for(int b=p.length-1;;b--)
                    if(p[b]>p[a])
                    {
                        int t=p[a];
                        p[a]=p[b];
                        p[b]=t;
                        for (a++, b=p.length-1;a<b;a++, b--)
                        {
                            t=p[a];
                            p[a]=p[b];
                            p[b]=t;
                        }
                        return true;
                    }
        return false;
    }
    public static void main(String[] args)
    {
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int minn=1005;
        int p1=in.nextInt();
        minn=min(p1, minn);
        int p2=in.nextInt();
        minn=min(minn, p2);
        int p3=in.nextInt();
        minn=min(minn, p3);
        int p4=in.nextInt();
        minn=min(minn, p4);
        int a=in.nextInt();
        int b=in.nextInt();
        int ans=0;
        if(minn>a)
            ans=min(minn, b+1)-a;
        for(int i=max(minn, a);i<=b;i++)
        {
            int []q={p1, p2, p3, p4};
            int num=0;
            while(nextPermutation(q))
            {
                int c=(((i%q[0])%q[1])%q[2])%q[3];
                if(c==i)
                    num++;
            }
            if(num>=7)
                ans++;
        }
        out.println(ans);
        out.close();
        System.exit(0);
    }
}

class InputReader
{
    BufferedReader buf;
    StringTokenizer tok;
    InputReader()
    {
        buf = new BufferedReader(new InputStreamReader(System.in));
    }
    boolean hasNext()
    {
        while(tok == null || !tok.hasMoreElements())
        {
            try
            {
                tok = new StringTokenizer(buf.readLine());
            }
            catch(Exception e)
            {
                return false;
            }
        }
        return true;
    }
    String next()
    {
        if(hasNext())
            return tok.nextToken();
        return null;
    }
    int nextInt()
    {
        return Integer.parseInt(next());
    }
    long nextLong()
    {
        return Long.parseLong(next());
    }
    double nextDouble()
    {
        return Double.parseDouble(next());
    }
    BigInteger nextBigInteger()
    {
        return new BigInteger(next());
    }
    BigDecimal nextBigDecimal()
    {
        return new BigDecimal(next());
    }
}


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

public class Modulus {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        BigInteger ans = new BigInteger("2");
        ans = ans.pow(n);
        BigInteger ans2 = new BigInteger(Integer.toString(m));
        ans = ans2.mod(ans);
        System.out.println(ans);
    }
}


import java.util.Scanner;

/**
 * Created by zephyr on 2/18/15.
 */
public class DrazilandHisFriendsB {
    public static void main(String args[]) {
        Scanner cin = new Scanner(System.in);
        int a = cin.nextInt(), b = cin.nextInt(), s = cin.nextInt();
        int total = Math.abs(a) + Math.abs(b);
        if (total <= s && ((s - total ) % 2 == 0))
            System.out.println("Yes");
        else
            System.out.println("No");
    }

}


import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.ArrayList;
import java.util.Collections;
import java.text.DecimalFormat;
import java.lang.Math;
public class Lo {
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      String s = sc.next();
      String t = sc.next();
      Set<Character> A = new HashSet<Character>();
      Set<Character> B = new HashSet<Character>();
      ArrayList<Character> AA = new ArrayList<Character>();
      ArrayList<Character> BB = new ArrayList<Character>();
      for(int i = 0; i < s.length(); i++){
          A.add(s.charAt(i));
          AA.add(s.charAt(i));
      }
      int con2 = 0;
      for(int i = 0; i < t.length(); i++){
          B.add(t.charAt(i));
          BB.add(t.charAt(i));
          if(s.indexOf(t.charAt(i))==-1){
              con2 = 1;
          }
      }
      Collections.sort(AA);
      Collections.sort(BB);
      //if(!AA.equals(BB) || con2==1|| s.length()<t.length()){
        //  System.out.println("need tree");
      //}
      if((s.length()==t.length())&&AA.equals(BB)){
          System.out.println("array");
      }
      else{
          int k = s.indexOf(t.charAt(0));
          int j = t.indexOf(t.charAt(0));
          int count = 0;
          while(k< s.length() && j< t.length() && k!=-1){
              if(s.charAt(k)==t.charAt(j)){
                  count++;
                  k++;
                  j++;
              }
              else{
                  k++;
              }
          }
          if(con2==0 && s.length()>t.length() && count==t.length()){
              System.out.println("automaton");
          }
          else if(con2==1){
              System.out.println("need tree");
          }
          else if(s.length()>t.length()&& count!=t.length()&& B.size()!=1){
              System.out.println("both");
          }
          else{
              System.out.println("need tree");
          }
      }
    }
}


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

public class D {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	interface Interactor {
		int ask(int x, int y);

		void answer(int[] xs, int[] ys);
	}

	class SubmitInteractor implements Interactor {

		@Override
		public int ask(int x, int y) {
			if (Math.abs(x) > B || Math.abs(y) > B) {
				return -1;
			}
			out.println("0 " + x + " " + y);
			out.flush();
			try {
				return nextInt();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return -1;
		}

		@Override
		public void answer(int[] xs, int[] ys) {
			out.println("1 " + xs.length + " " + ys.length);
			for (int x : xs) {
				out.print(x + " ");
			}
			out.println();
			for (int y : ys) {
				out.print(y + " ");
			}
			out.println();
		}

	}

	static final int B = 100_000_000;
	static final int MAX_QUERIES = 300_000;

	int ask1d(int[] xs, int x) {
		int pos = Arrays.binarySearch(xs, x);
		if (pos < 0) {
			pos = -pos - 2;
		}
		int ret = Integer.MAX_VALUE;
		if (pos != -1) {
			ret = Math.min(ret, x - xs[pos]);
		}
		if (pos + 1 < xs.length) {
			ret = Math.min(ret, xs[pos + 1] - x);
		}
		return ret;
	}

	class LocalInteractor implements Interactor {

		int[] xs;
		int[] ys;

		int qryCnt = 0;

		@Override
		public int ask(int x, int y) {
			if (Math.abs(x) > B && Math.abs(y) > B) {
				return -1;
			}
			if (x > B) {
				x = B;
			}
			if (x < -B) {
				x = -B;
			}
			if (y > B) {
				y = B;
			}
			if (y < -B) {
				y = -B;
			}
			if (++qryCnt > MAX_QUERIES) {
				throw new AssertionError("too many queries");
			}
			return Math.min(ask1d(xs, x), ask1d(ys, y));
		}

		@Override
		public void answer(int[] xs, int[] ys) {
			Arrays.sort(xs);
			Arrays.sort(ys);

			if (!Arrays.equals(xs, this.xs) || !Arrays.equals(ys, this.ys)) {
				throw new AssertionError("wa");
			} else {
				System.err.println("gg in " + qryCnt);
			}
		}

		public LocalInteractor(int[] xs, int[] ys) {
			Arrays.sort(xs);
			Arrays.sort(ys);
			this.xs = xs;
			this.ys = ys;
		}

	}
	static final Random rng = new Random();

	int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	void go(int low, int high, Interactor it, List<Integer> ans) {
		if (high - low <= 1) {
			return;
		}

		int mid = (low + high) >> 1;
		int dist = it.ask(mid, mid);

		if (mid - dist == low) {
			if (mid + dist != high && it.ask(mid + dist, mid + dist) == 0) {
				ans.add(mid + dist);
			}
			return;
		}

		int found = it.ask(mid - dist, mid - dist) == 0 ? mid - dist : mid + dist;

		ans.add(found);
		go(low, found, it, ans);
		go(found, high, it, ans);
	}

	void solve(Interactor it) {
		int low = -B + it.ask(-B, -B);
		int high = B - it.ask(B, B);

		List<Integer> ans = new ArrayList<>();
		if (low == high) {
			ans.add(low);
		} else {
			ans.add(low);
			ans.add(high);
			go(low, high, it, ans);
		}

		int z = rand(-B, B);

		int[] ansX = new int[ans.size()];
		int[] ansY = new int[ans.size()];
		int szX = 0, szY = 0;

		for (int x : ans) {
			if (it.ask(x, z) == 0) {
				ansX[szX++] = x;
			}
			if (it.ask(z, x) == 0) {
				ansY[szY++] = x;
			}
		}

		it.answer(Arrays.copyOf(ansX, szX), Arrays.copyOf(ansY, szY));

	}

	D() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		// solve(new SubmitInteractor());
		// solve(new LocalInteractor(new int[] { 2 }, new int[] { 0, -3 }));
//		int cnt = 10000;
//		int[] xs = new int[cnt];
//		int[] ys = new int[cnt];

//		int small = B / 1000 * 999;
		// int small = B;
//		int small = 113231512;

//		for (int i = 0; i < cnt; i++) {
//			xs[i] = rand(-B, B);
//			ys[i] = rand(-B, B);
//		}

//		solve(new LocalInteractor(xs, ys));
		solve(new SubmitInteractor());
		out.close();
	}

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

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

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

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

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

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


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

public class Main {
     public static void main( String args[] ) throws Exception{
         BufferedReader br = new BufferedReader (new InputStreamReader (System.in),1024*8);
         StringTokenizer toke = new StringTokenizer(br.readLine());
         int res=0,min=0;
         int r=Integer.parseInt(toke.nextToken()),g=Integer.parseInt(toke.nextToken()),b=Integer.parseInt(toke.nextToken());
         int arr[]=new int[3];arr[0]=r;arr[1]=g;arr[2]=b;Arrays.sort(arr);min=arr[0];
         r=r-min;g=g-min;b=b-min;
         int aux=(r/3) +(g/3)+ (b/3);
         if((r%3)+(g%3)+(b%3) == 4 && min>0)min++;
         System.out.println(min+aux);
   }
}


import java.io.*;
import java.util.*;
import java.util.jar.Manifest;

public class CFB {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    private static final long MOD = 1000L * 1000L * 1000L + 7;
    private static final int[] dx = {0, -1, 0, 1};
    private static final int[] dy = {1, 0, -1, 0};
    private static final String yes = "Yes";
    private static final String no = "No";

    int n;
    int m;
    void solve() throws IOException {
        n = nextInt();
        m = nextInt();
        long res = 0;
        Map<Long, Long> hist = findHist();
        for (Map.Entry<Long, Long> entry1 : hist.entrySet()) {
            for (Map.Entry<Long, Long> entry2 : hist.entrySet()) {
                long l1 = entry1.getKey();
                long l2 = entry2.getKey();
                if ((l1 + l2) % m == 0) {
                    res += entry1.getValue() * entry2.getValue();
                }
            }
        }

        outln(res);
    }

    Map<Long, Long> findHist() {
        Map<Long, Long> res = new HashMap<>();
        int cnt = n / m;
        int left = n % m;
        for (int i = 0; i < m; i++) {
            long rem = 1L * (i + 1) * (i + 1) % m;
            res.put(rem, cnt * 1L + res.getOrDefault(rem, 0L));
        }

        for (int i = 0; i < left; i++) {
            long rem = 1L * (i + 1) * (i + 1) % m;
            res.put(rem, 1L + res.getOrDefault(rem, 0L));
        }

        return res;
    }

    void shuffle(int[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }
    long gcd(long a, long b) {
        while(a != 0 && b != 0) {
            long c = b;
            b = a % b;
            a = c;
        }
        return a + b;
    }
    private void outln(Object o) {
        out.println(o);
    }
    private void out(Object o) {
        out.print(o);
    }
    private void formatPrint(double val) {
        outln(String.format("%.9f%n", val));
    }
    public CFB() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    public static void main(String[] args) throws IOException {
        new CFB();
    }

    public long[] nextLongArr(int n) throws IOException{
        long[] res = new long[n];
        for(int i = 0; i < n; i++)
            res[i] = nextLong();
        return res;
    }
    public int[] nextIntArr(int n) throws IOException {
        int[] res = new int[n];
        for(int i = 0; i < n; i++)
            res[i] = nextInt();
        return res;
    }
    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }
    public String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}


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

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

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

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

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

            Point point = (Point) o;

            if (x != point.x) return false;
            if (y != point.y) return false;
            if (z != point.z) return false;

            return true;
        }

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

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        Point[][] ans = new Point[51][];
        ans[1] = new Point[]{new Point(0, 0, 0)};
        ans[2] = new Point[]{new Point(0, 0, 0), new Point(0, 1, 0), new Point(1, 1, 0), new Point(1, 0, 0), new Point(1, 0, 1), new Point(1, 1, 1), new Point(0, 1, 1), new Point(0, 0, 1)};
        for (int n = 3; n < ans.length; ++n) {
            Point[] prev = ans[n - 1];
            int prevSize = (n - 1) * (n - 1) * (n - 1);
            if (prev.length != prevSize) throw new RuntimeException();
            int sideSize = (n - 1) * (n - 1);
            if (!prev[prevSize - sideSize - 1].equals(new Point(n - 2, 0, n - 3))) throw new RuntimeException();
            if (!prev[prevSize - sideSize].equals(new Point(n - 2, 0, n - 2))) throw new RuntimeException();
            if (!prev[prevSize - 1].equals(new Point(0, 0, n - 2))) throw new RuntimeException();
            if (!prev[0].equals(new Point(0, 0, 0))) throw new RuntimeException();
            Point[] cur = new Point[n * n * n];
            ans[n] = cur;
            int curPtr = 0;
            for (int i = 0; i < sideSize; ++i) {
                Point old = prev[prevSize - 1 - i];
                cur[curPtr++] = new Point(old.x, old.y, 0);
            }
            for (int i = 0; i < prevSize; ++i) {
                Point old = prev[i];
                cur[curPtr++] = new Point(n - 2 - old.x, old.y, old.z + 1);
            }
            Point[] rect = getRectangleTraversal(n - 1, n);
            for (int i = 0; i < rect.length; ++i) {
                cur[curPtr++] = new Point(n - 1, rect[i].x, rect[i].y);
            }
            rect = getRectangleTraversal2(n);
            for (int i = 0; i < rect.length; ++i) {
                cur[curPtr++] = new Point(rect[i].x, n - 1, rect[i].y);
            }
            if (curPtr != cur.length) throw new RuntimeException();
            for (int i = 0; i < cur.length; ++i) {
                int tmp = cur[i].y;
                cur[i].y = cur[i].z;
                cur[i].z = tmp;
            }
        }
        int n = in.nextInt();
        int[][][] field = new int[n][n][n];
        Point prev = null;
        int at = 0;
        for (Point p : ans[n]) {
            if (prev != null) {
                int d = Math.abs(p.x - prev.x) + Math.abs(p.y - prev.y) + Math.abs(p.z - prev.z);
                if (d != 1) throw new RuntimeException();
            }
            prev = p;
            ++at;
            if (field[p.x][p.y][p.z] != 0) throw new RuntimeException();
            field[p.x][p.y][p.z] = at;
        }
        boolean xf = true;
        for (int[][] x : field) {
            if (xf) xf = false; else out.println();
            for (int[] y : x) {
                boolean zf = true;
                for (int z : y) {
                    if (zf) zf = false; else out.print(" ");
                    if (z == 0) throw new RuntimeException();
                    out.print(z);
                }
                out.println();
            }
        }
    }

    private Point[] getRectangleTraversal2(int n) {
        int sx = n;
        int sy = n;
        Point[] res = new Point[sx * sy];
        int resPtr = 0;
        if (sy % 2 == 0) {
            for (int y = sy - 1; y >= 0; --y) {
                if (y % 2 != 0) {
                    for (int x = 0; x < sx; ++x)
                        res[resPtr++] = new Point(y, x, 0);
                } else {
                    for (int x = sx - 1; x >= 0; --x)
                        res[resPtr++] = new Point(y, x, 0);
                }
            }
        } else {
            for (int y = sy - 1; y >= 2; --y) {
                if (y % 2 == 0) {
                    for (int x = 0; x < sx; ++x)
                        res[resPtr++] = new Point(y, x, 0);
                } else {
                    for (int x = sx - 1; x >= 0; --x)
                        res[resPtr++] = new Point(y, x, 0);
                }
            }
            for (int x = sx - 1; x >= 0; --x) {
                if (x % 2 == 0) {
                    res[resPtr++] = new Point(1, x, 0);
                    res[resPtr++] = new Point(0, x, 0);
                } else {
                    res[resPtr++] = new Point(0, x, 0);
                    res[resPtr++] = new Point(1, x, 0);
                }
            }
        }
        if (resPtr != res.length) throw new RuntimeException();
        return res;
    }

    private Point[] getRectangleTraversal(int sx, int sy) {
        Point[] res = new Point[sx * sy];
        int resPtr = 0;
        if (sy % 2 != 0) {
            for (int y = sy - 1; y >= 0; --y) {
                if (y % 2 == 0) {
                    for (int x = 0; x < sx; ++x)
                        res[resPtr++] = new Point(x, y, 0);
                } else {
                    for (int x = sx - 1; x >= 0; --x)
                        res[resPtr++] = new Point(x, y, 0);
                }
            }
        } else {
            for (int y = sy - 1; y >= 2; --y) {
                if (y % 2 != 0) {
                    for (int x = 0; x < sx; ++x)
                        res[resPtr++] = new Point(x, y, 0);
                } else {
                    for (int x = sx - 1; x >= 0; --x)
                        res[resPtr++] = new Point(x, y, 0);
                }
            }
            for (int x = 0; x < sx; ++x) {
                if (x % 2 == 0) {
                    res[resPtr++] = new Point(x, 1, 0);
                    res[resPtr++] = new Point(x, 0, 0);
                } else {
                    res[resPtr++] = new Point(x, 0, 0);
                    res[resPtr++] = new Point(x, 1, 0);
                }
            }
        }
        if (resPtr != res.length) throw new RuntimeException();
        return res;
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

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

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

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

    }


import java.io.*;
import java.math.BigInteger;
import java.util.*;
import static java.lang.Math.*;

public class Main implements Runnable {
    BufferedReader in;
    PrintWriter out;
    StringTokenizer st;

    int a, b, n;

    int[][] dp;
    BigInteger need;

    int rec(int item, int box) {
        if (item >= 50)
            return 1;
        if (box >= 35000)
            return 1;
        int ret = dp[item][box];
        if (ret == -1) {
            BigInteger a = BigInteger.valueOf(box).pow(item);
            if (a.compareTo(need) >= 0)
                ret = 0;
            else {
                ret = 100;
                ret = min(ret, rec(item, box + 1));
                ret = min(ret, rec(item + 1, box));
            }
            if (ret == 0)
                ret = 1;
            else
                ret = 0;
            dp[item][box] = ret;
        }
        return ret;
    }

    void solve() throws IOException {
        a = ni();
        b = ni();
        n = ni();
        if (a == 1 && (1 << b) >= n) {
            out.println("Missing");
            return;
        }
        dp = new int[50][35000];
        for (int i = 0; i < dp.length; i++) {
            Arrays.fill(dp[i], -1);
        }
        need = BigInteger.valueOf(n);
        int ret = rec(b, a);
        if (ret == 1)
            out.println("Masha");
        else
            out.println("Stas");
    }

    public Main() throws IOException {

    }

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

    int ni() throws IOException {
        return Integer.valueOf(ns());
    }

    long nl() throws IOException {
        return Long.valueOf(ns());
    }

    double nd() throws IOException {
        return Double.valueOf(ns());
    }

    public static void main(String[] args) throws IOException,
            InterruptedException {
        Thread th = new Thread(null, new Main(), "Main", 67108864);
        th.start();
        th.join();
        if (failed)
            throw new RuntimeException();
    }

    static boolean failed = false;

    @Override
    public void run() {
        Locale.setDefault(Locale.US);
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        try {
            solve();
            in.close();
            out.close();
        } catch (IOException e) {
            failed = true;
        }
    }
}


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

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

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    final BufferedReader br;
    final PrintWriter pw;
    StringTokenizer st;

    class Diploma{

        int min;
        int max;

        public Diploma(int min, int max){
            this.min = min;
            this.max = max;
        }

    }

    public void solve() throws Exception {
        int n = nextInt();
        Diploma[] a = new Diploma[3];
        for (int i = 0; i < 3; i++) {
            a[i] = new Diploma(nextInt(),nextInt());
        }
        int one = a[0].min;
        int two = a[1].min;
        int three = a[2].min;

        while (one + two + three != n) {

            if (n - two - three <= a[0].max) {
                one = n - two - three;
            } else if (two + 1 <= a[1].max) {
                two++;
            } else if (three + 1 <= a[2].max) {
                three++;
            }

        }
        pw.println(one + " " + two + " " + three);
    }

    public void run() throws Exception{
        long start = System.currentTimeMillis();
        solve();
        if(!ONLINE_JUDGE){
            long end = System.currentTimeMillis();
            System.err.println(end - start + " ms");
        }
        pw.close();
    }

    public Main() throws Exception {

        br = (ONLINE_JUDGE) ? new BufferedReader(new InputStreamReader(System.in))
                : new BufferedReader(new FileReader("in.txt"));

        pw = (ONLINE_JUDGE) ?
                new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)))
                : new PrintWriter(new BufferedWriter(new FileWriter("out.txt")));

    }

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

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

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

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

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

    public BigInteger nextBigInteger () throws IOException {
        return new BigInteger(next());
    }

    public String nextLine() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            return br.readLine();
        }
        StringBuilder sb = new StringBuilder(st.nextToken());
        while (st.hasMoreTokens()){
            sb.append(" " + st.nextToken());
        }
        return sb.toString();
    }

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

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

}


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

/**
 * Created by Luis Ngo on 22/12/2016.
 */
public class P746C {
    public static void main (String[] args){
        Scanner  scanner =  new Scanner(System.in);
        int s =  scanner.nextInt();
        int x1 =  scanner.nextInt();
        int x2 =  scanner.nextInt();
        int t1 =  scanner.nextInt();
        int t2 =  scanner.nextInt();
        int p =  scanner.nextInt();
        int d =  scanner.nextInt();

        int time1 = Math.abs(x2-x1)*t2;

        int time2 = 0;
        if (x2 -x1 < 0 && d < 0) {
            if (p < x2)
                time2 = (2*s -(x2 - p)) * t1;
            else {
                time2 = (p - x2) * t1;
                if (p<x1) time2 += s*2*t1;
            }
        } else if (x2 -x1 < 0  && d > 0)time2 = (s-p + s-x2) * t1;
        else if (x2 -x1 > 0  && d > 0) {
            if (p > x2) time2 = (2*s -(p - x2)) * t1;
             else {
                time2 = (x2-p) * t1;
                if (p>x1) time2 += s*2*t1;
            }
        }else time2 = (p +x2) * t1;
        System.out.println(Math.min(time1,time2));
    }

}


import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main
{
    static int n;
    static int[][][] p=new int[10][10][3];
    static int a,b,c,d,e;
    static int k;
    static int[][] dp=new int[10][10];
    static int[][] m=new int[30][2];
    static int ee=0;
    static int[] ru=new int[10];
    static int[] chu=new int[10];
    static int mi=-1,mx=-1;
    public static void main(String[] args) {
        Scanner cin=new Scanner(new BufferedInputStream(System.in));
        n=cin.nextInt();
        k=n*(n-1)/2;
        for(int i=0;i<k;i++){
            a=cin.nextInt();
            b=cin.nextInt();
            c=cin.nextInt();
            d=cin.nextInt();
            e=cin.nextInt();
            p[a][b][0]=c; p[a][b][1]=d; p[a][b][2]=e;
        }
        for(int i=1;i<=n;i++){
            for(int j=i+1;j<=n;j++){
                m[ee][0]=i;
                m[ee][1]=j;
                ee++;
            }
        }
        //System.out.println(ee);
        dfs(0,0);
        System.out.println(mi+" "+mx);
    }

    public static void dfs(int cnt,int ans){
        if(cnt==ee){
            solve();
            return;
        }
        if(mi!=-1&&ans>mi)
            return;
        if(n==6&&chu[3]!=0&&ru[2]!=chu[2])
            return;
        if(n==6&&chu[4]!=0&&ru[3]!=chu[3])
            return;
        if(n==6&&chu[5]!=0&&ru[4]!=chu[4])
            return;
        int i=m[cnt][0],j=m[cnt][1];
        for(int k=p[i][j][0];k<=p[i][j][1];k++){
            chu[i]+=k;
            ru[j]+=k;
            dp[i][j]=k;
            if(cnt<n-1)
                dfs(cnt+1,ans+k);
            else
                dfs(cnt+1,ans);
            chu[i]-=k;
            ru[j]-=k;
        }
    }

    public static void solve(){
        //System.out.println(10);
        for(int i=2;i<n;i++){
            if(ru[i]!=chu[i])
                return;
        }
        int liu=0,cost=0;
        for(int i=1;i<n;i++)
            liu+=dp[i][n];
        for(int i=1;i<=n;i++){
            for(int j=i+1;j<=n;j++){
                if(dp[i][j]==0)
                    continue;
                cost+=p[i][j][2]+dp[i][j]*dp[i][j];
            }
        }
        if(mi==-1){
            mi=liu;
            mx=cost;
        }
        else{
            if(liu<mi){
                mi=liu;
                mx=cost;
            }
            else if(liu==mi){
                mx=Math.max(mx,cost);
            }
        }
    }
}


import java.util.Scanner;

/*
 * 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.
 */

/**
 *
 * @author ac
 */
public class P1146A {
    public static void main(String[] args){
        Scanner sc = new Scanner (System.in);

        char[] c = sc.next().toCharArray();
        int n=c.length;
        int x = 0;

        int r = n / 2 + 1;
        for(int i=0; i<c.length; i++){
            if(c[i]=='a'){
                x++;
            }
        }

        int ans = n;
        if(x < r) {
            ans = 2 * x - 1;
        }
        System.out.println(ans);
    }
}


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

public class b{

    public static void main(String [] args) throws IOException{
        FastScanner sc=new FastScanner();
        PrintWriter out=new PrintWriter(System.out);
        int n=sc.nextInt();
        int d=sc.nextInt();
        int [] time=sc.nextIntArray(n);
        int timeUsed=0;
        for(int i : time)timeUsed+=i;
        timeUsed+=(n-1)*10;

        if(timeUsed>d){
            out.println(-1);
            out.close();return;
        }

        int cnt=(n-1)*2;
        cnt+=(d-timeUsed)/5;
        out.println(cnt);
        out.close();

    }
}

class FastScanner{
    private int BUFFER_SIZE = 1 << 16;

   private  DataInputStream din;

   private  byte[] buffer;

   private int bufferPointer, bytesRead;

   public FastScanner() {
       din = new DataInputStream(System.in);
       buffer = new byte[BUFFER_SIZE];
       bufferPointer = bytesRead = 0;
   }

   public FastScanner( String file_name) throws IOException {
       din = new DataInputStream(new FileInputStream(file_name));
       buffer = new byte[BUFFER_SIZE];
       bufferPointer = bytesRead = 0;
   }

   public String readLine() throws IOException {
        byte[] buf = new byte[64];
       int cnt = 0, c;
       while ((c = read()) != -1) {
           if (c == '\n')
               break;
           buf[cnt++] = (byte) c;
       }
       return new String(buf, 0, cnt);
   }

   public String next() throws IOException{

       byte c = read();
       while(Character.isWhitespace(c)){
           c = read();
       }

        StringBuilder builder = new StringBuilder();
       builder.append((char)c);
       c = read();
       while(!Character.isWhitespace(c)){
           builder.append((char)c);
           c = read();
       }

       return builder.toString();
   }

   public int nextInt() throws IOException {
       int ret = 0;
       byte c = read();
       while (c <= ' ')
           c = read();
        boolean neg = (c == '-');
       if (neg)
           c = read();
       do {
           ret = ret * 10 + c - '0';
       } while ((c = read()) >= '0' && c <= '9');

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

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

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

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

   public char nextChar() throws IOException{
       byte c = read();
       while(Character.isWhitespace(c)){
           c = read();
       }
       return (char) c;
   }

   public double nextDouble() throws IOException {
       double ret = 0, div = 1;
       byte c = read();
       while (c <= ' ')
           c = read();
        boolean neg = (c == '-');
       if (neg)
           c = read();

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

       if (c == '.') {
           while ((c = read()) >= '0' && c <= '9') {
               ret += (c - '0') / (div *= 10);
           }
       }

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

   public double[] nextDoubleArray( int n) throws IOException {
        double arr[] = new double[n];
       for(int i = 0; i < n; i++){
           arr[i] = nextDouble();
       }
       return arr;
   }

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

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

   public void close() throws IOException {
       if (din == null)
           return;
       din.close();
   }

}


import java.util.*;
public class CodeForces {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int k = input.nextInt();
		String s = input.next();
		Queue<String>q = new LinkedList<>();
		HashSet<String>set = new HashSet<>();
		set.add(s);
		q.add(s);
		int cost =0;
		while(!q.isEmpty()){
			String ss = q.remove();
			if(set.size() == k)break;
			for(int i =0;i<ss.length();i++){
				StringBuffer temp = new StringBuffer(ss);
				temp.deleteCharAt(i);

				if(!set.contains(temp.toString()) && set.size()<k){
					set.add(temp.toString());
					q.add(temp.toString());
					cost+=(s.length()-temp.length());
				}else if(set.size() == k)break;
			}
		}
		if(set.size() != k)cost = -1;
		System.out.println(cost);

	}

}

/*
1.make sure to include continue or return if u are handling a specific case separately!!!!
and check the constraints of every alphabet(missed to check for case 0)!!!!!!!!!

2.when u have transitions between states and its not dp try dfs (also think of topo sort)
 */


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

public class SingleTest {
    public static void main(String[] args){
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int test_cases = 1;
        Solver s = new Solver();
        for (int i = 1; i <= test_cases; i++)
            s.solve(1, in, out);
        out.close();
    }
}

class Solver {
    void solve(int test_number, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int[] ac = new int[6];
        int[] bc = new int[6];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            ac[a[i]]++;
        }
        for (int i = 0; i < n; i++) {
            b[i] = in.nextInt();
            bc[b[i]]++;
        }
        int give = 0, ex = 0;
        for (int i = 1; i <= 5; i++) {
            if (ac[i] == bc[i]) continue;
            if (ac[i] > bc[i]) {
                int diff = ac[i] - bc[i];
                if (diff % 2 == 1) {
                    out.println("-1");
                    return;
                }
                if (give < 0) {
                    if (Math.abs(give) >= diff / 2) {
                        give += diff / 2;
                    }
                    else {
                        ex += diff / 2 - Math.abs(give);
                        give += diff / 2;
                    }
                }
                else {
                    give += diff / 2;
                    ex += diff / 2;
                }
            }
            else {
                int diff = bc[i] - ac[i];
                if (diff % 2 == 1) {
                    out.println("-1");
                    return;
                }
                if (give > 0) {
                    if (diff / 2 <= give) {
                        give -= diff / 2;
                    }
                    else {
                        ex += diff / 2 - give;
                        give -= diff / 2;
                    }
                }
                else {
                    give -= diff / 2;
                    ex += diff / 2;
                }
            }
        }
        out.println(ex);
    }
}

class InputReader {
    BufferedReader br;
    StringTokenizer st;

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

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

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

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

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

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


import java.util.*;
import java.io.*;
public class TestClass {

	static PrintWriter out = new PrintWriter(System.out);
	public static void main(String args[] ) throws Exception {

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        int p = 0,f=0;
        int a[] = new int[n];
        String q[] = new String[n];
        for(int i=0;i<n;i++)
        {
        	String s1[] = in.readLine().split(" ");
        	a[i] = Integer.parseInt(s1[0]);
        	q[i] = s1[1];
        }
        for(int i=0;i<n;i++)
        {
        	if(i==0)
        	{
        		if(!q[i].equals("South"))
            	{
            		out.println("NO");
            		f=1;
            		break;
            	}
        	}
        	if(i==n-1)
        	{
        		if(!q[i].equals("North"))
            	{
            		out.println("NO");
            		f=1;
            		break;
            	}
        	}

        	if(q[i].equals("North"))
        	{
        		p = p-a[i];
        	}
        	else if(q[i].equals("South"))
        	{
        		p = p+a[i];
        	}
        	if(p>20000 || p<0)
        	{
        		out.println("NO");
        		f=1;
        		break;
        	}
        	if(p==20000)
        	{
        		if(i+1<n)
        		{
	        		if(q[i].equals("North"))
	        		{
	        			if(!q[i+1].equals("South"))
	        			{
	        				out.println("NO");
	        				f=1;
	                		break;
	        			}
	        		}
	        		if(q[i].equals("South"))
	        		{
	        			if(!q[i+1].equals("North"))
	        			{
	        				out.println("NO");
	        				f=1;
	                		break;
	        			}
	        		}
        		}
        	}
        	if(p==0)
        	{
        		if(i+1<n)
        		{
	        		if(q[i].equals("North"))
	        		{
	        			if(!q[i+1].equals("South"))
	        			{
	        				out.println("NO");
	        				f=1;
	                		break;
	        			}
	        		}
	        		if(q[i].equals("South"))
	        		{
	        			if(!q[i+1].equals("North"))
	        			{
	        				out.println("NO");
	        				f=1;
	                		break;
	        			}
	        		}
        		}
        	}
        }
        if(f==0 && p==0)
        {
        	out.println("YES");
        }
        else if(f==0)
        {
        	out.println("NO");
        }
        out.close();
    }

}


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

public class A implements Runnable {
	public static void main (String[] args) {new Thread(null, new A(), "_cf", 1 << 28).start();}

	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("");

		int n = fs.nextInt();
		if(n == 1) {
			System.out.println(0);
			return;
		}

		int log = Integer.numberOfTrailingZeros(Integer.highestOneBit(n))+1;
		int[] a = fs.nextIntArray(n);

		int[] left = new int[3*n], right = new int[3*n];
		for(int i = 0; i < 3*n; i++) {
			int p1 = i-a[i%n], p2 = i+a[i%n];
			if(p1 < 0) p1 = -1; if(p2 >= 3*n) p2 = 3*n;
			left[i] = p1;
			right[i] = p2;
		}

		RMQLowMemory[] q1 = new RMQLowMemory[log];
		RMQLowMemoryMax[] q2 = new RMQLowMemoryMax[log];

		q1[0] = new RMQLowMemory(left);
		q2[0] = new RMQLowMemoryMax(right);

		int[] prevLA = new int[3*n];
		int[] prevRA = new int[3*n];
		for(int i = 0; i < 3*n; i++) {
			prevLA[i] = left[i];
			prevRA[i] = right[i];
		}

		for(int lg = 1; lg < log; lg++) {
			for(int i = 0; i < 3*n; i++) {
				int prevL = left[i];
				int prevR = right[i];
				if(prevL < 0) left[i] = prevL;
				else left[i] = q1[lg-1].query(prevL, Math.min(3*n-1, prevR));
				if(prevR >= 3*n) right[i] = prevR;
				else right[i] = q2[lg-1].query(Math.max(0, prevL), prevR);

				prevLA[i] = left[i]; prevRA[i] = right[i];
			}
			q1[lg] = new RMQLowMemory(left);
			q2[lg] = new RMQLowMemoryMax(right);
		}

		int[] res = new int[n];
		for(int i = n; i < 2*n; i++) {
			int best = 0, cL = i, cR = i;
			for(int lg = log-1; lg >= 0; lg--) {
				int nL = q1[lg].query(cL, cR);
				int nR = q2[lg].query(cL, cR);
				if(nR-nL+1 < n && nL >= 0 && nR < 3*n) {
					best += 1<<lg;
					cL = nL; cR = nR;
				}
			}
			res[i%n] = ++best;
		}
		for(int i = 0; i < n; i++) out.print(res[i] + " ");
		out.println();
		out.close();
	}

	int walk(int[][] lift, int pos, int dist) {
		int n = lift[0].length;
		while(dist > 0) {
			if(pos < 0 || pos >= n) break;
			int hi = Integer.highestOneBit(dist);
			int bit = Integer.numberOfTrailingZeros(hi);
			pos = lift[bit][pos];

			dist -= hi;
		}
		return pos;
	}

	class RMQLowMemory {
		final static int blockSize=32;
		int[] low, a;
		int[][] lift;

		public RMQLowMemory(int[] a) {
			int n=a.length, m=0;
			a=a.clone();
			this.a=a.clone();
			low=new int[n];
			for (int i=0; i<n; low[i]=++m, m<<=1, i++)
				while (m!=0 && a[i-Integer.numberOfTrailingZeros(m)]>= a[i])
					m-=Integer.lowestOneBit(m);

			int nn=(n+blockSize-1)>>5;
			int maxlog = Integer.numberOfTrailingZeros(Integer.highestOneBit(nn)) + 2;
			lift = new int[maxlog][nn];
			Arrays.fill(lift[0], Integer.MAX_VALUE);
			for (int i = 0; i < n; i++)
				lift[0][i/blockSize]=Math.min(lift[0][i/blockSize], a[i]);

			int lastRange = 1;
			for (int lg = 1; lg < maxlog; lg++, lastRange<<=1)
				for (int i = 0; i < nn; i++)
					lift[lg][i] = Math.min(lift[lg - 1][i], lift[lg - 1][Math.min(i + lastRange, nn - 1)]);

		}

		int query(int low, int high) {
			high++;
			int lowBlock=(low+blockSize-1)>>5, highBlock=high>>5;
			int crossBlock=acrossBlockQuery(lowBlock, highBlock);
			int edge1=edgeQuery(Math.max(low, high-blockSize), high);
			int edge2=edgeQuery(low, Math.min(low+blockSize-1, high));
			return Math.min(Math.min(edge1, edge2), crossBlock);
		}

		int acrossBlockQuery(int lBlock, int hBlock) {
			if (lBlock>=hBlock) return Integer.MAX_VALUE;
			int exp = Integer.highestOneBit(hBlock-lBlock);
			int lg = Integer.numberOfTrailingZeros(exp);
			return Math.min(lift[lg][lBlock], lift[lg][hBlock - exp]);
		}

		int edgeQuery(int l, int h) {
			int mask=(int) (low[h-1]&((1l<<h-l)-1));
			int moveLeft=Integer.numberOfTrailingZeros(Integer.highestOneBit(mask));
			return a[h-1-moveLeft];
		}
	}

	class RMQLowMemoryMax {
		final static int blockSize=32;
		int[] low, a;
		int[][] lift;

		public RMQLowMemoryMax(int[] a) {
			a=a.clone();
			for (int i=0; i<a.length; i++) a[i]*=-1;
			int n=a.length, m=0;
			this.a=a;
			low=new int[n];
			for (int i=0; i<n; low[i]=++m, m<<=1, i++)
				while (m!=0 && a[i-Integer.numberOfTrailingZeros(m)]>=a[i])
					m-=Integer.lowestOneBit(m);

			int nn=(n+blockSize-1)>>5;
			int maxlog = Integer.numberOfTrailingZeros(Integer.highestOneBit(nn)) + 2;
			lift = new int[maxlog][nn];
			Arrays.fill(lift[0], Integer.MAX_VALUE);
			for (int i = 0; i < n; i++)
				lift[0][i/blockSize]=Math.min(lift[0][i/blockSize], a[i]);

			int lastRange = 1;
			for (int lg = 1; lg < maxlog; lg++, lastRange<<=1)
				for (int i = 0; i < nn; i++)
					lift[lg][i] = Math.min(lift[lg - 1][i], lift[lg - 1][Math.min(i + lastRange, nn - 1)]);

		}

		int query(int low, int high) {
			high++;
			int lowBlock=(low+blockSize-1)>>5, highBlock=high>>5;
			int crossBlock=acrossBlockQuery(lowBlock, highBlock);
			int edge1=edgeQuery(Math.max(low, high-blockSize), high);
			int edge2=edgeQuery(low, Math.min(low+blockSize-1, high));
			return -Math.min(Math.min(edge1, edge2), crossBlock);
		}

		int acrossBlockQuery(int lBlock, int hBlock) {
			if (lBlock>=hBlock) return Integer.MAX_VALUE;
			int exp = Integer.highestOneBit(hBlock-lBlock);
			int lg = Integer.numberOfTrailingZeros(exp);
			return Math.min(lift[lg][lBlock], lift[lg][hBlock - exp]);
		}

		int edgeQuery(int l, int h) {
			int mask=(int) (low[h-1]&((1l<<h-l)-1));
			int moveLeft=Integer.numberOfTrailingZeros(Integer.highestOneBit(mask));
			return a[h-1-moveLeft];
		}
	}

//	class RMQLowMemoryMax {
//		final static int blockSize=32;
//		int[] low, a;
//		int[][] lift;
//
//		public RMQLowMemoryMax(int[] a) {
//			int n=a.length, m=0;
//			this.a=a;
//			low=new int[n];
//			for (int i=0; i<n; low[i]=++m, m<<=1, i++)
//				while (m!=0 && a[i-Integer.numberOfTrailingZeros(m)]>=a[i])
//					m-=Integer.lowestOneBit(m);
//
//			int nn=(n+blockSize-1)>>5;
//			int maxlog = Integer.numberOfTrailingZeros(Integer.highestOneBit(nn)) + 2;
//			lift = new int[maxlog][nn];
//			Arrays.fill(lift[0], Integer.MIN_VALUE);
//			for (int i = 0; i < n; i++)
//				lift[0][i/blockSize]=Math.max(lift[0][i/blockSize], a[i]);
//
//			int lastRange = 1;
//			for (int lg = 1; lg < maxlog; lg++, lastRange<<=1)
//				for (int i = 0; i < nn; i++)
//					lift[lg][i] = Math.max(lift[lg - 1][i], lift[lg - 1][Math.min(i + lastRange, nn - 1)]);
//
//		}
//
//		int query(int low, int high) {
//			high++;
//			int lowBlock=(low+blockSize-1)>>5, highBlock=high>>5;
//			int crossBlock=acrossBlockQuery(lowBlock, highBlock);
//			int edge1=edgeQuery(Math.max(low, high-blockSize), high);
//			int edge2=edgeQuery(low, Math.min(low+blockSize-1, high));
//			return Math.max(Math.max(edge1, edge2), crossBlock);
//		}
//
//		int acrossBlockQuery(int lBlock, int hBlock) {
//			if (lBlock>=hBlock) return Integer.MIN_VALUE;
//			int exp = Integer.highestOneBit(hBlock-lBlock);
//			int lg = Integer.numberOfTrailingZeros(exp);
//			return Math.max(lift[lg][lBlock], lift[lg][hBlock - exp]);
//		}
//
//		int edgeQuery(int l, int h) {
//			int mask=(int) (low[h-1]&((1l<<h-l)-1));
//			int moveLeft=Integer.numberOfTrailingZeros(Integer.highestOneBit(mask));
//			return a[h-1-moveLeft];
//		}
//
//	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) {
			try {
				in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
			}
			catch (Exception e) {
				in = new BufferedInputStream(System.in, BS);
			}
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}

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

	}

}


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

public class X424A {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] temp = br.readLine().split(" ");
        int n = Integer.parseInt(temp[0]);
        String x = br.readLine();
        int a = 0;
        int b = 0;
        for (char ch : x.toCharArray()) {
            if (ch == 'X') {
                a++;
            } else {
                b++;
            }
        }
        StringBuilder sb = new StringBuilder();
        int res = n / 2 - a;
        sb.append(n / 2 - Math.min(a, b));
        sb.append('\n');
        for (char ch : x.toCharArray()) {
            if (res < 0 && ch == 'X') {
                sb.append('x');
                res++;
            } else if (res > 0 && ch == 'x') {
                sb.append('X');
                res--;
            } else {
                sb.append(ch);
            }
        }
        System.out.println(sb);
    }
}


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

public class ProblemA {
    public static void main(String[] args) {
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);

        new ProblemA().solve(in, out);

        out.close();
    }

    public void solve(InputReader in, PrintWriter out) {
        int[][] a = new int[8][8];

        for (int i = 0; i < 8; i++) {
            String s = in.nextLine();

            for (int j = 0; j < s.length(); j++) {
                if (s.charAt(j) == 'W') {
                    a[i][j] = 1;
                } else if (s.charAt(j) == 'B') {
                    a[i][j] = 2;
                }
            }
        }

        int minA = Integer.MAX_VALUE;
        int minB = Integer.MAX_VALUE;
        for (int j = 0; j < 8; j++) {

            for (int i = 0; i < 8; i++) {
                if (a[i][j] == 1) {
                    boolean isOk = true;
                    for (int k = 0; k < i; k++) {
                        if (a[k][j] == 2) {
                            isOk = false;
                        }
                    }

                    if (isOk) {
                        minA = Math.min(minA, i);
                    }
                }
            }

            for (int i = 6; i >= 0; i--) {
                if (a[i][j] == 2) {
                    boolean isOk = true;
                    for (int k = i + 1; k < 8; k++) {
                        if (a[k][j] == 1) {
                            isOk = false;
                        }
                    }

                    if (isOk) {
                        minB = Math.min(minB, 7 - i);
                    }
                }
            }
        }

        if (minA <= minB) {
            out.print("A");
        } else {
            out.print("B");
        }
    }

    static class InputReader {
        public BufferedReader br;
        public StringTokenizer st;

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

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

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

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

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


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

public class Main implements Runnable {

	public void _main() throws IOException {
		int n = nextInt();
		int k = nextInt();
		int h = nextInt();
		int[] m = new int[n];
		int[] v = new int[n];
		for (int i = 0; i < n; i++) {
			m[i] = nextInt();
		}
		for (int i = 0; i < n; i++) {
			v[i] = nextInt();
		}
		Lemming[] a = new Lemming[n];
		for (int i = 0; i < n; i++) {
			a[i] = new Lemming(m[i], v[i], i);
		}
		Arrays.sort(a);
		double left = -1;
		double right = 1500000000;
		int[] ans = new int[k];
		for (int it = 0; it < 100; it++) {
			double t = left + (right - left) / 2;
			int j = calc(ans, a, n, t, k, h);
			if (j >= k)
				right = t;
			else
				left = t;
		}
		calc(ans, a, n, right, k, h);
		//out.println(right);
		for (int i = 0; i < k; i++)
			out.print((ans[i] + 1) + " ");
	}

	// calc returns the number of rocks we can climb on if we have t time units
	private int calc(int[] ans, Lemming[] a, int n, double t, int k, int h) {
		int j = 0;
		for (int i = 0; i < n; i++) {
			double w = t * a[i].v;
			double need = (j + 1) * (long)h;
			if (w >= need) {
				if (j < k)
					ans[j] = a[i].id;
				++j;
			}
		}
		return j;
	}

	class Lemming implements Comparable<Lemming> {
		int m, v, id;
		Lemming(int m, int v, int id) {
			this.m = m;
			this.v = v;
			this.id = id;
		}
		public int compareTo(Lemming o) {
			if (m != o.m) {
				return m < o.m ? -1 : 1;
			}
			if (v != o.v) {
				return v < o.v ? -1 : 1;
			}
			if (id != o.id) {
				return id < o.id ? -1 : 1;
			}
			return 0;
		}
	}

	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer st;

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

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

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

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

	public static void main(String[] args) {
		Locale.setDefault(Locale.UK);
		new Thread(new Main()).start();
	}

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			//in = new BufferedReader(new FileReader("a.in"));
			//out = new PrintWriter(new FileWriter("a.out"));

			_main();

			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(202);
		}
	}

}


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

public class ProblemB {
    public static void main(String[] args) {
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);

        new ProblemB().solve(in, out);

        out.close();
    }

    public void solve(InputReader in, PrintWriter out) {
        int a = in.nextInt();
        int x = in.nextInt();
        int y = in.nextInt();

        int k = y / a;

        if (k * a == y) {
            out.print(-1);

            return;
        }

        if (k == 0) {
            if (2 * x >= a || 2 * x <= -1 * a) {
                out.print(-1);

                return;
            } else {
                out.print(1);

                return;
            }
        }

        if (k % 2 == 0) {
            if (x == 0 || x >= a || x <= -1 * a) {
                out.print(-1);

                return;
            } else {
                if (x < 0) {
                    out.print(k * 3 / 2);
                } else {
                    out.print(k * 3 / 2 + 1);
                }

                return;
            }
        } else {
            if (2 * x >= a || 2 * x <= -1 * a) {
                out.print(-1);

                return;
            } else {
                out.print(3 * (k + 1) / 2 - 1);

                return;
            }
        }
    }

    static class InputReader {
        public BufferedReader br;
        public StringTokenizer st;

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

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

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

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

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


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

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

    static class TaskC {
        public int mod = 1000000007;
        public int x1;
        public int x2;
        public int y1;
        public int y2;
        public int k;
        public int MAXB = 32;
        public int[][] dpc;
        public int[][] dps;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            x1 = in.nextInt() - 1;
            y1 = in.nextInt() - 1;
            x2 = in.nextInt() - 1;
            y2 = in.nextInt() - 1;
            k = in.nextInt() - 1;
            dpc = new int[MAXB][1 << 5];
            dps = new int[MAXB][1 << 5];
            for (int i = 0; i < MAXB; i++) {
                Arrays.fill(dpc[i], -1);
                Arrays.fill(dps[i], -1);
            }
            dfs(MAXB - 1, 0, 0, 0, 0, 0);
            out.println((dps[MAXB - 1][0] + dpc[MAXB - 1][0]) % mod);
        }

        public void dfs(int bit, int gx, int lx, int gy, int ly, int lk) {
            int cm = getMask(gx, lx, gy, ly, lk);
            if (dpc[bit][cm] != -1) return;

            int cx1 = (x1 >> bit) & 1;
            int cx2 = (x2 >> bit) & 1;
            int cy1 = (y1 >> bit) & 1;
            int cy2 = (y2 >> bit) & 1;
            int ck = (k >> bit) & 1;
            dpc[bit][cm] = 0;
            dps[bit][cm] = 0;
            for (int xb = 0; xb <= 1; xb++) {
                for (int yb = 0; yb <= 1; yb++) {
                    if (xb == 0 && cx1 == 1 && gx == 0) continue;
                    if (xb == 1 && cx2 == 0 && lx == 0) continue;
                    if (yb == 0 && cy1 == 1 && gy == 0) continue;
                    if (yb == 1 && cy2 == 0 && ly == 0) continue;
                    int bitk = xb ^ yb;
                    if (bitk == 1 && ck == 0 && lk == 0) continue;

                    int ngx = gx | (xb > cx1 ? 1 : 0);
                    int ngy = gy | (yb > cy1 ? 1 : 0);
                    int nlx = lx | (xb < cx2 ? 1 : 0);
                    int nly = ly | (yb < cy2 ? 1 : 0);
                    int nlk = lk | (bitk < ck ? 1 : 0);

                    if (bit > 0) {
                        dfs(bit - 1, ngx, nlx, ngy, nly, nlk);
                        int ms = getMask(ngx, nlx, ngy, nly, nlk);
                        dps[bit][cm] = (int) ((dps[bit][cm] + dps[bit - 1][ms] + 1L * dpc[bit - 1][ms] * (bitk << bit)) % mod);
                        dpc[bit][cm] += dpc[bit - 1][ms];
                        if (dpc[bit][cm] >= mod) dpc[bit][cm] -= mod;
                    } else {
                        dps[bit][cm] += bitk << bit;
                        dpc[bit][cm]++;
                    }
                }
            }
        }

        public int getMask(int gx, int lx, int gy, int ly, int lk) {
            int msk = gx;
            msk <<= 1;
            msk |= lx;
            msk <<= 1;
            msk |= gy;
            msk <<= 1;
            msk |= ly;
            msk <<= 1;
            msk |= lk;
            return msk;
        }

    }

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

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

        public int read() {
            if (this.numChars == -1) {
                throw new InputMismatchException();
            } else {
                if (this.curChar >= this.numChars) {
                    this.curChar = 0;

                    try {
                        this.numChars = this.stream.read(this.buf);
                    } catch (IOException var2) {
                        throw new InputMismatchException();
                    }

                    if (this.numChars <= 0) {
                        return -1;
                    }
                }

                return this.buf[this.curChar++];
            }
        }

        public int nextInt() {
            int c;
            for (c = this.read(); isSpaceChar(c); c = this.read()) {
                ;
            }

            byte sgn = 1;
            if (c == 45) {
                sgn = -1;
                c = this.read();
            }

            int res = 0;

            while (c >= 48 && c <= 57) {
                res *= 10;
                res += c - 48;
                c = this.read();
                if (isSpaceChar(c)) {
                    return res * sgn;
                }
            }

            throw new InputMismatchException();
        }

        public String next() {
            int c;
            while (isSpaceChar(c = this.read())) {
                ;
            }

            StringBuilder result = new StringBuilder();
            result.appendCodePoint(c);

            while (!isSpaceChar(c = this.read())) {
                result.appendCodePoint(c);
            }

            return result.toString();
        }

        public static boolean isSpaceChar(int c) {
            return c == 32 || c == 10 || c == 13 || c == 9 || c == -1;
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

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

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

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

        public void println(int i) {
            writer.println(i);
        }

    }
}


// practice with kaiboy
import java.io.*;
import java.util.*;

public class CF1081A extends PrintWriter {
	CF1081A() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF1081A o = new CF1081A(); o.main(); o.flush();
	}

	void main() {
		int n = sc.nextInt();
		println(n <= 2 ? n : 1);
	}
}