import java.util.HashMap;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.List;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Set;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.util.Collections;
import java.io.InputStream;

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

class TaskE_AnnAndCubics {

    List<Long> factorials;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int k = in.nextInt();
        long S = in.nextLong();

        factorials = new ArrayList<Long>();
        factorials.add(1L);
        for (int i = 2;; ++i) {
            factorials.add(factorials.get(factorials.size()-1) * i);
            if (factorials.get(factorials.size()-1) > S) {
                break;
            }
        }
        factorials.remove(factorials.size()-1);

        int[] a = Utils.readIntArray(in, n);

        int n2 = n / 2;
        int n1 = n - n2;

        HashMap<Long, HashMap<Integer, Long>> leftSide = buildIt(n1, ArrayUtils.subArray(a, 0, n1), S, k);
        HashMap<Long, HashMap<Integer, Long>> rightSide = buildIt(n2, ArrayUtils.subArray(a, n1, n), S, k);

        long res = 0;
        for (long keyLeft : leftSide.keySet()) {
            long needKey = S - keyLeft;
            if (needKey >= 0 && rightSide.containsKey(needKey)) {
                res += getIt(leftSide.get(keyLeft), rightSide.get(needKey), k);
            }
        }
        out.println(res);
    }

    private long getIt(HashMap<Integer, Long> left, HashMap<Integer, Long> right, int k) {
        long res = 0;
        for (int key : left.keySet()) {
            for (int key2 : right.keySet()) {
                if (key + key2 <= k) {
                    res += left.get(key) * right.get(key2);
                }
            }
        }
        return res;
    }

    private HashMap<Long, HashMap<Integer, Long>> buildIt(int n, int[] a, long S, int k) {
        HashMap<Long, HashMap<Integer, Long>> res = new HashMap<Long, HashMap<Integer, Long>>();

        for (int set = 0; set < (1 << n); ++set) {
            for (int subset = set; subset >= 0; subset = ((subset - 1) & set)) {
                if (Integer.bitCount(subset) > k) continue;
                long sum = 0;
                boolean badMask = false;
                for (int i = 0; i < n; ++i) {
                    if (BitUtils.checkBit(subset, i)) {
                        if (a[i] > factorials.size()) {
                            badMask = true;
                            break;
                        } else {
                            sum += factorials.get(a[i] - 1);
                        }
                    } else if (BitUtils.checkBit(set, i)) {
                        sum += a[i];
                    }
                    if (sum > S) {
                        badMask = true;
                        break;
                    }
                }
                if (!badMask) {
                    if (sum <= S) {
                        addToRes(res, Integer.bitCount(subset), sum);
                    }
                }
                if (subset == 0) break;
            }
        }
        return res;
    }

    private void addToRes(HashMap<Long, HashMap<Integer, Long>> dict, int k, long sum) {
        if (!dict.containsKey(sum)) {
            HashMap<Integer, Long> map = new HashMap<Integer, Long>();
            map.put(k, 1L);
            dict.put(sum, map);
        } else {
            HashMap<Integer, Long> map = dict.get(sum);
            if (!map.containsKey(k)) {
                map.put(k, 1L);
            } else {
                map.put(k, map.get(k) + 1);
            }
            dict.put(sum, map);
        }
    }

}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer stt;

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

    public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            return null;
        }
    }

    public String nextString() {
        while (stt == null || !stt.hasMoreTokens()) {
            stt = new StringTokenizer(nextLine());
        }
        return stt.nextToken();
    }

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

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

}

class Utils {
    public static int[] readIntArray(InputReader in, int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; ++i) {
            a[i] = in.nextInt();
        }
        return a;
    }

}

class ArrayUtils {

    public static int[] subArray(int[] a, int start, int finish) {
        int[] result = new int[finish - start];
        for (int i = start; i < finish; ++i) {
            result[i-start] = a[i];
        }
        return result;
    }

}

class BitUtils {
    public static boolean checkBit(int mask, int bit) {
        return (mask & (1 << bit)) > 0;
    }

}


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

public class MadokaAndTheBestUniversity {
	private static final int N_MAX = 100_000;

	private static final int MOD = 1_000_000_007;

	private static final IntList[] FACTORS = new IntList[N_MAX + 1];
	static {
		for (int i = 1; i <= N_MAX; ++i) {
			FACTORS[i] = new IntList();
		}
		for (int i = 1; i <= N_MAX; ++i) {
			for (int j = i; j <= N_MAX; j += i) {
				FACTORS[j].add(i);
			}
		}
	}

	private static final int[] TOTIENT = new int[N_MAX + 1];
	static {
		for (int i = 1; i < TOTIENT.length; ++i) {
			TOTIENT[i] = i;
		}
		for (int i = 2; i < TOTIENT.length; ++i) {
			if (TOTIENT[i] != i) {
				continue;
			}
			for (int j = i; j < TOTIENT.length; j += i) {
				TOTIENT[j] -= TOTIENT[j] / i;
			}
		}
	}

	public static void solve(FastIO io) {
		final int N = io.nextInt();

		long total = 0;
		for (int c = 1; c + 2 <= N; ++c) {
			int rem = N - c;
			IntList facs = FACTORS[rem];
			for (int i = facs.size() - 2; i >= 0; --i) {
				int fi = facs.get(i);
				total += 1L * lcm(c, fi) * TOTIENT[rem / fi];
				total %= MOD;
			}
		}
		io.println(total);
	}

	/**
	 * Computes the GCD (greatest common denominator) between two numbers.
	 */
	public static int gcd(int a, int b) {
		if (a < b)
			return gcd(b, a);

		int r = a % b;
		if (r == 0)
			return b;

		return gcd(b, r);
	}

	/**
	 * Computes the LCM (least common multiple) between all the numbers.
	 */
	public static int lcm(int... arr) {
		int lcm = arr[0];
		for (int i = 1; i < arr.length; i++)
			lcm = lcm * arr[i] / gcd(lcm, arr[i]);

		return lcm;
	}

	private static class IntList extends ArrayList<Integer> {
		private static final long serialVersionUID = 8986468115134862220L;
	}

	public static class FastIO {
		private InputStream reader;
		private PrintWriter writer;

		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastIO(InputStream r, OutputStream w) {
			reader = r;
			writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(w)));
		}

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

		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 String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

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

		// TODO: read this byte-by-byte like the other read functions.
		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			return nextIntArray(n, 0);
		}

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

		public long[] nextLongArray(int n) {
			return nextLongArray(n, 0);
		}

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

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

		public void print(Object... objects) {
			for (int i = 0; i < objects.length; i++) {
				if (i != 0) {
					writer.print(' ');
				}
				writer.print(objects[i]);
			}
		}

		public void println(Object... objects) {
			print(objects);
			writer.println();
		}

		public void printArray(int[] arr) {
			for (int i = 0; i < arr.length; i++) {
				if (i != 0) {
					writer.print(' ');
				}
				writer.print(arr[i]);
			}
		}

		public void printArray(long[] arr) {
			for (int i = 0; i < arr.length; i++) {
				if (i != 0) {
					writer.print(' ');
				}
				writer.print(arr[i]);
			}
		}

		public void printlnArray(int[] arr) {
			printArray(arr);
			writer.println();
		}

		public void printlnArray(long[] arr) {
			printArray(arr);
			writer.println();
		}

		public void printf(String format, Object... args) {
			print(String.format(format, args));
		}

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

	public static void main(String[] args) {
		FastIO io = new FastIO(System.in, System.out);
		solve(io);
		io.flush();
	}
}


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

public class E {

    static int N, M, K;
    static String s;
    static StringTokenizer st;
    static int[] d;
    static long[] fact;

    static HashSet<Integer> hm = new HashSet();
    static long c(int[] d) {
        //System.out.println(Arrays.toString(d));
        int l = Arrays.hashCode(d);
        if(hm.contains(l)){
            return 0;
        }
        long top = 0;
        long bot = 1;
        int sum = 0;
        for (int i = 0; i < d.length; i++) {
            sum += d[i];
            bot *= fact[d[i]];
        }
        //System.out.println(sum);
        long ans = fact[sum];
        for (int i = 0; i < d.length; i++) {
            ans /= fact[d[i]];
        }
        //long ans = top / bot;
        //System.out.println(top + " " + bot);
        //System.out.println(ans);

        long ans2 = 0;
        if (d[0] > 0) {;
            ans2 = fact[sum-1];
            d[0]--;
            for (int i = 0; i < d.length; i++) {
                ans2 /= fact[d[i]];
            }
            d[0]++;
        }

        hm.add(l);

        //System.out.println(Arrays.toString(d) + " " + sum + " " + ans + " " + ans2);
        return ans-ans2;
    }

    public static long DFS(int[] d) {
        //System.out.println(Arrays.toString(d));
        long ans = c(d);
        //System.out.println(ans);
        for (int i = 0; i < d.length; i++) {
            if (d[i] > 1) {
                int[] d2 = new int[d.length];
                for (int j = 0; j < d.length; j++) {
                    d2[j] = d[j];
                }
                d2[i]--;
                ans += DFS(d2);
            }
        }
        //System.out.println("returning " + ans);
        if (ans < 0) {
            while (true) {

            }
        }

        return ans;
    }

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

        fact = new long[20];
        fact[0] = 1;

        for (int i = 1; i < 20; i++) {
            fact[i] = fact[i - 1] * i;
        }

        //System.out.println(Arrays.toString(fact));
        //System.out.println(fact[18]);
        int[] d = new int[10];
        long N = Long.parseLong(br.readLine());
        while (N > 0) {
            d[(int) (N % 10)]++;
            N /= 10;
        }

        long ans = DFS(d);
        System.out.println(ans);
        //System.out.println(fact[19]);
        //System.out.println(c(d));

        out.close();
    }
}


import java.util.*;

public class CodeForces {
	Scanner scan = new Scanner(System.in);

	private static long gcd(long a, long b)
	{
	    while (b > 0)
	    {
	        long temp = b;
	        b = a % b;
	        a = temp;
	    }
	    return a;
	}

	private static long gcd(long[] input)
	{
	    long result = input[0];
	    for(int i = 1; i < input.length; i++) result = gcd(result, input[i]);
	    return result;
	}

	private static long lcm(long a, long b)
	{
	    return a * (b / gcd(a, b));
	}

	private static long lcm(long[] input)
	{
	    long result = input[0];
	    for(int i = 1; i < input.length; i++) result = lcm(result, input[i]);
	    return result;
	}

	CodeForces()
	{
	String s,x,y,a,b;
	s = scan.nextLine();
	String [] temp = s.split(" ");
	x = temp[0];
	y = temp[1];
	a = temp[2];
	b = temp[3];
	boolean flag = false;
	long[] input = new long[2];
	input[0] = Integer.parseInt(x);
	input[1] = Integer.parseInt(y);
	long kpk = lcm(input);
	long counter = 0;
	long start = 0;
	for(long i=Integer.parseInt(a);i<=Integer.parseInt(b)&&!flag;i++)
	{
		if(i%Integer.parseInt(y)==0&&i%Integer.parseInt(x)==0)
		{
			++counter;
			flag = true;
			start = i;
		}
	}
	long remain = flag?(Integer.parseInt(b) - start) / kpk:0;
	counter+=remain;
	System.out.println(counter);
	}
	public static void main(String[] args)
	{
	new CodeForces();
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.PrintWriter;
import java.util.TreeMap;
public class E1113
{
    static class QN{
        int index;
        long sum;
        QN(int in,long an){
            index=in;
            sum=an;
        }
    }
    static class SegmentTree{
        long sum,pmin,lazy;
        int st,en;
        boolean rem;
        SegmentTree left,right;
        SegmentTree(int _st,int _en,long _v){
            st=_st;
            en=_en;
            lazy=_v;
            rem=true;
            sum=(en-st+1)*lazy;
            pmin=Math.min(lazy,sum);
        }
        long pmin(){
            return rem?(Math.min(lazy,(en-st+1)*lazy)):(pmin);
        }
        long sum(){
            return rem?((en-st+1)*lazy):(sum);
        }
        void update(int l,int r,long v){
            //completely outside
            if(l>en||r<st)
                return;
            //completely inside
            if(l<=st&&r>=en){
                //update lazy;
                lazy=v;
                rem=true;
                return;
            }
            //partial cover
            lazyPropagate();
            left.update(l, r, v);
            right.update(l, r, v);
            sum=left.sum()+right.sum();
            pmin=Math.min(left.pmin(),left.sum()+right.pmin());
            return;
        }
        void lazyPropagate(){
            if(left==null){
                int mid=(st+en)>>1;
                left=new SegmentTree(st,mid,lazy);
                right=new SegmentTree(mid+1,en,lazy);
            }else if(rem){
                left.lazy=lazy;
                right.lazy=lazy;
                left.rem=true;
                right.rem=true;
            }
            if(rem){
                sum=(en-st+1)*lazy;
                pmin=Math.min(lazy,sum);
            }
            rem=false;
        }
        /**returns least index which has value <= given value**/
        QN query(int l,int r,long v,long su){
            //no cover
            if(st>r||en<l)
                return new QN(-1,0);
            //full cover
            if(l<=st&&en<=r){
                if(su+pmin()<=v)
                    return query2(v,su);
                return new QN(-1,su+sum());
            }
            lazyPropagate();

            QN q1=left.query(l,r,v,su);
            if(q1.index!=-1)
                return q1;
            q1=right.query(l,r,v,q1.sum);
            return q1;
        }
        QN query2(long v,long su){
            if(st==en)
                return new QN(st,su+sum());
            lazyPropagate();
            if(left.pmin()+su<=v)
                return left.query2(v,su);
            else
                return right.query2(v,su+left.sum());

        }

    }
    static class Scanner
    {
        BufferedReader br;
        StringTokenizer tk=new StringTokenizer("");
        public Scanner(InputStream is)
        {
            br=new BufferedReader(new InputStreamReader(is));
        }
        public int nextInt() throws IOException
        {
            if(tk.hasMoreTokens())
                return Integer.parseInt(tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return nextInt();
        }
        public long nextLong() throws IOException
        {
            if(tk.hasMoreTokens())
                return Long.parseLong(tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return nextLong();
        }
        public String next() throws IOException
        {
            if(tk.hasMoreTokens())
                return (tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return next();
        }
        public String nextLine() throws IOException
        {
            tk=new StringTokenizer("");
            return br.readLine();
        }
        public double nextDouble() throws IOException
        {
            if(tk.hasMoreTokens())
                return Double.parseDouble(tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return nextDouble();
        }
        public char nextChar() throws IOException
        {
            if(tk.hasMoreTokens())
                return (tk.nextToken().charAt(0));
            tk=new StringTokenizer(br.readLine());
            return nextChar();
        }
        public int[] nextIntArray(int n) throws IOException
        {
            int a[]=new int[n];
            for(int i=0;i<n;i++)
                a[i]=nextInt();
            return a;
        }
        public long[] nextLongArray(int n) throws IOException
        {
            long a[]=new long[n];
            for(int i=0;i<n;i++)
                a[i]=nextLong();
            return a;
        }
        public int[] nextIntArrayOneBased(int n) throws IOException
        {
            int a[]=new int[n+1];
            for(int i=1;i<=n;i++)
                a[i]=nextInt();
            return a;
        }
        public long[] nextLongArrayOneBased(int n) throws IOException
        {
            long a[]=new long[n+1];
            for(int i=1;i<=n;i++)
                a[i]=nextLong();
            return a;
        }

    }

    public static void main(String args[]) throws IOException
    {
        Scanner in=new Scanner(System.in);
        PrintWriter out=new PrintWriter(System.out);
        SegmentTree st=new SegmentTree(1,1000000000,0);
        int q=in.nextInt();
        TreeMap<Integer,Integer> mp=new TreeMap<>();
        mp.put(0,0);
        mp.put(1000000001,0);
        while(q--!=0){
            int tp=in.nextInt();
            switch(tp){
                case 1:
                    int tm=in.nextInt();
                    int vl=in.nextInt();
                    int nxt=mp.higherKey(tm)-1;
                    st.update(tm, nxt, vl);
                    mp.put(tm,vl);
                    break;
                case 2:
                    int tc=in.nextInt();
                    int vp=mp.lowerEntry(tc).getValue();
                    int net=mp.higherKey(tc)-1;
                    st.update(tc, net, vp);
                    mp.remove(tc);
                    break;
                case 3:
                    int l=in.nextInt();
                    int lc=l;
                    l=mp.ceilingKey(l);
                    int r=in.nextInt();
                    int v=in.nextInt();
                    if(v==0){
                        out.println(lc);
                        continue;
                    }
                    if(l>=r){
                        out.println(-1);
                        continue;
                    }
                    QN aa=st.query(l, r-1, -v, 0);
                    if(aa.index==-1)
                        out.println(-1);
                    else{
                        int spd=mp.floorEntry(aa.index).getValue();
                        double remv=-(v+(aa.sum-spd));
                        double anss=aa.index;
                        anss+=remv/spd;
                        out.println(anss);

                    }

            }

        }
        out.close();
    }

}


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

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

    int compress(int[] aa, int n) {
        Random rand = new Random();
        for (int i = 0; i < n; i++) {
            int j = rand.nextInt(i + 1);
            int tmp = aa[i]; aa[i] = aa[j]; aa[j] = tmp;
        }
        Arrays.sort(aa, 0, n);
        int m = 1;
        for (int i = 1; i < n; i++)
            if (aa[i] != aa[i - 1])
                aa[m++] = aa[i];
        return m;
    }
    void main() {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int n = a + b;
        int s = (int) Math.sqrt(n) + 1;
        int[] gg = new int[s + s];
        int m = 0;
        for (int g = 1; g <= s; g++)
            gg[m++] = g;
        for (int k = 1; k <= s; k++) {
            int g = n / k;
            gg[m++] = g;
        }
        m = compress(gg, m);
        int ans = 0;
        for (int h = 0; h < m; h++) {
            int g = gg[h];
            int al = (int) ((a + (long) g) / (g + 1));
            int bl = (int) ((b + (long) g) / (g + 1));
            int ar = a / g;
            int br = b / g;
            if (al <= ar && bl <= br) {
                int l = Math.max(n / (g + 1) + 1, al + bl);
                int r = Math.min(n / g, ar + br);
                if (l <= r)
                    ans += r - l + 1;
            }
        }
        println(ans);
    }
}


import java.io.*;
import java.util.*;
import java.lang.*;
import java.math.*;
import java.text.DecimalFormat;
import java.lang.reflect.Array;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
public class Codeforces{
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static long MOD = (long)(1e9+7);
	static long MOD2 = MOD*MOD;
	//static long MOD = 998244353;
	static FastReader sc = new FastReader();
	static int pInf = Integer.MAX_VALUE;
	static int nInf = Integer.MIN_VALUE;
	public static void main(String[] args){
		int test = 1;
		//test = sc.nextInt();
		while(test-->0){
			long a = sc.nextLong();
			long b = sc.nextLong();
			long n = sc.nextLong();
			long x = sc.nextLong();
			if(a==1) {
				out.println(add(x, mul(n, b)));
				continue;
			}
			long a1 = mul(fastExpo(a, n), x);
			long a2 = mul(b, mul((fastExpo(a, n)-1),finextDoubleMMI_fermat(a-1, (int)MOD)));
			out.println(add(a1, a2));
		}
		out.close();
	}
	public static long solve(long a, long b, long x, long y, long n) {
		if(a-x<n) {
			n = n-(a-x);
			a = x;
			b = Math.max(y, b-n);
		}
		else {
			a = a-n;
		}
		return a*b;
	}
	public static int lowerBound(int key, ArrayList<Integer> A) {
		int s = 0;
		int e = A.size()-1;
		if(e==-1) {
			return 0;
		}
		int ans = -1;
		while(s<=e) {
			int m = s+(e-s)/2;
			if(A.get(m)>=key) {
				ans = m;
				e = m-1;
			}
			else {
				s = m+1;
			}
		}
		return ans==-1?s:ans;
	}
	public static int upperBound(int key, ArrayList<Integer> A) {
		int s = 0;
		int e = A.size()-1;
		if(e==-1) {
			return 0;
		}
		int ans = -1;
		while(s<=e) {
			int m = s+(e-s)/2;
			if(A.get(m)>key) {
				ans = m;
				e = m-1;
			}
			else {
				s = m+1;
			}
		}
		return ans==-1?s:ans;
	}
	public static long c2(long n) {
		if((n&1)==0) {
			return mul(n/2, n-1);
		}
		else {
			return mul(n, (n-1)/2);
		}
	}
	public static long mul(long a, long b){
	    return ((a%MOD)*(b%MOD))%MOD;
	}
	public static long add(long a, long b){
	    return ((a%MOD)+(b%MOD))%MOD;
	}
	public static long sub(long a, long b){
	    return ((a%MOD)-(b%MOD))%MOD;
	}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Integer.lowestOneBit(i)   Equals k where k is the position of the first one in the binary
//Integer.highestOneBit(i)  Equals k where k is the position of the last one in the binary
//Integer.bitCount(i)       returns the number of one-bits
//Collections.sort(A,(p1,p2)->(int)(p2.x-p1.x)) To sort ArrayList in descending order wrt values of x.
//            Arrays.parallelSort(a,new Comparator<TPair>() {
//      		public int compare(TPair a,TPair b) {
//        			if(a.y==b.y) return a.x-b.x;
//        			return b.y-a.y;
//        		}
//        	});
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//PrimeFactors
    public static ArrayList<Long> primeFactors(long n) {
        ArrayList<Long> arr = new ArrayList<>();
        if (n % 2 == 0)
            arr.add((long) 2);
        while (n % 2 == 0)
            n /= 2;
        for (long i = 3; i <= Math.sqrt(n); i += 2) {
            int flag = 0;
            while (n % i == 0) {
                n /= i;
                flag = 1;
            }
            if (flag == 1)
                arr.add(i);
        }
        if (n > 2)
            arr.add(n);
        return arr;
    }
//Pair Class
	static class Pair implements Comparable<Pair>{
		int x;
		int y;
		int len;
		public Pair(int x, int y) {
			this.x = x;
			this.y = y;
			this.len = y-x+1;
		}
		/*@Override
		public int compareTo(Pair o) {
			if(this.x==o.x){
			    return (this.y-o.y);
			}
			return (this.x-o.x);
		}*/
		@Override
		public int compareTo(Pair o) {
			if(this.len==o.len) {
				return this.x-o.x;
			}
			else {
				return o.len-this.len;
			}
		}
	}
	static class TPair implements Comparable<TPair>{
		int two;
		int three;
		int prime;
		public TPair(int two, int three, int prime) {
			this.two = two;
			this.three = three;
			this.prime = prime;
		}
		@Override
		public int compareTo(TPair o) {
			if(this.three==o.three){
			    return (this.two-o.two);
			}
			return -1*(this.three-o.three);
		}
	}
//nCr
	static long ncr(long n, long k) {
        long ret = 1;
        for (long x = n; x > n - k; x--) {
            ret *= x;
            ret /= (n - x + 1);
        }

        return ret;
    }
	static long finextDoubleMMI_fermat(long n,int M)
    {
        return fastExpo(n,M-2);
    }

    static long nCrModPFermat(int n, int r, int p)
    {
        if (r == 0)
            return 1;
        long[] fac = new long[n+1];
        fac[0] = 1;
        for (int i = 1 ;i <= n; i++)
            fac[i] = fac[i-1] * i % p;
        return (fac[n]* finextDoubleMMI_fermat(fac[r], p)% p * finextDoubleMMI_fermat(fac[n-r], p) % p) % p;
    }
//Kadane's Algorithm
    static long maxSubArraySum(ArrayList<Long> a) {
    	if(a.size()==0) {
    		return 0;
    	}
    	long max_so_far = a.get(0);
    	long curr_max = a.get(0);
    	for (int i = 1; i < a.size(); i++) {
           curr_max = Math.max(a.get(i), curr_max+a.get(i));
           max_so_far = Math.max(max_so_far, curr_max);
    	}
    	return max_so_far;
    }
//Shuffle Sort
    static final Random random=new Random();
	static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
//Merge Sort
	static void merge(long 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 */
        long L[] = new long [n1];
        long R[] = new long [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()
    static void sort(long 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);
        }
    }
//Brian Kernighans Algorithm
    static long countSetBits(long n){
        if(n==0) return 0;
        return 1+countSetBits(n&(n-1));
    }
//Factorial
    static long factorial(long n){
        if(n==1) return 1;
        if(n==2) return 2;
        if(n==3) return 6;
        return n*factorial(n-1);
    }
//Euclidean Algorithm
    static long gcd(long A,long B){
        if(B==0) return A;
        return gcd(B,A%B);
    }
//Modular Exponentiation
    static long fastExpo(long x,long n){
        if(n==0) return 1;
        if((n&1)==0) return fastExpo((x*x)%MOD,n/2)%MOD;
        return ((x%MOD)*fastExpo((x*x)%MOD,(n-1)/2))%MOD;
    }
//AKS Algorithm
    static boolean isPrime(long n){
        if(n<=1) return false;
        if(n<=3) return true;
        if(n%2==0 || n%3==0) return false;
        for(int i=5;i<=Math.sqrt(n);i+=6)
            if(n%i==0 || n%(i+2)==0) return false;
        return true;
    }
//Reverse an array
    static <T> void reverse(T arr[],int l,int r){
    	Collections.reverse(Arrays.asList(arr).subList(l, r));
    }
  //Print array
    static void print1d(int arr[]) {
    	out.println(Arrays.toString(arr));
    }
    static void print2d(int arr[][]) {
    	for(int a[]: arr) out.println(Arrays.toString(a));
    }
//Sieve of eratosthenes
    static int[] findPrimes(int n){
        boolean isPrime[]=new boolean[n+1];
        ArrayList<Integer> a=new ArrayList<>();
        int result[];
        Arrays.fill(isPrime,true);
        isPrime[0]=false;
        isPrime[1]=false;
        for(int i=2;i*i<=n;++i){
            if(isPrime[i]==true){
                for(int j=i*i;j<=n;j+=i) isPrime[j]=false;
            }
        }
        for(int i=0;i<=n;i++) if(isPrime[i]==true) a.add(i);
        result=new int[a.size()];
        for(int i=0;i<a.size();i++) result[i]=a.get(i);
        return result;

    }
//Indivisual factors of all nos till n
    static ArrayList<Integer>[] indiFactors(int n){
    	ArrayList<Integer>[] A = new ArrayList[n+1];
    	for(int i = 0; i <= n; i++) {
    		A[i] = new ArrayList<>();
    	}
    	int[] sieve = new int[n+1];
    	for(int i=2;i<=n;i++) {
       		if(sieve[i]==0) {
       			for(int j=i;j<=n;j+=i) if(sieve[j]==0) {
       				//sieve[j]=i;
       				A[j].add(i);
       			}
       		}
       	}
    	return A;
    }
//Segmented Sieve
    static boolean[] segmentedSieve(long l, long r){
    	boolean[] segSieve = new boolean[(int)(r-l+1)];
    	Arrays.fill(segSieve, true);
    	int[] prePrimes = findPrimes((int)Math.sqrt(r));
    	for(int p:prePrimes) {
    		long low = (l/p)*p;
    		if(low < l) {
    			low += p;
    		}
    		if(low == p) {
    			low += p;
    		}
    		for(long j = low; j<= r; j += p) {
    			segSieve[(int) (j-l)] = false;
    		}
    	}
    	if(l==1) {
    		segSieve[0] = false;
    	}
    	return segSieve;
    }
//Euler Totent function
    static long countCoprimes(long n){
        ArrayList<Long> prime_factors=new ArrayList<>();
        long x=n,flag=0;
        while(x%2==0){
            if(flag==0) prime_factors.add(2L);
            flag=1;
            x/=2;
        }
        for(long i=3;i*i<=x;i+=2){
            flag=0;
            while(x%i==0){
                if(flag==0) prime_factors.add(i);
                flag=1;
                x/=i;
            }
        }
        if(x>2) prime_factors.add(x);
        double ans=(double)n;
        for(Long p:prime_factors){
            ans*=(1.0-(Double)1.0/p);
        }
        return (long)ans;
    }
	static long modulo = (long)1e9+7;
	public static long modinv(long x){
	    return modpow(x, modulo-2);
	}
	public static long modpow(long a, long b){
	    if(b==0){
	        return 1;
	    }
	    long x = modpow(a, b/2);
	    x = (x*x)%modulo;
	    if(b%2==1){
	        return (x*a)%modulo;
	    }
	    return x;
	}
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
		//it reads the data about the specified point and divide the data about it ,it is quite fast
		//than using direct

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

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

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

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

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

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


import java.util.Scanner;

public class Main2 {
	public static void TokitsukazeAndEnhancement573() {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int add=0;
		if(getCategory(n+1)<getCategory(n)) {
			n++;
			add++;
			if(getCategory(n+1)<getCategory(n)) {
				n++;
				add++;
			}
		}
		else if(getCategory(n+2)<getCategory(n)) {
			n+=2;
			add+=2;

		}
		System.out.println(add+" "+getCategory(n));

	}
	public static char getCategory(int n) {
		if(n%4==1)
			return 'A';
		else if(n%4==3)
			return 'B';
		else if(n%4==2)
			return 'C';

			return 'D';

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

}


/*
 * Author: Minho Kim (ISKU)
 * Date: March 5, 2018
 * E-mail: minho.kim093@gmail.com
 *
 * https://github.com/ISKU/Algorithm
 * http://codeforces.com/problemset/problem/931/A
 */

import java.util.*;

public class A {
	public static void main(String... args) {
		Scanner sc = new Scanner(System.in);
		int first = sc.nextInt();
		int second = sc.nextInt();

		if (first > second) {
			int temp = second;
			second = first;
			first = temp;
		}

		int ii = 1, jj = 1;
		int isum = 0, jsum = 0;
		for (int i = first, j = second; true;) {
			i++;
			isum += ii++;
			if (i == j)
				break;
			j--;
			jsum += jj++;
			if (i == j)
				break;
		}

		System.out.print(isum + jsum);
	}
}


import java.util.*;
import java.io.*;
import java.math.*;
public class Solution{

    static void affiche(int n,PrintWriter out){
        for(int i=0;i<n/2;i++){
            out.print("4");
        }
        for(int i=0;i<n/2;i++){
            out.print("7");
        }
    }

    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        //StringTokenizer st = new StringTokenizer(br.readLine());

        PrintWriter out = new PrintWriter(System.out);

        //int n = Integer.parseInt(st.nextToken());
        String s = br.readLine();
        int n = s.length();
        int last = -1;
        if(n%2==1){
            n++;
            affiche(n,out);
        }else{
            int[] a = new int[n];
            for(int i=0;i<n;i++){
                a[i] = (int)(s.charAt(i)-'0');
            }
            boolean ok = true;;
            for(int i=0;i<n;i++){
                if(a[i]!=4 && a[i]!=7){
                    ok = false;
                    break;
                }
            }
            int four = 0;
            int seven = 0;
            for(int i=0;i<n;i++){
                if(a[i]==4) four++;
                else seven++;
            }
            if(four!=seven) ok = false;

            if(ok){
                out.print(s);
            }else{

                last = -1;
                four = 0;
                seven = 0;
                for(int i=0;i<n;i++){
                    if(a[i]>7) break;
                    if(a[i]!=4 && a[i]!=7){
                        if(a[i]<4) four++;
                        else seven++;
                        if(four+n-i-1>=seven) last = i;
                        break;
                    }
                    if(a[i]==4){
                        if(four+n-i-1>=seven+1) last = i;
                        four++;
                    }else seven++;

                    if(four+n-i-1<seven) break;

                }

                if(last==-1) {
                    affiche(n+2,out);
                }else{

                    four = 0;
                    seven = 0;
                    for(int i=0;i<last;i++){
                        out.print(a[i]);
                        if(a[i]==4) four++;
                        else seven++;
                    }
                    if(a[last]<4){
                        out.print("4");
                        four++;
                    }
                    else{
                        out.print("7");
                        seven++;
                    }

                    for(int i=0;i<n/2 - four;i++){
                        out.print("4");
                    }
                    for(int i=0;i<n/2 - seven;i++){
                        out.print("7");
                    }

                }
            }
        }
        out.println("");

        out.flush();
    }

}


import java.util.*;
import java.lang.*;
import java.io.*;
public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int c = 0, len = Integer.parseInt(br.readLine());
		String s = br.readLine();
		for(int i = 0;i < len;i++)
		{
		    char ch = s.charAt(i);
		    if(ch == '0')
		    {
		        if(c > 0)
		        {
		            System.out.print(c);
		            c = 0;
		        }
		        if(i == len - 1 || s.charAt(i+1) == '0')
		        {
		            System.out.print("0");
		        }
		    }
		    else
		    {
		        c++;
		    }
		}
		if(s.charAt(len-1)== '1')
		System.out.println(c);
		else
		System.out.println();
	}
}


import java.util.Scanner;

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

		int m = Integer.parseInt(kboard.nextLine());

		int[] fives = {5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125};

		int ans = -1;
		for (int i = 1; i <= m * 5; i++) {
			int sum = 0;
			for (Integer j: fives) {
				sum += i / j;
			}
			if (sum == m) {
				ans = i;
				break;
			}
		}
		if (ans == -1) {
			System.out.println("0");
		} else {
			if (ans == 1) {
				System.out.println("4");
				System.out.println("1 2 3 4");
			} else {
				System.out.println("5");
				for (int i = 0; i < 5; i++) {
					System.out.print((ans + i) + " ");
				}
			}
		}
	}
}


//package CP.Ladder11;

import java.io.*;
import java.util.*;
import java.util.stream.IntStream;

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

@SuppressWarnings("ALL")
public class ABusinessTrip {
    public static void main(String[] $) throws IOException {
        ABusinessTrip o = new ABusinessTrip();
        o.main();
        out.flush();
        out.close();
    }

    void main() throws IOException {
        int k = in.ri();
        int[] a = in.ria(12);
        Arrays.sort(a);
        ARR.reverse(a);
        int ans = 0;
        int count = 0;
        for (int i = 0; i < 12; i++) {
            if (ans < k) {
                ans += a[i];
                count++;
            } else {
                break;
            }
        }
        if (ans < k) out.prln(-1);
        else out.prln(count);
    }

    static BufferedReader __in = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter __out = new PrintWriter(new OutputStreamWriter(System.out));
    static StringTokenizer input;
    static Random __rand = new Random();
    // constants
    static final int IBIG = 1000000007;
    static final int IMAX = 2147483647;
    static final int IMIN = -2147483648;
    static final long LMAX = 9223372036854775807L;
    static final long LMIN = -9223372036854775808L;

    //Fast Reader Class
    /*static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

    //Input fxs
    static class in {
        // input
        static void r() throws IOException {
            input = new StringTokenizer(rline());
        }

        static int ri() throws IOException {
            return Integer.parseInt(rline());
        }

        static long rl() throws IOException {
            return Long.parseLong(rline());
        }

        static double rd() throws IOException {
            return Double.parseDouble(rline());
        }

        static int[] ria(int n) throws IOException {
            int[] a = new int[n];
            r();
            for (int i = 0; i < n; ++i) a[i] = ni();
            return a;
        }

        static int[] riam1(int n) throws IOException {
            int[] a = new int[n];
            r();
            for (int i = 0; i < n; ++i) a[i] = ni() - 1;
            return a;
        }

        static long[] ria1i(long n) throws IOException {
            long[] a = new long[(int) n + 1];
            r();
            for (int i = 1; i <= n; i++) a[i] = nl();
            return a;
        }

        static long[] rla(int n) throws IOException {
            long[] a = new long[n];
            r();
            for (int i = 0; i < n; ++i) a[i] = nl();
            return a;
        }

        static double[] rda(int n) throws IOException {
            double[] a = new double[n];
            r();
            for (int i = 0; i < n; ++i) a[i] = nd();
            return a;
        }

        static char[] rcha() throws IOException {
            return rline().toCharArray();
        }

        static ArrayList<Integer> riaa(int n) throws IOException {
            ArrayList<Integer> a = new ArrayList<>();
            r();
            for (int i = 0; i < n; i++) a.add(ni());
            return a;
        }

        static String rline() throws IOException {
            return __in.readLine();
        }

        static String n() {
            return input.nextToken();
        }

        static int rni() throws IOException {
            r();
            return ni();
        }

        static int ni() {
            return Integer.parseInt(n());
        }

        static long rnl() throws IOException {
            r();
            return nl();
        }

        static long nl() {
            return Long.parseLong(n());
        }

        static double rnd() throws IOException {
            r();
            return nd();
        }

        static double nd() {
            return Double.parseDouble(n());
        }

        static List<List<Integer>> rg(int n, int m) throws IOException {
            List<List<Integer>> g = GR.g(n);
            for (int i = 0; i < m; ++i) GR.c(g, rni() - 1, ni() - 1);
            return g;
        }

        static void rg(List<List<Integer>> g, int m) throws IOException {
            for (int i = 0; i < m; ++i) GR.c(g, rni() - 1, ni() - 1);
        }

        static List<List<Integer>> rdg(int n, int m) throws IOException {
            List<List<Integer>> g = GR.g(n);
            for (int i = 0; i < m; ++i) GR.cto(g, rni() - 1, ni() - 1);
            return g;
        }

        static void rdg(List<List<Integer>> g, int m) throws IOException {
            for (int i = 0; i < m; ++i) GR.cto(g, rni() - 1, ni() - 1);
        }

        static List<Set<Integer>> rsg(int n, int m) throws IOException {
            List<Set<Integer>> g = GR.sg(n);
            for (int i = 0; i < m; ++i) GR.c(g, rni() - 1, ni() - 1);
            return g;
        }

        static void rsg(List<Set<Integer>> g, int m) throws IOException {
            for (int i = 0; i < m; ++i) GR.c(g, rni() - 1, ni() - 1);
        }

        static List<Set<Integer>> rdsg(int n, int m) throws IOException {
            List<Set<Integer>> g = GR.sg(n);
            for (int i = 0; i < m; ++i) GR.cto(g, rni() - 1, ni() - 1);
            return g;
        }

        static void rdsg(List<Set<Integer>> g, int m) throws IOException {
            for (int i = 0; i < m; ++i) GR.cto(g, rni() - 1, ni() - 1);
        }

        static int[][] rim(int n, int m) throws IOException {
            int[][] a = new int[n][m];
            for (int i = 0; i < n; i++) {
                in.r();
                for (int j = 0; j < m; j++) {
                    a[i][j] = in.ni();
                }
            }
            return a;
        }
    }

    //Output fxs
    static class out {
        // output
        static void pr(int i) {
            __out.print(i);
        }

        static void prln(int i) {
            __out.println(i);
        }

        static void pr(long l) {
            __out.print(l);
        }

        static void prln(long l) {
            __out.println(l);
        }

        static void pr(double d) {
            __out.print(d);
        }

        static void prln(double d) {
            __out.println(d);
        }

        static void pr(char c) {
            __out.print(c);
        }

        static void prln(char c) {
            __out.println(c);
        }

        static void pr(char[] s) {
            __out.print(new String(s));
        }

        static void prln(char[] s) {
            __out.println(new String(s));
        }

        static void pr(String s) {
            __out.print(s);
        }

        static void prln(String s) {
            __out.println(s);
        }

        static void pr(Object o) {
            __out.print(o);
        }

        static void prln(Object o) {
            __out.println(o);
        }

        static void prln() {
            __out.println();
        }

        static void pryes() {
            prln("yes");
        }

        static void pry() {
            prln("Yes");
        }

        static void prY() {
            prln("YES");
        }

        static void prno() {
            prln("no");
        }

        static void prn() {
            prln("No");
        }

        static void prN() {
            prln("NO");
        }

        static void pryesno(boolean b) {
            prln(b ? "yes" : "no");
        }

        ;

        static void pryn(boolean b) {
            prln(b ? "Yes" : "No");
        }

        static void prYN(boolean b) {
            prln(b ? "YES" : "NO");
        }

        static void prln(int... a) {
            for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i) ;
            if (a.length > 0) prln(a[a.length - 1]);
            else prln();
        }

        static void prln(long... a) {
            for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i) ;
            if (a.length > 0) prln(a[a.length - 1]);
            else prln();
        }

        static void prln(double... a) {
            for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i) ;
            if (a.length > 0) prln(a[a.length - 1]);
            else prln();
        }

        static <T> void prln(Collection<T> c) {
            int n = c.size() - 1;
            Iterator<T> iter = c.iterator();
            for (int i = 0; i < n; pr(iter.next()), pr(' '), ++i) ;
            if (n >= 0) prln(iter.next());
            else prln();
        }

        static void h() {
            prln("hlfd");
            flush();
        }

        static void flush() {
            __out.flush();
        }

        static void close() {
            __out.close();
        }

        static void prM(int[][] a, int n, int m) {
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++)
                    out.pr(a[i][j] + " ");
                out.prln();
            }
        }
    }

    //Math fxs
    static class mathx {
        // math util
        static int minof(int a, int b, int c) {
            return min(a, min(b, c));
        }

        static int minof(int... x) {
            if (x.length == 1) return x[0];
            if (x.length == 2) return min(x[0], x[1]);
            if (x.length == 3) return min(x[0], min(x[1], x[2]));
            int min = x[0];
            for (int i = 1; i < x.length; ++i) if (x[i] < min) min = x[i];
            return min;
        }

        static long minof(long a, long b, long c) {
            return min(a, min(b, c));
        }

        static long minof(long... x) {
            if (x.length == 1) return x[0];
            if (x.length == 2) return min(x[0], x[1]);
            if (x.length == 3) return min(x[0], min(x[1], x[2]));
            long min = x[0];
            for (int i = 1; i < x.length; ++i) if (x[i] < min) min = x[i];
            return min;
        }

        static int maxof(int a, int b, int c) {
            return max(a, max(b, c));
        }

        static int maxof(int... x) {
            if (x.length == 1) return x[0];
            if (x.length == 2) return max(x[0], x[1]);
            if (x.length == 3) return max(x[0], max(x[1], x[2]));
            int max = x[0];
            for (int i = 1; i < x.length; ++i) if (x[i] > max) max = x[i];
            return max;
        }

        static long maxof(long a, long b, long c) {
            return max(a, max(b, c));
        }

        static long maxof(long... x) {
            if (x.length == 1) return x[0];
            if (x.length == 2) return max(x[0], x[1]);
            if (x.length == 3) return max(x[0], max(x[1], x[2]));
            long max = x[0];
            for (int i = 1; i < x.length; ++i) if (x[i] > max) max = x[i];
            return max;
        }

        static int powi(int a, int b) {
            if (a == 0) return 0;
            int ans = 1;
            while (b > 0) {
                if ((b & 1) > 0) ans *= a;
                a *= a;
                b >>= 1;
            }
            return ans;
        }

        static long powl(long a, int b) {
            if (a == 0) return 0;
            long ans = 1;
            while (b > 0) {
                if ((b & 1) > 0) ans *= a;
                a *= a;
                b >>= 1;
            }
            return ans;
        }

        static int fli(double d) {
            return (int) d;
        }

        static int cei(double d) {
            return (int) ceil(d);
        }

        static long fll(double d) {
            return (long) d;
        }

        static long cel(double d) {
            return (long) ceil(d);
        }

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

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

        static int lcm(int a, int b) {
            return a * b / gcd(a, b);
        }

        static long lcm(long a, long b) {
            return a * b / gcd(a, b);
        }

        static int randInt(int min, int max) {
            return __rand.nextInt(max - min + 1) + min;
        }

        static long mix(long x) {
            x += 0x9e3779b97f4a7c15L;
            x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9L;
            x = (x ^ (x >> 27)) * 0x94d049bb133111ebL;
            return x ^ (x >> 31);
        }
    }

    //Array fxs
    static class ARR {
        // array util
        static void reverse(int[] a) {
            for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {
                int swap = a[i];
                a[i] = a[n - i - 1];
                a[n - i - 1] = swap;
            }
        }

        static void reverse(long[] a) {
            for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {
                long swap = a[i];
                a[i] = a[n - i - 1];
                a[n - i - 1] = swap;
            }
        }

        static void reverse(double[] a) {
            for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {
                double swap = a[i];
                a[i] = a[n - i - 1];
                a[n - i - 1] = swap;
            }
        }

        static void reverse(char[] a) {
            for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {
                char swap = a[i];
                a[i] = a[n - i - 1];
                a[n - i - 1] = swap;
            }
        }

        static void shuffle(int[] a) {
            int n = a.length - 1;
            for (int i = 0; i < n; ++i) {
                int ind = mathx.randInt(i, n);
                int swap = a[i];
                a[i] = a[ind];
                a[ind] = swap;
            }
        }

        static void shuffle(long[] a) {
            int n = a.length - 1;
            for (int i = 0; i < n; ++i) {
                int ind = mathx.randInt(i, n);
                long swap = a[i];
                a[i] = a[ind];
                a[ind] = swap;
            }
        }

        static void shuffle(double[] a) {
            int n = a.length - 1;
            for (int i = 0; i < n; ++i) {
                int ind = mathx.randInt(i, n);
                double swap = a[i];
                a[i] = a[ind];
                a[ind] = swap;
            }
        }

        static void rsort(int[] a) {
            shuffle(a);
            sort(a);
        }

        static void rsort(long[] a) {
            shuffle(a);
            sort(a);
        }

        static void rsort(double[] a) {
            shuffle(a);
            sort(a);
        }

        static int[] copy(int[] a) {
            int[] ans = new int[a.length];
            System.arraycopy(a, 0, ans, 0, a.length);
            return ans;
        }

        static long[] copy(long[] a) {
            long[] ans = new long[a.length];
            System.arraycopy(a, 0, ans, 0, a.length);
            return ans;
        }

        static double[] copy(double[] a) {
            double[] ans = new double[a.length];
            System.arraycopy(a, 0, ans, 0, a.length);
            return ans;
        }

        static char[] copy(char[] a) {
            char[] ans = new char[a.length];
            System.arraycopy(a, 0, ans, 0, a.length);
            return ans;
        }
    }

    //Graph fxs
    static class GR {
        // graph util
        static List<List<Integer>> g(int n) {
            List<List<Integer>> g = new ArrayList<>();
            for (int i = 0; i < n; ++i) g.add(new ArrayList<>());
            return g;
        }

        static List<Set<Integer>> sg(int n) {
            List<Set<Integer>> g = new ArrayList<>();
            for (int i = 0; i < n; ++i) g.add(new HashSet<>());
            return g;
        }

        static void c(List<? extends Collection<Integer>> g, int u, int v) {
            g.get(u).add(v);
            g.get(v).add(u);
        }

        static void cto(List<? extends Collection<Integer>> g, int u, int v) {
            g.get(u).add(v);
        }

        static void dc(List<? extends Collection<Integer>> g, int u, int v) {
            g.get(u).remove(v);
            g.get(v).remove(u);
        }

        static void dcto(List<? extends Collection<Integer>> g, int u, int v) {
            g.get(u).remove(v);
        }
    }

    //Utilsx class
    static class utilX {
        static int[] subsetSum(int[] nums) {
            int M = IntStream.of(nums).sum();
            int[] m = new int[M + 10];
            for (int i = 0; i < M + 10; i++) m[i] = 0;
            m[0] = 1;
            for (int num : nums) {
                for (int j = M; j >= num; j--) {
                    m[j] |= m[j - num];
                }
            }
            return m;
        }

        static int LIS(int[] nums) {
            int[] m = new int[nums.length];
            for (int i = nums.length - 1; i >= 0; i--) {
                m[i] = 1;
                for (int j = i + 1; j < nums.length; j++) {
                    if (nums[j] > nums[i]) {
                        m[i] = max(m[i], m[j] + 1);
                    }
                }
            }
            int ans = 0;
            for (int i = 0; i < nums.length; i++) {
                ans = max(ans, m[i]);
            }
            return ans;
        }
    }

    //Pair Class
    static class Pair<F, S> {
        public final F first;
        public final S second;

        public Pair(F first, S second) {
            this.first = first;
            this.second = second;
        }

        @Override
        public boolean equals(Object o) {
            if (!(o instanceof Pair)) {
                return false;
            }
            Pair<?, ?> p = (Pair<?, ?>) o;
            return Objects.equals(p.first, first) && Objects.equals(p.second, second);
        }
    }
}


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

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

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

        if (N == 1 && M == 1) {
            out.println(1);
        }
        else {
            double ans = 1.0 / N + (double) (N - 1) / N * (M - 1) / (N * M - 1);
            out.println(ans);
        }
    }
}

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

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

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

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

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

        return res.toString();
    }

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

}


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

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

    static class ALetsWatchFootball {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int x = in.nextInt();
            long tottal = a * x;
            long down = (tottal + b - 1) / b;
            out.println(Math.max(0, down - x));

        }

    }
}


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

public class CF1{
    public static void main(String[] args) {
        FastScanner sc=new FastScanner();
//        int T=sc.nextInt();
        int T=1;
        for (int tt=0; tt<T; tt++){
            int n = sc.nextInt();
            int m =sc.nextInt();
            long ans =1;
            boolean done []= new boolean [n+1];
            int size=0;
            int x=2;
            while (x<=n){
                size++;
                x*=2;
            }
            long dp[]= new long [size+1];
            boolean p[]= new boolean[m*size+1];
            long t=0;
            for (int j=1; j<=size; j++){
                for (int y=1; y<=m; y++){
                    if (!p[j*y]){
                        p[j*y]=true;
                        t++;
                    }
                }
                dp[j]=t;
            }
            for (int i=2; i<=n; i++){
                if (!done[i]){
                    int sizez=0;
                    long temp=i;
                    while (temp<=n){
                        done[(int)temp]=true;
                        sizez++;
                        temp*=i;
                    }
                    ans+=dp[sizez];
                }
            }
            System.out.println(ans);
        }
    }
   static int calc(long t){
        int x =0;
        while (t>0){
            x+=t%2;
            t/=2;
        }
        return x;
   }
    static long factorial (int x){
        if (x==0) return 1;
        long ans =x;
        for (int i=x-1; i>=1; i--){
            ans*=i;
            ans%=mod;
        }
        return ans;
    }
    static int mod =1000000007;
    static long power2 (long a, long b){
        long res=1;
        while (b>0){
            if ((b&1)== 1){
                res= (res * a % mod)%mod;
            }
            a=(a%mod * a%mod)%mod;
            b=b>>1;
        }
        return res;
    }

    boolean[] sieveOfEratosthenes(int n)
    {

        boolean prime[] = new boolean[n+1];
        for(int i=0;i<=n;i++)
            prime[i] = true;

        for(int p = 2; p*p <=n; p++)
        {
            if(prime[p] == true)
            {
                for(int i = p*p; i <= n; i += p)
                    prime[i] = false;
            }
        }
        return prime;
    }
    static void sort(int[] a) {
        ArrayList<Integer> l=new ArrayList<>();
        for (int i:a) l.add(i);
        Collections.sort(l);
        for (int i=0; i<a.length; i++) a[i]=l.get(i);
    }
    static void sortLong(long[] a) {
        ArrayList<Long> l=new ArrayList<>();
        for (long i:a) l.add(i);
        Collections.sort(l);
        for (int i=0; i<a.length; i++) a[i]=l.get(i);
    }
    static long gcd (long n, long m){
        if (m==0) return n;
        else return gcd(m, n%m);
    }

    static class Pair implements Comparable<Pair>{
        int x,y;
        public Pair(int x, int y){
            this.x = x;
            this.y = y;
        }
        public int compareTo(Pair o){
            return this.x-o.x;
        }
        // this.x-o.x is ascending
    }
    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

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


import static java.lang.System.*;
import java.util.*;

public class E166{
    public static Scanner sc = new Scanner(in);
    public static Random rand=new Random();

    int mod=100000000;
    public void run(){
        int n1=sc.nextInt(),n2=sc.nextInt(),k1=sc.nextInt(),k2=sc.nextInt();

        int[][][][] dp=new int[n1+1][n2+1][11][2];
        dp[1][0][1][0]=dp[0][1][1][1]=1;
        for(int i=0;i<=n1;i++)for(int j=0;j<=n2;j++){
            if(j>=1)for(int k=1;k<=k1;k++){
                dp[i][j][1][1]+=dp[i][j-1][k][0];
                dp[i][j][1][1]%=mod;
            }
            if(i>=1)for(int k=2;k<=k1;k++){
                dp[i][j][k][0]+=dp[i-1][j][k-1][0];
                dp[i][j][k][0]%=mod;
            }
            if(i>=1)for(int k=1;k<=k2;k++){
                dp[i][j][1][0]+=dp[i-1][j][k][1];
                dp[i][j][1][0]%=mod;
            }
            if(j>=1)for(int k=2;k<=k2;k++){
                dp[i][j][k][1]+=dp[i][j-1][k-1][1];
                dp[i][j][k][1]%=mod;
            }
        }
        long val=0;
        for(int i=1;i<=k1;i++){
            val+=dp[n1][n2][i][0];
            val%=mod;
        }
        for(int i=1;i<=k2;i++){
            val+=dp[n1][n2][i][1];
            val%=mod;
        }
        ln(val%mod);
    }

    public static void main(String[] _) {
        new E166().run();
    }

    public int[] nextIntArray(int n){
        int[] res=new int[n];
        for(int i=0;i<n;i++){
            res[i]=sc.nextInt();
        }
        return res;
    }
    public static void pr(Object o) {
        out.print(o);
    }
    public static void ln(Object o) {
        out.println(o);
    }
    public static void ln() {
        out.println();
    }

}


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

public class C {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        segment[] A = new segment[4];
        for (int i = 0; i < 4; i++) {
            A[i] = new segment(in.nextInt(), in.nextInt(), in.nextInt(),
                    in.nextInt());
            if (A[i].x1 > A[i].x2) {
                A[i].x1 ^= A[i].x2;
                A[i].x2 ^= A[i].x1;
                A[i].x1 ^= A[i].x2;
            }
            if (A[i].y1 > A[i].y2) {
                A[i].y1 ^= A[i].y2;
                A[i].y2 ^= A[i].y1;
                A[i].y1 ^= A[i].y2;
            }
            if ((A[i].x1 != A[i].x2 && A[i].y1 != A[i].y2)
                    || (A[i].x2 - A[i].x1) + (A[i].y2 - A[i].y1) == 0) {
                System.out.println("NO");
                return;
            }
        }
        Arrays.sort(A);
        if (A[0].x1 == A[1].x1 && A[0].y1 == A[1].y1 && A[1].x2 == A[3].x2
                && A[1].y1 == A[3].y1 && A[0].y2 == A[2].y1
                && A[0].x1 == A[2].x1 && A[2].x2 == A[3].x1
                && A[2].y1 == A[3].y2)
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}

class segment implements Comparable<segment> {
    int x1;
    int y1;
    int x2;
    int y2;

    public segment(int i, int j, int k, int l) {
        x1 = i;
        y1 = j;
        x2 = k;
        y2 = l;
    }

    public int compareTo(segment o) {
        if (x1 != o.x1)
            return x1 - o.x1;
        if (x2 != o.x2)
            return x2 - o.x2;
        return y1 - o.y1;
    }

}


import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Math.max;
import static java.lang.System.exit;
import static java.util.Arrays.fill;

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

public class G {

	static final long inf = Long.MAX_VALUE / 2;

	static void solve() throws Exception {
		int k = scanInt();
		long f[] = new long[6];
		for (int i = 0; i < 6; i++) {
			f[i] = scanLong();
		}
		long dyn[] = new long[1000000], ndyn[] = new long[1000000];
		fill(dyn, 1, 1000000, -inf);
		int p10 = 1;
		int smpos[] = new int[1000000];
		for (int p = 0; p < 6; p++) {
			fill(ndyn, -inf);
			long cf = f[p];
			int s = 3 * p10;
			for (int i = 0; i < 1000000; i++) {
				dyn[i] -= i / s * cf;
			}
			for (int m = 0; m < s; m++) {
				int smhead = 0, smtail = 0;
				for (int i = m; i < 1000000; i += s) {
					while (smtail > smhead && dyn[i] >= dyn[smpos[smtail - 1]]) {
						--smtail;
					}
					smpos[smtail++] = i;
					long v = dyn[smpos[smhead]] + i / s * cf;
					ndyn[i] = max(ndyn[i], v);
					if (i + p10 < 1000000) {
						ndyn[i + p10] = max(ndyn[i + p10], v);
					}
					if (i + 2 * p10 < 1000000) {
						ndyn[i + 2 * p10] = max(ndyn[i + 2 * p10], v);
					}
					if (smpos[smhead] == i - (long) (9 * k - 9) * p10) {
						++smhead;
					}
				}
			}
			for (int i = 0; i < 1000000; i++) {
				for (int ss = 9 * k - 6; ss <= 9 * k; ss++) {
					if (i - (long) ss * p10 >= 0) {
						ndyn[i] = max(ndyn[i], dyn[i - ss * p10] + ((i - ss * p10) / s + (ss % 3 == 0 ? ss / 3 : 3 * k - 3)) * cf);
					}
				}
			}
			p10 *= 10;
			long t[] = dyn;
			dyn = ndyn;
			ndyn = t;
		}
		int q = scanInt();
		for (int qq = 0; qq < q; qq++) {
			out.println(dyn[scanInt()]);
		}
	}

	static int scanInt() throws IOException {
		return parseInt(scanString());
	}

	static long scanLong() throws IOException {
		return parseLong(scanString());
	}

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

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}


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

public class Test {
    int readInt() {
        int ans = 0;
        boolean neg = false;
        try {
            boolean start = false;
            for (int c = 0; (c = System.in.read()) != -1; ) {
                if (c == '-') {
                    start = true;
                    neg = true;
                    continue;
                } else if (c >= '0' && c <= '9') {
                    start = true;
                    ans = ans * 10 + c - '0';
                } else if (start) break;
            }
        } catch (IOException e) {
        }
        return neg ? -ans : ans;
    }

    int r, c;
    Scanner sca = new Scanner(System.in);
    long[][] C = new long[64][64];
    long best = Long.MAX_VALUE;

    void dfs(long x, long y, int v1, int v2) {
        long d = Math.abs(x - y);
        if (best <= 1 || d - C[v1][r]*C[v2][r] >= best) return;
        if (v1 == 0 && v2 == 0) {
            if (d < best) best = d;
            return;
        }
        if (v1 > 0) {
            long c1 = C[v1][r] - C[v1-1][r], s2 = C[v2][r];
            dfs(x, y + c1*s2, v1 - 1, v2);
        }
        if (v2 > 0) {
            long s1 = C[v1][r], c2 = C[v2][r] - C[v2-1][r];
            dfs(x + s1*c2, y, v1, v2 - 1);
        }
    }

    int[] cntA = new int[64], cntB = new int[64];
    Map<Long, Long> cache = new TreeMap<>();
    char[] cs;

    long solve(long x, long y, int v1, int v2) {
        long k = x*10000 + v1*100  + v2;
        Long v = cache.get(k);
        if (v != null) return v;
        v = 0l;
        long d = Math.abs(x - y);
        if (d - C[v1][r]*C[v2][r] > best) {
            cache.put(k, v);
            return v;
        }
        if (v1 == 0 && v2 == 0) return 1;
        char c = cs[v1 + v2 - 1];
        if (v1 > 0 && c != 'B') {
            long c1 = C[v1][r] - C[v1 - 1][r], s2 = C[v2][r];
            v += solve(x, y + c1*s2, v1 - 1, v2);
        }
        if (v2 > 0 && c != 'A') {
            long s1 = C[v1][r], c2 = C[v2][r] - C[v2-1][r];
            v += solve( x + s1*c2, y, v1, v2 - 1);
        }
        cache.put(k, v);
        return v;
    }

    void start() {
        r = sca.nextInt(); c = sca.nextInt(); sca.nextLine();
        cs = sca.nextLine().toCharArray();
        for (int i = 0; i <= 2*(r + c); i++)
            for (int j = 0; j <= 2*(r + c); j++) {
                if (j == 0) C[i][j] = 1;
                else if (i == 0) C[i][j] = 0;
                else C[i][j] = C[i-1][j - 1] + C[i - 1][j];
            }
        int v1 = r + c, v2 = r + c;
        long x = 0, y = 0;
        while (v1 > 0 && v2 > 0) {
            if (x > y) {
                long c1 = C[v1][r] - C[v1 - 1][r], s2 = C[v2][r];
                y += c1*s2;
                v1--;
            } else {
                long s1 = C[v1][r], c2 = C[v2][r] - C[v2-1][r];
                x += s1*c2;
                v2--;
            }
        }
        best = Math.abs(x - y);
        dfs(0, 0, r + c, r + c);
        for (int i = 0; i < 2*(r+c); i++) {
            cntA[i + 1] = cntA[i] + (cs[i] == 'A' ? 1 : 0);
            cntB[i + 1] = cntB[i] + (cs[i] == 'B' ? 1 : 0);
        }
        long ans = solve(0, 0, r + c, r + c);
        System.out.println(ans);
    }

    public static void main(String[] args) {

        new Test().start();

    }
}


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

import java.util.Scanner;

/**
 *
 * @author Lotfi
 */
public class edu {

    public static void main(String[] arg) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b=sc.nextInt();
        int c = sc.nextInt();
         int d=sc.nextInt();
        System.out.println(Math.max(Math.abs(a-c), Math.abs(b-d)));
}}


import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.util.Collections;
import java.util.Arrays;

public class Main {

	class Input {
		BufferedReader bf;
		StringTokenizer st;

		long nextLong() throws IOException {
			if (!st.hasMoreTokens())
				st = new StringTokenizer(bf.readLine());
			return Long.parseLong(st.nextToken());
		}

		Input(InputStream stream) throws IOException {
			bf = new BufferedReader(new InputStreamReader(stream));
			st = new StringTokenizer(bf.readLine());
		}

		int nextInt() throws IOException {
			if (!st.hasMoreTokens())
				st = new StringTokenizer(bf.readLine());
			return Integer.parseInt(st.nextToken());
		}

		double nextDouble() throws IOException {
			if (!st.hasMoreTokens())
				st = new StringTokenizer(bf.readLine());
			return Double.parseDouble(st.nextToken());
		}

		void readLine() throws IOException {
			st = new StringTokenizer(bf.readLine());
		}

		String nextString() throws IOException {
			if (!st.hasMoreTokens())
				st = new StringTokenizer(bf.readLine());
			return st.nextToken();
		}

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

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

	static Input in;

	public void solve() throws IOException {
		in = new Input(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		int c = in.nextInt();
		int d = in.nextInt();
		if (((d - c) == (c - b)) && ((c - b) == (b - a)))
			System.out.println(d + (b - a));
		else {
			double q = (double) b / a;
			double q2 = (double) c / b;
			double q3 = (double) d / c;
			if ((q == q2) && (q2 == q3)) {

				double res = d * q;
				int res2 = (int) (d * q);
				if (res % res2 != 0)
					System.out.println(42);
				else
					System.out.println(res2);
			} else
				System.out.println(42);
		}

		in.close();
	}

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

	}

}


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

public class Cups {

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

		Reader.init(System.in);
		long rubles = Reader.nextLong();
		long plastic = Reader.nextLong();
		long glass = Reader.nextLong();
		long rem = Reader.nextLong();
		PrintWriter out = new PrintWriter(System.out);

		long x = 0;
		long y = 0;

		if(rubles>=plastic)
		x = (rubles / plastic) + solve(rubles % plastic, glass, rem);

		if(rubles>=glass)
		y = solve(rubles, glass, rem, plastic);

		out.println(Math.max(x, y));

		out.flush();

	}

	static class Reader {
		static BufferedReader reader;
		static StringTokenizer tokenizer;

		/** call this method to initialize reader for InputStream */
		static void init(InputStream input) {
			reader = new BufferedReader(new InputStreamReader(input));
			tokenizer = new StringTokenizer("");
		}

		/** get next word */
		static String next() throws IOException {
			while (!tokenizer.hasMoreTokens()) {

				tokenizer = new StringTokenizer(reader.readLine());
			}
			return tokenizer.nextToken();
		}

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

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

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

	private static long solve(long rubles, long glass, long rem, long plastic) {

		long sum = 0;
		long n = 0;
		long diff = glass - rem;
		long x = rem;
		long y = rubles - x;

		n = (y) / diff;

		sum += n;
		rubles -= (n * diff);

		if (rubles >= plastic)
			sum += rubles / plastic;

		return sum;
	}

	private static long solve(long rubles, long glass, long rem) {

		long sum = 0;
		long n = 0;
		while (rubles >= glass) {

			n = (rubles / glass);
			sum += n;
			rubles %= glass;
			rubles += (n * rem);

		}

		return sum;
	}
}


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

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

		Task solver = new Task();
		solver.solve(in, out);
		out.close();
	}
}

class Task {
	final static int MAXN = 2111111;
	final static long MD = 1000000007;
	long[] inv, fact, factInv;

	long pow(int x, int y) {
		long ret = 1, tmp = x;
		for (; y > 0; y >>= 1) {
			if ((y & 1) == 1)
				ret = ret * tmp % MD;
			tmp = tmp * tmp % MD;
		}
		return ret;
	}

	long perm(int n, int m) {
		return n < m ? 0 : fact[n] * factInv[n - m] % MD;
	}

	void solve(Scanner in, PrintWriter out) {
		int k = in.nextInt(), w = in.nextInt();
		inv = new long[MAXN];
		fact = new long[MAXN];
		factInv = new long[MAXN];
		inv[1] = 1;
		for (int i = 2; i < MAXN; ++i)
			inv[i] = (MD - MD / i * inv[(int)MD % i] % MD) % MD;

		fact[0] = factInv[0] = 1;
		for (int i = 1; i < MAXN; ++i) {
			fact[i] = fact[i - 1] * i % MD;
			factInv[i] = factInv[i - 1] * inv[i] % MD;
		}

		long ans = 0;
		for (int t = 1; t <= k; ++t) {
			if (w - 1 >= t)
				ans = (ans + perm(k, t) * perm(k, t) % MD * t % MD * pow(k, w - 1 - t) % MD) % MD;
			else
				ans = (ans + perm(k, t) * perm(k - t + w - 1, w - 1) % MD * w % MD) % MD;
			if (w - 1 >= t + 1)
				ans = (ans + perm(k, t) * perm(k, t + 1) % MD * t % MD * pow(k, w - 2 - t) % MD) % MD;
			else
				ans = (ans + perm(k, t) * perm(k - 2 - t + w, w - 1) % MD * (w - 1) % MD) % MD;
		}

		out.println(ans);
	}
}


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

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

    static class FCoffeeVarietiesEasyVersion {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            int n = s.nextInt(), k = s.nextInt();
            int BL_SZ = k + 1 >> 1;
            boolean[] rep = new boolean[n];
            for (int i = 0; i < n; i++) if (query(i, s, w)) rep[i] = true;
            for (int i = 0; i < n; i += BL_SZ) {
                for (int j = i + BL_SZ; j < n; j += BL_SZ) {
                    reset(w);
                    for (int l = i, c = 0; c < BL_SZ; l++, c++) query(l, s, w);
                    for (int l = j, c = 0; c < BL_SZ; l++, c++) if (query(l, s, w)) rep[l] = true;
                }
            }
            int ans = 0;
            for (int i = 0; i < n; i++) if (!rep[i]) ans++;
            w.println("! " + ans);
            w.flush();
        }

        boolean query(int i, FastReader s, PrintWriter w) {
            w.println("? " + ++i);
            w.flush();
            return s.nextChar() == 'Y';
        }

        void reset(PrintWriter w) {
            w.println('R');
            w.flush();
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

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

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

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

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

            return buf[curChar++];
        }

        public int nextInt() {

            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 char nextChar() {

            int c = read();

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

            return (char) c;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

        }

    }
}


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

public class FTL {

    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(System.in);
        int p1 = in.nextInt();
        long t1 = in.nextLong();
        int p2 = in.nextInt();
        long t2 = in.nextLong();
        int h = in.nextInt(), s = in.nextInt();

        long[] f = new long[h+1];
        long[] g = new long[h+1];
        Arrays.fill(f,(long)1e16);
        Arrays.fill(g,(long)1e16);

        for (int i = 0; i <=h ; i++) {
            for (int j = 0; j <= h; j++) {
                long t = Math.max((long)i*t1, (long)j*t2);
                long tt = Math.max((long)(i+1)*t1, (long)(j+1)*t2);
                int x = Math.min(h, i*(p1-s)+j*(p2-s));
                int y = Math.min(h, i*(p1-s)+j*(p2-s)+p2+p1-s);
                f[x] = Math.min(f[x],t);
                g[y] = Math.min(g[y],tt);
            }
        }
        for (int i = 0; i <=h ; i++) {
            for (int j = 0; j <= h; j++) {
                int x = Math.min(i+j, h);
                f[x] = Math.min(f[x], f[i]+g[j]);
            }
        }
        System.out.print(f[h]);
    }
}


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

public class Main {

    static class Cube {

        private boolean[] hasDigit;

        public boolean[] getHasDigit() {
            return hasDigit;
        }

        public Cube(int[] digits) {
            hasDigit = new boolean[10];
            Arrays.fill(hasDigit,false);

            for (int x: digits) {
                hasDigit[x] = true;
            }
        }

        public static void solve() {

            Scanner in = new Scanner(System.in);
            int n = in.nextInt();
            Cube[] cubes = new Cube[n];
            boolean[] wasCube = new boolean[n];

            for (int i = 0; i < n; i++) {
                int[] array = new int[6];
                for (int j = 0; j < 6; j++) {
                    array[j] = in.nextInt();
                }
                cubes[i] = new Cube(array);
            }

            ArrayList shuffle = new ArrayList<>();
            if (n == 1) {
                shuffle.add(new int[]{0});
            } else if (n == 2) {
                shuffle.add(new int[]{0, 1});
                shuffle.add(new int[]{1, 0});
            } else {
                shuffle.add(new int[]{0, 1, 2});
                shuffle.add(new int[]{0, 2, 1});
                shuffle.add(new int[]{1, 0, 2});
                shuffle.add(new int[]{1, 2, 0});
                shuffle.add(new int[]{2, 0, 1});
                shuffle.add(new int[]{2, 1, 0});
            }

            for (int x = 1; x < 1000; x++) {
                String number = Integer.toString(x);
                boolean ok = false;

                for (int i = 0; i < shuffle.size(); i++) {
                    int[] permutation = (int[]) shuffle.get(i);
                    int count = 0;
                    Arrays.fill(wasCube, false);

                    for (int j = 0; j < number.length(); j++) {
                        for (int k = 0; k < cubes.length; k++) {
                            boolean[] search = cubes[permutation[k]].getHasDigit();
                            if (!wasCube[permutation[k]] && search[Character.getNumericValue(number.charAt(j))]) {
                                count++;
                                wasCube[permutation[k]] = true;
                                break;
                            }
                        }
                    }

                    if (count == number.length()) {
                        ok = true;
                        break;
                    }
                }

                if (!ok) {
                    System.out.println(x-1);
                    return;
                }

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

    public static void main(String[] args) {
        Cube.solve();
    }
}


import java.awt.Point;
import java.io.*;
import java.lang.Integer;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import java.util.ArrayDeque;

import static java.lang.Math.*;

public class Main {

    final boolean ONLINE_JUDGE = !new File("input.txt").exists();
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException {
        if (ONLINE_JUDGE) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

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

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

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

    public static void main(String[] args) {
        new Main().run();
        // Sworn to fight and die
    }

    public void run() {
        try {
            long t1 = System.currentTimeMillis();
            init();
            solve();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = " + (t2 - t1));
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    class LOL implements Comparable<LOL> {
        long count;
        long type;

        public LOL(long time, long num) {
            this.count = time;
            this.type = num;
        }

        @Override
        public int compareTo(LOL o) {

            if (o.count != count)
                return (int) (o.count - count); // ---->
            return (int) (o.type - type); // <----
        }

    }

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

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

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

    public void solve() throws IOException {
       int n = readInt();
        char[] s = readString().toCharArray();
        for (int i = 0; i < n - 4; i++)
            for(int j = 1; j <= (n - i - 1)/4; j++)
                if(s[i] == '*' && s[i+j] == '*' && s[i+2*j] == '*'&& s[i+3*j] == '*'&& s[i+4*j] == '*') {
                    out.print("yes");
                    return;
                }
        out.print("no");
    }

}


import java.util.*;

public class Minimizing {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int k = scanner.nextInt();
		String S = scanner.next();
		char[] digitList = S.toCharArray();

		if (n == 1 && k > 0) {
			System.out.println(0);
			scanner.close();
			return;
		}

		int i = 0, counter = 1;

		if (S.charAt(0) != '1' && k > 0) {
			digitList[0] = '1';
			i += 1;
		}

		while (i < k && counter < n) {
			if (S.charAt(counter) != '0') {
				digitList[counter] = '0';
				i += 1;
			}
			counter += 1;
		}
		System.out.println(new String(digitList));
		scanner.close();
	}
}