import java.util.List;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.StringTokenizer;
import java.io.InputStream;

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

class TaskB {
    final int mod = 1000000007;
    long[] cnt = new long[10];

    long c(long n, long k){
        long ans = 1;
        for(int i = 0; i <k; ++i){
            ans *= n - i;
            ans %= mod;
            ans *= IntegerUtils.modInverse(i + 1, mod);
            ans %= mod;
        }
        return ans;
    }
    long solve(int level, int[] number, int sum){
        if(sum >= 9)
            return 0;
        if(level == 6){
            long ans = 0;
            for(int i = sum + 1; i <= 9; ++i){
                long res = cnt[i];
                for(int j = 0; j <= 9; ++j){
                    res *= c(cnt[j],number[j]);
                    res %= mod;
                }
                ans += res;
                ans %= mod;
            }
            return ans;
        }
        long res = 0;
        for(int i = 0; i <= 8; ++i){
            number[i]++;
            sum+=i;
            res += solve(level + 1, number, sum);
            res %= mod;
            sum-=i;
            number[i]--;
        }
        return res;

    }
    public void solve(int testNumber, Reader in, OutputWriter out) {

        int n = in.nextInt();
        String s = String.valueOf(n);
        int x[][] = new int[11][11];

        x[0][0] = 1;
        for(int i = 1; i < 11; ++i){
            x[i][0] = x[i - 1][0] * 8;
            for(int j = 1; j < 11; ++j){
                x[i][j] = x[i - 1][j] * 8 + x[i - 1][j - 1] * 2;
            }
        }

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

            if(s.charAt(i) > '0'){
                long mult = s.charAt(i)  -'0';
                long m2 = 0;
                if(mult >= 8){
                    --mult;
                    ++m2;
                }
                if(mult >= 5){
                    --mult;
                    ++m2;
                }

                int l = s.length() - i;
                for(int  r = 0; r <=l ;++r){
                    if(cur + r > 10)
                        continue;
                    cnt[cur + r] += x[l - 1][r] * mult %mod;
                    cnt[cur + r] %= mod;
                    if(m2 >= 0 && cur + r + 1 <= 10){
                        cnt[cur + r + 1] += (x[l - 1][r] * m2) % mod;
                        cnt[cur + r + 1] %= mod;
                    }

                }

            }

            if(s.charAt(i) == '4' || s.charAt(i)== '7')
                ++cur;

        }

        cnt[0]--;
        cnt[cur]++;

        //out.println(Arrays.toString(cnt));

        out.println(solve(0,new int[10], 0) * 720 % mod);
    }

}

class IntegerUtils {

    public static long power(long base, long power, long mod) {
        long result = 1 % mod;
        base %= mod;
        while (power > 0) {
            if (power % 2 == 1) {
                result *= base;
                result %= mod;
            }
            base *= base;
            base %= mod;
            power >>= 1;
        }
        return result;
    }

    public static long modInverse(long number, long mod) {
        return power(number, mod - 2, mod);
    }

    }

class Reader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public Reader(BufferedReader reader) {
        this.reader = reader;
    }

    public Reader(InputStream stream) {
        this(new BufferedReader(new InputStreamReader(stream)));
    }

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

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

    private String readLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

class OutputWriter extends PrintWriter {

    public OutputWriter(OutputStream out) {
        super(out);
    }

    public OutputWriter(java.io.Writer writer){
        super(writer);
    }

    }


package current;

import io.Reader;
import io.OutputWriter;
import numbers.IntegerUtils;

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

public class TaskB {
    final int mod = 1000000007;

    long c(long n, long k){
        long ans = 1;
        for(int i = 0; i <k; ++i){
            ans *= n - i;
            ans %= mod;
            ans *= IntegerUtils.modInverse(i + 1, mod);
            ans %= mod;
        }
        return ans;
    }
    long solve(int level, long [] number, int sum){
        if(sum >= 9)
            return 0;
        if(level == 6){
            long ans = 0;
            for(int i = sum + 1; i <= 9; ++i){
                ans += number[i];
                ans %= mod;
            }
            return ans;
        }
        long res = 0;
        for(int i = 0; i <= 9; ++i){
            if(number[0] == 0)
                continue;
            number[i]--;
            sum += i;
            res += solve(level + 1, number, sum) * (number[i] + 1) % mod;
            res %= mod;
            sum-=i;
            number[i]++;
        }
        return res;

    }
    public void solve(int testNumber, Reader in, OutputWriter out) {

        int n = in.nextInt();
        String s = String.valueOf(n);
        int x[][] = new int[11][11];
        long[] cnt = new long[11];
        x[0][0] = 1;
        for(int i = 1; i < 11; ++i){
            x[i][0] = x[i - 1][0] * 8;
            for(int j = 1; j < 11; ++j){
                x[i][j] = x[i - 1][j] * 8 + x[i - 1][j - 1] * 2;
            }
        }

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

            if(s.charAt(i) > '0'){
                long mult = s.charAt(i)  -'0';
                long m2 = 0;
                if(mult >= 8){
                    --mult;
                    ++m2;
                }
                if(mult >= 5){
                    --mult;
                    ++m2;
                }

                int l = s.length() - i;
                for(int  r = 0; r <=l ;++r){
                    if(cur + r > 10)
                        continue;
                    cnt[cur + r] += x[l - 1][r] * mult %mod;
                    cnt[cur + r] %= mod;
                    if(m2 >= 0 && cur + r + 1 <= 10){
                        cnt[cur + r + 1] += (x[l - 1][r] * m2) % mod;
                        cnt[cur + r + 1] %= mod;
                    }

                }

            }

            if(s.charAt(i) == '4' || s.charAt(i)== '7')
                ++cur;

        }

        cnt[0]--;
        cnt[cur]++;

        //out.println(Arrays.toString(cnt));

        out.println(solve(0,cnt, 0));
    }

}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class q5 {
	static ArrayList<Integer>[] gph,rgph;
	static int[] visited1,visited2;
	static boolean cycle;
	static int[] count;
	static void dfs(int i) {
		visited1[i]=1;
		visited2[i]=1;
		for(int x:gph[i]) {
			if(visited2[x]==1) {
				cycle=true;break;
			}
			else {
				if(visited1[x]==0) dfs(x);
			}
		}
		visited2[i]=0;

	}

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

		Reader.init(System.in);
		PrintWriter out=new PrintWriter(System.out);
		StringBuffer output=new StringBuffer("");
//		int n=Reader.nextInt(),m=Reader.nextInt();
//		String s=Reader.next();
//		 gph=new ArrayList[n+1];
//		 visited1=new int[n+1];visited2=new int[n+1];
//		 int[] deg=new int[n+1];
//		 long[][] v=new long[n][26];
//		 rgph=new ArrayList[n+1];
//		for(int i=1;i<=n;i++) gph[i]=new ArrayList<Integer>();
//		for(int i=1;i<=n;i++) rgph[i]=new ArrayList<Integer>();
//		for(int i=0;i<m;i++) {
//			int a=Reader.nextInt();
//			int b=Reader.nextInt();
//			gph[a].add(b);
//			deg[b]++;
//			rgph[b].add(a);
//
//		}
//		cycle=false;
//		for(int i=1;i<=n;i++) {
//			if(visited1[i]==0) {
//				dfs(i);
//			}
//		}
//		if(cycle) {
//			output.append(-1);
//		}
//		else {
//			count=new int[26];
//
//		}
		long a,b,p,x;
		a=Reader.nextLong();b=Reader.nextLong();p=Reader.nextLong();x=Reader.nextLong();
		BigInteger aa=BigInteger.valueOf(a);
		BigInteger bb=BigInteger.valueOf(b);
		BigInteger pp=BigInteger.valueOf(p);
		long ans=0;
		for(int i=1;i<p;i++) {
			BigInteger cc=aa.modPow(BigInteger.valueOf((long)i), pp);
			cc=cc.modInverse(pp);
			cc=cc.multiply(bb);
			cc=cc.mod(pp);
			long v=cc.longValue();
			long xx=(x-i)/(p-1);
			long k=(i-v+p)%p;
			if(xx>=0 && x-i>=0) {
				long v2=(xx)/(p);
				if(k<=xx%p) v2++;

				ans+=v2;
			}
		}
		output.append(ans);
		out.write(output.toString());
		out.flush();

	}
}
class NoD{
	int a,b;
	String s;
	NoD(int aa,int bb){
		a=aa;b=bb;
		s=a+" "+b;
	}
	@Override
	public boolean equals(Object o) {
		if(o!=null && o.getClass()==getClass()) {
			NoD c= (NoD) o;
			return c.a==a && c.b==b;
		}
		return false;
	}
	@Override
	public int hashCode() {
		return s.hashCode();
	}
}

class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

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

    /** get next word */
    static String nextLine() throws IOException{
    	return reader.readLine();
    }
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }

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


import com.sun.xml.internal.bind.v2.model.core.ID;

import java.io.*;
import java.lang.reflect.Array;
import java.math.*;
import java.text.DecimalFormat;
import java.util.*;

public class Main {
    private static int [] inv;
    private static int [] A;
    private static int n;
    private static HashMap<Integer,Integer> HM ;
    private static HashMap<Integer,LinkedList<Integer> > Sol = new HashMap<>();

    private static int mul(int a,int b,int m) {
        long ab = a*(long)b;
        ab %= m;
        if (ab < 0) ab += m;
        return (int) ab;
    }

    private static void init(int a,int p){
        inv = new int[p];
        inv[1] = 1;
        for (int i = 2;i < p;i++)
            inv[i] = mul(-(p/i),inv[p%i],p);

        A = new int[p];
        for (int i = 0,q = 1;i < p;i++) {
            A[i] = q;
            q = mul(a,q,p);
        }

        n = (int)(Math.sqrt(p + 0.0) + 1);
        n = Math.min(n,p-1);
        int an = A[n];
        HM = new HashMap<>();
        for (int i = 1,q = an;i <= n;i++) {
            if (!HM.containsKey(q)) HM.put(q,i);
            q = mul(q,an,p);
        }
    }

    public static void main(String[] args) throws Exception{
        IO io = new IO(null,null);
        int a = io.getNextInt(),b = io.getNextInt(),p = io.getNextInt();
        long x = io.getNextLong();
        init(a,p);

        long ans = 0;
        for (int n0 = 0,q = 1;n0 < p - 1 && n0 <= x;n0++) {
            int y = mul(inv[q],b,p);
            y = n0 - y;
            if (y < 0) y += p;
            // k*(p-1) + n0 <= x
            // k <= (x-n0)/p
            long lim = (x-n0)/(p - 1);
//            System.err.println(n0 + ". " + (y*(p-1L) + n0) + " q = " + q + " y = " + y + " lim = " + lim);
            if (y <= lim)
                ans += (lim - y)/p + 1;

            q = mul(q,a,p);
        }
        io.println(ans);

        io.close();
    }
}

class IO{
    private BufferedReader br;
    private StringTokenizer st;
    private PrintWriter writer;
    private String inputFile,outputFile;

    public boolean hasMore() throws IOException{
        if(st != null && st.hasMoreTokens()) return true;
        if(br != null && br.ready()) return true;
        return false;
    }
    public String getNext() throws FileNotFoundException, IOException{
        while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public String getNextLine() throws FileNotFoundException, IOException{
        return br.readLine().trim();
    }

    public int getNextInt() throws FileNotFoundException, IOException{
        return Integer.parseInt(getNext());
    }
    public long getNextLong() throws FileNotFoundException, IOException{
        return Long.parseLong(getNext());
    }

    public void print(double x,int num_digits) throws  IOException{
        writer.printf("%." + num_digits + "f" ,x);
    }
    public void println(double x,int num_digits) throws  IOException{
        writer.printf("%." + num_digits + "f\n" ,x);
    }
    public void print(Object o) throws  IOException{
        writer.print(o.toString());
    }

    public void println(Object o) throws  IOException{
        writer.println(o.toString());
    }
    public IO(String x,String y) throws FileNotFoundException, IOException{
        inputFile = x;
        outputFile = y;
        if(x != null) br = new BufferedReader(new FileReader(inputFile));
        else br = new BufferedReader(new InputStreamReader(System.in));
        if(y != null) writer = new PrintWriter(new BufferedWriter(new FileWriter(outputFile)));
        else writer = new PrintWriter(new OutputStreamWriter(System.out));
    }

    protected void close() throws IOException{
        br.close();
        writer.close();
    }
    public void outputArr(Object [] A) throws IOException{
        int L = A.length;
        for (int i = 0;i < L;i++) {
            if(i > 0) writer.print(" ");
            writer.print(A[i]);
        }
        writer.print("\n");
    }
}


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

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

    static class Solver{
/*
        long powMod(long a, long b, long mod) {
            long ans = 1;
            for(;b!=0;b>>=1) {
                if((b&1) != 0) {
                    ans=ans*a%mod;
                }
                a=a*a%mod;
            }
            return ans;
        }
*/
        long powMod(long a, long b, long p) {
            if(b == 1)return a;
            if(b == 0)return 1;
            return ((powMod(a,b/2,p)%p)*(powMod(a,b-b/2,p)%p)) % p;
        }
        long inv(long a, long mod) {
            return powMod(a,mod-2,mod)%mod;
        }

        void solve(InputReader in, PrintWriter out) {
            long a=in.nextLong(),b=in.nextLong(),p=in.nextLong(),x=in.nextLong();
            long ans = 0;long P = p*(p-1);
            for(long i=1;i<p;++i) {
                long ai = powMod(a,i,p);
                long binv = b*inv(ai,p) % p;
                long r=(p*i+(p-1)*(p-1)%P*binv)%P;
                ans+=x/P+((x%P>=r)?1:0);
            }
            out.println(ans);
        }

    }

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

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

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

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

    }
}


import java.util.*;

public class E {

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

		int a = sc.nextInt(), b = sc.nextInt(), p = sc.nextInt();
		long x = sc.nextLong();

		long arr[] = new long[p];
		arr[p-1] = 1;
		for(int i=p-2;i>=0;i--){
			arr[i] = arr[i+1] * a % p;
		}

		long ans = 0;
		long T = (long)p*(p-1);

		for(int i = 1;i<=p-1;i++){
			long j = (i- b * arr[i]) % p;
			while(j < 0){
				j+=p;
			}

			long n = j * (p-1) + i;

			while(n <= x){
				ans ++;
				n += T;
			}
		}

		System.out.println(ans);

	}

}


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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			int [][] mp = new int [10][10];
			for(int i=0;i<m;i++) {
				int a = sc.nextInt();
				int b = sc.nextInt();
				mp[a][b]=1;
				mp[b][a]=1;
			}

			if(n<=6) {
				System.out.println(m);
			}
			else {
				if(m==21) {
					System.out.println(16);
				}
				else {
					int ans=0;
					for(int i=1;i<=7;i++) {
						for(int j=i+1;j<=7;j++) {
							int sum=0;
							for(int k=1;k<=7;k++) {

								if(mp[i][k]!=0&&mp[j][k]!=0){
									sum++;
								}
							}
							ans=Math.max(ans,m-sum+1);
						}
					}
					System.out.println(ans);
				}
			}
		}
	}

}


import java.util.Scanner;
import java.util.StringTokenizer;

import java.util.Scanner;

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

       while(sc.hasNext()){
           int n=sc.nextInt();
           int k=sc.nextInt();
           int a[][]=new int[10][10];
           for (int i=0;i<k;i++){
               int b=sc.nextInt();
               int c=sc.nextInt();
           }
           if(n<=6){
               System.out.println(k);
           }else{
               if (k==21){
                   System.out.println(16);
               }else{
                   int ans=0;
                   for (int i=1;i<=7;i++){
                       for (int j=1;j<=7;j++){
                           int sum=0;
                           for (int l=0;i<=7;l++){
                               if (a[i][k]!=0 && a[j][k]!=0){
                                   sum++;
                               }
                           }
                           ans=Math.max(ans,k-sum);

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

    }
}


import java.util.Scanner;
public class Fff {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n= sc.nextInt();
		int m= sc.nextInt();
		int a= sc.nextInt();
		int b= sc.nextInt();
		int price =0;
		int d= 0;
if (n%2==0){
	d=n/m;
	price= c*b;}
else {
	n=n-1;
	d=n/m;
	price= d*b;
	price= price+a;
	}
System.out.print(price);
	}
}


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

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

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(br.readLine());
        int c[] = new int[n];
        StringTokenizer str = new StringTokenizer(br.readLine());
        for (int i = 0; i < n; i++) {
            c[i] = Integer.parseInt(str.nextToken());
        }
        if( (n % 2 == 0) && (c[0] % 2 == 0) && (c[n-1] % 2 == 0)){
            System.out.println("No");
        }
        else{
            System.out.println("Yes");
        }

    }
}


import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	int n;
	int [] arr;
	public static void main(String[] args) throws Exception {
        new Main();
    }

	public Main() throws Exception{
		Scanner sc = new Scanner(System.in);
//		Scanner sc = new Scanner(new FileReader("input"));

		n = sc.nextInt();
		arr = new int[n];

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

		if (canDevideInOdd(arr)){
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

        sc.close();
	}

	boolean canDevideInOdd(int[] arr1){

		if (arr1.length == 0){
			return false;
		}
		if ( arr1[0]%2==0 ){
			return false;
		}

		if ( arr1[arr1.length - 1]%2==0 ){
			return false;
		}

		if (arr1[0] % 2 == 1 && arr1.length % 2 == 1 && arr1[arr1.length - 1] % 2 == 1){
			return true;
		}

		for (int i=0;i<arr1.length;i++){
			if (arr1[i]%2 == 1 && (i + 1)% 2 == 1){
				int [] arr2 = new int[arr1.length - i - 1];
				for (int j=i + 1;j<arr1.length;j++){
					arr2[j - (i + 1)] = arr1[j];
				}
				if (canDevideInEven(arr2)){

					return true;
				}

			}

		}
		return false;
	}

	boolean canDevideInEven(int[] arr1){

		if (arr1.length == 0){
			return true;
		}
		if ( arr1[0]%2==0 ){
			return false;
		}

		if ( arr1[arr1.length - 1]%2==0 ){
			return false;
		}

		for (int i=0;i<arr1.length;i++){
			if (arr1[i]%2 == 1 && (i + 1) % 2 == 1){
				int [] arr2 = new int[arr1.length - i - 1];
				for (int j=i + 1;j<arr1.length;j++){
					arr2[j - (i + 1)] = arr1[j];
				}
//				printArr(arr2);
				if (canDevideInOdd(arr2)){
					return true;
				}

			}

		}

		return false;
	}

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

	}

}


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

public class E {
    static int n;
    static int m;
    static int[][][] DP;
    static int[] dx = { 0, 0, 1, -1 };
    static int[] dy = { 1, -1, 0, 0 };
    static int inf = 1000000;

    public static int get(int x, int current, int last) {
        if (x == n) {
            if (last == 0)
                return 0;
            else
                return -inf;
        }
        if (DP[x][current][last] != -1)
            return DP[x][current][last];
        int max = 0;
        for (int mask = 0; mask < (1 << m); mask++) {
            int tempLast = last;
            int tempCurrent = current;
            int tempNext = (1 << m) - 1;
            for (int i = 0; i < m; i++)
                if ((mask & (1 << i)) != 0) {
                    if (i > 0)
                        tempCurrent &= ~(1 << (i - 1));
                    if (i < m - 1)
                        tempCurrent &= ~(1 << (i + 1));
                    tempNext &= ~(1 << (i));
                    tempLast &= ~(1 << (i));
                }
            if (tempLast != 0)
                continue;
            max = Math.max(
                    max,
                    m - Integer.bitCount(mask)
                            + get(x + 1, tempNext, tempCurrent & ~mask));
        }
        return DP[x][current][last] = max;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();
        int y = in.nextInt();
        n = Math.max(x, y);
        m = Math.min(x, y);
        DP = new int[n][1 << m][1 << m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < (1 << m); j++)
                Arrays.fill(DP[i][j], -1);
        System.out.println(get(0, (1 << m) - 1, 0));
    }
}
package Rnd85;

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

public class E {
    static int n;
    static int m;
    static int[][][] DP;
    static int[] dx = { 0, 0, 1, -1 };
    static int[] dy = { 1, -1, 0, 0 };
    static int inf = 1000000;

    public static int get(int x, int current, int last) {
        if (x == n) {
            if (last == 0)
                return 0;
            else
                return -inf;
        }
        if (DP[x][current][last] != -1)
            return DP[x][current][last];
        int max = 0;
        for (int mask = 0; mask < (1 << m); mask++) {
            int tempLast = last;
            int tempCurrent = current;
            int tempNext = (1 << m) - 1;
            for (int i = 0; i < m; i++)
                if ((mask & (1 << i)) != 0) {
                    if (i > 0)
                        tempCurrent &= ~(1 << (i - 1));
                    if (i < m - 1)
                        tempCurrent &= ~(1 << (i + 1));
                    tempNext &= ~(1 << (i));
                    tempLast &= ~(1 << (i));
                }
            if (tempLast != 0)
                continue;
            max = Math.max(
                    max,
                    m - Integer.bitCount(mask)
                            + get(x + 1, tempNext, tempCurrent & ~mask));
        }
        return DP[x][current][last] = max;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();
        int y = in.nextInt();
        n = Math.max(x, y);
        m = Math.min(x, y);
        DP = new int[n][1 << m][1 << m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < (1 << m); j++)
                Arrays.fill(DP[i][j], -1);
        System.out.println(get(0, (1 << m) - 1, 0));
    }
}


import java.util.*;
public class ckde {
    public static void main(String[]args){
        Scanner sc= new Scanner(System.in);
        String s=sc.next();
        char x=s.charAt(0);
        char y=s.charAt(s.length()-1);
        if(s.length()<2) System.out.println(s);

        else{
            String ans=""+x;
            s=s.substring(1,s.length()-1);
            int size=s.length();
            s+="";
            boolean ukve=true;
            for(int i=0;i<size;i++){
                if( i!=0 && i!=size-3 &&  i+3<size && s.substring(i,i+3).equals("dot")){
                    ans+=".";
                    i+=2;
                }
                else if( i!=0 && i!= size-2 && i+2<size && s.substring(i,i+2).equals("at") && ukve){
                    ans+="@";
                    i+=1;
                    ukve=false;
                }
                else ans+=s.charAt(i);
            }
            ans+=y;
            System.out.println(ans);

        }
    }
}


import java.util.*;

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

        int n = sc.nextInt();

        int[] a = new int[n];

        int maxCount = 0;

        for(int i=0; i<a.length; i++){
            a[i] = sc.nextInt();
            if(a[i] == 1){
                maxCount++;
            }
        }

        for(int j=0; j<n; j++){
            for(int i=0; i<=j; i++){
                int count = 0;

                for(int k=0; k<n; i++){
                    if(k <=i && k<=j){
                        count += 1 - a[k];
                    }
                    else{
                        count += a[k];
                    }
                }

                if(maxCount < count){
                    maxCount = count;
                }
            }
        }

        System.out.println(maxCount);
    }
}


import java.io.*;
import java.util.Arrays;
import java.util.Locale;
import java.util.StringTokenizer;
import java.util.function.Function;

public class E {
    String fileName = "E";

    public int n, m;

    public static class Event implements Comparable<Event> {
        public static final int OPEN_TYPE = 0;
        public static final int POINT_TYPE = 1;
        public static final int CLOSE_TYPE = 2;

        public int x, type;

        public Event(int x, int type) {
            this.x = x;
            this.type = type;
        }

        @Override
        public int compareTo(Event event) {
            if (Integer.compare(x, event.x) != 0)
                return Integer.compare(x, event.x);
            else return Integer.compare(type, event.type);
        }
    }

    public static final class Node {
        public int l, r;
        public int max, maxInd;

        public Node leftNode, rightNode;

        public Node(int l, int r) {
            this.l = l;
            this.r = r;
        }
    }

    public void relax(Node root) {
        if (root.leftNode.max > root.rightNode.max) {
            root.max = root.leftNode.max;
            root.maxInd = root.leftNode.maxInd;
        } else {
            root.max = root.rightNode.max;
            root.maxInd = root.rightNode.maxInd;
        }
    }

    public Node build(int l, int r, Function<Integer, Integer> getItem) {
        Node res = new Node(l, r);
        if (l == r) {
            res.max = getItem.apply(l);
            res.maxInd = l;
        } else {
            int m = (r + l) / 2;
            res.leftNode = build(l, m, getItem);
            res.rightNode = build(m + 1, r, getItem);
            relax(res);
        }
        return res;
    }

    public void set(Node root, int ind, int val) {
        if (ind < root.l || ind > root.r)
            return;
        if (root.l == root.r) {
            root.max = val;
            return;
        }
        set(root.leftNode, ind, val);
        set(root.rightNode, ind, val);
        relax(root);
    }

    public static class QueryResult {
        public int max, maxInd;

        public QueryResult(int max, int maxInd) {
            this.max = max;
            this.maxInd = maxInd;
        }

        public QueryResult(QueryResult first, QueryResult second) {
            if (first.max > second.max) {
                this.max = first.max;
                this.maxInd = first.maxInd;
            } else {
                this.max = second.max;
                this.maxInd = second.maxInd;
            }
        }
    }

    public QueryResult query(Node root, int l, int r) {
        if (r == -1)
            return new QueryResult(0, -1);
        if (r < root.l || l > root.r)
            return new QueryResult(Integer.MIN_VALUE, -1);
        if (l <= root.l && r >= root.r) {
            return new QueryResult(root.max, root.maxInd);
        }
        return new QueryResult(query(root.leftNode, l, r), query(root.rightNode, l, r));
    }

    public int[] getLens(int[] a) {
        Node root = build(0, n, ind -> 0);
        int[] len = new int[a.length];
        for (int i = 0; i < a.length; i++) {
            int curVal = a[i];
            int prevLen = query(root, 0, curVal).max;
            len[i] = prevLen + 1;
            if (query(root, curVal, curVal).max < len[i])
                set(root, curVal, len[i]);
        }
        return len;
    }

    public void solve() throws IOException {
        n = nextInt();
        m = nextInt();
        Event[] events = new Event[2 * n + m];
        for (int i = 1; i <= m; i++) {
            events[i - 1] = new Event(i, Event.POINT_TYPE);
        }
        for (int i = 0; i < n; i++) {
            int l = nextInt();
            int r = nextInt();
            events[m + 2 * i] = new Event(l, Event.OPEN_TYPE);
            events[m + 2 * i + 1] = new Event(r, Event.CLOSE_TYPE);
        }
        Arrays.sort(events);
        int[] cnt = new int[m];
        int balance = 0;
        for (int i = 0; i < events.length; i++) {
            Event curEvent = events[i];
            if (curEvent.type == Event.OPEN_TYPE) {
                balance++;
            } else if (curEvent.type == Event.CLOSE_TYPE) {
                balance--;
            } else if (curEvent.type == Event.POINT_TYPE) {
                cnt[curEvent.x - 1] = balance;
            }
        }
        int[] lenUp = getLens(cnt);
        int[] newCnt = new int[cnt.length];
        for (int i = 0; i < cnt.length; i++) {
            newCnt[i] = cnt[cnt.length - i - 1];
        }
        int[] lenDown = getLens(newCnt);
        int[] revLenDown = new int[lenDown.length];
        for (int i = 0; i < lenDown.length; i++) {
            revLenDown[i] = lenDown[lenDown.length - i - 1];
        }
        int max = 0;
        for (int i = 0; i < n; i++) {
            int cur = lenUp[i] + revLenDown[i] - 1;
            max = Math.max(max, cur);
        }
        out.print(max);
    }

    public void run() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);

            solve();

            out.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    BufferedReader br;
    StringTokenizer in;
    PrintWriter out;

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

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

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

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

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new E().run();
    }
}


import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

import static java.lang.Math.*;

public class Main {
    BufferedReader br;
    StringTokenizer in;
    PrintWriter pw;
    Random r;
    int INF = (int) 1e9;
    int mod = (int) (1e9 + 7);
    //int p = 26;
    ArrayList<Integer> g[];

    void end(int a, int n) {
        if ((int) Math.pow(2, a) != n) pw.print(a);
        else pw.print("Final!");
        pw.close();
        System.exit(0);
    }

    class node {
        int val;
        int m;
        int size;
        int prior;
        node L;
        node R;

        public node(int v) {
            val = v;
            prior = r.nextInt();
            size = 1;
            L = null;
            R = null;
        }
    }

    int sgs(node c) {
        if (c == null) return 0;
        return c.size;
    }

    int sgm(node c) {
        if (c == null) return INF;
        return c.m;
    }

    void relax(node c) {
        if (c == null) return;
        c.size = 1 + sgs(c.L) + sgs(c.R);
    }

    class pair implements Comparable<pair> {
        int a;
        int b;

        public pair(int aa, int bb) {
            a = aa;
            b = bb;
        }

        @Override
        public int compareTo(pair o) {
            if (a != o.a) return a - o.a;
            return b - o.b;
        }
    }

    class road {
        int to;
        int w;

        public road(int tto, int ww) {
            to = tto;
            w = ww;
        }

        public road() throws IOException {
            to = nextInt();
            w = nextInt();
        }
    }

    void readG(int n, int m) throws IOException {
        g = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            g[i] = new ArrayList<>();
        }
        for (int i = 0; i < m; i++) {
            int a = nextInt() - 1;
            int b = nextInt() - 1;
            int w = nextInt();
//            g[a].add(new road(b, w));
//            g[b].add(new road(a, w));
        }
    }

    int p[];
    int d[];

    void solve() throws IOException {
        int n = nextInt();
        int m = nextInt();
        event[] p = new event[n * 2];
        for (int i = 0; i < n; i++) {
            int l = nextInt();
            int r = nextInt();
            p[i] = new event(l, 1);
            p[i + n] = new event(r, -1);
        }
        int q = p.length;
        int b = 0;
        Arrays.sort(p);
        int bal[] = new int[m + 1];
        int prev = 0;
        for (int i = 0; i < q; i++) {
            event a = p[i];
            if (a.t == -1) {
                for (int j = prev + 1; j <= a.time; j++) {
                    bal[j] = b;
                }
                prev = a.time;
            } else {
                for (int j = prev + 1; j < a.time; j++) {
                    bal[j] = b;
                }
                prev = a.time - 1;
            }
            b += a.t;
        }
//        for (int i = 1; i <= m; i++) {
//            pw.print(bal[i]);
//        }
        int revbal[] = new int[m + 1];
        for (int i = 1; i <= m; i++) {
            revbal[i] = bal[m + 1 - i];
        }
        int nvp[] = getnvp(bal);
        int rnvp[] = getnvp(revbal);
        int ans = 0;
        for (int i = 1; i <= m; i++) {
            int z = nvp[i];
            int w = rnvp[m - i];
            int sum = z + w;
            ans = max(ans, sum);
        }
        pw.print(ans);
    }

    int[] getnvp(int a[]) {
        int n = a.length;
        int d[] = new int[n + 1];
        int ans[] = new int[n];
        Arrays.fill(d, INF);
        d[0] = -INF;
        int last = 0;
        for (int i = 1; i < n; i++) {
            ans[i] = ans[i - 1];
            int c = a[i];
            int l = 0;
            int r = last + 1;
            while (l + 1 != r) {
                int m = (l + r) / 2;
                if (d[m] <= c) l = m;
                else r = m;
            }
            if (d[r] == INF) {
                ans[i]++;
                last++;
            }
            d[r] = min(d[r], c);
        }
        return ans;
    }

    class event implements Comparable<event> {
        int time;
        int t;

        public event(int ttime, int tt) {
            time = ttime;
            t = tt;
        }

        @Override
        public int compareTo(event o) {
            if (time != o.time) return time - o.time;
            else return t - o.t;
        }
    }

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

    void run() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        pw = new PrintWriter(new OutputStreamWriter(System.out));
        r = new Random(5);
        solve();
        pw.close();
    }

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

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

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


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.*;

public class Main {
    ArrayList<ArrayList<Integer>> q;
    boolean[] used;

    public void solve() throws IOException {
        int n = nextInt();
        int m = nextInt();
        int[] a = new int[m + 1];
        for (int i = 0; i < n; i++) {
            a[nextInt() - 1]++;
            a[nextInt()]--;
        }
        for (int i = 1; i < m; i++) {
            a[i] += a[i - 1];
        }
        int[] d = new int[m + 10];
        Arrays.fill(d, Integer.MAX_VALUE);
        int k = 0;
        int[] v1 = new int[m + 1];
        int[] v2 = new int[m + 1];
        for (int i = 0; i < m; i++) {
            int l = 0;
            int r = m;
            while (r - l > 1) {
                int m1 = (r + l) / 2;
                if (d[m1] > a[i]) {
                    r = m1;
                } else {
                    l = m1;
                }
            }
            if (d[l] <= a[i]) {
                l++;
            }
            if (d[l] == Integer.MAX_VALUE){
                k++;
            }
            d[l] = a[i];
            v1[i] = k;
        }
        k = 0;
        int max = 0;
        for (int i = m - 1; i >= 0; i--) {
            int l = 0;
            int r = m + 2;
            while (r - l > 1) {
                int m1 = (r + l) / 2;
                if (d[m1] > a[i]) {
                    r = m1;
                } else {
                    l = m1;
                }
            }
            if (d[l] <= a[i]) {
                l++;
            }
            if (d[l] == Integer.MAX_VALUE){
                k++;
            }
            d[l] = a[i];
            v2[i] = k;
            max = Math.max(max,v1[i] + v2[i + 1]);
        }
        max = Math.max(max,v2[0]);
        out.print(max);
    }

    BufferedReader br;
    StringTokenizer sc;
    PrintWriter out;

    String nextToken() throws IOException {
        while (sc == null || !sc.hasMoreTokens()) {
            try {
                sc = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                sc = null;
            }
        }
        return sc.nextToken();
    }

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

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

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

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new Main().run();
    }

    public void run() throws IOException {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
}


import java.util.*;

public class A{

    public static void main(String args[]){
        Scanner s=new Scanner(System.in);
        int a=s.nextInt(),b=s.nextInt();
        if(a>b){
            System.out.print(b+" ");
            int c=a-b;
            System.out.print(c/2);
        }
        else{
            System.outprint(a+" ");
            int c=b-a;
            System.out.print(c/2);
        }
    }
}


import java.io.BufferedInputStream;
import java.util.Scanner;

/**
 * Created by jizhe on 2016/1/10.
 */
public class TrafficLights {
    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedInputStream(System.in));

        int L = in.nextInt();
        int D = in.nextInt();
        int V = in.nextInt();
        int G = in.nextInt();
        int R = in.nextInt();

        int turns = D/(V*(G+R));
        int distanceNear = D-turns*(V*(G+R));
        if( distanceNear <= G*V )
        {
            double time = (double)L/(double)V;
            System.out.printf("%f\n", time);
        }
        else
        {
            double time = turns*(G+R)+(G+R)+(double)(L-D)/(double)V;
            System.out.printf("%f\n", time);
        }
    }
}


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;
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);
        TaskB solver = new TaskB();
        solver.solve(in,out);
        out.close();
    }
}
class TaskB{
    public void solve(InputReader in, PrintWriter out){
        double l = in.nextInt();
        double d = in.nextInt();
        double v = in.nextInt();
        double g = in.nextInt();
        double r = in.nextInt();
        double x = d/v;
        double y = g+r;
        double time;
        if(x%y<g){
           time = l/v + (int)(x/y) * y;
        }
        else{
            time = r + g - x%y + l/v + (int)(x/y) * y ;
        }
        out.println(time);
    }
}
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());
    }
}


// package CF;

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

public class D {
	static int memo [][][][];
	static char [] s,t,v;
	static int [] p;
	static int INF = 20000;
	static int dp(int s1, int v1, int s2, int v2){
		if(v1 == v.length || v2 == v.length)
			return -INF;
		if(s1 == s.length || s2 == t.length)
			return 0;
		if(memo[s1][v1][s2][v2] != -1)
			return memo[s1][v1][s2][v2];
		int ans = 0;
		if(s[s1] == t[s2]){
			int tmp1 = v1, tmp2 = v2;
			if(v[v1] == s[s1])
				v1++;
			else
			{
				if(v1 > 0)
					v1 = p[v1-1];
			}
			if(v[v2] == t[s2])
				v2++;
			else{
				if(v2 > 0)
					v2 = p[v2-1];
			}
			ans = Math.max(ans, 1 + dp(s1+1, v1, s2+1, v2));
			v1 = tmp1;
			v2 = tmp2;
		}
		ans = Math.max(ans, Math.max(dp(s1+1, v1, s2, v2), dp(s1, v1, s2+1, v2)));
//		System.out.println(s1 + " " + v1 + " " + s2 + " " + v2 + " " + ans);

		return memo[s1][v1][s2][v2] = ans;
	}
	static StringBuilder sb;
	static void print(int s1, int v1, int s2, int v2){
		if(s1 == s.length || s2 == t.length)
			return;
		int opt = dp(s1, v1, s2, v2);
		if(s[s1] == t[s2]){
			int tmp1 = v1, tmp2 = v2;
			if(v[v1] == s[s1])
				v1++;
			else
			{
				if(v1 > 0)
					v1 = p[v1-1];
			}
			if(v[v2] == t[s2])
				v2++;
			else{
				if(v2 > 0)
					v2 = p[v2-1];
			}
			if(opt == 1 + dp(s1+1, v1, s2+1, v2)){
				sb.append(s[s1]);
				print(s1+1, v1, s2+1, v2);
				return;
			}
			v1 = tmp1;
			v2 = tmp2;
		}
		if(opt == dp(s1+1, v1, s2, v2))
			 print(s1+1, v1, s2, v2);
		else print(s1, v1, s2+1, v2);
	}
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		s = sc.next().toCharArray();
		t = sc.next().toCharArray();
		v = sc.next().toCharArray();
		memo = new int[101][101][101][101];
		for(int [][][]i:memo)
			for(int [][]j:i)
				for(int []k:j)
					Arrays.fill(k, -1);
		p = prefixFunction(v);
		sb = new StringBuilder();
		print(0, 0, 0, 0);
		out.println(sb.length() == 0?0:sb);
		out.flush();
		out.close();
	}
	static int[] prefixFunction(char[] s)		// O(n)
	{
		int n = s.length, pi[] = new int[n];
		for(int i = 1, j = 0; i < n; ++i)		//j = pi[i-1] at the beginning of every iteration
		{
			while(j > 0 && s[i] != s[j])
				j = pi[j-1];
			if(s[i] == s[j])
				++j;
			pi[i] = j;
		}
		return pi;
	}
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(FileReader fileReader) {
			br = new BufferedReader(fileReader);
		}

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

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

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

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

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


import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Double.parseDouble;
import static java.lang.String.*;

public class Main {

    static char [] s,t,virus;
    static int [][][] dp;
    static int [][][] choice;
    static StringBuilder sol;
    static int [] p;

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                                            //(new FileReader("input.in"));
        StringBuilder out = new StringBuilder();
        StringTokenizer tk;

        s = in.readLine().toCharArray();
        t = in.readLine().toCharArray();
        virus = in.readLine().toCharArray();

        dp = new int[s.length+1][t.length+1][virus.length+1];
        choice = new int[s.length+1][t.length+1][virus.length+1];
        sol = new StringBuilder();

        for(int i=0; i<=s.length; i++)
            for(int j=0; j<=t.length; j++)
                Arrays.fill(dp[i][j],-1);

        p = new int[virus.length];
        for(int i=1,k=0; i<virus.length; i++) {
            while(k>0 && virus[k]!=virus[i])
                k = p[k-1];
            if(virus[k]==virus[i])
                p[i] = ++k;
            else p[i] = k;
        }

        int v = calc(0,0,0);

        if(v==0) {
            System.out.println("0");
            return;
        }

        findSol(0,0,0);

        System.out.println(sol);
    }

    static int calc(int i,int j,int k) {
        if(k==virus.length)
            return -(int)1e9;
        if(i==s.length || j==t.length)
            return 0;

        if(dp[i][j][k]!=-1)
            return dp[i][j][k];

        int c3 = 0;

        if(s[i]==t[j] && !(s[i]==virus[k] && k==virus.length-1)) {
            boolean f = (virus[k]!=s[i] && k>0);
            int nk = (virus[k]==s[i] ? k+1 : (k>0 ? p[k-1] : 0));
            if(f && virus[nk]==s[i]) nk++;
            else if(f) nk = 0;

            c3 = calc(i+1,j+1,nk) + 1;
        }

        if(s[i]==t[j] && s[i]==virus[k] && k==virus.length-1) c3 = -(int)1e9;

        int c1 = calc(i+1,j,k),c2 = calc(i,j+1,k);
        int mx = max(c3,max(c1,c2));
        choice[i][j][k] = (c3==mx ? 0 : (c2==mx ? 2 : 1));

        return dp[i][j][k] = max(c3,max(c1,c2));
    }

    static void findSol(int i,int j,int k) {
        if(k==virus.length || i==s.length || j==t.length)
            return;

        if(choice[i][j][k]==0) {
            sol.append(s[i]);

            boolean f = (virus[k]!=s[i] && k>0 ? true : false);
            int nk = (virus[k]==s[i] ? k+1 : (k>0 ? p[k-1] : 0));
            if(f && virus[nk]==s[i]) nk++;
            else if(f) nk = 0;

            findSol(i+1,j+1,nk);
            return;
        }

        if(choice[i][j][k]==1) {
            findSol(i+1,j,k);
            return;
        }

        if(choice[i][j][k]==2) {
            findSol(i,j+1,k);
            return;
        }
    }
}


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

public class Main {

	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;

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

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

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

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

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

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

	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));

	public static FastReader sc = new FastReader();

	static int mod = (int) (1e9+7),MAX=(int) (2e5);
    static List<Integer>[] edges;
	static char[] vir,s1,s2;
	static int[][][] dp;
	static int[] lps;
	public static void main(String[] args){

	  s1 = sc.next().toCharArray();
	  s2 = sc.next().toCharArray();
	  vir = sc.next().toCharArray();
	  lps = lps(new String(vir));
	  dp = new int[110][110][110];

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

	  int ans = f(0,0,0);
	  if(ans == 0) out.print(0);
	  else print(0,0,0,"");

      out.close();
	}

	private static void print(int i, int j, int k, String str) {
		  if (i == s1.length || j == s2.length) {
		        out.print(str);
		        return;
		    }
		    int cur = dp[i][j][k];
		    int r = f(i+1,j,k);
		    if (r == cur){ print(i+1,j,k,str); return; }
		    r = f(i,j+1,k);
		    if (r == cur) { print(i,j+1,k,str); return; }

		    while (k > 0 && vir[k] != s1[i]) k = lps[k - 1];
		    if (vir[k] == s1[i]) ++k;
		    print(i+1,j+1,k,str+s1[i]);

	}

	static int[] lps(String vir) {
	    int n = vir.length();
	    int[] pi = new int[n];
	    for (int i = 1; i < n; i++) {
	        int j = pi[i-1];
	        while (j > 0 && vir.charAt(i) != vir.charAt(j))
	            j = pi[j-1];
	        if (vir.charAt(i) == vir.charAt(j))
	            j++;
	        pi[i] = j;
	    }
	    return pi;
	}

	private static int f(int i, int j, int k) {
		if (k == vir.length) return -Integer.MIN_VALUE/10;
		if (i == s1.length) return 0;
		if (j == s2.length) return 0;

		if(dp[i][j][k]!=-1) return dp[i][j][k];

		int o1=0,o2=0,o3=0;
		int k1 = k;
		if(s1[i] == s2[j]) {
			if(s1[i] == vir[k1]) {
				o1 = 1 + f(i+1,j+1,k1+1);
			}else {
				/*
				 * if next char don't match we can't reset k to 0
				 * becz now suffix of lcs = ....prefix of virus + s1[i]
				 * the new k will be length of LPS of string = prefix of virus + s1[i]
				 */
			    while (k1 > 0 && vir[k1] != s1[i]) k1 = lps[k1-1];
			    if (s1[i] == vir[k1]) k1++;
				o1 = 1 + f(i+1,j+1,k1);
			}
		}else {
				o2 = f(i+1,j,k);
				o3 = f(i,j+1,k);
	        }

		return dp[i][j][k] = Math.max(o1, Math.max(o2, o3));
	}

}


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

public class R201_D1_D {
    static String s1;
    static String s2;
    static String virus;
    static int fail[];
    static int dp[][][];
    static int next[][][];

    public static void kmpPreprocess(String t) {
        int i = 0, j = -1;
        int m = t.length();
        fail = new int[m + 1];
        fail[i] = j;
        while (i < m) {
            while (j >= 0 && t.charAt(i) != t.charAt(j)) {
                j = fail[j];
            }
            ++i;
            ++j;
            fail[i] = j;
        }
    }

    public static int get_matched(char curr, int j) {
        while (j >= 0 && curr != virus.charAt(j)) {
            j = fail[j];
        }
        return j + 1;
    }

    public static int call(int index_a, int index_b, int matched) {
        if (matched == virus.length())
            return -1000000;
        if (index_a == s1.length() || index_b == s2.length())
            return 0;
        if (dp[index_a][index_b][matched] != -1)
            return dp[index_a][index_b][matched];
        int res = call(index_a + 1, index_b, matched);
        next[index_a][index_b][matched] = 0;
        int b = call(index_a, index_b + 1, matched);
        if (b > res) {
            res = b;
            next[index_a][index_b][matched] = 1;
        }

        if (s1.charAt(index_a) == s2.charAt(index_b)) {
            int c = 1 + call(index_a + 1, index_b + 1,
                    get_matched(s1.charAt(index_a), matched));
            if (c > res) {
                res = c;
                next[index_a][index_b][matched] = 2;
            }
        }
        return dp[index_a][index_b][matched] = res;
    }

    public static void main(String[] args) throws Exception {
        InputReader in = new InputReader(System.in);
        s1 = in.readString();
        s2 = in.readString();
        virus = in.readString();
        dp = new int[100][100][100];
        next = new int[100][100][100];

        for (int i = 0; i < dp.length; i++) {
            for (int j = 0; j < dp[i].length; j++) {
                for (int j2 = 0; j2 < dp[i][j].length; j2++) {
                    dp[i][j][j2] = -1;
                }
            }
        }
        kmpPreprocess(virus);
        int len = call(0, 0, 0);
        // System.out.println(len);

        if (len == 0)
            System.out.println(0);
        else {
            String res = "";
            int a = 0, b = 0, c = 0;
            while (res.length() < len) {
                if (next[a][b][c] == 0)
                    a++;
                else if (next[a][b][c] == 1)
                    b++;
                else {
                    res += s1.charAt(a);
                    a++;
                    b++;
                }
            }
            System.out.println(res);
        }
    }

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

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

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

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

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

        private String readLine0() {
            StringBuffer buf = new StringBuffer();
            int c = read();
            while (c != '\n' && c != -1) {
                buf.appendCodePoint(c);
                c = read();
            }
            return buf.toString();
        }

        public String readLine() {
            String s = readLine0();
            while (s.trim().length() == 0)
                s = readLine0();
            return s;
        }

        public String readLine(boolean ignoreEmptyLines) {
            if (ignoreEmptyLines)
                return readLine();
            else
                return readLine0();
        }

        public char readCharacter() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            return (char) c;
        }

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


import java.util.*;
import java.lang.*;
import java.io.*;
public class RBK
{
	public static void main(String[] args)
	{

   Scanner scan = new Scanner(System.in);
   int x1 = scan.nextInt();
   int y1 = scan.nextInt();
   int x2 = scan.nextInt();
   int y2 = scan.nextInt();
   Chess Moves = new Chess();
   Moves.rook(x1,y1,x2,y2);
   Moves.bishop(x1,y1,x2,y2);
   Moves.king(x1,y1,x2,y2);

	}
}

public class Chess
{
	void rook (int x1,int y1,int x2,int y2)
	{
		if(x1==x2 || y1==y2)
		{
			System.out.println("1");
		}
		else
			System.out.println("2");
	}

	void bishop (int x1,int y1,int x2,int y2)
	{
       int a,b;
       a=x1-x2;
       b=y1-y2;
       if(a<0)	a=-a;
       if(b<0)	b=-b;
       if((a%2)==(b%2))
       {
       	if(a==b)
       		System.out.println("1");
       	else
       		System.out.println("2");
       }
       else
       	System.out.println("0");
	}

	void king (int x1,int y1,int x2,int y2)
	{
		int a,b;
       a=x1-x2;
       b=y1-y2;
       if(a<0)	a=-a;
       if(b<0)	b=-b;
       if(a==b)
       {
         System.out.println(a);
       }
       else
       {
       	 if (a>b)
         	System.out.println(a);
         else
         	System.out.println(b);
       }

	}

}


import java.util.Scanner;

public class UndoubtedlyLuckyNumber {
	private int number, result = 0;

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		UndoubtedlyLuckyNumber obj = new UndoubtedlyLuckyNumber();
		obj.number = input.nextInt();
		int value;
		StringBuilder temp = new StringBuilder();
		for (int i = 1; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				if (i != j) {
					obj.solve(i, j, i, temp);
					temp.append((char) (i + '0'));
					value = Integer.valueOf(temp.toString());
					while (j > 0 && value <= obj.number) {
						obj.result--;
						temp.append((char) (i + '0'));
						value = Integer.valueOf(temp.toString());
					}
					temp.setLength(0);
				}
			}
		}
		System.out.println(obj.result);
	}

	private void solve(int x, int y, int num, StringBuilder temp) {
		temp.append((char) (num + '0'));
		int value = Integer.valueOf(temp.toString());
		if (value <= number) {
			result++;
			solve(x, y, x, temp);
			solve(x, y, y, temp);
		}
		temp.setLength(temp.length() - 1);
	}

}


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

public class D {

	static class Scanner{
		BufferedReader br=null;
		StringTokenizer tk=null;
		public Scanner(){
			br=new BufferedReader(new InputStreamReader(System.in));
		}
		public String next() throws IOException{
			while(tk==null || !tk.hasMoreTokens())
				tk=new StringTokenizer(br.readLine());
			return tk.nextToken();
		}
		public int nextInt() throws NumberFormatException, IOException{
			return Integer.valueOf(next());
		}
	}

	static int[][][][] dp=new int[11][11][11][2];
	static char[] Number;
	static long mod=1000000007;

	static void init(){
		for(int i=0;i<11;i++)
			for(int j=0;j<11;j++)
				for(int k=0;k<11;k++){
					dp[i][j][k][0]=-1;
					dp[i][j][k][1]=-1;
				}
	}

	static int klucky(int index,int acum,int k,boolean tope){
		if (dp[index][acum][k][tope?1:0]>=0)
			return dp[index][acum][k][tope?1:0];
		if (index==Number.length){
			dp[index][acum][k][tope?1:0]=(acum==k)?1:0;
			return (acum==k)?1:0;
		}
		int limit= (tope)? Number[index] - '0': 9;
		int sol=0;
		for(int i=0;i<=limit;i++){
			if (i==4 || i==7)
				sol+=klucky(index+1,acum+1,k,tope && i==limit);
			else
				sol+=klucky(index+1,acum,k,tope && i==limit);
		}
		dp[index][acum][k][tope?1:0]=sol;
		return sol;
	}

	static int ways(int k){
		if (k==0)
			return klucky(0,0,k,true)-1;
		return klucky(0,0,k,true);
	}

	static long bforce(int partido,int total,int acum, int[] used){
		if (partido==6)
			return (acum==total)?1:0;
		long ret=0;
	    for(int i=0;i<10;i++){
	    	if (ways(i)==used[i])
	    		continue;
	    	used[i]++;
	    	long tmp = bforce(partido+1,total, acum + i,used);
	    	used[i]--;
	    	tmp = ((ways(i) - used[i]) * tmp) % mod;
	    	ret = (ret + tmp) % mod;
	    }
	    return ret;
	}

	public static void main(String args[]) throws IOException{
		Scanner sc=new Scanner();
		init();
		Number=sc.next().toCharArray();
		long res=0;
		int[] used=new int[10];
		for(int i=1;i<10;i++){
			for(int j=0;j<10;j++)
				used[j]=0;
			used[i]=1;
			for(int j=0;j<i;j++){
				long tmp=(ways(i)*bforce(0,j,0,used))%mod;
				res = (res + tmp) % mod;
			}
		}
		System.out.println(res);
	}
}


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

public class D {

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
		// StringTokenizer to = new StringTokenizer(sc.readLine(), " ");
		ArrayList<Integer> xs = new ArrayList<Integer>();
		ArrayList<Integer> ys = new ArrayList<Integer>();
		int[] x = new int[8], y = new int[8];
		for (int i = 0; i < 8; i++) {
			StringTokenizer to = new StringTokenizer(sc.readLine(), " ");
			// StringTokenizer to = new StringTokenizer(sc.readLine(), " ");
			x[i] = Integer.parseInt(to.nextToken());
			y[i] = Integer.parseInt(to.nextToken());
			if (!xs.contains(x[i]))
				xs.add(x[i]);
			if (!ys.contains(y[i]))
				ys.add(y[i]);
		}
		if (xs.size() > 3 || ys.size() > 3) {
			System.out.println("ugly");
			System.exit(0);
		}
		Collections.sort(xs);
		Collections.sort(ys);
		for (int i = 0; i < 8; i++) {
			if (x[i] == xs.get(1) && y[i] == ys.get(1)) {
				System.out.println("ugly");
				System.exit(0);
			}
		}
		System.out.println("respectable");
	}
}


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

public class Main {
    public static void main(String[] args) throws Exception {
        in = new BufferedReader(new InputStreamReader(System.in, "ISO-8859-1"));
        out = new PrintWriter(System.out);

        solve();

        in.close();
        out.close();
    }

    private static void solve() throws Exception {
        double l = nextInt(), d = nextInt(), v = nextInt(), g = nextInt(), r = nextInt();
        double t1 = d / v;
        int del = (int) ((g + r) / t1);
        double ost = g + r - del * t1;
        if (ost > g) {
            out.format(Locale.US, "%.10f\n", t1 + (l - d) / v);
        } else {
            out.format(Locale.US, "%.10f\n", t1 + (l - d) / v + ost);
        }
    }

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

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

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

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


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

public class trafficlight{
    public static void main(String[] args) {
        Scanner br = new Scanner(System.in);
        int l = br.nextInt();
        int d = br.nextInt();
        int v = br.nextInt();
        int g = br.nextInt();
        int r = br.nextInt();
        double ttl = d/(v*1.0);
        boolean green = true;
        int time = 0;
        while(time < ttl){
        	if(green){
        		time+=g;
        	}
        	else{
        		time+=r;
        	}
        	if(ttl < time){
        		break;
        	}
        	green = !green;
        }
        double ans = 0;
        if(green){
        	ans = l/(v*1.0);
        }
        else{
        	ans = time+((l-d)/(v*1.0));
        }
        System.out.printf("%.8f\n", ans);
    }
}


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

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

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

		out.close();
	}
}

class InputReader {
	BufferedReader buff;
	StringTokenizer tokenizer;

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

	String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens())
			try {
				tokenizer = new StringTokenizer(buff.readLine());
			}
			catch (IOException e) {
				throw new RuntimeException(e);
			}
		return tokenizer.nextToken();
	}
	int nextInt() { return Integer.parseInt(next()); }
	long nextLong() { return Long.parseLong(next()); }
}

class Task {
	final static int MAXL = 19;
	final static int MAXN = 1 << 9;
	final static int LCM = 2520;
	long[][][] dp;

	long divTest(int x, int mask) {
		for (int i = 1; i < 10; ++i)
			if ((mask << 1 >> i & 1) == 1)
				if (x % i != 0)
					return 0L;
		return 1L;
	}

	long go(long l, long r) {
		int[] a = new int[MAXL], b = new int[MAXL];
		int pos = -1;
		for (int i = 0; i < MAXL; ++i) {
			a[i] = (int)(l % 10);
			b[i] = (int)(r % 10);
			if (a[i] != b[i])
				pos = i;
			l /= 10; r /= 10;
		}

		long ret = 0;
		int[] rem = new int[MAXL], mask = new int[MAXL];
		for (int i = MAXL - 2; i >= 0; --i) {
			rem[i] = (rem[i + 1] * 10 + a[i + 1]) % LCM;
			mask[i] = mask[i + 1] | 1 << a[i + 1] >> 1;
		}
		for (int i = 0; i <= pos; ++i)
			for (int j = a[i] + 1; j < (i == pos ? b[i] : 10); ++j)
				ret += dp[i][mask[i] | 1 << j >> 1][(rem[i] * 10 + j) % LCM];

		rem = new int[MAXL]; mask = new int[MAXL];
		for (int i = MAXL - 2; i >= 0; --i) {
			rem[i] = (rem[i + 1] * 10 + b[i + 1]) % LCM;
			mask[i] = mask[i + 1] | 1 << b[i + 1] >> 1;
		}
		for (int i = pos - 1; i >= 0; --i)
			for (int j = 0; j < b[i]; ++j)
				ret += dp[i][mask[i] | 1 << j >> 1][(rem[i] * 10 + j) % LCM];

		return ret;
	}

	void solve(InputReader in, PrintWriter out) {
		dp = new long[MAXL][MAXN][LCM];
		for (int i = 0; i < MAXN; ++i)
			for (int j = 0; j < LCM; ++j)
				dp[0][i][j] = divTest(j, i);

		for (int i = 1; i < MAXL; ++i)
			for (int j = 0; j < MAXN; ++j)
				for (int k = 0; k < LCM; ++k) {
					dp[i][j][k] = dp[i - 1][j][k * 10 % LCM];
					for (int c = 0; c < 9; ++c)
						dp[i][j][k] += dp[i - 1][j | 1 << c][(k * 10 + c + 1) % LCM];
				}

		for (int q = in.nextInt(); q-- > 0; ) {
			long l = in.nextLong(), r = in.nextLong();
			out.println(go(l - 1, r + 1));
		}
	}
}


import java.util.*;
import java.io.*;
import java.math.*;
public class round51D {
	public static void main(String args[]) throws Exception{
		cf55D tmp=new cf55D();
		tmp.solve();
	}
}
class cf55D {
	final static int N=20;
	final static int mod=2520;
	final static int M=(1<<8);
	long dp[][][]=new long[N][M][mod];
	ArrayList<Integer> dig=new ArrayList<Integer>();
	int t;
	long l,r;
	void init(long num) {
		long xx=num;
		while(xx>0) {
			int y=(int)xx%10;
			dig.add(y);
			xx/=10;
		}
		for(int i=0;i<N;i++) {
			for(int j=0;j<M;j++) {
				Arrays.fill(dp[i][j],-1);
			}
		}
	}
	long calc(int cont,int st,int re,int limit) {
		if(cont==-1) {
			for(int i=0;i<8;i++) {
				if((st&(1<<i))!=0&&re%(i+2)!=0) {
					return 0;
				}
			}
			return 1;
		}
		if(limit==0&&dp[cont][st][re]!=-1) return dp[cont][st][re];
		int bound=(limit==1? dig.get(cont):9);
		long res=0;
		for(int i=0;i<=bound;i++) {
			int stt=st;
			if(i>=2) stt|=(1<<(i-2));
			res+=calc(cont-1,stt,(re*10+i)%mod,(limit==1&&i==bound? 1:0));
		}
		if(limit==0) dp[cont][st][re]=res;
		return res;
	}
	void solve() throws Exception{
		//System.setIn(new BufferedInputStream(new FileInputStream("in.txt")));
		Scanner in=new Scanner(System.in);
		t=in.nextInt();
		for(int i=0;i<t;i++) {
			l=in.nextInt();
			r=in.nextInt();
			dig.clear();
			init(l-1);
			int sz=dig.size();
			long ll=calc(sz-1,0,0,1);

			dig.clear();
			init(r);
			sz=dig.size();
			long rr=calc(sz-1,0,0,1);
			System.out.println(rr-ll);
		}
	}
}


package set;
import java.util.Scanner;

public class Code {
	static int reflectNum(int number){
		if(number<100000)
		{
			if(number<100)
			{
				if(number<10)
					return (9-number);
				else
					return (99-number);
			}
			else
			{
				if(number<10000)
				{
					if(number<1000)
						return (999-number);
					else
						return (9999-number);
				}
				else
					return (99999-number);
			}
		}
		else
		{
			if(number<10000000)
			{
				if(number<1000000)
					return (999999-number);
				else
					return (9999999-number);
			}
			else
			{
				if(number<100000000)
					return (99999999-number);
				else
					return (999999999-number);
			}
		}
	}

	public static void main(String[] args)
	{
		Scanner read = new Scanner(System.in);
		int l,r;
		long max=-1;
		l = read.nextInt();
		r = read.nextInt();
		if(r==0)
			max=0;
		else if(l==1000000000)
			max = 8999999999000000000L;
		else
		{
			for ( ; l <= r ; l++)
				if(max<l*reflectNum(l))
					max = l*reflectNum(l);
		}
		System.out.println(max);
	}
}


import java.util.Scanner;

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

        long l=in.nextInt();
        long r=in.nextInt();
        long best=Math.max(func (l),func(r));
        for(long i=5; i<r; i*=10)
        {
            if(i>=l)
            {
                best=Math.max(best,func(i));
            }
        }
        System.out.print(best);

    }
    public static long func(long x)
    {
        char rr[]=String.valueOf(x).toCharArray();
        for(int i=0; i<rr.length; i++)
        {
            rr[i]=(char) ('9'-rr[i]);

        }
        long best=Long.parseLong(new String (rr));
        return x*best;

    }

}


package Ulohy;

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

public class Reflexe {

    public static int reflexe(int cislo) {
        String cisloString = Integer.toString(cislo);
        int vysledek = 0;
        for (int i = 0; i < cisloString.length(); i++) {
            vysledek = vysledek + 9 - (cisloString.charAt(i) - 48);
            if (i != cisloString.length() - 1) {
                vysledek = vysledek * 10;
            }
        }
        return (vysledek);
    }

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

        int minCislo = mujScanner.nextInt();
        int maxCislo = mujScanner.nextInt();
        int desetiny = 1;

        String prevedeni1 = Integer.toString(minCislo);
        String prevedeni2 = Integer.toString(maxCislo);
        for (int i = prevedeni1.length(); i < prevedeni2.length(); i++) {
             desetiny = desetiny * 10;
        }
        if(desetiny != 1) minCislo = desetiny;

        long vysledek = 0L;
        long mezipocet = 0L;

        vysledek = reflexe(minCislo) * minCislo;
        for (int i = minCislo; i <= maxCislo; i++) {
            mezipocet = reflexe(i) * i;
            if(mezipocet > vysledek){
                vysledek = reflexe(i) * i;
            }
        }
        System.out.println(vysledek);
    }
}


import java.util.Scanner;

/**
 * Created by mostafa on 10/7/17.
 */
public class FightMonster {
    static int inf = (int) 1e9;

    static boolean canwin(int hpy, int atky, int defy, int hpm, int atkm, int defm) {
        if(atky <= defm)
            return false;
        if(atkm <= defy)
            return true;

        int dmg1 = atky - defm;
        int moves1 = (hpm + dmg1 - 1) / dmg1;

        int dmg2 = atkm - defy;
        int moves2 = (hpy + dmg2 - 1) / dmg2;

        return moves1 < moves2;
    }

    static int hp(int hpy, int atky, int defy, int hpm, int atkm, int defm) {
        if(atky <= defm)
            return inf;
        if(atkm <= defy)
            return 0;

        int ans = inf;
        int low = 0, high = inf;
        while(low <= high) {
            int mid = (low + high) / 2;
            if (canwin(hpy + mid, atky, defy, hpm, atkm, defm)) {
                ans = mid;
                high = mid - 1;
            }
            else
                low = mid + 1;
        }

        return ans;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int hpy = sc.nextInt(), atky = sc.nextInt(), defy = sc.nextInt();
        int hpm = sc.nextInt(), atkm = sc.nextInt(), defm = sc.nextInt();
        int h = sc.nextInt(), a = sc.nextInt(), d = sc.nextInt();
        int ans = (int) 1e9;

        for(int atk = 0; atk <= 10000; atk++)
            for(int def = 0; def <= 10000; def++) {
                int hp = hp(hpy, atky + atk, defy + def, hpm, atkm, defm);
                if(hp == inf)
                    continue;
                ans = Math.min(ans, atk * a + def * d + hp * h);
            }
        System.out.println(ans);
    }
}


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

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

class TaskB {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
		int hpY = in.nextInt();
		int atkY = in.nextInt();
		int defY = in.nextInt();

		int hpM = in.nextInt();
		int atkM = in.nextInt();
		int defM = in.nextInt();

		int H = in.nextInt();
		int A = in.nextInt();
		int D = in.nextInt();

		int minCost = Integer.MAX_VALUE;

		for (int h=0; h<=500; h++){
			for (int a=0; a<=500; a++){
				for (int d=0; d<=500; d++){
					if (wins(hpY + h, atkY + a, defY+d, hpM, atkM, defM)){
						minCost = Math.min(minCost, h * H + a*A + d*D);
					}
				}
			}
		}

		out.println(minCost);
    }

	private boolean wins(int hpY, int atkY, int defY, int hpM, int atkM, int defM){
		int rounds1 = rounds(hpY, defY, atkM);
		int rounds2 = rounds(hpM, defM, atkY);

		return (rounds2 != Integer.MAX_VALUE && rounds1 > rounds2);
	}

	private int rounds(int hpY, int defY, int atkM){
		int val = Math.max(0, atkM - defY);

		if (val == 0){
			return Integer.MAX_VALUE;
		}

		if (hpY % val == 0){
			return hpY/val;
		}

		return hpY/val + 1;
	}

}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

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

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

        return tokenizer.nextToken();
    }

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

}


import java.util.Scanner;

public class C {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int h1 = s.nextInt();
        int a1 = s.nextInt();
        int d1 = s.nextInt();
        int h2 = s.nextInt();
        int a2 = s.nextInt();
        int d2 = s.nextInt();
        int n1 = s.nextInt();
        int n2 = s.nextInt();
        int n3 = s.nextInt();

        int m1 = a1 - d2;
        int m2 = a2 - d1;
        int an = (m1 <= 0) ? (-m1 + 1) : 0;
        m1 += an;
        int k = h2/m1 + (h2%m1 == 0 ? 0 : 1);
        int hn = k*m2  + 1 - h1;
        if (hn <= 0) {
            System.out.println(an*n2);
            return;
        }

        k = h1/m2 + (h1%m2 == 0 ? 0 : 1);
        if (k == 1) {
            an = Math.abs(m2 - m1) + an;
        } else {
            k--;
            an = h2/k + (h2%k == 0 ? 0 : 1) - m1 + an;
        }

        k = h2/m1 + (h2%m1 == 0 ? 0 : 1);
        int dn = h1/k;
        if (h1 <= k*dn) {
            dn--;
        }
        dn = m2 - dn;

        int min = Integer.MAX_VALUE;
        for (int h = 0; h <= hn; h++) {
            int p1 = h*n1;
            for (int d = 0; d <= dn; d++) {
                int p2 = p1 + d*n3;
                for (int a = 0; a <= an; a++) {
                    int c = p2 + a*n2;
                    if (isWin(h1 + h, a1 + a, d1 + d, h2, a2, d2) && c < min) {
                        min = c;
                    }
                }
            }
        }

        System.out.println(min);
    }

    private static boolean isWin(int h1, int a1, int d1, int h2, int a2, int d2) {
        int m1 = a1 - d2;
        int m2 = a2 - d1;
        if (m1 <= 0) {
            return false;
        }
        if (m2 <= 0) {
            return true;
        }
        int k1 = h1/m2 + (h1%m2 == 0? 0 : 1);
        int k2 = h2/m1 + (h2%m1 == 0? 0 : 1);
        return k1 > k2;
    }

}


import java.util.Scanner;

public class EsA {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int r1,r2,c1,c2;
		r1=scan.nextInt();
		c1=scan.nextInt();
		r2=scan.nextInt();
		c2=scan.nextInt();

		//torre
		if(r1==c1 || r2 == c2){
			System.out.print(1);
		}else{
			System.out.print(2);
		}
		System.out.print(" ");

		//alfiere
		if((r1+c1)%2 != (r2+c2)%2){
			System.out.print(0);
		}else {
			int dif1 = Math.abs(r1-c1);
			int dif2 = Math.abs(r1-c1);
			if(dif1 == dif2){
				System.out.print(1);
			}else{
				System.out.print(2);
			}

		}
		System.out.print(" ");

		//re
		if(r1==r2){
			System.out.print(Math.abs(c2-c1));
		}else if(c1==c2){
			System.out.print(Math.abs(r2-r1));
		}else{
			int moves = 0;
			int pr=r1;
			int pc=c1;
			if(r1>r2){
				while(true){
					pr+=1;
					pc+=1;
					moves+=1;
					if(pr==r2){
						System.out.println(Math.abs(c2-c1));
						break;
					}else if(pc==c2){
						System.out.print(Math.abs(r2-r1));
						break;
					}
				}
			}else{
				while(true){
					pr-=1;
					pc-=1;
					moves+=1;
					if(pr==r2){
						System.out.println(Math.abs(c2-c1));
						break;
					}else if(pc==c2){
						System.out.print(Math.abs(r2-r1));
						break;
					}
				}
			}

		}
		System.out.println();
	}

}


 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
import java.lang.Math;
/**
 *
 * @author SONY
 */
public class chess {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
    Scanner s = new Scanner(System.in);
    int r1,r2,c1,c2;
    int n1,n2,n3;
    r1=s.nextInt();
    c1=s.nextInt();
    r2=s.nextInt();
    c2=s.nextInt();
     if(c2<c1)
            n1=n2=n3=0;
     else
     {
    //for rook (goes horixontally and vertically any no. of steps )
    if(r1==r2||c1==c2)
    {

    if(r1==r2&&c1==c2)
        n1=0;

    else
        n1=1;
    }
    else
            n1=2;
      //for bishop (goes vertically any no. of steps
    int y =c2-c1;
    int x=r2-r1;
     int x1 ,x2,y1,y2;
    x1=r2-1;
    y1=c2-1;
    x2=r2+1;
    y2=c2-1;
    //diagonal qs
    if(x==y||x==((-1)*y))
    {
        n2=1;
    }

    else if((x2-r1)==(y2-c1)||(x2-r1)==(c1-y2))
        n2=2;
    else if((x1-r1)==(y1-c1)||(x1-r1)==(c1-y1))
        n2=2;
    else
        n2=0;

    // for king (1 move only any direction)
      if(x==y||x==((-1)*y)) //diagonal
      {
            n3=y;
      }
      else if ((r1==r2))
          n3=c2-c1;
        else if ((c1==c2))
          n3=r2-r1;
        else
        {
            if(r2<c2)
            {
                //a=r2;
                int b=c1+r2-r1;
                n3=r2-r1-1+c2-b;

            }
            else //a=c2;
            {
                int c=r1+r2-r1;
                n3=c2-c1+r2-c;
            }
        }
     }
     n1=Math.abs(n1);
     n2=Math.abs(n2);
     n3=Math.abs(n3);
    System.out.println(n1+" "+n2+" "+n3);
    }
}


import java.util.*;
public class Bear{
	public static void main(String[] args){
int a[1000],num[1005];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        num[a[i]]++;
    }
    for(int i=1;i<=1000;i++)
    {
        if(num[i]&&num[i+1]&&num[i+2])
        {
            System.out.println("YES");
            return 0;
        }
    }
    System.out.println("NO");
    return 0;
}

}


import java.util.Scanner;
import java.util.Arrays;
public class top{
  public static void main(String [] args){
    Scanner scan = new Scanner(System.in);
    int n=scan.nextInt();
    int [] a= new int[n];
    boolean t = true;
    for(int i=0;i<n;++)
      a[i]=scan.nextInt();
       Arrays.sort(a);
      for(int i=0;i<n;++){
        if(a[i]==a[i+1]-1&&a[i+1]==a[i+2]-1)
          System.out.println("yes");
        t = false;
        break;
      }
      if(t==true)
        System.out.println("no");
  }
}


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

public class P2_TheGoldenAge {

	static long x , y , r , l , max = 0;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		StringTokenizer st = new StringTokenizer(br.readLine());
		x = Integer.parseInt(st.nextToken());
		y = Integer.parseInt(st.nextToken());
		if(y < x){
			long temp = x;
			x = y;
			y = temp;
		}
		r = Integer.parseInt(st.nextToken());
		l = Integer.parseInt(st.nextToken());
		pw.println(backtrack(r,0));
		pw.flush();
	}

	private static long backtrack(long idx , long num) {
		if(idx > l)
			return Math.max(max , num);
		for(long i = 1 ; i < idx ; i *= x){
			if(isPow(idx-i)){
				max = Math.max(max , num);
				return backtrack(idx+1 , 0);
			}
		}
		return backtrack(idx+1 , num+1);
	}

	private static boolean isPow(long z) {
		while(z > 1)
			if(z%y != 0)
				return false;
			else
				z /= y;
		return true;
	}

}


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

public class TheGoldenAge {
	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner(System.in);
		long x=sc.nextInt();
		long y=sc.nextInt();
		long l=sc.nextInt();
		long r=sc.nextInt();
		int end1=log(x,r);
		int end2=log(y,r);
		PriorityQueue<Long>pq=new PriorityQueue<Long>();
		for(int i=0;i<=end1;++i) {
			for(int j=0;j<=end2;++j ) {
				long d=(long) (Math.pow(x, i)+Math.pow(y, j));
				if(d<=r && d>=l)
					pq.add(d);
			}
		}
		pq.add(r+1);
		long lst=l-1;
		long max=0;
		while(!pq.isEmpty()) {
			long nxt=pq.poll();
			long intrvl=nxt-(lst+1);
			max=Math.max(max, intrvl);
			lst=nxt;
		}
		System.out.println(max);

	}
	public static int log(long base,long a) {
		return (int)(Math.log(a)/Math.log(base));
	}
	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

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

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

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

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

		public double nextDouble() throws IOException
		{
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if(x.charAt(0) == '-')
			{
				neg = true;
				start++;
			}
			for(int i = start; i < x.length(); i++)
				if(x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				}
				else
				{
					sb.append(x.charAt(i));
					if(dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg?-1:1);
		}

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

	}
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.Iterator;

public class Main
{
    static class Pair{
    	int first,second;
    	public Pair(int first,int second){
    		this.first=first;
    		this.second=second;
    	}
    }
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	static class Solution
	{
		final long mod = 1000000007;
		final int  max = (int)1e6+2;

		////////////////////////////////

	    public void solve(InputReader sc,PrintWriter out)
	    {

	            int x1=i(),y1=i(),x2=i(),y2=i();
	            int x=i(),y=i();
	            if(((x2-x1)%x==0||y2-y1)%y==0)&&(((x2-x1)/x)%2==((y2-y1)/y)%2))
	            	out.println("YES");
	            else
	            	out.println("NO");

    	}

    	///////////////////////////////Methods///////////////////////////////////////////////////////
        int lower_bound(ArrayList<Integer> a, int key) {
    		int l = 0;
    		int h = a.size(); // Not n - 1

    		while (l < h) {
        		int mid = (l + h) / 2;
        		if (key <= a.get(mid)) {
            		h = mid;
        		} else {
            		l = mid + 1;
        		}
    		}
    		return l;
		}
    	int upper_bound(ArrayList<Integer> a, int key) {
    		int l = 0;
   		    int h = a.size(); // Not n - 1

   		    if(key>=a.get(h-1))
    			return (h);

   			while (l < h) {
        		int mid = (l + h) / 2;
        		if (key >= a.get(mid)) {
            		l = mid + 1;
        		} else {
            		h = mid;
        		}
    		}

    		return l;
		}

        ////////////////////////////////////////////////////////////
        public int i(){	return sc.nextInt();}
		public long l(){ return sc.nextLong();}
		public String s(){ return sc.next();}
		public int[] iarr(int n){int[] ar = new int[n];for(int i=0;i<n;++i) ar[i] = sc.nextInt(); return ar; }
		public long[] larr(int n){long[] ar = new long[n+1];for(int i=1;i<=n;++i) ar[i] = sc.nextLong(); return ar; }
		public void parr(int[] ar){	for(int i=0;i<ar.length;i++)	out.print(ar[i]+" ");
			out.println();
		}
		public void parl(long[] ar){	for(int i=0;i<ar.length;i++)	out.print(ar[i]+" ");
			out.println();
		}
        ///////////////////////////////////////Methods/////////////////////////////////////////////////////
 	}

 	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 	static	InputReader sc = new InputReader();
	static    PrintWriter out= new PrintWriter(System.out);
	Main() throws IOException {

	    final long start = System.currentTimeMillis();
		new Solution().solve(sc,out);
		@SuppressWarnings("unused")
		final long duration = System.currentTimeMillis()-start;
		out.close();
	}

	public static void main(String args[]) {
		new Thread(null, new Runnable() {
			public void run() {
				try {
					new Main();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}, "1", 1 << 26).start();
	}
	static class InputReader{
		final InputStream stream;
		final byte[] buf = new byte[8192];
		int curChar, numChars;
		SpaceCharFilter filter;

		public InputReader(){
			this.stream = System.in;
		}

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

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

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

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

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

}


import java.io.*;
import java.util.*;
import java.lang.*;
    public class templ {
    public static void main(String[] args) throws FileNotFoundException {
     try
     {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        templ ob=new templ();
        int x1=in.nextInt();
        int y1=in.nextInt();
        int x2=in.nextInt();
        int y2=in.nextInt();
        int x=in.nextInt();
        int y=in.nextInt();
        int a1=Math.abs(x1-x2);
        float a=(float)a1/x;
        int a2=Math.abs(y1-y2);
        float b=(float)a2/y;
        float k=Math.abs(a-b);
        if(k/2==(int)k/2)
        out.println("YES");
        else
        out.println("NO");
        out.close();
    }
        catch(Exception e){
        return;
    }
    }
    static class InputReader {

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

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

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

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

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

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

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

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

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

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

    }
}