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.StringTokenizer;

public class Task {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA s=new TaskA();
        s.solve(in, out);
        out.close();
    }
}

class TaskA {
    public void solve(InputReader in, PrintWriter out){
        int k=in.nextInt();
        String[] ss=new String[4];
        for(int i=0;i<4;i++){
            ss[i]=in.next();
        }

        int[] a=new int[9];
        for(int i=0;i<9;i++)
            a[i]=0;

        for(int i=0;i<4;i++){
            for(int j=0;j<4;j++){
                if(ss[i].charAt(j)!='.')
                    a[ss[i].charAt(j)-'1']++;
            }
        }

        boolean flag=true;
        for(int i=0;i<9;i++){
            if(a[i]>k*2){
                flag=false;
                break;
            }
        }

        if(flag){
            out.println("YES");
        }else{
            out.println("NO");
        }
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

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

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

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

}


import java.util.Scanner;

public class MidnightOil {

    public static int n, ko;

    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        n = input.nextInt();
        ko = input.nextInt();
        System.out.println(search(1, 1_000_000_000));
        input.close();
    }

    public static long search(long min, long max){
        long mid = (max - min) / 2 + min;
        long lines = lines(mid);

        if(min == max)
            return mid;
        if(min > max)
            return Long.MAX_VALUE;

        if(lines < n)
            return search(mid + 1, max);
        return Math.min(mid, search(min, mid));
    }

    public static long lines(long v){
        long ret = 0,
                k = 1;
        while(k <= v){
            ret += v / k;
            k *= ko;
        }
        return ret;
    }

}


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

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

class TaskA {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        HashMap<String, Integer> m = new HashMap<String, Integer>();
        String str = in.next();
        int n = str.length();
        int ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j <= n; j++) {
                String s = str.substring(i, j);
                int len = s.length();
                if (m.containsKey(s)) {
                    ans = Math.max(ans, m.get(s));
                } else {
                    m.put(s, len);
                }
            }
        }
        out.println(ans);
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

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

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

}


import java.util.*;
public class Main{
    public static void main(String[] args) {
        //int test;
        Scanner sc=new Scanner(System.in);
        //test=sc.nextInt();
      //  while (test-->0){
            int a,b,c,d;
            a=sc.nextInt();
            b=sc.nextInt();
            c=sc.nextInt();
            d=sc.nextInt();
            long pre[]=new long[10000003];
            for(int i=a;i<=b;i++){
                pre[i+b]++;
                pre[i+c+1]--;
            }
            for(int i=1;i<=10000002;i++){
                pre[i]=pre[i-1]+pre[i];
            }
            for(int i=10000002;i>=1;i--){
                pre[i-1]+=pre[i];
            }
            long ans=0;
            for(int i=c;i<=d;i++){
                ans+=pre[i+1];
            }
            System.out.println(ans);

       // }
    }
}


import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.awt.Point;
import java.math.BigInteger;

import static java.lang.Math.*;

public class CodeforcesC implements Runnable {

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

    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()) {
            try {
                tok = new StringTokenizer(in.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        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 Thread(null, new CodeforcesC(), "", 128 * (1L << 20)).start();
    }

    long timeBegin, timeEnd;

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

    long memoryTotal, memoryFree;

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

    void debug(Object... objects) {
        if (DEBUG) {
            for (Object o : objects) {
                System.err.println(o.toString());
            }
        }
    }

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

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

    boolean DEBUG = false;

    void solve() throws IOException {

        int l = readInt();
        int r = readInt();

        int n = 9;
        int[] ten = new int[n + 1];

        ten[0] = 1;

        for (int i = 1; i <= n; i++)
            ten[i] = 10 * ten[i - 1];

        long answer = 0;

        List<Long> luckyNumbers = new ArrayList<Long>();

        for (int length = 1; length <= n; length++) {
            for (int cur = 0; cur < (1 << length); cur++) {
                int value = 0;
                for (int j = 0; j < length; j++) {
                    if (((1 << j) & cur) == (1 << j))
                        value += ten[j] * 7;
                    else
                        value += ten[j] * 4;
                }
                //out.println(value);
                luckyNumbers.add(1l * value);
            }
        }

        luckyNumbers.add(4444444444l);

        long lastNumber = l;

        for (long luckyNumber : luckyNumbers) {
            if (luckyNumber > r) {
                answer += 1l * (r - lastNumber + 1) * luckyNumber;
                break;
            }
            if (luckyNumber >= l) {
                answer += 1l * (luckyNumber - lastNumber + 1) * luckyNumber;
                lastNumber = luckyNumber + 1;
            }
        }

        out.println(answer);
    }
}


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

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

class TaskC {

    final int lim = 40000;

    public void solve(int testNumber, InputReader in, PrintWriter out) {

        int c = in.nextInt(), hr = in.nextInt(), hb = in.nextInt();
        int wr = in.nextInt(), wb = in.nextInt();

        long ans = 0;
        if (wr >= lim) ans = solve1(c, wr, hr, wb, hb);
        else if (wb >= lim) ans = solve1(c, wb, hb, wr, hr);
        else if ((long) hr * wb < (long) hb * wr) ans = solve2(c, wr, hr, wb, hb);
        else ans = solve2(c, wb, hb, wr, hr);

        out.println(ans);
    }

    private long solve2(int c, int wr, int hr, int wb, int hb) {
        long ans = 0;
        for (int i = 0; i <= lim && (long) i * wr <= c; ++i)
            ans = Math.max(ans, (long) i * hr + (long) ((c - i * wr) / wb) * hb);
        return ans;
    }

    private long solve1(int c, int wr, int hr, int wb, int hb) {
        long ans = 0;
        for (int i = 0; (long) i * wr <= c; ++i)
            ans = Math.max(ans, (long) i * hr + (long) ((c - i * wr) / wb) * hb);
        return 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 UnknownError();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new UnknownError();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

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

    public String next() {
        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;
    }

}


//package CodeForces.Round677Div3;

import java.io.*;import java.util.*;import java.math.*;
public class A
{
    static long mod=1000000007l;
    static int max=Integer.MAX_VALUE,min=Integer.MIN_VALUE;
    static long maxl=Long.MAX_VALUE,minl=Long.MIN_VALUE;
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;
    static StringBuilder sb;

    static public void main(String[] args)throws Exception
    {
        st=new StringTokenizer(br.readLine());
        int t=i();
        sb=new StringBuilder(1000000);

        while(t-->0) {
            String s = s() ;
            int ans = 0 ;
            Character ch = s.charAt(0) ;
            int n = s.length() ;
            if(ch=='1'){
                ans+=0 ;
            } else if (ch == '2') {
                ans+=10 ;
            }
            else if (ch == '3') {
                ans+=20 ;
            }
            else if (ch == '4') {
                ans+=30 ;
            }
            else if (ch == '5') {
                ans+=40 ;
            }
            else if (ch == '6') {
                ans+=50 ;
            }
            else if (ch == '7') {
                ans+=60 ;
            }
            else if (ch == '8') {
                ans+=70 ;
            }
            else if (ch == '9') {
                ans+=80 ;
            }
            ans+= (n*(n+1))/2 ;
            sl(ans) ;
        }
        p(sb) ;
    }

    static void s(String s){sb.append(s);}
    static void s(int s){sb.append(s);}
    static void s(long s){sb.append(s);}
    static void s(char s){sb.append(s);}
    static void s(double s){sb.append(s);}
    static void ss(){sb.append(' ');}
    static void sl(String s){sb.append(s);sb.append("\n");}
    static void sl(int s){sb.append(s);sb.append("\n");}
    static void sl(long s){sb.append(s);sb.append("\n");}
    static void sl(char s){sb.append(s);sb.append("\n");}
    static void sl(double s){sb.append(s);sb.append("\n");}
    static void sl(){sb.append("\n");}
    static int max(int a,int b){return a>b?a:b;}
    static int min(int a,int b){return a<b?a:b;}
    static int abs(int a){return Math.abs(a);}
    static long max(long a,long b){return a>b?a:b;}
    static long min(long a,long b){return a<b?a:b;}
    static long abs(long a){return Math.abs(a);}
    static int sq(int a){return (int)Math.sqrt(a);}
    static long sq(long a){return (long)Math.sqrt(a);}
    static int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
    static boolean pa(String s,int i,int j)
    {
        while(i<j)if(s.charAt(i++)!=s.charAt(j--))return false;
        return true;
    }
    static int ncr(int n,int c,long m)
    {
        long a=1l;
        for(int x=n-c+1;x<=n;x++)a=((a*x)%m);
        long b=1l;
        for(int x=2;x<=c;x++)b=((b*x)%m);
        return (int)((a*(mul((int)b,m-2,m)%m))%m);
    }
    static boolean[] sieve(int n)
    {
        boolean bo[]=new boolean[n+1];
        bo[0]=true;bo[1]=true;
        for(int x=4;x<=n;x+=2)bo[x]=true;
        for(int x=3;x*x<=n;x+=2)if(!bo[x])for(int y=x*x;y<=n;y+=x)bo[y]=true;
        return bo;
    }
    static int[] fac(int n)
    {
        int bo[]=new int[n+1];
        for(int x=1;x<=n;x++)for(int y=x;y<=n;y+=x)bo[y]++;
        return bo;
    }
    static long mul(long a,long b,long m)
    {
        long r=1l;
        a%=m;
        while(b>0)
        {
            if((b&1)==1)r=(r*a)%m;
            b>>=1;
            a=(a*a)%m;
        }
        return r;
    }
    static int i()throws IOException
    {
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        return Integer.parseInt(st.nextToken());
    }
    static long l()throws IOException
    {
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        return Long.parseLong(st.nextToken());
    }
    static String s()throws IOException
    {
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        return st.nextToken();
    }
    static double d()throws IOException
    {
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        return Double.parseDouble(st.nextToken());
    }
    static void p(Object p){System.out.print(p);}
    static void p(String p){System.out.print(p);}
    static void p(int p){System.out.print(p);}
    static void p(double p){System.out.print(p);}
    static void p(long p){System.out.print(p);}
    static void p(char p){System.out.print(p);}
    static void p(boolean p){System.out.print(p);}
    static void pl(Object p){System.out.println(p);}
    static void pl(String p){System.out.println(p);}
    static void pl(int p){System.out.println(p);}
    static void pl(char p){System.out.println(p);}
    static void pl(double p){System.out.println(p);}
    static void pl(long p){System.out.println(p);}
    static void pl(boolean p){System.out.println(p);}
    static void pl(){System.out.println();}
    static int[] ari(int n)throws IOException
    {
        int ar[]=new int[n];
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        for(int x=0;x<n;x++)ar[x]=Integer.parseInt(st.nextToken());
        return ar;
    }
    static int[][] ari(int n,int m)throws IOException
    {
        int ar[][]=new int[n][m];
        for(int x=0;x<n;x++)
        {
            if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
            for(int y=0;y<m;y++)ar[x][y]=Integer.parseInt(st.nextToken());
        }
        return ar;
    }
    static long[] arl(int n)throws IOException
    {
        long ar[]=new long[n];
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        for(int x=0;x<n;x++) ar[x]=Long.parseLong(st.nextToken());
        return ar;
    }
    static long[][] arl(int n,int m)throws IOException
    {
        long ar[][]=new long[n][m];
        for(int x=0;x<n;x++)
        {
            if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
            for(int y=0;y<m;y++)ar[x][y]=Long.parseLong(st.nextToken());
        }
        return ar;
    }
    static String[] ars(int n)throws IOException
    {
        String ar[]=new String[n];
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        for(int x=0;x<n;x++) ar[x]=st.nextToken();
        return ar;
    }
    static double[] ard(int n)throws IOException
    {
        double ar[]=new double[n];
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        for(int x=0;x<n;x++)ar[x]=Double.parseDouble(st.nextToken());
        return ar;
    }
    static double[][] ard(int n,int m)throws IOException
    {
        double ar[][]=new double[n][m];
        for(int x=0;x<n;x++)
        {
            if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
            for(int y=0;y<m;y++)ar[x][y]=Double.parseDouble(st.nextToken());
        }
        return ar;
    }
    static char[] arc(int n)throws IOException
    {
        char ar[]=new char[n];
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        for(int x=0;x<n;x++)ar[x]=st.nextToken().charAt(0);
        return ar;
    }
    static char[][] arc(int n,int m)throws IOException
    {
        char ar[][]=new char[n][m];
        for(int x=0;x<n;x++)
        {
            String s=br.readLine();
            for(int y=0;y<m;y++)ar[x][y]=s.charAt(y);
        }
        return ar;
    }
    static void p(int ar[])
    {
        StringBuilder sb=new StringBuilder(2*ar.length);
        for(int a:ar)
        {
            sb.append(a);
            sb.append(' ');
        }
        System.out.println(sb);
    }
    static void p(int ar[][])
    {
        StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
        for(int a[]:ar)
        {
            for(int aa:a)
            {
                sb.append(aa);
                sb.append(' ');
            }
            sb.append("\n");
        }
        p(sb);
    }
    static void p(long ar[])
    {
        StringBuilder sb=new StringBuilder(2*ar.length);
        for(long a:ar)
        {
            sb.append(a);
            sb.append(' ');
        }
        System.out.println(sb);
    }
    static void p(long ar[][])
    {
        StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
        for(long a[]:ar)
        {
            for(long aa:a)
            {
                sb.append(aa);
                sb.append(' ');
            }
            sb.append("\n");
        }
        p(sb);
    }
    static void p(String ar[])
    {
        int c=0;
        for(String s:ar)c+=s.length()+1;
        StringBuilder sb=new StringBuilder(c);
        for(String a:ar)
        {
            sb.append(a);
            sb.append(' ');
        }
        System.out.println(sb);
    }
    static void p(double ar[])
    {
        StringBuilder sb=new StringBuilder(2*ar.length);
        for(double a:ar)
        {
            sb.append(a);
            sb.append(' ');
        }
        System.out.println(sb);
    }
    static void p(double ar[][])
    {
        StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
        for(double a[]:ar)
        {
            for(double aa:a)
            {
                sb.append(aa);
                sb.append(' ');
            }
            sb.append("\n");
        }
        p(sb);
    }
    static void p(char ar[])
    {
        StringBuilder sb=new StringBuilder(2*ar.length);
        for(char aa:ar)
        {
            sb.append(aa);
            sb.append(' ');
        }
        System.out.println(sb);
    }
    static void p(char ar[][])
    {
        StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
        for(char a[]:ar)
        {
            for(char aa:a)
            {
                sb.append(aa);
                sb.append(' ');
            }
            sb.append("\n");
        }
        p(sb);
    }
}


import java.util.*;
import java.io.*;
public class Main {
    static class Scan {
        private byte[] buf=new byte[1024];
        private int index;
        private InputStream in;
        private int total;
        public Scan()
        {
            in=System.in;
        }
        public int scan()throws IOException
        {
            if(total<0)
            throw new InputMismatchException();
            if(index>=total)
            {
                index=0;
                total=in.read(buf);
                if(total<=0)
                return -1;
            }
            return buf[index++];
        }
        public int scanInt()throws IOException
        {
            int integer=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n))
            {
                if(n>='0'&&n<='9')
                {
                    integer*=10;
                    integer+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            return neg*integer;
        }
        public double scanDouble()throws IOException
        {
            double doub=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n)&&n!='.')
            {
                if(n>='0'&&n<='9')
                {
                    doub*=10;
                    doub+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            if(n=='.')
            {
                n=scan();
                double temp=1;
                while(!isWhiteSpace(n))
                {
                    if(n>='0'&&n<='9')
                    {
                        temp/=10;
                        doub+=(n-'0')*temp;
                        n=scan();
                    }
                    else throw new InputMismatchException();
                }
            }
            return doub*neg;
        }
        public String scanString()throws IOException
        {
            StringBuilder sb=new StringBuilder();
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            while(!isWhiteSpace(n))
            {
                sb.append((char)n);
                n=scan();
            }
            return sb.toString();
        }
        private boolean isWhiteSpace(int n)
        {
            if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
            return true;
            return false;
        }
    }
    public static void main(String args[]) throws IOException {
        Scanner input=new Scanner(System.in);
        long x0=input.nextLong();
        long y0=input.nextLong();
        long ax=input.nextLong();
        long ay=input.nextLong();
        long bx=input.nextLong();
        long by=input.nextLong();
        long xs=input.nextLong();
        long ys=input.nextLong();
        long time=input.nextLong();
        int cnt=1;
        long x=x0,y=y0;
        while(true) {
            x*=ax;
            x+=bx;
            y*=ay;
            y+=by;
            if(x<(long)3*Math.pow(10, 16) && y<3*(long)Math.pow(10, 17)) {
                cnt++;
            }
            else {
                break;
            }
        }
        long arrx[]=new long[cnt];
        long arry[]=new long[cnt];
        x=x0;
        y=y0;
        for(int i=0;i<cnt;i++) {
            arrx[i]=x;
            arry[i]=y;
            x*=ax;
            x+=bx;
            y*=ay;
            y+=by;
        }
//        for(int i=0;i<cnt;i++) {
//            System.out.println(arrx[i]+" "+arry[i]);
//        }
        int ans=0;
        for(int i=0;i<cnt;i++) {
            ans=Math.max(ans, solve(arrx,arry,i,xs,ys,time));
//            System.out.println(i+" "+ans);
        }
        System.out.println(ans);
    }
    public static int solve(long arrx[],long arry[],int strt,long x0,long y0,long time) {
        int cnt=0;
        long rem=time;
        long x=x0,y=y0;
        for(int i=strt;i>=0;i--) {
            long diff=Math.abs(arrx[i]-x)+Math.abs(arry[i]-y);
            if(diff<=rem) {
                rem-=diff;
                cnt++;
                x=arrx[i];
                y=arry[i];
            }
            else {
                break;
            }
        }
        for(int i=strt+1;i<arrx.length;i++) {
            long diff=Math.abs(arrx[i]-x)+Math.abs(arry[i]-y);
            if(diff<=rem) {
                rem-=diff;
                cnt++;
                x=arrx[i];
                y=arry[i];
            }
            else {
                break;
            }
        }
        int max=cnt;
        cnt=0;
        x=x0;
        y=y0;
        rem=time;
        for(int i=strt;i<arrx.length;i++) {
            long diff=Math.abs(arrx[i]-x)+Math.abs(arry[i]-y);
            if(diff<=rem) {
                rem-=diff;
                cnt++;
                x=arrx[i];
                y=arry[i];
            }
            else {
                break;
            }
        }
        for(int i=strt-1;i>=0;i--) {
            long diff=Math.abs(arrx[i]-x)+Math.abs(arry[i]-y);
            if(diff<=rem) {
                rem-=diff;
                cnt++;
                x=arrx[i];
                y=arry[i];
            }
            else {
                break;
            }
        }
        max=Math.max(max, cnt);
        return max;
    }
}


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

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);
    TaskA solver = new TaskA();
    solver.solve(1, in, out);
    out.close();
  }
}

class TaskA {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int a, n, b;
        a = in.nextInt(); b = in.nextInt(); n = in.nextInt();

        int k = 0;

        // 1st a, next b, so on
        while(n >= 0) {
            ++k;
            n -= euclid_gcd( (k % 2 == 1) ? a : b, n);
        }

        // why isnt (k & 1) working instead of k % 2 == 1 ?
        // check !
        if (k % 2 == 1) out.println(1);
        else out.println(0);

        return;
    }

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

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

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

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

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


import java.util.*;

public class NonSquareEquation {

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

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

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


import java.util.Scanner;
import java.util.Arrays;
import java.util.Stack;
public class main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String arr1[] = sc.nextLine().split("");
        String arr2[] = sc.nextLine().split("");
        int counter = 0;
        for (int i = 0; i < arr2.length; i++) {
            if (arr2[i].equals(arr1[counter])) {
                counter++;
            }

        }System.out.println(counter+1);
    }
}


import java.util.Scanner;

import static java.lang.Math.log;

public class CF186C {
    static public void main(String[] args) {
        new Thread(null, new Runnable() {
            public void run() {
                CF186C.run();
            }
        }, "1", 16 * (1 << 20)).start();
    }

    static void run() {
        Scanner scanner = new Scanner(System.in);
        try {
            long n = scanner.nextLong();
            long res;
            if (n == 0)
                res = 1;
            else
                res = (pow2(n * 2 - 1) + pow2(n - 1)) % 1000000007;
            System.out.println(res);
        }

        finally {
            scanner.close();
        }
    }

    static long[] d = new long[128]; // d[i] is 2 ^ (2 ^ i)
    static {
        d[0] = 2;
        for (int i = 1; i < d.length; i++)
            d[i] = (d[i - 1] * d[i - 1]) % 1000000007;
    }

    static long pow2(long p) {
        if (p == 0) {
            return 1;
        }
        int log2 = (int)(log(p)/log(2));
        return (d[log2] * pow2(p - (1L << log2))) % 1000000007;
    }
}


import java.util.*;

public class Ice{
	public static void main(String[] args){
		Scanner arya = new Scanner(System.in);
		int n = arya.nextInt();
		arya.nextLine();
		String s = arya.nextLine();

		int S=0,F=0;

		for(int i=0;i<n-1;i++){
			if(s.charAt(i)=='S' && s.charAt(i+1)=='F')
				S++;
			else
				if(s.charAt(i)=='F' && s.charAt(i+1)=='S')
					F++;
		}

		if(S>F)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
}


import java.util.*;
import java.lang.*;
import java.io.*;
public class Codechef
{
    static long fact(long n){
        long res=1;
        for(int i=1;i<=n;i++){
            res=res*i;
        }
        return res;
    }
	public static void main (String[] args) throws java.lang.Exception
	{
	    Scanner sc=new Scanner(System.in);
	   // BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	    int t=1;
	    //t=sc.nextInt();
	  //  int t=Integer.parseInt(br.readLine());
	    while(--t>=0){
	        long n=sc.nextLong();
	        long D=fact(n/2)*fact(n/2);
	        long temp=(fact(n)/D)/2;
	        //System.out.println(temp);
	        long temp1=(fact(n/2-1));
	       System.out.println(temp*temp1*temp1);

	    }

	}
}


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

public class Main {

	/**
	 * @param args
	 */

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		//int T = in.nextInt();
		solve(1,in,out);
		out.flush();

	}

	private static void solve(int testCases, InputReader in, PrintWriter out) {
		// TODO Auto-generated method stub
		int n = in.nextInt();
		int count  = 0;
		for(int i = 0 ; i < n ; i++){
			int k = in.nextInt();
			if(k==100){
				count++;
			}
		}
		if(n==1){
			out.println("NO");
			return;
		}else if(count==0 && n%2==1){
			out.println("NO");
			return;
		}
		if(count%2==0){
			out.println("YES");
		}else{
			out.println("NO");
		}
	}

}

class InputReader {
	BufferedReader br ;
	StringTokenizer tokenizer;

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

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

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

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

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


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

public class Main {

	// This is my functions
static double u(double x1,double y1,double x2,double y2){
    return Math.sqrt( (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)  );
}

  static int[] a = new int[10000000];
public static void main(String[] args) {
   Scanner scan = new Scanner(System.in);

    String s1,s2;

    s1=scan.next();
    s2=scan.next();
    for(int i=0;i<=s1.length()-1;i++){

    	if(s1.charAt(i)==s2.charAt(i) ){
    		System.out.print(0);
    	}else{
    		System.out.print(1);
    	}
    }

    System.out.println();

}
}


import java.util.*;
public class solution{
public static void main(String...args){
Scanner scan=new Scanner(System.in);
int a[][]=new int[3][3];
int b[][]=new int[3][3];
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
a[i][j]=scan.nextInt();
}
}
for(int i=0;i<3;i++){
	for(int j=0;j<3;j++){
		int x=0;
		int y=0;
		if(i<2)
		x=a[i+1][j];
	    if(j<2) y=a[i][j+1];
		b[i][j]=a[i][j]+x+y;
	}
}
for(int i=0;i<3;i++){
	for(int j=0;j<3;j++){
		int x=0;
		int y=0;
		if(i>0)
		x=a[i-1][j];
	    if(j>0) y=a[i][j-1];
		b[i][j]=b[i][j]+x+y;
	}
}
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
System.out.print(((b[i][j]+1)%2));
}
System.out.println();
}
}
}


import java.util.Scanner;

public class RestoringPassword {
public static void main(String[] args) {
   Scanner cs=new Scanner(System.in);
   String s=cs.next();
   String [] s1=new String [10];
   String[]s2=new String[8];
   for(int i=0;i<10;i++)
   {
       s1[i]=cs.next();
   }
   for(int i=0;i<8;i++)
   {

       s2[i]=s.substring(0+(10*i),10+(10*i));
   }
   String res="";
   for(int i=0;i<8;i++)
   {
       for (int j=0;j<10;j++)
       {
           if(s2[i].equals(s1[j]))
           {
               res=res+j;
               break;
           }
       }
   }
    System.out.println(res);

}
}


import java.io.*;
import java.util.*;
public class solution{
    public static void main(String[] args)
    {
        Scanner snr=new Scanner(System.in);
        int n=snr.nextInt();
        int x=snr.nextInt();
        int cnt=0;

        for (int i = 1; i <= n; i++)
        if (x % i == 0 && x / i <= n) cnt++;
        System.out.println(cnt);
    }
}


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

public class TaskC {

	public FasterScanner mFScanner;
	public PrintWriter mOut;
	private static final boolean LEFT = true;
	private static final boolean RIGHT = false;
	private static boolean sFound;

	public TaskC() {
		mFScanner = new FasterScanner();
		mOut = new PrintWriter(System.out);
	}

	public void solve() {
		int h;
		long visNodes;
		long n;

		h = mFScanner.nextInt();
		n = mFScanner.nextLong();

		sFound = false;

		visNodes = dfs(n, LEFT, h, 1, (1L << h));

		mOut.println(visNodes);

	}

	public long dfs(long child, boolean dir, int height, long begin, long end) {

		long sum = 1;
		long temp;

		if (height == 0 && begin == child) {
			sFound = true;
			return 0;
		}

		if (height == 0)
			return 1;

		if (child >= begin && child <= end) {
			temp = end - begin + 1;
			temp /= 2;

			if (dir == LEFT) {
				sum += dfs(child, RIGHT, height - 1, begin, begin + temp - 1);
			} else {
				sum += dfs(child, LEFT, height - 1, end - temp + 1, end);
			}

			dir = !dir;

			if (!sFound) {
				if (dir == LEFT) {
					sum += dfs(child, RIGHT, height - 1, begin, begin + temp
							- 1);
				} else {
					sum += dfs(child, LEFT, height - 1, end - temp + 1, end);
				}
			}

		} else {
			sum += (1L << (height + 1)) - 2;
		}

		return sum;

	}

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

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

	public static void main(String[] args) {
		TaskC mSol = new TaskC();
		mSol.solve();
		mSol.flush();
		mSol.close();
	}

	class FasterScanner {
		private InputStream mIs;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FasterScanner() {
			this(System.in);
		}

		public FasterScanner(InputStream is) {
			mIs = is;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = mIs.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;
		}

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

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

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

		public char[] nextCharArray(int N) {
			int i;
			char[] array;
			String str;

			array = new char[N];

			i = 0;

			str = nextLine();

			for (i = 0; i < N && i < str.length(); i++) {
				array[i] = str.charAt(i);
			}

			return array;
		}

		public char[][] nextChar2DArray(int M, int N) {
			int i;
			char[][] array;

			array = new char[M][N];

			i = 0;

			for (i = 0; i < M; i++) {
				array[i] = nextCharArray(N);
			}

			return array;
		}

		public int[] nextIntArray(int N) {
			int i;
			int[] array;

			array = new int[N];

			i = 0;

			for (i = 0; i < N; i++) {
				array[i] = nextInt();
			}

			return array;
		}

		public int[][] nextInt2DArray(int M, int N) {
			int i;
			int[][] array;

			array = new int[M][N];

			i = 0;

			for (i = 0; i < M; i++) {
				array[i] = nextIntArray(N);
			}

			return array;
		}

		public long[] nextLongArray(int N) {
			int i;
			long[] array;

			array = new long[N];

			i = 0;

			for (i = 0; i < N; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public long[][] nextLong2DArray(int M, int N) {
			int i;
			long[][] array;

			array = new long[M][N];

			i = 0;

			for (i = 0; i < M; i++) {
				array[i] = nextLongArray(N);
			}

			return array;
		}

		public double[] nextDoubleArray(int N) {
			int i;
			double[] array;

			array = new double[N];

			for (i = 0; i < N; i++) {
				array[i] = nextDouble();
			}

			return array;
		}

		public double[][] nextDouble2DArray(int M, int N) {
			int i;
			double[][] array;

			array = new double[M][N];

			for (i = 0; i < M; i++) {
				array[i] = nextDoubleArray(N);
			}

			return array;
		}

	}
}


import java.util.Scanner;

public class TextVolume {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		scn.nextLine();
		String str = scn.nextLine();
		int max = 0;
		int cn = 0;
		for(int i = 0;i<str.length();i++){
			char ch = str.charAt(i);
			if(ch == ' '){
				cn=0;
			}
			if(ch>='A'&& ch<='Z'){
				cn++;
				if(cn>max){
					max = cn;
				}
			}
		}
		System.out.println(max);
	}
}


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

public class TaskB {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		new TaskB().solve(in, out);
		in.close();
		out.close();
	}

	private void solve(Scanner in, PrintWriter out) {
		int n = in.nextInt();
		int m = in.nextInt();
		if (m < n) {
			n += m;
			m = n - m;
			n -= m;
		}
		int g = 0, f = 0;
		f += n;
		g += m - 1;
		out.println(g + " " + f);
	}

}


import java.awt.*;
import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;

/*
	br = new BufferedReader(new FileReader("input.txt"));
	pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
	br = new BufferedReader(new InputStreamReader(System.in));
	pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
 */

public class Main {
	private static BufferedReader br;
	private static StringTokenizer st;
	private static PrintWriter pw;

	static int[] dx = new int[]{-1,0,0,0,1};
	static int[] dy = new int[]{0,-1,0,1,0};

	public static void main(String[] args) throws IOException	{
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		int qq = 1;
		//int qq = Integer.MAX_VALUE;
		//int qq = readInt();
		for(int casenum = 1; casenum <= qq; casenum++)	{
			int ret = 0;
			int n = readInt();
			int sum = 0;
			for(int i = 0; i < n; i++)	{
				sum += readInt();
			}
			n++;
			for(int k = 1; k <= 5; k++)	{
				if((sum+k)%n != 1)	{
					ret++;
				}
			}
			pw.println(ret);
		}
		pw.close();
	}

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

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

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

	private static String nextToken() throws IOException	{
		while(st == null || !st.hasMoreTokens())	{
			if(!br.ready())	{
				pw.close();
				System.exit(0);
			}
			st = new StringTokenizer(br.readLine().trim());
		}
		return st.nextToken();
	}
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.StringTokenizer;

public class A {

    static StringTokenizer st;
    static BufferedReader br;
    static PrintWriter pw;
    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        int n = nextInt();
        int[]x = new int[n+1];
        for (int i = 1; i <= n; i++) {
            x[i] = nextInt();
        }
        Arrays.sort(x, 1, n+1);
        for (int i = 1; i <= n; i++) {
            boolean ok = true;
            int r = 1, h = 1;
            for (int j = 1; j <= n; j++) {
                if (x[j] < h-1) {
                    ok = false;
                    break;
                }
                r++;
                if (r==i+1) {
                    r = 1;
                    h++;
                }
            }
            if (ok) {
                System.out.println(i);
                return;
            }
        }
        pw.close();
    }
    private static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    private static long nextLong() throws IOException {
        return Long.parseLong(next());
    }
    private static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }
    private static String next() throws IOException {
        while (st==null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }
}


import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;

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

class TaskA {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
		long n = in.readLong(), res = 1, p = 3;
		while (p < n) {
			if (n % p != 0) res = Math.max(res, n / p + 1);
			p *= 3;
		}
		out.print(res);
	}
}

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

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

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

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

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
	}
	public void close() {
		writer.close();
	}
	public void print(long i) {
		writer.print(i);
	}
}


import java.io.*;

public class A {

  private static final String REGEX = " ";
  private static final Boolean DEBUG = false;
  private static final String FILE_NAME = "input.txt";

  public static void main(String[] args) throws IOException {
    if (DEBUG) {
      generate();
    }
    Solver solver = new Solver();
    solver.readData();
    solver.solve();
    solver.print();
  }

  private static void generate() throws IOException {
//    FileWriter writer = new FileWriter("input.txt");
//    writer.close();
  }

  private static class Solver {
    private StringBuilder myStringBuilder = new StringBuilder();
    int n;
    int[] a, b;

    void readData() throws IOException {
      Scanner scanner = new Scanner();
      n = scanner.nextInt();
      a = scanner.nextIntArray(n);
      b = scanner.nextIntArray(n);
      scanner.close();
    }

    void solve() {
      int[] as = new int[5];
      int[] bs = new int[5];

      for (int i : a) {
        as[i - 1]++;
      }

      for (int i : b) {
        bs[i - 1]++;
      }

      int sum = 0;
      int x = 0;
      for (int i = 0; i < 5; i++) {
        int abs = Math.abs(as[i] - bs[i]);
        if (abs % 2 == 1) {
          out(-1);
          return;
        }
        if (as[i] > bs[i]) {
          x += abs / 2;
        } else {
          x -= abs / 2;
        }
        sum += abs / 2;
      }
      if (x!=0){
        out(-1);
      } else {
        out(sum / 2);
      }
    }

    void print() {
      System.out.println(myStringBuilder);
    }

    void out(Object object) {
      myStringBuilder.append(object);
    }

    void out(String string) {
      myStringBuilder.append(string);
    }

    public void out(boolean b) {
      myStringBuilder.append(b);
    }

    public void out(char c) {
      myStringBuilder.append(c);
    }

    public void out(int i) {
      myStringBuilder.append(i);
    }

    public void out(long lng) {
      myStringBuilder.append(lng);
    }

    public void out(float f) {
      myStringBuilder.append(f);
    }

    public void out(double d) {
      myStringBuilder.append(d);
    }

    public void newLine() {
      myStringBuilder.append("\n");
    }

    @SuppressWarnings("SameParameterValue")
    int[] splitInteger(String string, int n) {
      final String[] split = string.split(REGEX, n);
      int[] result = new int[split.length];
      for (int i = 0; i < n; ++i) {
        result[i] = Integer.parseInt(split[i]);
      }
      return result;
    }

    public int[] splitInteger(String string) {
      return splitInteger(string, 0);
    }

    @SuppressWarnings("SameParameterValue")
    long[] splitLong(String string, int n) {
      final String[] split = string.split(REGEX, n);
      long[] result = new long[split.length];
      for (int i = 0; i < n; ++i) {
        result[i] = Long.parseLong(split[i]);
      }
      return result;
    }

    public long[] splitLong(String string) {
      return splitLong(string, 0);
    }

    @SuppressWarnings("SameParameterValue")
    double[] splitDouble(String string, int n) {
      final String[] split = string.split(REGEX, n);
      double[] result = new double[split.length];
      for (int i = 0; i < n; ++i) {
        result[i] = Double.parseDouble(split[i]);
      }
      return result;
    }

    public double[] splitDouble(String string) {
      return splitDouble(string, 0);
    }

    @SuppressWarnings("SameParameterValue")
    String[] splitString(String string, int n) {
      return string.split(REGEX, n);
    }

    public int max(int a, int b) {
      return Math.max(a, b);
    }

    public int max(int[] arr) {
      int max = Integer.MIN_VALUE;
      for (int x : arr) {
        max = max(max, x);
      }
      return max;
    }

    public long max(long a, long b) {
      return Math.max(a, b);
    }

    public int min(int a, int b) {
      return Math.min(a, b);
    }

    public long min(long a, long b) {
      return Math.min(a, b);
    }

    public double max(double a, double b) {
      return Math.max(a, b);
    }

    public double min(double a, double b) {
      return Math.min(a, b);
    }

    private final static int MOD = 1000000009;

    int multMod(int a, int b) {
      return ((a % MOD) * (b % MOD)) % MOD;
    }

    int sumMod(int a, int b) {
      return ((a % MOD) + (b % MOD)) % MOD;
    }

    long multMod(long a, long b) {
      return ((a % MOD) * (b % MOD)) % MOD;
    }

    long sumMod(long a, long b) {
      return ((a % MOD) + (b % MOD)) % MOD;
    }

    int sum(int[] arr) {
      int sum = 0;
      for (int i = 0; i < arr.length; i++) {
        sum += arr[i];
      }
      return sum;
    }

    long sum(long[] arr) {
      long sum = 0;
      for (int i = 0; i < arr.length; i++) {
        sum += arr[i];
      }
      return sum;
    }

    private class Scanner {
      private int currentIndex = 0;
      private String[] objects;
      private final BufferedReader myReader;
      private Computable<Character> charComputer;
      private Computable<Double> doubleComputer;
      private Computable<Integer> intComputer;
      private Computable<Long> longComputer;

      Scanner() throws FileNotFoundException {
        InputStream in = DEBUG ? new FileInputStream(FILE_NAME) : System.in;
        myReader = new BufferedReader(new InputStreamReader(in));
        charComputer = () -> objects[currentIndex].charAt(0);
        doubleComputer = () -> Double.parseDouble(objects[currentIndex]);
        intComputer = () -> Integer.parseInt(objects[currentIndex]);
        longComputer = () -> Long.parseLong(objects[currentIndex]);
      }

      String nextLine() throws IOException {
        objects = null;
        currentIndex = 0;
        return myReader.readLine();
      }

      int nextInt() throws IOException {
        return next(intComputer);
      }

      int[] nextIntArray(int n) throws IOException {
        return splitInteger(nextLine(), n);
      }

      long[] nextLongArray(int n) throws IOException {
        return splitLong(nextLine(), n);
      }

      long nextLong() throws IOException {
        return next(longComputer);

      }

      double nextDouble() throws IOException {
        return next(doubleComputer);

      }

      char nextChar() throws IOException {
        return next(charComputer);
      }

      <T> T next(Computable<T> computer) throws IOException {
        T result;
        if (objects == null || currentIndex >= objects.length) {
          String s = myReader.readLine();
          objects = s.split(" ");
          currentIndex = 0;
        }
        result = computer.compute();
        currentIndex++;
        return result;
      }

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

    }

    interface Computable<T> {
      T compute();
    }

  }

}


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.StringTokenizer;

//Your code goes here
public class Main {

	static class ProblemSolver{
		public void solveTheProblem(InputReader in,PrintWriter out){

			//Take the necessary inputs and variables
			String s=in.next();

			//Evaluation of the result
			/*
			 * Here we need to take care of simply one thing
			 * i.e. the indexing. Say the length of the string
			 * is n then as we know the indexing starts from 0
			 * and ends with n-1 but here we have 2 more indices
			 * 		1. start(-1)
			 * 		2. end(n)
			 *
			 * Rest is all about finding the maximum gap b/w
			 * 2 alphabets considering both the start and end
			 * indices.
			 */
			int max=0;
			int start=-1;/* start index as -1 */
			for(int curr=0;curr<s.length();++curr){
				if(s.charAt(curr)=='A'||s.charAt(curr)=='E'||s.charAt(curr)=='I'||s.charAt(curr)=='O'||s.charAt(curr)=='U'||s.charAt(curr)=='Y'){
					max=Math.max(max, curr-start);
					start=curr;
				}
			}
			/* considering the case of end index */
			max=Math.max(max, s.length()-start);

			//Displaying of the result
			System.out.println(max);
		}
	}

	//Default template for all the codes
	static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

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

    }

	//Template.Main method for all the codes
	public static void main(String[] args) {
		InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
		ProblemSolver problemSolver = new ProblemSolver();
		problemSolver.solveTheProblem(in, out);
		out.close();
	}

}


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

public class elements {

	public static HashSet<String> elements;

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

        elements = new HashSet<String>();

        String temp = "H He Li Be B C N O F Ne Na Mg Al Si P S Cl Ar K Ca Sc Ti V Cr Mn Fe Co Ni Cu Zn Ga Ge As Se Br Kr Rb Sr Y Zr Nb Mo Tc Ru Rh Pd Ag Cd In Sn Sb Te I Xe Cs Ba La Ce Pr Nd Pm Sm Eu Gd Tb Dy Ho Er Tm Yb Lu Hf Ta W Re Os Ir Pt Au Hg Tl Pb Bi Po At Rn Fr Ra Ac Th Pa U Np Pu Am Cm Bk Cf Es Fm Md No Lr Rf Db Sg Bh Hs Mt Ds Rg Cn Nh Fl Mc Lv Ts Og";

        String[] ele = temp.split(" ");

        for (String e : ele) {
        	elements.add(e.toUpperCase());
        }

        String s = scan.nextLine();
        //elements.add("H");

        if (possible(0, s)) {
        	System.out.println("YES");
        }
        else {
        	System.out.println("NO");
        }

        //out.close();
    }

    public static boolean possible(int index, String s) {
    	int n = s.length();

    	boolean f = false;

    	if (index >= n)
    		return true;

    	String find = "" + s.charAt(index);

    	if (elements.contains(find)) {
    		f|=possible(index+1, s);
    	}

    	if (index + 1 < n) {
    		find += s.charAt(index+1);
    		if (elements.contains(find)) {
    			f|=possible(index+2, s);
    		}
    		if (index + 2 < n) {
    			find += s.charAt(index+2);
    			if (elements.contains(find)) {
    				f|=possible(index+3, s);
    			}
    		}
    	}

    	return f;
    }

}


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

public class Main {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

		long n = scn.nextLong() + 1, k = scn.nextLong(), i = 1;

		while(i <= k && i <= 100) {
			if(n % i != 0) {
				System.out.println("No");
				return;
			}

			i++;
		}

		System.out.println("Yes");
	}
}


import java.util.*;

public class Solution {

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

  public static void main(String[] args) {
    System.out.println((sc.next().length() + 1) * 25 + 1);

  }
}


 import java.util.*;
 import java.math.*;
 import java.io.*;
 public class Main
 {
 	public static void main(String[] args)
 	{
 		Scanner in = new Scanner(System.in);
 		long a = in.nextInt();
 		long b = in.nextInt();
 		long x = in.nextInt();
 		long y = in.nextInt();
 		long z = in.nextInt();
 		long res = 0;
 		x *= 2;
 		x += y;
 		z *= 3;
 		z += y;
 		if(x - a > 0) res += x - a;
 		if(z - b > 0) res += z - b;
 		System.out.println(res);
 	}
}


/**
 * Created by user on 11/10/2019.
 */

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

public class tilePainting {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(System.out));
        long num = Long.parseLong(br.readLine());
        ArrayList<Long> primeList = new ArrayList<>(100);
        for(int i=2;i<=Math.sqrt(num);i++){
            if(num%i==0){
                primeList.add((long) i);
                while(num%i==0)
                    num/=i;
            }
        }
        if(num!=1)
            primeList.add(num);
        if(primeList.size()>1)
            System.out.println(1);
        else if(primeList.size()==0)
            System.out.println(num);
        else
            System.out.println(primeList.get(0));

    }
}


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

import java.util.*;

public class B {
	public static void main(String... args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int H = (int) (Math.log(N) / Math.log(2));
		int A = sc.nextInt() + (1 << H) - 1;
		int B = sc.nextInt() + (1 << H) - 1;

		while (A != B) {
			A /= 2;
			B /= 2;
		}

		int R = (int) (Math.log(A) / Math.log(2));
		System.out.print((R == 0) ? "Final!" : H - R);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.StringTokenizer;
public class codeforces870A
{
	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;
		}
	}

	public static void main(String[] args)
	{
        FastReader s=new FastReader();
        StringBuilder sb=new StringBuilder();
        int n=s.nextInt(),m=s.nextInt(),i,x,y;
        List<Integer> l1= new LinkedList<>();
        List<Integer> l2= new LinkedList<>();
        List<Integer> l3= new LinkedList<>();
        for(i=0;i<n;i++)
        l1.add(s.nextInt());
        for(i=0;i<m;i++)
        l2.add(s.nextInt());
        for(i=0;i<m;i++)
        {
            if(l1.contains(l2.get(i)))
            l3.add(l2.get(i));
        }
        if(l3.isEmpty())
        {
            x=Collections.min(l1);
            y=Collections.min(l2);
            sb.append(Math.min(x,y));
            sb.append(Math.max(x,y));
        }
        else
        sb.append(Collections.min(l3));
        System.out.print(sb);
    }
}


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

public class Solution {

    private static void solve(InputReader in, OutputWriter out) {
        int n = in.nextInt();

        int[] a = new int[n];
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            if (a[i] < min) min = a[i];
        }

        boolean updated;
        do {
            updated = false;
            for (int i = 0; i < n; i++)
                if (a[i] > min) {
                    updated = true;

                    if (a[i] % min == 0)
                        a[i] = min;
                    else {
                        a[i] = a[i] % min;
                        min = a[i];
                    }
                }
        } while (updated);

        int sum = 0;
        for (int i = 0; i < n; i++)
            sum += a[i];

        out.print(sum);
    }

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        OutputWriter out = new OutputWriter(System.out);
        solve(in, out);
        in.close();
        out.close();
    }

    private static class InputReader {

        private BufferedReader br;
        private StringTokenizer st;

        InputReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }

        String nextLine() {
            String line = null;

            try {
                line = br.readLine();

            } catch (IOException e) {
                e.printStackTrace();
            }

            return line;
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String line = nextLine();

                if (line == null)
                    return null;

                st = new StringTokenizer(line);
            }

            return st.nextToken();
        }

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

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

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

        int[] nextIntArray(int n) {
            int[] a = new int[n];

            for (int i = 0; i < n; i++)
                a[i] = nextInt();

            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];

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

            return a;
        }

        void close() {
            try {
                br.close();

            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static class OutputWriter {

        BufferedWriter bw;

        OutputWriter(OutputStream os) {
            bw = new BufferedWriter(new OutputStreamWriter(os));
        }

        void print(int i) {
            print(Integer.toString(i));
        }

        void println(int i) {
            print(i);
            print('\n');
        }

        void print(long l) {
            print(Long.toString(l));
        }

        void println(long l) {
            print(l);
            print('\n');
        }

        void print(double d) {
            print(Double.toString(d));
        }

        void println(double d) {
            print(d);
            print('\n');
        }

        void print(boolean b) {
            print(Boolean.toString(b));
        }

        void println(boolean b) {
            print(b);
            print('\n');
        }

        void print(char c) {
            try {
                bw.write(c);

            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        void println(char c) {
            print(c);
            print('\n');
        }

        void print(String s) {
            try {
                bw.write(s);

            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        void println(String s) {
            print(s);
            print('\n');
        }

        void close() {
            try {
                bw.close();

            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}


import java.io.*;
import java.util.*;
public class B {
    static int M = (int)(1e9) + 7;
    // 937481864 60
    public static long pow(long a, long b) {
        long res = 1;
        while( b > 0 ) {
            if( b % 2 == 1 ) res *= a;
            res %= M;
            a *= a;
            a %= M;
            b /= 2;
        }
        return res % M;
    }

    public static long solve(int k) {
        long ans = 6;
        long nodes = (1L<<k) - 2;
        ans = ans * pow(4, nodes) ;
        ans %= M;
        return ans;
    }

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        // int t = Integer.parseInt(br.readLine());
        int t = 1;
        while( t-->0 ) {
            int k = Integer.parseInt(br.readLine());

            System.out.println(solve(k));
        }
    }
}


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

public class eduA {
public static void main(String[] args) throws IOException {
	BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
	String [] s = bf.readLine().split(" ");
	String [] s1 = bf.readLine().split(" ") ;
	int n [] = new int [4] ;
	n[0] = Integer.parseInt(s[0]) ;
	n[1] = Integer.parseInt(s1[0]) ;
	n[2] = Integer.parseInt(s[1]);
	n[3] = Integer.parseInt(s1[1]) ;
	int n1 = Math.abs(n[1]- n[0]) ;

	int n2 = Math.abs(n[3]- n[2]);

			int answer = Math.max(n1, n2) ;
			System.out.println(answer);
}
}


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

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

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            int l = in.nextInt();
            long res = choose(l + 3, 3) - count(a, b, c, l) - count(b, c, a, l) - count(c, a, b, l);
            out.println(res);
        }

        private long count(int a, int b, int c, int l) {
            int low = Math.max(c, a + b);
            int high = c + l;
            long res = 0;
            for (int i = low; i <= high; i++) {
                int max = Math.min(i - a - b, l - i + c);
                if (max >= 0) res += choose(max + 2, 2);
            }
            return res;
        }

        private long choose(int n, int k) {
            long res = 1;
            for (int i = 1; i <= k; i++)
                res = res * (n - i + 1) / i;
            return res;
        }

    }

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

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

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

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

    }
}


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

		String s = sc.nextLine();
		int cnt=0;

		for (int i=0;i<26;i++){
			if(s.indexOf('a'+i)!=-1)
				cnt++;
		}
		System.out.println(cnt%2==1?"IGNORE HIM!":"CHAT WITH HER!");

	}
}


import java.util.*;

public class CFA {
	static int a,b,ta,tb,c,d,s,ans;
	static String ss;
	public static void main(String args[]) {
		Scanner in=new Scanner(System.in);
		a=in.nextInt();ta=in.nextInt();
		b=in.nextInt();tb=in.nextInt();
		ss=in.next();
		c=Integer.parseInt(ss.substring(0,2));
		d=Integer.parseInt(ss.substring(3,5));
		s=c*60+d-5*60;
		c=(s+ta)/b+1;
		if(s<tb) d=0;
		else d=(s-tb)/b+1;
		if((s+ta)%b==0) c--;
		if(s+ta>18*60+59) c=(18*60+59)/b+1;
		ans=c-d;
		System.out.println(ans);
	}
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Collections;

public class CFChess {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(System.out));
		byte[][] arr = new byte[8][8];
		ArrayList <Byte> white = new ArrayList<>();
		ArrayList <Byte> black = new ArrayList<>();
		String[] inputs;
		byte k=0,l=0;
		for(int i=0;i<8;i++){
			inputs = buff.readLine().split("");
			for(int j=0;j<8;j++){
				if(inputs[j].equals("."))
					arr[i][j] = 0;
				else if(inputs[j].equals("W")){
					arr[i][j] = 1;
					white.add((byte)i);
				}
				else if(inputs[j].equals("B")){
					arr[i][j] = 2;
					black.add((byte)i);
				}

			}
		}
		Collections.sort(white);
		Collections.sort(black);
		boolean whiteflag = false,blackflag = false;
		byte whiteMax = 127,blackMax = 127;
		for(int size= 0;size<white.size();size++){
			whiteflag = false;
			int row = white.get(size) ;
			int col = -1;
			for(int i=0;i<8;i++){
				if(arr[row][i]==1){
					col = i;
					arr[row][i] =11;
					break;
				}
			}
			for(int i=row;i>=0;i--){
				if(arr[i][col]==2 || arr[i][col]==22){
					whiteflag = true;
					break;
				}
			}

			if(!whiteflag){
				whiteMax = (byte)(row -(byte)0);
				break;
			}
		}

		for(int size= black.size()-1;size>-1;size--){
			blackflag = false;
			int row = black.get(size) ;
			int col = -1;
			for(int i=0;i<8;i++){
				if(arr[row][i]==2){
					col = i;
					arr[row][i] = 22;
					break;
				}
			}
			for(int i=row;i<8;i++){
				if(arr[i][col]==1 || arr[i][col]==11){
					blackflag = true;
					break;
				}
			}

			if(!blackflag){
				blackMax = (byte)((byte)7-row);
				break;
			}
		}

		if(whiteMax<=blackMax){
			wr.write("A");
		}
		else{
			wr.write("B");
		}
		wr.flush();
		wr.close();
	}

}


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

    public class Main{
        static class Run implements Runnable{
            //TODO parameters
            final boolean consoleIO = true;
            final String inFile = "input.txt";
            final String outFile = "output.txt";

            int[] s;
            boolean[] b;
            Vector<Integer> simple;
            HashSet<Integer> hs;

            void gen(int n) {
                s = new int[n+1];
                b = new boolean[n+1];

                for(int i = 2; i < s.length; ++i)
                    s[i] = i;

                boolean exit = false;
                int p = 1;
                while(!exit) {
                    boolean find = false;
                    for(int i = p+1; i < s.length; ++i)
                        if(b[i] == false) {
                            p = i;
                            find = true;
                            break;
                        }

                    if(!find) {
                        exit = true;
                        break;
                    }

                    int j = 2;
                    int k = p*j;
                    while(k < s.length) {
                        b[k] = true;
                        ++j;
                        k = p*j;
                    }
                }

                simple = new Vector<Integer>();
                hs = new HashSet<Integer>();
                for(int i = 2; i < s.length; ++i)
                    if(!b[i]) {
                        simple.add(i);
                        hs.add(i);
                    }
            }

            @Override
            public void run() {
                int n = nextInt();
                int k = nextInt();
                gen(1000);

                int sz = simple.size();
                int count = 0;

                for(int i = 0; i < sz-1; ++i) {
                    int a = simple.get(i);
                    int b = simple.get(i+1);
                    int c = a + b + 1;

                    if(c <= n) {
                        if(hs.contains(c))
                            ++count;
                    }
                    else
                        break;
                }

                print(count >= k ? "YES" : "NO");
                close();
            }
        //=========================================================================================================================
            BufferedReader in;
            PrintWriter out;
            StringTokenizer strTok;

            Run() {
                if (consoleIO) {
                    initConsoleIO();
                }
                else {
                    initFileIO();
                }
            }

            void initConsoleIO() {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(new OutputStreamWriter(System.out));
            }

            void initFileIO() {
                try {
                    in = new BufferedReader(new FileReader(inFile));
                    out = new PrintWriter(new FileWriter(outFile));
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            void close() {
                try {
                    in.close();
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

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

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

            float nextFloat() {
                return Float.parseFloat(nextToken());
            }

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

            String nextLine() {
                try {
                    return in.readLine();
                } catch (IOException e) {
                    return "__NULL";
                }
            }

            boolean hasMoreTokens() {
                return (strTok == null) || (strTok.hasMoreTokens());
            }

            String nextToken() {
                while (strTok == null || !strTok.hasMoreTokens()) {
                    String line;
                    try {
                        line = in.readLine();
                        strTok = new StringTokenizer(line);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }

                return strTok.nextToken();
            }

            void cout(Object o){
                System.out.println(o);
            }

            void print(Object o) {
                out.write(o.toString());
            }

            void println(Object o) {
                out.write(o.toString() + '\n');
            }

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

            String sprintf(String format, Object... args) {
            return MessageFormat.format(format, args);
        }
        }

        static class Pair<A, B> {
            A a;
            B b;

            A f() {
                return a;
            }

            B s() {
                return b;
            }

            Pair(A a, B b) {
                this.a = a;
                this.b = b;
            }

            Pair(Pair<A, B> p) {
                a = p.f();
                b = p.s();
            }
        }

        public static void main(String[] args) throws IOException {
            Run run = new Run();
            Thread thread = new Thread(run);
            thread.run();
        }
    }


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

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        String s = scanner.nextLine();
        scanner.close();
        char a[] = s.substring(0, n).toCharArray();
        char b[] = s.substring(n).toCharArray();
        Arrays.sort(a);
        Arrays.sort(b);
        boolean able = true;
        for(int i = 0; i < a.length; i++){
            if(a[i] <= b[i]){
                able = false;
            }
        }
        if(able){
            System.out.println("YES");
            return;
        }
        able = true;
        for(int i = 0; i < b.length; i++){
            if(a[i] >= b[i]){
                able = false;
            }
        }
        System.out.println(able ? "YES" : "NO");
    }
}


import java.util.Scanner;

public class A {

    public static void main(String[] args) {
        System.out.println(((new Scanner(System.in)).nextInt() >> 1) * 3);
    }
}


import java.util.Scanner;

public class B_116_Little_Pigs_and_Wolves {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		char grid[][] = new char[n][m];
		for (int i = 0; i < n; i++) {
			String s = sc.next();
			for (int j = 0; j < m; j++) {
				grid[i][j] = s.charAt(j);
			}
		}
		int count = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if ((grid[i][j] == 'W')
						&& ((i > 0 && grid[i - 1][j] == 'P')
								|| (j > 0 && grid[i][j - 1] == 'P')
								|| (i < n - 1 && grid[i + 1][j] == 'P')
								|| (j < m - 1 && grid[i][j + 1] == 'P'))) {
					count++;
				}

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


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

public class Cp {
	public static void main(String[] args) throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String readLine = br.readLine();
		String[] split = readLine.split(" ");
		int vert=Integer.parseInt(split[0]);
		int edge=Integer.parseInt(split[1]);
		int connect[]=new int[vert];
		int graph[][]=new int[vert][vert];
		int max=0;
		int cnt[]=new int[vert];
		for (int i = 0; i < edge; i++) {
			readLine = br.readLine();
			split = readLine.split(" ");
			int t=Integer.parseInt(split[0]);
			int t2=Integer.parseInt(split[1]);
			connect[t-1]++;
			connect[t2-1]++;

			graph[t-1][t2-1]=1;
			graph[t2-1][t-1]=1;
		}
		HashSet<Integer> hs=new HashSet<Integer>();
		if(vert<=6) {
			System.out.println(edge);
			System.exit(0);
		}else {
			for (int i = 0; i < cnt.length; i++) {
				for (int j = i+1; j < cnt.length; j++) {

					cnt[i]=0;
					cnt[j]=0;
					int a=1;
					int count=0;
					for (int j2 = 0; j2 < cnt.length; j2++) {
						if(j2!=i&&j2!=j) {
							cnt[j2]=a;
							a++;
						}
					}
					for (int k = 0; k < cnt.length; k++) {
						for (int k2 = 0; k2 < cnt.length; k2++) {
							if(cnt[k]!=0&&cnt[k2]!=0) {
								if(graph[k][k2]==1&&k!=k2) {
									count++;
								}
							}
						}
					}
					count=count/2;

					if(connect[i]>connect[j]) {
						for (int k = 0; k < cnt.length; k++) {
							if(graph[i][k]!=1&&graph[j][k]==1&&k!=i) {
								count++;

							}
						}
						count=count+connect[i];
					}else {
						for (int k = 0; k < cnt.length; k++) {
							if(graph[j][k]!=1&&graph[i][k]==1&&k!=j) {
								count++;
							}
						}
						count=count+connect[j];
					}

					if(count>max) {
						max=count;
					}

					cnt[i]=0;
					cnt[j]=0;

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

	}
}


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

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

class TaskA {

    public void solve(int testNumber, Scanner in, PrintWriter out) {
        String input = in.next();
        int res = -1;
        int first = 0;
        String max = "1000000";
        for (int second = 1; second < input.length(); ++second){
            for (int third = second + 1; third < input.length(); ++third){
                if (second - first > 7 || third - second > 7 || input.length() - third > 7){
                    continue;
                }
                if (second - first == 7 && !input.substring(first, second).equals(max)) {
                    continue;
                }
                if (third - second == 7 && !input.substring(second, third).equals(max)){
                    continue;
                }
                if (input.length() - third == 7 && !input.substring(third).equals(max)){
                    continue;
                }
                if (input.charAt(first) == '0' && second != 1){
                    continue;
                }
                if (input.charAt(second) == '0' && third != second + 1){
                    continue;
                }
                if (input.charAt(third) == '0' && third != input.length() - 1){
                    continue;
                }
                int val = Integer.valueOf(input.substring(first, second) ) + Integer.valueOf(input.substring(second, third) )+ Integer.valueOf(input.substring(third) );
                res = Math.max(val, res);
            }
        }
        out.println(res);return;
    }
}


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

public class A655 {

	private static boolean home = !"true".equals(System.getProperty("ONLINE_JUDGE"));
	private static boolean debug = false;

	public static void main(String[] args) throws IOException {
		int nrTeste = 2;
String[] inputs = {"AB\nXC\nXB\nAC\n", "AB\nXC\nAC\nBX\n"};
String[] expected = {"YES\n", "NO\n"};
		for (int i = 0; home && i < nrTeste; i++) {
			System.out.print("\nExpect: " + expected[i] + "\n   Got: ");
			System.setIn(new ByteArrayInputStream(inputs[i].getBytes()));
			solve();
		}
		if (!home) {
			solve();
		}
		System.out.close();
	}

	public static void solve() throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		String line1 = br.readLine();
		String s = br.readLine();
		line1 = line1 + s.charAt(1) + s.charAt(0);
		if (home) {
			System.out.println(line1);
		}
		while(line1.charAt(0) != 'X') {
			line1 = line1.substring(1) + line1.charAt(0);
		}
		if (home) {
			System.out.println(line1);
		}
		String line2 = br.readLine();
		s = br.readLine();
		line2 = line2 + s.charAt(1) + s.charAt(0);
		while(line2.charAt(0) != 'X') {
			line2 = line2.substring(1) + line2.charAt(0);
		}
		if (home) {
			System.out.println(line2);
		}
		boolean yes = false;
		for (int i = 0; i< 4; i++) {
			if (line1.equals(line2)){
				pw.println("YES");
				yes = true;
				break;
			}
			line2 = 'X' + line2.substring(2) + line2.charAt(1);
			if (home) {
				System.out.println(line2);

			}
		}
		if (!yes) {
			pw.println("NO");

		}
		br.close();
		pw.flush();
	}

}


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

public class cfProblem {

	public static void main(String[] args) throws Exception {
		execute();
	}

	public static void execute() throws Exception
	{
		String s = nextString();
		String l = "><+-.,[]";
		int sum = 0;
		for (int i = 0; i < s.length(); i++) {
			for (int j = 0; j < l.length(); j++) {
				if (s.charAt(i) == l.charAt(j)) {
					sum = (sum * 16 + (8 + j)) % 1000003;
					break;
				}
			}
		}
		write(sum);
	}

    static BufferedReader jin = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;

    static String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            String line = jin.readLine();
            if (line == null) {
                return null;
            }
            st = new StringTokenizer(line);
        }
        return st.nextToken();
    }

    static void write(Object... s) {
    	for (Object ss : s)
    		System.out.print(String.valueOf(ss));
    }

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

    static String nextString() throws IOException {
        return (String)nextToken();
    }

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

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

}


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

public class Main{
static int mod = (int)(Math.pow(10, 9) + 7);

   public static void main(String[] args) {
      MyScanner sc = new MyScanner();
      out = new PrintWriter(new BufferedOutputStream(System.out));
      long n = sc.nextLong();
      long b=  sc.nextLong();
      //b = pow(10,9)+7;

      HashMap<Long, Long> pf = new HashMap<Long, Long>();
      for (long i = 2; i * i <= b; i++) {
    	  long t = 0;
    	  while (b % i == 0) {
    		  b /= i;
    		  t++;
    	  }
    	  if (t > 0) {
    		  pf.put(i, t);
    	  }
      }
      if (b > 1) {
    	  pf.put(b, (long) 1);
      }
     long maxSum = Long.MAX_VALUE;
     for (Map.Entry<Long, Long> e: pf.entrySet()) {
    	 	long p = e.getKey();
    	 	long t = e.getValue();
    	 	long temp = n;
   	  long sum = 0;
   	  while (temp> 0) {
   		  sum += temp/=p;
   	  }
   	  maxSum = Long.min(maxSum, sum/t);
     }

  	  out.println(maxSum);

    	  out.close();
   }

   static long pow(long a, long N) {
	   if (N == 0) return 1;
	   else if (N == 1) return a;
	   else {
		   long R = pow(a,N/2);
		   if (N % 2 == 0) {
			   return R*R;
		   }
		   else {
			   return R*R*a;
		   }
	   }
   }

   static long powMod(long a, long N) {
	   if (N == 0) return 1;
	   else if (N == 1) return a % mod;
	   else {
		   long R = powMod(a,N/2) % mod;
		   R *= R % mod;
		   if (N % 2 == 1) {
			   R *= a % mod;
		   }
			   return R % mod;
	   }
   }
static void mergeSort(int[] A){ // low to hi sort, single array only
      int n = A.length;
      if (n < 2) return;
      int[] l = new int[n/2];
      int[] r = new int[n - n/2];

      for (int i = 0; i < n/2; i++){
        l[i] = A[i];
      }

      for (int j = n/2; j < n; j++){
        r[j-n/2] = A[j];
      }

      mergeSort(l);
      mergeSort(r);
      merge(l, r, A);
    }

    static void merge(int[] l, int[] r, int[] a){
      int i = 0, j = 0, k = 0;
      while (i < l.length && j < r.length && k < a.length){
        if (l[i] < r[j]){
          a[k] = l[i];
          i++;
        }
        else{
          a[k] = r[j];
          j++;
        }
        k++;
      }
      while (i < l.length){
        a[k] = l[i];
        i++;
        k++;
      }

      while (j < r.length){
        a[k] = r[j];
        j++;
        k++;
      }
    }

   //-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;

   //-----------MyScanner class for faster input----------
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;

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

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

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

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

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

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

   }
   //--------------------------------------------------------
}


import java.util.*;
public class C14 {
	static int[][] grid;
	public static void main(String[] args)	{
		Scanner scan = new Scanner(System.in);
		grid = new int[4][4];
		for(int i = 0; i < 4; i++)
			for(int j = 0; j < 4; j++)
				grid[i][j] = scan.nextInt();
		fix(0);
		fix(1);
		fix(2);
		fix(3);
		for(int i = 0; i < 4; i++)	{
			for(int j = i+1; j < 4; j++)	{
				if(grid[i][0] != grid[j][0])
					continue;
				if(grid[i][1] != grid[j][1])
					continue;
				if(grid[i][2] != grid[j][2])
					continue;
				if(grid[i][3] != grid[j][3])
					continue;
				System.out.println("NO");
				return;
			}
		}
		Set<Integer> x = new HashSet<Integer>();
		Set<Integer> y = new HashSet<Integer>();
		x.add(grid[0][0]);
		x.add(grid[0][2]);
		y.add(grid[0][1]);
		y.add(grid[0][3]);
		x.add(grid[1][0]);
		x.add(grid[1][2]);
		y.add(grid[1][1]);
		y.add(grid[1][3]);
		x.add(grid[2][0]);
		x.add(grid[2][2]);
		y.add(grid[2][1]);
		y.add(grid[2][3]);
		x.add(grid[3][0]);
		x.add(grid[3][2]);
		y.add(grid[3][1]);
		y.add(grid[3][3]);
		if(x.size() != 2 || y.size() != 2)	{
			System.out.println("NO");
			return;
		}
		if((grid[0][0] == grid[0][2]) == (grid[0][1] == grid[0][3]))	{
			System.out.println("NO");
			return;
		}
		if((grid[1][0] == grid[1][2]) == (grid[1][1] == grid[1][3]))	{
			System.out.println("NO");
			return;
		}
		if((grid[2][0] == grid[2][2]) == (grid[2][1] == grid[2][3]))	{
			System.out.println("NO");
			return;
		}
		if((grid[3][0] == grid[3][2]) == (grid[3][1] == grid[3][3]))	{
			System.out.println("NO");
			return;
		}
		System.out.println("YES");
	}
	public static void fix(int x)	{
		if(grid[x][0] > grid[x][2])	{
			int x1 = grid[x][0];
			int y1 = grid[x][1];
			int x2 = grid[x][2];
			int y2 = grid[x][3];
			grid[x][0] = x2;
			grid[x][1] = y2;
			grid[x][2] = x1;
			grid[x][3] = y1;
		}
		if(grid[x][0] == grid[x][2] && grid[x][1] > grid[x][3])		{
			int x1 = grid[x][0];
			int y1 = grid[x][1];
			int x2 = grid[x][2];
			int y2 = grid[x][3];
			grid[x][0] = x2;
			grid[x][1] = y2;
			grid[x][2] = x1;
			grid[x][3] = y1;
		}
	}
}


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

public class ENC {

	public static void main(String[] args) throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer(br.readLine());
		int a=Integer.parseInt(st.nextToken());
		int b=Integer.parseInt(st.nextToken());
		int c=Integer.parseInt(st.nextToken());
		int total=a*b*c;
		int[] d=new int[total];
		for (int i=0;i<total;i++){
			for (int j=i;j<total;j+=i+1){
				d[j]++;
			}
		}
		long res=0;
		for (int i=1;i<=a;i++){
			for (int j=1;j<=b;j++){
				for (int k=1;k<=c;k++){
					res+=d[i*j*k-1];
				}
			}
		}
		System.out.println(res);
	}

}