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: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a.sort()
ans = True
if n%2:
  key=0
  if a[0] != key:
    ans = False
  p = 1
else:
  key=1
  if a[0] != key or a[1] != key:
    ans = False
  p = 2

for i in range(p, n):
  if i%2 == n%2:
    key += 2
  if a[i] != key:
    ans = False
    break

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
key = True
if n%2:
  key = False
ans = True
for i in range(n):
  if key:
    if a[i] != (i//2)*2+1:
      ans = False
      break
  else:
    if a[i] != ((i+1)//2)*2:
      ans = False
      break

if ans:
  print(pow(2, n//2, pow(10, 9)+7))
else:
  print(0)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
from collections import Counter
cnt = Counter(a)
#from collections import Counter
if n % 2 == 0:
    for i in range(1, n, 2):
        if cnt[i] != 2:
            print(0)
            quit()
else:
    if cnt[0] != 1:
        print(0)
        quit()
    for i in range(2, n, 2):
        if cnt[i] != 2:
            print(0)
            quit()
mod = 10 ** 9 + 7
print(2 ** (n // 2) % mod)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = sorted(list(map(int, input().split())))

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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    order = []
    for a in A:
        order.append(((N + 1 + a) // 2, (N + 1 - a) // 2))

    cnt = {}
    for o in order:
        if o not in cnt:
            cnt[o] = 1
        else:
            cnt[o] += 1

    ans = 1
    MOD = 1000000007
    for k, v in cnt.items():
        if k[0] == k[1] and v > 1:
            ans = 0
            break
        elif v > 2:
            ans = 0
            break
        else:
            ans *= v
            ans %= MOD
    print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
import sys
MOD = 10 ** 9 + 7
n = int(input())
a = list(map(int,input().split()))

b = Counter(a)

ans = 1
if n % 2 == 0:
    for i in range(1,n,2):
        if b[i] == 2:
            ans = ans * 2 % MOD
        else:
            print(0)
            sys.exit()
            
else:
    if b[0] == 1:
        for i in range(2,n,2):
            if b[i] == 2:
                ans = ans * 2 % MOD
            else:
                print(0)
                sys.exit()
    else:
        print(0)
        sys.exit()
        
print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

P = 10 ** 9 + 7


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()

    if N % 2 == 0:
        is_ok = True
        for i in range(N//2):
            if not A[2*i] == A[2*i+1] == (2*i+1):
                is_ok = False
        if is_ok:
            ans = pow(2, N//2, P)
        else:
            ans = 0

    else:
        is_ok = True
        if not A[0] == 0:
            is_ok = False
        for i in range((N-1)//2):
            if not A[2*(i+1)-1] == A[2*(i+1)] == 2*(i+1):
                is_ok = False
        if is_ok:
            ans = pow(2, (N-1)//2, P)
        else:
            ans = 0

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter
import sys
MOD = 10 ** 9 + 7
n = int(input())
a = list(map(int,input().split()))

b = Counter(a)

ans = 1
if n % 2 == 0:
    for i in range(1,n,2):
        if b[i] == 2:
            ans = ans * 2 % MOD
        else:
            print(0)
            sys.exit()
            
else:
    if b[0] == 1:
        for i in range(2,n,2):
            if b[i] == 2:
                ans = ans * 2 % MOD
            else:
                print(0)
                sys.exit()
    else:
        print(0)
        sys.exit()
        
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
key = True
if n%2:
  key = False
ans = True
for i in range(n):
  if key:
    if a[i] != (i//2)*2+1:
      ans = False
      break
  else:
    if a[i] != ((i+1)//2)*2:
      ans = False
      break

if ans:
  print(pow(2, n//2, pow(10, 9)+7))
else:
  print(0)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter

n = int(readline())
a = list(map(int, readline().split()))
counter = sorted(list(Counter(a).items()))
if n % 2 == 1:
    if counter[0] != (0, 1):
        print(0)
        exit()
    else:
        memo = 2
        counter.pop(0)
else:
    memo = 1
for k, v in counter:
    if memo != k or v != 2:
        print(0)
        exit()
    memo += 2
mod = 10 ** 9 + 7
print(pow(2, len(counter), mod))

Submission status: Accepted

Solution code:
from collections import defaultdict
def solve():
    N = int(input())
    A = list(map(int,input().split()))
    MOD = 10 ** 9 + 7

    d = defaultdict(int)

    for a in A:
        d[a] += 1
    
    num = 1
    if N % 2 != 0:
        if d[0] != 1:
            print(0)
            return
        num = 2
    
    while num < N:
        if d[num] != 2:
            print(0)
            return
        num += 2
    
    print(pow(2,N//2,MOD))
                
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from collections import Counter
M = 10**9 + 7
N = int(input())
A = list(map(int, input().split()))
ac = Counter(A)

def validate():
    uniq = N // 2
    if N % 2 == 1:
        uniq += 1
        if ac[0] != 1:
            return False
    if len(ac) != uniq:
        return False
    for k, v in ac.items():
        if k == 0 and v == 1:
            continue
        if v != 2:
            return False
        if N % 2 == k % 2:
            return False
    return True


def solve():
    if not validate():
        return 0
    return pow(2, N//2, M)


print(solve())

Submission status: Accepted

Solution code:
from collections import defaultdict

N=int(input())
A=list(map(int,input().split()))
if N%2==0:
    check={2*i+1:2 for i in range(0,N//2)}
else:
    check={2*i:2 for i in range(0,N//2+1)}
    check[0]=1

data=defaultdict(int)
for i in range(0,N):
    data[A[i]]+=1

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

Submission status: Accepted

Solution code:
from collections import defaultdict
mod = 10**9+7
n = int(input())
a = list(map(int,input().split()))
dic = defaultdict(int)
for i in range(n):
    dic[a[i]] += 1
if n % 2 == 0:
    for i in range(n//2):
        if dic[2*i+1] != 2:
            print(0)
            exit()
else:
    for i in range(n//2):
        if dic[2*i+2] != 2:
            print(0)
            exit()
        if dic[0] != 1:
            print(0)
            exit()
print(pow(2,(n//2),mod))

Submission status: Accepted

Solution code:
from collections import Counter


N = int(input())
A = list(map(int, input().split()))
c = sorted(Counter(A).items())

MOD = 10**9 + 7

if N%2 == 0:
    for i in range(len(c)):
        if c[i][0] != 2*i+1 or c[i][1] != 2:
            print(0)
            exit()
    print(pow(2, len(c), MOD))
else:
    if c[0][0] != 0 or c[0][1] != 1:
        print(0)
        exit()
    for i in range(1, len(c)):
        if c[i][0] != 2*i or c[i][1] != 2:
            print(0)
            exit()
    print(pow(2, len(c)-1, MOD))

Submission status: Accepted

Solution code:
import numpy as np
from collections import Counter
mo = 1000000007
r = range
 
n = int(input())
a = np.array(list(map(int, input().split())))
 
c = Counter(a.tolist())
 
if n % 2 == 1 and (0 not in c or c[0] != 1): print(0); exit();
 
for i in r(n//2):
    x = i * 2 + (1 if n % 2 == 0 else 2)
    if x not in c or c[x] != 2: print(0); exit();
 
print(2 ** (n//2) % mo)

Submission status: Accepted

Solution code:
def assert_(L, nm):
    for i in range(len(L) // 2):
        i *= 2
        if L[i] == L[i + 1] == nm:
            nm += 2
            continue
        print(0)
        exit()
    pass


mod = int(1e9) + 7

n = int(input())
A = [int(x) for x in input().split()]
A.sort()

if n % 2 == 0:
    if A[0] != 1 or A[1] != 1:
        print(0)
        exit()
    assert_(A[2:], 3)
else:
    if A[0] != 0:
        print(0)
        exit()
    assert_(A[1:], 2)

ans = 1
num_power = (n - 1) // 2 if n % 2 == 1 else n // 2
for _ in range(num_power):
    ans *= 2
    ans %= mod
print(ans)

Submission status: Accepted

Solution code:
# import bisect
from collections import Counter, deque # https://note.nkmk.me/python-scipy-connected-components/
# from copy import copy, deepcopy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    N=int(input())
    A=list(map(int,input().split()))
    mod=10**9+7
    if N%2==0:
        l=[2*i+1 for i in range(0,N//2)]+[2*i+1 for i in range(0,N//2)]
        if Counter(l)!=Counter(A):
            ans=0
        else:
            ans=2**(N//2)
    else:
        l=[2*i for i in range(1,N//2+1)]*2+[0]
        if Counter(l)!=Counter(A):
            ans=0
        else:
            ans=2**(N//2)
    print(ans%mod)


resolve()

Submission status: Accepted

Solution code:

n = int(input())
a = sorted(list(map(int, input().split())))
b = [0 for _ in range(n)]

if n % 2:
    for i in range(1,n,2):
        b[i] = b[i+1] = n - i
else:
    for i in range(0,n,2):
        b[i] = b[i+1] = n - (i + 1)
b.sort()

for i, j in zip(a, b):
    if i != j:
        print(0)
        exit()

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

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    arr = tuple(map(int, input().split()))
    from collections import Counter
    cnt = Counter(arr)
    m = 10 ** 9 + 7
    ans = 1
    for i in range(N - 1, 0, -2):
        if i not in cnt or cnt[i] != 2:
            ans = 0
            break
        ans = (ans << 1) % m
    if N % 2 and (0 not in cnt or cnt[0] != 1):
        ans = 0
    print(ans % m)

resolve()

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
c = Counter(A)
if n % 2 == 1 and c[0] == 1 and all(c[2 * i] == 2 for i in range(1, n // 2 + 1)):
  print(2 ** (n // 2) % (10 ** 9 + 7))
elif n % 2 == 0 and all(c[2 * i - 1] == 2 for i in range(1, n // 2 + 1)):
  print(2 ** (n // 2) % (10 ** 9 + 7))
else:
  print(0)

Submission status: Accepted

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

#以下が an mod p を求めるソースコードです.
def power_func(a, n, p):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % p
        a = a * a % p
        n = n >> 1
    return res

A.sort()
if N % 2 == 0 and A == [2*(i // 2)+1 for i in range(N)] or\
        N % 2 == 1 and A == [2*((i+1) // 2) for i in range(N)]:
    #print(2**(N // 2))
    print(power_func(2,N//2,MOD))
else:
    print(0)

Submission status: Accepted

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

#以下が an mod p を求めるソースコードです.
def power_func(a,n,p):
  bi=str(format(n,"b"))#2進表現に
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res


A.sort()
if N % 2 == 0 and A == [2*(i // 2)+1 for i in range(N)] or\
        N % 2 == 1 and A == [2*((i+1) // 2) for i in range(N)]:
    #print(2**(N // 2))
    print(power_func(2,N//2,MOD))
else:
    print(0)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = [0]*((N + 1)//2)
    if N % 2 == 1:
        for a in A:
            if a % 2 == 1:
                print(0)
                return
            B[a//2] += 1
    else:
        for a in A:
            if a % 2 == 0:
                print(0)
                return
            B[(a - 1)//2] += 1
    ans = 1
    # print(B)
    for i in range(len(B)):
        b = B[i]
        if N % 2 == 1 and i == 0:
            if b != 1:
                print(0)
                return
        elif b != 2:
            print(0)
            return
        ans = (ans * b) % (10**9 + 7)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
d=dict()
for i in range(n):
  if a[i] not in d:
    d[a[i]]=1
  else:
    d[a[i]]+=1
d=sorted(list(d.items()))
if n%2:
  for i in range(len(d)):
    if i==0:
      if d[i][0]!=0 or d[i][1]!=1:
        print(0)
        exit()
    else:
      if d[i][0]!=i*2 or d[i][1]!=2:
        print(0)
        exit()
  print(pow(2,len(d)-1,mod))
else:
  for i in range(len(d)):
    if d[i][0]!=2*i+1 or d[i][1]!=2:
      print(0)
      exit()
  print(pow(2,len(d),mod))

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(A)

for value in c.values():
    if(value == c[0]):
        continue
    if(value%2 != 0):
        print(0)
        quit()

if(N%2 != 0):
    if(c[0] == 1):
        ans = (2**(len(c)-1))%mod    
        print(ans)
    else:
        print(0)
else:
    if(c[0]):
        print(0)
    else:
        ans = (2**len(c))%mod
        print(ans)

Submission status: Accepted

Solution code:
n=int(input())
mod=10**9+7
from collections import Counter as co
var=co(map(int,input().split()))
if n%2:
    if 0 not in var:print(0);exit()
    if var[0]!=1:print(0);exit()
    for i in range(2,n,2):
        if i not in var:print(0);exit()
        if var[i]!=2:print(0);exit()
else:
    for i in range(1,n,2):
        if i not in var:print(0);exit()
        if var[i]!=2:print(0);exit()
print(2**(n//2)%mod)

Submission status: Accepted

Solution code:
#AGC015-B
if False:
    S=list(input())
    N=len(S)
    ans=0
    for i in range(N):
        if S[i]=='U':
            ans+=N-(i+1)
            ans+=i*2
        else:
            ans+=(N-(i+1))*2
            ans+=i
    print(ans)
            
#ARC069-C
if False:
    N,M=map(int,input().split())
    ans=min(N,M//2)
    if N<(M//2):
        ans+=((M//2-N)*2+(M%2))//4
    print(ans)

#ABC028-D
if False:
    N,K=map(int,input().split())
    ans=3*(N-1)+6*(K-1)*(N-K)+1
    ans=ans/(N**3)
    print(ans)

#ABC133-D
if False:
    N=int(input())
    A=[int(i) for i in input().split()]
    ANS=[sum(A)-2*sum(A[1::2])]
    for i in range(N-1):
        ANS.append(2*A[i]-ANS[-1])
    print(*ANS)

#ARC066-C
N=int(input())
A=[int(i) for i in input().split()]
const=10**9+7
cnt={}
ans=0
flag=True
if N%2==0:
    for k in range(N):
        cnt[k]=0
    for a in A:
        cnt[a]+=1
    for k in range(1,N,2):
        if cnt[k]!=2:
            flag=False
            break
    if flag: ans=pow(2,N//2,const)
else:
    for k in range(N):
        cnt[k]=0
    for a in A:
        cnt[a]+=1
    for k in range(0,N,2):
        if k==0:
            if cnt[0]!=1:
                flag=False
                break
        else:
            if cnt[k]!=2:
                flag=False
                break
    if flag: ans=pow(2,(N-1)//2,const)
print(ans)

Submission status: Accepted

Solution code:
mod = 10**9+7

def naive_quad_power(n):
    ret = 1
    for i in range(n):
        ret = (2*ret)%mod
        
    return ret

def solve():
    N = int(input())
    A = list(map(int, input().split()))
    valid = {abs(N-1-2*i):2 for i in range(N)}
    if N % 2 == 1:
        valid[0] = 1
        
    check = {k:0 for k in valid}
    val = True
    for a in A:
        if a in check and check[a] < valid[a]:
            check[a] = check[a]+1
        else:
            val = False
            break
    
    #print(check, valid)
    
    ret = naive_quad_power(N//2) if val else 0
    print(ret)
    
solve()

Submission status: Accepted

Solution code:
from collections import defaultdict


def my_pow(x,n):
    ret = 1
    mod = 10**9+7
    for _ in range(n):
        ret = (ret*x)%mod
    return ret
    

def check():
    N = int(input())
    A = [int(i) for i in input().split()]
    count = defaultdict(int)
    
    if N%2==0:
        for a in A:        
            if a%2==0:
                return 0
            count[a] += 1
        for cnt in count.values():
            if cnt != 2:
                return 0
        return my_pow(2,len(count))
    else:
        for a in A:
            if a%2!=0:
                return 0
            count[a] += 1
        if count[0] != 1:
            return 0
        count[0] = 2
        for cnt in count.values():
            if cnt != 2:
                return 0
        return my_pow(2,len(count)-1)
      
print(check())

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def power_func(a,n,p):
  bi=str(format(n,"b"))#2進表現に
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res

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

A.sort()
if N%2:
  correct = [0]
  for i in range(N//2):
    correct += [(i+1)*2]*2
else:
  correct = []
  for i in range(N//2):
    correct += [i*2+1]*2
    
if A == correct:
  print(power_func(2, N//2, MOD))
else:
  print(0)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
b = [0 for _ in range(n)]

if n % 2:
    for i in range(1,n,2):
        b[i] = b[i+1] = n - i
else:
    for i in range(0,n,2):
        b[i] = b[i+1] = n - (i + 1)
b.sort()

for i, j in zip(a, b):
    if i != j:
        print(0)
        exit()

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

Submission status: Accepted

Solution code:
from collections import Counter
mod = 10 ** 9 + 7
ans = 0
n = int(input())
A = list(map(int, input().split()))
c = Counter(A)
flag = True
if n % 2 == 0:
    odd = 1
    for val, cnt in sorted(c.items()):
        # print(val, cnt)
        if cnt == 2 and val == odd:
            odd += 2
        else:
            flag = False
            break
else:
    even = 0
    for val, cnt in sorted(c.items()):
        # print(val, cnt)
        if val == 0 and cnt == 1:
            even += 2
            continue
        if val == even and cnt == 2:
            even += 2
            continue
        else:
            flag = False
            break
if flag:
    ans = pow(2, n // 2, mod)
else:
    ans = 0
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n, *a = map(int, open(0).read().split())
a = Counter(a)

if n%2==0:
        i = cant = 0
        for v, c in sorted(a.items()):
                if 2*i+1!=v or c!=2: cant = True
                i += 1
else:
        i = cant = 0
        for v, c in sorted(a.items()):
                if i==0: cant = (c!=1)
                elif 2*i!=v or c!=2:  cant = True
                i += 1

if cant: print(0)
else: print(pow(2, n//2, 1000000007))

Submission status: Accepted

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

ans = 2**(N//2)
table = collections.defaultdict(int)
flag = True
for x in A:
    table[x] += 1

for x in table:
    if x % 2 == N % 2:
        flag = False
        break
    if x == 0 and table[x] > 1:
        flag = False
        break
    if x >= 1 and table[x] != 2:
        flag = False
        break
    if x > N - 1:
        flag = False
        break
mod = 10**9 + 7
if flag:
    print(ans % mod)
else:
    print(0)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
ans = 1
cnt = [0] * N
for a in A:
    if a != 0 and cnt[a] == 1:
        ans = ans * 2 % mod
    elif a == 0 and cnt[a] != 0 or cnt[a] > 1:
        ans = 0
    cnt[a] += 1
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

MOD = 10 ** 9 + 7
N = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)

for i in a:
    d[i] += 1

for v, c in d.items():
    if N % 2 == 0:
        if v % 2 == 1 and c == 2:
            continue
        else:
            print(0)
            exit()
    else:
        if v % 2 == 0 and c == 2:
            continue
        elif v == 0 and c == 1:
            continue
        else:
            print(0)
            exit()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = sorted(inpl())
now = 0 if n%2 else -1
for i in range(n):
    if i%2 == n%2:
        now += 2
    if a[i] != now:
        print(0)
        quit()
print(pow(2,n//2)%mod)

Submission status: Accepted

Solution code:
from collections import Counter

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

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

print(pow(2, N // 2, 10**9 + 7))

Submission status: Accepted

Solution code:
def main():
    MOD = 10**9 + 7
    N = int(input())
    A = [int(i) for i in input().split()]
    ans = 0
    from collections import Counter
    c = Counter(A)
    if N % 2 == 1:
        if all(v == 2 if k != 0 else v == 1 for k, v in c.items()):
            ans += pow(2, (len(c.keys())-1), MOD)
    else:
        if all(v == 2 for k, v in c.items()):
            ans += pow(2, (len(c.keys())), MOD)
    k = sorted(set(A))
    for i in range(len(c.keys())-1):
        if k[i] + 2 != k[i+1]:
            ans = 0
            break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    a.sort()
    if n&1:
        n >>= 1
        if a != sorted([2*i for i in range(n+1)]+[2*i for i in range(1,n+1)]):
            print(0)
        else:
            print(pow(2,n,mod))
    else:
        n >>= 1
        if a != sorted([2*i+1 for i in range(n)]+[2*i+1 for i in range(n)]):
            print(0)
        else:
            print(pow(2,n,mod))
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

N = ii()
A = sorted(li())

if N%2==1:
    if A[0]!=0:
        print(0)
        exit()
    for i in range(1, N//2+1):
        i2 = i*2
        if A[i2-1]!=i2 or A[i2]!=i2:
            print(0)
            exit()

else:
    for i in range(N//2):
        i2 = i*2
        if A[i2]!=i2+1 or A[i2+1]!=i2+1:
            print(0)
            exit()

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

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, accumulate
import itertools
import heapq
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def print_matrix(mat):
    for i in range(len(mat)):
        print(*mat[i])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N = I()
    A = LI()
    A = sorted(A)

    cur = 0
    value = 1
    if N % 2 == 1:
        cur = 1
        value = 2
        if A[0] != 0:
            print(0)
            return

    while cur < N:
        if not (A[cur] == value and A[cur+1] == value):
            print(0)
            return
        cur += 2
        value += 2

    if N % 2 == 1:
        print(pow(2, (N - 1) // 2, MOD))
    else:
        print(pow(2, N // 2, MOD))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
c = a.count(0)
    
odd_count = len(list(filter(lambda x: (x%2 != 0) , a)))

if(n%2 == 1):
    if(c != 1 or odd_count !=0):
        print(0)
        exit()
else:
    if(c != 0 or odd_count !=n):
        print(0)
        exit()
        
m = 1000000007
p = n//2
ans = 1
for _ in range(0,p):
    ans = 2*ans % m
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
l = input().split(" ")
l1=[0]*n
for i in range(len(l)):
    l[i]=int(l[i])
    l1[l[i]]+=1
if l1[0]>0 and n%2==0:
    print(0)
elif l1[0]>1 and n%2==1:
    print(0)
else:
    c = set(l)
    mod = int(1e9) +7
    for k in range(1,len(l1)):
        if l1[k]%2!=0:
            print(0)
            exit()
    if(l1[0]):    
        print(pow(2,len(c)-1,mod))
    else:
        print(pow(2,len(c),mod))