Problem: Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.

There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.

Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w ≤ a), (h ≤ b) and (w/h = x/y).

In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.

Input

The first line contains four integers a, b, x, y (1 ≤ a, b, x, y ≤ 10^{18}) — the constraints on the screen width and height, and on the aspect ratio.

Output

Print one integer — the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.

Examples

Input

17 15 5 3


Output

3


Input

14 16 7 22


Output

0


Input

4 2 6 4


Output

1


Input

1000000000000000000 1000000000000000000 999999866000004473 999999822000007597


Output

1000000063

Note

In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).

In the second example, there is no TV set meeting the constraints.

In the third example, there is only one variant: (3, 2).

Solution (in JAVA):

Solution:
import java.io.Reader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;


public class Main {
	
	private static Scanner input = new Scanner(System.in);
		
	private static final int MOD = 1_000_000_000 + 7;
	
	public static void main(String[] args) {
					
		long a = input.nextLong();
		long b = input.nextLong();

		long x = input.nextLong();
		long y = input.nextLong();
		
		long gcd = gcd(x,y);
		
		x=x/gcd;
		y=y/gcd;
			
		long ax = a/x;
		long by = b/y;
		
		long ans = Math.min(ax, by);
		
		System.out.println(ans);

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

		  	HashMap<Integer, Long> map = new HashMap<>();
			
			for (int i = 0; i < a.length; i++) {
				Long value = map.get(a[i]);
				map.put(a[i], value == null ? 1 : ++value);
			}
			
			long count = 0;
			
			for (Map.Entry<Integer, Long> m : map.entrySet()) {
				if(m.getValue() > 1) {
					count+=countCorrectPair(m.getValue());
				}			
			}
			
			int ans;
			
	        if (count > 1_000_000_000)
	            ans = 1_000_000_000;
	        
	        else ans = (int)count;   
	        
	        return ans;

	}
	static long countCorrectPair(long n) {
		return n*(n-1)/2;
	}
	static int solution(int M, int[] A) {
		
	        int N = A.length;
	        
	        int[] count = new int[M+1];
	        
	        for (int i = 0; i <= M; i++)
	            count[i] = 0;
	        
	        int maxOccurence = 1;
	        int index = 0;
	        
	        for (int i = 0; i < N; i++) {
	        	
	            if (count[A[i]] > 0) {	            	
	                int tmp = count[A[i]];	                
	                count[A[i]] = tmp + 1;
	            }
	            else {
	                count[A[i]] = 1;
	            }
	            
                if (count[A[i]] > maxOccurence) {
                    maxOccurence = count[A[i]];
                    index = i;
                }
	        }
	        System.out.println(Arrays.toString(count));
	        return A[index];
	    }
	static boolean isSortedAscending (int [] a) {
		for (int i = 0; i < a.length - 1; i++) {
			if(a[i+1]<a[i]) return false;
		}
		return true;
	}
			
	static boolean isSortedDescending (int [] a) {
		for (int i = 0; i < a.length - 1; i++) {
			if(a[i+1]>a[i]) return false;
		}
		return true;
	}
	static int magic (int n, int a, int b) {
		
		if (n==1) return Math.min(a, b);
		
		int min = Math.min(a, b);
		int max = Math.max(a, b);
		
		int [] ar = new int[n];
		
		ar[0] = min;
		ar[1] = max;
		
		for (int i = 2; i < n; i++) {
			if(i%2==0)
				ar[i] = (ar[i-2] + min)%MOD;
			else
				ar[i] = (ar[i-2] + max)%MOD;
		}
		
		return ar[n-1];
	}
	
	static int gcd (int a,int b) {
		if(b == 0) return a;
		return gcd(b,a%b);
	}
	static int swapedArray (int [] a ) {
		
		int sum = 0;
		
		for (int i = 0; i < a.length; i++) {
			if(a[i]>i+1) {
				int temp = a[i]-(i+1);
				if(temp>2) {
					sum = Integer.MIN_VALUE;
					break;
				}
				else {
					sum+=temp;
				}
			}
		}
		
		return sum;
	}
	
	static int sumOfArray (int [] a) {
		
		int sum = 0;
		
		for (int i = 0; i < a.length; i++) {
			sum+=a[i];
		}
		
		return sum;
	}
		
	static long F (int n) {
		
		long res = 1;

		for (int i = 2; i <=n; i++) {
			res*=i;
		}
		
		return res;
	}
	static void replace (int [] a, int n, int m) {
		for (int i = 0; i < a.length; i++) {
			if(a[i]==n) a[i] = m;
		}
	}
	static int Max (int [] a ) {
		int max = Integer.MIN_VALUE;
		
		for (int i = 0; i < a.length; i++) {
			max = Math.max(max, a[i]);
		}
		
		return max;
	}
	static int countOfOne (String S) {
		
		int count = 0;
		int max = Integer.MIN_VALUE;
		
		char [] cc = S.toCharArray();

		for (char c : cc)
		{
			if(c == '1') {
				count++;
			}
			else {
				max = Math.max(max, count);
				count = 0;
			}
		}
		
		return max = Math.max(max, count);
	}

	static int bubbleSort (int [] a) {
		
		int count = 0;
		
		for (int i = 0; i < a.length - 1; i++) {
			for (int j = i+1; j < a.length; j++) {
				if(a[j]<a[i]) {
					int temp = a[j];
					a[j] = a[i];
					a[i] = temp;
					count++;
				}
			}
		}
		
		return count;
	}
	static int minInRange (int [] a, int l, int r) {
		int min = a[l];
		
		for (int i = l+1; i <=r; i++) {
			min = Math.min(a[i], min);
		}
		
		return min;
	}

	
	static void readAnArray (int [] a)
	{		
		for (int i = 0; i < a.length; i++) {
			a[i] = input.nextInt();
		}
	}
	
	static boolean isPrime (int n) {
		
		if(n<2) return false;
		
		for (int i = 2; i*i<=n; i++) {
			if(n%i==0) return false;
		}
		
		return true;
	}
	
}