Problem:


Score : 300 points

Problem Statement

There are N people, conveniently numbered 1 through N.
They were standing in a row yesterday, but now they are unsure of the order in which they were standing.
However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person.
According to their reports, the difference above for person i is A_i.

Based on these reports, find the number of the possible orders in which they were standing.
Since it can be extremely large, print the answer modulo 10^9+7.
Note that the reports may be incorrect and thus there may be no consistent order.
In such a case, print 0.

Constraints

1≦N≦10^5

0≦A_i≦N-1

Input

The input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the number of the possible orders in which they were standing, modulo 10^9+7.

Sample Input 1

5
2 4 4 0 2

Sample Output 1

4

There are four possible orders, as follows:

2,1,4,5,3

2,5,4,1,3

3,1,4,5,2

3,5,4,1,2

Sample Input 2

7
6 4 0 2 4 0 2

Sample Output 2

0

Any order would be inconsistent with the reports, thus the answer is 0.

Sample Input 3

8
7 5 1 1 7 3 5 3

Sample Output 3

16



Sample input:
5
2 4 4 0 2


Sample output:
4

Submission status: Time Limit Exceeded

Solution code:
num =int(input())

val = [int(x) for x in input().split()]

_len = len(val)
sort_val = sorted(val)
set_val = set(sort_val)

res = True

if len(val) %2 != 0 and sort_val.count(0) != 1:
    res = False
elif len(val) %2 != 0 and sort_val.count(0) == 1:
    val = val[1:]
    set_val.remove(0)

for i in set_val:
    if sort_val.count(i) != 2:
        res = False
        break
    else:
        sort_val = sort_val[2:]

cnt = 1
if res:
    for i in range(0, _len//2):
        cnt = cnt*2 % 1000000007

print(0 if not res else cnt)

Submission status: Time Limit Exceeded

Solution code:
num =int(input())

val = [int(x) for x in input().split()]

sort_val = sorted(val)
set_val = set(sort_val)

res = True

if len(val) %2 != 0:
    for i in set_val:
        if (i == 0 and sort_val.count(i) != 1) or (i != 0 and sort_val.count(i) %2 != 0):
            res = False
            break
else:
    for i in set_val:
        if sort_val.count(0) != 0 or sort_val.count(i) %2 != 0:
            res = False
            break

cnt = 1
if res:
    for i in range(0, len(sort_val)//2):
        cnt = cnt*2 % 1000000007

print(0 if not res else cnt)

Submission status: Time Limit Exceeded

Solution code:
num =int(input())

val = [int(x) for x in input().split()]

sort_val = sorted(val)
set_val = set(sort_val)

res = True

if len(val) %2 != 0:
    for i in set_val:
        if (i == 0 and sort_val.count(i) != 1) or (i != 0 and sort_val.count(i) %2 != 0):
            res = False
            break
else:
    for i in set_val:
        if sort_val.count(0) != 0 or sort_val.count(i) %2 != 0:
            res = False
            break

cnt = 1
for i in range(0, len(sort_val)//2):
    cnt = cnt*2 % 1000000007

print(0 if res == False else cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

MOD = 10 ** 9 + 7
def main():
    N = int(input())
    A_list = list(sorted(list(map(int, input().split()))))

    num_of_zero = A_list.count(0)
    if N % 2 == 0:
        if num_of_zero != 0:
            print(0)
            return
    else:
        if num_of_zero != 1:
            print(0)
            return
    for i in range(N - 1, 0, -2):
        if A_list.count(i) != 2:
            print(0)
            return

    print(pow(2, (N // 2), MOD))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
N=input()
A=list(map(int, input().split()))
A.sort(reverse=1)
if A[0]%2==1:
  if len(A)==int(A[0]/2)*2+1 or len(A)==int(A[0]/2)*2+2:
    for j in range(A[0],1,-2):
      if A.count(j)!=2:
        print(0)
        sys.exit()
    if A.count(1)==2 or A.count(1)==1:
      print(2**int(len(A)/2))
    else:
      print(0)
  else:
    print(0)
if A[0]%2==0:
  if len(A)==A[0]+1 or len(A)==A[0]+2:
    for j in range(A[0],0,-2):
      if A.count(j)!=2:
        print(0)
        sys.exit()
    if A.count(0)==2 or A.count(0)==1:
      print(2**int(len(A)/2))
    else:
      print(0)
  else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    A = tuple(map(int, input().split()))

    i = N - 1
    while i >= 0:
        n = A.count(i)
        if i == 0 and n != 1:
            print('0')
            break
        elif i != 0 and n != 2:
            print('0')
            break
        i -= 2
    else:
        comb = (2 ** (N // 2)) % 1000000007
        print(str(comb))

main()

Submission status: Time Limit Exceeded

Solution code:
num = int(raw_input())
array = map(int, raw_input().split(" "))

all_ok = True
if num % 2 == 0:
    for i in range(num / 2):
        n = i * 2 + 1
        if n in array and ( array.count(n) == 2 ):
            continue
        else:
            all_ok = False
            break
else:
    for i in range(num / 2 + 1):
        n = i * 2
        if n == 0:
            if n in array and (array.count(n) == 1):
                continue
            else:
                all_ok = False
                break
        else:
            if n in array and ( array.count(n) == 2 ):
                continue
            else:
                all_ok = False
                break


div = pow(10, 9) + 7
if all_ok:
    print pow(2, (num/2) ) % div
else:
    print 0

Submission status: Time Limit Exceeded

Solution code:
num = int(raw_input())
array = raw_input().split(" ")

array_list = list(set(array[:]))
contain = []
if num % 2 == 0:
    for i in range(num / 2):
        contain.append(i * 2 + 1)
else:
    for i in range(num / 2 + 1):
        contain.append(i * 2)

all_ok = True
for i in range(len(array)):

    if int(array[i]) in contain:
        if (int(array[i]) == 0 and array.count(array[i]) == 1):
            continue
        elif (int(array[i]) != 0 and array.count(array[i]) == 2):
            continue
        else:
            all_ok = False
            break
    else:
        all_ok = False
        break

div = pow(10, 9) + 7
if all_ok:
    print pow(2, (num/2) ) % div
else:
    print 0

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Here your code !

N=int(input())
numbers=input().rstrip().split(" ")

count=2**(N//2)

if N%2==1:
    if numbers.count("0")!=1:
        count=0
    i=2

elif N%2==0:
    i=1

while(i<=N-1):
    if numbers.count(str(i))!=2:
        count=0
        break
    i+=2
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(x) for x in input().split()]

def is_satisfied(s):
    ln = len(s)
    for i in range(ln - 1, 1, -2):
        if not s.count(i) == 2:
            return False
    if ln % 2 == 0:
        if not s.count(1) == 2:
            return False
    else:
        if not s.count(0) == 1:
            return False

    return True


ans = 2 ** (n // 2) % (10 ** 9 + 7)
print(ans if is_satisfied(a) else 0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(x) for x in input().split()]

def is_satisfied(s):
    ln = len(s)
    check = [s.count(i) == 2 for i in range(ln - 1, 1, -2)]
    if ln % 2 == 0:
        check.append(s.count(1) == 2)
    else:
        check.append(s.count(0) == 1)

    return all(check)


ans = 2 ** (n // 2) % (10 ** 9 + 7)
print(ans if is_satisfied(a) else 0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(x) for x in input().split()]

def is_satisfied(s):
    ln = len(s)
    check = [s.count(i) == 2 for i in range(ln - 1, 1, -2)]
    if ln % 2 == 0:
        check.append(s.count(1) == 2)
    else:
        check.append(s.count(0) == 1)

    return all(check)


ans = 2 ** (n // 2) if is_satisfied(a) else 0
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))

if N % 2 == 0:
	l = list(range(1, N, 2)) * 2
else:
	l = [0] + list(range(2, N, 2)) * 2

flag = True

for i in range(N):
	if A.count(l[i]) != l.count(l[i]):
		flag = False
		break

if flag == False:
	print(0)
else:
	if N % 2 == 0:
		print(int(2**(N/2)) % 1000000007)
	else:
		print(int(2**((N-1)/2)) % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))

if N % 2 == 0:
	l = list(range(1, N, 2)) * 2
else:
	l = [0] + list(range(2, N, 2)) * 2

for i in range(N):
	flag = True
	if sorted(l)[i] != sorted(A)[i]:
		flag = False
		break
	
if flag == False:
	print(0)
else:
	if N % 2 == 0:
		print(int(2**(N/2)) % 1000000007)
	else:
		print(int(2**((N-1)/2)) % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding:utf-8 -*-
import sys, math
N = int(input())
A = sorted(list(map(int,input().split())))
"""
s = set()
redundancy = [ r for r in A if r in s or s.add(r) ] #重複している数字を格納
"""
ans = 1
factor = 0

while factor < N:
    tmp = A.count(A[factor])
    if tmp >= 1 and tmp <= 2:
        if A[factor] == 0 and tmp == 2:
            print(0)
            sys.exit()
        else:
            ans *= tmp
            factor += tmp
            continue
    else:
        print(0)
        sys.exit()

"""
for tmp in redundancy:
    if A.count(tmp) > 2 or tmp == 0:
        print(0)
        sys.exit()
    else:
        ans *= A.count(tmp)
"""
print(ans%((10**9)+7))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding:utf-8 -*-
import sys, math
N = int(input())
A = sorted(list(map(int,input().split())))
#s = set()
#redundancy = [ r for r in A if r in s or s.add(r) ] #重複している数字を格納
ans = 1
factor = 0

if A.count(factor) >= 2:
    print(0)
    sys.exit()

while factor < N:
    tmp = A.count(A[factor])
    if tmp >= 1 and tmp <= 2:
        ans *= tmp
        factor += tmp
        continue
    else:
        print(0)
        sys.exit()

"""
for tmp in redundancy:
    if A.count(tmp) > 2 or tmp == 0:
        print(0)
        sys.exit()
    else:
        ans *= A.count(tmp)
"""
print(ans%((10**9)+7))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding:utf-8 -*-
import sys, math
N = int(input())
A = list(map(int,input().split()))
s = set()
redundancy = [ r for r in A if r in s or s.add(r) ] #重複している数字を格納
ans = 1
for tmp in redundancy:
    if A.count(tmp) > 2 or tmp == 0:
        print(0)
        sys.exit()
    else:
        ans *= A.count(tmp)
print(ans%((10**9)+7))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
Nc = 0
e = 0
B = []
A.sort()
if N % 2 == 0:
    for i in range(1, N//2 + 1):
        B = B + [2*i - 1, 2*i -1]
    if A == B:
        Nc = 2**(N//2)
else:
    for i in range(1, ((N-1)//2) + 1):
        B = B + [2*i, 2*i]
    B = [0] + B
    if A == B:
        Nc = 2**((N-1)//2)

print(Nc%1000000007)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
Nc = 1
e = 0
for i in range(N):
    if (N-A[i]-1) < 0:
        e = 1
        Nc = 0
        break
if e ==0:
    if A.count(0) >= 2:
        Nc *= 0
    else:
        for i in range(N-1):
                if A.count(i+1) == 2:
                    Nc *= 2
                elif A.count(i+1) ==0:
                    Nc *= 1
                else:
                    Nc *= 0
                    break

print(Nc%1000000007)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
Nc = 1
if A.count(0) >= 2:
    Nc *= 0
else:
    for i in range(N):
        if (N-A[i]) >= 1:
                if A.count(i+1) == 2:
                    Nc = Nc*2%1000000007
                elif A.count(i+1) == 0:
                    Nc *= 1
                else:
                    Nc *= 0
                    break
        else:
            Nc *= 0
            break

print(Nc)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))

      
if n%2==0:
    for i in range(1,n,2):
        if a.count(i) != 2:
            print(0)
            break
    else:
        print(2**(n//2) % (10**9+7))

if n%2==1:
    if a.count(0)!=1:
            print(0)
            exit()        
    for i in range(2,n,2):
        if a.count(i) != 2:
            print(0)
            break
    else:
        print(2**((n-1)//2) % (10**9+7))

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(input())
data = list(map(int, input().split()))
if n % 2 == 1:
    if data.count(0) != 1:
        print(0)
        sys.exit()
    else:
        i = 1
        while 2 * i + 1 <= n:
            if data.count(2 * i) != 2:
                print(0)
                sys.exit()
            i += 1
        print((2 ** ((n - 1) // 2)) % (10 ** 9 + 7))
else:
    for i in range(n//2):
        if data.count(2 * i + 1) != 2:
            print(0)
            sys.exit()
    print((2 ** (n // 2)) % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import sys


def main():
    count = int(raw_input())
    li = [int(n) for n in raw_input().split()]
    if count%2 == 1: # 奇数
        if li.count(0) != 1:
            print 0
            return
        count_list = range(count)[2::2]
    else: # 偶数
        count_list = range(count)[1::2]

    for i in count_list:
        if li.count(i) != 2:
            print 0
            return
    print 2**(count/2)%(10**9+7)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def mk_count_list(ls):
    length = len(ls)
    keys = list(set(ls))
    cnt_ls = []
    for item in keys:
        cnt = ls.count(item)
        if cnt != 0 and cnt != 2:
            cnt_ls.append((item, cnt))
    #print("ls", ls, keys, cnt_ls)
    return cnt_ls

def check_verify_pair(ls):
    length = len(ls)
    count_list = mk_count_list(ls)
    min_val = min(ls)
    if length%2 == 0:
       if count_list: return False 
    if length%2 == 1:
        #print(count_list)
        if len(count_list) == 1 and min(ls) == min(count_list)[0] and min(count_list)[1] == 1:
            return True
        else:
            return False
    return True
    
if __name__ == "__main__":
    n = int(input())
    ls = list(map(int, input().split()))
    length = len(ls)
    if not check_verify_pair(ls):
        print(0)
    else:
        ans = 2**(length//2)%(10**9+7)
        print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
n=int(input())
array=[int(i) for i in input().split()]

if n%2==0:
    sub=1
else:
    sub=2
    if array.count(0) != 1:
        print(0)
        sys.exit()

for i in range(sub,n,2):
    if array.count(i) != 2:
        print(0)
        sys.exit()


print(2**int(n/2))

Submission status: Time Limit Exceeded

Solution code:
N = int(raw_input())
line = map(int,raw_input().split(' '))
if N%2 == 0:
    for i in range(1,N-1,2):
        if line.count(i) != 2:
            print 0
            exit(0)
        line.remove(i)
        line.remove(i)
    print 2**(N/2) %(10**9+7)
else:
    if line.count(0) != 1:
        print 0
        exit(0)
    line.remove(0)
    for i in range(2,N-1,2):
        if line.count(i) != 2:
            print 0
            exit(0)
        line.remove(i)
        line.remove(i)
    print 2**(N/2)%(10**9+7)

Submission status: Time Limit Exceeded

Solution code:
N = int(raw_input())
line = map(int,raw_input().split(' '))
if N%2 == 0:
    for i in range(1,N-1,2):
        if line.count(i) != 2:
            print 0
            exit(0)
    print 2**(N/2) %(10**9+7)
else:
    if line.count(0) != 1:
        print 0
        exit(0)
    for i in range(2,N-1,2):
        if line.count(i) != 2:
            print 0
            exit(0)
    print 2**(N/2)%(10**9+7)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
M = N//2
if N % 2 == 1 and A.count(0) == 1 and all(A.count(i*2)==2 for i in range(1,M-1)):
    print((2 ** M) % (10**9+7))
elif N % 2 == 0 and all(A.count(i*2-1)==2 for i in range(1, M-1)):
    print((2 ** M) % (10**9+7))
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
M = N//2
if N % 2 == 1 and A.count(0) == 1 and all(A.count(i*2+2)==2 for i in range(M)):
    print((2 ** M) % (10**9+7))
elif N % 2 == 0 and all(A.count(i*2+1)==2 for i in range(M)):
    print((2 ** M) % (10**9+7))
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
M = N//2
if N % 2 == 1 and A.count(0) == 1 and all(A.count(i*2+2)==2 for i in range(N//2)):
    print((2 ** M) % (10**9+7))
elif N % 2 == 0 and all(A.count(i*2+1)==2 for i in range(N//2)):
    print((2 ** M) % (10**9+7))
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
N=int(raw_input().split()[0])
A=(map(int,raw_input().split()))
MOD=10**9+7
def result():
    
    if all(1-N<=b<=N-1 for b in A) and all ((N%2!=b%2) for b in A):
        X=[]
        for a in A:
            if N%2==1:
                if (N+1)/2<a:
                    X.append(N-a)
                else:
                    X.append(a)
            else:
                if N/2<a:
                    X.append(N-1-a)
                else:
                    X.append(a)
            
        for a in X:
            if X.count(a)>2:
                return 0
        if N%2==0:
            return  2**((N)/2)
        else :
            if  X.count(0)>1:
                return 0
            return  2**((N-1)/2)
    
    else:
        return 0
    

if __name__=="__main__":
    print result()%MOD

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = input().split()

flag = True
if n % 2 == 0:
    for i in range(int(n/2)):
        if a.count(str(i*2 + 1)) == 2:
            pass
        else:
            flag = False
            break
    ans = 2**(n/2) % (1e9 + 7)

else:  # n % 2 == 1
    if a.count('0') == 1:
        for i in range(int((n - 1) / 2)):
            if a.count(str((i + 1) * 2)) == 2:
                pass
            else:
                flag = False
                break
    else:
        flag = False

    ans = 2**((n-1)/2) % (1e9 + 7)

if flag:
    print(int(ans))
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = input().split()

flag = True
if n % 2 == 0:
    for i in range(int(n/2)):
        if a.count(str(i*2 + 1)) == 2:
            pass
        else:
            flag = False
            break
    ans = 2**(n/2) % (10**9 + 7)

else:  # n % 2 == 1
    if a.count('0') == 1:
        for i in range(int((n - 1) / 2)):
            if a.count(str((i + 1) * 2)) == 2:
                pass
            else:
                flag = False
                break
    else:
        flag = False

    ans = 2**((n-1)/2) % (10**9 + 7)

if flag:
    print(int(ans))
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = input().split()

flag = True
if n % 2 == 0:
    for i in range(int(n/2)):
        if a.count(str(i*2 + 1)) == 2:
            pass
        else:
            flag = False
    ans = 2**(n/2) % (10**9 + 7)

else:  # n % 2 == 1
    if a.count('0') == 1:
        pass
    else:
        flag = False
    for i in range(int((n-1)/2)):
        if a.count(str((i+1)*2)) == 2:
            pass
        else:
            flag = False
    ans = 2**((n-1)/2) % (10**9 + 7)

if flag:
    print(int(ans))
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
line = list(map(int, input().split()))
n = N - 1
ans = 1
while(len(line) >= 0):
    c = line.count(n)
    if (len(line) == 0):
        print(ans % (10**9+7))
        break
    if len(line) == 1 and line[0] == 0:
        print(ans % (10**9+7))
        break
    elif c != 2:
        print(0)
        break
    else:
        ans *= 2
        line = [i for i in line if i != n]
        n = n - 2

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))

l = []
if N % 2 == 1:
    if A.count(0) != 1:
        print(0)
    else:
        l = list(range(2, N, 2))
        for i in range(2, N, 2):
            if A.count(i) != 2:
                print(0)
                break
        else:
            print(2 ** len(l))
else:
    l = list(range(1, N, 2))
    for i in range(1, N, 2):
        if A.count(i) != 2:
            print(0)
            break
    else:
        print(2 ** len(l))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
error = 0

if N%2 == 1:
      if A.count(0) != 1:
            error += 1
      for i in range(2, N, 2):
            if A.count(i) != 2:
                  error += 1
      if error > 0:
            print(0)
      else:
            print(int((2**((N-1)/2))%(10**9+7)))
      
else:
      if A.count(0) != 0:
            error += 1
      for i in range(1, N, 2):
            if A.count(i) != 2:
                  error += 1
      if error > 0:
            print(0)
      else:
            print(int((2**(N/2))%(10**9+7)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N=int(raw_input())
A=map(int, raw_input().split())


cnt = 0
if N%2 == 0:
    if A.count(0) >= 1:
        print 0
        cnt = 1
    else:
        for i in np.arange(1, N, 2):
            if A.count(i) != 2:
                print 0
                cnt = 1
                break
    if cnt == 0:
        print 2**(N/2)%(10**9+7)
else:
    if A.count(0) >= 2:
        print 0
        cnt = 1
    else:
        for i in np.arange(2, N, 2):
            if A.count(i) != 2:
                print 0
                cnt = 1
                break
    if cnt == 0:
        print 2**(N/2)%(10**9+7)

Submission status: Time Limit Exceeded

Solution code:


N = int(input())
A = list(map(int,input().split()))

if len(A)%2 == 1:

    for i in range(0,len(A),2):

        cnt = A.count(i)
        if i == 0:
            if cnt > 1:
                print(0)
                break
            elif cnt==1 and len(A)%2==0:
                print(0)
                break
            elif cnt==0 and len(A)%2==1:
                print(0)
                break
        elif cnt != 2:
            print(0)
            break

        if i == len(A)-1:
            print(2**int(len(A)/2) % (10**9+7))

else:
    
    for i in range(1,len(A),2):

        cnt = A.count(i)
        if i == 0:
            if cnt > 1:
                print(0)
                break
            elif cnt==1 and len(A)%2==0:
                print(0)
                break
            elif cnt==0 and len(A)%2==1:
                print(0)
                break
        elif cnt != 2:
            print(0)
            break

        if i == len(A)-1:
            print(2**int(len(A)/2) % (10**9+7))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
if N % 2 == 1 and (A.count(0) != 1 or not all(A.count(i*2+2)==2 for i in range(N//2))):
    print(0)
elif N % 2 == 0 and not all(A.count(i*2+1)==2 for i in range(N//2)):
    print(0)
else:
    print(2**(N//2) % (10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
import sys

n = int(input())
a = list(map(int, input().split(' ')))

isodd = n % 2 == 1
for i in a:
    count = a.count(i)
    if isodd and i == 0:
        if count == 1:
            continue
        else:
            print(0)
            sys.exit(0)
    if count != 2:
        print(0)
        sys.exit(0)

ans = 1
mod = 10**9+7
for i in range(int(n/2)):
    ans = ans * 2 % mod 

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
sa=set(a)
f=True
if n%2==0:
    if sa=={int(i) for i in range(1,n,2)}:
        for i in range(1,n,2):
            if a.count(i)!=2:
                f=False
                break
    else:
        f=False
else:
    if a.count(0)==1:
        for i in range(2,n,2):
            if a.count(i)!=2:
                f=False
                break
    else:
        f=False
print(2**(n//2) if f else 0)

Submission status: Time Limit Exceeded

Solution code:
import sys

n = int(input())
a = list(map(int, input().split(' ')))

isodd = n % 2 == 1
for i in a:
    count = a.count(i)
    if isodd and i == 0:
        if count == 1:
            continue
        else:
            print(0)
            sys.exit(0)
    if count != 2:
        print(0)
        sys.exit(0)

print(2**int(n/2)%(10**9+7))

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
d = list(c.values())
if (n % 2 == 1 and c[0] == 1 and d.count(2) == (n-1)//2) or (n % 2 == 0 and d.count(2) == n//2):
    print(pow(2, n//2, 10**9+7))
else:
    print(0)

Submission status: Accepted

Solution code:
MOD=1e9+7

from collections import defaultdict
def check_even(c):
	ans=1
	d=defaultdict(int)
	for i in range(len(c)):
		d[c[i]]+=1
	
		if c[i]>=len(c) or c[i]%2==0 or d[c[i]]>2:
			return 0
		
		if d[c[i]]==1:
			ans=ans*2 % MOD
	return int(ans)
		
def check_odd(c):
	ans=1
	d=defaultdict(int)
	for i in range(len(c)):
		d[c[i]]+=1
		if c[i]>=len(c) or c[i]%2==1 or d[0]>1 or d[c[i]]>2:
			return 0
		
		if c[i]!=0 and d[c[i]]==1:
			ans=ans*2%MOD
			
	return int(ans)
		
n=int(input())
c=list(map(int,input().split()))
if n%2==0:
	print(check_even(c))
else:
	print(check_odd(c))

Submission status: Accepted

Solution code:
n = int(input())
A = sorted(map(int,input().split()))

if n % 2 == 1:
    ex = [0]
    
    for i in range(n//2):
        a = 2 * (i+1)
        ex += [a,a]
        
else:
    ex = []
    a = 1
    
    for i in range(n//2):
        ex += [a,a]
        a += 2
        
ans = 0

if A == ex:
    ans = 2 ** (n//2) % (10**9 + 7)
    
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
res = True
anse = list(i for i in range(1, n, 2))
anso = list(i for i in range(2, n, 2))
if n % 2 != 0:
  if a[0] != 0:
    res = False
    print(0)
  a = a[1:]
  for i in range(0, len(a), 2):
    if a[i] != anso[i//2] or a[i+1] != anso[i//2]:
        print(0)
        res = False
        break


if n % 2 == 0:
    for i in range(0, len(a), 2):
        if a[i] != anse[i//2] or a[i+1] != anse[i//2]:
            print(0)
            res = False
            break

p = 10**9 + 7
if res:
  print(pow(2, n//2, p))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
res = True
if n % 2 != 0:
  if a[0] != 0:
    res = False
    print(0)
  a = a[1:]
for i in range(0, len(a), 2):
  if a[i] != a[i+1]:
    print(0)
    res = False
    break

p = 10**9 + 7
if res:
  print(pow(2, n//2, p))

Submission status: Accepted

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n = i_input()
    l = i_list()
    l.sort()

    if n == 1:
        if 0 in l:
            print(1)
            exit()
        else:
            print(0)
            exit()


    L = {}
    for i,k in itertools.groupby(l):
        L[i] = len(list(k))

    cnt = 0

    for i, k in L.items():
        if i == 0:
            if k > 1:
                print(0)
                exit()
        else:
            if k != 2:
                print(0)
                exit()
            else:
                cnt += 1
    print(2**cnt % MOD)









if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
alst = list(map(int, input().split()))
num = n - 1
ans_lst = [abs(i) for i in range(-num, num + 1, 2)]
alst.sort()
ans_lst.sort()
if alst != ans_lst:
    print(0)
else:
    MOD = 10 ** 9 + 7
    ans = pow(2, n // 2, MOD)
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
l = [0] * n
for x in a:
    l[x] += 1
for i in range(n):
    if l[i] > 2:
        print(0)
        exit()
    if l[i] > 0 and (i + n) % 2 == 0: 
        print(0)
        exit()
if n % 2 == 1 and l[0] > 1:
    print(0)
    exit()
print(pow(2, n // 2, 10 ** 9 + 7))

Submission status: Accepted

Solution code:
N=int(input())
*A,=sorted(map(int,input().split()))
 
a=True
if N%2==0:
 for i in range(1,N,2):
  if A[i-1]!=i or A[i]!=i:
    a=False
    break
else:
 if A[0]!=0:a=False
 else:
    for i in range(2,N,2):
     if A[i-1]!=i or A[i]!=i:
        a=False
        break
print(2**(N//2)%(10**9+7) if a else 0)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
num_map = [0] * ((n + 2 - 1) // 2)
for i in range(n):
    num_map[a[i] // 2] += 1

res = 2 - n % 2
if num_map[0] != 2 - n % 2:
    print(0)
else:
    for i in range(1, (n + 2 - 1) // 2):
        if num_map[i] != 2:
            print(0)
            break
        else:
            res = res * 2 % mod
    else:
        print(res)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
num_map = [0] * ((n + 2 - 1) // 2)
for i in range(n):
    num_map[a[i] // 2] += 1

res = 1
if n % 2 == 1:
    if num_map[0] != 1:
        print(0)
    else:
        for i in range(1, (n + 2 - 1) // 2):
            if num_map[i] != 2:
                print(0)
                break
            else:
                res = res * 2 % mod
        else:
            print(res)
else:
    for i in range((n + 2 - 1) // 2):
        if num_map[i] != 2:
            print(0)
            break
        else:
            res = res * 2 % mod
    else:
        print(res)

Submission status: Accepted

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))

flag = True
if N%2 == 0:
    if 0 in A or len(set(A)) != N//2:
        flag = False
else:
    if len([0 for a in A if a == 0]) != 1 or len(set(A)) != N//2 + 1:
        flag = False

if  flag:
    print(2**((N//2))%(10**9+7))
else:
    print(0)

Submission status: Accepted

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))

flag = True
if N%2 == 0:
    if 0 in A or len(set(A)) != N//2:
        flag = False
else:
    if len([0 for a in A if a == 0]) != 1 or len(set(A)) != N//2 + 1:
        flag = False

if  flag:
    print(2**(math.floor(N/2))%(10**9+7))
else:
    print(0)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
x=[0]*(n+1)
p=10**9+7
for i in a:
   x[i]+=1
if n%2==0:
    m=n//2
    f=0
    for i in range(m):
        if x[2*i+1]!=2:
            f=1
    if f==1:
        print(0)
    else:
        print(pow(2,m,p))
else:
    m=n//2
    f=0
    if x[0]!=1:
        f=1
    for i in range(m):
        if x[2*i+2]!=2:
            f=1
    if f==1:
        print(0)
    else:
        print(pow(2,m,p))