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:
N = int(input())
A = list(map(int, input().split()))
MOD = 10 * 9 + 7

flag = True

if 0 in A:
    if A.count(0) != 1:
        flag = False
S = set(A)
if 0 in S:
    S.remove(0)
flag = all(A.count(x) == 2 for x in S)

if flag:
    print(2 ** (N//2) % MOD)
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
MOD = 10 * 9 + 7

flag = True

if 0 in A:
    if A.count(0) != 1:
        flag = False

for a in set(A):
    if a == 0:
        continue
    if A.count(a) != 2:
        flag = False
        break

if flag:
    print(2 ** (N//2) % MOD)
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
MOD = 10 * 9 + 7

flag = True
s = set()

if 0 in A:
    if A.count(0) != 1:
        flag = False
    s.add(0)
for a in A:
    if a in s:
        continue
    if A.count(a) != 2:
        flag = False
        break
    s.add(a)

if flag:
    print(2 ** (N//2) % MOD)
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
MOD = 10 * 9 + 7

flag = True

for i in range((N+1)%2, N, 2):
    if i == 0:
        if A.count(0) != 1:
            flag = False
    elif A.count(i) != 2:
        flag = False
if flag:
    print(2 ** (N//2) % MOD)
else:
    print(0)

Submission status: Time Limit Exceeded

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

if N%2==0:
  for i in range(1,N,2):
    if A.count(i)!=2:
      f = False
else:
  for i in range(2,N,2):
    if A.count(i)!=2:
      f = False

if f:
  print(pow(2,N//2,10**9+7))
else:
  print(0)

Submission status: Time Limit Exceeded

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

if N%2==0:
  for i in range(1,N,2):
    if A.count(i)!=2:
      f = False
else:
  for i in range(2,N,2):
    if A.count(i)!=2:
      f = False

if f:
  print(2**(N//2))
else:
  print(0)

Submission status: Time Limit Exceeded

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

Devide_N=10**9+7
Rem_2_32_DN=(2**32)%Devide_N

if N%2==1:
  if A.count(0)!=1:
    print(0)
  else:
    for ch_n in range(1,(N-1)//2+1):
      if A.count(ch_n*2)!=2:
        break
      else:
        A.remove(ch_n*2)
        A.remove(ch_n*2)
    else:
      exp=(N-1)//2
      
      exp_quotient_32=exp//32
      exp_rem_32=exp%32
      Rem_ans_Devide_N=1
      for _ in range(exp_quotient_32):
        Rem_ans_Devide_N=(Rem_ans_Devide_N*Rem_2_32_DN)%Devide_N
        
      print((Rem_ans_Devide_N*2**(exp_rem_32))%Devide_N)
      sys.exit()
    print(0)
else:
  for ch_n in range(1,N//2+1):
    if A.count(ch_n*2-1)!=2:
      break
    else:
      A.remove(ch_n*2-1)
      A.remove(ch_n*2-1)
  else:
    exp=N//2
    
    exp_quotient_32=exp//32
    exp_rem_32=exp%32
    Rem_ans_Devide_N=1
    for _ in range(exp_quotient_32):
      Rem_ans_Devide_N=(Rem_ans_Devide_N*Rem_2_32_DN)%Devide_N
      
    print((Rem_ans_Devide_N*2**(exp_rem_32))%Devide_N)
    sys.exit()
  print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
A = list(set(a))
flag = True
if n%2==0:
  if a.count(0)>0:
    flag=False
  else:
    for i in A:
      if a.count(i)!=2:
        flag=False
        break
else:
  if a.count(0)!=1:
    flag=False
  else:
    A.pop(A.index(0))
    for j in A:
      if a.count(j)!=2:
        flag=False
        break
if flag==True:
    print((2**(n//2))%(10**9+7))
else:
  print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
A = list(set(a))
flag = True
if n%2==0:
  if a.count(0)>0:
    flag=False
  else:
    for i in A:
      if a.count(i)!=2:
        flag=False
else:
  if a.count(0)!=1:
    flag=False
  else:
    A.pop(A.index(0))
    for j in A:
      if a.count(j)!=2:
        flag=False
if flag==True:
    print((2**(n//2))%(10**9+7))
else:
  print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
flag = True
if n%2==0:
  if a.count(0)>0:
    flag=False
  else:
    for i in range(n):
      if a.count(a[i])!=2:
        flag=False
else:
  if a.count(0)!=1:
    flag=False
  else:
    a.pop(a.index(0))
    for i in range(n-1):
      if a.count(a[i])!=2:
        flag=False

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
if n%2==0:
  for i in range(0,n,2):
    if a.count(i+1)!=2:
        print(0)
        exit()
else:
  if a.count(0)!=1:
    print(0)
    exit()
  else:
    for i in range(2,n,2):
      if a.count(i)!=2:
        print(0)
        exit()
  
print(2**(n//2))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
if n%2==0:
  for i in range(0,n,2):
    if a.count(i+1)!=2:
        print(0)
        exit()
else:
  if a.count(0)==1:
    for i in range(2,n,2):
      if a.count(i)!=2:
        print(0)
        exit()
  else:
    print(0)
    exit()
    
print(2**(n//2))

Submission status: Time Limit Exceeded

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

if N%2==0:
    n=N//2
    c=0
    for i in range(n):
        j=2*i+1
        if A.count(j)==2:
            c=c
        else:
            c+=1
            
if N%2==1:
    n=N//2
    
    c=0
    for i in range(1, n+1):
        j=2*i
        if A.count(j)==2:
            c=c
        else:
            c+=1
    
    if A.count(0)==1:
        c=c
    else: 
        c+=1
        
if c==0:
    print(2**n%(10**9+7))
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
ai=[int(x) for x in input().split()]
if (ai.count(0)==1 or ai.count(0)==0)and all([ai.count(i)==0 or ai.count(i)==2 for i in range(1,n)]):
    nd=n//2
    ans=1
    for i in range(nd):
        ans*=2
        ans%=10**9+7
    print(ans)
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
n =int(input())

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

result = False

if n % 2 == 0:
    if len(a) == n and sum(a) == n*n/2:
        for i in range(n-1, -1, -2):
            if i not in set(a):break
        result = True

else:
    if len(a) == n and sum(a) == (n+1)*(n-1)/2:
        for i in range(n-1, -1, -2):
            if i not in set(a):break
        result = True
        
if result: print(2**int(n/2) % (10**9+7))
else:print(0)

Submission status: Time Limit Exceeded

Solution code:
n =int(input())

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

result = False

if len(set(a)) == int((n+1)/2) and sum(a)==int(n/2)*int((n+1)/2)*2:
    for i in range(n-1, -1, -2):
        if i not in set(a):
            result = False
            break
    result = True

if result:print(2**int(n/2) % (10**9 + 7))
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
n =int(input())

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

result = -1

for i in range(n-1, -1, -2):
    if i != 0 and a.count(i) != 2 or i == 0 and a.count(i) != 1:
        result = 0
        break

if result == 0:print(result)
else:
    print(2**int(n/2) % (10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
n =int(input())

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

result = -1

for i in range(n-1, -1, -2):
    check = 0
    for ii in range(n):
        if a[ii] == i: check += 1
    if i != 0 and check != 2:
        result = 0
        break
    elif i == 0 and check != 1:
        result = 0
        break
if result != 0:
    result = 2**int(n / 2) % (10 ** 9 + 7)

print(result)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
mem = list(map(int, input().split()))

mod = 10 ** 9 + 7
flag = True
while 0 in mem:
    mem.remove(0)
for i in mem:
    if not mem.count(i) == 2:
        flag = False
        break
if flag:
    print(int((2 ** (int(len(mem)) / 2) % mod)))
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
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)
            exit()
    print(2 ** ((N - 1) // 2))
else:
    for i in range(1, N, 2):
        if A.count(i) != 2:
            print(0)
            exit()
    print(2 ** (N // 2))

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
n=int(input())
aa=list(map(int,input().split()))
m=n-1
while m>=0:
    if (m==0 and aa.count(m)!=1) or (m>0 and aa.count(m)!=2):
        print(0)
        sys.exit()
    m-=2
print(2**(n//2))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lst = [int(i) for i in input().split()]
mod = 10**9 + 7

flg = True
cnt = 0
ans = 1
if n%2 != 0:
    for i in range(n):
        if i==0:
            if lst.count(0) != 1:
                flg = False
        elif i%2!=0 and lst.count(i)!=0:
            flg = False
        elif i%2==0 and lst.count(i)!=2:
            flg = False
        elif i%2==0 and lst.count(i)==2:
            cnt += 1
    
else:
    for i in range(1,n):
        if i%2==0 and lst.count(i)!=0:
            flg = False
        elif i%2!=0 and lst.count(i)!=2:
            flg = False
        elif i%2!=0 and lst.count(i)==2:
            cnt += 1

if flg:
    for i in range(cnt):
        ans *= 2
        ans %= mod
    print(ans)
    
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lst = [int(i) for i in input().split()]
mod = 10**9 + 7


flg = True
cnt = 0
if n%2 != 0:
    for i in range(n):
        if i==0:
            if lst.count(0) != 1:
                flg = False
        elif i%2!=0 and lst.count(i)!=0:
            flg = False
        elif i%2==0 and lst.count(i)!=2:
            flg = False
        elif i%2==0 and lst.count(i)==2:
            cnt += 1
    ans = 2 ** cnt
    
else:
    for i in range(1,n):
        if i%2==0 and lst.count(i)!=0:
            flg = False
        elif i%2!=0 and lst.count(i)!=2:
            flg = False
        elif i%2!=0 and lst.count(i)==2:
            cnt += 1
    ans = 2 ** cnt

if flg:
    print(ans % mod)
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(input())
a = [int(i) for i in input().split()]
for i in range(n):
    if a.count(i)>=3:
        print(0)
        sys.exit()
if a.count(0) >= 2:
    print(0)
    sys.exit()
if 0 in a:
    a.remove(0)
b = set(a)
print(2**(len(b)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
A = [int(i) for i in input().split()]
count = collections.Counter(A)
ans = 0
if N%2 == 1:
  for k,v in count.items():
    if k%2 == 1 or (k != 0 and v != 2):
      break
  else:
    ans = 2**(N//2)
else:
  for k,v in count.items():
    if k%2 == 0 or v != 2:
      break
    else:
      ans = 2**(N//2)
print(ans%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
f=True
if n%2==1:
    if a.count(0)!=1:
        f=False
    for i in  range(2,n,2):
        if a.count(i)!=2:
            f=False
else:
    for i in range(1,n,2):
        if a.count(i)!=2:
            f=False
if f:
    print((2**(n//2))%mod)
else:
    print(0)

Submission status: Time Limit Exceeded

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

A.sort(reverse = True)
if N % 2 == 1:
  if A.count(A[-1]) == 0:
    print(0)
    exit(0)
else:
  if A.count(A[-1]) == 1:
    print(0)
    exit(0)
res = 1
temp = 0
for i in range(N):
  if A.count(A[i]) == 2:
    if temp == A[i]:
      continue
    res *= 2
  else:
    if i == N - 1:
      continue
    res = 0
    break
  temp = A[i]
print(res)

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)
            exit()
    print(int((2 ** (N/2)) % (10*9 + 7)))
else:
    for j in range(0, N, 2):
        if j == 0:
            if int(A.count(j)) != 1:
                print(0)
                exit()
        else:
            if A.count(j) != 2:
                print(0)
                exit() 
    print(int(2 ** ((N-1)/2) % (10*9 + 7)))

Submission status: Time Limit Exceeded

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

oops = 0

if n % 2 == 1:  # 奇数
    if a.count(0) >= 2:
        print(0)
        exit()
    elif 0 in a:  # 中央値あれば
        a.remove(0)  # 消す
        # print(a)
        n -= 1
    else:
        # print("a")
        print(0)
        exit()

    for i in range(2, n, 2):
        if a.count(i) != 2:
            print(0)
            exit()
        a.remove(i)
        a.remove(i)
        # print("i", i)
            # print("b")

else:  # 偶数
    for i in range(1, n, 2):
        if a.count(i) != 2:
            print(0)
            exit()
        a.remove(i)
        a.remove(i)

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

Submission status: Time Limit Exceeded

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

oops = 0

if n % 2 == 1:  # 奇数
    if a.count(0) >= 2:
        print(0)
        exit()
    elif 0 in a:  # 中央値あれば
        a.remove(0)  # 消す
        # print(a)
        n -= 1
    else:
        # print("a")
        print(0)
        exit()

    for i in range(2, n, 2):
        if a.count(i) != 2:
            print(0)
            exit()            # print("i", i)
            # print("b")

else:  # 偶数
    for i in range(1, n, 2):
        if a.count(i) != 2:
            print(0)
            exit()

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

Submission status: Time Limit Exceeded

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

oops = 0

if n % 2 == 1:  # 奇数
    if a.count(0) >= 2:
        oops = 1
        print(0)
        exit()
    elif 0 in a:  # 中央値あれば
        a.remove(0)  # 消す
        # print(a)
        n -= 1
    else:
        # print("a")
        oops = 1  # ないならエラー

    # 奇数
    # print("n - 1", (n - 1))
    for i in range(2, n, 2):
        if a.count(i) != 2:
            oops = 1
            # print("i", i)
            # print("b")
            break

else:
    for i in range(1, n, 2):
        if a.count(i) != 2:
            oops = 1
            break

if oops == 1:
    print(0)
    exit()
# print(n)
print((2 ** (n // 2)) % ((10 ** 9) + 7))
# print((2 ** (n // 2)) % ((10 ** 9) + 7))

Submission status: Time Limit Exceeded

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

oops = 0

if n % 2 == 1:  # 奇数
    if a.count(0) >= 2:
        oops = 1
        print(0)
        exit()
    elif 0 in a:  # 中央値あれば
        a.remove(0)  # 消す
        # print(a)
        n -= 1
    else:
        # print("a")
        oops = 1  # ないならエラー

    # 奇数
    # print("n - 1", (n - 1))
    for i in range(2, n, 2):
        if a.count(i) != 2:
            oops = 1
            # print("i", i)
            # print("b")
            break

else:
    for i in range(1, n, 2):
        if a.count(i) != 2:
            oops = 1
            break

if oops == 1:
    print(0)
    exit()
# print(n)
print((2 ** (n // 2)))
# print((2 ** (n // 2)) % ((10 ** 9) + 7))

Submission status: Time Limit Exceeded

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l.sort()

  if n%2==0:
    for i in range(n):
      if (i//2)*2+1!=l[i]:
        return 0
    return pow(2,n//2)%mod

  else:
    if l[0]!=0:
      return 0
    for i in range(n-1):
      if (i//2)*2+2!=l[1:][i]:
        return 0
    return pow(2,n//2)%mod

print(main())

Submission status: Time Limit Exceeded

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l.sort()

  x=1
  if n%2==0:
    f=True
    for i in range(n):
      if f:
        f=False
        x*=2
        x%=mod
      else:
        f=True
      if (i//2)*2+1!=l[i]:
        return 0
    return x

  else:
    if l[0]!=0:
      return 0
    f=True
    for i in range(n-1):
      if f:
        f=False
        x*=2
        x%=mod
      else:
        f=True
      if (i//2)*2+2!=l[1:][i]:
        return 0
    return x

print(main())

Submission status: Time Limit Exceeded

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l.sort()

  if n%2==0:
    for i in range(n):
      if (i//2)*2+1!=l[i]:
        return 0
    x=1
    for _ in range(n//2):
      x*=2
      x%=mod
    return x

  else:
    if l[0]!=0:
      return 0
    for i in range(n-1):
      if (i//2)*2+2!=l[1:][i]:
        return 0
    x=1
    for _ in range(n//2):
      x*=2
      x%=mod
    return x

print(main())

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = input()

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

def solve(N, A):
    flag = True
    
    if(N%2==0):
        if(A.count(0)!=0):
            flag = False
        else:
            for i in range(1, N, 2):
                if(A.count(i)!=2):
                    flag = False
                    break
                
    else:
        if(A.count(0)!=1):
            flag = False
        else:
            for i in range(2, N, 2):
                if(A.count(i)!=2):
                    flag = False
                    break      
    
    print((2**int(N/2))%(10**9+7) if flag else 0)

if __name__ == '__main__': 
    N = int(input())
    A = [int(a) for a in input().split()]
    
    solve(N, A)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = [int(i) for i in input().split()]
for i in range(n):
    temp = 0
    if n%2==1 and i%2==0 or n%2==0 and i%2==1:
        temp = 2
    if n%2==1 and i==0:
        temp = 1
    if A.count(i)!=temp:
        print(0)
        exit()
print(2**(n//2))

Submission status: Time Limit Exceeded

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

if N % 2 == 1:
    if A.count(0) != 1:
        print(0)
        quit()
    s = 2
else:
    s = 1

for i in range(s, N, 2):
    if A.count(i) != 2:
        print(0)
        quit()
print(2**(N//2)%(10**9+7))

Submission status: Time Limit Exceeded

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

if N % 2 == 1:
    if A.count(0) != 1:
        print(0)
        quit()
    s = 2
else:
    s = 1

for i in range(s, N, 2):
    if A.count(i) != 2:
        print(0)
        quit()
print(2**(N//2))

Submission status: Time Limit Exceeded

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

A.sort()
if N % 2 == 1:
    if A.count(0) != 1:
        print(0)
        quit()
    s = 2
else:
    s = 1

for i in range(s, N, 2):
    if A.count(i) != 2:
        print(0)
        quit()
print(2**(N//2))

Submission status: Time Limit Exceeded

Solution code:


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()

Submission status: Time Limit Exceeded

Solution code:


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()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]

if N % 2:
    if A.count(0) != 1:
        flg = 0
    else:
        if all(A.count(i) == 2 for i in range(2, N, 2)):
            flg = 1
        else:
            flg = 0
else:
    if all(A.count(i) == 2 for i in range(1, N, 2)):
        flg = 1
    else:
        flg = 0

if flg:
    ans = 2 ** (N//2) % (10**9+7)
else:
    ans = 0

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]

if N % 2:
    if A.count(0) != 1:
        flg = 0
    else:
        if all(A.count(i) == 2 for i in range(2, N, 2)):
            flg = 1
        else:
            flg = 0
else:
    if all(A.count(i) == 2 for i in range(1, N, 2)):
        flg = 1
    else:
        flg = 0

if flg:
    ans = 1
    for i in range(N//2):
        ans *= 2
        ans %= 10**9 + 7
else:
    ans = 0

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]

if N % 2:
    if A.count(0) != 1:
        flg = 0
    else:
        if all(j % 2 == 0 for j in A):
            if all(A.count(i) == 2 for i in range(2, N, 2)):
                flg = 1
            else:
                flg = 0
        else:
            flg = 0
else:
    if all(j % 2 for j in A):
        if all(A.count(i) == 2 for i in range(1, N, 2)):
            flg = 1
        else:
            flg = 0
    else:
        flg = 0

if flg:
    ans = 1
    for i in range(N//2):
        ans *= 2
        ans %= 10**9 + 7
else:
    ans = 0

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]

if N % 2:
    if A.count(0) != 1:
        flg = 0
    else:
        if all(A.count(i) == 2 for i in range(2, N, 2)):
            if all(j % 2 == 0 for j in A):
                flg = 1
            else:
                flg = 0
        else:
            flg = 0
else:
    if all(A.count(i) == 2 for i in range(1, N, 2)):
        if all(j % 2 for j in A):
            flg = 1
        else:
            flg = 0
    else:
        flg = 0

print(2**(N//2) if flg else 0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(x) for x in input().split()]

# validation
if A.count(0) > 1:
    print(0)
    exit()

start = 2 if N % 2 == 1 else 1
for n in range(start, N - 1, 2):
    if A.count(n) != 2:
        print(0)
        exit()

if N % 2 != 0:
    N -= 1

tempN = int(N / 2)
ans = int(2 ** tempN)

if ans > 1000000007:
    ans %= 1000000007

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(x) for x in input().split()]

# validation
if A.count(0) > 1:
    print(0)
    exit()

for a in A:
    if A.count(a) > 2:
        print(0)
        exit()

if N % 2 != 0:
    N -= 1

tempN = int(N / 2)
ans = int(2 ** tempN)

if ans > 1000000007:
    ans %= 1000000007

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(x) for x in input().split()]

flag = False
# validation
for a in A:
    if A.count(a) > 2:
        print(0)
        exit()
    elif A.count(a) == 1:
        if a != 0:
            print(0)
            exit()
        elif flag is False:
            flag = True
        else:
            print(0)
            exit()

if N % 2 != 0:
    N -= 1

tempN = int(N / 2)
ans = int(2 ** tempN)

temp = 10 ** 9 + 7
if ans > temp:
    ans %= temp

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
def power(x, y):
   if y == 0:
       return 1
   elif y == 1:
       return x % mod
   elif y % 2 == 0:
       return power(x, y/2) ** 2 % mod
   else:
       return power(x, (y-1)/2) ** 2 * x % mod

if N%2 == 0: # 偶数の時
	for i in range(N//2):
		if A.count(N-1-2*i) != 2:
			# print(N-1-2*i)
			print(0)
			break
	else:
		print(power(2,(N//2)))
else: # 奇数の時
	if A.count(0) != 1:
		print(0)
	else:
		for i in range((N-1)//2):
			if A.count(N-1-2*i) != 2:
				# print(N-1-2*i)
				print(0)
				break
		else:
			print(power(2,((N-1)//2)))

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

if N%2 == 0: # 偶数の時
	for i in range(N//2):
		if A.count(N-1-2*i) != 2:
			# print(N-1-2*i)
			print(0)
			break
	else:
		print(2**(N//2)%MOD)
else: # 奇数の時
	if A.count(0) != 1:
		print(0)
	else:
		for i in range((N-1)//2):
			if A.count(N-1-2*i) != 2:
				# print(N-1-2*i)
				print(0)
				break
		else:
			print(2**((N-1)//2)%MOD)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
import itertools
count = 0
check = tuple([int(abs((N-i+1)- i)) for i in range(1,N+1)])

import math
flag = True
for i in check[0:math.ceil(N/2)]:
    if A.count(i) != 2 and i != 0:
        flag = False
    if A.count(i) != 1 and i == 0:
        flag = False
        
if flag:
    print(2 ** (N//2))
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
import itertools
count = 0
check = tuple([int(abs((N-i+1)- i)) for i in range(1,N+1)])
for p in itertools.permutations(A):
    if p == check:
        count += 1
print(count)

Submission status: Time Limit Exceeded

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

if not(N % 2):
	for i in range(1, N, 2):
		if A.count(i) != 2:
			print(0)
			exit()
else:
	if A.count(0) != 1:
		print(0)
		exit()
	for i in range(2, N, 2):
		if A.count(i) != 2:
			print(0)
			exit()

mod = 10**9+7
print(2**(N//2) % mod)

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(input())
a = list(map(int, input().split()))
ans = 0
flag = 0
if n % 2 == 1:
  if a.count(0) != 1:
    print(0)
    sys.exit()
  else:
    sa = n-1
    while sa > 0:
      if a.count(sa) != 2:
        print(0)
        sys.exit()
      sa -= 2
else:
  if a.count(0) != 0:
    print(0)
    sys.exit()
  else:
    sa = n-1
    while sa > 0:
      if a.count(sa) != 2:
        print(0)
        sys.exit()
      sa -= 2


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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
flag = 0
if n % 2 == 1:
  if a.count(0) != 1: flag = 1
  else:
    sa = n-1
    while sa > 0:
      if a.count(sa) != 2:
        flag = 1
        break
      sa -= 2
else:
  if a.count(0) != 0: flag = 1
  else:
    sa = n-1
    while sa > 0:
      if a.count(sa) != 2:
        flag = 1
        break
      sa -= 2

if flag == 0:
  print(2 ** (n // 2))
else:
  print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
flag = 0
if n % 2 == 1:
  if a.count(0) != 1: flag = 1
  else:
    for i in range(n // 2 + 1):
      if a[i] != 0 and a.count(a[i]) != 2:
        flag = 1
else:
  if a.count(0) != 0: flag = 1
  else:
    for i in range(n // 2 + 1):
      if a.count(a[i]) != 2:
        flag = 1

if flag == 0:
  print(2 ** (n // 2))
else:
  print(0)