Problem p03061 (python)

Fixed submission:
import sys

def gcd(x, y, *val):
    val = sorted([x, y], reverse=True) + list(val)
    count = len(val)

    if count == 2:
        if val[1] == 0:
            return val[0]

        mod = val[0] % val[1]
        if mod == 0:
            return val[1]
        elif mod == 1:
            return 1
        else:
            return gcd(val[1], mod)
    else:
        if count % 2 == 1:
            val.append(val[-1])

        return gcd(*[gcd(val[i], val[i + 1]) for i in range(0, count, 2)])
        

def main():
    sinputl = sys.stdin.readline

    num = int(sinputl().strip())
    input = [int(x) for x in sinputl().split()]

    gcd_max = 1
    input_mem = []

    if num == 2:
        print(max(input))
        return

    gcd_left = [0]
    gcd_right = [0]

    for i in range(num - 1):
        gcd_left.append(gcd(input[i], gcd_left[i]))
        gcd_right.append(gcd(input[-1 - i], gcd_right[i]))

    gcd_right.reverse()
    gcd_list = []

    for i in range(num):
        gcd_list.append(gcd(gcd_left[i], gcd_right[i]))

    print(max(gcd_list))



if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys

def gcd(x, y, *val):
    val = [x, y] + list(val)
    val.sort(reverse=True)
    count = len(val)

    if count == 2:
        mod = val[0] % val[1]
        if mod == 0:
            return val[1]
        elif mod == 1:
            return 1
        else:
            return gcd(val[1], mod)
    else:
        if count % 2 == 1:
            val.append(min(val))

        return gcd(*[gcd(val[i], val[i + 1]) for i in range(0, count, 2)])
        

def main():
    sinputl = sys.stdin.readline

    num = int(sinputl().strip())
    input = [int(x) for x in sinputl().split()]

    gcd_max = 1
    input_mem = []

    if num == 2:
        print(max(input))
        return

    for i in range(num):
        mem = input.pop(num - 1 - i)
        gcd_max = max(gcd_max, gcd(*input, *input_mem))
        input_mem.append(mem)

    print(gcd_max)



if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys

def gcd(x, y, *val):
    val = [x, y] + list(val)
    val.sort(reverse=True)

    if len(val) == 2:
        mod = val[0] % val[1]
        if mod == 0:
            return val[1]
        elif mod == 1:
            return 1
        else:
            return gcd(val[1], mod)
    else:
        length = len(val)
        if length % 2 == 1:
            val.append(val[-1])

        return gcd(*[gcd(val[i], val[i + 1]) for i in range(0, length, 2)])
        

def main():
    sinputl = sys.stdin.readline

    num = int(sinputl().strip())
    input = [int(x) for x in sinputl().split()]

    gcd_max = 1
    input_mem = []

    if num == 2:
        print(max(input))
        return

    for i in range(num):
        mem = input.pop(num - 1 - i)
        gcd_max = max(gcd_max, gcd(*input, *input_mem))
        input_mem.append(mem)

    print(gcd_max)



if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys

def gcd(x, y, *val):
    val = [x, y] + list(val)
    val.sort(reverse=True)

    if len(val) == 2:
        mod = val[0] % val[1]
        if mod == 0:
            return val[1]
        elif mod == 1:
            return 1
        else:
            return gcd(val[1], mod)
    else:
        length = len(val)
        if length % 2 == 1:
            val.append(val[-1])

        return gcd(*[gcd(val[i], val[i + 1]) for i in range(0, length, 2)])
        

def main():
    sinputl = sys.stdin.readline

    num = int(sinputl().strip())
    input = [int(x) for x in sinputl().split()]

    gcd_max = 1
    input_mem = []

    for i in range(num):
        mem = input.pop(num - 1 - i)
        gcd_max = max(gcd_max, gcd(*input, *input_mem))
        input_mem.append(mem)

    print(gcd_max)



if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys

def gcd(x, y, *val):
    val = [x, y] + list(val)
    val.sort(reverse=True)

    if len(val) == 2:
        mod = val[0] % val[1]
        if mod == 0:
            return val[1]
        elif mod == 1:
            return 1
        else:
            return gcd(val[1], mod)
    else:
        return gcd(*[gcd(val[i], val[i + 1]) for i in range(0, len(val), 2)], val[-1])
        

def main():
    sinputl = sys.stdin.readline

    num = int(sinputl().strip())
    input = [int(x) for x in sinputl().split()]

    gcd_max = 1
    input_mem = []

    for i in range(num):
        mem = input.pop(num - 1 - i)
        gcd_max = max(gcd_max, gcd(*input, *input_mem))
        input_mem.append(mem)

    print(gcd_max)



if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys

def gcd(x, y, *val):
    val = [x, y] + list(val)
    val.sort(reverse=True)

    if len(val) == 2:
        mod = val[0] % val[1]
        if mod == 0:
            return val[1]
        elif mod == 1:
            return 1
        else:
            return gcd(val[1], mod)
    else:
        return gcd(*[gcd(val[i], val[i + 1]) for i in range(0, len(val), 2)], val[-1])
        

def main():
    sinputl = sys.stdin.readline

    num = int(sinputl().strip())
    input = [int(x) for x in sinputl().split()]

    gcd_max = 1
    input_mem = []

    for i in range(num):
        mem = input.pop(num - 1 - i)
        gcd_max = max(gcd_max, gcd(*input, *input_mem))
        input_mem.append(mem)

    print(gcd_max)



if __name__ == "__main__":
    main()