AtCoder Beginner Contest 046 - AtCoDeer and Election Report

AtCoDeer the deer is seeing a quick report of election results on TV.
Two candidates are standing for the election: Takahashi and Aoki.
The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes.
AtCoDeer has checked the report N times, and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i.
It is known that each candidate had at least one vote when he checked the report for the first time.
Find the minimum possible total number of votes obtained by the two candidates when he checked the report for the N-th time.
It can be assumed that the number of votes obtained by each candidate never decreases.

-----Constraints-----
 - 1≦N≦1000
 - 1≦T_i,A_i≦1000 (1≦i≦N)
 - T_i and A_i (1≦i≦N) are coprime.
 - It is guaranteed that the correct answer is at most 10^{18}.

-----Input-----
The input is given from Standard Input in the following format:
N
T_1 A_1
T_2 A_2
:
T_N A_N

-----Output-----
Print the minimum possible total number of votes obtained by Takahashi and Aoki when AtCoDeer checked the report for the N-th time.

-----Sample Input-----
3
2 3
1 1
3 2

-----Sample Output-----
10

When the numbers of votes obtained by the two candidates change as 2,3 → 3,3 → 6,4, the total number of votes at the end is 10, which is the minimum possible number.

Source: atcoder | Difficulty: EASY


Solutions:
n = int(input())
ans_t = 1
ans_a = 1
for i in range(n):
	(t, a) = map(int, input().split())
	if t == 1:
		k1 = ans_t
	else:
		k1 = (ans_t - 1) // t + 1
	if a == 1:
		k2 = ans_a
	else:
		k2 = (ans_a - 1) // a + 1
	k = max(k1, k2)
	ans_t = k * t
	ans_a = k * a
print(ans_t + ans_a)


import io
import math
data = int(input())
(nim, mike) = (1, 1)
for _ in range(data):
	(n, m) = [int(_) for _ in input().split(' ')]
	l = max(-(-nim // n), -(-mike // m))
	(nim, mike) = (l * n, l * m)
print(nim + mike)


def f1(a, b):
	if a % b == 0:
		return a // b
	else:
		return a // b + 1
n = int(input())
t = 1
a = 1
for i in range(n):
	(ti, ai) = map(int, input().split())
	k = max(f1(t, ti), f1(a, ai))
	t = ti * k
	a = ai * k
print(t + a)


n = int(input())
(A, B) = (0, 0)
for i in range(n):
	(x, y) = map(int, input().split())
	(t, a) = (1, 1)
	if A > x:
		t = A // x
		if A % x != 0:
			t += 1
	if B > y:
		a = B // y
		if B % y != 0:
			a += 1
	m = max(t, a)
	A = x * m
	B = y * m
print(A + B)


from sys import stdin
import math
N = int(stdin.readline().rstrip())
(t, a) = (1, 1)
for _ in range(N):
	(T, A) = [int(x) for x in stdin.readline().rstrip().split()]
	n = max((t + T - 1) // T, (a + A - 1) // A)
	t = n * T
	a = n * A
print(t + a)


n = int(input())
l = [list(map(int, input().split())) for i in range(n)]
t = l[0][0]
a = l[0][1]
for j in range(1, n):
	z = max((t + l[j][0] - 1) // l[j][0], (a + l[j][1] - 1) // l[j][1])
	t = l[j][0] * z
	a = l[j][1] * z
print(t + a)


import math
N = int(input())
ta = [tuple(map(int, input().split())) for _ in range(N)]
left = ta[0][0]
right = ta[0][1]
res = left + right
for (t, a) in ta[1:]:
	tmp1 = (left + t - 1) // t
	tmp2 = (right + a - 1) // a
	buff = max(tmp1, tmp2)
	right = buff * a
	left = buff * t
print(int(right + left))


N = int(input())
(TNow, ANow) = (int(T) for T in input().split())
for TN in range(1, N):
	(TNext, ANext) = (int(T) for T in input().split())
	Magn = max(TNow // TNext + (TNow % TNext != 0), ANow // ANext + (ANow % ANext != 0))
	(TNow, ANow) = (TNext * Magn, ANext * Magn)
print(TNow + ANow)


n = int(input())
(vt, va) = (1, 1)
for i in range(n):
	(t, a) = list(map(int, input().split()))
	d = max((t + vt - 1) // t, (a + va - 1) // a)
	vt = d * t
	va = d * a
print(vt + va)


N = int(input())
(A, B) = (1, 1)
for _ in range(N):
	(x, y) = map(int, input().split())
	n = max((A - 1) // x + 1, (B - 1) // y + 1)
	A = n * x
	B = n * y
print(A + B)


N = int(input())
(x, y) = (1, 1)
for i in range(N):
	(a, b) = map(int, input().split())
	mul = max((x + a - 1) // a, (y + b - 1) // b)
	x = mul * a
	y = mul * b
print(x + y)


N = int(input())
T = []
A = []
for i in range(N):
	(t, a) = map(int, input().split())
	T.append(t)
	A.append(a)
a = 1
b = 1
for i in range(N):
	n = max((a + T[i] - 1) // T[i], (b + A[i] - 1) // A[i])
	a = n * T[i]
	b = n * A[i]
print(a + b)


from math import ceil
from fractions import Fraction
N = int(input())
a = 1
b = 1
for i in range(N):
	(x, y) = map(int, input().split())
	n = max(ceil(Fraction(a, x)), ceil(Fraction(b, y)))
	(a, b) = (n * x, n * y)
print(a + b)


ma = lambda : map(int, input().split())
ni = lambda : int(input())
n = ni()
(pt, pa) = ma()
for i in range(n - 1):
	(t, a) = ma()
	l = max((pt + t - 1) // t, (pa + a - 1) // a)
	pt = t * l
	pa = a * l
print(pt + pa)


n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
(x, y) = (a[0][0], a[0][1])
for i in range(1, n):
	xr = (x + a[i][0] - 1) // a[i][0]
	yr = (y + a[i][1] - 1) // a[i][1]
	r = max(xr, yr)
	x = r * a[i][0]
	y = r * a[i][1]
print(x + y)


n = int(input())
(ca, cb) = (0, 0)
for i in range(n):
	(a, b) = list(map(int, input().split()))
	(x, y) = (1, 1)
	if ca > a:
		x = ca // a
		if ca % a:
			x += 1
	if cb > b:
		y = cb // b
		if cb % b:
			y += 1
	x = max(x, y)
	ca = a * x
	cb = b * x
print(ca + cb)


N = int(input())
x = 1
y = 1
for i in range(N):
	(T, A) = map(int, input().split())
	p = (T + x - 1) // T
	q = (A + y - 1) // A
	x = T * max(p, q)
	y = A * max(p, q)
print(x + y)


n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
x = 1
y = 1
for i in range(n):
	a = ab[i][0]
	b = ab[i][1]
	m = max(-(-x // a), -(-y // b))
	x = m * a
	y = m * b
print(x + y)


n = int(input())
t = 1
a = 1
for _ in range(n):
	(ti, ai) = map(int, input().split())
	if t % ti != 0:
		t = (t // ti + 1) * ti
	if a % ai != 0:
		a = (a // ai + 1) * ai
	r = max(t // ti, a // ai)
	t = ti * r
	a = ai * r
print(a + t)


N = int(input())
(t, a) = (1, 1)
for _ in range(N):
	(_t, _a) = map(int, input().split())
	n = max(-(-t // _t), -(-a // _a))
	(t, a) = (n * _t, n * _a)
print(t + a)


import sys
readline = sys.stdin.readline

def ceil(a, b):
	return -(-a // b)

def main():
	N = int(readline())
	inp = [tuple(map(int, readline().rstrip().split())) for _ in range(N)]
	(scr_t, scr_a) = (0, 0)
	for (t, a) in inp:
		if t >= scr_t and a >= scr_a:
			scr_t = t
			scr_a = a
		elif t < scr_t and a >= scr_a:
			scr_t = t * ceil(scr_t, t)
			scr_a = scr_t * a // t
		elif a < scr_a and t >= scr_t:
			scr_a = a * ceil(scr_a, a)
			scr_t = scr_a * t // a
		elif t / a >= scr_t / scr_a:
			scr_a = a * ceil(scr_a, a)
			scr_t = scr_a * t // a
		else:
			scr_t = t * ceil(scr_t, t)
			scr_a = scr_t * a // t
	print(scr_t + scr_a)

def __starting_point():
	main()
__starting_point()


N = int(input())
import math
(t, a) = map(int, input().split())
for i in range(N - 1):
	(T, A) = map(int, input().split())
	g = math.ceil(max(-(-t // T), -(-a // A)))
	t = g * T
	a = g * A
ans = t + a
print(ans)


n = int(input())
t0 = 1
a0 = 1
for i in range(n):
	(t, a) = map(int, input().split())
	mul = max((t0 - 1) // t + 1, (a0 - 1) // a + 1)
	t0 = t * mul
	a0 = a * mul
print(t0 + a0)


import numpy as np
import sys

def sinput():
	return sys.stdin.readline()

def iinput():
	return int(sinput())

def imap():
	return map(int, sinput().split())

def fmap():
	return map(float, sinput().split())

def iarr():
	return list(imap())

def farr():
	return list(fmap())

def sarr():
	return sinput().split()
n = int(input())
tv = av = 1
t = [0] * n
a = [0] * n
for i in range(n):
	(t[i], a[i]) = imap()
for i in range(n):
	tmp = max(tv // t[i] + (tv % t[i] != 0), av // a[i] + (av % a[i] != 0))
	tv = t[i] * tmp
	av = a[i] * tmp
print(tv + av)


import math
N = int(input())
t = a = 1
for i in range(N):
	(T, A) = map(int, input().split())
	qT = (t + T - 1) // T
	qA = (a + A - 1) // A
	q = max(qT, qA)
	t = T * q
	a = A * q
r = t + a
print(r)


n = int(input())
a = [tuple(map(int, input().split())) for _ in range(n)]
(s, t) = (1, 1)
for i in range(0, n):
	j = max((s + a[i][0] - 1) // a[i][0], (t + a[i][1] - 1) // a[i][1])
	(s, t) = (a[i][0] * j, a[i][1] * j)
print(s + t)


import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):

	def assertIO(self, input, output):
		(stdout, stdin) = (sys.stdout, sys.stdin)
		(sys.stdout, sys.stdin) = (StringIO(), StringIO(input))
		resolve()
		sys.stdout.seek(0)
		out = sys.stdout.read()[:-1]
		(sys.stdout, sys.stdin) = (stdout, stdin)
		self.assertEqual(out, output)

	def test_入力例_1(self):
		input = '3\n2 3\n1 1\n3 2'
		output = '10'
		self.assertIO(input, output)

	def test_入力例_2(self):
		input = '4\n1 1\n1 1\n1 5\n1 100'
		output = '101'
		self.assertIO(input, output)

	def test_入力例_3(self):
		input = '5\n3 10\n48 17\n31 199\n231 23\n3 2'
		output = '6930'
		self.assertIO(input, output)

def resolve():
	N = int(input())
	R = [list(map(int, input().split())) for _ in range(N)]
	t = R[0][0]
	a = R[0][1]
	for i in range(1, N):
		n = max((t + R[i][0] - 1) // R[i][0], (a + R[i][1] - 1) // R[i][1])
		t = n * R[i][0]
		a = n * R[i][1]
	print(t + a)

def __starting_point():
	resolve()
__starting_point()


N = int(input())
(T, A) = map(int, input().split())
for i in range(N - 1):
	(t, a) = map(int, input().split())
	da = (a - A % a) % a
	dt = (A + da) * t // a - T
	if dt >= 0:
		A += da
		T += dt
	else:
		i = -(dt // t)
		da += i * a
		dt += i * t
		A += da
		T += dt
print(T + A)


import sys
readline = sys.stdin.readline

def ceil(a, b):
	return -(-a // b)

def main():
	N = int(readline())
	inp = [tuple(map(int, readline().rstrip().split())) for _ in range(N)]
	(scr_t, scr_a) = (1, 1)
	for (t, a) in inp:
		n = max(ceil(scr_t, t), ceil(scr_a, a))
		scr_t = n * t
		scr_a = n * a
	print(scr_t + scr_a)

def __starting_point():
	main()
__starting_point()


n = int(input())
A = [[int(i) for i in input().split()] for i in range(n)]
(x, y) = (1, 1)
for i in range(n):
	(a, b) = A[i]
	m = max(-(-x // a), -(-y // b))
	(x, y) = (a * m, b * m)
print(x + y)


n = int(input())
(x, y) = map(int, input().split())
import math
for i in range(n - 1):
	(t, a) = map(int, input().split())
	tbai = (x - 1) // t + 1
	abai = (y - 1) // a + 1
	bai = max(tbai, abai)
	x = t * bai
	y = a * bai
print(x + y)


t = a = 1
for i in range(int(input())):
	(T, A) = map(int, input().split())
	n = max(-(-t // T), -(-a // A))
	t = n * T
	a = n * A
print(t + a)


n = int(input())
nowa = 1
nowt = 1
for i in range(n):
	(t, a) = list(map(int, input().split()))
	bai = max(nowa * -1 // a * -1, nowt * -1 // t * -1)
	nowa = a * bai
	nowt = t * bai
print(nowa + nowt)


N = int(input())
(t0, a0) = (1, 1)
for _ in range(N):
	(t, a) = map(int, input().split())
	n = max((t0 - 1) // t + 1, (a0 - 1) // a + 1)
	(t0, a0) = (n * t, n * a)
print(t0 + a0)


n = int(input())
x = y = 1
for i in range(n):
	(t, a) = map(int, input().split())
	bx = 1 if x % t else 0
	by = 1 if y % a else 0
	k = max(x // t + bx, y // a + by)
	(x, y) = (t * k, a * k)
print(x + y)


n = int(input())
TA = [list(map(int, input().split())) for _ in range(n)]
(nowt, nowa) = TA[0]
for (t, a) in TA[1:]:
	c = max(-(-nowt // t), -(-nowa // a))
	(nowt, nowa) = (c * t, c * a)
print(nowt + nowa)


N = int(input())
(T, A) = (1, 1)
for (t, a) in [map(int, input().split()) for _ in range(N)]:
	n = max(-(-T // t), -(-A // a))
	(T, A) = (n * t, n * a)
print(T + A)


from math import ceil
from decimal import *
N = int(input())
(A, B) = (1, 1)
for i in range(N):
	nums = [int(x) for x in input().split()]
	(x, y) = (nums[0], nums[1])
	n = Decimal(max(ceil(A / x), ceil(B / y)))
	(A, B) = (x * n, y * n)
print(A + B)


n = int(input())
e = [[int(i) for i in input().split()] for i in range(n)]
a = e[0][0]
b = e[0][1]
for i in range(n - 1):
	k = [-(-a // e[i + 1][0]), -(-b // e[i + 1][1])]
	a = max(k) * e[i + 1][0]
	b = max(k) * e[i + 1][1]
print(a + b)


n = int(input())
(a, b) = (1, 1)

def div(k, l):
	if k % l == 0:
		return k // l
	else:
		return k // l + 1
for i in range(n):
	(x, y) = map(int, input().split())
	m = max(div(a, x), div(b, y))
	a = m * x
	b = m * y
print(a + b)


import sys

def resolve():
	readline = sys.stdin.readline
	n = int(readline())
	(a, b) = map(int, readline().rstrip().split())
	for _ in range(n - 1):
		(x, y) = map(int, readline().rstrip().split())
		start = max(a // x, b // y)
		for z in range(start, start + 1000):
			if x * z >= a and y * z >= b:
				(a, b) = (x * z, y * z)
				break
	print(a + b)
	return
if 'doTest' not in globals():
	resolve()
	return


N = int(input())
(T, A) = map(int, input().split())
for i in range(N - 1):
	(t, a) = map(int, input().split())
	k = max(-(-T // t), -(-A // a))
	(T, A) = (t * k, a * k)
print(T + A)


from math import ceil
N = int(input())
(T, A) = (1, 1)
for (t, a) in [map(int, input().split()) for _ in range(N)]:
	n = int(max(T // t + (0 if T % t == 0 else 1), A // a + (0 if A % a == 0 else 1)))
	(T, A) = (n * t, n * a)
print(T + A)


n = int(input())
ans = 0
(a, b) = (1, 1)
for i in range(n):
	(x, y) = map(int, input().split())
	n = max(-(-a // x), -(-b // y))
	(a, b) = (x * n, y * n)
print(a + b)


n = int(input())
(x, y) = map(int, input().split())
for i in range(n - 1):
	(t, a) = map(int, input().split())
	k = (x + t - 1) // t
	m = (y + a - 1) // a
	p = max(k, m)
	x = t * p
	y = a * p
print(x + y)


n = int(input())
(nt, na) = map(int, input().split())
for i in range(n - 1):
	(t, a) = map(int, input().split())
	x = -min(-nt // t, -na // a)
	(nt, na) = (x * t, x * a)
print(nt + na)


import math
N = int(input())
T = [list(map(int, input().split())) for i in range(N)]
cur = [1, 1]
for i in T:
	K = max(cur[0] // i[0] + (cur[0] % i[0] != 0), cur[1] // i[1] + (cur[1] % i[1] != 0))
	cur = [j * K for j in i]
print(sum(cur))


from math import ceil
n = int(input())
a = 1
b = 1
for i in range(n):
	(s, t) = map(int, input().split())
	x = max((a + s - 1) // s, (b + t - 1) // t)
	a = x * s
	b = x * t
print(a + b)


N = int(input())
vt = va = 1
for _ in range(N):
	(T, A) = map(int, input().split())
	kt = -(-vt // T)
	ka = -(-va // A)
	k = max(kt, ka)
	vt = k * T
	va = k * A
print(vt + va)


N = int(input())
t = a = 1
for i in range(N):
	(T, A) = list(map(int, input().split()))
	num = max(-(-t // T), -(-a // A))
	(t, a) = (num * T, num * A)
print(t + a)


n = int(input())
t = [0] * n
a = [0] * n
for i in range(n):
	(t[i], a[i]) = map(int, input().split())
tcnt = t[0]
acnt = a[0]
for i in range(1, n):
	x = max((tcnt + t[i] - 1) // t[i], (acnt + a[i] - 1) // a[i])
	tcnt = t[i] * x
	acnt = a[i] * x
print(tcnt + acnt)


import math
n = int(input())
ta = [list(map(int, input().split())) for i in range(n)]
(T, A) = (1, 1)
for (t, a) in ta:
	mul = max(-(-A // a), -(-T // t))
	(T, A) = (t * mul, a * mul)
print(T + A)


from decimal import *
from math import ceil
n = int(input())
(a, b) = (1, 1)
for i in range(n):
	(x, y) = map(int, input().split())
	m = Decimal(max(ceil(a / x), ceil(b / y)))
	a = x * m
	b = y * m
print(a + b)


N = int(input())
Q = [tuple(map(int, input().split())) for _ in range(N)]
vote = Q[0]
for (p, q) in Q[1:]:
	if p == q:
		g = max(vote)
		vote = (g, g)
	p_v0 = (vote[0] + p - 1) // p * p
	p_v1 = q * p_v0 // p
	q_v1 = (vote[1] + q - 1) // q * q
	q_v0 = p * q_v1 // q
	if p_v1 < vote[1]:
		vote = (q_v0, q_v1)
	elif q_v0 < vote[0]:
		vote = (p_v0, p_v1)
	elif p_v0 + p_v1 <= q_v0 + q_v1:
		vote = (p_v0, p_v1)
	else:
		vote = (q_v0, q_v1)
ans = sum(vote)
print(ans)


N = int(input())
takahashi = 1
aoki = 1
for i in range(N):
	(T, A) = list(map(int, input().split()))
	n = max((takahashi + T - 1) // T, (aoki + A - 1) // A)
	takahashi = n * T
	aoki = n * A
print(takahashi + aoki)


(t, a) = (1, 1)
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	m = max((t + x - 1) // x, (a + y - 1) // y)
	(t, a) = (x * m, y * m)
print(t + a)


from math import ceil
N = int(input())
(prv_t, prv_a) = (1, 1)
for _ in range(N):
	(t, a) = map(int, input().split())
	x = max(-(-prv_t // t), -(-prv_a // a))
	(prv_t, prv_a) = (t * x, a * x)
print(prv_t + prv_a)


t = a = 1
exec('u,b=map(int,input().split());x=0-min(-t//u,-a//b);t,a=u*x,b*x;' * int(input()))
print(t + a)


n = int(input())
t_sum = 1
a_sum = 1
for i in range(n):
	(T, A) = map(int, input().split())
	t_sum = max(-(-t_sum // T), -(-a_sum // A)) * T
	a_sum = max(-(-t_sum // T), -(-a_sum // A)) * A
print(t_sum + a_sum)


n = int(input())
(a, b) = map(int, input().split())
for _ in range(n - 1):
	(c, d) = map(int, input().split())
	i = (a + c - 1) // c
	j = (b + d - 1) // d
	k = max(i, j)
	a = c * k
	b = d * k
print(a + b)


n = int(input())
tvote = 1
avote = 1
for i in range(n):
	(t, a) = [int(n) for n in input().split()]
	k = (tvote - 1) // t + 1
	tnow = t * k
	anow = a * k
	if avote > anow:
		k = (avote - 1) // a + 1
		tnow = t * k
		anow = a * k
	tvote = tnow
	avote = anow
print(avote + tvote)


N = int(input())
TA = [list(map(int, input().split())) for _ in range(N)]
pa = 1
pt = 1
for (t, a) in TA:
	k = max(pt // t, pa // a)
	if a * k < pa or t * k < pt:
		k += 1
	pa = a * k
	pt = t * k
print(pa + pt)


n = int(input())
(anst, ansa) = map(int, input().split())
for _ in range(1, n):
	(t, a) = map(int, input().split())
	if anst > t or ansa > a:
		mul = max(-(-anst // t), -(-ansa // a))
		anst = mul * t
		ansa = mul * a
	else:
		anst = t
		ansa = a
print(anst + ansa)


import sys
import math
n = int(input())
(T, A) = (1, 1)
for i in range(n):
	(t, a) = map(int, input().split())
	coef = max((T + t - 1) // t, (A + a - 1) // a)
	(T, A) = (coef * t, coef * a)
print(T + A)


N = int(input())
T = 1
A = 1
for i in range(N):
	(x, y) = map(int, input().split())
	d1 = 1
	d2 = 1
	if T > x:
		d1 = (T - 1) // x + 1
	if A > y:
		d2 = (A - 1) // y + 1
	T = max(d1, d2) * x
	A = max(d1, d2) * y
print(T + A)


n = int(input())
(t0, a0) = (1, 1)
for i in range(n):
	(t, a) = map(int, input().split())
	if t0 / a0 > t / a:
		while t0 % t != 0:
			t0 += 1
		a0 = t0 * a // t
	elif t0 / a0 < t / a:
		while a0 % a != 0:
			a0 += 1
		t0 = a0 * t // a
print(t0 + a0)


n = int(input())
(t, a) = (1, 1)
for i in range(n):
	(ti, ai) = map(int, input().split())
	m = max((t + ti - 1) // ti, (a + ai - 1) // ai)
	(t, a) = (ti * m, ai * m)
print(t + a)


import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input():
	return sys.stdin.readline().strip()

def INT():
	return int(input())

def MAP():
	return list(map(int, input().split()))

def LIST():
	return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
N = INT()
TA = [LIST() for _ in range(N)]
vote_T = 1
vote_A = 1
for (x, y) in TA:
	n = max((vote_T + x - 1) // x, (vote_A + y - 1) // y)
	vote_T = x * n
	vote_A = y * n
print(vote_A + vote_T)


N = int(input())
T = 1
A = 1
for i in range(N):
	(ti, ai) = map(int, input().split())
	m = max(-(-T // ti), -(-A // ai))
	T = ti * m
	A = ai * m
print(T + A)


t = int(input())
par = [0, 0]
for i in range(t):
	(p, t) = map(int, input().split())
	if p >= par[0] and t >= par[1]:
		par = [p, t]
	else:
		n = max((par[0] - 1) // p + 1, (par[1] - 1) // t + 1)
		par = [p * n, t * n]
print(sum(par))


n = int(input())
(ra, rb) = (1, 1)
for i in range(n):
	(a, b) = map(int, input().split())
	n = max((ra + a - 1) // a, (rb + b - 1) // b)
	ra = a * n
	rb = b * n
print(ra + rb)


n = int(input())
L = []
for i in range(n):
	L.append([int(i) for i in input().split()])
x = L[0][0]
y = L[0][1]
for i in range(n - 1):
	n = max(-(-x // L[i + 1][0]), -(-y // L[i + 1][1]))
	x = n * L[i + 1][0]
	y = n * L[i + 1][1]
print(x + y)


def main():
	N = int(input())
	TA = [list(map(int, input().split(' '))) for _ in range(N)]
	if N == 1:
		print(sum(TA[0]))
		return
	(cur_t, cur_a) = TA[0]
	for (t, a) in TA[1:]:
		ratio = max([(cur_t + t - 1) // t, (cur_a + a - 1) // a])
		(cur_t, cur_a) = (ratio * t, ratio * a)
	print(cur_t + cur_a)

def __starting_point():
	main()
__starting_point()


from math import ceil
N = int(input())
TA = [list(map(int, input().split())) for _ in range(N)]
a = 1
b = 1
for (x, y) in TA:
	n = max(-(-a // x), -(-b // y))
	a = n * x
	b = n * y
print(a + b)


from decimal import Decimal, getcontext
from math import ceil
getcontext().prec = 1000
N = int(input())
(takahashi, aoki) = (1, 1)
for _ in range(N):
	(a, b) = map(int, input().split())
	c = max(ceil(Decimal(str(takahashi)) / Decimal(a)), ceil(Decimal(str(aoki)) / Decimal(b)))
	takahashi = c * a
	aoki = c * b
print(takahashi + aoki)


N = int(input())
(X, Y) = map(int, input().split())
(T, A) = (0, 0)
(b, c) = (0, 0)
for i in range(N - 1):
	(T, A) = map(int, input().split())
	b = (X + T - 1) // T * T
	c = b // T * A
	if c >= Y:
		(X, Y) = (b, c)
	else:
		Y = (Y + A - 1) // A * A
		X = Y // A * T
print(X + Y)


from fractions import gcd
n = int(input())
(T, A) = (1, 1)
for i in range(n):
	(t, a) = map(int, input().split())
	m = max(-(-T // t), -(-A // a))
	T = t * m
	A = a * m
print(T + A)


import math
from fractions import Fraction
from decimal import *
n = int(input())
(x, y) = list(map(int, input().split()))
(t, a) = (x, y)
for _ in range(n - 1):
	(tt, aa) = list(map(int, input().split()))
	c = max(math.ceil(Fraction(t, tt)), math.ceil(Fraction(a, aa)))
	c = max(1, c)
	t = tt * c
	a = aa * c
ans = t + a
print(ans)


n = int(input())
(p, q) = (1, 1)
for _ in range(n):
	(t, a) = map(int, input().split())
	n = max((p + t - 1) // t, (q + a - 1) // a)
	(p, q) = (n * t, n * a)
print(p + q)


import math
n = int(input())
(a, b) = (1, 1)
for _ in range(n):
	(x, y) = [int(_) for _ in input().split(' ')]
	l = max(-(-a // x), -(-b // y))
	(a, b) = (l * x, l * y)
print(a + b)


n = int(input())
tpred = 1
apred = 1
for i in range(n):
	(t, a) = map(int, input().split())
	tpred = t * max(-(-tpred // t), -(-apred // a))
	apred = a * max(-(-tpred // t), -(-apred // a))
print(tpred + apred)


def main():
	N = int(input())
	(T1, A1) = map(int, input().split())
	for _ in range(N - 1):
		(T2, A2) = map(int, input().split())
		n = max(-(-T1 // T2), -(-A1 // A2))
		(T1, A1) = (T2 * n, A2 * n)
	print(T1 + A1)

def __starting_point():
	main()
__starting_point()


def ceil(x, y):
	return x // y + (not not x % y)
n = int(input())
(a, b) = (1, 1)
for i in range(n):
	(t, s) = map(int, input().split())
	i = max(ceil(a, t), ceil(b, s))
	a = t * i
	b = s * i
print(a + b)


n = int(input())
ta = [list(map(int, input().split())) for _ in range(n)]
(pt, pa) = (1, 1)
for i in range(n):
	(t, a) = ta[i]
	v = max((pt + t - 1) // t, (pa + a - 1) // a)
	pt = v * t
	pa = v * a
print(pt + pa)


def ceil(x, y):
	return (x + y - 1) // y

def main():
	n = int(input())
	takahashi = 1
	aoki = 1
	for _ in range(n):
		(t, a) = list(map(int, input().split()))
		diff = max(ceil(takahashi, t), ceil(aoki, a))
		takahashi = t * diff
		aoki = a * diff
	print(takahashi + aoki)

def __starting_point():
	main()
__starting_point()


n = int(input())
ls = [list(map(int, input().split())) for _ in range(n)]
(x, y) = ls[0]
for (a, b) in ls[1:]:
	k = max((x + a - 1) // a, (y + b - 1) // b)
	(x, y) = (k * a, k * b)
print(x + y)


def ceil(a, b):
	return a // b + (a % b > 0)
N = int(input())
T = A = 1
for i in range(N):
	(t, a) = map(int, input().split())
	m = max(ceil(T, t), ceil(A, a))
	T = t * m
	A = a * m
print(T + A)


N = int(input())
(A, B) = map(int, input().split())
for _ in range(N - 1):
	(T, S) = map(int, input().split())
	x = max((A + T - 1) // T, (B + S - 1) // S)
	A = x * T
	B = x * S
print(A + B)


from decimal import Decimal, ROUND_CEILING
N = int(input())
pairs = (map(Decimal, input().split()) for _ in range(N))
t = Decimal('1')
a = Decimal('1')
ceil = lambda d: d.to_integral_exact(rounding=ROUND_CEILING)
for (ti, ai) in pairs:
	mul = max(ceil(t / ti), ceil(a / ai))
	t = ti * mul
	a = ai * mul
print(int(t + a))


n = int(input())
ratio_array = [tuple(map(int, input().split())) for _ in range(n)]
(t, a) = (1, 1)
for (x, y) in ratio_array:
	m = max((t + x - 1) // x, (a + y - 1) // y)
	(t, a) = (m * x, m * y)
print(t + a)


from math import ceil
N = int(input())
(T, A) = (1, 1)
for k in range(N):
	(t, a) = map(int, input().split())
	b = max(T // t, A // a)
	if t * b < T or a * b < A:
		b += 1
	(T, A) = (t * b, a * b)
print(T + A)


N = int(input())
(HT, HA) = map(int, input().split())
for i in range(1, N):
	(T, A) = map(int, input().split())
	B = max(-(-HT // T), -(-HA // A))
	HT = B * T
	HA = B * A
print(HT + HA)


n = int(input())
TA = [list(map(int, input().split())) for _ in range(n)]
T = A = 1
for (t, a) in TA:
	r = max(A // a, T // t)
	if r * a >= A and r * t >= T:
		A = r * a
		T = r * t
	else:
		A = (r + 1) * a
		T = (r + 1) * t
print(T + A)


import sys
input = sys.stdin.readline
n = int(input())
T = 1
A = 1
for i in range(n):
	(t, a) = map(int, input().split())
	x = -(-T // t)
	y = -(-A // a)
	bai = max(x, y)
	T = t * bai
	A = a * bai
print(T + A)


n = int(input())
(t_all, a_all) = (0, 0)
for i in range(n):
	(t, a) = list(map(int, input().split()))
	if i == 0:
		t_all = t
		a_all = a
	elif t >= t_all and a >= a_all:
		(t_all, a_all) = (t, a)
	else:
		(diff1, diff2) = (0, 0)
		diff1 = t_all // t if t_all % t == 0 else t_all // t + 1
		diff2 = a_all // a if a_all % a == 0 else a_all // a + 1
		max_diff = max(diff1, diff2)
		t_all = t * max_diff
		a_all = a * max_diff
print(t_all + a_all)


n = int(input())
(a, b) = map(int, input().split())
for i in range(n - 1):
	(c, d) = map(int, input().split())
	x = -min(-a // c, -b // d)
	(a, b) = (c * x, d * x)
print(a + b)


n = int(input())
tv = 1
av = 1
for i in range(n):
	(ti, ai) = map(int, input().split())
	m = max(int((tv - 1) // ti) + 1, int((av - 1) // ai) + 1)
	tv = m * ti
	av = m * ai
print(tv + av)


n = int(input())
from math import ceil
tkhs = 1
aoki = 1
for _ in range(n):
	(t, a) = map(int, input().split())
	k = max((tkhs + t - 1) // t, (aoki + a - 1) // a)
	tkhs = k * t
	aoki = k * a
print(tkhs + aoki)


N = int(input())
(bridge, blue) = map(int, input().split())
for _ in range(N - 1):
	(t, a) = map(int, input().split())
	k = max((bridge + t - 1) // t, (blue + a - 1) // a)
	(bridge, blue) = (k * t, k * a)
print(bridge + blue)


n = int(input())
ll = [list(map(int, input().split())) for _ in [0] * n]
t = 1
a = 1
for l in ll:
	if l[0] >= t and l[1] >= a:
		t = l[0]
		a = l[1]
	else:
		c = max([-(-t // l[0]), -(-a // l[1])])
		t = l[0] * c
		a = l[1] * c
print(t + a)


N = int(input())
(x, y) = (0, 0)
for i in range(N):
	p = 0
	(T, A) = map(int, input().split())
	if i == 0:
		(x, y) = (T, A)
		continue
	if x <= T and y <= A:
		(x, y) = (T, A)
	elif x <= T and A < y:
		if y % A != 0:
			p = 1
		x = T * (y // A + p)
		y = A * (y // A + p)
	elif T < x and y <= T:
		if x % T != 0:
			p = 1
		y = A * (x // T + p)
		x = T * (x // T + p)
	elif x // T + 1 <= y // A + 1:
		if y % A != 0:
			p = 1
		x = T * (y // A + p)
		y = A * (y // A + p)
	else:
		if x % T != 0:
			p = 1
		y = A * (x // T + p)
		x = T * (x // T + p)
print(x + y)


N = int(input())
TA = [list(map(int, input().split())) for i in range(N)]
(T, A) = (1, 1)
for (t, a) in TA:
	z = max(T // t, A // a)
	if T > t * z or A > a * z:
		z += 1
	T = t * z
	A = a * z
print(T + A)


N = int(input())
(a, b) = (1, 1)
for i in range(N):
	(T, A) = map(int, input().split())
	mult = max((T + a - 1) // T, (A + b - 1) // A)
	(a, b) = (T * mult, A * mult)
print(a + b)


n = int(input())
f = lambda : map(int, input().split())
(a, b) = f()
for _ in range(1, n):
	(c, d) = f()
	t = max(1, 0 - -a // c, 0 - -b // d)
	(a, b) = (c * t, d * t)
print(a + b)


import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7

def resolve():
	n = int(input())
	TA = [list(map(int, input().split())) for _ in range(n)]
	(t_pev, a_prev) = TA[0]
	for i in range(1, n):
		(t_now, a_now) = TA[i]
		if t_pev <= t_now and a_prev <= a_now:
			(t_pev, a_prev) = (t_now, a_now)
		else:
			d = max((t_pev + (t_now - 1)) // t_now, (a_prev + (a_now - 1)) // a_now)
			(t_pev, a_prev) = (t_now * d, a_now * d)
	print(t_pev + a_prev)

def __starting_point():
	resolve()
__starting_point()


import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007

def main():
	(N, *TA) = list(map(int, read().split()))
	(x, y) = (1, 1)
	for (t, a) in zip(*[iter(TA)] * 2):
		m1 = (x + t - 1) // t
		m2 = (y + a - 1) // a
		m = max(m1, m2)
		(x, y) = (t * m, a * m)
	print(x + y)
	return

def __starting_point():
	main()
__starting_point()


import math
n = int(input())
A = B = 1
for i in range(n):
	(x, y) = [int(i) for i in input().split()]
	n = max(-(-A // x), -(-B // y))
	A = n * x
	B = n * y
print(A + B)


n = int(input())
(b, u) = map(int, input().split())
(x, c, v) = (1, 1, 1)
for i in range(n - 1):
	(a, t) = map(int, input().split())
	c = b if b % a == 0 else (b // a + 1) * a
	v = u if u % t == 0 else (u // t + 1) * t
	x = max(c // a, v // t)
	b = a * x
	u = t * x
print(b + u)


from sys import stdin

def main():
	readline = stdin.readline
	n = int(readline())
	for i in range(n):
		if i == 0:
			(t, a) = map(int, readline().split())
		else:
			(t_i, a_i) = map(int, readline().split())
			tmp1 = (t + t_i - 1) // t_i
			tmp2 = (a + a_i - 1) // a_i
			x = max(tmp1, tmp2)
			t = t_i * x
			a = a_i * x
	print(a + t)

def __starting_point():
	main()
__starting_point()


n = int(input())
ta = [list(map(int, input().split())) for _ in range(n)]
t = 1
a = 1
for i in ta:
	m = max(-(-t // i[0]), -(-a // i[1]))
	t = m * i[0]
	a = m * i[1]
print(t + a)


(t, a) = (1, 1)
for _ in [0] * int(input()):
	(x, y) = map(int, input().split())
	k = max((t + x - 1) // x, (a + y - 1) // y)
	(t, a) = (x * k, y * k)
print(t + a)


N = int(input())
T = A = 1
for _ in range(N):
	(t, a) = map(int, input().split())
	k = max([1, T // t + (T % t != 0), A // a + (A % a != 0)])
	(T, A) = (k * t, k * a)
print(T + A)


from math import ceil
from fractions import Fraction
N = int(input())
(A, B) = (1, 1)
for i in range(N):
	(x, y) = map(int, input().split())
	n = max(ceil(Fraction(A, x)), ceil(Fraction(B, y)))
	(A, B) = (n * x, n * y)
print(A + B)


import math
n = int(input())
ta = [[int(i) for i in input().split()] for j in range(n)]
a = 1
b = 1
for i in range(n):
	n = max(~-a // ta[i][0] + 1, ~-b // ta[i][1] + 1)
	a = n * ta[i][0]
	b = n * ta[i][1]
print(a + b)


n = int(input())
(x, y) = map(int, input().split())
z = x + y
for i in range(n - 1):
	(a, b) = map(int, input().split())
	k = max((x - 1) // a, (y - 1) // b) + 1
	x = k * a
	y = k * b
print(x + y)


n = int(input())
(t, a) = map(int, input().split())
for i in range(n - 1):
	(T, A) = map(int, input().split())
	count = max(a // A, t // T)
	while A * count < a or T * count < t:
		count += 1
	a = count * A
	t = count * T
print(a + t)


n = int(input())
a = 0
b = 0
for _ in range(n):
	(x, y) = map(int, input().split())
	if not a:
		(a, b) = (x, y)
		continue
	z = max(-(-a // x), -(-b // y))
	(a, b) = (z * x, z * y)
print(a + b)


import sys
from io import StringIO
import unittest

def yn(b):
	print('Yes' if b == 1 else 'No')
	return

def resolve():
	readline = sys.stdin.readline
	n = int(readline())
	for i in range(n):
		(x, y) = list(map(int, readline().rstrip().split()))
		if i == 0:
			(a, b) = (x, y)
			continue
		start = max(a // x, b // y)
		zz = start - 1
		for z in range(start, start + 1000):
			if x * z >= a and y * z >= b:
				zz = z
				break
		(a, b) = (x * z, y * z)
	print(a + b)
	return
if 'doTest' not in globals():
	resolve()
	return


(n, *l) = map(int, open(0).read().split())
for i in range(2, n * 2, 2):
	m = max(0 - l[i - 2] // -l[i], 0 - l[i - 1] // -l[i + 1])
	l[i] *= m
	l[i + 1] *= m
print(l[-1] + l[-2])


N = int(input())
Ratio = [tuple(map(int, input().split())) for _ in range(N)]
from math import ceil
Vote = (1, 1)
for (t, a) in Ratio:
	p = max((t + Vote[0] - 1) // t, (a + Vote[1] - 1) // a)
	Vote = (p * t, p * a)
print(sum(Vote))


N = int(input())
TA = [list(map(int, input().split(' '))) for _ in range(N)]
(n_t, n_a) = (1, 1)
for (t, a) in TA:
	v = max(-(-n_t // t), -(-n_a // a))
	(n_t, n_a) = (t * v, a * v)
print(n_t + n_a)


import math

def main():
	N = int(input())
	(T, A) = list(map(int, input().split()))
	for _ in range(N - 1):
		(t, a) = list(map(int, input().split()))
		x = max(-(-T // t), -(-A // a))
		T = t * x
		A = a * x
	print(T + A)

def __starting_point():
	main()
__starting_point()


def f(x, y):
	return x // y + (1 if x % y > 0 else 0)
n = int(input())
(a, b) = list(map(int, input().split()))
for i in range(n - 1):
	(c, d) = list(map(int, input().split()))
	e = max(f(a, c), f(b, d))
	(a, b) = (c * e, d * e)
print(a + b)


import math
from fractions import Fraction
N = int(input())
(a, b) = map(int, input().split())
ret_a = a
ret_b = b
for _ in range(1, N):
	(a, b) = map(int, input().split())
	x = math.ceil(max(Fraction(ret_a, a), Fraction(ret_b, b)))
	ret_a = a * x
	ret_b = b * x
print(ret_a + ret_b)


import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def lcm(a, b):
	return a * b // gcd(a, b)

def main():
	n = II()
	ta = LLI(n)
	x = y = -1
	for (t, a) in ta:
		if x == -1:
			(x, y) = (t, a)
			continue
		c = max((t + x - 1) // t, (a + y - 1) // a)
		x = c * t
		y = c * a
	print(x + y)
main()


(n, t, a, *u) = map(int, open(0).read().split())
for (u, b) in zip(u[::2], u[1::2]):
	x = 0 - min(-t // u, -a // b)
	(t, a) = (u * x, b * x)
print(t + a)


import sys
import math

def main():
	mod = 1000000007
	inf = float('inf')
	sys.setrecursionlimit(10 ** 6)

	def input():
		return sys.stdin.readline().rstrip()

	def ii():
		return int(input())

	def mi():
		return list(map(int, input().split()))

	def mi_0():
		return [int(x) - 1 for x in input().split()]

	def lmi():
		return list(map(int, input().split()))

	def lmi_0():
		return list([int(x) - 1 for x in input().split()])

	def li():
		return list(input())

	def calc_minimum_card_pair(a, b, s, t):
		multiply_rate = max((a + s - 1) // s, (b + t - 1) // t)
		return (s * multiply_rate, t * multiply_rate)
	n = ii()
	L = [lmi() for _ in range(n)]
	(a, b) = (1, 1)
	for (s, t) in L:
		(a, b) = calc_minimum_card_pair(a, b, s, t)
	print(a + b)

def __starting_point():
	main()
__starting_point()


N = int(input())
A = 1
B = 1
for i in range(N):
	(a, b) = map(int, input().split())
	n = max((A + a - 1) // a, (B + b - 1) // b)
	(A, B) = (n * a, n * b)
print(A + B)


n = int(input())
(x, y) = [int(i) for i in input().split()]
for i in range(n - 1):
	(t, a) = [int(i) for i in input().split()]
	c = max(-(-x // t), -(-y // a))
	x = t * c
	y = a * c
print(x + y)


n = int(input())
(t0, a0) = (1, 1)
for i in range(n):
	(t1, a1) = map(int, input().split())
	f0 = t0 // t1
	if t0 % t1 != 0:
		f0 += 1
	f1 = a0 // a1
	if a0 % a1 != 0:
		f1 += 1
	f = max(f0, f1)
	(t0, a0) = (t1 * f, a1 * f)
print(t0 + a0)


n = int(input())
li_hi = list()
a = 1
b = 1
for i in range(n):
	li_hi.append(list(map(int, input().split())))
for l in li_hi:
	w = max(-(-a // l[0]), -(-b // l[1]))
	a = w * l[0]
	b = w * l[1]
print(a + b)


def ceil(a, b):
	return a // b + (1 if a % b else 0)
n = int(input())
(x, y) = (1, 1)
for _ in range(n):
	(t, a) = [int(i) for i in input().split()]
	k = max(ceil(x, t), ceil(y, a))
	(x, y) = (t * k, a * k)
print(x + y)


n = int(input())
query = [tuple(map(int, input().split())) for _ in range(n)]
(x, y) = (1, 1)
for (t, a) in query:
	if t >= x and a >= y:
		x = t
		y = a
	elif t < x and a < y:
		x = t * max((x + t - 1) // t, (y + a - 1) // a)
		y = a * max((x + t - 1) // t, (y + a - 1) // a)
	elif t < x:
		x = t * ((x + t - 1) // t)
		y = a * ((x + t - 1) // t)
	else:
		x = t * ((y + a - 1) // a)
		y = a * ((y + a - 1) // a)
print(x + y)


n = int(input())
for i in range(n):
	if i == 0:
		(t, a) = map(int, input().split())
	else:
		(x, y) = map(int, input().split())
		p = (t + x - 1) // x
		q = (a + y - 1) // y
		r = max(p, q)
		(t, a) = (x * r, y * r)
print(t + a)


n = int(input())
(pt, pa) = (0, 0)
for _ in range(n):
	(t, a) = tuple(map(int, input().split()))
	l = 0
	r = 10 ** 18 + 1
	while r - l > 1:
		mid = (l + r) // 2
		if t * mid >= pt and a * mid >= pa:
			r = mid
		else:
			l = mid
	(pt, pa) = (t * r, a * r)
print(pt + pa)


import fractions
N = int(input())
(t, a) = (1, 1)
for i in range(N):
	(T, A) = map(int, input().split())
	n = max(-(-a // A), -(-t // T))
	(t, a) = (n * T, n * A)
print(t + a)


import math
n = int(input())
ta = [list(map(int, input().split())) for _ in range(n)]
(x, y) = ta[0]
for i in range(1, n):
	(t, a) = ta[i]
	k = max(-(-x // t), -(-y // a))
	(x, y) = (k * t, k * a)
print(x + y)


N = int(input())
(T, A) = (1, 1)
for _ in range(N):
	(t, a) = map(int, input().split())
	if T <= t and A <= a:
		(T, A) = (t, a)
		continue
	z = max(-(-T // t), -(-A // a))
	(T, A) = (t * z, a * z)
print(T + A)


n = int(input())
A = [1, 1]
for i in range(n):
	(t, a) = map(int, input().split())
	tt = (A[0] + t - 1) // t
	aa = (A[1] + a - 1) // a
	A[0] = max(tt, aa) * t
	A[1] = max(tt, aa) * a
print(A[0] + A[1])


N = int(input())
TA = [list(map(int, input().split())) for _ in range(N)]
t = 1
a = 1
for i in range(N):
	x = max(-(-t // TA[i][0]), -(-a // TA[i][1]))
	t = TA[i][0] * x
	a = TA[i][1] * x
print(t + a)


n = int(input())
a = 1
b = 1
for i in range(n):
	(c, d) = map(int, input().split())
	num = max((a + c - 1) // c, (b + d - 1) // d)
	a = num * c
	b = num * d
print(a + b)


n = int(input())
(t, a) = (1, 1)
import math
for _ in range(n):
	(T, A) = map(int, input().split())
	k = (T + t - 1) // T
	m = (A + a - 1) // A
	x = max(k, m)
	(t, a) = (x * T, x * A)
print(t + a)


import math
from fractions import Fraction
n = int(input())
anst = 1
ansa = 1
for _ in range(n):
	(ti, ai) = list(map(int, input().split()))
	anst = ti * math.ceil(max(Fraction(anst, ti), Fraction(ansa, ai)))
	ansa = ai * math.ceil(max(Fraction(anst, ti), Fraction(ansa, ai)))
print(int(anst + ansa))


n = int(input())
(a, b) = (1, 1)
for _ in range(n):
	(x, y) = map(int, input().split())
	k = -min(-a // x, -b // y)
	a = k * x
	b = k * y
print(a + b)


N = int(input())
TA = [tuple(map(int, input().split())) for _ in range(N)]
ans = TA[0]
for ta in TA[1:]:
	x = max((ans[0] + ta[0] - 1) // ta[0], (ans[1] + ta[1] - 1) // ta[1])
	ans = (x * ta[0], x * ta[1])
print(sum(ans))


n = int(input())
(t_lst, a_lst) = ([], [])
for i in range(n):
	(ti, ai) = map(int, input().split())
	t_lst.append(ti)
	a_lst.append(ai)
(t, a) = (1, 1)
for i in range(n):
	(ti, ai) = (t_lst[i], a_lst[i])
	n = max((t + ti - 1) // ti, (a + ai - 1) // ai)
	t = n * ti
	a = n * ai
print(t + a)


def nextpt(ratio1, ratio2, pt):
	if ratio1[0] * ratio2[1] - ratio1[1] * ratio2[0] > 0:
		pt[0] = pt[0] + -1 * pt[0] % ratio2[0]
		pt[1] = pt[0] * ratio2[1] // ratio2[0]
	else:
		pt[1] = pt[1] + -1 * pt[1] % ratio2[1]
		pt[0] = pt[1] * ratio2[0] // ratio2[1]
	return pt
n = int(input())
ratios = [list(map(int, input().split())) for _ in range(n)]
pt = ratios[0]
for i in range(n - 1):
	pt = nextpt(ratios[i], ratios[i + 1], pt)
print(sum(pt))


import math
n = int(input())
(a, b) = (1, 1)
for i in range(n):
	(x, y) = map(int, input().split(' '))
	tmp = max(-(-a // x), -(-b // y))
	a = x * tmp
	b = y * tmp
print(a + b)


import sys

def v():
	N = int(sys.stdin.readline())
	P = []
	(pt, pa) = tuple(map(int, sys.stdin.readline().split()))
	res = pt + pa
	for _ in [0] * (N - 1):
		(xt, xa) = tuple(map(int, sys.stdin.readline().split()))
		xs = xt + xa
		kt = pt // xt if pt % xt == 0 else pt // xt + 1
		ka = pa // xa if pa % xa == 0 else pa // xa + 1
		k = max([kt, ka])
		(pt, pa) = (k * xt, k * xa)
		res = pt + pa
	print(res)

def __starting_point():
	v()
__starting_point()


(a, b) = (1, 1)
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	k = max((a + x - 1) // x, (b + y - 1) // y)
	a = x * k
	b = y * k
print(a + b)


class Combination:

	def __init__(self, n, mod):
		self.n = n
		self.mod = mod
		self.fac = [1 for i in range(self.n + 1)]
		self.finv = [1 for i in range(self.n + 1)]
		for i in range(2, self.n + 1):
			self.fac[i] = self.fac[i - 1] * i % self.mod
			self.finv[i] = self.finv[i - 1] * pow(i, -1, self.mod) % self.mod

	def comb(self, n, m):
		return self.fac[n] * (self.finv[n - m] * self.finv[m] % self.mod) % self.mod

def iparse():
	return list(map(int, input().split()))

def __starting_point():
	n = int(input())
	ml = 1
	last = [0, 0]
	for i in range(n):
		x = iparse()
		l = (last[0] + x[0] - 1) // x[0]
		r = (last[1] + x[1] - 1) // x[1]
		m = max(l, r)
		if m == 0:
			m = 1
		x[0] *= m
		x[1] *= m
		last = x
	print(sum(last))
__starting_point()


N = int(input())
R = [list(map(int, input().split())) for _ in range(N)]
T = 0
A = 0
for (t, a) in R:
	n = max((T - 1) // t + 1, (A - 1) // a + 1)
	T = n * t
	A = n * a
	if T + A == 0:
		T += t
		A += a
print(T + A)


n = int(input())
ta = [list(map(int, input().split())) for i in range(n)]
(a, b) = (1, 1)
for i in range(n):
	l = -min(-a // ta[i][0], -b // ta[i][1])
	a = ta[i][0] * l
	b = ta[i][1] * l
print(a + b)


n = int(input())
ary = list(map(int, input().split()))
for i in range(n - 1):
	tmp_ary = list(map(int, input().split()))
	t_rate = (ary[0] - 1) // tmp_ary[0] + 1
	a_rate = (ary[1] - 1) // tmp_ary[1] + 1
	rate = max([t_rate, a_rate])
	ary = list(map(lambda x: x * rate, tmp_ary))
print(int(ary[0] + ary[1]))


n = int(input())
(a, b) = [int(x) for x in input().split()]
for _ in range(n - 1):
	(c, d) = [int(x) for x in input().split()]
	k = max((a - 1) // c + 1, (b - 1) // d + 1)
	(a, b) = (c * k, d * k)
print(a + b)


n = int(input())
(x, y) = map(int, input().split())
for _ in range(n - 1):
	(t, a) = map(int, input().split())
	i = max((x + t - 1) // t, (y + a - 1) // a)
	x = t * i
	y = a * i
print(x + y)


n = int(input())
(x, y) = (1, 1)
for _ in range(n):
	(p, q) = map(int, input().split())
	m = max((x + p - 1) // p, (y + q - 1) // q)
	(x, y) = (m * p, m * q)
print(x + y)


N = int(input())
(TT, AA) = map(int, input().split())
for k in range(1, N):
	(T, A) = map(int, input().split())
	j = max((TT - 1 + T) // T, (AA - 1 + A) // A)
	TT = T * j
	AA = A * j
print(TT + AA)


n = int(input())
(x, y) = (1, 1)
for _ in range(n):
	(t, a) = map(int, input().split())
	r = (x + t - 1) // t
	s = (y + a - 1) // a
	x = max(r, s) * t
	y = max(r, s) * a
print(x + y)


n = int(input())
(t_i, a_i) = map(int, input().split())
t = []
a = []
t.append(t_i)
a.append(a_i)
for i in range(1, n):
	(t_i, a_i) = map(int, input().split())
	t.append(t_i)
	a.append(a_i)
	if t[i - 1] > t[i] or a[i - 1] > a[i]:
		t_max = t[i - 1] // t[i]
		if t[i - 1] % t[i] != 0:
			t_max += 1
		a_max = a[i - 1] // a[i]
		if a[i - 1] % a[i] != 0:
			a_max += 1
		bai = max(t_max, a_max)
		t[i] *= bai
		a[i] *= bai
print(t[-1] + a[-1])


from decimal import *
from math import ceil
N = int(input())
(T, A) = (1, 1)
for i in range(N):
	(Ti, Ai) = map(int, input().split())
	r = Decimal(max(ceil(T / Ti), ceil(A / Ai)))
	(T, A) = (Ti * r, Ai * r)
print(T + A)


n = int(input())
(a, b) = (1, 1)
for i in range(n):
	(x, y) = map(int, input().split())
	s = -(-a // x)
	t = -(-b // y)
	(a, b) = (max(s, t) * x, max(s, t) * y)
print(a + b)


N = int(input())
(A, B) = (1, 1)
for i in range(N):
	tmpl = list(map(int, input().split()))
	tmp = max(-1 * (-1 * A // tmpl[0]), -1 * (-1 * B // tmpl[1]))
	(A, B) = (tmpl[0] * tmp, tmpl[1] * tmp)
print(A + B)


import math
N = int(input())
ls = []
for i in range(N):
	ls.append(list(map(int, input().split())))
T = 1
A = 1
for i in range(N):
	bai = max(-(-T // ls[i][0]), -(-A // ls[i][1]))
	T = bai * ls[i][0]
	A = bai * ls[i][1]
print(T + A)


n = int(input())
ta = [[int(i) for i in input().split()] for j in range(n)]
tt = 1
aa = 1
for i in ta:
	ta = max(-(-tt // i[0]), -(-aa // i[1]))
	tt = ta * i[0]
	aa = ta * i[1]
print(tt + aa)


N = int(input())
(t, a) = list(map(int, input().split(' ')))
for _ in range(N - 1):
	(nt, na) = list(map(int, input().split(' ')))
	if nt >= t and na >= a:
		t = nt
		a = na
	else:
		tr = (t + nt - 1) // nt
		ar = (a + na - 1) // na
		r = max(tr, ar)
		t = r * nt
		a = r * na
print(t + a)


N = int(input())
(min_T, min_A) = (1, 1)
for _ in range(N):
	(T, A) = map(int, input().split())
	i = max(-(-min_A // A), -(-min_T // T))
	min_T = T * i
	min_A = A * i
print(min_T + min_A)


N = int(input())
T = 1
A = 1
for i in range(N):
	Tk = [0, 0]
	Ak = [0, 0]
	(Tn, An) = map(int, input().rstrip().split(' '))
	if T % Tn == 0:
		Tk[0] = T
	else:
		Tk[0] = (T // Tn + 1) * Tn
	Ak[0] = Tk[0] // Tn * An
	if Ak[0] < A:
		Ak[0] = 10 ** 18 + 1
	if A % An == 0:
		Ak[1] = A
	else:
		Ak[1] = (A // An + 1) * An
	Tk[1] = Ak[1] // An * Tn
	if Tk[1] < T:
		Tk[1] = 10 ** 18 + 1
	if Tk[0] + Ak[0] <= Tk[1] + Ak[1]:
		T = Tk[0]
		A = Ak[0]
	else:
		T = Tk[1]
		A = Ak[1]
print(A + T)


from sys import stdin, stdout
import bisect
import math

def st():
	return list(stdin.readline().strip())

def inp():
	return int(stdin.readline())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return list(map(int, stdin.readline().split()))

def pr(n):
	stdout.write(str(n) + '\n')

def soe(limit):
	l = [1] * (limit + 1)
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
		a *= a
		n = n >> 1
	return r

def solve():
	n = inp()
	(a, b) = (1, 1)
	for _ in range(n):
		(x, y) = mp()
		d = max((x + a - 1) // x, (y + b - 1) // y)
		a = d * x
		b = d * y
	pr(a + b)
for _ in range(1):
	solve()


n = int(input())
(t1, a1) = list(map(int, input().split()))
for i in range(n - 1):
	(t, a) = list(map(int, input().split()))
	if t1 * a == t * a1:
		pass
	elif t1 * a < t * a1:
		a1 = -(-a1 // a) * a
		t1 = a1 // a * t
	else:
		t1 = -(-t1 // t) * t
		a1 = t1 // t * a
print(a1 + t1)


def main():
	from math import ceil
	n = int(input())
	(a, b) = (1, 1)
	for _ in range(n):
		(i, j) = list(map(int, input().split()))
		x = max((a + i - 1) // i, (b + j - 1) // j)
		(a, b) = (x * i, x * j)
	print(a + b)

def __starting_point():
	main()
__starting_point()


N = int(input())
tans = 1
aans = 1
for i in range(N):
	(t, a) = map(int, input().split())
	n = max(-(-tans // t), -(-aans // a))
	tans = n * t
	aans = n * a
print(aans + tans)


n = int(input())
t_v = a_v = 1
for _ in range(n):
	(t, a) = [int(x) for x in input().split()]
	r = max((t_v + t - 1) // t, (a_v + a - 1) // a)
	(t_v, a_v) = (r * t, r * a)
print(t_v + a_v)


N = int(input())
TA = [list(map(int, input().split())) for _ in range(N)]
(T, A) = (0, 0)
for (t, a) in TA:
	if T == 0 and A == 0:
		T = t
		A = a
		continue
	if t == a:
		M = max(T, A)
		T = M
		A = M
	elif t < a:
		n = max(T // t * t, A // a * t)
		while n < T or a * (n // t) < A:
			n += t
		T = n
		A = a * (T // t)
	else:
		n = max(A // a * a, T // t * a)
		while n < A or t * (n // a) < T:
			n += a
		A = n
		T = t * (A // a)
print(A + T)


a = b = 1
for _ in range(int(input())):
	(c, d) = map(int, input().split())
	m = max(0 - -a // c, 0 - -b // d)
	(a, b) = (c * m, d * m)
print(a + b)


N = int(input())
V = [list(map(int, input().split())) for k in range(N)]
T = 1
A = 1
for k in V:
	t = max(T // k[0], A // k[1])
	if t * k[0] < T or t * k[1] < A:
		t += 1
	T = k[0] * t
	A = k[1] * t
print(T + A)


n = int(input())
ta = [list(map(int, input().split())) for _ in range(n)]
(tv, av) = (1, 1)
for (t, a) in ta:
	i = (t + tv - 1) // t
	j = (a + av - 1) // a
	k = max(i, j)
	tv = t * k
	av = a * k
print(tv + av)


n = int(input())
(a, b) = map(int, input().split())
if n != 1:
	for _ in range(n - 1):
		(A, B) = map(int, input().split())
		k = max(1, (a + A - 1) // A, (b + B - 1) // B)
		a = k * A
		b = k * B
print(a + b)


n = int(input())
(A, B) = (0, 0)
for i in range(n):
	(x, y) = map(int, input().split())
	(dx, dy) = (1, 1)
	if A > x:
		dx = A // x
		if A % x != 0:
			dx += 1
	if B > y:
		dy = B // y
		if B % y != 0:
			dy += 1
	a = max(dx, dy)
	(A, B) = (a * x, a * y)
print(A + B)


n = int(input())
A = 0
B = 0
for _ in range(n):
	(a, b) = map(int, input().split())
	A = max(A, a)
	B = max(B, b)
	w = max((A + B - 1) // (a + b) + 1, (A - 1) // a + 1, (B - 1) // b + 1)
	A = w * a
	B = w * b
print(A + B)


n = int(input())
(a, b) = map(int, input().split())
for i in range(n - 1):
	(x, y) = map(int, input().split())
	c = max(-(-a // x), -(-b // y))
	(a, b) = (x * c, y * c)
print(a + b)


N = int(input())
(Tl, Al) = map(int, input().split())
for i in range(N - 1):
	(Tr, Ar) = map(int, input().split())
	k = max((Tl - 1) // Tr, (Al - 1) // Ar) + 1
	(Tl, Al) = (k * Tr, k * Ar)
print(Tl + Al)


n = int(input())
(x, y) = (1, 1)
for i in range(n):
	(a, b) = map(int, input().split())
	if x % a == 0:
		x1 = x // a
	else:
		x1 = x // a + 1
	if y % b == 0:
		y1 = y // b
	else:
		y1 = y // b + 1
	z1 = max(x1, y1)
	(x, y) = (a * z1, b * z1)
print(x + y)


N = int(input())
t = 0
a = 0
for _ in range(N):
	(rt, ra) = map(int, input().split())
	c = max((t - 1) // rt + 1, (a - 1) // ra + 1)
	t = rt * c
	a = ra * c
	if a + t == 0:
		t += rt
		a += ra
print(a + t)


import math
n = int(input())
ta = [tuple(map(int, input().split())) for _ in range(n)]
(a, b) = ta[0]
for i in range(n):
	(x, y) = ta[i]
	z = max(-(-a // x), -(-b // y))
	a = x * z
	b = y * z
ans = a + b
print(ans)


N = int(input())

def ceil(a, b):
	return (a + b - 1) // b
(T, A) = (1, 1)
for _ in range(N):
	(Tt, At) = map(int, input().split())
	x = max(ceil(T, Tt), ceil(A, At))
	(T, A) = (Tt * x, At * x)
print(T + A)


import math
n = int(input())
(a, b) = (1, 1)
for _ in range(n):
	(ai, bi) = [int(x) for x in input().split()]
	n = max((a - 1) // ai, (b - 1) // bi) + 1
	a = n * ai
	b = n * bi
print(a + b)


def cin():
	return list(map(int, input().split()))

def cino(test=False):
	if not test:
		return int(input())
	else:
		return input()

def cina():
	return list(map(int, input().split()))
a = cino()
(x, y) = (1, 1)
for _ in range(a):
	(p, q) = cin()
	k = max((x + p - 1) // p, (y + q - 1) // q)
	(x, y) = (k * p, k * q)
print(x + y)


import math
n = int(input())
ans = list(map(int, input().split()))
if n == 1:
	print(sum(ans))
else:
	ans1 = []
	ans1.append(ans)
	for i in range(n - 1):
		(x, y) = list(map(int, input().split()))
		(p, q) = (ans1[-1][0], ans1[-1][1])
		if p % x == 0:
			p1 = p // x
		else:
			p1 = p // x + 1
		if q % y == 0:
			q1 = q // y
		else:
			q1 = q // y + 1
		pq = max(p1, q1)
		r = [x * pq, y * pq]
		ans1.append(r)
	print(sum(ans1[-1]))


import fractions
N = int(input())
vt = va = 0
for _ in range(N):
	(T, A) = map(int, input().split())
	kt = -(-vt // T)
	ka = -(-va // A)
	if kt == 0 and ka == 0:
		vt = T
		va = A
	else:
		k = max(kt, ka)
		vt = k * T
		va = k * A
print(vt + va)


from math import gcd
n = int(input())
for i in range(n):
	(a, b) = list(map(int, input().split()))
	if i == 0:
		(pre_a, pre_b) = (a, b)
	if pre_a * b < pre_b * a:
		mul = (pre_b + b - 1) // b
		pre_b = mul * b
		pre_a = pre_b * a // b
	else:
		mul = (pre_a + a - 1) // a
		pre_a = mul * a
		pre_b = pre_a * b // a
print(pre_a + pre_b)


N = int(input())
(t, a) = map(int, input().split())
for i in range(N - 1):
	(nt, na) = map(int, input().split())
	p = max((t + nt - 1) // nt, (a + na - 1) // na)
	t = nt * p
	a = na * p
print(t + a)


import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy
N = int(input())
(A, B) = (1, 1)
for i in range(N):
	(XA, XB) = map(int, input().split())
	if A * XB > XA * B:
		d = (A + XA - 1) // XA
		(A, B) = (d * XA, d * XB)
	else:
		d = (B + XB - 1) // XB
		(A, B) = (d * XA, d * XB)
print(A + B)


from math import ceil
N = int(input())
votes = [1, 1]
rate = 1
for i in range(N):
	(t, a) = map(int, input().split())
	rate = max((votes[0] - 1) // t, (votes[1] - 1) // a) + 1
	votes = [t * rate, a * rate]
print(sum(votes))


N = int(input())
(T, A) = map(int, input().split())
for i in range(N - 1):
	(t, a) = map(int, input().split())
	p = (T - 1) // t + 1
	q = (A - 1) // a + 1
	n = max(p, q)
	T = n * t
	A = n * a
print(T + A)


n = int(input())
tans = 1
aans = 1
for i in range(n):
	(t, a) = map(int, input().split())
	tt = (tans + t - 1) // t
	at = (aans + a - 1) // a
	mt = max([tt, at])
	tans = t * mt
	aans = a * mt
print(tans + aans)


import math
from fractions import Fraction
n = int(input())
x = [1, 1]
for i in range(n):
	(a0, b0) = x
	(a, b) = [int(i) for i in input().split()]
	m = math.ceil(max(Fraction(a0, a), Fraction(b0, b)))
	x = [m * a, m * b]
print(int(sum(x)))


N = int(input())
(a, b) = (1, 1)
for _ in range(N):
	(x, y) = map(int, input().split())
	n = max((a + x - 1) // x, (b + y - 1) // y)
	(a, b) = (n * x, n * y)
print(a + b)


import sys
input = sys.stdin.readline
N = int(input())
(X, Y) = (1, 1)
for i in range(N):
	(T, A) = map(int, input().split())
	k = max((X + T - 1) // T, (Y + A - 1) // A)
	(X, Y) = (k * T, k * A)
print(X + Y)


N = int(input())
T = []
A = [1, 1]
for i in range(N):
	t = list(map(int, input().split()))
	n0 = (A[0] - 1) // t[0] + 1
	n1 = (A[1] - 1) // t[1] + 1
	n = max(n0, n1)
	A[0] = t[0] * n
	A[1] = t[1] * n
print(sum(A))


N = int(input())
(x, y) = (1, 1)
for _ in range(N):
	(T, A) = map(int, input().split())
	p = max(-(-x // T), -(-y // A))
	x = T * p
	y = A * p
print(x + y)


N = int(input())
tak = 1
aok = 1
for _ in range(N):
	(t, a) = map(int, input().split())
	d = max(-(-aok // a), -(-tak // t))
	(tak, aok) = (t * d, a * d)
print(tak + aok)


n = int(input())
(t_prev, a_prev) = map(int, input().split())
for i in range(n - 1):
	(t, a) = map(int, input().split())
	k = max(t_prev // t + min(1, t_prev % t), a_prev // a + min(1, a_prev % a))
	(t_prev, a_prev) = (t * k, a * k)
print(t_prev + a_prev)


n = int(input())
vote_t = 1
vote_a = 1
for _ in range(n):
	(t, a) = list(map(int, input().split()))
	n = max((vote_t + t - 1) // t, (vote_a + a - 1) // a)
	vote_t = n * t
	vote_a = n * a
print(vote_t + vote_a)


N = int(input())
(tx, ax) = (1, 1)
for _ in range(N):
	(T, A) = map(int, input().split())
	fac = max(tx // T, ax // A)
	if T * fac < tx or A * fac < ax:
		fac += 1
	tx = T * fac
	ax = A * fac
print(tx + ax)


def ceil(x, y):
	return (x - 1) // y + 1
N = int(input())
TA = [list(map(int, input().split())) for _ in range(N)]
(t, a) = (1, 1)
for (T, A) in TA:
	rate = max(ceil(t, T), ceil(a, A))
	t = T * rate
	a = A * rate
print(t + a)


n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
(A, B) = (a[0][0], a[0][1])
for i in range(1, n):
	C = max([1, -(-A // a[i][0]), -(-B // a[i][1])])
	A = a[i][0] * C
	B = a[i][1] * C
print(A + B)


N = int(input())
T = 0
A = 0
for _ in range(N):
	(t, a) = map(int, input().split())
	i = max(T // t, A // a, 1)
	while T > i * t or A > i * a:
		i += 1
	T = i * t
	A = i * a
print(T + A)


N = int(input())
ballots = [list(map(int, input().split())) for _ in range(N)]

def eceil(x, y):
	return (x + y - 1) // y
prev = ballots[0]
for i in range(1, N):
	(m, n) = ballots[i]
	k = max(eceil(prev[0], m), eceil(prev[1], n))
	tot = k * (m + n)
	prev[0] = tot * m // (m + n)
	prev[1] = tot * n // (m + n)
print(sum(prev))


n = int(input())
(nt, na) = (1, 1)
for _ in range(n):
	(t, a) = map(int, input().split())
	(x, y) = (-(-nt // t), -(-na // a))
	m = max(x, y)
	(nt, na) = (t * m, a * m)
print(nt + na)


n = int(input())
(A, B) = (1, 1)
for _ in [0] * n:
	(t, a) = map(int, input().split())
	v = max((A + t - 1) // t, (B + a - 1) // a)
	(A, B) = (v * t, v * a)
print(A + B)


N = int(input())
(takahashi, aoki) = (1, 1)
for _ in range(N):
	(a, b) = map(int, input().split())
	c = max((takahashi - 1) // a + 1, (aoki - 1) // b + 1)
	takahashi = c * a
	aoki = c * b
print(takahashi + aoki)


n = int(input())
p = 1
q = 1
for i in range(n):
	(t, a) = map(int, input().split())
	f = max((p + t - 1) // t, (q + a - 1) // a)
	p = t * f
	q = a * f
print(p + q)


N = int(input())
t = 1
a = 1
for i in range(1, N + 1):
	(tk, ao) = input().split()
	T = int(tk)
	A = int(ao)
	n = max(-1 * t // T * -1, -1 * a // A * -1)
	a = n * A
	t = n * T
print(a + t)


n = int(input())
(t_, a_) = (1, 1)
for _ in range(n):
	(x, y) = map(int, input().split())
	l = max((t_ - 1) // x, (a_ - 1) // y) + 1
	t_ = l * x
	a_ = l * y
print(t_ + a_)


N = int(input())
(a, b) = (1, 1)
for i in range(N):
	(aa, bb) = map(int, input().split())
	k = max((a + aa - 1) // aa, (b + bb - 1) // bb)
	aa *= k
	bb *= k
	(a, b) = (aa, bb)
print(a + b)


from math import floor
N = int(input())
(T, A) = (1, 1)
for (t, a) in [map(int, input().split()) for _ in range(N)]:
	n = max(-(-T // t), -(-A // a))
	(T, A) = (n * t, n * a)
print(T + A)


def gcd(x, y):
	if y == 0:
		return x
	else:
		return gcd(y, x % y)

def lcm(x, y):
	return x * y // gcd(x, y)
N = int(input())
(x, y) = (0, 0)
for i in range(N):
	p = 0
	(T, A) = map(int, input().split())
	if i == 0:
		(x, y) = (T, A)
		continue
	if x <= T and y <= A:
		(x, y) = (T, A)
	elif x <= T and A < y:
		if y % A != 0:
			p = 1
		x = T * (y // A + p)
		y = A * (y // A + p)
	elif T < x and y <= T:
		if x % T != 0:
			p = 1
		y = A * (x // T + p)
		x = T * (x // T + p)
	elif x // T + 1 <= y // A + 1:
		if y % A != 0:
			p = 1
		x = T * (y // A + p)
		y = A * (y // A + p)
	else:
		if x % T != 0:
			p = 1
		y = A * (x // T + p)
		x = T * (x // T + p)
print(x + y)