import java.util.Scanner;
public class prob59A{
    public static void main (String[] args){
      Scanner s=new Scanner(System.in);
      //System.out.println("enter word?");
      String x = s.next();
      toupperorlower(x);
    }
    public static void toupperorlower(String word) {
        char ch[] = new char[word.length()];
        String z = word.toLowerCase();
        char x[] = new char[word.length()];
        for (int i = 0; i < ch.length; i++) {
            ch[i] = word.charAt(i);
        }
        for (int i = 0; i < ch.length; i++) {
            x[i] = z.charAt(i);
        }
        int lower = 0;
        int upper = 0;
        for (int i = 0; i < ch.length; i++) {
            if (x[i] == ch[i]) {
                lower++;
            }
            if (x[i] != ch[i]) {
                upper++;
            }

        }
        if (upper > lower) {
            System.out.println(word.toUpperCase());
        }
        if (lower >= upper) {
            System.out.println(word.toLowerCase());
        }

    }
}


import java.util.*;
import java.math.BigInteger;
import java.util.Arrays;
import java.text.DecimalFormat;
import java.lang.ArrayIndexOutOfBoundsException;
import java.lang.Exception;
import java.lang.ArithmeticException;
import java.lang.InterruptedException;
import java.lang.NullPointerException;
public class Test{
	 static Scanner s = new Scanner(System.in);
	 static int _I(){int x=s.nextInt(); return x;}
	 static long _ll(){long l=s.nextLong(); return l;}
	 static double _d(){double x=s.nextDouble(); return x;}
	 static String _S(){String str=s.nextLine(); return str;}
	 static int gcd(int x,int y){return y==0 ? x:gcd(y,x%y);}
	 static int lcm(int x,int y){return x*y;}
	 long ar[]=new long[100000];

	public static void solve(){
		DecimalFormat d= new DecimalFormat("00");
		String str=Test._S();
		int t=Test._I();
		String ss[]=str.split(":");
		Integer hh=Integer.parseInt(ss[0]);
		Integer mm=Integer.parseInt(ss[1]);
		mm=mm+t;
		if(mm>=60){
			hh=hh+mm/60;
			mm=mm%60;
			if(hh>23){
				hh=hh%24;
			}
		}
		System.out.println(d.format(hh)+":"+d.format(mm));
	}
	public static void main_field(){

		Test.solve();
	}
	public static void main(String[] args){
		Test t = new Test();
		Test.main_field();

	}
}


import java.util.Scanner;

public class Main {

    static long  xo=0,yo=0, GCD=0;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long  n = sc.nextLong();
        long  p = sc.nextLong();
        long  w = sc.nextLong();
        long  d = sc.nextLong();
        long  x, y,z;

        long  g = GCD(w,d);

        if(p%g!=0){
            System.out.println("-1");
            return;
        }

        if(n*w<p){
            // this is when he won all matches but
            // points are not equal to p
            System.out.println("-1");
            return;
        }

        p/=g;
        w/=g;
        d/=g;

        y = ((p%w) * inverseModulo(d,w))%w;
        x = (p-y*d)/w;
        if(x+y>n){
            //if number of wins and  draw is greater than total number of matches
            System.out.println("-1");
            return;
        }

        if(x<0){
            System.out.println("-1");
            return;
        }

        z = n-(x+y);
        System.out.println(x+" "+y+" "+z);

    }

    private static long inverseModulo(long a, long  m) {
        if(m==1)return 0;
        long  m0 =m,x =1,y=0;

        while(a>1){
            long  q = a/m , t =m;
            m = a%m; a=t;
            t =y;
            y = x - q * y;
            x =t;

        }

        if(x<0) x+=m0;
        return x;

    }

    private static void ExtendedEuclid(long  a, long  b){
        //base case

        if (b == 0) {

            xo =1;
            yo=0;
            GCD = a;
            return;
        }

        ExtendedEuclid(b,a%b);

        long  cX = yo;
        long  cy = xo - (a/b)*yo;

        xo = cX;
        yo = cy;
    }

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


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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int doors = sc.nextInt();
		int floors = sc.nextInt();
		int flats = sc.nextInt();
		int from =  sc.nextInt();
		int to =  sc.nextInt();

		int from_flat = (from - 1)% flats;
		int from_floor =
				((from - from_flat - 1)% (floors*flats))/flats ;

		int from_door = (from - from_floor * flats -from_flat - 1) /
				(floors*flats);

		int to_flat = (to - 1)% flats;
		int to_floor =
				((to - to_flat - 1)% (floors*flats))/flats ;

		int to_door = (to - to_floor * flats - to_flat - 1) /
				(floors*flats);

		int time = 0;
		if(to_door == from_door){
			time += Math.min(Math.abs(to_floor - from_floor) * 5,
					10 +  Math.abs(to_floor - from_floor));
			//System.out.println(time);
		} else {
			time += Math.min(Math.abs(from_floor - 0) * 5,
					10 +  Math.abs(from_floor - 0));
			//System.out.println(time);
			time += 15 * Math.min(doors - Math.abs(to_door - from_door),
					Math.abs(to_door - from_door));
			//System.out.println(time);
			time += Math.min(Math.abs(to_floor - 0) * 5,
					10 +  Math.abs(to_floor - 0));
			//System.out.println(time);
		}
		System.out.println(time);
	}
}


import java.util.*;

public class CODE {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        int arr[] = new int[2 * n];
        int count = 0;
        HashSet<Integer> set = new HashSet<>();

        for (int i = 0; i < 2 * n; i++) {
            arr[i] = sc.nextInt();
            set.add(arr[i]);
        }

        for (int i = 0; i < 2 * n; i++) {
            for (int j = i; j < 2 * n; j++) {
                if (set.contains(arr[i] ^ arr[j])) {
                    count++;
                    if (arr[i] != arr[j]) {
                        count++;
                    }
                }
            }
        }

        System.out.println(count % 2 == 0 ? "Karen" : "Koyomi");
    }
}


import java.io.*;
import java.util.*;
import java.util.regex.*;
public class vk18
{
    public static void main(String[]stp) throws Exception
    {
    	Scanner scan=new Scanner(System.in);
    	PrintWriter pw = new PrintWriter(System.out);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer(br.readLine());
        long n=Long.parseLong(st.nextToken()),m=0;
        st=new StringTokenizer(br.readLine());
        long k=Long.parseLong(st.nextToken());
        st=new StringTokenizer(br.readLine());
        long a=Long.parseLong(st.nextToken());
        st=new StringTokenizer(br.readLine());
        long b=Long.parseLong(st.nextToken());
		long ans=0;
		if(k==1) { ans+=(n-1)*a; n=1; }
		while(n>1)
		{
			if(n%k==0)
			{
				m=n%k;
				ans+=Math.min(b,(n-n/k)*a);
				n/=k;
			}
			else
			{
				m=(n%k);
				if(n == m) { ans+=(n-1)*a; break; }
				ans+=(m)*a;
				n-=(n%k);

			}
		}
		pw.print(ans);
        pw.flush();
    }

}


/**
 * Created with IntelliJ IDEA.
 * User: Sergey Epifanov
 * Date: 5/19/12
 */
import java.io.*;
import java.util.Arrays;
import java.util.Scanner;

public class B {
    public static void main(String args[]) throws IOException {
        new B().run();
    }

    private Scanner in;
    private PrintWriter out;

    private void run() throws IOException {
        boolean online = System.getProperty("ONLINE_JUDGE") != null;
        in = online ? new Scanner(System.in) :
                new Scanner(new FileReader("input.txt"));
        out = online ? new PrintWriter(System.out) :
                new PrintWriter(new FileWriter("output.txt"));
        solve();
        out.flush();
        out.close();
    }

    private void solve() throws IOException {

        // input
        long w = in.nextInt();
        long h = in.nextInt();
        long w2 = w/2 * (w - w/2);
        long h2 = h/2 * (h - h/2);
        long res = w2 * h2;
        out.println(res);
    }
}


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 C_Round_253_Div1 {

	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();
		final int[] data = new int[n];
		final TreeSet<Integer> set = new TreeSet();

		for (int i = 0; i < n; i++) {
			set.add(i);

			data[i] = in.nextInt();

		}
		long result = 0;
		boolean[] check = new boolean[n];

		LinkedList<Integer> tmp = new LinkedList();
		boolean[] inS = new boolean[n];
		for (int i = 1; i + 1 < n; i++) {
			if (!check[i]) {
				inS[i] = true;
				tmp.add(i);
				while (!tmp.isEmpty()) {
					int v = tmp.poll();
					inS[v] = false;
					if (check[v]) {
						continue;
					}
					Integer a = set.lower(v);
					Integer b = set.higher(v);
					if (a != null && b != null && data[a] >= data[v]
							&& data[v] <= data[b]) {
						check[v] = true;
						set.remove(v);

						result += (long) Math.min(data[a], data[b]);
						if (!inS[a])
							tmp.add(a);
						if (!inS[b])
							tmp.add(b);
						// System.out.println(set + " " + v + " " + result + " "
						// + a + " " + b);
					}

				}
			}
		}
		TreeSet<Integer> list = new TreeSet(new Comparator<Integer>() {

			@Override
			public int compare(Integer o1, Integer o2) {
				int a = set.lower(o1);
				int b = set.higher(o1);
				int c = set.lower(o2);
				int d = set.higher(o2);
				a = Math.min(data[a], data[b]);
				c = Math.min(data[c], data[d]);
				return a - c;
			}
		});
		for (int i = 1; i + 1 < n; i++) {
			if (!check[i]) {
				list.add(i);
			}
		}
		while(!list.isEmpty()){
			int v = list.pollLast();
			set.remove(v);
			int a = set.lower(v);
			int b = set.higher(v);
			int c = Math.min(data[a], data[b]);
			result += c;
			if(a != 0){
				list.remove(a);
				list.add(a);
			}
			if(b != n -1){
				list.remove(b);
				list.add(b);
			}
			//System.out.println(list);

		}
		out.println(result);

		out.close();
	}

	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 y - o.y;
		}
	}

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

public class B {

    static MyScanner in = new MyScanner();
    static   PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;
    static long H,W;
    static BitSet bs;
    static long mod = 1000000007;
      // All possible moves of a knight
    static   int X[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
    static int Y[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
    static int [] dr   = {-1,0,0,1};
    static int [] dc = {0,1,-1,0};
    static int [][] grid = new int[3][3];
    static int R1 =0;
    static int R2 = 0;
    static int R3=0;
    static int C1 = 0;
    static int C2 = 0;
    static int C3 = 0;
    static int D1 = 0;
    static int D2 = 0;

    public static void main(String args[]) throws IOException {
    /**
1.What is the unknown:
2.What are the data: an array of tlen ght  the value is 10^9
3.What is the condition:
4. understand the problem:
5. What are the cases edges in the problem:
6.What what max:
7. Are you using a data stcuture. And which one:
8.Is there reursion what is the base case. For example COINS:
*/
            for(int i=0;i<3;i++)
                for(int j=0;j<3;j++)
                    grid[i][j] = in.nextInt();
        boolean stop = false;
        for(int i=1;i<=1000000&&!stop;i++){
            //set a[0][0] = 1
            grid[0][0] = i;
            if(firstCol()==firstRow()){
                int newVal = firstCol()-secondRow();
                grid[1][1] = newVal;
                if(secondRow()==secondCol()&&secondRow()==firstCol()&&newVal >0){
                    int val = firstCol()-thirdCol();
                    grid[2][2] = val;
                    if(secondRow()==secondCol()&&secondRow()==firstCol()&&thirdCol()==thirdRow()&&val>0&&topLeftAndButtomRight()==bottumLeftAdnTopRight()){
                        printTwoDArray();
                        stop  = true;
                    }
                    grid[2][2] = 0;
                }
                grid[1][1] = 0;
            }
            grid[0][0] = 0;

        }

            out.flush();
    }
    private static int topLeftAndButtomRight (){
        int sum=0;
        for(int i=0;i<3;i++)
            sum+=grid[i][i];
        return sum;
    }
    private static int bottumLeftAdnTopRight (){
        int sum=0;
        for(int i=2;i>=0;i--)
            sum+=grid[i][2-i];
        return sum;
    }
    private static void printTwoDArray() {
        for(int i=0;i<grid.length;i++){
            for(int j=0;j<grid[i].length;j++){
                out.print(grid[i][j]+" ");
            }
            out.print("\n");
        }
    }

    public static int firstRow() {
        int sum=0;
        for(int i=0;i<3;i++)
            sum+=grid[0][i];
        return sum;
    }
    public static int secondRow(){
        int sum=0;
        for(int i=0;i<3;i++)
            sum+=grid[1][i];
        return sum;
    }  public static int thirdRow(){
        int sum=0;
        for(int i=0;i<3;i++)
            sum+=grid[2][i];
        return sum;
    }
    public static int thirdCol(){
        int sum=0;
        for(int i=0;i<3;i++)
            sum+=grid[i][2];
        return sum;
    }
    public static int secondCol(){
        int sum=0;
        for(int i=0;i<3;i++)
            sum+=grid[i][1];
        return sum;
    }
    public static int firstCol (){
        int sum=0;
        for(int i=0;i<3;i++)
            sum+=grid[i][0];
        return sum;
    }
    public static boolean subseqeunce(String s, String t){
        for(int i=0,j=0;i<s.length();i++){
            if(j<t.length()&&s.charAt(i)==t.charAt(j)){
                j++;
            }
            if(j==t.length()) return true;
        }
        return false;
    }

    private static int lowrBound(int[] a, int lo, int hi, int element) {
        while(lo<hi){
            int mid = lo+(hi-lo)/2;
            if(element>a[mid]){
                lo = mid+1;
            }else{
                hi  = mid;
            }
        }
        if(lo<a.length&&a[lo]==element){
            return lo+1;
        }
        return lo;
    }

    static long lcm(int a, int b) {
        return (a*b)/gcd(a, b);
    }
    static boolean isVowel(char c) {
        if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||c=='y'){
            return true;
        }
        return false ;
    }
    static class IP implements Comparable<IP>{
        public int first,second;
        IP(int first, int second){
            this.first = first;
            this.second = second;
        }
        public int compareTo(IP ip){
            if(first==ip.first)
                return second-ip.second;
            return first-ip.first;
        }
        @Override
        public String toString() {
            return first+" "+second;
        }

    }

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

        static boolean isEven(long a) {
            return (a&1)==0;
        }

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

     }
}


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

public class P1599C {
    public static void main(String[] args) throws IOException {
        MyScanner scanner = new MyScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int n = scanner.nextInt();
        double p = scanner.nextDouble();

        int lo = 0, hi = n, ans = n;
        while (lo <= hi) {
            int m = (lo + hi) / 2;
            if (chance(n, m) >= p) {
                hi = m - 1;
                ans = m;
            } else {
                lo = m + 1;
            }
        }
        writer.println(ans);

        writer.flush();
    }

    private static double chance(int n, int m) {
        double p = 0.0;

        if (m >= 3) {
            p += comb(m, 3);
        }
        if (m >= 2 && n - m >= 1) {
            p += comb(m, 2) * comb(n - m, 1);
        }
        if (m >= 1 && n - m >= 2) {
            p += comb(m, 1) * comb(n - m, 2) / 2.0;
        }

        return p / comb(n, 3);
    }

    private static long comb(int from, int pick) {
        long ans = 1;
        for (int i = 0; i < pick; i++) {
            ans *= from - i;
        }
        for (int i = 2; i <= pick; i++) {
            ans /= i;
        }

        return (int)ans;
    }

    private static class MyScanner {
        private BufferedReader reader;
        private StringTokenizer st;

        public MyScanner(InputStream inputStream) {
            reader = new BufferedReader(new InputStreamReader(inputStream));
        }

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

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

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

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


import java.util.Scanner;

public class CF236_1 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int k = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        int v = in.nextInt();

        if (k > b) {
        int i;
        for (i = 0; a > 0; i++) {

            if (b > 0) {
            for (int j = 0; b >= 0; b--) {
                a = a - v;
            }
            }else {
                a = a - v;
            }
        }
        System.out.println(i);
        } else {
    //
            int i;
            for (i = 0; a > 0; i++) {
                if (b>=0){
                for (int j = 0; (b >= 0)&(j < k) ; j++) {
                        a = a - v;
                        b--;
                    }
                b = b+1;
                }else a = a - v;

            }
            System.out.println(i);
            }

    }
}


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

public class C {
	public static long [] fac;
	public static long [][] comb;
	public static long mod= 998244353;
	public static void main(String[] args) throws IOException {
		FastScanner in= new FastScanner(System.in);
		PrintWriter out= new PrintWriter(System.out);
		int a= in.nextInt();
		int b= in.nextInt();
		int c= in.nextInt();

		comb= new long[5001][5001];
		fac= new long[5001];
		fac[0]=1;
		for (long i = 1; i < fac.length; i++) {
			fac[(int)i]= (fac[(int) (i-1)]*i)%mod;
		}
		comb[0][0]= 1;
		for (int i=1;i<=5000;i++) {
			comb[i][0]=1;
			for (int j=1;j<=i;j++)
				comb[i][j]= (comb[i-1][j-1]+comb[i-1][j])%mod;
		}
		long res=1;
		res= (res*go(a,b))%mod;
		res= (res*go(b,c))%mod;
		res= (res*go(a,c))%mod;

		System.out.println(res);

	}
	public static long go(int a, int b) {
		long res=0;
		for (int i = 0; i <=a && i<=b; i++) {
			long cur= fac[i];
			cur= (cur*comb[a][i])%mod;
			cur= (cur*comb[b][i])%mod;
			res= (res+cur)%mod;
		}
		return res;
	}
	static class p implements Comparable<p>{
		int x;
		int y;
		public p(int a, int b) {
			x=a;
			y=b;
		}
		public int compareTo(p o) {
			return this.x-o.x;
		}
	}
	static class FenwickTree {
		long[] ft;
		public FenwickTree(int n) {
			ft = new long[n + 1];
		}

		int rsq(int b) {
			int sum = 0;
			for (; b > 0; b -= (b & (-b)))
				sum += ft[b];
			return sum;
		}

		int rsq(int a, int b) {
			return rsq(b) - (a == 1 ? 0 : rsq(a - 1));
		}

		void update(int k, int v) {
			for (; k < ft.length; k += (k & (-k)))
				ft[k] += v;
		}
	}

	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
			st = new StringTokenizer("");
		}

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

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
		public double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
	}
}


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

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

    static class TaskH {
        long[] lens;
        Description[] cache;
        int m;
        int[] b;
        int[] gen;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int d = in.nextInt();
            m = in.nextInt();
            gen = new int[d];
            for (int i = 0; i < d; ++i) gen[i] = in.nextInt();
            int blen = in.nextInt();
            b = new int[blen];
            for (int i = 0; i < blen; ++i) {
                b[i] = in.nextInt();
            }
            long left = in.nextLong();
            long right = in.nextLong();
            lens = new long[100];
            long len = 1;
            int layer = 0;
            lens[layer] = len;
            while (true) {
                ++layer;
                if (len < (right + d - 1) / d) {
                    len *= d;
                    lens[layer] = len;
                } else {
                    lens[layer] = right + 1;
                    break;
                }
            }
            cache = new Description[layer + 1];
            Description d1 = describe(layer, right);
            Description d2 = describe(layer, left + b.length - 2);
            long res = d1.matchesInside[0] - d2.matchesInside[0];
            out.println(res);
        }

        private Description describe(int layer, long upto) {
            if (upto > lens[layer]) throw new RuntimeException();
            if (upto == lens[layer]) {
                if (cache[layer] != null) return cache[layer];
            }
            Description res = null;
            if (upto <= 0) {
                res = new Description(upto);
                return res;
            }
            if (layer == 0) {
                res = new Description(upto);
                for (int shift = 0; shift < m; ++shift) {
                    if (b.length > 1 && b[0] >= shift) {
                        res.matchesPrefix[shift] = BigInteger.ONE;
                    } else {
                        res.matchesPrefix[shift] = BigInteger.ZERO;
                    }
                    if (b.length > 1 && b[b.length - 1] >= shift) {
                        res.matchesSuffix[shift] = BigInteger.ONE.shiftLeft(b.length - 1);
                    } else {
                        res.matchesSuffix[shift] = BigInteger.ZERO;
                    }
                    if (b.length == 1 && b[0] >= shift) {
                        ++res.matchesInside[shift];
                    }
                    byte[] bits = new byte[(b.length + 7) >> 3];
                    for (int i = 0; i < b.length; ++i) {
                        if (b[i] >= shift) {
                            bits[bits.length - 1 - (i >> 3)] |= (1 << (i & 7));
                        }
                    }
                    res.coveredIfStartsFrom[shift] = new BigInteger(1, bits);
                }
            } else {
                long togo = upto;
                for (int i = 0; i < gen.length && togo > 0; ++i) {
                    long by = Math.min(togo, lens[layer - 1]);
                    Description d = describe(layer - 1, by);
                    res = combine(res, d, gen[i]);
                    togo -= by;
                }
            }
            if (res == null) throw new RuntimeException();
            if (upto == lens[layer]) {
                cache[layer] = res;
            }
            return res;
        }

        private Description combine(Description a, Description b, int delta) {
            if (a == null) {
                if (delta != 0) throw new RuntimeException();
                return b;
            }
            Description res = new Description(a.len + b.len);
            for (int shift = 0; shift < m; ++shift) {
                int ashift = shift;
                int bshift = (shift + delta) % m;
                res.matchesInside[shift] = a.matchesInside[ashift] + b.matchesInside[bshift];
                res.matchesInside[shift] += a.matchesPrefix[ashift].and(b.matchesSuffix[bshift].shiftRight(1)).bitCount();
                res.matchesPrefix[shift] = b.matchesPrefix[bshift];
                if (b.len < this.b.length) {
                    res.matchesPrefix[shift] = res.matchesPrefix[shift].or(a.matchesPrefix[ashift].and(b.coveredIfStartsFrom[bshift].shiftRight(1)).shiftLeft((int) b.len));
                }
                res.matchesSuffix[shift] = a.matchesSuffix[ashift];
                if (a.len < this.b.length) {
                    res.matchesSuffix[shift] = res.matchesSuffix[shift].or(b.matchesSuffix[bshift].shiftRight((int) a.len).and(a.coveredIfStartsFrom[ashift]));
                }
                if (a.len < this.b.length) {
                    res.coveredIfStartsFrom[shift] = a.coveredIfStartsFrom[ashift].and(b.coveredIfStartsFrom[bshift].shiftRight((int) a.len));
                } else {
                    res.coveredIfStartsFrom[shift] = BigInteger.ZERO;
                }
            }
            return res;
        }

        class Description {
            long len;
            long[] matchesInside = new long[m];
            BigInteger[] matchesPrefix = new BigInteger[m];
            BigInteger[] matchesSuffix = new BigInteger[m];
            BigInteger[] coveredIfStartsFrom = new BigInteger[m];

            public Description(long len) {
                this.len = len;
            }

        }

    }

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

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

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

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

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

    }
}


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

public class Conversion {

	private static long converted=-1;

	public static void main(String[] args) {
		Scanner s=new Scanner(System.in);
		long base=s.nextLong();
		String baseAsString=base+"";
		s.nextLine();
		StringBuilder unconverted=new StringBuilder(s.nextLine());
		Queue<Long> pieces=new LinkedList<Long>();
		while (unconverted.length()!=0) {
			for (int length=baseAsString.length(); length>0; length--) {
				if (canRemove(unconverted, base-1, unconverted.length()-length,length)) {
					pieces.add(converted);
					remove(unconverted, length);
					break;
				}
			}
		}
		for (Long l:pieces) {
			//System.out.println(l);
		}
		long total=0;
		long power=0;
		while (!pieces.isEmpty()) {
			long exponent=1;
			for (int i=0; i<power; i++) {
				exponent*=base;
			}
			total+=pieces.remove()*exponent;
			power++;
		}
		System.out.println(total);
	}

	private static boolean canRemove(StringBuilder unconverted, long maxValue, int index, int length) {
		String substring=unconverted.substring(Math.max(0, index), Math.min(index+length, unconverted.length()));
		if (substring.startsWith("0")&&length!=1) {
			return false;
		}
		converted=Long.parseLong(substring);
		return converted<=maxValue;
	}

	private static void remove(StringBuilder unconverted, int length) {
		for (int i=0; i<length&&unconverted.length()!=0; i++) {
			unconverted.deleteCharAt(unconverted.length()-1);
		}
	}

}


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

public class Main {

	public static void main(String[] args) throws Exception {
		long time = System.nanoTime();

		int n = next();

		int[] x1 = new int[n];
		int[] x2 = new int[n];
		int[] y1 = new int[n];
		int[] y2 = new int[n];

		for (int i = 0; i < n; i++) {
			x1[i] = next();
			y1[i] = next();
			x2[i] = next();
			y2[i] = next();
		}

		TreeSet<Integer> setx = new TreeSet<Integer>();
		TreeSet<Integer> sety = new TreeSet<Integer>();

		for (int x : x1) setx.add(x);
		for (int x : x2) setx.add(x);
		for (int y : y1) sety.add(y);
		for (int y : y2) sety.add(y);

		int kx = setx.size();
		int ky = sety.size();

		int[] x = new int[kx];
		int[] y = new int[ky];

		int ind = 0;
		for (int xx : setx) x[ind++] = xx;
		ind = 0;
		for (int yy : sety) y[ind++] = yy;

/*		for (int i = 0; i < kx; i++) out.print(x[i] + " ");
		out.println();
		for (int i = 0; i < ky; i++) out.print(y[i] + " ");
		out.println();*/

		boolean flag = true;
		for (int i = 0; i < kx - 1; i++)
			for (int j = 0; j < ky - 1; j++) {
				boolean cont = false;
				for (int t = 0; t < n; t++) {
					if ((x1[t] - x[i])*(x2[t] - x[i]) <= 0 && (x1[t] - x[i + 1])*(x2[t] - x[i + 1]) <= 0 &&
						(y1[t] - y[j])*(y2[t] - y[j]) <= 0 && (y1[t] - y[j + 1])*(y2[t] - y[j + 1]) <= 0) cont = true;
				}

				if (!cont) flag = false;
			}

	   	flag &= x[kx - 1] - x[0] == y[ky - 1] - y[0];

		out.println(flag ? "YES" : "NO");

//		System.out.println((System.nanoTime() - time)* 1e-9);
		out.close();
	}
	static PrintWriter out = new PrintWriter(System.out);

	static BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer in = new StringTokenizer("");

	static String nextToken() throws Exception {
		if (!in.hasMoreTokens()) in = new StringTokenizer(bufferedreader.readLine());
		return in.nextToken();
	}

	static int next()  throws Exception {return Integer.parseInt(nextToken());};
	static int[] next(int n) throws Exception {
		int[] x = new int[n];
		for (int i = 0; i < n; i++) x[i] = next();
		return x;
	}
	static int[][] next(int n, int m) throws Exception {
		int[][] x = new int[n][];
		for (int i = 0; i < n; i++) x[i] = next(m);
		return x;
	}

	static long nextl() throws Exception {return Long.parseLong(nextToken());};
	static long[] nextl(int n) throws Exception {
		long[] x = new long[n];
		for (int i = 0; i < n; i++) x[i] = nextl();
		return x;
	}
	static long[][] nextl(int n, int m) throws Exception {
		long[][] x = new long[n][];
		for (int i = 0; i < n; i++) x[i] = nextl(m);
		return x;
	}

	static double nextd() throws Exception {return Double.parseDouble(nextToken());};
	static double[] nextd(int n) throws Exception {
		double[] x = new double[n];
		for (int i = 0; i < n; i++) x[i] = nextd();
		return x;
	}
	static double[][] nextd(int n, int m) throws Exception {
		double[][] x = new double[n][];
		for (int i = 0; i < n; i++) x[i] = nextd(m);
		return x;
	}

	static String nextline() throws Exception {
		in = new StringTokenizer("");
		return bufferedreader.readLine();
	}

}


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

public class Main{
    public static void main(String[] args){
        Scanner SC =  new Scanner(System.in);
        BigInteger a, b, x, y, xynwd;
        a=new BigInteger(SC.next());
        b=new BigInteger(SC.next());
        x=new BigInteger(SC.next());
        y=new BigInteger(SC.next());
        xynwd=x.gcd(y);
        x=x.divide(xynwd);
        y=y.divide(xynwd);
        a=a.divide(x);
        b=b.divide(y);
        System.out.println(a.compareTo(b)>0 ? b : a);
    }
}


import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.*;
import java.util.regex.Pattern;

public class CF1156G {
    public static void main(String[] args) throws Exception {
        boolean local = System.getProperty("ONLINE_JUDGE") == null;
        boolean async = false;

        Charset charset = Charset.forName("ascii");

        FastIO io = local ? new FastIO(new FileInputStream("D:\\DATABASE\\TESTCASE\\Code.in"), System.out, charset) : new FastIO(System.in, System.out, charset);
        Task task = new Task(io, new Debug(local));

        if (async) {
            Thread t = new Thread(null, task, "dalt", 1 << 27);
            t.setPriority(Thread.MAX_PRIORITY);
            t.start();
            t.join();
        } else {
            task.run();
        }

        if (local) {
            io.cache.append("\n\n--memory -- \n" + ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) >> 20) + "M");
        }

        io.flush();
    }

    public static class Task implements Runnable {
        final FastIO io;
        final Debug debug;
        int inf = (int) 1e8;
        int mod = (int) 1e9 + 7;

        public int mod(int val) {
            val %= mod;
            if (val < 0) {
                val += mod;
            }
            return val;
        }

        public int mod(long val) {
            val %= mod;
            if (val < 0) {
                val += mod;
            }
            return (int) val;
        }

        public Task(FastIO io, Debug debug) {
            this.io = io;
            this.debug = debug;
        }

        @Override
        public void run() {
            solve();
        }

        Map<String, Var> context = new HashMap<>();
        HashSet<String> remainNames = new HashSet<>();
        Deque<String> useable = new ArrayDeque<>();

        public void solve() {
            int n = io.readInt();

            for (int i = 0; i < n; i++) {
                parseLine();
            }

            StringBuilder builder = new StringBuilder();
            for (int i = 'a'; i <= 'z'; i++) {
                for (int i2 = 'a'; i2 <= 'z'; i2++) {
                    for (int i3 = 'a'; i3 <= 'z'; i3++) {
                        for (int i4 = 'a'; i4 <= 'z'; i4++) {
                            builder.setLength(0);
                            builder.append((char) i).append((char) i2).append((char) i3).append((char) i4);
                            remainNames.add(builder.toString());
                        }
                    }
                }
            }

            remainNames.removeAll(context.keySet());
            useable.addAll(remainNames);

            String finalName = rebuild(getVar("res"));
            if (trace.isEmpty() && !finalName.equals("res")) {
                trace.add("res=" + finalName);
                finalName = "res";
            }
            if (!trace.isEmpty()) {
                trace.add(trace.remove(trace.size() - 1).replace(finalName, "res"));
            }
            io.cache.append(trace.size()).append('\n');
            for (String s : trace) {
                io.cache.append(s).append('\n');
            }
        }

        List<String> trace = new ArrayList<>();

        Random random = new Random(12345678);
        Map<String, String> exprToName = new HashMap<>();

        public String randomName() {
            return useable.removeFirst();
        }

        public String register(String expr, String name) {
            if (exprToName.containsKey(expr)) {
                return exprToName.get(expr);
            } else {
                trace.add(name + "=" + expr);
                exprToName.put(expr, name);
                return name;
            }
        }

        StringBuilder common = new StringBuilder(1024);

        public String concat(String... parts) {
            common.setLength(0);
            for (String part : parts) {
                common.append(part);
            }
            return common.toString();
        }

        Map<Var, String> cache = new IdentityHashMap<>();

        public String rebuild(Var var) {
            if (cache.containsKey(var)) {
                return cache.get(var);
            }
            String retName = null;
            if (var instanceof UnknownVar) {
                retName = ((UnknownVar) var).name;
            }
            if (var instanceof Reference) {
                retName = rebuild(var.arg1);
            }
            if (var instanceof Expr) {
                String name = randomName();
                String arg1 = rebuild(var.arg1);
                String arg2 = rebuild(((Expr) var).arg2);
                retName = register(concat(arg1, ((Expr) var).op, arg2), name);
            }
            cache.put(var, retName);
            return retName;
        }

        char[] line = new char[100];
        Lexer lexer = new Lexer();

        public Var getVar(String s) {
            if (!context.containsKey(s)) {
                UnknownVar var = new UnknownVar();
                var.name = s;
                context.put(s, var);
            }
            return context.get(s);
        }

        public void parseLine() {
            int len = io.readString(line, 0);
            lexer.reset(line, len);
            String variable = lexer.readName();
            lexer.readOp();
            String arg1 = lexer.readName();
            if (!lexer.hasMore()) {
                Reference reference = new Reference();
                reference.arg1 = getVar(arg1);
                context.put(variable, reference);
            } else {
                Expr expr = new Expr();
                expr.arg1 = getVar(arg1);
                expr.op = lexer.readOp();
                expr.arg2 = getVar(lexer.readName());
                Reference reference = new Reference();
                reference.arg1 = expr;
                context.put(variable, reference);
            }
        }
    }

    public static class Lexer {
        char[] data;
        int len;
        int rpos = 0;
        StringBuilder builder = new StringBuilder();

        public void reset(char[] data, int len) {
            this.data = data;
            this.len = len;
            rpos = 0;
        }

        public boolean hasMore() {
            return rpos != len;
        }

        public String readName() {
            builder.setLength(0);
            while (rpos < len && data[rpos] != '=' &&
                    data[rpos] != '$' && data[rpos] != '^' && data[rpos] != '#' && data[rpos] != '&') {
                builder.append(data[rpos++]);
            }
            return builder.toString();
        }

        public String readOp() {
            builder.setLength(0);
            builder.append(data[rpos++]);
            return builder.toString();
        }
    }

    public static class Var {
        Var arg1;
    }

    public static class Expr extends Var {
        String op;
        Var arg2;
    }

    public static class UnknownVar extends Var {
        String name;
    }

    public static class Reference extends Var {

    }

    public static class FastIO {
        public final StringBuilder cache = new StringBuilder();
        private final InputStream is;
        private final OutputStream os;
        private final Charset charset;
        private StringBuilder defaultStringBuf = new StringBuilder(1 << 8);
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastIO(InputStream is, OutputStream os, Charset charset) {
            this.is = is;
            this.os = os;
            this.charset = charset;
        }

        public FastIO(InputStream is, OutputStream os) {
            this(is, os, Charset.forName("ascii"));
        }

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

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

        public int readInt() {
            int sign = 1;

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

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

            return val;
        }

        public long readLong() {
            int sign = 1;

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

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

            return val;
        }

        public double readDouble() {
            boolean sign = true;
            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+';
                next = read();
            }

            long val = 0;
            while (next >= '0' && next <= '9') {
                val = val * 10 + next - '0';
                next = read();
            }
            if (next != '.') {
                return sign ? val : -val;
            }
            next = read();
            long radix = 1;
            long point = 0;
            while (next >= '0' && next <= '9') {
                point = point * 10 + next - '0';
                radix = radix * 10;
                next = read();
            }
            double result = val + (double) point / radix;
            return sign ? result : -result;
        }

        public String readString(StringBuilder builder) {
            skipBlank();

            while (next > 32) {
                builder.append((char) next);
                next = read();
            }

            return builder.toString();
        }

        public String readString() {
            defaultStringBuf.setLength(0);
            return readString(defaultStringBuf);
        }

        public int readLine(char[] data, int offset) {
            int originalOffset = offset;
            while (next != -1 && next != '\n') {
                data[offset++] = (char) next;
                next = read();
            }
            return offset - originalOffset;
        }

        public int readString(char[] data, int offset) {
            skipBlank();

            int originalOffset = offset;
            while (next > 32) {
                data[offset++] = (char) next;
                next = read();
            }

            return offset - originalOffset;
        }

        public int readString(byte[] data, int offset) {
            skipBlank();

            int originalOffset = offset;
            while (next > 32) {
                data[offset++] = (byte) next;
                next = read();
            }

            return offset - originalOffset;
        }

        public char readChar() {
            skipBlank();
            char c = (char) next;
            next = read();
            return c;
        }

        public void flush() {
            try {
                os.write(cache.toString().getBytes(charset));
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public boolean hasMore() {
            skipBlank();
            return next != -1;
        }
    }

    public static class Debug {
        private boolean allowDebug;

        public Debug(boolean allowDebug) {
            this.allowDebug = allowDebug;
        }

        public void assertTrue(boolean flag) {
            if (!allowDebug) {
                return;
            }
            if (!flag) {
                fail();
            }
        }

        public void fail() {
            throw new RuntimeException();
        }

        public void assertFalse(boolean flag) {
            if (!allowDebug) {
                return;
            }
            if (flag) {
                fail();
            }
        }

        private void outputName(String name) {
            System.out.print(name + " = ");
        }

        public void debug(String name, int x) {
            if (!allowDebug) {
                return;
            }

            outputName(name);
            System.out.println("" + x);
        }

        public void debug(String name, long x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println("" + x);
        }

        public void debug(String name, double x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println("" + x);
        }

        public void debug(String name, int[] x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println(Arrays.toString(x));
        }

        public void debug(String name, long[] x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println(Arrays.toString(x));
        }

        public void debug(String name, double[] x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println(Arrays.toString(x));
        }

        public void debug(String name, Object x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println("" + x);
        }

        public void debug(String name, Object... x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println(Arrays.deepToString(x));
        }
    }
}


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

public class Main {

    static int b[];
    static String numbers;
    static String av;

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

        numbers = sc.nextLine();
        av = sc.nextLine();
        int n = av.length();
        b = new int[n];
        Arrays.fill(b, 1);
        int num = numbers.length();
        int totalCount = 0;

        while (find0(numbers.charAt(0))) {
            int m = 1;
            for (int i = 1; i < num; i++)
                if (find0(numbers.charAt(i))) {
                    m = m + 1;
                }
            if (num == m) {
                totalCount = totalCount + 1;
            } else break;
        }

        pw.println(totalCount);
        pw.close();
        sc.close();
    }

    static boolean find0(char c) {
        for (int i = 0; i < b.length; i++) {
            if (b[i] == 1 && check(c, av.charAt(i))) {
                b[i] = 0;
                return true;
            }
        }
        return false;
    }

    private static boolean check(char c, char c1) {
        if (c == c1) {
            return true;
        }
        if (c == '2' || c == '5' || c == '6' || c == '9' || c1 == '2' || c1 == '5' || c1 == '6' || c1 == '9') {
            //2 and 5
            if (c == '2' && c1 == '5') {
                return true;
            }
            if (c == '5' && c1 == '2') {
                return true;
            }
            if (c1 == '2' && c == '5') {
                return true;
            }
            if (c1 == '5' && c == '2') {
                return true;
            }
            //6 and 9
            if (c == '6' && c1 == '9') {
                return true;
            }
            if (c == '9' && c1 == '6') {
                return true;
            }
            if (c1 == '6' && c == '9') {
                return true;
            }
            if (c1 == '9' && c == '6') {
                return true;
            }
        }
        return false;
    }
}


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

public class Postcard {

    static void print(char[] arr) {
        StringBuilder sb = new StringBuilder();
        for (int j = 0; j < arr.length; j++) {
            if (arr[j] != '?' && arr[j] != '*' && arr[j] != 'A') {
                sb.append(arr[j]);
            }
        }
        System.out.println(sb);
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char arr[] = in.next().toCharArray();
        int num = in.nextInt();
        int cane = 0, snow = 0, size = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == '*') {
                snow++;
            } else if (arr[i] == '?') {
                cane++;
            } else {
                size++;
            }
        }
        if(size<num&&snow==0){
            System.out.println("Impossible");
        }else if (size == num) {
            print(arr);
            //////////////////////////////////////////////////////////////
        } else if (num > size && snow > 0) {
            StringBuilder sb = new StringBuilder();
            int diff=num-size;
            for (int j = 0; j < arr.length; j++) {
                if(arr[j]=='*'){
                    for (int i = j-1; num>size; ) {
                        sb.append(arr[i]);
                        size++;
                    }
                }
                if (arr[j] != '?' && arr[j] != '*' && arr[j] != 'A') {
                    sb.append(arr[j]);
                }
            }
            System.out.println(sb);
            ///////////////////////////////////////////////////////////////////
        }else if (size - (cane + snow) <= num) {
            int i = 0;
            while (size > num && i < arr.length) {
                if (arr[i] == '?' || arr[i] == '*') {
                    arr[i - 1] = 'A';
                    size--;
                }
                i++;
            }//while

            print(arr);
            ////////////////////////////////////////////////////////////////
        } else {
            System.out.println("Impossible");
        }

    }//psvm
}//class


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

/**
 * Created by vignesh on 1/27/2017.
 */
public class hackerRank {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        String[] pokemons= {"vaporeon", "jolteon", "flareon", "umbreon", "leafeon", "glaceon", "sylveon", "espeon"};
        int n = input.nextInt();
        String s = new String();
        s = input.next();
        int alpha  = 0, count = 0;

        for (int i = 0; i < s.length(); i++) {

            if(s.charAt(i) != '.')

                alpha++;

        }

        if(s.length() == 8)

            System.out.println("vaporeon");

        else if(s.length() == 6)

            System.out.println("espeon");

        else{

            for(int i =1; i <= 6; i++){

                count = 0;

                for(int j = 0; j < 7; j++){

                    if(s.charAt(j) != '.'){

                        if(s.charAt(j) == pokemons[i].charAt(j))

                            count++;

                    }

                    if(count  == alpha) {

                        System.out.println(pokemons[i]);
                        break;
                    }

                }

                if(count == alpha)

                    break;

            }

        }

    }
}


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

public class Training {

    public static void main(String[] args) {
        FastReader in = new FastReader();

        int n = in.nextInt();

        StringBuilder sb = new StringBuilder();

        int prv = 0;
        for (int i = n; i >= 1; i--) {
            if ((n % i == 0) && prv % i == 0) {
                sb.append(i == 1 ? i : i + " ");
                prv = i;
            }
        }

        System.out.println(sb);
    }
}

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


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

public class E {

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

    void solve() throws IOException {
        int n = nextInt();
        int m = nextInt();

        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();

        long ans = 0;

        int maxP = m / n;
        for (int p = 1; p <= maxP; p++) {
            long minLastSum = (long)p * (p + 1) / 2 * n;
            if (a[n - 1] < minLastSum)
                continue;
            long maxLastSum = (long)m * p - (long)n * p * (p - 1) / 2;
            long[] money = new long[n];
            money[n - 1] = Math.min(maxLastSum, a[n - 1]);
            for (int i = n - 2; i >= 0; i--)
                money[i] = Math.min(a[i], money[i + 1] - p);

            long firstMax = (long)(m + 1) * p - (long)n * p * (p + 1) / 2;
            long diff = firstMax - money[0];
            if (diff < 0)
                throw new AssertionError();
            long firstPay = diff <= m - p * n ? (m - p * n + 1 - diff) : 1;
            long free = (m - firstPay + 1) - n * p;

            long cur = money[0];
            long last = money[0];
            for (int j = 1; j < n; j++) {
                long now = last + p;
                long shift = Math.min(free, money[j] - now);
                free -= shift;
                last = now + shift;
                cur += last;
            }

            ans = Math.max(ans, cur);
        }

        out.println(ans);
    }

    void inp() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

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

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

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

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

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

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


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

public	 class CODEFORCES
	{
		private InputStream is;
		private PrintWriter out;
		int time = 0, DP[], start[], end[], dist[], black[], MOD = (int) (1e9 + 7),
				arr[], weight[][], x[], y[], parent[];
		int MAX = 100000, N, K;
		long red[];
		ArrayList<Integer>[] amp;
		ArrayList<Pair>[][] pmp;
		boolean b[], boo[][];
		Pair prr[];
		HashMap<Pair, Integer> hm = new HashMap();
		long Dp[][][][] = new long[110][110][12][12];

		void soln()
		{
			is = System.in;
			out = new PrintWriter(System.out);
			long s = System.currentTimeMillis();
			solve();
			// out.close();
			out.flush();
			// tr(System.currentTimeMillis() - s + "ms");
		}

		public static void main(String[] args) throws Exception
		{
			new Thread(null, new Runnable()
			{
				public void run()
				{
					try
					{
						// new CODEFORCES().soln();
					} catch (Exception e)
					{
						System.out.println(e);
					}
				}
			}, "1", 1 << 26).start();
			new CODEFORCES().soln();
		}

		int ans = 0, cost = 0, D[][];
		char ch[], ch1[];
		int hash = 29;
		TreeSet<Cell> ts;
		int prime[] = new int[100000];
		int dp[] = new int[50000];
		TreeSet<String> tset = new TreeSet<>();
		void solve()
		{
			long n = nl();
			long low = 1, high = n, ans = high;
			while(low<=high) {
				long mid = (low+high)/2;
				long temp = n;
				long cnt = 0;
				while(temp>0) {
					if(temp<=mid) {
						cnt += temp;
						temp = 0;
					}
					else {
						temp -= mid;
						cnt += mid;
					}
					temp -= temp/10;
				}
				//out.println(mid+" "+cnt);
				if(cnt>=((n+1)/2)) {
					high = mid-1;
					ans = mid;
				}
				else {
					low = mid+1;
				}
			}
			out.println(ans);
		}
		void printArray(long[] arr) {
			for(long i : arr) out.print(i +" ");
			out.println();
		}
		void bfs(int x) {
			Queue<Integer> q = new LinkedList<>();
			q.add(x);
			arr[x] = 0;
			while(!q.isEmpty()) {
				int y = q.poll();
				for(int i : amp[y]) {
					arr[i] = min(arr[i],arr[y]+1);
					if(!b[i]) {
						q.add(i);
						b[i] = true;
					}
				}
			}
		}
		long calc(char ch[]) {
			long val = 1, sum = 0;
			for(char c : ch) {
				if(c == 'S') sum += val;
				else val*=2;
			}
			return sum;
		}
		int dfs(int x) {
			b[x] = true;
			//start[x] = time++;
			int ans = 1;
			for(int i : amp[x]) {
				if(!b[i]) {
					ans += dfs(i);
				}
			}
			//end[x] = time;
			if(x!= 0 && ans%2==0 && (N-ans)%2==0) cost++;

			return ans;
		}
		int calc(int x) {
			String s = Integer.toString(x);
			int ans = 0;
			for(char ch : s.toCharArray()) ans += (ch-'0');
			return ans;
		}
		boolean isCons(char ch){
			if(ch!='a' && ch!='e' && ch!='i' && ch!='o' && ch!='u' && ch!=' ') return true;
			return false;
		}
		void seive(int x){
			b = new boolean[x+1];
			for(int i = 2;i*i<=x;i++){
				if(!b[i]){
					for(int j = 2*i;j<=x;j+=i) b[j] = true;
				}
			}
		}
		long[][] matMul(long a[][] , long b[][], int n)
		{
			long res[][] = new long[n][n];
			for(int i = 0;i<n;i++){
				for(int j = 0;j<n;j++){
					long sum = 0;
					for(int k = 0;k<n;k++){
						sum += (a[i][k]*1l*b[k][j]);
						sum %= MOD;
					}
					res[i][j] = sum;
				}
			}
			return res;
		}
		int min(int a, int b)
		{
			return (a<b)?a:b;
		}
		private class Cell implements Comparable<Cell>
		{
			int u, v, s;
			public Cell(int u, int v, int s)
			{
				this.u = u;
				this.v = v;
				this.s = s;
			}
			public int hashCode()
			{
				return Objects.hash();
			}
			public int compareTo(Cell other)
			{
				return (Long.compare(s, other.s) != 0 ? (Long.compare(s, other.s)):(Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u)))
						&((Long.compare(s, other.s) != 0 ? (Long.compare(s, other.s)):(Long.compare(u, other.v)!=0?Long.compare(u, other.v):Long.compare(v, other.u))));
			}
			public String toString()
			{
				return this.u + " " + this.v;
			}
		}

		class Pair implements Comparable<Pair>
		{
			int u, v, z, i;

			Pair(int u, int v)
			{
				this.u = u;
				this.v = v;
			}

			Pair()
			{

			}

			Pair(int u, int v, int z, int i)
			{
				this.u = u;
				this.v = v;
				this.z = z;
				this.i = i;
			}

			public int hashCode()
			{
				return Objects.hash();
			}

			public boolean equals(Object o)
			{
				Pair other = (Pair) o;
				return (((u == other.v && v == other.u)));
			}

			public int compareTo(Pair other)
			{
				//return (((u == other.v && v == other.u)))?0:1;
				// return Integer.compare(val, other.val);
				return Long.compare(u, other.u);// != 0 ? (Long.compare(u, other.u)): (Long.compare(v, other.v));
						//&(Long.compare(u, other.v) != 0 ? (Long.compare(u, other.v)): (Long.compare(v, other.u))));
			}

			public String toString()
			{
				return this.u + " " + this.v;
			}
		}

		int max(int a, int b)
		{
			if (a > b)
				return a;
			return b;
		}

		void buildGraph(int n)
		{
			for (int i = 0; i < n; i++)
			{
				int x1 = ni() - 1, y1 = ni() - 1;
				amp[x1].add(y1);
				amp[y1].add(x1);
			}
		}
		long modInverse(long a, long mOD2)
		{
			return power(a, mOD2 - 2, mOD2);
		}

		long power(long x, long y, long m)
		{
			if (y == 0)
				return 1;
			long p = power(x, y / 2, m) % m;
			p = (p * p) % m;

			return (y % 2 == 0) ? p : (x * p) % m;
		}

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

		static class ST1
		{
			int arr[], st[], size;

			ST1(int a[])
			{
				arr = a.clone();
				size = 10 * arr.length;
				st = new int[size];
				build(0, arr.length - 1, 1);
			}

			void build(int ss, int se, int si)
			{
				if (ss == se)
				{
					st[si] = arr[ss];
					return;
				}
				int mid = (ss + se) / 2;
				int val = 2 * si;
				build(ss, mid, val);
				build(mid + 1, se, val + 1);
				st[si] = Math.min(st[val], st[val + 1]);
			}

			int get(int ss, int se, int l, int r, int si)
			{
				if (l > se || r < ss || l > r)
					return Integer.MAX_VALUE;
				if (l <= ss && r >= se)
					return st[si];
				int mid = (ss + se) / 2;
				int val = 2 * si;
				return Math.min(get(ss, mid, l, r, val),
						get(mid + 1, se, l, r, val + 1));
			}
		}

		static class ST
		{
			int arr[], lazy[], n;

			ST(int a)
			{
				n = a;
				arr = new int[10 * n];
				lazy = new int[10 * n];
			}

			void up(int l, int r, int val)
			{
				update(0, n - 1, 0, l, r, val);
			}

			void update(int l, int r, int c, int x, int y, int val)
			{
				if (lazy[c] != 0) {
					lazy[2 * c + 1] += lazy[c];
					lazy[2 * c + 2] += lazy[c];
					if (l == r)
						arr[c] += lazy[c];
					lazy[c] = 0;
				}
				if (l > r || x > y || l > y || x > r)
					return;
				if (x <= l && y >= r)

				{
					lazy[c] += val;
					return;
				}
				int mid = l + r >> 1;
				update(l, mid, 2 * c + 1, x, y, val);
				update(mid + 1, r, 2 * c + 2, x, y, val);
				arr[c] = Math.max(arr[2 * c + 1], arr[2 * c + 2]);
			}

			int an(int ind)
			{
				return ans(0, n - 1, 0, ind);
			}

			int ans(int l, int r, int c, int ind)
			{
				if (lazy[c] != 0)
				{
					lazy[2 * c + 1] += lazy[c];
					lazy[2 * c + 2] += lazy[c];
					if (l == r)
						arr[c] += lazy[c];
					lazy[c] = 0;
				}
				if (l == r)
					return arr[c];
				int mid = l + r >> 1;
				if (mid >= ind)
					return ans(l, mid, 2 * c + 1, ind);
				return ans(mid + 1, r, 2 * c + 2, ind);
			}
		}

		public static int[] shuffle(int[] a, Random gen)
		{
			for (int i = 0, n = a.length; i < n; i++)
			{
				int ind = gen.nextInt(n - i) + i;
				int d = a[i];
				a[i] = a[ind];
				a[ind] = d;
			}
			return a;
		}

		long power(long x, long y, int mod)
		{
			long ans = 1;
			while (y > 0)
			{
				if (y % 2 == 0)
				{
					x = (x * x) % mod;
					y /= 2;
				} else
				{
					ans = (x * ans) % mod;
					y--;
				}
			}
			return ans;
		}

		// To Get Input
		// Some Buffer Methods
		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.*;
import java.util.*;
import java.math.*;
import java.lang.*;

 //@Manan Parmar

public class Solution2 implements Runnable {

    public void run() {

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

        int t=sc.nextInt();
        while(t--!=0)
        {
            int n=sc.nextInt();
            if(n%3==0||n%7==0)
                n=0;
            else
            {
            while(true)
            {
                if(n%3==0||n%7==0)
                {
                    n=0;
                    break;
                }
                else if(n>=7)
                    n=n-7;
                else if(n>=3)
                    n=n-3;
                else
                    break;
            }
            }
            //out.println(n);
            if(n==0)
                out.println("YES");
            else
                out.println("NO");
        }
        out.close();
    }

//========================================================================

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

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

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

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

            return res * sgn;
        }

        public long nextLong() {
            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;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

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

            return res.toString();
        }

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

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

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

    public static void main(String args[]) throws Exception {
        new Thread(null, new Solution2(),"Main",1<<27).start();
    }
}


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

public class Main {

    void run(){
        boolean oj = System.getProperty("ONLINE_JUDGE")!=null;
//        boolean oj = false;
        if( oj ){
            br  = new BufferedReader( new InputStreamReader (System.in ) );
            out = new PrintWriter   ( new OutputStreamWriter(System.out) );
        }
        else{
            try{
                br  = new BufferedReader(new FileReader("abc.in"));
                out = new PrintWriter(   new FileWriter("abc.out") );
            } catch (IOException e) {
                MLE();
            }
        }
        long tBeg = System.currentTimeMillis();
        solve();
//        deb();
//        out.println( "TIME: " + (System.currentTimeMillis()-tBeg)/1e3 );
        out.flush();
    }

    BufferedReader br;
    StringTokenizer in;
    PrintWriter out;

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

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

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

    public static void main(String[] args) throws IOException {
        new Thread( null, new Runnable() {
            @Override
            public void run() {
                new Main().run();
            }
        }, "myThread", 1<<30 ).run();
    }

    void MLE(){
//        for(;;);
        int[][] adj = new int[1024*1024][];
        for( int i = 0; i < adj.length; ++i )
            adj[i] = new int[1024*1024];
    }

//    final int cntBits = 29;
//
//    HashMap<Integer,Integer> mem = new HashMap<Integer, Integer>();
//    int g( int msk ){
//        if( mem.containsKey(msk) )
//            return mem.get(msk);
//
//        if( msk == 0 ){
//            mem.put(msk,0);
//            return 0;
//        }
//
//        boolean[] u = new boolean[200];
//        for( int i = 1; i <= cntBits; ++i ){
//            if(!( (msk&(1<<i)) != 0 ))continue;
//            int toMsk = msk;
//            for( int j = i; j <= cntBits; j+=i ){
//                toMsk &= ~(1<<j);
//            }
//            u[g(toMsk)] = true;
//        }
//        for( int ansG = 0; ; ++ansG )
//            if( !u[ansG] ){
//                mem.put(msk,ansG);
//                return ansG;
//            }
//    }

    final int[] g = new int[]{0, 1, 2, 1, 4, 3, 2, 1, 5, 6, 2, 1, 8, 7, 5, 9, 8, 7, 3, 4, 7, 4, 2, 1, 10, 9, 3, 6, 11, 12};

    void solve(){
//        for( int c = 1; c <= cntBits; ++c ){
//            int msk = 0;
//            for( int j = 1; j <= c; ++j )
//                msk |= (1<<j);
//            out.print( ", " + g(msk) );
//        }
//        out.println();

        int n = nextInt();
        int s = g[1];
        int other = n-1;

        BitSet bs = new BitSet();
        int i;
        for( i = 2; i*i <= n; ++i ){
            if( bs.get(i) ) continue;

            int a = 0;
            for( long j = i; j <= n;  j *= i, ++a, --other ){
                if( j < 1e5 ) bs.set((int)j,true);
            }
            s ^= g[a];
        }
        if( other%2==1 ) s ^= 1;
        out.println( s != 0? "Vasya" : "Petya" );
    }

}


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

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

public class Try
{

    static class InputReader {

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

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

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

		public int ni() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nl() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

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

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

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

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

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

	}

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

		}
		static PrintWriter w = new PrintWriter(System.out);
                static int p = 0;
 static char [][]sol;
    public static void main(String[] args)
    {

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

        prime  = new boolean[n + 1];
		sieve();
		prime[1] = false;

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

       /*

	long a = sc.nl();

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

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

                    }

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

         // MergeSort ob = new MergeSort();
       // ob.sort(arr, 0, arr.length-1);

    // Student []st = new Student[x];
   // st[i] = new Student(i,d[i]);
     //Arrays.sort(st,(p,q)->p.diff-q.diff);
//BigDecimal x = new BigDecimal(b[i]).multiply(new BigDecimal("-1")).divide(new BigDecimal(a[i]),100,RoundingMode.HALF_UP);

int x = sc.ni();
int k = sc.ni();
if(k==1)
{
    w.println(3*x);
}
else
{
    int p = Math.min(k-1, x-k);
    w.println(p + (3*x));
}

   w.close();

    }

    static int []a;
    static long a1,b;
    public static int searchlow(int x) {
		int lo=0, hi=a.length-1;
		int res=Integer.MIN_VALUE;
		while(lo<=hi){
	        int mid = (lo+hi)/2;
	        if(a[mid]==x){
	            res = mid;
	            hi = mid - 1;
	        }
	        else if(a[mid]>x){
	            hi = mid - 1;
	        }
	        else{
	            lo = mid + 1;
	        }
	    }
	    return res==Integer.MIN_VALUE?lo:res;
	}
	public static int searchhigh(int x) {
		int lo=0, hi=a.length-1;
		int res=Integer.MIN_VALUE;
		while(lo<=hi){
	        int mid = (lo+hi)/2;
	        if(a[mid]==x){
	            res = mid;
	            lo=mid+1;
	        }
	        else if(a[mid]>x){
	            hi = mid - 1;
	        }
	        else{
	            lo = mid + 1;
	        }
	    }
	    return res==Integer.MIN_VALUE?hi:res;
	}
	public static long ct(int l, int r) {
		int lo=searchlow(l), hi=searchhigh(r);
		return hi-lo+1;
	}
    static long log2(long value) {
    return Long.SIZE-Long.numberOfLeadingZeros(value);
}

    static class Student
    {
        int id;
        //int x;
       String s;
        int y;

        Student(int id,String s,int y)
        {
            this.id = id;
            //this.x = x;
            this.s = s;
            this.y = y;

        }

    }

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

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

	return gcd(b%a, a);
    }

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

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

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

        return (long)result;

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

    }

    public static void primeFactors(int n,int x)
    {
        as = new ArrayList<>();

        // Print the number of 2s that divide n
        while (n%2==0)
        {

            as.add(2);
            //System.out.print(2 + " ");
            n /= 2;

        }

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

               // System.out.print(i + " ");

                as.add(i);
                n /= i;

            }

        }

        // This condition is to handle the case whien
        // n is a prime number greater than 2
        if (n >= 2)
        {

            as.add(n);
        }

    }
    static int digitsum(int x)

    {

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

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

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

    static boolean isprime(long n)
    {

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

    long i = 5;
   long w = 2;

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

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

    return true;
    }

    static boolean binarysearch(int []arr,int p,int n)
    {
        //ArrayList<Integer> as = new ArrayList<>();
        //as.addAll(0,at);
        //Collections.sort(as);
        boolean re = false;
        int st = 0;
        int end = n-1;

        while(st <= end)
        {
            int mid = (st+end)/2;

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

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

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

            re = true;
            break;
            }

        }
         return re;

    }

    /* Java program for Merge Sort */
static class MergeSort
{
    // Merges two subarrays of arr[].
    // First subarray is arr[l..m]
    // Second subarray is arr[m+1..r]
    void merge(int arr[], int l, int m, int r)
    {
        // Find sizes of two subarrays to be merged
        int n1 = m - l + 1;
        int n2 = r - m;

        /* Create temp arrays */
        int L[] = new int [n1];
        int R[] = new int [n2];

        /*Copy data to temp arrays*/
        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];

        /* Merge the temp arrays */

        // Initial indexes of first and second subarrays
        int i = 0, j = 0;

        // Initial index of merged subarry array
        int k = l;
        while (i < n1 && j < n2)
        {
            if (L[i] <= R[j])
            {
                arr[k] = L[i];
                i++;
            }
            else
            {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        /* Copy remaining elements of L[] if any */
        while (i < n1)
        {
            arr[k] = L[i];
            i++;
            k++;
        }

        /* Copy remaining elements of R[] if any */
        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    // Main function that sorts arr[l..r] using
    // merge()
    void sort(int arr[], int l, int r)
    {
        if (l < r)
        {
            // Find the middle point
            int m = (l+r)/2;

            // Sort first and second halves
            sort(arr, l, m);
            sort(arr , m+1, r);

            // Merge the sorted halves
            merge(arr, l, m, r);
        }
    }

    /* A utility function to print array of size n */

}

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

         // Java program to print all permutations using
// Heap's algorithm
static class HeapAlgo
{
   //static ArrayList<Integer> []ad;
	//Prints the array
	void printArr(int a[], int n)
	{

		for (int i=0; i<n; i++)
		{
			System.out.print(a[i] + " ");
		as1[p].add(a[i]);
		}
                p++;

		//System.out.println();
	}

	//Generating permutation using Heap Algorithm
	void heapPermutation(int a[], int size, int n)
	{
		// if size becomes 1 then prints the obtained
		// permutation

		if (size == 1)
		{
			printArr(a,n);

		}

		for (int i=0; i<size; i++)
		{
			heapPermutation(a, size-1, n);
                        p++;

			// if size is odd, swap first and last
			// element
			if (size % 2 == 1)
			{
				int temp = a[0];
				a[0] = a[size-1];
				a[size-1] = temp;
			}

			// If size is even, swap ith and last
			// element
			else
			{
				int temp = a[i];
				a[i] = a[size-1];
				a[size-1] = temp;
			}
		}
	}
        public static int lowerBound(int[] array, int length, int value) {
        int low = 0;
        int high = length-1;
        while (low < high) {
            final int mid = (low + high) / 2;
            if (value <= array[mid]) {
                high = mid;
            } else {
                low = mid + 1;
            }
        }
        return low;
  }
  public static int upperBound(int[] array, int length, int value) {
        int low = 0;
        int high = length-1;
        while (low < high) {
            final int mid = (low + high) / 2;
            if (value >= array[mid]) {
                low = mid + 1;
            } else {
                high = mid;
            }
        }
        return low;
    }

	// Driver code

}

// This code has been contributed by Amit Khandelwal.
// JAVA program for implementation of KMP pattern
// searching algorithm

static class KMP_String_Matching {
	boolean KMPSearch(String pat, String txt)
	{
            int f = 0;
		int M = pat.length();
		int N = txt.length();

		// create lps[] that will hold the longest
		// prefix suffix values for pattern
		int lps[] = new int[M];
		int j = 0; // index for pat[]

		// Preprocess the pattern (calculate lps[]
		// array)
		computeLPSArray(pat, M, lps);

		int i = 0; // index for txt[]
		while (i < N) {
			if (pat.charAt(j) == txt.charAt(i)) {
				j++;
				i++;
			}
			if (j == M) {
                            /*
				System.out.println("Found pattern "
								+ "at index " + (i - j));
                            */
                            f = 1;
                           // return true;
				j = lps[j - 1];
			}

			// mismatch after j matches
			else if (i < N && pat.charAt(j) != txt.charAt(i)) {
				// Do not match lps[0..lps[j-1]] characters,
				// they will match anyway
				if (j != 0)
					j = lps[j - 1];
				else
					i = i + 1;
			}
		}
                if(f==0)
                    return false;
                else
                    return true;
	}

	void computeLPSArray(String pat, int M, int lps[])
	{
		// length of the previous longest prefix suffix
		int len = 0;
		int i = 1;
		lps[0] = 0; // lps[0] is always 0

		// the loop calculates lps[i] for i = 1 to M-1
		while (i < M) {
			if (pat.charAt(i) == pat.charAt(len)) {
				len++;
				lps[i] = len;
				i++;
			}
			else // (pat[i] != pat[len])
			{
				// This is tricky. Consider the example.
				// AAACAAAA and i = 7. The idea is similar
				// to search step.
				if (len != 0) {
					len = lps[len - 1];

					// Also, note that we do not increment
					// i here
				}
				else // if (len == 0)
				{
					lps[i] = len;
					i++;
				}
			}
		}
	}

	// Driver program to test above function
        /*
	public static void main(String args[])
	{
		String txt = "ABABDABACDABABCABAB";
		String pat = "ABABCABAB";
		new KMP_String_Matching().KMPSearch(pat, txt);
	}
        */
}
// This code has been contributed by Amit Khandelwal.

}


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

public class Main {
    public static MyScanner sc = new MyScanner(System.in);
    public static PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] args) {
        int n = sc.nextint();
        int mod = sc.nextint();
        int[] dp1 = new int[n + 9];
        int[] dp2 = new int[n + 9];
        dp2[1] = 1;
        for(int i = 1; i <= n; i++){
            dp1[i] += dp1[i - 1];
            dp1[i] %= mod;
            dp2[i] = dp1[i];
            if(i == 1){
                dp2[i] = 1;
            }
            dp1[i + 1] += dp2[i];
            dp1[i + 1] %= mod;
            for(int j = 2; i * j <= n; j++){
                dp1[i * j] += dp2[i];
                dp1[i * j] %= mod;
                if((i + 1) * j <= n) {
                    dp1[(i + 1) * j] += mod - dp2[i];
                    dp1[(i + 1) * j] %= mod;
                }
            }
        }
        out.print(dp2[n]);
        out.close();
    }
}
class MyScanner {
    private BufferedReader br;
    private StringTokenizer tokenizer;

    public MyScanner(InputStream is) {
        br = new BufferedReader(new InputStreamReader(is));
    }

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

    public int nextint() {
        return Integer.parseInt(next());
    }
    public long nextlong() {
        return Long.parseLong(next());
    }
}