import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
static int n;
static long[] a, b, c, d;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt(br.readLine().trim());
a = new long[n];
b = new long[n];
c = new long[n];
d = new long[n];
for (int i = 0; i < n; i++) {
String[] parts = br.readLine().trim().split("\\s+");
a[i] = Long.parseLong(parts[0]);
b[i] = Long.parseLong(parts[1]);
c[i] = Long.parseLong(parts[2]);
d[i] = Long.parseLong(parts[3]);
}
long low = 1;
long high = 1_000_000_000L;
long answer = high;
while (low <= high) {
long mid = low + (high - low) / 2;
if (canMatch(mid)) {
answer = mid;
high = mid - 1;
} else {
low = mid + 1;
}
}
System.out.println(answer);
}
static boolean canMatch(long k) {
// Build adjacency list
List<Integer>[] adj = new List[n];
for (int i = 0; i < n; i++) {
adj[i] = new ArrayList<>();
for (int j = 0; j < n; j++) {
if (c[i] * k >= a[j] && d[i] * k >= b[j]) {
adj[i].add(j);
}
}
}
// Implement Hopcroft-Karp
int[] pairU = new int[n];
int[] pairV = new int[n];
Arrays.fill(pairU, -1);
Arrays.fill(pairV, -1);
int result = 0;
while (bfs(adj, pairU, pairV)) {
for (int u = 0; u < n; u++) {
if (pairU[u] == -1) {
if (dfs(u, adj, pairU, pairV)) {
result++;
}
}
}
}
return result >= n;
}
static boolean bfs(List<Integer>[] adj, int[] pairU, int[] pairV) {
int nLeft = n;
Queue<Integer> queue = new LinkedList<>();
int[] dist = new int[nLeft];
Arrays.fill(dist, -1);
for (int u = 0; u < nLeft; u++) {
if (pairU[u] == -1) {
dist[u] = 0;
queue.add(u);
}
}
boolean foundAugmentingPath = false;
while (!queue.isEmpty()) {
int u = queue.poll();
for (int v : adj[u]) {
if (pairV[v] != -1 && dist[pairV[v]] == -1) {
dist[pairV[v]] = dist[u] + 1;
queue.add(pairV[v]);
} else if (pairV[v] == -1) {
foundAugmentingPath = true;
}
}
}
return foundAugmentingPath;
}
static boolean dfs(int u, List<Integer>[] adj, int[] pairU, int[] pairV) {
for (int v : adj[u]) {
if (pairV[v] == -1 || (dfs(pairV[v], adj, pairU, pairV))) {
pairU[u] = v;
pairV[v] = u;
return true;
}
}
return false;
}
}