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: Wrong Answer

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)









if __name__=="__main__":
    main()

Submission status: Wrong Answer

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









if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
MOD=1000000007
A=list(map(int,input().split()))
cnt=[0 for i in range(N)]
for i in range(N):
    cnt[A[i]]+=1
if N%2==0:
    for i in range(1,N,2):
        if cnt[i]!=2:
            print(0)
            break
    else:
        print(2**(N//2)%MOD)
else:
    if cnt[0]!=1:
        print(0)
    else:
        for i in range(2,(N+1)//2,2):
            if cnt[i]!=2:
                print(0)
                break
        else:
            print(2**((N-1)//2))

Submission status: Wrong Answer

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

a.sort()

if n%2==0:
    for i in range(n//2):
        if a[i*2]!=i*2+1 or a[i*2+1]!=i*2+1:
            print(0)
            exit()
    
    print(2**(n//2))


else:
    if a[0]!=0:
        print(0)
        exit()
    
    b=a[1:]

    for i in range(n//2):
        if b[i*2]!=i*2+2:
            print(0)
            exit()
        
        if b[i*2+1]!=i*2+2:
            print(0)
            exit()

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

Submission status: Wrong Answer

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

from collections import Counter
l=list(Counter(A).values())

if N%2==0 and set(l[1:])!={2}:
    print(0)
elif N%2==1 and (l[0]!=1 or set(l[1:])!={2}):
    print(0)
else:
    print(2**(N//2)%(10**9+7))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
if n%2==1:
    x=[i for i in range(n)]
    for i in range(n):
        if i%2==1:
            x[i]+=1
else:
    x=[i for i in range(n)]
    for i in range(n):
        if i%2==0:
            x[i]+=1
a.sort()
if x==a:
    print(2**((n+1)//2-1))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
Sum = 1
mod = 1000000007

a.sort()
data = []
if N % 2 == 0:
    for i in range(int(N / 2)):
        data.append(1 + i * 2)
        data.append(1 + i * 2)
else:
    data.append(0)
    for i in range(1, N // 2 + 1):
        data.append(i * 2)
        data.append(i * 2)

if a == data:
    for i in range(N // 2):
        Sum *= 2
        Sum % mod
    print(Sum)
else:
    print(0)

Submission status: Wrong Answer

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

lst=[0]*n

for i in a:
  lst[i]+=1
  
if lst[0]>=2:
  print(0)
  exit()
  
if lst[0]==0:
  for i in range(n):
    if i%2==1:
      if lst[i]!=2:
        print(0)
        exit()
      
      else:
        ans*=2

    else:
        if lst[i]!=0:
            print(0)
            exit()

else:
  for i in range(1,n):
    if i%2==0:
      if lst[i]!=2:
        print(0)
        exit()
      
      else:
        ans*=2

    else:
        if lst[i]!=0:
            print(0)
            exit()


print(ans)

Submission status: Wrong Answer

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

lst=[0]*n

for i in a:
  lst[i]+=1
  
if lst[0]>=2:
  print(0)
  exit()
  
if lst[0]==0:
  for i in range(n):
    if i%2==1:
      if lst[i]!=2:
        print(0)
        exit()
      
      else:
        ans*=2

    else:
        if lst[i]!=0:
            print(0)
            exit()

else:
  for i in range(n):
    if i%2==0:
      if lst[i]!=2:
        print(0)
        exit()
      
      else:
        ans*=2

    else:
        if lst[i]!=0:
            print(0)
            exit()


print(ans)

Submission status: Wrong Answer

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

lst=[0]*n

for i in a:
  lst[i]+=1
  
if lst[0]>=2:
  print(0)
  exit()
  
if lst[0]==0:
  for i in range(n):
    if i%2==1:
      if lst[i]!=2:
        print(0)
        exit()
      
      else:
        ans*=2

    else:
        if lst[i]!=0:
            print(0)
            exit()

else:
  for i in range(10**5+10):
    if i%2==0:
      if lst[i]!=2:
        print(0)
        exit()
      
      else:
        ans*=2

    else:
        if lst[i]!=0:
            print(0)
            exit()


print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
from collections import Counter as co
c=co(list(map(int,input().split())))
ans=2**(n//2)
if n%2 :
    if 0 not in c or c[0]>1:ans=0
    for i in range(1,n):
        if i%2==0 :
            if i not in c or c[i]!=2:ans=0;break
        else:
            if i in c:ans=0;break
else:
    if 0 in c:ans=0
    for  i in range(1,n):
        if i%2:
            if i not in c or c[i]!=2:ans=0;break
        else:
            if i in c:ans=0;break
print(ans)

Submission status: Wrong Answer

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

valid = True

if num % 2 == 1: # odd
  check = list(range(0,num+1,2))[1:]
  
  valid1 = t[0] == 0
  valid2 = check == t[2::2] # even, skip first
  valid3 = check == t[1::2] # odd
  valid = valid1 and valid2 and valid3
  
  if not valid:
    print(0)
  else:
    ans = 2**((num-1)//2) % (10**9 + 7)
    print(ans)
  
else: # even 
  check = list(range(1,num,2))
  
  valid1 = True
  valid2 = check == t[::2] # even
  valid3 = check == t[1::2] # odd
  valid = valid1 and valid2 and valid3
  
  if not valid:
    print(0)
  else:
    ans = 2**((num-1)//2) % (10**9 + 7)
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
a=sorted(list(map(int,input().split())))
ans=1
flag=(n+1)%2
if flag==0:
  if a[0]==0:
    a.pop(0)
  else:
    print(0)
    sys.exit()
else:
  if a[0]==a[1]==1:
    a.pop(0)
    a.pop(0)
    ans*=2
  else:
    print(0)
    sys.exit()
for i in range((n-flag-1)//2):
  if a[i*2]==a[i*2+1]==flag+(i+1)*2:
    ans*=2
  else:
    print(0)
    sys.exit()
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().strip()
mod = 10**9+7

def main():
    N = int(input())
    A = list(map(int, input().split()))
    d = defaultdict(int)
    for a in A: d[a] += 1
    if N % 2 != 0:
        for key in d:
            if key == 0:
                if d[0] != 1:
                    print(0)
                    return
            elif key % 2 != 0 or key >= N or d[key] != 2:
                print(0)
                return
    else:
        for key in d:
            if key % 2 == 0 or key >= N or d[key] != 2:
                print(0)
    print(pow(2, N // 2, mod))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
mod=10**9+7
if n%2==0:
    d={i:2 for i in range(1,n,2)}
else:
    d={i:2 for i in range(0,n,2)}
    d[0]=1
for a in l:
    if a in d:
        d[a]-=1
    else:
        print(0)
        exit()
for i in d.values():
    if i!=0:
        print(0)
        exit()
print(2**(n//2))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
mod=10**9+7
if n%2==0:
    d={i:2 for i in range(1,n,2)}
else:
    d={i:2 for i in range(0,n,2)}
    d[0]=1
for a in l:
    if a in d:
        if d[a]==0:
            print(0)
            exit()
        d[a]-=1
    else:
        print(0)
        exit()
print((n//2)**2)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
mod=10**9+7
if n%2==0:
    d={i:2 for i in range(1,n,2)}
else:
    d={i:2 for i in range(0,n,2)}
    d[0]=1
for a in l:
    if a in d:
        if d[a]==0:
            print(0)
            exit()
        d[a]-=1
    else:
        print(0)
        exit()
print(2**(n//2))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = sorted(Counter([int(T) for T in input().split()]).most_common(),key=lambda X:X[0])
PassFlag = True
if N%2==1:
    for TA in range(0,(N+1)//2):
        if A[TA][0]!=(2*TA) or A[TA][1]!=(1+(A[TA][0]!=0)):
            PassFlag = False
            break
    print([0,2**((N-1)//2)][PassFlag])
else:
    for TA in range(0,N//2):
        if A[TA][0]!=(2*TA+1) or A[TA][1]!=2:
            PassFlag = False
            break
    print([0,2**(N//2)][PassFlag])

Submission status: Wrong Answer

Solution code:
def main():
  N = int(input())
  A = [int(a) for a in input().split(" ")]
  A.sort()
 
  if N % 2 == 1 and A.count(0) != 1:
    print(0)
    return 0
  elif N % 2 == 0 and A.count(0) > 0:
    print(0)
    return 0
  
  if N % 2 == 1:
    A.pop(0)
  
  cnt = 0
  while len(A) > 0:
    if A[0] != A[1] or (len(A) > 2 and A[0] == A[1] and A[1] == A[2]):
      print(0)
      return 0
    elif A[0] == A[1] == 2 * cnt + (N % 2) + 1:
      cnt += 1
      A.pop(0)
      A.pop(0)
    else:
      print(0)
      return 0
 
  ans = 1
  for p in range(cnt):
    ans = (ans * 2) % 1000000009
  print(ans)

main()

Submission status: Wrong Answer

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

  if N % 2 == 1 and A.count(0) != 1:
    print(0)
    return 0
  elif N % 2 == 0 and A.count(0) > 0:
    print(0)
    return 0
  
  if N % 2 == 1:
    A.pop(0)
  
  cnt = 0
  while len(A) > 0:
    if A[0] != A[1] or (len(A) > 2 and A[0] == A[1] and A[1] == A[2]):
      print(0)
      return 0
    elif A[0] == A[1] == 2 * cnt + (N % 2) + 1:
      cnt += 1
      A.pop(0)
      A.pop(0)
    else:
      print(0)
      return 0

  ans = 1
  for p in range(cnt):
    ans = (ans * 2) % 1000000009
  print(ans)
      

main()

Submission status: Wrong Answer

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


a = sorted(a)

num = 0
judge = 0

if len(a)%2 == 1:
    if a[0] == 0:
        for i in range(1, n, 2):
            if a[i] == i+1 and a[i+1] == i+1:
                num += 1
            else:
                print(0)
                judge = 1
                break
    else:
        print(0)
        judge=1
else:
    for i in range(0, n, 2):
            if a[i] == i+1 and a[i+1] == i+1:
                num += 1
            else:
                print(0)
                judge = 1
                break
        
if judge == 0:
    result = (2**num)%10000000007
    print(result)

Submission status: Wrong Answer

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

if n%2==0:
    b=list(range(1,n,2))
    for i in range(n//2):
        if a.count(b[i])!=2:
            print("0")
            flag+=1
            break
if n%2==1:
    c=list(range(0,n,2))
    for i in range(n//2):
        if i==0:
            if a.count(c[i])!=1:
                print("0")
                flag+=1
                break

        else:
            if a.count(c[i])!=2:
                print("0")
                flag+=1
                break
        
if flag==0:
    print(((n//2)**2)%(10**9+7))

Submission status: Wrong Answer

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

if n%2==0:
    b=list(range(1,n,2))
    for i in range(n//2):
        if a.count(b[i])!=2:
            print("0")
            flag+=1
            break
if n%2==1:
    c=list(range(0,n,2))
    for i in range(n//2):
        if i==0:
            if a.count(c[i])!=1:
                print("0")
                flag+=1
                break

        else:
            if a.count(c[i])!=2:
                print("0")
                flag+=1
                break
        
if flag==0:
    print((n//2)**2)

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int, input().split()))
# 絶対値の差は、
# 奇数の場合はN+1から2ずつ減らして行った分しかない。(N+1)/2
# 偶数の場合はNから2ずつ減らして行った分しかない。N/2
nums = {}
exists = True
if N % 2 == 0:
    for A in As:
        if A in nums:
            nums[A] += 1
        else:
            nums[A] = 1
    for key, value in nums.items():
        if key == 0:
            exists = False
        if key % 2 == 1:
            exists = False
        if value != 2:
            exists = False

else:
    for A in As:
        if A in nums:
            nums[A] += 1
        else:
            nums[A] = 1
    for key, value in nums.items():
        if key == 0:
            if value != 1:
                exists = False
        else:
            if value != 2:
                exists = False
if not exists:
    print(0)
else:
    ans = 1
    if N % 2 == 0:
        for i in range(int(N / 2)):
            ans = ans * 2
            ans %= 10**9 + 7
    else:
        for i in range(int((N - 1) / 2)):
            ans = ans * 2
            ans %= 10**9 + 7
            # 絶対値の差は0の時は1人だけ。そのほかは2人だけ。これが満たせるなら
            # (偶数)2**(N+1/2)
            # (奇数)2**(N/2)
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int, input().split()))
# 絶対値の差は、
# 奇数の場合はN+1から2ずつ減らして行った分しかない。(N+1)/2
# 偶数の場合はNから2ずつ減らして行った分しかない。N/2
nums = {}
exists = True
if N % 2 == 0:
    for A in As:
        if A in nums:
            nums[A] += 1
        else:
            nums[A] = 1
    for key, value in nums.items():
        if value != 2:
            exists = False

else:
    for A in As:
        if A in nums:
            nums[A] += 1
        else:
            nums[A] = 1
    for key, value in nums.items():
        if key == 0:
            if value != 1:
                exists = False
        else:
            if value != 2:
                exists = False
if not exists:
    print(0)
else:
    ans = 2
    if N % 2 == 0:
        for i in range(1, int(N / 2)):
            ans = ans * 2
            ans %= 10**9 + 7
    else:
        for i in range(1, int((N - 1) / 2)):
            ans = ans * 2
            ans %= 10**9 + 7
            # 絶対値の差は0の時は1人だけ。そのほかは2人だけ。これが満たせるなら
            # (偶数)2**(N+1/2)
            # (奇数)2**(N/2)
    print(ans)

Submission status: Wrong Answer

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

if n % 2 == 0:
    b = [1,1]
    s = 3
else:
    b = [0]
    s = 2

for i in range(s,n,2):
    b += [i,i]
if a == b:
    print(2 ** (len(b) // 2) % 100000007)
else:
    print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

B = [0] * N

for a in A:
    B[a] += 1

ok = True

if N % 2 == 1:
    ok = ok and B[0] == 1
    for i in range(1, N):
        ok = ok and B[i] == (2 if i % 2 == 0 else 0)
else:
    for i in range(N):
        ok = ok and B[i] == (0 if i % 2 == 0 else 2)

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

Submission status: Wrong Answer

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

B = [0] * N

for a in A:
    B[a] += 1

ok = True

if N % 2 == 1:
    ok = ok and B[0] == 1
    for i in range(1, N):
        ok = ok and B[i] == 2 if i % 2 == 0 else 0
else:
    for i in range(N):
        ok = ok and B[i] == 0 if i % 2 == 0 else 2

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

Submission status: Wrong Answer

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

B = [0] * N

for a in A:
    B[a] += 1

ok = True

if N % 2 == 1:
    ok = ok and B[0] == 1
    for i in range(1, (N + 1) // 2):
        ok = ok and B[2 * i] == 2
else:
    for i in range(N // 2):
        ok = ok and B[2 * i + 1] == 2

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

Submission status: Wrong Answer

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

B = [0] * N

for a in A:
    B[a] += 1

ok = True

if N % 2 == 1:
    ok = ok and B[0] == 1
    for i in range(1, (N + 1) // 2):
        ok = ok and B[2 * i] == 2
else:
    for i in range(N // 2):
        ok = ok and B[2 * i + 1]

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

Submission status: Wrong Answer

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

B = [0] * ((N + 1) // 2)
for a in A:
    B[a // 2] += 1

if B.count(2) == (N // 2):
    if N % 2 == 1 and B[0] != 1:
        print(0)
    else:
        print(2 ** (N // 2))
else:
    print(0)

Submission status: Wrong Answer

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

if n%2 == 0:
  for i in range(0,n-1,2):
    if a[i] == a[i+1]: continue
    print(0)
    exit()
else:
  if a[0] != 0:
    print(0)
    exit()
  for i in range(1,n-1,2):
    if a[i] == a[i+1]: continue
    print(0)
    exit()
      
ans = 1
for i in range(n//2):
  ans += 2**i
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
a=sorted(list(map(int,input().split())))
a_count=Counter(a)
if n%2==1:
    ans=1
    for i in a_count:
        if i==0:
            if a_count[i]!=1:
                print(0)
                break
        else:
            if a_count[i]==2:
                ans*=2
            else:
                print(0)
                break
    else:
      print(ans)
else:
    ans=1
    for j in a_count:
        if a_count[j]==2:
            ans*=2
        else:
            print(0)
            break
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
a=sorted(list(map(int,input().split())))
a_count=Counter(a)
if n%2==1:
    ans=1
    for i in a_count:
        if i==0:
            if a_count[i]>1:
                print(0)
                break
        else:
            if a_count[i]==2:
                ans*=2
            else:
                print(0)
                break
    else:
      print(ans)
else:
    ans=1
    for j in a_count:
        if a_count[j]==2:
            ans*=2
        else:
            print(0)
            break
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy,deepcopy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N = i()
A = l()
ans = 1
l = [0]*N
for i in range(N):
    l[A[i]] += 1
for i in range(N):
    c = l[i]
    if N%2 == i%2:
        if c:
            ans *= 0
    else:
        if c == 0:
            ans *= 0
        if c == 1:
            if i != 0:
                ans *= 0
        if c == 2:
            ans *= 2
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c=Counter(a)
ans=1
if n%2==1:
    for i in range(n):
        if i%2==1 and c[i]>0:
            ans=0
            break
        elif i%2==0 and c[i]==2:
            ans*=2
        if i==0 and c[i]!=1:
            ans=0
            break
else:
    for i in range(n):
        if i%2==0 and c[i]>0:
            ans=0
            break
        elif i%2==1 and c[i]==2:
            ans*=2
print(ans)

Submission status: Wrong Answer

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

a.sort()

if n%2 == 1: 
    if a[0] != 0:
        print(0)
        exit()
    else:
        a.remove(0)
        tmp = 2
else:
    tmp = 1

for i in range(n//2):
    if tmp == a[0] and tmp == a[1]:
        a.remove(tmp)
        a.remove(tmp)
    else:
        print(0)
        exit()
    tmp += 2

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

ans=1
mod=10**9+7
cnt=Counter(A)
for key,count in cnt.most_common():
    if key==0 and count>1:
        print(0)
        exit()
    if key!=0 and count==1:
        print(0)
        exit()
    if count>2:
        print(0)
        exit()

    if count==2:
        ans*=2
        ans%mod

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

ans=1
mod=10**9+7
cnt=Counter(A)
for key,count in cnt.most_common():
    if key!=0 and count==1:
        print(0)
        exit()
    if count>2:
        print(0)
        exit()

    if count==2:
        ans*=2
        ans%mod

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

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

X = [0] * N
for i, a in enumerate(A):
    j = (N - 1 - a) // 2
    X[j] += 1

for i, x in enumerate(X):
    if x == 1 and not (i == (N + 1) // 2):
        print(0)
        exit()
    if x > 2:
        print(0)
        exit()

ans = 1
for x in X:
    if x == 0:
        break
    ans *= x
    ans %= MOD
print(ans)

Submission status: Wrong Answer

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

a.sort()
if n % 2 == 0:
  if a[0] == 1 and a[1] == 1:
    for i in range(2, n, 2):
      if a[i] == a[i + 1] and a[i - 1] + 2 == a[i]:
        continue
      else:
        flg = 1
        break
  else:
    flg = 1
else:
  if a[0] == 0:
    for i in range(1, n, 2):
      if a[i] == a[i + 1] and a[i - 1] + 2 == a[i]:
        continue
      else:
        flg = 1
        break
  else:
    flg = 1

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

Submission status: Wrong Answer

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

a.sort()
if n % 2 == 0:
  if a[0] == 1 and a[1] == 1:
    for i in range(2, n, 2):
      if a[i] == a[i + 1]:
        continue
      else:
        flg = 1
        break
  else:
    flg = 1
else:
  if a[0] == 0:
    for i in range(1, n, 2):
      if a[i] == a[i + 1]:
        continue
      else:
        flg = 1
        break
  else:
    flg = 1

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

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
p=10**9+7

def main(n,a):
  h=n//2
  g=n%2
  a.sort()
  c=[2*(x//2)+g+1 for x in range(n-g)]
  if g==1:
    c.insert(0,0)
  if a!=c:
      return 0
  return 2**(h%(p-1))

if __name__=='__main__':
  n=int(input())
  a=list(map(int,sys.stdin.readline().strip().split()))
  print(main(n,a))

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
p=10**9+7

def main(n,a):
  h=n//2
  g=n%2
  if g==1:
    if a.count(0)!=1:
      return 0
    else:
      del a[a.index(0)]
  b=[0]*(n-g)
  d=deque(a)
  while d:
    x=d.pop()
    b[x-1-g]=x
    b[x-g]=x
  c=[2*(x//2)+g+1 for x in range(n-g)]
  if g==1:
    b.insert(0,0)
    c.insert(0,0)
  if b!=c:
      return 0
  return 2**(h%(p-1))
n=int(input())
a=list(map(int,sys.stdin.readline().strip().split()))

print(main(n,a))

Submission status: Wrong Answer

Solution code:
import sys
p=10**9+7

def main(n,a):
  h=n//2
  g=n%2
  a.sort()
  c=[2*(x//2)+g+1 for x in range(n-g)]
  if g==1:
    c.insert(0,0)
  if c!=a:
      return 0
  return 2**(h%(p-1))
n=int(input())
a=list(map(int,sys.stdin.readline().strip().split()))

print(main(n,a))

Submission status: Wrong Answer

Solution code:
import sys
p=10**9+7

def main(n,a):
  h=n//2
  if a.count(0)!=n%2:
    return 0
  for x in range(n%2+1,h,2):
    if a.count(x)!=2:
      return 0
  return 2**(h%(p-1))
n=int(input())
a=list(map(int,sys.stdin.readline().strip().split()))

print(main(n,a))

Submission status: Wrong Answer

Solution code:
MOD = 10 ** 9 + 7
num = [0] * (10 ** 5 + 1)
N = int(input())
A = list(map(int,input().split()))
for i in range(len(A)):
	num[A[i]] += 1
if N % 2 == 1:
	for i in range(0,N,2):
		cnt = num[i]
		if i == 0:
			if cnt != 1:
				print(0)
				exit()
		else:
			if cnt != 2:
				print(0)
				exit()
	print(2 ** (N // 2))
else:
	for i in range(1,N,2):
		cnt = num[i]
		if cnt != 2:
			print(0)
			exit()
	print(2 ** (N // 2) % MOD)

Submission status: Wrong Answer

Solution code:
MOD = 10 ** 9 + 7
num = [0] * (10 ** 5 + 1)
N = int(input())
A = list(map(int,input().split()))
for i in range(len(A)):
	num[A[i]] += 1
if N % 2 == 1:
	for i in range(0,N,2):
		cnt = num[i]
		if i == 0:
			if cnt != 1:
				print(0)
				exit()
		else:
			if cnt != 2:
				print(0)
				exit()
	print(2 ** (N // 2))
else:
	for i in range(1,N,2):
		cnt = num[i]
		if cnt != 2:
			print(0)
			exit()
	print(2 ** (N // 2))

Submission status: Wrong Answer

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

if len(a)%2 == 0:
    for i in range(0, len(a), 2):
        if a[i] != i + 1 or a[i + 1] != i + 1:
            print(0)
            exit()
else:
    if a[0] != 0:
        print(0)
        exit()
    for i in range(1, len(a), 2):
        if a[i] != i + 1 or a[i + 1] != i + 1:
            print(0)
            exit()

for i in range(len(a)//2):
    ans *= 2

print(ans)

Submission status: Wrong Answer

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

if len(a)%2 == 0:
    for i in range(0, len(a), 2):
        if a[i] != a[i + 1]:
            print(0)
            exit()
else:
    for i in range(1, len(a), 2):
        if a[i] != a[i + 1]:
            print(0)
            exit()

for i in range(len(a)//2):
    ans *= 2

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
mod=10**9+7
A.sort()
ans=1
if N%2==1:
  i=1
  if A[0]!=0:
    print(0)
    exit()
  for i in range(1,N,2):
    if A[i]==A[i+1]:
      ans*=2
      ans%=mod
    else:
      print(0)
      exit()
  print(ans)
else:
  i=0
  for i in range(0,N,2):
    if A[i]==A[i+1]:
      ans*=2
      ans%=mod
    else:
      print(0)
  print(ans)