public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int ans = n*5 % k == 0 ? n*5/k : n*5/k + 1;
        int ans2 = n*2%k == 0 ? n*2/k : n*2/k + 1;
        int ans3 = n*8%k == 0 ? n*8/k : n*8/k + 1;
        System.out.println(ans + ans2 + ans3);
        }
    }


public class CF1080A
{
	BufferedReader in = new BufferedReader(System.in);
	StringTokenizer st = new StringTokenizer(in.readLine());
	int n = Integer.parseInt(st.nextToken());
	int k = Integer.parseInt(st.nextToken());

	int redS = n * 2;
	int greenS = n * 5;
	int blueS = n * 8;

	int redN = redS / k;
	int greenN = greenS / k;
	int blueN = blueS / k;

	if(redS % k != 0) redN++;
	if(greenS % k != 0) greenN++;
	if(blueS % k != 0) blueN++;

	System.out.println(redN + greenN + blueN);
}


import java.util.Scanner;
public class A1080{
    public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int k = scan.nextInt();
    int red = 2*n;
    int blue = 8 * n;
    int green = 5 * n;
    double r = red/k;
    double g = green/n;
    double b = blue/n;
    System.out.println((Math.ceil(r));
    //int output  = int(Math.ceil(r) + Math.ceil(g) + Math.ceil(b));
    //System.out.println(output);

    }
}


import java.util.*;

public class PetyaOrigami{
	public static void main(String args[]){
		Scanner kbd = new Scanner(System.in);
		int n = Integer.parseInt(kbd.next());
		int c = Integer.parseInt(kbd.next());
		int kol = ((n*2+k-1)/k) + ((n*5+k-1)/k) + ((n*8+k-1)/k)
		System.out.println(kol);
	}
}


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

public class Div1_462D {

	static final long MOD = 1_000_000_007;

	static final long INV6 = 166_666_668;
	static final long INV30 = 233_333_335;
	static final long INV42 = 23_809_524;

	static long[] polyC;

	static final long[][] comb = { { 1 }, { 1, 1 }, { 1, 2, 1 }, { 1, 3, 3, 1 } };

	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter printer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		long N = Long.parseLong(reader.readLine());
		long SQRTN = (long) Math.sqrt(N);

		long nModded = N % MOD;

		polyC = new long[] { nModded * (nModded + 1) % MOD * (nModded + 2) % MOD * INV6 % MOD,
				(3 * nModded % MOD + 4) % MOD * INV6 % MOD, (-3 * nModded % MOD - 6 + 4 * MOD) % MOD * INV6 % MOD,
				2 * INV6 % MOD };

		long[] powC = new long[4];

		long[] powXSQ = new long[4];

		long sum = 0;
		for (long x = -SQRTN; x <= SQRTN; x++) {
			Arrays.fill(powC, 0);
			long XSQ = x * x % MOD;

			powXSQ[0] = 1;
			powXSQ[1] = XSQ;
			powXSQ[2] = powXSQ[1] * XSQ % MOD;
			powXSQ[3] = powXSQ[2] * XSQ % MOD;

			for (int term = 0; term <= 3; term++) {
				for (int subT = 0; subT <= term; subT++) {
					// subT is power of y^2
					long cCoeff = powXSQ[term - subT] * comb[term][subT] * polyC[term] % MOD;
					powC[subT] = (powC[subT] + cCoeff) % MOD;
				}
			}

			long YMAX = (long) Math.sqrt(N - x * x);
			sum = (sum + powC[3] * 2 * sumSixths(YMAX)) % MOD;
			sum = (sum + powC[2] * 2 * sumFourths(YMAX)) % MOD;
			sum = (sum + powC[1] * 2 * sumSquares(YMAX)) % MOD;
			sum = (sum + powC[0] * ((2 * YMAX + 1) % MOD)) % MOD;
		}
		printer.println(sum);
		printer.close();
	}

	static long sumSquares(long N) {
		return N * (N + 1) % MOD * (2 * N + 1) % MOD * INV6 % MOD;
	}

	static long sumFourths(long N) {
		return N * (N + 1) % MOD * (2 * N + 1) % MOD * ((3 * N * (N + 1) - 1) % MOD) % MOD * INV30 % MOD;
	}

	static long sumSixths(long N) {
		return N * (N + 1) % MOD * (2 * N + 1) % MOD * ((3 * N * (N + 1) % MOD * ((N * N + N - 1) % MOD) + 1) % MOD)
				% MOD * INV42 % MOD;
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.File;
import java.util.ArrayList;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Collections;
import java.io.InputStream;

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

    static class TaskD {
        public int mod = 1000000007;
        public long inv6 = Utils.inv(6, mod);
        public long inv60 = Utils.inv(60, mod);

        public long sum2(long from, long to, long X, long a) {
            long ret = inv6;
            ret = ret * (from - to - 1 + mod) % mod;
            long a1 = 2 * from * from % mod - from + to + 2 * to * to % mod + 2 * from * to % mod;
            a1 %= mod;
            if (a1 < 0) a1 += mod;
            a1 = a1 * a % mod;
            a1 = a1 - 3 * X * (from + to) % mod;
            a1 %= mod;
            if (a1 < 0) a1 += mod;
            return ret * a1 % mod;

        }

        public long sum1(long from, long to, long m, long a) {
            long ret = inv60;
            ret = ret * a % mod * (a + 1) % mod * (2 * a + 1) % mod * (from - to - 1 + mod) % mod;
            long inner = 6 * a * a % mod + 6 * a % mod + 5 * from % mod - 10 * m % mod + 5 * to % mod - 12;
            inner %= mod;
            if (inner < 0) inner += mod;
            return ret * inner % mod;
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            long m = in.nextLong();
            long mm = m % mod;
            long base = mm * (mm + 1) % mod * (mm + 2) % mod * inv6 % mod;
            ArrayList<Long> a1 = new ArrayList<>();
            ArrayList<Long> a2 = new ArrayList<>();
            long sk = 0, sa = 0;
            for (int k = 1; 1L * k * k <= m; k++) {
                a1.add(1L * k * k);
                a2.add(m - 1L * k * k + 1);
                sa++;
                sk = (sk + 1L * k * k) % mod;
            }
            a1.add(m + 1);
            Collections.reverse(a2);
            long start = System.currentTimeMillis();
            ArrayList<Long> ss = new ArrayList<>();
            int i1 = 0, i2 = 0;
            while (i1 < a1.size() && i2 < a2.size()) {
                if (a1.get(i1) < a2.get(i2)) ss.add(a1.get(i1++));
                else ss.add(a2.get(i2++));
            }
            while (i1 < a1.size()) ss.add(a1.get(i1++));
            while (i2 < a2.size()) ss.add(a2.get(i2++));
            Collections.sort(ss);
            Debug.print(System.currentTimeMillis() - start);

            long sqrtval = 1;
            long ans = 0;
            for (int i = 0; i < ss.size() - 1; i++) {
                long from = ss.get(i), to = ss.get(i + 1) - 1;
                if (from > to) continue;

                while ((sqrtval + 1) * (sqrtval + 1) <= to) sqrtval++;
                while ((m - sa * sa) < to) {
                    sk = (sk - sa * sa) % mod;
                    if (sk < 0) sk += mod;
                    sa--;
                }
                from %= mod;
                to %= mod;
                long X = (sa + 1) * (mm + 1) % mod - sk;
                if (X < 0) X += mod;
                long add = sum1(from, to, mm, sa) + sum2(from, to, X, sa + 1);
                add = add * sqrtval % mod;
                add %= mod;
                ans = (ans + add) % mod;

            }
//        for (int n = 1; n <= m; n++) {
//            for (int k = 0; k * k <= n; k++) {
//                ans += (int)(Math.sqrt(n-k*k)) * n * (m - n + 1);
//            }
//        }
            ans *= 4;
            ans += base;
            out.println(ans % mod);
        }

    }

    static class Debug {
        public static boolean DEBUG;

        static {
            try {
                DEBUG = System.getProperty("user.dir").contains("Dropbox");
            } catch (Exception e) {
                DEBUG = false;
            }
        }

        private static ArrayList<String> getParams() {
            StackTraceElement[] t = new Exception().getStackTrace();
            StackTraceElement up = t[2];

            ArrayList<String> ret = new ArrayList<>();
            ret.add(up.getFileName() + "/" + up.getMethodName());
            try {
                BufferedReader br = new BufferedReader(new FileReader(
                        new File("src/" + up.getClassName().replaceAll("\\.", "/") + ".java")));
                int g = up.getLineNumber();
                while (--g > 0) br.readLine();
                String q = br.readLine();
                String[] ss = q.split("Debug\\.print\\(");
                String[] qq = ss[1].substring(0, ss[1].indexOf(")")).split(",");
                for (int i = 0; i < qq.length; i++) {
                    ret.add(qq[i].trim());
                }
            } catch (Exception e) {
            }
            for (int i = 0; i < 100; i++) ret.add("???");
            return ret;
        }

        private static String toString(Object o) {
            if (o instanceof Object[]) {
                return Arrays.toString((Object[]) o);
            } else if (o instanceof char[]) {
                return new String((char[]) o);
            } else if (o instanceof int[]) {
                return Arrays.toString((int[]) o);
            } else if (o instanceof long[]) {
                return Arrays.toString((long[]) o);
            } else if (o instanceof double[]) {
                return Arrays.toString((double[]) o);
            } else {
                return o.toString();
            }
        }

        public static void print(Object x) {
            if (!DEBUG) return;
            ArrayList<String> s = getParams();
            System.out.println(s.get(0) + ": " + s.get(1) + " = " + toString(x));
        }

    }

    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(long i) {
            writer.println(i);
        }

    }

    static class Utils {
        public static long inv(long N, long M) {
            long x = 0, lastx = 1, y = 1, lasty = 0, q, t, a = N, b = M;
            while (b != 0) {
                q = a / b;
                t = a % b;
                a = b;
                b = t;
                t = x;
                x = lastx - q * x;
                lastx = t;
                t = y;
                y = lasty - q * y;
                lasty = t;
            }
            return (lastx + M) % M;
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1 << 16];
        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 long nextLong() {
            int c;
            for (c = this.read(); isSpaceChar(c); c = this.read()) {
                ;
            }

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

            long res = 0L;

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

            throw new InputMismatchException();
        }

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

    }
}


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

public class Codeforces933D {
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		long n = Long.parseLong(st.nextToken());

		int counter = 0;
		int N = 1000000007;

		for (int i = 0; i < 500000; i++) {
			counter += firstsum(n, 4*i+1);
			counter -= firstsum(n, 4*i+3);
			counter %= N;
		}

		for (int b = 1; b <= n/2000000; b++) {
			counter += secondsum(n, b);
			counter %= N;
		}

		int ans = (2*((2*counter)%N))%N;
		long k = ((((((n%N)*(n%N+1))%N)*(n%N+2))%N)*166666668)%N;
		ans = (ans + (int) k)%N;
		System.out.println(ans);
	}

	//1/2 = 500000004
	//1/3 = 333333336
	//1/6 = 166666668
	//lmao
	public static int firstsum(long n, long q) {
		int N = 1000000007;
		long floornq = (n/q)%N;
		n %= N;
		q %= N;
		long sum = ((floornq*(floornq+1))/2)%N;
		long sumsquare = (((sum*(2*floornq+1))%N)*333333336)%N;
		long sumcube = (sum*sum)%N;
		long nsquare = (n*n)%N;
		long qsquare = (q*q)%N;
		long qcube = (q*qsquare)%N;

		long k1 = (nsquare*floornq - qsquare*sumsquare + n*floornq + q*sum)%N;
		if (k1 < 0)
			k1 += N;
		k1 = (k1*(n+1))%N;
		k1 = (k1*500000004)%N;

		long k2 = (((((n*(n+1))%N)*(2*n+1))%N)*166666668)%N;
		k2 = (k2*floornq)%N;

		long k3 = (((qcube*sumcube)%N)*333333336)%N;
		k3 -= (((qsquare*sumsquare)%N)*500000004)%N;
		k3 += (((q*sum)%N)*166666668)%N;

		long ans = (k1-k2+k3)%N;
		if (ans < 0)
			ans += N;
		return (int) ans;
	}

	//wtf who successfully codes this up in a real round?
	public static int secondsum(long n, long b) {
		int N = 1000000007;
		long bsquare = (b*b)%N;
		long bcube = (b*bsquare)%N;
		long max = (n/(4*b)-1)%N;
		long numk = (max + N + 1 - 500000)%N;
		long sumk = ((max)*(max+1)/2 + 250875)%N;
		long sumksquare = ((((long) max * (long) (max+1))%N * (long) (2*max + 1))%N * 166666668)%N-375084213;
		if (sumksquare < 0)
			sumksquare += N;

		long k1 = (((bcube*sumksquare)%N)*32)%N;
		long k2 = (((bsquare*sumk)%N * (4*b-1)%N)%N *8)%N;
		long k3 = ((26*bcube - 12*bsquare + b)%N * 333333336)%N;
		if (k3 < 0)
			k3 += N;
		k3 = (k3*numk)%N;
		long k4 = (((n+1)%N)*(b*(numk*(((4*b*500000 + 4*b*max)+4*b-1)%N)%N)%N))%N;

		long k5 = 0;
		long k6 = 0;

		if (n%(4*b) >= b) {
			long min2 = ((4*b)*(n/(4*b))+b)%N;
			long max2 = (Math.min((4*b)*(n/(4*b))+3*b-1, n))%N;
			//sum from min2 to max2 of (n+1-i)*i
			k5 = (((((max2*(max2+1))%N)*(2*max2+1))%N)*166666668)%N;
			k5 -= (((((((min2-1)*min2)%N)*(2*min2-1))%N)*166666668)%N);
			k6 = ((max2*(max2+1) - min2*(min2-1))/2)%N;
			k6 = (k6*((n+1)%N))%N;
			System.out.println(k6);
		}

		return (int) ((k4-k1-k2-k3-k5+k6+7*(long)N)%N);
	}

}


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

public class D3 {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		long m = nl();
		int mod = 1000000007;
		long mm = m%mod;
		long ans = 0;
		for(long x = 1;x*x <= m;x++){
			long n = (long)Math.sqrt(m-x*x);
			ans += invl(420, mod) * (n+1) % mod
					* (70*mm%mod*mm%mod*mm+210*mm%mod*mm
							-42*mm%mod*n%mod*n%mod*n%mod*n%mod
							-63*mm%mod*n%mod*n%mod*n%mod
							-140*mm%mod*n%mod*n%mod*x%mod*x%mod
							+63*mm%mod*n%mod*n%mod
							-70*mm%mod*n%mod*x%mod*x%mod
							+42*mm%mod*n%mod
							-210*mm%mod*x%mod*x%mod*x%mod*x%mod
							+210*mm%mod*x%mod*x%mod
							+140*mm%mod
							+20*n%mod*n%mod*n%mod*n%mod*n%mod*n%mod
							+50*n%mod*n%mod*n%mod*n%mod*n%mod
							+84*n%mod*n%mod*n%mod*n%mod*x%mod*x%mod
							-64*n%mod*n%mod*n%mod*n%mod
							+126*n%mod*n%mod*n%mod*x%mod*x%mod
							-146*n%mod*n%mod*n%mod
							+140*n%mod*n%mod*x%mod*x%mod*x%mod*x%mod
							-266*n%mod*n%mod*x%mod*x%mod
							+76*n%mod*n%mod
							+70*n%mod*x%mod*x%mod*x%mod*x%mod
							-154*n%mod*x%mod*x%mod
							+64*n%mod
							+140*x%mod*x%mod*x%mod*x%mod*x%mod*x%mod
							-420*x%mod*x%mod*x%mod*x%mod
							+280*x%mod*x%mod
							)%mod;
		}
		ans = ans * 4 + mm*(mm+1)%mod*(mm+2)%mod*invl(6,mod)%mod;
		ans %= mod;
		if(ans < 0)ans += mod;
		out.println(ans);
	}

	public static long invl(long a, long mod) {
		long b = mod;
		long p = 1, q = 0;
		while (b > 0) {
			long c = a / b;
			long d;
			d = a;
			a = b;
			b = d % b;
			d = p;
			p = q;
			q = d - c * q;
		}
		return p < 0 ? p + mod : p;
	}

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

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

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

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

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

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

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

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

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

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

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

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

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

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

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

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


import java.io.*;

public class Main {
    final static double mod = 1e9 + 7;
	public static void main (String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		String[] input = bf.readLine().split(" ");
		long p = Long.parseLong(input[0]);
		long k = Long.parseLong(input[1]);
		long order = 1;
		long temp = k;

		if (k == 0)
		    System.out.println((int)Math.pow(p, p - 1));
		else {
    	    while (temp != 1) {
    	        temp = (k * temp) % p;
    	        order++;
    	    }

    	    if (k == 1)
		        System.out.println((((int)Math.pow(p,p) % (int) mod));
		    else
		        System.out.println((((int)Math.pow(p, (p - 1)/order)) % (int) mod));
		}
	}
}


import java.util.*;

public class Solution{
	private static final int MOD = 1000000007;

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

		int p = scanner.nextInt();
		int k = scanner.nextInt();

		int i=1;
		long curr = k;

		while (curr != 1){
			i++;
			curr = (curr * k) % MOD;
		}

		long sol = pow(p, (p-1)/i);

		System.out.println(sol);
	}

	private long pow(long base, long exp){
		long sol = 1;

		for (int i=0; i<exp; i++){
			sol = (sol * exp) % MOD;
		}

		return sol;
	}

}


import java.util.*;

public class Solution{
	private static final int MOD = 1000000007;

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

		int p = scanner.nextInt();
		int k = scanner.nextInt();

		if (k <= 1){
			out.println(pow(p, p-1));
			return;
		}

		int i=1;
		long curr = k;

		while (curr != 1){
			i++;
			curr = (curr * k) % p;
		}

		long sol = pow(p, (p-1)/i);

		System.out.println(sol);
	}

	private static long pow(long base, long exp){
		long sol = 1;

		for (int i=0; i<exp; i++){
			sol = (sol * base) % MOD;
		}

		return sol;
	}

}


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

/**
 * Created by chavit on 01.12.2015.
 */
public class B {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        if (!BigInteger.valueOf(n).isProbablePrime()) {
            throw new AssertionError();
        }
        int k = in.nextInt();
        int[] multiplier = new int[n];
        long res = 1, mod = (long)(1e+9+7);
        for (int i = 1; i < n; i++) {
            int pos = i;
            if (multiplier[pos] != 0) {
                continue;
            }
            res = (res * n) % mod;
            while (multiplier[pos] != 1) {
                multiplier[pos] = 1;
                pos = (int)(((long)pos * (long)k) % (long)n);
            }
        }
        System.out.println(res);
    }
}


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

public class Main {

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

		public InputReader() {
			reader = new BufferedReader(new InputStreamReader(System.in), 32765);
			tokenizer = null;
		}

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(System.in), 32765);
			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 char nextChar() {
			return next().charAt(0);
		}

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

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

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

		public int[] nextIntArr(int n) {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = this.nextInt();
			}
			return arr;
		}

		public Integer[] nextIntegerArr(int n) {
			Integer[] arr = new Integer[n];
			for (int i = 0; i < n; i++) {
				arr[i] = new Integer(this.nextInt());
			}
			return arr;
		}

		public int[][] next2DIntArr(int n, int m) {
			int[][] arr = new int[n][m];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					arr[i][j] = this.nextInt();
				}
			}
			return arr;
		}

		public int[] nextSortedIntArr(int n) {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = this.nextInt();
			}
			Arrays.sort(arr);
			return arr;
		}

		public long[] nextLongArr(int n) {
			long[] arr = new long[n];
			for (int i = 0; i < n; i++) {
				arr[i] = this.nextLong();
			}
			return arr;
		}

		public char[] nextCharArr(int n) {
			char[] arr = new char[n];
			for (int i = 0; i < n; i++) {
				arr[i] = this.nextChar();
			}
			return arr;
		}
	}

	public static InputReader scn = new InputReader();
	public static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) throws Exception {
		// InputStream inputStream = System.in; // Useful when taking input other than
		// console eg file handling // check ctor of inputReader
		// To print in file use this:- out = new PrintWriter("destination of file
		// including extension");

		int n = scn.nextInt(), x = 0;
		int[] arr = new int[n];
		for(int i = 0; i < n; i++) {
			arr[i] = scn.nextInt();
		}
		Arrays.sort(arr);
		int g = 0;
		for(int i = 1; i < n; i++) {
			int diff = arr[i] - arr[i - 1];
			g = gcd(g, diff);
		}

		for(int i = 1; i < n; i++) {
			int diff = arr[i] - arr[i - 1];
			x += diff / g - 1;
		}

		System.out.println(x);
	}

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


import java.util.*;
public class Main{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        long l = sc.nextLong();
        long r = sc.nextLong();
        long ans = 0;
        HashSet<Long> set = new HashSet();
        for(long i=0;i<=40;i++)
        {
            for(long j=0;j<=40;j++)
            {
                long p = Math.pow(2,i);
                p*=Math.pow(3,j);
                if(p>=l&&p<=r)
                set.add(j);
            }
        }
        System.out.println(set.size());
    }
}


import sun.tools.jstat.Scale;

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

/**
 * @author Aleksey Koshelev (aleksey.koshelev@inventale.com) 13.04.2018 23:06
 */
public class Main {
    public static void main(String[] args) {
        long l, r;
        long counter = 0;
        Scanner scanner = new Scanner(System.in);

        l = scanner.nextLong();
        r = scanner.nextLong();

        Main main = new Main();
        for (long i = l; i <= r; i++) {
            counter += main.is23(i);
        }

        System.out.println(counter);
    }

    private boolean isSimple(long val){
        BigInteger b  = new BigInteger(String.valueOf(val));
        return b.isProbablePrime(4);
    }

    private ArrayList<Long> getDividers(long val) {
        ArrayList<Long> dividers = new ArrayList<>();
        for (long i = 1; i <= val; i++) {
            if (isSimple(i) && val % i == 0) dividers.add(i);
        }
        return dividers;
    }

    private int is23(long val) {
        ArrayList<Long> dividers = getDividers(val);
        if (val == 1) return 1;
        if (dividers.size() <= 3 && dividers.contains(1L) && (dividers.contains(2L) && dividers.contains(3L)) ||
                (dividers.contains(2L) && dividers.size() == 2) || (dividers.contains(3L) && dividers.size() == 2)) {
            return 1;
        }
        return 0;
    }
}


import java.io.ByteArrayInputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

import live.ZZ;

import static java.lang.Math.*;

/*
 *
 * CFR 667, Div 2
 * https://codeforces.com/contest/1409
 *
 *
 *
 */
public class F_3 {

	public static void main(String[] args) throws Exception {
		new F_3().go();
	}
	static boolean LOCAL = System.getProperty("ONLINE_JUDGE") == null;

	Scanner in;
	//	String INPUT = "15 6\r\n" +
	//			"qwertyhgfdsazxc\r\n" +
	//			"qa";

	String INPUT = "	200 190\r\n" +
			"ghcebcdabheeeaeabfghdbegecabebhbahdhfchabchchbdcbcaebaebdbgebebhdadgegdahh"+
			"daaabehhgghchadfbggbgecahagdfceeffchfddecfgcdbbdhhecfhdfefdbeagcgaedahdebf"+
			"ffhecfcbbcdceghbfcggeaegcdhdchhebffhgchbgacddabcfbcg\r\n" +
			"	ha";

	//	String INPUT = "10 5   \n" +
	//			"qxaxxqxxqx        \n" +
	//			"qa";

	void go() {
		if (LOCAL) {
			System.setIn(new ByteArrayInputStream(INPUT.getBytes()));
		}
		in = new Scanner(System.in);
		long startTime = System.currentTimeMillis();
		solve();
		if (LOCAL) {
			System.out.printf("[%dms]", System.currentTimeMillis()-startTime);
		}
		in.close();
	}

	PrintWriter out = new PrintWriter(System.out);

	void solve() {
		solve2(1);
		out.flush();
	}

	// int inf = (int) 1e9;

	void solve2(int caseNr) {
		int n = in.nextInt();
		int k = in.nextInt();
		String s_str = in.next();
		String t_str = in.next();
		char[] s = s_str.toCharArray();
		char[] t = t_str.toCharArray();

		int[][][] dp = new int[n+1][k+1][n+1];

		for (int i = 0; i < n+1; i++) {
			for (int j = 0; j < k+1; j++) {
				Arrays.fill(dp[i][j], -1);
			}
		}

		dp[0][0][0] = 0;

		for (int i = 0; i < n; i++) {
			for (int ck = 0; ck <= k; ck++) {
				for (int ct0 = 0; ct0 <= n; ct0++) {
					if (dp[i][ck][ct0] == -1) continue;
					int e0 = s[i] == t[0] ? 1 : 0;
					int e1 = s[i] == t[1] ? 1 : 0;
					int e01 = t[0] == t[1] ? 1 : 0;

					dp[i + 1][ck][ct0 + e0] = max(dp[i + 1][ck][ct0 + e0], dp[i][ck][ct0] + (e1==1 ? ct0 : 0));

					if (ck < k) {
						dp[i + 1][ck + 1][ct0 + 1] = max(dp[i + 1][ck + 1][ct0 + 1], dp[i][ck][ct0] + (e01==1 ? ct0 : 0));
						dp[i + 1][ck + 1][ct0 + e01] = max(dp[i + 1][ck + 1][ct0 + e01], dp[i][ck][ct0] + ct0);
					}

				}
			}
		}

		int ans = 0;
		for (int ck = 0; ck <= k; ck++) {
			for (int ct0 = 0; ct0 <= n; ct0++) {
				ans = max(ans, dp[n][ck][ct0]);
			}
		}

		//		System.out.printf("dp[1][0][0] = %d \n", dp[1][0][0]);
		//		System.out.printf("dp[1][0][1] = %d \n", dp[1][0][1]);
		//		System.out.printf("dp[1][1][0] = %d \n", dp[1][1][0]);
		//		System.out.printf("dp[1][1][1] = %d \n", dp[1][1][1]);

		// ZZ.showIntegerArray(dp[0]);

		System.out.println(ans);
	} // end of solve2

}


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

import java.util.*;

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

/* Name of the class has to be "Main" only if the class is public. */
public class Test
{

    public static int maxSubSeq(char s[],char a,char b,int n,int k,int index,int [][][]dp){
        if(k == 0)
        {

            // System.out.println(Arrays.toString(s));
            int ca = 0;

            int ans = 0;
            for(char c: s){
                if(c == a)
                    ca++;
                if(c == b  && ca > 0){
                    ans +=ca;
                }
            }
            return (a == b)?(ca-1)*(ca)/2:ans;
        }
        if(n == 0)
            return 0;
        if(dp[n][k][index] != -1)
            return dp[n][k][index];

        char or = s[n-1];
        s[n-1] = a;
        int ca = maxSubSeq(s, a, b, n-1, k-1,1,dp);
        s[n-1] = b;
        int cb = maxSubSeq(s, a, b, n-1, k-1,2,dp);
        s[n-1] = or;
        int co = maxSubSeq(s, a, b, n-1, k,0,dp);
        return Math.max(Math.max(co, cb),ca);
    }

	public static void main (String[] args) throws Exception {
		//code
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String s[] = in.readLine().split(" ");
        int n = Integer.parseInt(s[0]);
        int k = Integer.parseInt(s[1]);
        String ss = in.readLine();
        String t = in.readLine();
        int dp[][][] = new int[n+1][k+1][3];
        for(int a[][] : dp){
            for(int b[]:a)
                Arrays.fill(b, -1);
        }

        System.out.println(maxSubSeq(ss.toCharArray(), t.charAt(0), t.charAt(1), n, k,0,dp));

    }
}


import java.io.*;
import java.math.*;
import java.util.*;
public class Q6 {
	public static void main(String[] args) {
		/*Pairs of replacements (First letter, Second letter)
		 * Iterate over all pairs:
		 * (0,K)
		 * (1,K-1)
		 * .
		 * .
		 * .
		 * (K-1,1)
		 * (K,0) Take maximum of results
		 *
		 * UPD: Fix how many As you want to keep and Bs you want to keep among originals
		 *
		 * */
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int N = I.nextInt();
		int K = I.nextInt();
		String S = I.next();
		String T = I.next();
		long ans = 0;
		if (T.charAt(0)==T.charAt(1)) {
			long same = 0;
			for (int i = 0; i < N; i++) {
				same+=S.charAt(i)==T.charAt(0)?1:0;
			}
			same+=K;
			same=min(same,N); //Can't have more letters than length...
			ans=same*(same-1)/2;
		}else {
			int first = 0;
			int second = 0;
			for (int i = 0; i < N; i++) {
				first+=S.charAt(i)==T.charAt(0)?1:0;
				second+=S.charAt(i)==T.charAt(1)?1:0;
			}
			for (int A = 0; A<=first; A++) {
				for (int B = 0; B<=second; B++) {
					int max = min(K,N-A-B); //either switch K, or switch all untouched
					for (int a = 0; a <= max; a++) {
						//Second letter = max-a
						boolean[] keep = new boolean[N]; //Which letters we're keeping
						int cntF = 0;
						int cntS = 0;
						char[] UPD = S.toCharArray();//New word constructed (keep original in
						//beginning)
						long pair = B; //Number of second letter in new string
						for (int i = 0; i < N; i++) {
							if (cntF==A) break;
							if (S.charAt(i)==T.charAt(0)) {
								cntF++;
								keep[i]=true;
								UPD[i]=T.charAt(0);
							}
						}
						for (int i = N-1; i>=0; i--) {
							if (cntS==B) break;
							if (S.charAt(i)==T.charAt(1)&&!keep[i]) {
								cntS++;
								keep[i]=true;
								UPD[i]=T.charAt(1);
							}
						}
						int swap = 0;
						for (int i = 0; i < N; i++) {
							if (swap==a) break;
							if (!keep[i]) {
								swap++;
								UPD[i]=T.charAt(0);
								keep[i]=true; //We have touched this up (don't let suffix overlap)
							}
						}
						swap=0;
						for (int i = N-1; i >= 0; i--) {
							if (swap==max-a) break;
							if (!keep[i]) {
								swap++;
								UPD[i]=T.charAt(1);
								keep[i]=true;
								pair++;
							}
						}
						long curans = 0;
						for (int i = 0; i < N; i++) {
							if (UPD[i]==T.charAt(0)) {
								curans+=pair;
							}else if (UPD[i]==T.charAt(1)) pair--;
						}
						ans=max(ans,curans);
					}
				}
			}
		}
		O.pln(ans);
	}
	public static double max(double a, double b) {return Math.max(a, b);}
	public static double min(double a, double b) {return Math.min(a, b);}
	public static long min(long a, long b) {return Math.min(a,b);}
	public static long max(long a, long b) {return Math.max(a,b);}
	public static int min(int a, int b) {return Math.min(a,b);}
	public static int max(int a, int b) {return Math.max(a,b);}
	public static long abs(long x) {return Math.abs(x);}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0)
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return max(a,b);
		return GCD(min(a,b),max(a,b)%min(a,b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
		double nextDouble() {return Double.parseDouble(next());}
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(double x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
		void p(boolean x) {w.print(x);w.flush();}
	}
}


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

public class SolutionF extends Thread {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

    private static final FastReader scanner = new FastReader();
    private static final PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        new Thread(null, new SolutionF(), "Main", 1 << 26).start();
    }

    public void run() {
        int t = 1;
        for (int i = 0; i < t; i++) {
            solve();
        }
        out.close();
    }

    private static void solve() {
        scanner.nextInt();
        int k = scanner.nextInt();
        String s = scanner.next();
        String t = scanner.next();

        System.out.println(dp(s, t, 0, 0, k, new HashMap<>()));
    }

    private static long dp(String s, String t, int index, int amountFirst, int movesLeft, Map<String, Long> memo) {
        if (index == s.length()) {
            return 0;
        }

        String key = index + "-" + amountFirst + "-" + movesLeft;
        if (memo.get(key) != null) {
            return memo.get(key);
        }

        long nothing = dp(s, t, index+1, amountFirst + (s.charAt(index) == t.charAt(0) ? 1 : 0), movesLeft, memo)
                       + (s.charAt(index) == t.charAt(1) ? amountFirst : 0);
        long firstChar = 0;
        long secondChar = 0;

        if (movesLeft > 0) {
            firstChar = dp(s, t, index+1, amountFirst+1, movesLeft-1, memo)
                        + (t.charAt(0) == t.charAt(1) ? amountFirst : 0);
            secondChar = dp(s, t, index+1, amountFirst + (t.charAt(1) == t.charAt(0) ? 1 : 0), movesLeft-1, memo)
                         + amountFirst;
        }
        long result = Math.max(nothing, Math.max(firstChar, secondChar));
        memo.put(key, result);

        return result;
    }
}


import java.io.*;
import java.util.*;
import static java.util.Collections.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class cfa {

    @SuppressWarnings("unused")
    private static final int MOD = (int) (1e9 + 7), MOD_FFT = 998244353;
    private static final Reader r = new Reader();
    private static final PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
    private static final boolean thread = false;
    private static final boolean HAS_TEST_CASES = true;
    private static final int SCAN_LINE_LENGTH = 131074;

    static int n, a[], e[][], vis[];
    private static ArrayList<Integer> adj[], topo;

    static void solve() throws Exception {
        int n = ni(), k = ni(), l = ni();
        a = na(n);
        int p[] = new int[2 * k];
        for (int i = 1; i < p.length; i++) {
            if (i < k)
                p[i] = i % (k);
            else if (i == k)
                p[i] = k;
            else
                p[i] = k - (i % k);
        }

        for (int i = 0; i < p.length; i++) {
            if (rec(p, k, l, i, 0)) {
                pn("YES");
                return;
            }
        }
        pn("NO");
    }

    private static boolean rec(int[] p, int k, int l, int i, int j) {
        if (j == a.length)
            return true;
        if (a[j] + p[i % p.length] > l)
            return false;
        for (int j2 = 0; j2 < p.length; j2++) {
            if (a[j] + p[(i + j2) % p.length] > l)
                break;
            if (rec(p, k, l, i + j2 + 1, j + 1))
                return true;
        }
        return false;
    }

    // static void solve() throws Exception {
    //     n = ni();
    //     a = na(n);
    //     int[] f = new int[34];
    //     for (int i = 0; i < a.length; i++) {
    //         char[] ch = Integer.toBinaryString(a[i]).toCharArray();
    //         for (int j = 0; j < ch.length; j++) {
    //             f[j] += (ch[j] - '0');
    //         }
    //     }
    //     for (int i = 33; i > -1; --i) {
    //         if (f[i] % 2 == 1) {
    //             pn("WIN");
    //         }
    //     }
    // }

    public static void main(final String[] args) throws Exception {
        if (!thread) {
            final int testcases = HAS_TEST_CASES ? ni() : 1;
            for (int i = 1; i <= testcases; i++) {
                // out.print("Case #" + (i + 1) + ": ");
                try {
                    solve();
                } catch (final Exception e) {
                    pni("idk Exception");
                    e.printStackTrace(System.err);
                    System.exit(0);
                }
            }
            out.flush();
            r.close();
            out.close();
        }
    }

    @SuppressWarnings("unused")
    private static void swap(final int i, final int j) {
        final int temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }

    @SuppressWarnings("unused")
    private static int gcd(final int a, final int b) {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }

    @SuppressWarnings("unused")
    private static class Pair<T, E> implements Comparable<Pair<T, E>> {
        T fir;
        E snd;

        Pair() {
        }

        Pair(final T x, final E y) {
            this.fir = x;
            this.snd = y;
        }

        @Override
        @SuppressWarnings("unchecked")
        public int compareTo(final Pair<T, E> o) {
            final int c = ((Comparable<T>) fir).compareTo(o.fir);
            return c != 0 ? c : ((Comparable<E>) snd).compareTo(o.snd);
        }

    }

    @SuppressWarnings("unused")
    private static class pi implements Comparable<pi> {
        int fir, snd;

        pi() {
        }

        pi(final int a, final int b) {
            fir = a;
            snd = b;
        }

        public int compareTo(final pi o) {
            return fir == o.fir ? snd - o.snd : fir - o.fir;
        }

    }

    @SuppressWarnings("unused")
    private static <T> void checkV(final ArrayList<T> adj[], final int i) {
        adj[i] = adj[i] == null ? new ArrayList<>() : adj[i];
    }

    @SuppressWarnings("unused")
    private static <T> void checkV(final Vector<T> adj[], final int i) {
        adj[i] = adj[i] == null ? new Vector<>() : adj[i];
    }

    @SuppressWarnings("unused")
    private static int[] na(final int n) throws Exception {
        final int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = ni();
        }
        return a;
    }

    @SuppressWarnings("unused")
    private static int[] na1(final int n) throws Exception {
        final int[] a = new int[n + 1];
        for (int i = 1; i < a.length; i++) {
            a[i] = ni();
        }
        return a;
    }

    @SuppressWarnings("unused")
    private static String n() throws IOException {
        return r.readToken();
    }

    @SuppressWarnings("unused")
    private static String nln() throws IOException {
        return r.readLine();
    }

    private static int ni() throws IOException {
        return r.nextInt();
    }

    @SuppressWarnings("unused")
    private static long nl() throws IOException {
        return r.nextLong();
    }

    @SuppressWarnings("unused")
    private static double nd() throws IOException {
        return r.nextDouble();
    }

    @SuppressWarnings("unused")
    private static void p(final Object o) {
        out.print(o);
    }

    @SuppressWarnings("unused")
    private static void pn(final Object o) {
        out.println(o);
    }

    @SuppressWarnings("unused")
    private static void pn() {
        out.println("");
    }

    private static void pni(final Object o) {
        out.println(o);
        out.flush();
    }

    private static class Reader {
        private final int BUFFER_SIZE = 1 << 22;
        private final DataInputStream din;
        private final byte[] buffer;
        private int bufferPointer, bytesRead;
        // private StringTokenizer st;

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

        @SuppressWarnings("unused")
        public Reader(final String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        final byte[] buf = new byte[SCAN_LINE_LENGTH];

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

        public String readToken() throws IOException {
            int cnt = 0;
            int c;
            o: while ((c = read()) != -1) {
                if (!(c >= 33 && c <= 126))
                    if (cnt == 0)
                        continue o;
                    else
                        break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            final 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 nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            final 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 double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            final 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;
        }

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

    static {
        if (thread)
            new Thread(null, new Runnable() {
                @Override
                public void run() {
                    try {
                        final int testcases = HAS_TEST_CASES ? ni() : 1;
                        for (int i = 1; i <= testcases; i++) {
                            // out.print("Case #" + (i + 1) + ": ");
                            try {
                                solve();
                            } catch (final Exception e) {
                                e.printStackTrace(System.err);
                                System.exit(-1);
                            }
                        }
                        out.flush();
                        r.close();
                        out.close();
                    } catch (final Throwable t) {
                        t.printStackTrace(System.err);
                        System.exit(-1);
                    }
                }
            }, "rec", (1L << 28)).start();
    }

    @SuppressWarnings({ "unchecked", "unused" })
    private static <T> T deepCopy(final T old) {
        try {
            return (T) deepCopyObject(old);
        } catch (final IOException | ClassNotFoundException e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
        return null;
    }

    private static Object deepCopyObject(final Object oldObj) throws IOException, ClassNotFoundException {
        ObjectOutputStream oos = null;
        ObjectInputStream ois = null;
        try {
            final ByteArrayOutputStream bos = new ByteArrayOutputStream(); // A
            oos = new ObjectOutputStream(bos); // B
            // serialize and pass the object
            oos.writeObject(oldObj); // C
            oos.flush(); // D
            final ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray()); // E
            ois = new ObjectInputStream(bin); // F
            // return the new object
            return ois.readObject(); // G
        } catch (final ClassNotFoundException e) {
            pni("Exception in ObjectCloner = " + e);
            throw (e);
        } finally {
            oos.close();
            ois.close();
        }
    }

}


import java.util.*;
public class b1384 {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int tests = in.nextInt();
        while (tests > 0){
            int depths = in.nextInt();
            int[] dArr = new int[depths + 1];
            int cycle = in.nextInt();
            int limit = in.nextInt();
            int[] cArr = new int[2*cycle];
            int idx = 0;
            for (int i = 0 ; i <= cycle; i++){
                cArr[idx] = i;
                idx++;
            }
            for (int i = 1; i < cycle; i++){
                cArr[idx] = cycle - i;
                idx++;
            }
            dArr[0] = Integer.MIN_VALUE;
            for (int i = 0; i < depths; i++){
                dArr[i + 1] = in.nextInt();
            }
            System.out.println( eval(dArr, cArr, limit, 0, 0, 0) ? "Yes" : "No");
            tests--;
        }
        in.close();
    }
    private static boolean eval(int[] dArr, int[] cArr, int limit, int pos, int time, int stayed){
        if (pos == dArr.length) return true;
        int curPosDepth = dArr[pos] + cArr[time % cArr.length];
        if (curPosDepth > limit) return false;
        boolean swim = eval(dArr, cArr, limit, pos + 1, time + 1, 0);
        if (swim) return true;
        if (stayed < cArr.length){
            boolean stay = eval (dArr, cArr, limit, pos, time + 1, stayed + 1);
            if (stay) return true;
        }
        return false;
    }
}


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

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

    static class TaskA {
        static int[] p = new int[250];
        static int[] d = new int[100];
        static int n;
        static int l;
        static int k;
        static int dist;

        static boolean dfs(int time, boolean[][] vis) {
            dist++;
            if (dist == n + 1) return true;
            for (int i = time + 1; i < 2 * k + time + 1; i++) {
                if (vis[dist][i % (2 * k)]) continue;
                vis[dist][i % (2 * k)] = true;
                if (d[dist] + p[i % (2 * k)] <= l) {
                    if (dfs(i, vis)) return true;
                } else break;
            }
            dist--;
            return false;
        }

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int t = in.nextInt();
            while (t-- > 0) {
                n = in.nextInt();
                k = in.nextInt();
                l = in.nextInt();
                for (int i = 1; i <= n; i++)
                    d[i] = in.nextInt();
                for (int i = 0; i < 2 * k; i++) {
                    if (i < k) p[i] = i;
                    else p[i] = 2 * k - i;
                }
                boolean[][] vis = new boolean[110][220];
                for (int i = 0; i < 2 * k; i++) {
                    dist = 1;
                    if (d[dist] + p[i] <= l) {
                        if (dfs(i, vis)) {
                            out.println("Yes");
                            break;
                        }
                    }
                    if (i == 2 * k - 1) out.println("No");
                }
            }
        }

    }
}


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

public class Beach {
  static class State {
    public final int tide;
    public final int pos;
    public final boolean down;
    public State(int pos, int tide, boolean down) {
      this.tide = tide;
      this.pos = pos;
      this.down = down;
    }

    @Override
    public int hashCode() {
      return Arrays.deepHashCode(new Object[] {pos, tide, down});
    }

    @Override
    public boolean equals(Object other) {
      if (!(other instanceof State)) {
        return false;
      }

      State o = (State)other;
      if (this.tide == o.tide && this.pos == o.pos && this.down == o.down) {
        return true;
      } else {
        return false;
      }

    }
  }

  public static boolean dp(int pos, int tide, boolean down, Set<State> memo, int n, int k, int l, int[] depth) {
    // System.out.println(pos +" " + tide + " " + down);
    State state = new State(pos, tide, down);
    if (memo.contains(state)) {
      return false;
    }

    if (pos > n) {
      return true;
    }

    memo.add(state);

    tide += down ? -1 : +1;
    if (tide == 0) {
      down = false;
    }
    if (tide == k) {
      down = true;
    }

    // stay at current position
    if (depth[pos] + tide <= l && dp(pos, tide, down, memo, n, k, l, depth)) {
      return true;
    }
    if (depth[pos+1] + tide <= l && dp(pos+1, tide, down, memo, n,k,l,depth)) {
      return true;
    }
    return false;
  }
  public static void main(String[] args) throws NumberFormatException, IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int test = Integer.parseInt(br.readLine()); // 3 elements
    while (test-- > 0) {
      String[] s = br.readLine().split(" ");
      int n = Integer.parseInt(s[0]); // length of the shore
      int k = Integer.parseInt(s[1]); // seconds of tide for each wave
      int l = Integer.parseInt(s[2]); // maximum depth Koa can swim

      // depths array
      String[] sd = br.readLine().split(" ");
      int[] depth = new int[n+1];
      for (int i=0; i<n; i++) {
        depth[i+1] = Integer.parseInt(sd[i]);
      }
      depth[0] = -k;
      depth[n] = -k;

      /* main work: use dynamic programming, we use tuple (int pos, int tide, boolean down) represents
      the status of Koa, each time he can transfer to two status, either stay at same position (pos, tide + (int) down, down)
      or swim to next position (pos+1, tide?, down?)
      */
      Set<State> memo = new HashSet<>(); // record unsuccessful results

      if (dp(0, 0, false, memo, n, k, l, depth)) {
        System.out.println("YES");
      } else {
        System.out.println("NO");
      }

    }
    br.close();
  }
}


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

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

	public static long MOD = 1000000007;

	public static void main(String[] args) throws FileNotFoundException {
		// PrintWriter out = new PrintWriter(new FileOutputStream(new File(
		// "output.txt")));
		PrintWriter out = new PrintWriter(System.out);
		Scanner in = new Scanner();
		int n = in.nextInt();
		int[] data = new int[n];
		for (int i = 0; i < n; i++) {
			data[i] = in.nextInt();
		}
		Arrays.sort(data);
		if (n == 1) {
			if (data[0] == 0) {
				out.println("BitAryo");
			} else {
				out.println("BitLGM");
			}
		} else if (n == 2) {
			int[][][] dp = new int[2][data[0] + 1][data[1] + 1];
			for (int[][] a : dp) {
				for (int[] b : a) {
					Arrays.fill(b, -1);
				}
			}
			int r = cal(0, data[0], data[1], dp);
			if (r == 0) {
				out.println("BitLGM");
			} else {
				out.println("BitAryo");
			}
		} else {
			int[][][][] dp = new int[2][data[0] + 1][data[1] + 1][data[2] + 1];
			for (int[][][] a : dp) {
				for (int[][] b : a) {
					for (int[] c : b)
						Arrays.fill(c, -1);
				}
			}
			int r = cal2(0, data[0], data[1], data[2], dp);
			if (r == 0) {
				out.println("BitLGM");
			} else {
				out.println("BitAryo");
			}
		}
		out.close();
	}

	static int cal(int index, int a, int b, int[][][] dp) {
		if (a == 0 && b == 0) {
			return 1 - index;
		}
		if (dp[index][a][b] != -1) {
			return dp[index][a][b];
		}
		int result = 1 - index;
		for (int i = 1; i <= a; i++) {
			int x = Math.min(a - i, b);
			int y = Math.max(a - i, b);
			int v = cal(1 - index, x, y, dp);
			if (v == index) {
				result = index;
				break;
			}
		}
		if (result != index) {
			for (int i = 1; i <= b; i++) {
				int x = Math.min(b - i, a);
				int y = Math.max(b - i, a);
				int v = cal(1 - index, x, y, dp);
				if (v == index) {
					result = index;
					break;
				}
			}
			if (result != index) {
				for (int i = 1; i <= Math.min(a, b); i++) {
					int x = Math.min(b - i, a - i);
					int y = Math.max(b - i, a - i);
					int v = cal(1 - index, x, y, dp);
					if (v == index) {
						result = index;
						break;
					}
				}
			}
		}
		return dp[index][a][b] = result;
	}

	static int cal2(int index, int a, int b, int c, int[][][][] dp) {
		if (a == 0 && b == 0 && c == 0) {
			return 1 - index;
		}
		if (a == 0) {
			if ((b ^ c) == 0)
				return 1 - index;
			return index;
		}
		if (dp[index][a][b][c] != -1) {
			return dp[index][a][b][c];
		}
		int result = 1 - index;
		for (int i = 1; i <= a; i++) {
			int x = a - i;
			int y = b;
			int v = cal2(1 - index, x, y, c, dp);
			if (v == index) {
				result = index;
				break;
			}
		}
		if (result != index) {
			for (int i = 1; i <= b; i++) {
				int x = Math.min(b - i, a);
				int y = Math.max(b - i, a);
				int v = cal2(1 - index, x, y, c, dp);
				if (v == index) {
					result = index;
					break;
				}
			}
			if (result != index) {
				for (int i = 1; i <= c; i++) {
					int x = Math.min(a, c - i);
					int y = Math.max(b, c - i);
					int v = cal2(1 - index, x, a + b + c - i - x - y, y, dp);
					if (v == index) {
						result = index;
						break;
					}
				}
				if (result != index) {
					for (int i = 1; i <= a; i++) {

						int v = cal2(1 - index, a - i, b - i, c - i, dp);
						if (v == index) {
							result = index;
							break;
						}
					}
				}
			}
		}
		return dp[index][a][b][c] = result;
	}

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

	}

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

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

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

	}

	public static class Point implements Comparable<Point> {

		int x, y;

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

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

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

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

	public static class FT {

		long[] data;

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

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

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

		}
	}

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

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

		}
	}

	static class Scanner {

		BufferedReader br;
		StringTokenizer st;

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

		public String next() {

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

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

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

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

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

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


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

public class D173 {
	int INF = Integer.MAX_VALUE / 100;
	static Scanner sc = null;
	static PrintWriter out = null;
	int n = 0;
	long b1 = 1000;
	long b2 = 1000000;
	Map<Long, Boolean> map = new HashMap<Long, Boolean>();
	int cnt = 0;
	public void solve() throws Exception{
		n = sc.nextInt();
		int[] d = new int[3];
		for(int i = 0; i < n; i++){
			d[i] = sc.nextInt();
		}
		Arrays.sort(d);
		int d1, d2, d3;

		d1 = d[0];
		d2 = d[1];
		d3 = d[2];

		map.put((long)0, false);
		if(n == 1){
			if(d[2] == 0){
				System.out.println("BitAryo");
			}
			else{
				System.out.println("BitLGM");
			}
			return;
		}

		else if(n == 2){
			if(check2(d2, d3)){
				System.out.println("BitLGM");
			}
			else{
				System.out.println("BitAryo");
			}
		}
		else{
			if(check3(d1, d2, d3)){
				System.out.println("BitLGM");
			}
			else{
				System.out.println("BitAryo");
			}
		}

	}

	long create(int d1, int d2, int d3){
		long ret = d1 + b1 * d2 + b2 * d3;
		return ret;
	}

	boolean check2(int d1, int d2){
		cnt++;
		long ck = create(d1, d2, 0);
		if(map.containsKey(ck)){
			return map.get(ck);
		}
		if(d1 == 0){
			map.put(ck, true);
			return true;
		}
		if(d1 == d2){
			map.put(ck, true);
			return true;
		}

		for(int i = 1; i < d1; i++){
			if(!check2(d1 - i, d2 - i)){
				map.put(ck, true);
				return true;
			}
		}

		for(int i = 1; i < d1; i++){
			if(!check2(d1 - i, d2)){
				map.put(ck, true);
				return true;
			}
		}
		for(int i = 1; i < d2; i++){
			if(!check2(Math.min(d1, d2 - i), Math.max(d1, d2 - i))){
				map.put(ck, true);
				return true;
			}
		}
		map.put(ck, false);
		return false;
	}

	boolean check3(int d1, int d2, int d3){

		long ck = create(d1, d2, d3);
		if(map.containsKey(ck)){
			return map.get(ck);
		}

		if(d1 == d2 && d2 == d3){
			map.put(ck, true);
			return true;
		}

		if(d1 == 0){

			int k = d2 ^ d3;
			if(k > 0){
				map.put(ck, true);
				return true;
			}
			else{
				map.put(ck, false);
				return false;
			}
		}

		if( (d1 ^ d2) == 0 || (d2 ^ d3) == 0 || (d1 ^ d3) == 0){
			map.put(ck, true);
			return true;
		}

		for(int i = 1; i < d1; i++){
			if(!check3(d1 - i, d2 - i, d3 - i)){
				map.put(ck, true);
				return true;
			}
		}

		for(int i = 1; i < d1; i++){
			if(!check3(d1 - i, d2, d3)){
				map.put(ck, true);
				return true;
			}
		}

		for(int i = 1; i < d2; i++){
			if(!check3(Math.min(d1, d2 - i), Math.max(d1, d2 - i), d3)){
				map.put(ck, true);
				return true;
			}
		}

		for(int i = 1; i < d3; i++){
			int n1 = d1;
			int n2 = d2;
			int n3 = d3 - i;
			if(n3 < n1){
				int t = n3;
				n3 = n2;
				n2 = n1;
				n1 = t;
			}
			else if(n3 < n2){
				int t = n3;
				n3 = n2;
				n2 = t;
			}
			if(!check3(n1, n2, n3)){
				map.put(ck, true);
				return true;
			}
		}

		map.put(ck, false);
		return false;
	}

	/*
	boolean check(int[] c){
		long ck = 0;

		for(int i = 0; i < n; i++){
			ck += Math.pow(b1, i) * c[i];
		}

		if(map.containsKey(ck)){
			return map.get(ck);
		}
		boolean f = false;
		if(c[0] == 0){
			if(n == 2){
				f = true;
			}
			else{
				int k = c[1] ^ c[2];
				if(k > 0){
					map.put(ck, true);
					return true;
				}
			}
		}
		else{
			for(int i = 0; i < n; i++){
				int[] nc = new int[n];
				for(int j = 0; j < n; j++){
					if(i == j){
						nc[j] = 0;
					}
					else{
						nc[j] = c[i];
					}
				}
				Arrays.sort(nc);
				if(!check(nc)){
					map.put(ck, true);
					return true;
				}
			}
			int [] nc = new int[n];
			nc[0] = 0;
			for(int i = 1; i < n; i++){
				nc[i] = c[i] - c[0];
			}
			if(!check(nc)){
				map.put(ck, true);
				return true;
			}
			for(int i = 1; i < c[0]; i++){
				nc = new int[n];
				for(int j = 0; j < n; j++){
					nc[j] = c[j] - i;
				}
				if(!check(nc)){
					map.put(ck, true);
					return true;
				}
			}
			for(int i = 1; i < c[0]; i++){
				nc = Arrays.copyOf(c, n);
				nc[0] -= i;
				if(!check(nc)){
					map.put(ck, true);
					return true;
				}
			}
			for(int i = 1; i < c[1]; i++){
				nc = Arrays.copyOf(c, n);
				nc[1] -= i;
				Arrays.sort(nc);
				if(!check(nc)){
					map.put(ck, true);
					return true;
				}
			}
			if(n == 3){
				for(int i = 1; i < c[2]; i++){
					nc = Arrays.copyOf(c, n);
					nc[2] -= i;
					Arrays.sort(nc);
					if(!check(nc)){
						map.put(ck, true);
						return true;
					}
				}
			}
		}

		map.put(ck, f);
		return f;
	}
	*/
    public int[] readIntArray(int n) {
        int[] ret = new int[n];
        for (int i = 0; i < n; i++) {
            ret[i] = sc.nextInt();
        }
        return ret;
    }

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception{
		File file = new File("input.txt");
		if(file.exists()){
			System.setIn(new BufferedInputStream(new FileInputStream("input.txt")));
		}
		out = new PrintWriter(System.out);
		sc =  new Scanner(System.in);
		D173 t = new D173();
		t.solve();

		/*
		 *
TLE
2
298 184
		 */

	}

}


import java.util.*;

public class D {
	static final String FIRST = "BitLGM";
	static final String SECOND = "BitAryo";
	static class Holder{
		final int [] game;
		final int hash;
        Holder(int [] game){
        	this.game = game.clone();
        	this.hash = Arrays.hashCode(this.game);
        }
        public boolean equals(Object other){
        	if (this == other){
        		return true;
        	}
        	if (!(other instanceof Holder)){
        		return false;
        	}
        	final Holder h = (Holder)other;
        	return Arrays.equals(game, h.game);
        }
        public int hashCode(){
        	return hash;
        }
	}
	static boolean rec(int [] game, Map<Holder, Boolean> memo){
		final Holder key = new Holder(game);
		if (memo.containsKey(key)){
			return memo.get(key);
		}
		for (int i = 0; i < game.length; ++i){
			for (int j = 1; j <= game[i]; ++j){
				final int [] g = game.clone();
				g[i] -= j;
				Arrays.sort(g);
				if (!rec(g, memo)){
					memo.put(key,  true);
					return true;
				}
			}
		}
		for (int i = 1; i <= game[0]; ++i){
			final int [] g = game.clone();
			for (int j = 0; j < game.length; ++j){
				g[j] -= i;
			}
			if (!rec(g, memo)){
				memo.put(key,  true);
				return true;
			}
		}
		memo.put(key, false);
		return false;
	}
	public static void main(String [] args){
		try (Scanner s = new Scanner(System.in)){
			final int n = s.nextInt();
		    final int [] game = new int[n];
		    for (int i = 0; i < n; ++i){
		    	game[i] = s.nextInt();
		    }
		    Arrays.sort(game);
		    final boolean win = rec(game, new HashMap<Holder, Boolean>());
		    System.out.println((win ? FIRST : SECOND));
		}
	}
}


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

public class Main {

	public static void main(String[] args) throws Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int t,ca,i,j,k,l;
		String[] my;
		String line = br.readLine();
        int n,x,y,z;
        n = Integer.parseInt(line);
        String  win = "BitLGM";
         line = br.readLine();
        if(n==1)
        {

           x = Integer.parseInt(line);
           if(x==0)win = "BitAryo";

        }
        else if(n==2)
        {
            my = line.split(" ");
            x= Integer.parseInt(my[0]);
            y = Integer.parseInt(my[1]);
            int[][]a = new int[302][302];
            for(i=0;i<301;i++)
            for(j=0;j<301;j++)
            if(a[i][j]==0)
            {
                for(l = 1;i+l<301;l++)a[i+l][j] = 1;
                 for(l = 1;j+l<301;l++)a[i][j+l] = 1;
                 for(l=1;i+l<301 && j+l<301;l++)a[i+l][j+l] = 1;
            }
            if(a[x][y]==0)win = "BitAryo";
        }
        else {
              my = line.split(" ");
            x= Integer.parseInt(my[0]);
            y = Integer.parseInt(my[1]);
            z = Integer.parseInt(my[2]);
             int[][][]a = new int[302][302][302];
            for(i=0;i<301;i++)
            for(j=0;j<301;j++)
            for(k=0;k<301;k++)
            if(a[i][j][k]==0)
            {
              //  System.out.println(i+ " " + j + " " + k + " is loosing");
                for(l = 1;i+l<301;l++)a[i+l][j][k] = 1;
                 for(l = 1;j+l<301;l++)a[i][j+l][k] = 1;
                  for(l = 1;k+l<301;l++)a[i][j][k+l] = 1;
                 for(l=1;i+l<301 && j+l<301 && k+l<301;l++)a[i+l][j+l][k+l] = 1;
            }
            if(a[x][y][z]==0)win = "BitAryo";
        }
        System.out.println(win);

        }

}


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

import javax.swing.SwingConstants;

public class MainA {
	private static InputStream stream;
	private static byte[] buf = new byte[1024];
	private static int curChar;
	private static int numChars;
	private static SpaceCharFilter filter;
	private static PrintWriter pw;
	//private static long mod = 1000000000 + 7;
	static long count=0;
	static int flag=-1;
	static int d[];
	static int ans[][];
	static int d2[];
	static int ans2[][];
	public static int[] dfs( int v, int vis[], ArrayList<Integer> arr[],int k ,int r[])
	{
		vis[v]=1;
		for(int i=0;i<k;i++)ans[v][i]=d[i]+1;
		ans[v][r[v]]=0;
		for(int i=0;i<arr[v].size();i++)
		{
			int x=arr[v].get(i);

			if(vis[x]==0)
			{

				int a[]=dfs(x,vis,arr,k,r);
				for(int j=0;j<k;j++)
				{
					ans[v][j]=Math.min(ans[v][j],a[j]+1);
				}
				d=ans[v];
			}
		}
		return ans[v];
	}

	public static int[] dfs2( int v, int vis[], ArrayList<Integer> arr[],int k ,int r[])
	{
		vis[v]=1;
		for(int i=0;i<k;i++)ans2[v][i]=d2[i]+1;
		ans2[v][r[v]]=0;
		for(int i=arr[v].size()-1;i>=0;i--)
		{
			int x=arr[v].get(i);

			if(vis[x]==0)
			{

				int a[]=dfs(x,vis,arr,k,r);
				for(int j=0;j<k;j++)
				{
					ans2[v][j]=Math.min(ans2[v][j],a[j]+1);
				}
				d2=ans2[v];
			}
		}
		return ans2[v];
	}

	static int MAXN=101;
	public static class Node
	{
		long val;
		Node left,right;
		Node()
		{

		}
		Node(Node l,Node r,int v)
		{
			left=l;right=r;val=v;
		}
	}

	public static int cost[];
	public static Node version[];

	public static void build(Node n,int low,int high)
	{
	    if (low==high)
	    {
	        n.val = cost[low];
	        //pw.println(cost[low]+" "+low);
	        return;
	    }
	    int mid = (low+high) / 2;
	    n.left = new Node(null,null, 0);
	    n.right = new Node(null,null, 0);
	    build(n.left, low, mid);
	    build(n.right, mid+1, high);
	    n.val = n.left.val + n.right.val;
	}

	public static void upgrade(Node prev, Node cur, int low, int high,
	                                   int idx, long value)
	{
	    if (idx > high || idx < low || low > high)
	        return;

	    if (low == high)
	    {
	        cur.val = prev.val+value;
	        return;
	    }
	    int mid = (low+high) / 2;
	    if (idx <= mid)
	    {
	        cur.right = prev.right;
	        cur.left = new Node(null, null, 0);
	        upgrade(prev.left,cur.left, low, mid, idx, value);
	    }
	    else
	    {
	        cur.left = prev.left;
	        cur.right = new Node(null, null, 0);
	        upgrade(prev.right, cur.right, mid+1, high, idx, value);
	    }
	    cur.val = cur.left.val + cur.right.val;
	}

	public static long query(Node n, int low, int high, int l, int r)
	{
	    if (l > high || r < low || low > high)
	       return 0;
	    if (l <= low && high <= r)
	       return n.val;
	    int mid = (low+high) / 2;
	    long p1 = query(n.left,low,mid,l,r);
	    long p2 = query(n.right,mid+1,high,l,r);
	   // pw.println(p1+" "+p2+" "+low+" "+high );
	    return p1+p2;
	}

	public static int time=0;
	public static void dfs(int x,int vis[],ArrayList<Integer> arr[],int in[],int out[])
	{
		vis[x]=1;
		in[x]=time++;
		for(int i=0;i<arr[x].size();i++)
		{
			int y=arr[x].get(i);
			if(vis[y]==0)
			{
				dfs(y,vis,arr,in, out);
			}
		}
		out[x]=time-1;
	}
	public static boolean equa(char c)
	{
		if(c=='f' ||c=='r' ||c=='i' ||c=='e' ||c=='z' ||c=='a')return true;
		return false;
	}

	public static long shortestPath(int v,int n,int k, ArrayList<Pairs> arr[])
	{
		PriorityQueue<Pair> q=new PriorityQueue();
		q.add(new Pair(0,0));
		long dist[]=new long[n];
		boolean vis[]=new boolean[n];
		Arrays.fill(dist,Long.MAX_VALUE);
		dist[v]=0;
		//pw.println(k);

		while(!q.isEmpty())
		{

			Pair top=q.poll();

			//pw.println(pp.x+" "+pp.y+" "+pp.w);
			if(vis[top.x])
			{
				continue;
			}
			pw.println(top.x +" "+dist[top.x]);
			vis[top.x]=true;
			for(int i=0;i<arr[top.x].size();i++)
			{
				Pairs p=arr[top.x].get(i);
				int xd=p.x;
				//pw.println(i+" "+xd+" "+yd);
				if(!vis[xd])
				{
					long di=0;
					long div=(dist[top.x]/k)%2;
					if(div==1 )
					{
						di=k-dist[top.x]%k;
					}
					long dis=di+dist[top.x]+p.y;;
					if(dis< dist[xd])
					{
						dist[xd]=dis;
						q.add(new Pair(dist[xd],xd));
					}
				}
			}

		}
		//for(int i=0;i<ans.size();i++)pw.println(ans.get(i)+" "+dist[ans.get(i)]);

		return dist[n-1];
	}
	public static int vis[][];
	public static long dist[][];
	static int dx[]= {-1,0,1,0};
	static int dy[]= {0,1,0,-1};
	public static void zeroOnebfs(int n,int m, int x1,int y1,int x2,int y2)
	{
		Deque<Pairs> q=new LinkedList<Pairs>();
		q.addFirst(new Pairs(x1,y1));
		for(int i=0;i<n;i++)
		{
			Arrays.fill(dist[i],Long.MAX_VALUE);
		}
		dist[x1][y1]=0;

		while(!q.isEmpty())
		{
			Pairs pp=q.pop();
			for(int i=0;i<4;i++)
			{
				int xd=pp.x+dx[i];
				int yd=pp.y+dy[i];
				//pw.println(i+" "+xd+" "+yd);
				if((xd>=0 && yd>=0 && xd<n && yd <m)&& vis[xd][yd]!=Integer.MAX_VALUE)
				{
					long di=vis[xd][yd];
					long dis=di+dist[pp.x][pp.y];
					if(dis< dist[xd][yd])
					{
						dist[xd][yd]=dis;
						if(di==1)
							q.addLast(new Pairs(xd,yd));
						else
							q.addFirst(new Pairs(xd,yd));
					}
				}
			}

		}

	}

	public static class Pairs
	{
		int x,y;

		Pairs(int u,int v)
		{
			x=u;y=v;
		}

	}
	public static String s[];

	static int bc=0;
	public static int sum(int n)
	{
		if(n==0)
		{
			bc=bc+1;
			return bc;
		}
		int r=sum(n-1);
		return r+(++bc);
	}
	 public static int f(int time,int c,int arr[])
	    {
	        int count=0;int i=0;int temp=0;
	        while(i<arr.length)
	        {
	            if(c*arr[i]>time)return Integer.MAX_VALUE;
	            temp+=c*arr[i];
	            if(temp>time)
	            {
	               temp=c*arr[i];
	               count++;
	            }
	            i++;
	        }
	        if(temp>0)count++;
	        return count;
	    }
	public static int paint(int A, int B, int C[]) {

	       int low=0;int high=(int)100;int mid;int r=-1;
	       while(low<=high)
	       {
	            mid=(low+high)/2;
	            //pw.println(low+" "+high);
	           if(f(mid,B,C)<=A)
	           {
	        	   r=mid;
	               high=mid-1;
	           }
	           else
	           {
	               low=mid+1;
	           }
	       }
	       return (r%(10000003));
	    }

	   static ArrayList<ArrayList<Integer>> arr=new ArrayList<ArrayList<Integer>>();
	    public static ArrayList<ArrayList<Integer>> combine(int A, int B) {
	        co(A,B,0,1,new ArrayList<Integer>());
	        pw.println(arr.get(0).size());
	        for(int i=0;i<arr.size();i++)
	        {
	        	for(int j=0;j<arr.get(i).size();j++)
	        	{
	        		pw.print(arr.get(i).get(j));
	        	}
	        }
	        return arr;

	    }

	    public static void co(int n,int k,int pos,int cur,ArrayList<Integer> ar)
	    {
	        if(pos==k)
	        {
	        	for(int i=0;i<ar.size();i++)
	        	{
	        		pw.print(ar.get(i)+" ");
	        	}
	        	pw.println();
	            arr.add(ar);
	            return;
	        }
	        if(cur==n+1)
	        {
	            return;
	        }
	        ar.add(cur);
	        co(n,k,pos+1,cur+1,ar);
	        ar.remove((Integer)cur);
	        co(n,k,pos,cur+1,ar);
	    }

	private static void soln()
	{

		String s[]=new String[2];
		 s[0]=nextLine();
		 s[1]=nextLine();

		if(s[1].length()<2)
		{
			pw.println(0);return;
		}
		int len=s[1].length();
		int dp[][]=new int[len+1][5];int ans=0;
		for(int i=1;i<=len;i++)
		{
			if(i<=2)
			{
				int max=0;
				dp[i][0]=max;
				char c1=s[0].charAt(i-1);char c2=s[1].charAt(i-1);char c3=s[0].charAt(i);char c4=s[1].charAt(i);
				if(fu(c1,c2,c4))
				dp[i][1]=max+1;
				if(fu(c1,c2,c3))dp[i][2]=max+1;
				if(fu(c2,c3,c4))dp[i][3]=Math.max(max, dp[i-1][2])+1;
				if(fu(c1,c3,c4))dp[i][4]=Math.max(max,dp[i-1][1])+1;
			}
			else if(i==len)
			{
				int a=dp[i-1][1];int b=dp[i-1][2];int c=dp[i-1][3];int d=dp[i-1][4];int e=dp[i-1][0];
				int max1=Math.max(a, b);int max2=Math.max(c, d);int max3=Math.max(max1, e); ans=Math.max(max3, max2);
			}
			else
			{
				int a=dp[i-2][1];int b=dp[i-2][2];int c=dp[i-2][3];int d=dp[i-2][4];int e=dp[i-1][0];
				int max1=Math.max(a, b);int max2=Math.max(c, d);int max3=Math.max(max1, e);int max=Math.max(max3, max2);
				dp[i][0]=max;
				char c1=s[0].charAt(i-1);char c2=s[1].charAt(i-1);char c3=s[0].charAt(i);char c4=s[1].charAt(i);
				if(fu(c1,c2,c4))
				dp[i][1]=max+1;
				if(fu(c1,c2,c3))dp[i][2]=max+1;
				if(fu(c2,c3,c4))dp[i][3]=Math.max(max, dp[i-1][2])+1;
				if(fu(c1,c3,c4))dp[i][4]=Math.max(max,dp[i-1][1])+1;
			}
		}

		pw.println(ans);

	}

		public static boolean fu(char a,char b,char c)
		{
			if(a=='0' && b=='0' && c=='0')return true;
			return false;
		}
	    static ArrayList<String> answ=new ArrayList<String>();
	    public static ArrayList<String> generateParenthesis(int A) {
	        String res="";
	        pw.println("ji");
	        genP(0,0,A,res);
	        return answ;
	    }

	    public static void genP(int i,int j,int n,String res)
	    {
	        if(i==n)
	        {
	            if(j<n)
	            {
	                genP(i,j+1,n,res+")");
	            }
	            if(j==n)
	            {
	            	pw.println("hi");
	            	pw.println(res);
	            	answ.add(res);
	            }
	        }
	        else if(i==j)
	        {
	        	pw.println("hi2");
	            genP(i+1,j,n,res+"(");
	        }
	        else if(i>j)
	        {
	            //ar.add('(');
	            genP(i+1,j,n,res+"(");
	            //ar.remove((Character)'(');
	            //ar.add(')');
	            genP(i,j+1,n,res+")");
	            // ar.remove((Character)')');
	        }
	    }

	        public static ArrayList<String> generateParenthesis2(int A) {
	            genP(0,0,A,new ArrayList<Character>());
	            return answ;
	        }

	        public static void genP(int i,int j,int n,ArrayList<Character> ar)
	        {
	            if(i==n)
	            {
	            	if(j<n)
		            {
	            		ar.add(')');
	 	                genP(i,j+1,n,ar);
	 	                ar.remove((Character)')');
		            }
		            if(j==n)
		            {
		            	//pw.println("hi");
		            	String res="";
		            	for(int k=0;k<ar.size();k++)
		            	{
		            		res=res+ar.get(k);
		            	}
		            	//pw.println(res);
		            	answ.add(res);
		            }

	            }
	            else if(i==j)
	            {
	                ar.add('(');
	                genP(i+1,j,n,ar);
	                ar.remove((Character)'(');
	            }
	            else if(i>j)
	            {
	                ar.add('(');
	                genP(i+1,j,n,ar);
	                ar.remove((Character)'(');
	                //pw.println(i+" "+j);
	                if(i==2 && j==1)
	                {
	                	for(int k=0;k<ar.size();k++)pw.print(ar.get(k));
	                	pw.println();
	                }
	                ar.add(')');
	                genP(i,j+1,n,ar);
	                ar.remove((Character)')');
	            }
	        }

	static long d1, x, y;
	public static void extendedEuclid(long A, long B) {
	    if(B == 0) {
	        d1 = A;
	        x = 1;
	        y = 0;
	    }
	    else {
	        extendedEuclid(B, A%B);
	        long temp = x;
	        x = y;
	        y = temp - (A/B)*y;
	    }
	}
	public static long modInverse(long A, long M)
	{
	    extendedEuclid(A,M);
	    return (x%M+M)%M;    //x may be negative
	}
	private static long powe(long x1, long y1,long p) {
		long res = 1;

        // Update x if it is more
        // than or equal to p
        x1 = x1 % p;

        while (y1 > 0)
        {
            // If y is odd, multiply x
            // with result
            if((y1 & 1)==1)
                res = (res * x1) % p;

            // y must be even now
            // y = y / 2
            y1 = y1 >> 1;
            x1 = (x1 * x1) % p;
        }
        return res;
	}
	public static int biSearch(long div[],long n)
	{
		int low=0;int high=div.length-1;int res=-1;
		while(low<=high)
		{
			int mid=(low+high)/2;
			if(div[mid]<n)
			{
				res=mid;
				low=mid+1;
			}
			else high=mid-1;
		}
		return res;
	}
	public static void sieve(int prime[],int k,long co[],ArrayList<Integer> arr,long mod)
	{
		for(int i=0;i<=k;i++)prime[i]=i;

		for(int i=2;i*i<=k;i++)
		{
			if(prime[i]==i)
			{

				for(int j=2*i;j<=k;j+=i)
				{
					prime[j]=i;
				}
			}
		}
		for(int i=2;i<=k;i++)if(prime[i]==i)arr.add(prime[i]);
		co[1]=1;
		for(int i=2;i<=k;i++)
		{
			int key=i;int prev=0;co[i]=i;
			while(key>1)
			{
				int p=prime[key];
				key/=p;
				if(prev!=p)
				{
					co[i]=(co[i]*(p-1));
					co[i]=(co[i]/p);
				}
				prev=p;
			}
			co[i]=(co[i]*i)/2;
			co[i]=(co[i]%mod);
			//pw.println(i+" "+co[i]);
//			335337501
//			958499634
//			29518260
//			279765089
//			999998607
		}

	}

	public static double dist(int x, int y,int a[], int b[])
	{
		return Math.sqrt(Math.pow(a[x]-a[y],2)+Math.pow(b[x]- b[y],2));
	}
	public static double bSearch(int a[],int b[],int n,long p)
	{
		double l=0;double r=(double)1e15;
		for(int i=0;i<200;i++)
		{
			double mid=(l+r)/2;
			//pw.printf("%f ",mid);
			if(f(mid,a,b,p,n))
			{
				l=mid;

				//pw.printf(" %f", l);
			}
			else r=mid;
			//pw.println();
		}
		return l;
	}

	public static boolean f(double t,int a[],int b[],long p,int n)
	{
		double totalCons=0;
		for(int i=0;i<n;i++)
		{
			double total=a[i]*t-b[i];
			//pw.printf("%f\n", total);
			if(total>0)
			{
				totalCons+=total;
			}
		}
		//pw.printf("%f %f\n",totalCons,p*t);
		if(totalCons<=p*t)return true;
		else return false;
	}
	public static int check(String s[],int x, int y,int n,int m)
	{
		int dx[]= {-1,0,1,1,1,0,-1,-1};
		int dy[]= {-1,-1,-1,0,1,1,1,0};
		int count=0;
		for(int i=0;i<8;i++)
		{
			int vx=x+dx[i];
			int vy=y+dy[i];
			if(vx<0 || vx>=n ||vy<0 || vy>=m)
			{

			}
			else
			{
				if(s[vx].charAt(vy)=='*')count++;
			}
		}
		return count;
	}

	public static class Pair implements Comparable<Pair>
	{
		long val;
		int x;
		Pair(long a,int b)
		{
			val=a;x=b;
		}

		@Override
		public int compareTo(Pair o)
		{

			return Long.compare(val,o.val);
		}
	}
	public static class Segment {
		private int[] tree;
		private boolean[] lazy;
		private int size;
		private int n;

		private class node {
			private int a;
			private int b;
			private int c;

			public node(int x, int y, int z) {
				a = x;
				b = y;
				c = z;
			}
		}

		public Segment(int n) {
			//this.base=arr;
			int x = (int) (Math.ceil(Math.log(n) / Math.log(2)));
			size = 2 * (int) Math.pow(2, x) - 1;
			tree = new int[size];
			lazy = new boolean[size];
			this.n = n;
			build(0, 0, n - 1);
		}

		public void build(int id, int l, int r) {
			if (l == r) {
				return;
			}
			int mid = (l + r) / 2;
			build(2 * id + 1, l, mid);
			build(2 * id + 2, mid + 1, r);
			tree[id] = tree[2 * id + 1] + tree[2 * id + 2];
		}

		public int query(int l, int r) {
			return queryUtil(l, r, 0, 0, n - 1);
		}

		private int queryUtil(int x, int y, int id, int l, int r) {
			if (l > y || x > r)
				return 0;
			if (x <= l && r <= y) {
				//if(!lazy[id])
				return tree[id];
				//else
				//	return tree[id][0];
			}
			int mid = l + (r - l) / 2;
			shift(id);
			return queryUtil(x, y, 2 * id + 1, l, mid) + queryUtil(x, y, 2 * id + 2, mid + 1, r);
		}

		public void update(int x, int y, int colour, int id, int l, int r) {
			//System.out.println(l+" "+r+" "+x);
			if (x > r || y < l)
				return;
			if (x <= l && r <= y) {

				return;
			}
			int mid = l + (r - l) / 2;
			shift(id);
			update(x, y, colour, 2 * id + 1, l, mid);
			update(x, y, colour, 2 * id + 2, mid + 1, r);
			tree[id] = tree[2 * id + 1] + tree[2 * id + 2];
		}

		public void shift(int id) {

		}
	}

	public static void fft(double[] a, double[] b, boolean invert) {
		int count = a.length;
		for (int i = 1, j = 0; i < count; i++) {
			int bit = count >> 1;
			for (; j >= bit; bit >>= 1)
				j -= bit;
			j += bit;
			if (i < j) {
				double temp = a[i];
				a[i] = a[j];
				a[j] = temp;
				temp = b[i];
				b[i] = b[j];
				b[j] = temp;
			}
		}
		for (int len = 2; len <= count; len <<= 1) {
			int halfLen = len >> 1;
			double angle = 2 * Math.PI / len;
			if (invert)
				angle = -angle;
			double wLenA = Math.cos(angle), wLenB = Math.sin(angle);
			for (int i = 0; i < count; i += len) {
				double wA = 1, wB = 0;
				for (int j = 0; j < halfLen; j++) {
					double uA = a[i + j], uB = b[i + j];
					double vA = a[i + j + halfLen] * wA - b[i + j + halfLen] * wB;
					double vB = a[i + j + halfLen] * wB + b[i + j + halfLen] * wA;
					a[i + j] = uA + vA;
					b[i + j] = uB + vB;
					a[i + j + halfLen] = uA - vA;
					b[i + j + halfLen] = uB - vB;
					double nextWA = wA * wLenA - wB * wLenB;
					wB = wA * wLenB + wB * wLenA;
					wA = nextWA;
				}
			}
		}
		if (invert) {
			for (int i = 0; i < count; i++) {
				a[i] /= count;
				b[i] /= count;
			}
		}
	}

	static void multiply(long[][] a, long[][] b, long m) {
		int n = a.length;
		long[][] mul = new long[n][n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				mul[i][j] = 0;
				for (int k = 0; k < n; k++)
					mul[i][j] = (mul[i][j] + (a[i][k] * b[k][j]) % m) % m;
			}
		}
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				a[i][j] = mul[i][j];
	}

	private static long pow(long a, long b, long c) {
		if (b == 0)
			return 1;
		long p = pow(a, b / 2, c);
		p = (p * p) % c;
		return (b % 2 == 0) ? p : (a * p) % c;
	}

	private static long gcd(long n, long l) {
		if (l == 0)
			return n;
		return gcd(l, n % l);
	}

	public static void main(String[] args) throws Exception {
		//		new Thread(null, new Runnable()
		//		{
		//			@Override
		//			public void run()
		//			{
		//				/*try {
		//					InputReader(new FileInputStream("C:\\Users\\hardik\\Desktop\\B-large-practice.in"));
		//				} catch (FileNotFoundException e) { // TODO Auto-generated catch block
		//					e.printStackTrace();
		//				} */
		//				InputReader(System.in);
		//				pw = new PrintWriter(System.out);
		//				/*try {
		//					pw=new PrintWriter(new FileOutputStream("C:\\Users\\hardik\\Desktop\\out.txt"));
		//				} catch (FileNotFoundException e) { // TODO Auto-generated catch block
		//					e.printStackTrace();
		//				}*/
		//				soln();
		//				pw.close();
		//			}
		//		}, "1", 1 << 26).start();

		/*try {
			InputReader(new FileInputStream("C:\\Users\\hardik\\Desktop\\B-large-practice.in"));
		} catch (FileNotFoundException e) { // TODO Auto-generated catch block
			e.printStackTrace();
		} */
		InputReader(System.in);
		pw = new PrintWriter(System.out);
		/*try {
			pw=new PrintWriter(new FileOutputStream("C:\\Users\\hardik\\Desktop\\out.txt"));
		} catch (FileNotFoundException e) { // TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		soln();
		pw.close();
	}

	public static void InputReader(InputStream stream1) {
		stream = stream1;
	}

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

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

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

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

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

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

	private static String nextLine() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isEndOfLine(c));
		return res.toString();
	}

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

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

	private static void pArray(int[] arr) {
		for (int i = 0; i < arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static void pArray(long[] arr) {
		for (int i = 0; i < arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

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

	private static char nextChar() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		char c1 = (char) c;
		while (!isSpaceChar(c))
			c = read();
		return c1;
	}

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


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

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

		String R1 = in.nextLine();
		in.nextLine();
		String R2 = in.nextLine();

		int emptyS = 0, length = R1.length(), bishwock=0;
		int c1=0, c2=1;

		boolean[] visited1 = new boolean[length];
		boolean[] visited2 = new boolean[length];

		for(int i=0;i<length;i++)
		{
			visited1[i] = false;
			visited2[i] = false;
		}

		while(c2<length)
		{
			if(R1.charAt(c1)=='0' && !visited1[c1])
			{
				emptyS++;
				visited1[c1] = true;
			}
			if(R1.charAt(c2)=='0' && !visited1[c2])
			{
				emptyS++;
				visited1[c2] = true;
			}
			if(R2.charAt(c1)=='0' && !visited2[c1])
			{
				emptyS++;
				visited2[c1] = true;
			}
			if(R2.charAt(c2)=='0' && !visited2[c2])
			{
				emptyS++;
				visited2[c2] = true;
			}

			if(emptyS==4)
			{
				visited2[c2] = false;
				bishwock++;
				c1 += 1;
				c2 += 1;
			}

			if(emptyS==3)
			{
				bishwock++;
				c1 += 2;
				c2 += 2;
			}

			if(emptyS==2)
			{
				if(R1.charAt(c2)=='0')
					visited1[c2] = false;
				if(R2.charAt(c2)=='0')
					visited2[c2] = false;
				c1 += 1;
				c2 += 1;
			}

			if(emptyS==1)
			{
				if(R1.charAt(c2)=='0')
					visited1[c2] = false;
				if(R2.charAt(c2)=='0')
					visited2[c2] = false;
				c1 += 1;
				c2 += 1;
			}

			if(emptyS==0)
			{
				c1 += 2;
				c2 += 2;
			}

			emptyS = 0;
		}

		System.out.println(bishwock);
	}

}