Problem: 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.

Submission attempts (in order):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    N = in_n()
    TA = in_nl2(N)

    t_score, a_score = 1, 1
    for i in range(N):

        t, a = TA[i]
        # print(t, a, '------------------')

        if t == a:
            t_score = max(t_score, a_score)
            a_score = t_score
        else:
            t_s = -(-t_score // t) * t
            a_s = (t_s // t) * a
            if t_s >= t_score and a_s >= a_score:
                t_score = t_s
                a_score = a_s
                print(t_score, a_score)
                continue
            # else:
                # print('dame1', t_s, a_s)

            a_s = -(-a_score // a) * a
            t_s = (a_s // a) * t
            if t_s >= t_score and a_s >= a_score:
                t_score = t_s
                a_score = a_s
                print(t_score, a_score)
            # else:
                # print('dame2', t_s, a_s)

                # print(t_score, a_score)

    print(t_score + a_score)


if __name__ == '__main__':
    main()


import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    N = in_n()
    TA = in_nl2(N)

    t_score, a_score = 1, 1
    for i in range(N):

        t, a = TA[i]

        if t == a:
            t_score = max(t_score, a_score)
            a_score = t_score
        else:
            t_s = -(-t_score // t) * t
            a_s = (t_s // t) * a
            if t_s >= t_score and a_s >= a_score:
                t_score = t_s
                a_score = a_s
                continue

            a_s = -(-a_score // a) * a
            t_s = (a_s // a) * t
            if t_s >= t_score and a_s >= a_score:
                t_score = t_s
                a_score = a_s

    print(t_score + a_score)


if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

Accepted