Problem p03061 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import sys,fractions
from functools import reduce
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N = int(lines.pop(0))
    A = list(map(int, lines.pop(0).split(' ')))

    _l = 0
    L = []
    for i in range(N-1):
        _l = fractions.gcd(_l, A[i])
        L.append(_l)
    L.insert(0,0)

    _r = 0
    R = []
    for i in range(N-1):
        _r = fractions.gcd(_r, A[N-i-1])
        R.append(_r)
    R.reverse()
    R.append(0)

    print(max([fractions.gcd(l,r) for l, r in zip(L,R)]))



lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys,math
from functools import reduce
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N = int(lines.pop(0))
    A = list(map(int, lines.pop(0).split(' ')))

    _l = 0
    L = []
    for i in range(N):
        _l = math.gcd(_l, A[i])
        L.append(_l)

    _r = 0
    R = []
    for i in range(N):
        _r = math.gcd(_r, A[N-i-1])
        R.append(_r)

    print(max([math.gcd(l,r) for l, r in zip(L,R)]))



lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys,fractions
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    def dfs(res, flag, depth):
        if depth == N:
            return res
        if flag:
            return dfs(fractions.gcd(res, A[depth]), True, depth + 1)
        else:
            return max( dfs(res, True, depth + 1), dfs(fractions.gcd(res, A[depth]), False, depth + 1))

    N = int(lines.pop(0))
    A = list(map(int, lines.pop(0).split(' ')))
    print(dfs(0, False, 0) )
lines = [x.strip() for x in sys.stdin.readlines()]
solve(lines)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys,fraction
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    def dfs(res, flag, depth):
        if depth == N:
            return res
        if flag:
            return dfs(fraction.gcd(res, A[depth]), True, depth + 1)
        else:
            return max( dfs(res, True, depth + 1), dfs(fraction.gcd(res, A[depth]), False, depth + 1))

    N = int(lines.pop(0))
    A = list(map(int, lines.pop(0).split(' ')))
    print(dfs(0, False, 0) )
lines = [x.strip() for x in sys.stdin.readlines()]
solve(lines)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys,fraction
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    def dfs(res, flag, depth):
        if depth == N:
            return res
        if flag:
            return dfs(fraction.gcd(res, A[depth]), True, depth + 1)
        else:
            return max( dfs(res, True, depth + 1), dfs(fraction.gcd(res, A[depth]), False, depth + 1))

    N = int(lines.pop(0))
    A = list(map(int, lines.pop(0).split(' ')))
    print(dfs(0, False, 0) )
lines = [x.strip() for x in sys.stdin.readlines()]
solve(lines)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys,fraction
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    def dfs(res, flag, depth):
        if depth == N:
            return res
        if flag:
            return dfs(fraction.gcd(res, A[depth]), True, depth + 1)
        else:
            return max( dfs(res, True, depth + 1), dfs(fraction.gcd(res, A[depth]), False, depth + 1))

    N = int(lines.pop(0))
    A = list(map(int, lines.pop(0).split(' ')))
    print(dfs(0, False, 0) )
lines = [x.strip() for x in sys.stdin.readlines()]
solve(lines)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys,math
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    def dfs(res, flag, depth):
        if depth == N:
            return res
        if flag:
            return dfs(math.gcd(res, A[depth]), True, depth + 1)
        else:
            return max( dfs(res, True, depth + 1), dfs(math.gcd(res, A[depth]), False, depth + 1))

    N = int(lines.pop(0))
    A = list(map(int, lines.pop(0).split(' ')))
    print(dfs(0, False, 0) )
lines = [x.strip() for x in sys.stdin.readlines()]
solve(lines)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys,math
from functools import reduce
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    def dfs(res, flag, depth):
        if depth == N:
            return res
        if flag:
            return dfs(math.gcd(res, A[depth]), True, depth + 1)
        else:
            return max( dfs(res, True, depth + 1), dfs(math.gcd(res, A[depth]), False, depth + 1))

    N = int(lines.pop(0))
    A = list(map(int, lines.pop(0).split(' ')))
    print(dfs(0, False, 0) )
lines = [x.strip() for x in sys.stdin.readlines()]
solve(lines)