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()))
count=0
ans=1
if(N%2==0):
  flag=True
  for i in range(N//2):
    try:
      A.remove(2*i+1)
      try:
        A.remove(2*i+1)
        count+=1
        ans=(ans*2)%(10**9+7)
      except:
        flag=False
        break
    except:
      flag=False
      break
else:
  flag=True
  for i in range((N+1)//2):
    if(i==0):
      try:
        A.remove(0)
      except:
        flag=False
        break
    else:
      try:
        A.remove(2*i)
        try:
          A.remove(2*i)
          count+=1
          ans=(ans*2)%(10**9+7)
        except:
          flag=False
          break
      except:
        flag=False
        break
if(flag==True):
  print(ans)
else:
  print(0)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
count=0
if(N%2==0):
  flag=True
  for i in range(N//2):
    try:
      A.remove(2*i+1)
      try:
        A.remove(2*i+1)
        count+=1
      except:
        flag=False
        break
    except:
      flag=False
      break
else:
  flag=True
  for i in range((N+1)//2):
    if(i==0):
      try:
        A.remove(0)
      except:
        flag=False
        break
    else:
      try:
        A.remove(2*i)
        try:
          A.remove(2*i)
          count+=1
        except:
          flag=False
          break
      except:
        flag=False
        break
if(flag==True):
  print(2**count%(10**9+7))
else:
  print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
d = N // 2
a = [i for i in set(A) if A.count(i) == 2 and i != 0]
# ans = []
# def linking_up():
# ans_1 = [ i for i in range(N) if i % 2 == 1 and i!= 0 and A.count(i) == 2]
    # for i in range(N):
        # if i % 2 == 0 and i != 0:
            # if A.count(i) == 2 and A.count(0) == 1:
                # ans.append('c')
# ans_2 = [ i for i in range(N) if i % 2 == 0 and A.count(i) == 2]
        # else:
            # if A.count(i) == 2:
                # ans.append('a')
# linking_up()
if len(a) == d:
    a = (2 ** d) % (10 ** 9 + 7)
    print(a)
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
d = N // 2
ans = []
def linking_up():
    for i in range(N):
        if i % 2 == 0 and i != 0:
            if A.count(i) == 2 and A.count(0) == 1:
                ans.append('c')
        else:
            if A.count(i) == 2:
                ans.append('a')
linking_up()
if ans.count('a') == d or ans.count('c')== d:
    a = (2 ** d) % (10 ** 9 + 7)
    print(a)
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
d = N // 2
# ans = []
# def linking_up():
ans_1 = [ i for i in range(N) if i % 2 == 0 and i != 0 and A.count(i) == 2 and A.count(0) == 1]
    # for i in range(N):
        # if i % 2 == 0 and i != 0:
            # if A.count(i) == 2 and A.count(0) == 1:
                # ans.append('c')
ans_2 = [ i for i in range(N) if i % 2 and A.count(i) == 2]
        # else:
            # if A.count(i) == 2:
                # ans.append('a')
# linking_up()
if len(ans_1) == d or len(ans_2) == d:
    print(2 ** d)
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
d = N // 2
ans = []
def linking_up():
    for i in range(N):
        if i % 2 == 0 and i != 0:
            if A.count(i) == 2 and A.count(0) == 1:
                ans.append('c')
        else:
            if A.count(i) == 2:
                ans.append('a')
linking_up()
if ans.count('a') == d or ans.count('c')== d:
    print(2 ** d)
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
d = N // 2
ans = []
def linking_up():
    for i in range(N):
        if i % 2 == 0 and i != 0:
            if A.count(i) == 2 and A.count(0) == 1:
                ans.append('c')
            else:
                ans.append('b')
        else:
            if A.count(i) == 2:
                ans.append('a')
            else:
                ans.append('b')
linking_up()
if ans.count('a') == d or ans.count('c')== d:
    print(2 ** d)
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
d = N // 2
ans = []
def linking_up():
    for i in range(N):
        if i % 2 == 1:
            if A.count(i) == 2:
                ans.append('a')
            else:
                ans.append('b')
        elif i % 2 == 0 and i != 0:
            if A.count(i) == 2 and A.count(0) == 1:
                ans.append('c')
            else:
                ans.append('b')
linking_up()
if ans.count('a') == d or ans.count('c')== d:
    print(2 ** d)
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
d = N // 2
ans = []
def linking_up():
    if N % 2 == 0:
        for i in range(N):
            if i % 2 == 1:
                if A.count(i) == 2:
                    ans.append('a')
                else:
                    ans.append('b')
    else:
        for i in range(N):
            if i % 2 == 0 and i != 0:
                if A.count(i) == 2 and A.count(0) == 1:
                    ans.append('a')
                else:
                    ans.append('b')
linking_up()
if ans.count('a') == d:
    print(2 ** d)
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
s = 0
if n % 2 == 0:
    b = [int(i) for i in range(n) if i % 2 == 1]
    for i in b:
        c = a.count(i)
        if c != 2:
            s = 1
            break
    ans = 2 ** len(b) % (10**9 + 7)
else:
    b = [int(i) for i in range(n) if i % 2 == 0]
    for i in b:
        c = a.count(i)
        
        
        if c == 1 and i == 0:
            ans = 1
        elif c != 2:
            s = 1
            break
    ans = 2 ** (len(b)-1) % (10**9 + 7)

if s == 0:
    print(ans)
elif s == 1:
    print('0')

Submission status: Time Limit Exceeded

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

# 20:16
N = INT()
A = LIST()

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






        


    # c = Counter(A)
    # c = sorted(c.items(), key=lambda x: x[0], reverse = False)
    # if c[0][1] != 1:
        # print(0)
    # for i in c[1:]:
        # if c[0]

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

if len(A)%2 == 0:
    result = 2**(len(A)//2)
    for i in range(len(A)//2):
        if A.count(1+2*i) == 2:
            pass
        else:
            result = 0
            break
else:
    if A.count(0) == 1:
        result = 2**(len(A)//2)
        for i in range(1, len(A)//2):
            if A.count(2*i) == 2:
                pass
            else:
                result = 0
                break
    else:
        result = 0
print(result)

Submission status: Time Limit Exceeded

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

f = 1

if n%2 == 0:
    for i in range(n//2):
        if a.count((2*i)+1) != 2:
            f = 0
            break

else:
    if a.count(0) != 1:
        f == 0
    for i in range(n//2):
        if a.count((2*i)+2) != 2:
            f = 0
            break
if f == 0:
    print(f)
else:
    print(2**(n//2))

Submission status: Time Limit Exceeded

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

f = 1

if n%2 == 0:
    for i in range(n//2):
        if a.count(i*2+1) != 2:
            f = 0
            break

else:
    if a.count(0) != 1:
        f = 0
    for i in range(n//2):
        if a.count((i+1)*2) != 2:
            f = 0
            break

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

if n%2==1:
	if a.count(0)!=1:
		print(0)
		exit()
	n=int((n-1)/2)
	for j in range(n):
		if a.count((j+1)*2)!=2:
			print(0)
			exit()

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

Submission status: Time Limit Exceeded

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

if n%2==1:
	if a.count(0)!=1:
		print(0)
		exit()
	n=int((n-1)/2)
	for j in range(n):
		if a.count((j+1)*2)!=2:
			print(0)
			exit()

else :
	n=int(n/2)
	for j in range(n):
		if a.count(1+j*2)!=2:
			print(0)
			exit()
print(2**n)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
if n % 2 == 0:
    for i in range(n//2):
        if not a.count(2*i+1) == 2:
            print(0)
            break
    else: print(2**(n//2) % 1000000007)
else:
    for i in range(1,n//2+1):
        if not a.count(2*i) == 2:
            print(0)
            break
    else:
        if a.count(0) == 1:
            print(2**(n//2) % 1000000007)
        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(n//2):
        if not a.count(2*i+1) == 2:
            print(0)
            break
    else: print(2**(n//2))
else:
    for i in range(1,n//2+1):
        if not a.count(2*i) == 2:
            print(0)
            break
    else:
        if a.count(0) == 1:
            print(2**(n//2))
        else: print(0)

Submission status: Time Limit Exceeded

Solution code:
n,l=int(input()),list(map(int,input().split()))
if n%2==0:
  f=all(l.count(l[i])==2 for i in range(n))
else:
  f=all(l.count(l[i])==2 for i in range(n) if l[i]!=0) and l.count(0)==1
print(2**(n//2)%1000000007 if f==True else 0)

Submission status: Time Limit Exceeded

Solution code:
import sys

#計算量O(n/2)
N = int(input())
A = list(map(int,input().split()))
amari = 10**9 + 7
A.sort()

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

print(2**(N//2) % amari)

Submission status: Time Limit Exceeded

Solution code:
import sys

N = int(input())
A = list(map(int,input().split()))
amari = 10**9 + 7

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

print(2**(N//2) % amari)

Submission status: Time Limit Exceeded

Solution code:
m = 10**9+7
n = int(input())
a = list(map(int, input().split()))
check = 0
for i in set(a):
  if n%2 == 1:
    if i == 0 and a.count(i) == 1:
      pass
    elif i%2 == 0 and a.count(i) == 2:
      pass
    else:
      print(0)
      exit()
  else:
    if i%2 == 1 and a.count(i) == 2:
      pass
    else:
      print(0)
      exit()

print(2**(n//2)%m)

Submission status: Time Limit Exceeded

Solution code:
m = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
check = 0
for i in set(a):
  if n%2 == 1:
    if i == 0 and a.count(i) == 1:
      pass
    elif i%2 == 0 and a.count(i) == 2:
      pass
    else:
      print(0)
      exit()
  else:
    if i%2 == 1 and a.count(i) == 2:
      pass
    else:
      print(0)
      exit()

print(2**(n//2)%m)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
check = 0
for i in set(a):
  if n%2 == 1:
    if i == 0 and a.count(i) == 1:
      pass
    elif i%2 == 0 and a.count(i) == 2:
      pass
    else:
      print(0)
      exit()
  else:
    if i%2 == 1 and a.count(i) == 2:
      pass
    else:
      print(0)
      exit()

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

Submission status: Time Limit Exceeded

Solution code:
mod = 10 ** 9 + 7
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:
            pass
        else:
            print(0)
            exit()
    ans = (2 ** (N // 2))%mod

else:
    for i in range(0, N, 2):
        if i == 0:
            if A.count(i) == 1:
                pass
            else:
                print(0)
                exit()
        else:
            if A.count(i) == 2:
                pass
            else:
                print(0)
                exit()
        ans = (2 ** (N // 2)) % mod

print(ans)

Submission status: Time Limit Exceeded

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

if N % 2 == 0:
    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()

print(2 ** (N // 2) % mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
imput=sys.stdin.readline
import collections
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=1
if n%2==1 and collections.Counter(a)[0]==1:
    for i in range(2,n,2):
        if collections.Counter(a)[i]!=2:
            print(0)
            break
        else:
            ans=(ans%(10**9+7))*2%(10**9+7)
    else:
        print(ans%(10**9+7))
elif n%2==0:
    for i in range(1,n,2):
        if collections.Counter(a)[i]!=2:
            print(0)
            break
        else:
            ans=(ans%(10**9+7))*2%(10**9+7)
    else:
        print(ans%(10**9+7))
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
import collections
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=1
if n%2==1 and collections.Counter(a)[0]==1:
    for i in range(2,n,2):
        if collections.Counter(a)[i]!=2:
            print(0)
            break
        else:
            ans=(ans%(10**9+7))*2%(10**9+7)
    else:
        print(ans%(10**9+7))
elif n%2==0:
    for i in range(1,n,2):
        if collections.Counter(a)[i]!=2:
            print(0)
            break
        else:
            ans=(ans%(10**9+7))*2%(10**9+7)
    else:
        print(ans%(10**9+7))
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
import collections
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=1
if n%2==1 and collections.Counter(a)[0]==1:
    for i in range(2,n,2):
        if collections.Counter(a)[i]!=2:
            print(0)
            break
        else:
            ans=ans*2%(10**9+7)
    else:
        print(ans%(10**9+7))
elif n%2==0:
    for i in range(1,n,2):
        if collections.Counter(a)[i]!=2:
            print(0)
            break
        else:
            ans=ans*2%(10**9+7)
    else:
        print(ans%(10**9+7))
else:
    print(0)

Submission status: Time Limit Exceeded

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

if n%2==1 and collections.Counter(a)[0]==1:
    for i in range(2,n,2):
        if collections.Counter(a)[i]!=2:
            print(0)
            break
    else:
        print(2**(n//2)%(10**9+7))
elif n%2==0:
    for i in range(1,n,2):
        if collections.Counter(a)[i]!=2:
            print(0)
            break
    else:
        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()))
ok = True
cnt = n%2+1
for i in range(cnt,n,2):
    if a.count(i)!=2:
        ok = False
        break
if ok:
    print(2**(n//2))
else:
    print(0)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!python3.4.3

n = int(input())
a_list = list(map(int, input().split(' ')))
a_list.sort()
A = 2**(n//2)%(10**9+7)

for i in range(1, n):
    c = a_list.count(i)
    if c%2 != 0:
        A = 0
        break
print(A)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
def examC(mod):
    N = I()
    A = LI()
    num = (N+1)%2
    loop = (N+1)//2
    cur = int(1)
    if num==0:
        A.append(0)
        cur = cur/2
    for i in range(loop):
        if A.count(i*2+num)!=2:
            cur = int(0)
            break
        cur = int(cur*2)%mod
    print(cur)




import sys
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC(mod)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
set_A = set(A)

ans = 1

if n%2==0:
  for a_i in set_A:
    if A.count(a_i)!=2:
      ans = 0
      break
else:
  if A.count(0)!=1:
    ans = 0
  
  set_A.remove(0)
  for a_i in set_A:
    if A.count(a_i)!=2:
      ans = 0
      break
      
if ans!=0:
  ans = 2**(len(set_A))

print(ans%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
INFTY = 10**9+7
N = int(input())
A = list(map(int,input().split()))
if N%2==0:
    flag = 0
    for i in range(1,N,2):
        if A.count(i)==2:
            pass
        else:
            flag = 1
            break
else:
    flag = 0
    for i in range(2,N,2):
        if A.count(i)==2:
            pass
        else:
            flag = 1
            break
    if A.count(0)!=1:
        flag = 1
if flag==0:
    cnt = 1
    for i in range(N//2):
        cnt = (cnt*2)%INFTY
else:
    cnt = 0
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
mod = 10 ** 9 + 7
N = int(input())
A = [int(a) for a in input().split()]

# Nが偶数ならAiは全て奇数、Nが奇数なら Aiは全て偶数でなければならない,なぜなら、2x + Ai = N - 1を満たすxが自然数(非負整数)でなければならないから
# さらに、Nが奇数の時はfor i in range(0, N, 2) において 0が１個、それ以外のiが２個ずつ存在しなければならず(これはAiが全て偶数であることも満たしている)、
# Nが偶数の時はfor i in range(1, N, 2) において 全てのiが２個ずつ存在しなければならない(これはAiがすべて奇数であることも満たしている)
# これを踏まえた上でNが偶数の時は N/2人の位置が決まれば反対側の人の位置も決まり、Nが奇数の時は中央の人は固定として、それ以外 (N-1)/2人の位置が決まれば残りの人は反対側で位置が決まる。それぞれ２通りなので、
# よって
if N % 2 != 0:
    for i in range(0, N, 2):
        if A.count(i) == 2:
            continue
        elif A.count(0) == 1:
            continue
        print(0)
        exit()
    
    #order_count = 1
    #for i in range((N - 1) // 2):
    order_count = 2 ** ((N - 1) // 2) % mod

else:
    for i in range(1, N, 2):
        if A.count(i) != 2:
            print(0)
            exit()
    #order_count = 1
    #for i in range(N // 2):
    order_count = 2 ** (N // 2) % mod

print(order_count)

Submission status: Time Limit Exceeded

Solution code:
mod = 10 ** 9 + 7
N = int(input())
A = [int(a) for a in input().split()]

# Nが偶数ならAiは全て奇数、Nが奇数なら Aiは全て偶数でなければならない,なぜなら、2x + Ai = N - 1を満たすxが自然数(非負整数)でなければならないから
# さらに、Nが奇数の時はfor i in range(0, N, 2) において 0が１個、それ以外のiが２個ずつ存在しなければならず(これはAiが全て偶数であることも満たしている)、
# Nが偶数の時はfor i in range(1, N, 2) において 全てのiが２個ずつ存在しなければならない(これはAiがすべて奇数であることも満たしている)
# これを踏まえた上でNが偶数の時は N/2人の位置が決まれば反対側の人の位置も決まり、Nが奇数の時は中央の人は固定として、それ以外 (N-1)/2人の位置が決まれば残りの人は反対側で位置が決まる。それぞれ２通りなので、
# よって
if N % 2 != 0:
    for i in range(0, N, 2):
        if A.count(i) == 2:
            continue
        elif A.count(0) == 1:
            continue
        print(0)
        exit()
    
    order_count = 1
    for i in range((N - 1) // 2):
        order_count = order_count * 2 % mod

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

print(order_count)

Submission status: Time Limit Exceeded

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

# Nが偶数ならAiは全て奇数、Nが奇数なら Aiは全て偶数でなければならない,なぜなら、2x + Ai = N - 1を満たすxが自然数(非負整数)でなければならないから
# さらに、Nが奇数の時はfor i in range(0, N, 2) において 0が１個、それ以外のiが２個ずつ存在しなければならず(これはAiが全て偶数であることも満たしている)、
# Nが偶数の時はfor i in range(1, N, 2) において 全てのiが２個ずつ存在しなければならない(これはAiがすべて奇数であることも満たしている)
# これを踏まえた上でNが偶数の時は N/2人の位置が決まれば反対側の人の位置も決まり、Nが奇数の時は中央の人は固定として、それ以外 (N-1)/2人の位置が決まれば残りの人は反対側で位置が決まる。それぞれ２通りなので、
# よって
if N % 2 != 0:
    for i in range(0, N, 2):
        if A.count(i) == 2:
            continue
        elif A.count(0) == 1:
            continue
        print(0)
        exit()
    order_count = 2 ** ((N - 1) // 2)

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

print(order_count)

Submission status: Time Limit Exceeded

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

if N%2==1:
  B = list(map(abs,range(2, N, 2)))
else:
  B = list(map(abs,range(1, N, 2)))
  
if N%2==1 and A.count(0)!=1:
  print(0)
  exit()
  
for i in B:
  if A.count(i) !=2:
    print(0)
    exit()
  
print(2 ** int(N/2))

Submission status: Time Limit Exceeded

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


def is_valid():
    if n % 2 == 1 and A.count(0) != 1:
        return False

    for a in A:
        if n % 2 == a % 2:
            return False
        if a != 0 and A.count(a) != 2:
            return False
    return True


if not is_valid():
    print(0)
    exit()

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()))
mod = 10**9 + 7

if N % 2 == 1:
    A.remove(0)

A_set = set(A)
for i in A_set:
    if A.count(i) % 2 != 0:
        print(0)
        sys.exit()

cnt = 2**len(A_set) % mod
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys

N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7

if N % 2 == 1:
    A.remove(0)

A_set = set(A)
for i in A_set:
    if A.count(i) % 2 == 0:
        continue
    else:
        print(0)
        sys.exit()

cnt = 1
for j in range(len(A_set)):
    cnt = (cnt * 2) % mod
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys

N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7

if N % 2 == 1:
    A.remove(0)

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

cnt = 1
for j in range(len(set(A))):
    cnt = (cnt * 2) % mod
print(cnt)

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+1):
    if a.count(i*2-1) != 2:
      print(0)
      exit()
  print(2**(n//2))
else:
  if a.count(0) != 1:
    print(0)
    exit()
  for i in range(1,n//2):
    if a.count(i*2) != 2:
      print(0)
      exit()
  print(2**(n//2))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = list(map(int, input().split()))
l_2 = []
gusu_kisu = N % 2
end_F = 0
for i in range(N):
    if gusu_kisu == 1:
        An = l[i]
        if An % 2 == 1:
            end_F = 1
            break
        elif An == 0 and l_2.count(0) == 1:
            end_F = 1
            break
        elif l_2.count(An) == 2:
            end_F = 1
            break
        else:
            l_2.append(An)
    else:
        An = l[i]
        if An % 2 == 0:
            end_F = 1
            break
        elif l_2.count(An) == 2:
            end_F = 1
            break
        else:
            l_2.append(An)
#     print(An)
# print(end_F)
if end_F == 0:
    print((2 ** (N // 2)) % 1000000007)
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = list(map(int, input().split()))
l_2 = []
gusu_kisu = N % 2
end_F = 0
for i in range(N):
    if gusu_kisu == 1:
        An = l[i]
        if An % 2 == 1:
            end_F = 1
            break
        elif An == 0 and l_2.count(0) == 1:
            end_F = 1
            break
        elif l_2.count(An) == 2:
            end_F = 1
            break
        else:
            l_2.append(An)
    else:
        An = l[i]
        if An % 2 == 0:
            end_F = 1
            break
        elif l_2.count(An) == 2:
            end_F = 1
            break
        else:
            l_2.append(An)
#     print(An)
# print(end_F)
if end_F == 0:
    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(' ')))

false_flag = 0
if N % 2 == 0:
    count_ = 1
else:
    if A.count(0) != 1:
        false_flag = 1
    count_ = 2
while count_ < N and false_flag == 0:
    if A.count(count_) != 2:
        false_flag = 1
    count_ += 2

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

aa = dict.fromkeys(a)
f = 0
cnt = 0
for i in aa:
  if i == 0:
    if a.count(0) == 1:
      continue
    else:
      f = 1
  else:
    if a.count(i) == 2:
      cnt += 1
    else:
      f = 1
if f == 0:
  print(pow(2, cnt))
else:
  print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = [int(num) for num in input().split()]

cont = False
if n % 2 == 1:
  if A.count(0) != 1:
    cont = True
  else:
    for i in range(2, n, 2):
      if A.count(i) != 2:
        cont = True
        break
else:
  for i in range(1, n, 2):
    if A.count(i) != 2:
      cont = True
      break

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = [int(num) for num in input().split()]

cont = False
if n % 2 == 1:
  if A.count(0) != 1:
    cont = True
  for i in range(2, n, 2):
    if A.count(i) != 2:
      cont = True
      break
else:
  for i in range(1, n, 2):
    if A.count(i) != 2:
      cont = True
      break

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

Submission status: Time Limit Exceeded

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

if A.count(0)>1:
  print(0)
  exit()
m=n
for i in set(A):
  if A.count(i)>3:
    print(0)
    exit()
  else:
    m-=1
print(2**m)