Problem p03380 (python)

Fixed submission:
import sys
import itertools
from functools import lru_cache
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, (input().split(' '))))

#    @lru_cache(None)
#    def comb1(n, r):
#        if n == 0 or r == 0: return 1
#        return comb1(n, r - 1) * (n - r + 1) / r
#
##    def comb2(n, r):
##        if n < 0 or r < 0 or n < r:
##            return 0
##        elif n == 0 or r == 0:
##            return 1
##        return comb2(n - 1, r - 1) + comb2(n - 1, r)
#
#    max = 0
#    comb_val1 = 0
#    comb_val2 = 0
#    for ele in itertools.combinations(A, 2):
#        buf_val1 = ele[0]
#        buf_val2 = ele[1]
#        if ele[1] > ele[0]:
#            buf_val1 = ele[1]
#            buf_val2 = ele[0]
##        print(buf_val1, buf_val2)
#        val = comb1(buf_val1, buf_val2)
#        if val >= max:
#            max = val
#            comb_val1 = buf_val1
#            comb_val2 = buf_val2
#    print(max)
#    print(str(comb_val1) + ' ' + str(comb_val2))

### n=10^5 * a=0~10^9の組み合わせがありうるので計算量は結局多いのでメモ化しても意味はない。

    N = max(A)
    A.remove(N)
    min_distance = 10 ** 10
    M = 0
    for a in A:
        if abs(N/2 - a) < min_distance:
            min_distance = abs(N/2 - a)
            M = a
    print("{} {}".format(N, M))

Buggy submission (verdict: Runtime Error):
import sys
import itertools
from functools import lru_cache
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, (input().split(' '))))

    @lru_cache(None)
    def comb1(n, r):
        if n == 0 or r == 0: return 1
        return comb1(n, r - 1) * (n - r + 1) / r

    def comb2(n, r):
        if n < 0 or r < 0 or n < r:
            return 0
        elif n == 0 or r == 0:
            return 1
        return comb2(n - 1, r - 1) + comb2(n - 1, r)

    max = 0
    comb_val1 = 0
    comb_val2 = 0
    for ele in itertools.combinations(A, 2):
        buf_val1 = ele[0]
        buf_val2 = ele[1]
        if ele[1] > ele[0]:
            buf_val1 = ele[1]
            buf_val2 = ele[0]
#        print(buf_val1, buf_val2)
        val = comb2(buf_val1, buf_val2)
        if val >= max:
            max = val
            comb_val1 = buf_val1
            comb_val2 = buf_val2
#    print(max)
    print(str(comb_val1) + ' ' + str(comb_val2))

Buggy submission (verdict: Runtime Error):
import sys
import itertools
from functools import lru_cache
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, (input().split(' '))))

    @lru_cache(None)
    def comb1(n, r):
        if n == 0 or r == 0: return 1
        return comb1(n, r - 1) * (n - r + 1) / r

    def comb2(n, r):
        if n < 0 or r < 0 or n < r:
            return 0
        elif n == 0 or r == 0:
            return 1
        return comb2(n - 1, r - 1) + comb2(n - 1, r)

    max = 0
    comb_val1 = 0
    comb_val2 = 0
    for ele in itertools.combinations(A, 2):
        buf_val1 = ele[0]
        buf_val2 = ele[1]
        if ele[1] > ele[0]:
            buf_val1 = ele[1]
            buf_val2 = ele[0]
#        print(buf_val1, buf_val2)
        val = comb1(buf_val1, buf_val2)
        if val >= max:
            max = val
            comb_val1 = buf_val1
            comb_val2 = buf_val2
#    print(max)
    print(str(comb_val1) + ' ' + str(comb_val2))

Buggy submission (verdict: Runtime Error):
import sys
import itertools
from functools import lru_cache
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, (input().split(' '))))

#    def comb1(n, r):
#        if n == 0 or r == 0: return 1
#        return comb1(n, r - 1) * (n - r + 1) / r

    @lru_cache(None)
    def comb2(n, r):
        if n < 0 or r < 0 or n < r:
            return 0
        elif n == 0 or r == 0:
            return 1
        return comb2(n - 1, r - 1) + comb2(n - 1, r)

    max = 0
    comb_val1 = 0
    comb_val2 = 0
    for ele in itertools.combinations(A, 2):
        buf_val1 = ele[0]
        buf_val2 = ele[1]
        if ele[1] > ele[0]:
            buf_val1 = ele[1]
            buf_val2 = ele[0]
#        print(buf_val1, buf_val2)
        val = comb2(buf_val1, buf_val2)
        if val >= max:
            max = val
            comb_val1 = buf_val1
            comb_val2 = buf_val2
#    print(max)
    print(str(comb_val1) + ' ' + str(comb_val2))

Buggy submission (verdict: Runtime Error):
import sys
import itertools
from functools import lru_cache
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, (input().split(' '))))

#    def comb1(n, r):
#        if n == 0 or r == 0: return 1
#        return comb1(n, r - 1) * (n - r + 1) / r

    @lru_cache(None)
    def comb2(n, r):
        if n < 0 or r < 0 or n < r:
            return 0
        elif n == 0 or r == 0:
            return 1
        return comb2(n - 1, r - 1) + comb2(n - 1, r)

    max = 0
    comb_val1 = 0
    comb_val2 = 0
    for ele in itertools.combinations(A, 2):
        val = comb2(ele[1], ele[0])
        if val >= max:
            max = val
            if ele[1] > ele[0]:
                comb_val1 = ele[1]
                comb_val2 = ele[0]
            else:
                comb_val1 = ele[0]
                comb_val2 = ele[1]
#    print(max)
    print(str(comb_val1) + ' ' + str(comb_val2))