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.
[{"code": "import sys\nreadline = sys.stdin.readline\ndef ceil(a, b):\n    return -(-a//b)\n\ndef main():\n    N = int(readline())\n    inp = [tuple(map(int, readline().rstrip().split())) for _ in range(N)]\n    scr_t, scr_a = 0, 0\n    for t, a in inp:\n        if t >= scr_t and a >= scr_a:\n            scr_t = t\n            scr_a = a\n        elif t < scr_t and a >= scr_a:\n            scr_t = t * ceil(scr_t, t)\n            scr_a = scr_t * a // t\n        elif a < scr_a and t >= scr_t:\n            scr_a = a * ceil(scr_a, a)\n            scr_t = scr_a * t // a\n        else:\n            if t / a >= scr_t / scr_a:\n                scr_a = a * ceil(scr_a, a)\n                scr_t = scr_a * t // a\n            else:\n                scr_t = t * ceil(scr_t, t)\n                scr_a = scr_t * a // t\n\n    print((scr_t + scr_a))\n\ndef __starting_point():\n    main()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14248.0, "status": "done"}, {"code": "n = int(input())\nvote_t = 1\nvote_a = 1\n    \nfor _ in range(n):\n    t,a = list(map(int, input().split()))\n    n = max((vote_t + t - 1) // t, (vote_a + a -1) // a)\n    vote_t = n * t\n    vote_a = n * a\n\nprint(vote_t + vote_a)", "passed": true, "time": 0.14, "memory": 14316.0, "status": "done"}, {"code": "import sys\n\ndef resolve():\n    readline=sys.stdin.readline\n\n    n=int(readline())\n    a,b=map(int, readline().rstrip().split())\n    for _ in range(n-1):\n        x,y=map(int, readline().rstrip().split())\n        start=max(a//x,b//y)\n        for z in range(start,start+1000):\n            if x*z>=a and y*z>=b:\n                a,b=x*z,y*z\n                break\n    print(a+b)\n\n    return\n\nif 'doTest' not in globals():\n    resolve()\n    return", "passed": true, "time": 0.14, "memory": 14252.0, "status": "done"}, {"code": "n = int(input())\nA, B = 0, 0\nfor i in range(n):\n    x, y = map(int,input().split())\n    dx, dy = 1, 1\n    if A > x:\n        dx = A // x\n        if A % x != 0:\n            dx += 1\n    \n    if B > y:\n        dy = B // y\n        if B % y != 0:\n            dy += 1\n\n    a = max(dx, dy)\n    A, B = a * x, a * y\nprint(A + B)", "passed": true, "time": 0.25, "memory": 14120.0, "status": "done"}, {"code": "t = 1\na = 1\n\nfor i in range(int(input())):\n  T,A = map(int,input().split())\n  n = max(-(-t//T),-(-a//A))\n  t = n*T\n  a = n*A\n\nprint(t+a)", "passed": true, "time": 0.24, "memory": 14276.0, "status": "done"}, {"code": "N = int(input())\nRatio = [tuple(map(int, input().split())) for _ in range(N)]\nfrom math import ceil\nVote = (1, 1)\nfor t,a in Ratio:\n    p = max((t+Vote[0]-1)//t, (a+Vote[1]-1)//a)\n    Vote = (p*t, p*a)\nprint(sum(Vote))", "passed": true, "time": 0.16, "memory": 14272.0, "status": "done"}, {"code": "n = int(input())\nt_all, a_all = 0, 0\nfor i in range(n):\n    t, a = list(map(int, input().split()))\n    if i == 0:\n        t_all = t\n        a_all = a\n    else:\n        if t >= t_all and a >= a_all:\n            t_all, a_all = t, a\n        else:\n            diff1, diff2 = 0, 0\n            diff1 = t_all // t if t_all % t == 0 else t_all // t + 1\n            diff2 = a_all // a if a_all % a == 0 else a_all // a + 1\n            max_diff = max(diff1, diff2)\n            t_all = t * max_diff\n            a_all = a * max_diff\nprint((t_all + a_all))\n        \n", "passed": true, "time": 0.15, "memory": 14372.0, "status": "done"}, {"code": "N = int(input())\nTNow,ANow = (int(T) for T in input().split())\nfor TN in range(1,N):\n    TNext,ANext = (int(T) for T in input().split())\n    Magn = max(TNow//TNext+(TNow%TNext!=0),ANow//ANext+(ANow%ANext!=0))\n    TNow,ANow = TNext*Magn,ANext*Magn\nprint(TNow+ANow)", "passed": true, "time": 0.28, "memory": 14212.0, "status": "done"}, {"code": "import sys\ndef v():\n    N=int(sys.stdin.readline())\n    P=[]\n    pt,pa=tuple(map(int,sys.stdin.readline().split()))\n    res=pt+pa\n    for _ in [0]*(N-1):\n        xt,xa=tuple(map(int,sys.stdin.readline().split()))\n        xs=xt+xa\n        kt=pt//xt if pt%xt ==0 else pt//xt+1\n        ka=pa//xa if pa%xa ==0 else pa//xa+1\n        k=max([kt,ka])\n        pt,pa=k*xt,k*xa\n        res=pt+pa\n    print(res)\ndef __starting_point():v()\n\n__starting_point()", "passed": true, "time": 0.23, "memory": 14344.0, "status": "done"}, {"code": "from decimal import Decimal, ROUND_CEILING\n\nN = int(input())\npairs = (map(Decimal, input().split()) for _ in range(N))\n\nt = Decimal('1')\na = Decimal('1')\nceil = lambda d: d.to_integral_exact(rounding=ROUND_CEILING)\n\nfor ti, ai in pairs:\n    mul = max(ceil(t / ti), ceil(a / ai))\n    t = ti * mul\n    a = ai * mul\n\nprint(int(t + a))", "passed": true, "time": 0.15, "memory": 14224.0, "status": "done"}, {"code": "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\ndef II(): return int(sys.stdin.readline())\ndef MI(): return map(int, sys.stdin.readline().split())\ndef LI(): return list(map(int, sys.stdin.readline().split()))\ndef LLI(rows_number): return [LI() for _ in range(rows_number)]\ndef SI(): return sys.stdin.readline()[:-1]\n\ndef gcd(a,b):\n    while b:a,b=b,a%b\n    return a\n\ndef lcm(a,b):return a*b//gcd(a,b)\n\ndef main():\n    n=II()\n    ta=LLI(n)\n    x=y=-1\n    for t,a in ta:\n        if x==-1:\n            x,y=t,a\n            continue\n        c=max((t+x-1)//t,(a+y-1)//a)\n        x=c*t\n        y=c*a\n    print(x+y)\n\nmain()", "passed": true, "time": 0.14, "memory": 14128.0, "status": "done"}, {"code": "T = 1\nA = 1\n\nfor n in range(int(input())):\n  t,a = map(int,input().split())\n  m = max(-(-T//t),-(-A//a))\n  T = m*t\n  A = m*a\n\nprint(T+A)", "passed": true, "time": 0.14, "memory": 14092.0, "status": "done"}, {"code": "n = int(input())\nt_lst, a_lst = [], []\nfor i in range(n):\n    ti, ai = map(int, input().split())\n    t_lst.append(ti)\n    a_lst.append(ai)\n\nt, a = 1, 1\nfor i in range(n):\n    ti, ai = t_lst[i], a_lst[i]\n    n = max((t+ti-1)//ti, (a+ai-1)//ai)\n    t = n*ti\n    a = n*ai\nprint(t+a)", "passed": true, "time": 0.21, "memory": 14036.0, "status": "done"}, {"code": "from math import ceil \nN = int(input())\nvotes = [1,1]\nrate = 1\nfor i in range(N):\n    t,a = map(int,input().split())\n    rate = max((votes[0] - 1) // t, (votes[1] - 1) // a) + 1\n    # if t * rate >= votes[0] and a * rate >= votes[1]:\n    votes = [t * rate, a * rate]\n\nprint(sum(votes))", "passed": true, "time": 0.15, "memory": 14216.0, "status": "done"}, {"code": "n = int(input())\nA,B = 0,0\nfor i in range(n):\n    x,y = map(int,input().split())\n    t,a = 1,1\n    if A > x:\n        t = A // x\n        if A % x != 0:\n            t += 1\n    if B > y:\n        a = B // y\n        if B % y != 0:\n            a += 1\n    m = max(t,a)\n    A = x*m\n    B = y*m\nprint(A+B)", "passed": true, "time": 0.14, "memory": 14264.0, "status": "done"}, {"code": "import sys\nsys.setrecursionlimit(10 ** 7)\ninput = sys.stdin.readline\nf_inf = float('inf')\nmod = 10 ** 9 + 7\n\n\ndef resolve():\n    n = int(input())\n    TA = [list(map(int, input().split())) for _ in range(n)]\n\n    t_pev, a_prev = TA[0]\n    for i in range(1, n):\n        t_now, a_now = TA[i]\n        if t_pev <= t_now and a_prev <= a_now:\n            t_pev, a_prev = t_now, a_now\n        else:\n            d = max((t_pev + (t_now - 1)) // t_now, (a_prev + (a_now - 1)) // a_now)\n            t_pev, a_prev = t_now * d, a_now * d\n    print((t_pev + a_prev))\n\n\ndef __starting_point():\n    resolve()\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14328.0, "status": "done"}, {"code": "import math\nfrom fractions import Fraction\nn = int(input())\n# t0, a0 = map(int, input().split())\nanst = 1\nansa = 1\nfor _ in range(n):\n    ti, ai = list(map(int, input().split()))\n    anst = ti * math.ceil(max(Fraction(anst, ti), Fraction(ansa, ai)))\n    ansa = ai * math.ceil(max(Fraction(anst, ti), Fraction(ansa, ai)))\n    # p\n    # if math.ceil(anst/ti) < math.ceil(ansa/ai):\n    #     # if math.ceil(anst/ti)*ai >= ansa:\n    #     #     anst = ti * math.ceil(anst/ti)\n    #     #     ansa = ai * math.ceil(anst/ti)\n    #     # else:\n    #     ansa = ai * math.ceil(ansa/ai)\n    #     anst = ti * math.ceil(ansa/ai)\n    # else:\n    #     # if math.ceil(ansa/ai)*ti >= anst:\n    #     #     ansa = ai * math.ceil(ansa/ai)\n    #     #     anst = ti * math.ceil(ansa/ai)\n    #     # else:\n    #     ansa = ai * math.ceil(anst/ti)\n    #     anst = ti * math.ceil(anst/ti)\n    # # print(\"anst\", anst,\"ansa = \", ansa)\n        \nprint((int(anst + ansa)))\n    \n", "passed": true, "time": 0.15, "memory": 14052.0, "status": "done"}, {"code": "import sys, re\nfrom collections import deque, defaultdict, Counter\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians\nfrom itertools import permutations, combinations, product\nfrom operator import itemgetter, mul\nfrom copy import deepcopy\nfrom string import ascii_lowercase, ascii_uppercase, digits\n\ndef input(): return sys.stdin.readline().strip()\ndef INT(): return int(input())\ndef MAP(): return list(map(int, input().split()))\ndef LIST(): return list(map(int, input().split()))\nsys.setrecursionlimit(10 ** 9)\nINF = float('inf')\nMOD = 10 ** 9 + 7\n\nN = INT()\nTA = [LIST() for _ in range(N)]\nvote_T = 1\nvote_A = 1\nfor x, y in TA:\n\tn = max((vote_T+x-1)//x, (vote_A+y-1)//y)\n\tvote_T = x * n\n\tvote_A = y * n\nprint((vote_A + vote_T))\n", "passed": true, "time": 0.14, "memory": 14244.0, "status": "done"}, {"code": "### ----------------\n### \u3053\u3053\u304b\u3089\n### ----------------\n\nimport sys\nfrom io import StringIO\nimport unittest\n\ndef yn(b):\n    print((\"Yes\" if b==1 else \"No\"))\n    return\n\ndef resolve():\n    readline=sys.stdin.readline\n\n    #a,b,c=map(int, readline().rstrip().split())\n    #arr=list(map(int, readline().rstrip().split()))\n    n=int(readline())\n    for i in range(n):\n        x,y=list(map(int, readline().rstrip().split()))\n        if i==0:\n            a,b=x,y\n            continue\n        start=max(a//x,b//y)\n        zz=start-1\n        for z in range(start,start+1000):\n            if x*z>=a and y*z>=b:\n                zz=z\n                break\n        a,b=x*z,y*z\n    print((a+b))\n    #ss=readline().rstrip()\n    #yn(1)\n\n    return\n\nif 'doTest' not in globals():\n    resolve()\n    return\n\n### ----------------\n### \u3053\u3053\u307e\u3067 \n### ----------------\n", "passed": true, "time": 0.28, "memory": 14344.0, "status": "done"}, {"code": "n = int(input())\npt, pa = 0, 0\nfor _ in range(n):\n    t, a = tuple(map(int, input().split()))\n    l = 0\n    r = 10**18+1\n    while (r-l) > 1:\n        mid = (l+r)//2\n        if (t*mid >= pt and a*mid >= pa):\n            r = mid\n        else:\n            l = mid\n    pt, pa = t*r, a*r\n\nprint((pt+pa))\n", "passed": true, "time": 0.14, "memory": 14252.0, "status": "done"}, {"code": "import math\nN = int(input())\nls = []\nfor i in range(N):\n    ls.append(list(map(int,input().split())))\n\nT = 1\nA = 1\nfor i in range(N):\n    bai = max(-(-T//ls[i][0]),-(-A//ls[i][1]))\n    T = bai * ls[i][0]\n    A = bai * ls[i][1]\nprint(T+A)", "passed": true, "time": 0.14, "memory": 14116.0, "status": "done"}, {"code": "def cin():\n\treturn list(map(int,input().split()))\n\ndef cino(test=False):\n    if not test:\n        return int(input())\n    else:\n        return input()\ndef cina():\n  return list(map(int,input().split()))\n\na = cino()\nx,y = 1,1\nfor _ in range(a):\n    p,q = cin()\n    k = max((x+p-1)//p,(y+q-1)//q)\n    x,y = k*p,k*q\nprint((x+y))\n    \n", "passed": true, "time": 0.14, "memory": 14204.0, "status": "done"}, {"code": "n = int(input())\nary = list(map(int, input().split()))\nfor i in range(n - 1):\n  tmp_ary = list(map(int, input().split()))\n  t_rate = (ary[0] - 1) // tmp_ary[0] + 1\n  a_rate = (ary[1] - 1) // tmp_ary[1] + 1\n  rate = max([t_rate, a_rate])\n  ary = list(map(lambda x: x * rate, tmp_ary))\nprint(int(ary[0] + ary[1]))", "passed": true, "time": 0.2, "memory": 14116.0, "status": "done"}, {"code": "N=int(input())\ntakahashi=1\naoki=1\nfor i in range(N):\n  T,A=list(map(int,input().split()))\n  n=max((takahashi+T-1)//T,(aoki+A-1)//A)\n  takahashi=n*T\n  aoki=n*A\nprint((takahashi+aoki))\n", "passed": true, "time": 0.14, "memory": 14248.0, "status": "done"}, {"code": "import sys\nreadline = sys.stdin.readline\n\ndef ceil(a, b):\n    return -(-a//b)\n\ndef main():\n    N = int(readline())\n    inp = [tuple(map(int, readline().rstrip().split())) for _ in range(N)]\n    scr_t, scr_a = 1, 1\n    for t, a in inp:\n        n = max(ceil(scr_t, t), ceil(scr_a, a))\n        scr_t = n * t\n        scr_a = n * a\n\n    print(scr_t + scr_a)\n\ndef __starting_point():\n    main()\n__starting_point()", "passed": true, "time": 0.14, "memory": 14128.0, "status": "done"}, {"code": "N=int(input())\n\nvt=va=1\nfor _ in range(N):\n  T,A=map(int,input().split())\n  kt=-(-vt//T)\n  ka=-(-va//A)\n  \n  k=max(kt,ka)\n  vt=k*T\n  va=k*A  \n  #print(vt,va)\n  \nprint(vt+va)", "passed": true, "time": 0.13, "memory": 14236.0, "status": "done"}, {"code": "N = int(input())\nQ = [tuple(map(int, input().split())) for _ in range(N)]\nvote = Q[0]  # \u521d\u671f\u5024\u306f\u305d\u306e\u307e\u307e\u5f97\u7968(\u4e92\u3044\u306b\u7d20)\n\nfor p, q in Q[1:]:\n    if p == q:\n        g = max(vote)\n        vote = (g, g)\n    # p\u57fa\u6e96: \u73fe\u5728\u306e\u5f97\u7968\u4ee5\u4e0a\u306e\u6700\u5c0f\u306ep\u306e\u500d\u6570\n    p_v0 = ((vote[0] + p - 1) // p) * p\n    p_v1 = q * p_v0 // p\n    # q\u57fa\u6e96\n    q_v1 = ((vote[1] + q - 1) // q) * q\n    q_v0 = p * q_v1 // q\n    # \u6e1b\u3063\u3066\u3044\u305f\u3089\u9664\u5916\n    if p_v1 < vote[1]:\n        vote = (q_v0, q_v1)\n    elif q_v0 < vote[0]:\n        vote = (p_v0, p_v1)\n    else:\n        # \u3069\u3063\u3061\u3082\u3042\u308a\u3048\u308b\u306a\u3089\u5c0f\u3055\u3044\u307b\u3046\n        if p_v0 + p_v1 <= q_v0 + q_v1:\n            vote = (p_v0, p_v1)\n        else:\n            vote = (q_v0, q_v1)\n\nans = sum(vote)\nprint(ans)", "passed": true, "time": 0.14, "memory": 14256.0, "status": "done"}, {"code": "N = int(input())\na, b = 1, 1\nfor i in range(N):\n    x, y = map(int, input().split())\n    n = max((a + x - 1) // x, (b + y - 1) // y)\n    a = n * x\n    b = n * y\nprint(a + b)", "passed": true, "time": 0.14, "memory": 14168.0, "status": "done"}, {"code": "n = int(input())\nt,a = 1,1\nimport math\nfor _ in range(n):\n    T,A = map(int,input().split())\n    k=(T+t-1)//T\n    m=(A+a-1)//A\n    x=max(k,m)\n    t,a = x*T,x*A\nprint(t+a)", "passed": true, "time": 0.22, "memory": 14296.0, "status": "done"}, {"code": "def ceil(x, y):\n    # ceil(x / y)\n    return (x + y - 1) // y\n\n\ndef main():\n    n = int(input())\n    takahashi = 1\n    aoki = 1\n    for _ in range(n):\n        t, a = list(map(int, input().split()))\n        diff = max(ceil(takahashi, t), ceil(aoki, a))\n        takahashi = t * diff\n        aoki = a * diff\n    print((takahashi + aoki))\n\n\ndef __starting_point():\n    main()\n\n__starting_point()", "passed": true, "time": 0.29, "memory": 14068.0, "status": "done"}, {"code": "from decimal import Decimal,getcontext\nfrom math import ceil\n\nN = int(input())\n\ntakahashi,aoki = 1,1\n\nfor _ in range(N):\n    a,b = map(int,input().split())\n    c = max(ceil(takahashi/Decimal(a)),ceil(aoki/Decimal(b)))\n    takahashi = c*a\n    aoki = c*b\n\nprint(takahashi+aoki)", "passed": true, "time": 0.92, "memory": 14248.0, "status": "done"}, {"code": "n = int(input())\nquery = [tuple(map(int, input().split())) for _ in range(n)]\n\nx, y = 1, 1\nfor t, a in query:\n    if t >= x and a >= y:\n        x = t\n        y = a\n    else:\n        if t < x and a < y:\n            x = t * max((x + t - 1) // t, (y + a - 1) // a)\n            y = a * max((x + t - 1) // t, (y + a - 1) // a)\n        elif t < x:\n            x = t * ((x + t - 1) // t)\n            y = a * ((x + t - 1) // t)\n        else:\n            x = t * ((y + a - 1) // a)\n            y = a * ((y + a - 1) // a)\nprint(x + y)", "passed": true, "time": 0.23, "memory": 14248.0, "status": "done"}, {"code": "N=int(input())\nt=a=1\nfor i in range(N):\n    T,A=list(map(int,input().split()))\n    num=max(-(-t//T),-(-a//A))\n    t,a=num*T,num*A\nprint((t+a))\n", "passed": true, "time": 0.14, "memory": 14200.0, "status": "done"}, {"code": "N = int(input())\nballots = [list(map(int,input().split())) for _ in range(N)]\n\ndef eceil(x, y):\n    return (x+y-1)//y\nprev = ballots[0]\n\nfor i in range(1,N):\n    m,n = ballots[i]\n    k = max(eceil(prev[0],m),eceil(prev[1],n))\n    tot = k * (m+n)\n    prev[0] = tot*m//(m+n)\n    prev[1] = tot*n//(m+n)\n    #print(m,n,k,tot,prev)\nprint((sum(prev)))\n", "passed": true, "time": 0.2, "memory": 14204.0, "status": "done"}, {"code": "def gcd(x,y):\n    if y==0:\n        return x\n    else:\n        return gcd(y,x%y)\ndef lcm(x,y):\n    return x*y//gcd(x,y)\nN=int(input())\nx,y=0,0\nfor i in range(N):\n  p=0\n  T,A=map(int,input().split())\n  if i==0:\n    x,y=T,A\n    continue\n  if x<=T and y<=A:\n    x,y=T,A\n  elif x<=T and A<y:\n    if y%A!=0:\n      p=1\n    x=T*(y//A+p)\n    y=A*(y//A+p)\n  elif T<x and y<=T:\n    if x%T!=0:\n      p=1\n    y=A*(x//T+p)\n    x=T*(x//T+p)\n  else:\n    if (x//T+1)<=(y//A+1):\n      if y%A!=0:\n        p=1\n      x=T*(y//A+p)\n      y=A*(y//A+p)\n    else:\n      if x%T!=0:\n        p=1\n      y=A*(x//T+p)\n      x=T*(x//T+p)\nprint(x+y)", "passed": true, "time": 0.56, "memory": 14164.0, "status": "done"}, {"code": "N = int(input())\nT = 1\nA = 1\nfor i in range(N):\n    Tk = [0,0]\n    Ak = [0,0]\n    Tn,An = map(int,input().rstrip().split(\" \"))\n    if T % Tn == 0:\n        Tk[0] = T\n    else:\n        Tk[0] = (T // Tn + 1) * Tn\n    Ak[0] = (Tk[0] // Tn) * An\n    if Ak[0] < A:\n        Ak[0] = 10 ** 18 + 1\n\n    if A % An == 0:\n        Ak[1] = A\n    else:\n        Ak[1] = (A // An + 1) * An\n    Tk[1] = (Ak[1] // An) * Tn\n    if Tk[1] < T:\n        Tk[1] = 10 ** 18 + 1\n    \n    if Tk[0] + Ak[0] <= Tk[1] + Ak[1]:\n        T = Tk[0]\n        A = Ak[0]\n    else:\n        T = Tk[1]\n        A = Ak[1]\nprint(A + T)", "passed": true, "time": 0.22, "memory": 14328.0, "status": "done"}, {"code": "n = int(input())\nt, a = map(int, input().split())\nfor _ in range(n - 1):\n    x, y = map(int, input().split())\n    s = max((t + x - 1) // x, (a + y - 1) // y)\n    t, a = s * x, s * y\nprint(t + a)", "passed": true, "time": 0.29, "memory": 14088.0, "status": "done"}, {"code": "import math\nfrom fractions import Fraction\n\nN = int(input())\na, b = map(int, input().split())\nret_a = a\nret_b = b\nfor _ in range(1, N):\n    a, b = map(int, input().split())\n    x = math.ceil(max(Fraction(ret_a, a), Fraction(ret_b, b)))\n    ret_a = a * x\n    ret_b = b * x\nprint(ret_a + ret_b)", "passed": true, "time": 0.3, "memory": 14036.0, "status": "done"}, {"code": "n = int(input())\nca, cb = 0, 0\nfor i in range(n):\n    a, b = list(map(int,input().split()))\n    x, y = 1, 1\n    if ca > a:\n        x = ca // a\n        if ca % a:\n            x += 1\n    if cb > b:\n        y = cb // b\n        if cb % b:\n            y += 1\n    x = max(x, y)\n    ca = a * x\n    cb = b * x\nprint((ca + cb))\n", "passed": true, "time": 0.29, "memory": 14236.0, "status": "done"}, {"code": "#\n# abc046 c\n#\n\nimport sys\nfrom io import StringIO\nimport unittest\n\n\nclass TestClass(unittest.TestCase):\n    def assertIO(self, input, output):\n        stdout, stdin = sys.stdout, sys.stdin\n        sys.stdout, sys.stdin = StringIO(), StringIO(input)\n        resolve()\n        sys.stdout.seek(0)\n        out = sys.stdout.read()[:-1]\n        sys.stdout, sys.stdin = stdout, stdin\n        self.assertEqual(out, output)\n\n    def test_\u5165\u529b\u4f8b_1(self):\n        input = \"\"\"3\n2 3\n1 1\n3 2\"\"\"\n        output = \"\"\"10\"\"\"\n        self.assertIO(input, output)\n\n    def test_\u5165\u529b\u4f8b_2(self):\n        input = \"\"\"4\n1 1\n1 1\n1 5\n1 100\"\"\"\n        output = \"\"\"101\"\"\"\n        self.assertIO(input, output)\n\n    def test_\u5165\u529b\u4f8b_3(self):\n        input = \"\"\"5\n3 10\n48 17\n31 199\n231 23\n3 2\"\"\"\n        output = \"\"\"6930\"\"\"\n        self.assertIO(input, output)\n\n\ndef resolve():\n    N = int(input())\n    R = [list(map(int, input().split())) for _ in range(N)]\n\n    t = R[0][0]\n    a = R[0][1]\n    for i in range(1, N):\n        n = max((t+R[i][0]-1)//R[i][0], (a+R[i][1]-1)//R[i][1])\n        t = n*R[i][0]\n        a = n*R[i][1]\n\n    print((t+a))\n\n\ndef __starting_point():\n    # unittest.main()\n    resolve()\n\n__starting_point()", "passed": true, "time": 0.22, "memory": 14340.0, "status": "done"}, {"code": "import sys\n\nread = sys.stdin.read\nreadline = sys.stdin.readline\nreadlines = sys.stdin.readlines\nsys.setrecursionlimit(10 ** 9)\nINF = 1 << 60\nMOD = 1000000007\n\n\ndef main():\n    N, *TA = list(map(int, read().split()))\n\n    x, y = 1, 1\n\n    for t, a in zip(*[iter(TA)] * 2):\n        m1 = (x + t - 1) // t\n        m2 = (y + a - 1) // a\n        m = max(m1, m2)\n        x, y = t * m, a * m\n\n    print((x + y))\n    return\n\n\ndef __starting_point():\n    main()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14108.0, "status": "done"}, {"code": "import sys\nimport heapq, math\nfrom itertools import zip_longest, permutations, combinations, combinations_with_replacement\nfrom itertools import accumulate, dropwhile, takewhile, groupby\nfrom functools import lru_cache\nfrom copy import deepcopy\n\nN = int(input())\n\nA, B = 1, 1\n\nfor i in range(N):\n    XA, XB = map(int, input().split())\n\n    if A * XB > XA * B:\n        d = (A + XA - 1) // XA\n        A, B = d * XA, d * XB\n    else:\n        d = (B + XB - 1) // XB\n        A, B = d * XA, d * XB\n\nprint(A + B)", "passed": true, "time": 0.14, "memory": 14212.0, "status": "done"}, {"code": "n=int(input())\nta=[list(map(int,input().split())) for _ in range(n)]\ntv,av=1,1\n#print('-----')\nfor t,a in ta:\n  i=(t+tv-1)//t\n  j=(a+av-1)//a\n  k=max(i,j)\n  tv=t*k\n  av=a*k\nprint(tv+av)", "passed": true, "time": 0.14, "memory": 14088.0, "status": "done"}, {"code": "n = int(input())\n\np = 1\nq = 1\nfor i in range(n):\n  t, a = map(int, input().split())\n  f = max((p + t - 1) // t, (q + a - 1) // a)\n  p = t * f\n  q = a * f\n  \nprint(p+q)", "passed": true, "time": 0.14, "memory": 14240.0, "status": "done"}, {"code": "n=int(input())\na=b=1\nfor i in range(n):\n  x,y=map(int,input().split())\n  m=max(int((a-1)//x)+1,int((b-1)//y)+1)\n  a=m*x\n  b=m*y\nprint(a+b)", "passed": true, "time": 0.14, "memory": 14096.0, "status": "done"}, {"code": "N = int(input())\n\nT, A = map(int, input().split())\n\nfor i in range(N-1):\n  t, a = map(int, input().split())\n  da = (a - A%a)%a\n  dt = (A + da)*t//a - T\n  if dt >= 0:\n    A += da\n    T += dt\n  else:\n    i = -(dt // t)\n    da += i*a\n    dt += i*t\n    A += da\n    T += dt\n\nprint(T + A)", "passed": true, "time": 0.14, "memory": 14212.0, "status": "done"}, {"code": "n = int(input())\ntvote = 1\navote = 1\n\nfor i in range(n):\n\tt, a = [int(n) for n in input().split()]\n\tk = (tvote-1)//t + 1\n\ttnow = t * k\n\tanow = a * k\n\tif avote > anow:\n\t\tk = (avote-1)//a + 1\n\t\ttnow = t * k\n\t\tanow = a * k\n\ttvote = tnow\n\tavote = anow\n\t\nprint(avote+tvote)", "passed": true, "time": 0.14, "memory": 14272.0, "status": "done"}, {"code": "n=int(input())\np,q=1,1\n\nfor _ in range(n):\n    t,a=map(int,input().split())\n    #n=1\n    #hile p>n*t or q>n*a:\n    #    n+=1\n    n=max((p+t-1)//t,(q+a-1)//a)\n    p,q=n*t,n*a\n    #print(n,p,q)\n\nprint(p+q)", "passed": true, "time": 0.24, "memory": 14248.0, "status": "done"}, {"code": "import sys, re\nfrom collections import deque, defaultdict, Counter\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians\nfrom itertools import permutations, combinations, product\nfrom operator import itemgetter, mul\nfrom copy import deepcopy\nfrom string import ascii_lowercase, ascii_uppercase, digits\n\ndef input(): return sys.stdin.readline().strip()\ndef INT(): return int(input())\ndef MAP(): return list(map(int, input().split()))\ndef LIST(): return list(map(int, input().split()))\nsys.setrecursionlimit(10 ** 9)\nINF = float('inf')\nMOD = 10 ** 9 + 7\n\nN = INT()\nTA = [LIST() for _ in range(N)]\nvote_T = 1\nvote_A = 1\nfor x, y in TA:\n\tn = max(-(-vote_T // x), -(-vote_A // y))\n\tvote_T = x * n\n\tvote_A = y * n\nprint((vote_A + vote_T))\n", "passed": true, "time": 0.25, "memory": 14312.0, "status": "done"}, {"code": "N=int(input())\nt=a=1\nfor i in range(N):\n    T,A=list(map(int,input().split()))\n    num=max(-(-t//T),-(-a//A))\n    t,a=num*T,num*A\n\nprint((t + a))\n", "passed": true, "time": 0.14, "memory": 14036.0, "status": "done"}, {"code": "from sys  import stdin,stdout\n\nimport bisect\n\nimport math\n\ndef st():\n    return list(stdin.readline().strip())\n\ndef inp():\n    return int(stdin.readline())\n\ndef li():\n    return list(map(int,stdin.readline().split()))\n\ndef mp():\n    return list(map(int,stdin.readline().split()))\n\ndef pr(n):\n    stdout.write(str(n)+\"\\n\")\n\ndef soe(limit):\n    l=[1]*(limit+1)\n    prime=[]\n    for i in range(2,limit+1):\n        if l[i]:\n            for j in range(i*i,limit+1,i):\n                l[j]=0\n\n    for i in range(2,limit+1):\n        if l[i]:\n            prime.append(i)\n    return prime\n\ndef segsoe(low,high):\n    limit=int(high**0.5)+1\n    prime=soe(limit)\n    n=high-low+1\n    l=[0]*(n+1)\n    for i in range(len(prime)):\n        lowlimit=(low//prime[i])*prime[i]\n        if lowlimit<low:\n            lowlimit+=prime[i]\n        if lowlimit==prime[i]:\n            lowlimit+=prime[i]\n        for j in range(lowlimit,high+1,prime[i]):\n            l[j-low]=1\n    for i in range(low,high+1):\n        if not l[i-low]:\n            if i!=1:\n                print(i)\n                \ndef gcd(a,b):\n    while b:\n        a,b=b,a%b\n    return a\n\ndef power(a,n):\n    r=1\n    while n:\n        if n&1:\n            r=(r*a)\n        a*=a\n        n=n>>1\n    return r\n\n    \ndef solve():\n    n=inp()\n    a,b=1,1\n    for _ in range(n):\n        x,y=mp()\n        d=max((x+a-1)//x,(y+b-1)//y)\n        a=d*x\n        b=d*y\n    pr(a+b)\nfor _ in range(1):\n    solve()\n    \n", "passed": true, "time": 0.14, "memory": 14480.0, "status": "done"}, {"code": "N=int(input())\nt=a=1\nfor i in range(N):\n    T,A=list(map(int,input().split()))\n    num=max(-(-t//T),-(-a//A))\n    t,a=num*T,num*A\n\nprint((t + a))\n", "passed": true, "time": 0.14, "memory": 14164.0, "status": "done"}, {"code": "class Combination:\n    def __init__(self, n, mod):\n        self.n = n\n        self.mod = mod\n        self.fac = [1 for i in range(self.n + 1)]\n        self.finv = [1 for i in range(self.n + 1)]\n        for i in range(2, self.n+1):\n            self.fac[i] = (self.fac[i - 1] * i) % self.mod\n            self.finv[i] = (self.finv[i-1] * pow(i, -1, self.mod)) % self.mod\n\n    def comb(self, n, m):\n        return self.fac[n] * (self.finv[n-m] * self.finv[m] % self.mod) % self.mod\ndef iparse():\n    return list(map(int, input().split()))\n\n\ndef __starting_point():\n    n = int(input())\n    ml = 1\n    last = [0,0]\n    for i in range(n):\n        x = iparse()\n        # print(len(x))\n        l = (last[0] + x[0] - 1) // x[0]\n        r = (last[1] + x[1] - 1) // x[1]\n        m = max(l, r)\n        if m == 0:\n            m = 1\n        x[0] *= m\n        x[1] *= m\n        \n        last = x\n    print((sum(last)))\n    \n        \n    \n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14332.0, "status": "done"}, {"code": "n = int(input())\n\nt0, a0 = 1, 1\n\nfor i in range(n):\n    t1, a1 = map(int, input().split())\n    f0 = t0 // t1\n    if t0 % t1 != 0:f0 += 1\n    f1 = a0 // a1\n    if a0 % a1 != 0:f1 += 1\n    f = max(f0, f1)\n    t0, a0 = t1*f, a1*f\n\nprint(t0 + a0)", "passed": true, "time": 0.22, "memory": 14296.0, "status": "done"}, {"code": "N = int(input())\nx = 1\ny = 1\nfor i in range(N):\n    T, A = list(map(int, input().split()))\n    p = (T + x - 1) // T\n    q = (A + y - 1) // A\n    x = T * max(p, q)\n    y = A * max(p, q)\n    #print(f\"[{x} {y}]\")\nprint((x + y))\n", "passed": true, "time": 0.23, "memory": 14292.0, "status": "done"}, {"code": "n = int(input())\nT, A = map(int, input().split())\n\nfor _ in range(n-1):\n    t, a = map(int, input().split())\n    x = max(-(-T//t), -(-A//a))\n    T = x * t; A = x * a\nprint(T+A)", "passed": true, "time": 0.14, "memory": 14216.0, "status": "done"}, {"code": "n = int(input())\na,b = map(int,input().split())\n\nfor i in range(n-1):\n    c,d = map(int,input().split())\n    x = -min((-a)//c,(-b)//d)\n    a,b = c*x,d*x\nprint(a + b)", "passed": true, "time": 0.14, "memory": 14044.0, "status": "done"}, {"code": "#!/usr/bin/env python3\nimport math\n\ndef main():\n    N = int(input())\n    T, A = list(map(int, input().split()))\n    for _ in range(N-1):\n        t, a = list(map(int, input().split()))\n        # \u6841\u304c\u5927\u304d\u3044\u3068float\u306e\u8aa4\u5dee\u304c\u751f\u3058\u3066\u6b63\u3057\u304f\u5224\u5b9a\u3067\u304d\u306a\u3044\n        # \u8ca0\u306e\u6570\u306b\u3057\u3066\u5207\u308a\u6368\u3066\u306b\u3059\u308c\u3070ceil\u3068\u540c\u3058\u6319\u52d5\u306b\u306a\u308b\n        x = max(-(-T//t), -(-A//a))\n        T = t*x\n        A = a*x\n    print((T+A))\n\ndef __starting_point():\n    main()\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14224.0, "status": "done"}, {"code": "n = int(input())\nvt, va = 1, 1\nfor i in range(n):\n  t, a = list(map(int, input().split()))\n  d = max((t + vt - 1) // t, (a + va - 1) // a)\n  vt = d * t\n  va = d * a\nprint((vt + va))\n", "passed": true, "time": 0.15, "memory": 14072.0, "status": "done"}, {"code": "n = int(input())\nt = [0]*n\na = [0]*n\nfor i in range(n): t[i],a[i] = map(int,input().split())\ntcnt = t[0]\nacnt = a[0]\nfor i in range(1,n):\n    x = max((tcnt+t[i]-1)//t[i],(acnt+a[i]-1)//a[i])\n    tcnt = t[i]*x\n    acnt = a[i]*x\nprint(tcnt+acnt)", "passed": true, "time": 0.15, "memory": 14068.0, "status": "done"}, {"code": "N = int(input())\nt, a = list(map(int, input().split(' ')))\n\nfor _ in range(N - 1):\n    nt, na = list(map(int, input().split(' ')))\n    if nt >= t and na >= a:\n        t = nt\n        a = na\n    else:\n        tr = (t + nt - 1) // nt\n        ar = (a + na - 1) // na\n        r = max(tr, ar)\n        t = r * nt\n        a = r * na\n\nprint((t + a))\n", "passed": true, "time": 0.14, "memory": 14352.0, "status": "done"}, {"code": "n = int(input())\nca, cb = 0, 0\nfor i in range(n):\n    a, b = list(map(int,input().split()))\n    x, y = 1, 1\n    if ca > a:\n        x = ca // a\n        if ca % a:\n            x += 1\n    if cb > b:\n        y = cb // b\n        if cb % b:\n            y += 1\n    x = max(x, y)\n    ca = a * x\n    cb = b * x\nprint((ca + cb))\n", "passed": true, "time": 0.14, "memory": 14340.0, "status": "done"}, {"code": "def nextpt(ratio1, ratio2, pt):\n  if ratio1[0]*ratio2[1]-ratio1[1]*ratio2[0]>0:\n    pt[0]=pt[0]+((-1)*pt[0])%ratio2[0]\n    pt[1]=pt[0]*ratio2[1]//ratio2[0]\n  else:\n    pt[1]=pt[1]+((-1)*pt[1])%ratio2[1]\n    pt[0]=pt[1]*ratio2[0]//ratio2[1]\n  return pt\n\nn=int(input())\nratios = [list(map(int,input().split())) for _ in range(n)]\n\npt=ratios[0]\nfor i in range(n-1):\n  pt=nextpt(ratios[i], ratios[i+1], pt)\n\nprint(sum(pt))", "passed": true, "time": 0.14, "memory": 14136.0, "status": "done"}, {"code": "from sys import stdin\nimport math\nN = int(stdin.readline().rstrip())\nt,a = 1,1\n \nfor _ in range(N):\n    T,A = [int(x) for x in stdin.readline().rstrip().split()]\n    n = max((t + T - 1) // T,(a + A - 1) // A)\n    t = n*T\n    a = n*A\n    \nprint(t+a)", "passed": true, "time": 0.23, "memory": 14296.0, "status": "done"}, {"code": "from decimal import Decimal,getcontext\nfrom math import ceil\ngetcontext().prec = 1000\nN = int(input())\n \ntakahashi,aoki = 1,1\n \nfor _ in range(N):\n    a,b = map(int,input().split())\n    c = max(ceil(Decimal(str(takahashi))/Decimal(a)),ceil(Decimal(str(aoki))/Decimal(b)))\n    takahashi = c*a\n    aoki = c*b\n \nprint(takahashi+aoki)", "passed": true, "time": 0.15, "memory": 14108.0, "status": "done"}, {"code": "n = int(input())\nary = list(map(int, input().split()))\nfor i in range(n - 1):\n  tmp_ary = list(map(int, input().split()))\n  # \u6841\u304c\u5927\u304d\u3044\u3068ceil, floor\u3067\u306f\u6b63\u3057\u304f\u5224\u5b9a\u304c\u3067\u304d\u306a\u3044\n  t_rate = (ary[0] - 1) // tmp_ary[0] + 1\n  a_rate = (ary[1] - 1) // tmp_ary[1] + 1\n  rate = max([t_rate, a_rate])\n  ary = list(map(lambda x: x * rate, tmp_ary))\nprint(int(ary[0] + ary[1]))", "passed": true, "time": 0.15, "memory": 14152.0, "status": "done"}, {"code": "import math\n\nn=int(input())\nans=list(map(int,input().split()))\nif n==1:\n  print((sum(ans)))\n  \nelse:\n  ans1=[]\n  ans1.append(ans)\n  for i in range(n-1):\n    x,y=list(map(int,input().split()))\n    p,q=ans1[-1][0],ans1[-1][1]\n    if p%x==0:\n      p1=p//x\n    else:\n      p1=p//x+1\n    if q%y==0:\n      q1=q//y\n    else:\n      q1=q//y+1\n    pq=max(p1,q1)\n    r=[x*pq,y*pq]\n    ans1.append(r)\n    \n  print((sum(ans1[-1])))\n    \n", "passed": true, "time": 0.15, "memory": 14168.0, "status": "done"}, {"code": "def main():\n    N = int(input())\n    TA = [list(map(int, input().split(' '))) for _ in range(N)]\n    if N == 1:\n        print(sum(TA[0]))\n        return\n    cur_t, cur_a = TA[0]\n    for t, a in TA[1:]:\n        ratio = max([(cur_t + t - 1) // t, (cur_a + a - 1) // a])\n        cur_t, cur_a = ratio * t, ratio * a\n    print(cur_t + cur_a)\n\n\ndef __starting_point():\n    main()\n__starting_point()", "passed": true, "time": 0.15, "memory": 14116.0, "status": "done"}, {"code": "def main():\n    N = int(input())\n    T1, A1 = map(int, input().split())\n    for _ in range(N-1):\n        T2, A2 = map(int, input().split())\n        n = max(-(-T1//T2),-(-A1//A2))\n        T1,A1 = T2*n,A2*n\n    print(T1 + A1)\n\n\ndef __starting_point():\n    main()\n__starting_point()", "passed": true, "time": 0.15, "memory": 14064.0, "status": "done"}, {"code": "def main():\n    from math import ceil\n    n = int(input())\n    a, b = 1, 1\n    for _ in range(n):\n        i, j = list(map(int, input().split()))\n        x = max((a + i - 1) // i, (b + j - 1) // j)\n        a, b = x * i, x * j\n    print((a + b))\n\n\ndef __starting_point():\n    main()\n\n__starting_point()", "passed": true, "time": 0.28, "memory": 14176.0, "status": "done"}, {"code": "from sys import stdin\nimport math\nN = int(stdin.readline().rstrip())\nt,a = [int(x) for x in stdin.readline().rstrip().split()]\n \nfor _ in range(N-1):\n    T,A = [int(x) for x in stdin.readline().rstrip().split()]\n    n = max((t + T - 1) // T,(a + A - 1) // A)\n    t = n*T\n    a = n*A\n    \nprint(t+a)", "passed": true, "time": 0.14, "memory": 14056.0, "status": "done"}, {"code": "n = int(input())\n\nra,rb = 1,1\nfor i in range(n):\n  a,b = map(int,input().split())\n  n = max((ra+a-1)//a,(rb+b-1)//b)\n  ra = a*n\n  rb = b*n\n    \nprint(ra+rb)", "passed": true, "time": 0.16, "memory": 14328.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\nimport sys\n# import time\nimport math\n# import numpy as np\n# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall\n# import random                                # random, uniform, randint, randrange, shuffle, sample\n# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits\n# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)\n# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).\n# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()\n# from collections import defaultdict          # subclass of dict. defaultdict(facroty)\n# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)\n# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj\n# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj\n# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.\n# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference\n# from functools import reduce                 # reduce(f, iter[, init])\n# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)\n# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).\n# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).\n# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])\n# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]\n# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]\n# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])\n# from itertools import combinations, combinations_with_replacement\n# from itertools import accumulate             # accumulate(iter[, f])\n# from operator import itemgetter              # itemgetter(1), itemgetter('key')\n# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)\n\n\n\ndef main():\n    mod = 1000000007                # 10^9+7\n    inf = float('inf')              # sys.float_info.max = 1.79...e+308\n    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19\n    sys.setrecursionlimit(10**6)    # 1000 -> 1000000\n    def input(): return sys.stdin.readline().rstrip()\n    def ii():    return int(input())\n    def mi():    return list(map(int, input().split()))\n    def mi_0():  return [int(x)-1 for x in input().split()]\n    def lmi():   return list(map(int, input().split()))\n    def lmi_0(): return list([int(x)-1 for x in input().split()])\n    def li():    return list(input())\n\n    def calc_minimum_card_pair(a, b, s, t):\n        \"\"\"\n        \u73fe\u5728 a, b \u679a\u3067\u3042\u308b\u3068\u3059\u308b\n        \u30ab\u30fc\u30c9\u3092\u5897\u3084\u3059\u64cd\u4f5c\u3092\u884c\u3044\u6bd4\u3092 s : t \u306b\u3059\u308b\u3068\u304d\u3001\u5909\u5316\u5f8c\u306e\u30ab\u30fc\u30c9\u679a\u6570\u3092\u8fd4\u3059\n        \"\"\"\n        # multiply_rate = max(math.ceil(a / s), math.ceil(b / t))\n        multiply_rate = max((a + s - 1) // s, (b + t - 1) // t)\n        return (s * multiply_rate, t * multiply_rate)\n    \n    \n    n = ii()\n    L = [lmi() for _ in range(n)]\n    a, b = 1, 1\n    for s, t in L:\n        a, b = calc_minimum_card_pair(a, b, s, t)\n        # print(a, b)\n    \n    # print('')\n    print((a + b))\n\n\ndef __starting_point():\n    main()\n\n__starting_point()", "passed": true, "time": 0.23, "memory": 14284.0, "status": "done"}, {"code": "import fractions\nN=int(input())\n\nvt=va=0\nfor _ in range(N):\n  T,A=map(int,input().split())\n  kt=-(-vt//T)\n  ka=-(-va//A)\n  if kt==0 and ka==0:\n    vt=T\n    va=A\n  else:\n    k=max(kt,ka)\n    vt=k*T\n    va=k*A\n  \n  #print(vt,va)\n  \nprint(vt+va)", "passed": true, "time": 0.25, "memory": 14092.0, "status": "done"}, {"code": "n = int(input())\nA, B = 0, 0\nfor i in range(n):\n    x, y = map(int,input().split())\n    dx, dy = 1, 1\n    if A > x:\n        dx = A // x\n        if A % x != 0:\n            dx += 1\n    \n    if B > y:\n        dy = B // y\n        if B % y != 0:\n            dy += 1\n \n    a = max(dx, dy)\n    A, B = a * x, a * y\nprint(A + B)", "passed": true, "time": 0.15, "memory": 14276.0, "status": "done"}, {"code": "n = int(input())\nt_i,a_i = map(int,input().split())\nt = []\na = []\nt.append(t_i)\na.append(a_i)\nfor i in range(1,n):\n    t_i,a_i = map(int,input().split())\n    t.append(t_i)\n    a.append(a_i)\n    if t[i-1]>t[i] or a[i-1]>a[i]:\n        t_max = t[i-1]//t[i]\n        if t[i-1]%t[i]!=0:\n            t_max += 1\n        a_max = a[i-1]//a[i]\n        if a[i-1]%a[i]!=0:\n            a_max += 1\n        bai = max(t_max,a_max)\n        t[i] *= bai\n        a[i] *= bai\nprint(t[-1]+a[-1])", "passed": true, "time": 0.24, "memory": 14308.0, "status": "done"}, {"code": "import math\n\nn = int(input())\nta = [list(map(int, input().split())) for _ in range(n)]\n\nx, y = ta[0]\nfor i in range(1, n):\n    t, a = ta[i]\n    k = max(-(-x // t), -(-y // a))\n    x, y = k * t, k * a\n\nprint((x + y))\n", "passed": true, "time": 0.23, "memory": 14256.0, "status": "done"}, {"code": "from math import gcd\n\nn = int(input())\nfor i in range(n):\n    a, b = list(map(int, input().split()))\n    if i == 0:\n        pre_a, pre_b = a, b\n    if pre_a * b < pre_b * a:\n        mul = (pre_b + b - 1) // b\n        pre_b = mul * b\n        pre_a = pre_b * a // b\n    else:\n        mul = (pre_a + a - 1) // a\n        pre_a = mul * a\n        pre_b = pre_a * b // a\n    # print(i, pre_a, pre_b)\nprint((pre_a + pre_b))\n", "passed": true, "time": 0.19, "memory": 14084.0, "status": "done"}, {"code": "N=int(input())\nx,y=0,0\nfor i in range(N):\n  p=0\n  T,A=map(int,input().split())\n  if i==0:\n    x,y=T,A\n    continue\n  if x<=T and y<=A:\n    x,y=T,A\n  elif x<=T and A<y:\n    if y%A!=0:\n      p=1\n    x=T*(y//A+p)\n    y=A*(y//A+p)\n  elif T<x and y<=T:\n    if x%T!=0:\n      p=1\n    y=A*(x//T+p)\n    x=T*(x//T+p)\n  else:\n    if (x//T+1)<=(y//A+1):\n      if y%A!=0:\n        p=1\n      x=T*(y//A+p)\n      y=A*(y//A+p)\n    else:\n      if x%T!=0:\n        p=1\n      y=A*(x//T+p)\n      x=T*(x//T+p)\nprint(x+y)", "passed": true, "time": 0.22, "memory": 14144.0, "status": "done"}, {"code": "n=int(input())\nanst,ansa=map(int,input().split())\nfor _ in range(1,n):\n    t,a=map(int,input().split())\n    if anst>t or ansa>a:\n        mul=max(-(-anst//t),-(-ansa//a))\n        anst=mul*t\n        ansa=mul*a\n    else:\n        anst=t\n        ansa=a\nprint(anst+ansa)", "passed": true, "time": 0.14, "memory": 14280.0, "status": "done"}, {"code": "N=int(input())\nA,B=1,1\nfor i in range(N):\n   tmpl=list(map(int,input().split()))\n   tmp=max(-1*(-1*A//tmpl[0]),-1*(-1*B//tmpl[1]))\n   A,B=tmpl[0]*tmp,tmpl[1]*tmp\nprint(A+B)", "passed": true, "time": 0.14, "memory": 14284.0, "status": "done"}, {"code": "from decimal import Decimal,getcontext\nfrom math import ceil\ngetcontext().prec = 1000\nN = int(input())\n\ntakahashi,aoki = 1,1\n\nfor _ in range(N):\n    a,b = map(int,input().split())\n    c = max(ceil(Decimal(takahashi)/Decimal(a)),ceil(Decimal(aoki)/Decimal(b)))\n    takahashi = c*a\n    aoki = c*b\n\nprint(takahashi+aoki)", "passed": true, "time": 0.14, "memory": 14128.0, "status": "done"}, {"code": "n = int(input())\n\nt1, a1 = list(map(int,input().split()))\n\nfor i in range(n-1):\n    t,a = list(map(int,input().split()))\n    if t1 * a == t * a1:\n        pass\n    elif t1 * a < t * a1:\n        a1 = -(-a1 // a) * a\n        t1 = a1 // a * t\n    else:\n        t1 = -(-t1 // t) * t\n        a1 = t1 // t * a\n\nprint((a1+t1))\n", "passed": true, "time": 0.14, "memory": 14292.0, "status": "done"}, {"code": "N=int(input())\n\nvt=va=0\nfor _ in range(N):\n  T,A=map(int,input().split())\n  kt=-(-vt//T)\n  ka=-(-va//A)\n  \n  k=max(kt,ka,1)\n  vt=k*T\n  va=k*A  \n  #print(vt,va)\n  \nprint(vt+va)", "passed": true, "time": 0.14, "memory": 14076.0, "status": "done"}, {"code": "N = int(input())\nT, A = 1, 1\nfor _ in range(N):\n    t, a = map(int,input().split())\n    k = max((T - 1) // t + 1, (A - 1) // a + 1)\n    T = t * k\n    A = a * k\nprint(A + T)", "passed": true, "time": 0.14, "memory": 14340.0, "status": "done"}, {"code": "n = int(input())\nt_v = a_v = 1\nfor _ in range(n):\n    t, a = [int(x) for x in input().split()]\n    r = max((t_v + t - 1) // t, (a_v + a - 1) // a)\n    t_v, a_v = r * t, r * a\nprint(t_v + a_v)", "passed": true, "time": 0.14, "memory": 14280.0, "status": "done"}, {"code": "N = int(input())\n\ntakahashi,aoki = 1,1\n\nfor _ in range(N):\n    a,b = map(int,input().split())\n    c = max((takahashi-1)//a+1,(aoki-1)//b+1)\n    takahashi = c*a\n    aoki = c*b\n\nprint(takahashi+aoki)", "passed": true, "time": 0.14, "memory": 14264.0, "status": "done"}, {"code": "n=int(input())\nans_t=1\nans_a=1\nfor i in range(n):\n    t,a=map(int,input().split())\n    if t==1:\n        k1=ans_t\n    else:\n    \tk1=(ans_t-1)//t+1\n    if a==1:\n        k2=ans_a\n    else:\n    \tk2=(ans_a-1)//a+1\n    k=max(k1,k2)\n    ans_t=k*t\n    ans_a=k*a\nprint(ans_t+ans_a)", "passed": true, "time": 0.14, "memory": 14240.0, "status": "done"}, {"code": "from sys import stdin\ndef main():\n    #\u5165\u529b\n    readline=stdin.readline\n    n=int(readline())\n    for i in range(n):\n        if i==0:\n            t,a=map(int,readline().split())\n        else:\n            t_i,a_i=map(int,readline().split())\n            tmp1=(t+t_i-1)//t_i\n            tmp2=(a+a_i-1)//a_i\n            x=max(tmp1,tmp2)\n            t=t_i*x\n            a=a_i*x\n    \n    print(a+t)\n\ndef __starting_point():\n    main()\n__starting_point()", "passed": true, "time": 0.14, "memory": 14172.0, "status": "done"}, {"code": "N = int(input())\nT, A = map(int, input().split())\nfor i in range(N-1):\n  t, a = map(int, input().split())\n  p = (T-1)//t + 1\n  q = (A-1)//a + 1\n  n = max(p, q)\n  T = n*t\n  A = n*a\nprint(T+A)", "passed": true, "time": 0.14, "memory": 14076.0, "status": "done"}, {"code": "N = int(input())\nTA = [list(map(int, input().split())) for _ in range(N)]\n\nT, A = 0, 0\nfor t, a in TA:\n    if T == 0 and A == 0:\n        T = t\n        A = a\n        continue\n    if t == a:\n        M = max(T, A)\n        T = M\n        A = M\n    elif t < a:\n        n = max((T // t) * t, (A // a) * t)\n        while n < T or a * (n // t) < A:\n            n += t\n        T = n\n        A = a * (T // t)\n    else:\n        n = max((A // a) * a, (T // t) * a)\n        while n < A or t * (n // a) < T:\n            n += a\n        A = n\n        T = t * (A // a)\nprint(A + T)", "passed": true, "time": 0.14, "memory": 14284.0, "status": "done"}, {"code": "import math\nN = int(input())\nta = [tuple(map(int,input().split())) for _ in range(N)]\nleft = ta[0][0]\nright = ta[0][1]\nres = left+right\nfor t,a in ta[1:]:\n    tmp1 = (left+t-1)//t\n    tmp2 = (right+a-1)//a\n    buff = max(tmp1,tmp2)\n    right = buff*a\n    left = buff*t\nprint((int(right+left)))\n\n\n", "passed": true, "time": 0.14, "memory": 14256.0, "status": "done"}, {"code": "n=int(input())\nx,y=map(int,input().split())\nz=x+y\nfor i in range(n-1):\n  a,b=map(int,input().split())\n  k=max((x-1)//a,(y-1)//b)+1\n  x=k*a\n  y=k*b\nprint(x+y)", "passed": true, "time": 0.21, "memory": 14164.0, "status": "done"}]