Buggy python submission (verdict: Time Limit Exceeded):


def read_input():
    n = int(input())
    alist = list(map(int, input().split()))

    return n, alist


def possibility_check(n, alist):
    occurs = {}
    for a in alist:
        if a in occurs.keys():
            occurs[a] += 1
        else:
            occurs[a] = 1

    if n % 2:
        if occurs[0] == 1:
            for i in range(2, n, 2):
                if occurs[i] != 2:
                    return False
            return True
        else:
            return False
    else:
        for i in range(1, n, 2):
            if occurs[i] != 2:
                return False
        return True

def submit():
    n, alist = read_input()

    if possibility_check(n, alist):
        # ans = (2 ** (n // 2)) % (10**9 + 7)
        ans = 1
        for i in range(n // 2):
            ans *= 2
            if ans > 10**9 + 7:
                ans %= (10**9 + 7)
        print(ans)
    else:
        print(0)


if __name__ == '__main__':
    submit()


Fixed submission:


def read_input():
    n = int(input())
    alist = list(map(int, input().split()))

    return n, alist


def possibility_check(n, alist):
    alist.sort()

    if n % 2:
        even = [x for x in range(2, n) if x % 2 == 0]
        comp = [0] + even + even
        comp.sort()

    else:
        odd = [x for x in range(1, n) if x % 2 == 1]
        comp = odd + odd
        comp.sort()

    if alist == comp:
        return True
    else:
        return False


def submit():
    n, alist = read_input()

    if possibility_check(n, alist):
        # ans = (2 ** (n // 2)) % (10**9 + 7)
        ans = 1
        for i in range(n // 2):
            ans *= 2
            if ans > 10**9 + 7:
                ans %= (10**9 + 7)
        print(ans)
    else:
        print(0)


if __name__ == '__main__':
    submit()

Buggy python submission (verdict: Time Limit Exceeded):


def read_input():
    n = int(input())
    alist = list(map(int, input().split()))

    return n, alist


def possibility_check(n, alist):
    occurs = {}
    for a in alist:
        if a in occurs.keys():
            occurs[a] += 1
        else:
            occurs[a] = 1

    if n % 2:
        if occurs[0] == 1:
            for i in range(2, n, 2):
                if occurs[i] != 2:
                    return False
            return True
        else:
            return False
    else:
        for i in range(1, n, 2):
            if occurs[i] != 2:
                return False
        return True

def submit():
    n, alist = read_input()

    if possibility_check(n, alist):
        ans = (2 ** (n // 2)) % (10**9 + 7)
        print(ans)
    else:
        print(0)


if __name__ == '__main__':
    submit()


Fixed submission:


def read_input():
    n = int(input())
    alist = list(map(int, input().split()))

    return n, alist


def possibility_check(n, alist):
    alist.sort()

    if n % 2:
        even = [x for x in range(2, n) if x % 2 == 0]
        comp = [0] + even + even
        comp.sort()

    else:
        odd = [x for x in range(1, n) if x % 2 == 1]
        comp = odd + odd
        comp.sort()

    if alist == comp:
        return True
    else:
        return False


def submit():
    n, alist = read_input()

    if possibility_check(n, alist):
        # ans = (2 ** (n // 2)) % (10**9 + 7)
        ans = 1
        for i in range(n // 2):
            ans *= 2
            if ans > 10**9 + 7:
                ans %= (10**9 + 7)
        print(ans)
    else:
        print(0)


if __name__ == '__main__':
    submit()