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:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7

if n%2==0:
    c=Counter(a)
    for x in c:
        if x%2==0 or c[x]!=2:
            print(0)
            break
    else:
        print(pow(2,n//2,mod))
else:
    c=Counter(a)
    if 0 not in c or c[0]!=1:
        print(0)
        exit()
    for x in c:
        if x==0:
          continue
        if x%2==1 or c[x]!=2:
            print(0)
            break
    else:
        print(pow(2,(n-1)//2,mod))

Submission status: Accepted

Solution code:
n=int(input())
ar=sorted(list(map(int,input().split())))
re=[]
if(n%2==1):
    re.append(0)
    for e in range(2,n,2):
        re.append(e)
        re.append(e)
else:
    for e in range(1,n,2):
        re.append(e)
        re.append(e)
#print(ar,re)
if(ar!=re):
    print(0)
else:
    print(pow(2,n//2,10**9+7))

Submission status: Accepted

Solution code:
def main():
    import sys

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

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




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil, atan, pi
def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left
MOD = int(1e9)+7
INF = float('inf')


def solve():
    # n, m = [int(x) for x in input().split()]  
    n = int(input())
    a = [int(x) for x in input().split()]
    cnt = defaultdict(int)
    for e in a:
        cnt[e] += 1
    
    xd = 0
    for c in cnt:
        if cnt[c] == 2:
            xd += 1
    target = n // 2
    if n % 2 == 0:
        if xd == target and cnt[0] == 0:
            print(pow(2, xd, MOD))
            return
    else:
        if xd == target and cnt[0] == 1:
            print(pow(2, xd, MOD))
            return
        
    print(0)



    
t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""
a b a
d c d
a b a
"""

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
num=n-1
num2=0
num3=1
ans=pow(2,n//2,10**9+7)
for i in range(n//2):
    for j in range(2):
        if a[num2]!=num:
            num3=0
            break
        num2+=1
    num-=2
    if num3==0:
        break
if n%2==1:
    if a[-1]!=num:
        ans=0
if num3==0:
    ans=0
print(ans)

Submission status: Accepted

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

b=[0 for _ in range((n+1)//2)]
for i in range(n):
    b[a[i]//2]+=1
if n%2==0:
  for i in range(n//2):
    if b[i]!=2:
      print(0)
      break
  else:
    print(pow(2,n//2,10**9+7))
else:
  if b[0]!=1:
    print(0)
  else:
    for i in range(1,n//2+1):
      if b[i]!=2:
        print(0)
        break
    else:
      print(pow(2,n//2,10**9+7))

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N = NI()
    A = sorted(NLI())
    if N % 2:
        for i in range(N):
            if i % 2 == 0 and A[i] == i:
                continue
            elif i % 2 == 1 and A[i] == i + 1:
                continue
            else:
                print(0)
                exit()
        print(pow(2, (N//2), MOD))

    else:
        for i in range(N):
            if i % 2 == 0 and A[i] == i + 1:
                continue
            elif i % 2 == 1 and A[i] == i:
                continue
            else:
                print(0)
                exit()
        print(pow(2, (N//2), MOD))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter

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

C = Counter(A)
D = {}
MOD = 10**9+7
for i in range(N-1, -1, -2):
    if i == 0:
        D[i] = 1
    else:
        D[i] = 2

if C != D:
    print(0)
else:
    ans = pow(2, N//2, MOD)
    print(ans)

Submission status: Accepted

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

    exist = True
    res = 0
    if N % 2 == 0:
        check = [2] * (N // 2)
        for a in A:
            if a % 2 == 1:
                if check[(a-1)//2] > 0:
                    check[(a-1)//2] -= 1
                else:
                    exist = False
            else:
                exist = False
        if exist:
            res = 1
            for i in range(N//2):
                res *= 2
                res %= mod
    else:
        check = [2] * ((N+1) // 2)
        check[0] = 1
        for a in A:
            if a % 2 == 0:
                if check[a//2] > 0:
                    check[a//2] -= 1
                else:
                    exist = False
            else:
                exist = False
        if exist:
            res = 1
            for i in range((N-1)//2):
                res *= 2
                res %= mod

    print(res)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,*aa = map(int, open(0).read().split())

from collections import Counter
c = Counter(aa)

MOD = 10**9+7
cand = set(range((n+1)%2, n ,2))

if c.keys() - cand:
    ans = 0
else:
    ans = 1
    for v in cand:
        if v != 0 and c[v] != 2:
            ans = 0
            break
        elif v == 0 and c[v] != 1:
            ans = 0
            break
        elif v != 0:
            ans *= 2
            ans %= MOD

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
cnt = Counter(A)
MOD = 10 ** 9 + 7
isAble = True
if N % 2 == 1:
    if cnt[0] != 1:
        isAble = False
    for i in range(2, N, 2):
        if cnt[i] != 2:
            isAble = False
            break
else:
    for i in range(1, N, 2):
        if cnt[i] != 2:
            isAble = False
            break

if isAble:
    ans = 1
    for _ in range(N // 2):
        ans *= 2
        ans %= MOD
    print(ans)
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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


def resolve():
    n = int(input())
    A = sorted(list(map(int, input().split())))
    if n % 2 == 0:
        num = 1
        for i in range(0, n - 1, 2):
            if A[i] != num or A[i + 1] != num:
                print(0)
                exit()
            num += 2
    else:
        if A[0] != 0:
            print(0)
            exit()
        num = 2
        for i in range(1, n - 1, 2):
            if A[i] != num or A[i + 1] != num:
                print(0)
                exit()
            num += 2

    res = pow(2, n // 2, mod)
    print(res % mod)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
from math import ceil,floor,comb,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = sorted(LIST())

chk = True
if n % 2 == 0:
    for i in range(n):
        if a[i] != i//2 * 2 + 1:
            chk = False
else:
    for i in range(n):
        if a[i] != (i+1)//2 * 2:
            chk = False
if chk:
    ans = pow(2, n//2, 10**9+7)
    print(ans)
else:
    print(0)

Submission status: Accepted

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

from collections import Counter
cd = Counter(A)
# A.sort()

if N & 1:
    # odd
    if cd[0] != 1:
        print(0)
        exit(0)
    ng = False

    for ix in range(2, N//2 + 1, 2):
        if cd[ix] != 2:
            ng = True
            break

    if len(cd) != N//2 + 1:
        ng = True
    
    if ng:
        print(0)
    else:
        # print(pow(2,(N//2),M))
        ans = 1
        for ix in range(N//2):
            ans *= 2
            ans %= M
        print(ans)

else:
    # even
    ng = False
    for ix in range(1, N//2+1, 2):
        if cd[ix] != 2:
            ng = True
            break
    
    if len(cd) != N//2:
        ng = True
    
    if ng:
        print(0)
    else:
        # print(pow(2,(N//2),M))
        ans = 1
        for ix in range(N//2):
            ans *= 2
            ans %= M
        print(ans)

Submission status: Accepted

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

from collections import Counter
cd = Counter(A)
# A.sort()

if N & 1:
    # odd
    if cd[0] != 1:
        print(0)
        exit(0)
    ng = False

    for ix in range(2, N//2 + 1, 2):
        if cd[ix] != 2:
            ng = True
            break

    if len(cd) != N//2 + 1:
        ng = True
    
    if ng:
        print(0)
    else:
        print(pow(2,(N//2),M))

else:
    # even
    ng = False
    for ix in range(1, N//2+1, 2):
        if cd[ix] != 2:
            ng = True
            break
    
    if len(cd) != N//2:
        ng = True
    
    if ng:
        print(0)
    else:
        print(pow(2,(N//2),M))

Submission status: Accepted

Solution code:
# nの遇奇で出現する数字の数は固定されるのでそれから外れるとダメ 奇数んとき真ん中0以外ぜんぶ2 偶数ならぜんぶ2ずつ場所が割り当てられる
# もっとマシな実装できんのか
# たぶん割忘れてて1WA
n = int(input())
a = list(map(int, input().split()))
d = {}
MOD = 10**9 + 7
for av in a:
    if av not in d:
        d[av] = 1
    else:
        d[av] += 1
if n % 2 == 0:
    ans = 1
    for i in range(1, n, 2):
        if i not in d or d[i] != 2:
            print(0)
            exit()
        else:
            ans *= 2
            ans %= MOD
    print(ans)
else:
    if 0 not in d or d[0] != 1:
        print(0)
        exit()
    ans = 1
    for i in range(2, n, 2):
        if i not in d or d[i] != 2:
            print(0)
            exit()
        else:
            ans *= 2
            ans %= MOD
    print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

cnt = Counter(A)
diff = {}
if N % 2 == 0:
    for i in range(1, N, 2):
        diff[i] = 2
else:
    for i in range(0, N, 2):
        if i == 0:
            diff[i] = 1
        else:
            diff[i] = 2
MOD = 10 ** 9 + 7
if cnt != diff:
    print(0)
    exit()
else:
    print(pow(2, N//2, MOD))

Submission status: Accepted

Solution code:
def count(l):
    res = {}
    for d in l:
        if d in res:
            res[d] += 1
        else:
            res[d] = 1
    return res

n = int(input())
data = list(map(int, input().split()))
cnt = count(data)
mod = 10**9 + 7

ans = 1
for k, v in cnt.items():
    if k == 0:
        if v > 1 or n %2 == 0:
            print(0)
            exit()
        continue
    else:
        if v <= 2:
            ans *= 2
        else:
            print(0)
            exit()

print(ans%mod)

Submission status: Accepted

Solution code:
from collections import *
from itertools import *
from math import *
n=int(input())
a=sorted(list(map(int,input().split())))
b=list(Counter(a))
mod=7+10**9
if n%2==1:
    if a[0]!=0:
        print(0)
        exit()
    for i in range(1,n):
        if ceil(i/2)*2!=a[i]:
            print(0)
            exit()
    print(2**(n//2)%mod)
if n%2==0:
    for i in range(n):
        if floor(i/2)*2+1!=a[i]:
            print(0)
            exit()
    print(2**(n//2)%mod)

Submission status: Accepted

Solution code:
import sys
from collections import Counter

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N = in_n()
    A = in_nl()
    count = Counter(A)

    mod = 10**9 + 7

    if N % 2 == 0:
        f = True
        for i in range(1, N, 2):
            if count[i] != 2:
                f = False
                break

        if f:
            ans = pow(2, N // 2, mod)
        else:
            ans = 0
    else:
        f = (count[0] == 1)
        for i in range(2, N, 2):
            if count[i] != 2:
                f = False
                break

        if f:
            ans = pow(2, N // 2, mod)
        else:
            ans = 0

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
cA = Counter(A)
mod = pow(10,9)+7
ans = pow(2,n//2)
for i in range(n//2+n%2):
    if i==0 and n%2==1:
        if cA[0] !=1:
            ans = 0
            break
    elif cA[2*i+1-n%2]!=2:
        ans = 0
        break
print(ans%mod)

Submission status: Accepted

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

P = [0]*N

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

if P[0] != 1 and P[0]!=0:
	print(0)
	exit()

for i in range (1, N):
	if (i-N)%2 ==0:
		if P[i] > 0:
			print(0)
			exit()
	if (i-N)%2 != 0:
		if P[i] != 2 and P[i] !=0:
			print(0)
			exit()

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

Submission status: Accepted

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

a=sorted(a)
flgs=[]
if n%2==0:
    k=n//2
    for i in range(1,k+1):
        flgs.append(2*i-1)
        flgs.append(2*i-1)
else:
    k=(n-1)//2
    flgs.append(0)
    for j in range(1,k+1):
        flgs.append(2*j)
        flgs.append(2*j)

flgs=sorted(flgs)
if flgs==a:
    ans=2**k
    print(ans%mod)
else:
    print(0)

Submission status: Accepted

Solution code:
from collections import Counter

N=int(input())
A=list(map(int, input().split()))
D=Counter(A)
ans=1
p=10**9+7
for k,v in D.items():

    if k==0:
        if v!=1:
            print(0)
            exit()
    else:
        if v!=2:
            print(0)
            exit()
        else:
            ans*=2
            ans%=p
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

P = 10**9 + 7

rlt = 1
dic = Counter(As)

if N % 2 == 0:
  for k in dic:
    if k % 2 == 1 and dic[k] == 2:
      rlt *= 2
      rlt %= P
    else:
      print(0)
      exit()
else:
  for k in dic:
    if k == 0 and dic[k] == 1:
      continue
    elif k % 2 == 0 and dic[k] == 2:
      rlt *= 2
      rlt %= P
    else:
      print(0)
      exit()
      
print(rlt)

Submission status: Accepted

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

A.sort()

mod = 10**9+7

f = True
if n%2:#nは奇数
    if A[0] != 0:
        f = False
    else:
        check = 2
        for i in range(1,(n-1)//2+1):
            if not (A[2*i-1] == check and A[2*i] == check):
                f = False
                break
            check += 2
else:#nは偶数
    check = 1
    for i in range(1,n//2+1):
        if not (A[2*i-2] == check and A[2*i-1] == check):
            f = False
            break
        check += 2
if f:
    if n%2:
        print(pow(2, (n-1)//2, mod))
    else:
        print(pow(2, n//2, mod))
else:
    print(0)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,*a = map(int,read().split())

MOD = 10**9+7


res = [0]*(n)
for i in a:
    res[i] += 1

if n&1:
    if res[0]==1 and all(ri==2 for ri in res[2::2]):
        print(pow(2,n//2,MOD))
    else:
        print(0)
else:
    if all(ri==2 for ri in res[1::2]):
        print(pow(2,n//2,MOD))
    else:
        print(0)

Submission status: Accepted

Solution code:
import sys
from collections import Counter

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))
mod = 10 ** 9 + 7

C = Counter(A)
if N % 2 == 0:
    if not all([i == 2 for i in C.values()]):
        print(0)
    else:
        print(pow(2, N // 2, mod))
else:
    for i, v in C.items():
        if v > 2:
            print(0)
            exit()
        elif i != 0 and v == 1:
            print(0)
            exit()
        elif i == 0 and v > 1:
            print(0)
            exit()
    if 0 in C:
        print(pow(2, N // 2, mod))
    else:
        print(0)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
if N==1:
    if A[0]==0:
        print(1)
    else:
        print(0)
else:
    C = {}
    for i in range(N):
        a = A[i]
        if a not in C:
            C[a]=0
        C[a] += 1
    flag = 0
    if N%2==0:
        for i in range(1,N,2):
            if i in C and C[i]==2:continue
            flag=1
            break
    else:
        for i in range(2,N,2):
            if i in C and C[i]==2:continue
            flag = 1
            break
        if 0 not in C or C[0]!=1:
            flag = 1
    if flag==1:
        print(0)
    else:
        p = 10**9+7
        k = N//2
        ans = 1
        cnt = 1
        while cnt<=k:
            ans = (ans*2)%p
            cnt += 1
        print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
def solve():
    ans = 0
    mod = 10**9+7
    N = int(input())
    A = list(map(int, input().split()))
    c = Counter(A)
    for i in range(N):
        if (N-1-i)==i:
            if 0 not in c or c[0]!=1:
                return 0
        else:
            p = abs((N-1-i)-i)
            if p not in c or c[p]!=2:
                return 0
    ans = pow(2,N//2,mod)
    return ans
print(solve())

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
mod = 10**9+7

def pow(x, n):
    ans = 1
    n_tmp = n
    while n:
        if n % 2:
            ans *= x
            ans %= mod
        x *= x
        n >>= 1
    return ans

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

Submission status: Accepted

Solution code:
from collections import Counter
mod = 10 ** 9 + 7


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

    # check
    if N % 2 == 1:
        if C[0] != 1:
            return 0
        for i in range(2, N, 2):
            if C[i] != 2:
                return 0
    else:
        for i in range(1, N, 2):
            if C[i] != 2:
                return 0
    return pow(2, N//2, mod)


if __name__ == "__main__":
    print(main())

Submission status: Accepted

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

cnd = []
if N%2 == 0:
    for i in range(N//2):
        cnd.append(2*i+1)
        cnd.append(2*i+1)
else:
    for i in range(N//2+1):
        if i == 0:
            cnd.append(0)
        else:
            cnd.append(2*i)
            cnd.append(2*i)
            
B = sorted(A)
if cnd != B:
    print(0)
    exit()

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

Submission status: Accepted

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

mod = 10**9+7

def power(a, n, mod):
    bi=str(format(n,"b")) #2進数
    res=1
    for i in range(len(bi)):
        res=(res*res) %mod
        if bi[i]=="1":
            res=(res*a) %mod
    return res


from collections import Counter
if n%2 == 0:
    C = Counter(A)
    for i in range(1, n+1):
        if i%2 == 0:
            continue
        else:
            if C[i] != 2:
                print(0)
                exit()
    else:
        print(power(2, n//2, mod))
else:
    C = Counter(A)
    for i in range(1, n+1):
        if i == 0:
            if C[i] != 1:
                print(0)
                exit()
        elif i%2 == 1:
            continue
        else:
            if C[i] != 2:
                print(0)
                exit()
    else:
        print(power(2, n//2, mod))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import Counter

def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def solve(N, A, p=10**9+7):
    A.sort()
    if N % 2 == 1:
        if A[0] != 0:
            return 0
        for i in range(1, N):
            if A[i] != i + i%2:
                return 0
    else:
        for i in range(0, N):
            if A[i] != i + (1-i%2):
                return 0
    return pow(2, N//2, p)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Accepted

Solution code:
import collections
N=int(input())
A=collections.Counter(list(map(int,input().split())))
if N%2==0:
  for i in range(0,N,2):
    if i%2==0 and A[i]==0:
      pass
    elif i%2==1 and A[i]==2:
      pass
    else:
        print(0);exit(0)
else:
  for i in range(N):
    if i==0 and A[i]==1:
      continue
    if i%2==0 and A[i]==2:
      pass
    elif i%2==1 and A[i]==0:
      pass
    else:
      print(0);exit(0)
print(pow(2,N//2,10**9+7 ))

Submission status: Accepted

Solution code:
from collections import Counter

def powmod(a,n,m): #a^n mod m
    ans=1
    while n!=0:
        if n&1: ans=ans*a%m
        a=a*a%m
        n>>=1
    return ans%m

n=int(input())
a=list(map(int,input().split()))
a.sort()
dic=Counter(a)
if n%2==0:
    temp={}
    for i in range(1,n,2):
        temp[i]=2
    if temp!=dict(dic):
        print(0)
        exit()
else:
    temp={}
    temp[0]=1
    for i in range(2,n,2):
        temp[i]=2
    if temp!=dict(dic):
        print(0)
        exit()
print(powmod(2,n//2,10**9+7))

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(a)

if n % 2 == 0:
    for i in range(n):
        if i % 2 == 0 and c[i] == 0:
            continue
        elif i % 2 == 1 and c[i] == 2:
            continue
        else:
            print(0)
            exit(0)
else:
    for i in range(n):
        if i == 0 and c[i] == 1:
            continue
        if i % 2 == 0 and c[i] == 2:
            continue
        elif i % 2 == 1 and c[i] == 0:
            continue
        else:
            print(0)
            exit(0)

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

Submission status: Accepted

Solution code:
mod = 10**9+7
def power(a,n):
  ans = 1
  while n:
    if n%2:
      ans = (ans*a)%mod
    a = (a*a)%mod
    n >>= 1
  return ans%mod 
n = int(input())
a = list(map(int,input().split()))
x = [0 for _ in range(n)]
for ai in a:
  x[ai] += 1
if n%2 == 0:
  if sum(x[0::2]) != 0:
    print(0)
    exit()
  for i in range(1,n,2):
    if x[i] != 2:
      print(0)
      exit()
  print(power(2,n//2))
else:
  if sum(x[1::2]) != 0:
    print(0)
    exit()
  if x[0] != 1:
    print(0)
    exit()
  if n == 1:
    print(1)
    exit()
  for i in range(2,n,2):
    if x[i] != 2:
      print(0)
      exit()
  print(power(2,(n-1)//2))

Submission status: Accepted

Solution code:
from collections import Counter

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

c_al = Counter(al)

if n % 2 == 0:
    for k,v in c_al.items():
        if v != 2:
            print(0)
            exit()
    print(pow(2, n // 2, 10 ** 9 + 7))

elif n % 2 != 0:
    for k, v in c_al.items():
        if k == 0:
            if v != 1:
                print(0)
                exit()
        elif v != 2:
            print(0)
            exit()
    print(pow(2, n // 2, 10 ** 9 + 7))

Submission status: Accepted

Solution code:
def solve(A,N,M):
    #正しく並べると
    #Nが奇数: N-1 N-3 .... 2 0 2 .... N-3 N-1
    #Nが偶数: N-1 N-3 ... 3 1 1 3 ... N-3 N-1
    #になるはず

    A.sort(reverse = True)

    if N % 2 != 0:
        if A[len(A)-1] == 0:
            A.pop()
        else:
            return 0

    ans = pow(2,len(A)//2,M)
    a = 1
    if N % 2 != 0:
        a += 1
    while len(A) > 0:
        if A[len(A)-1] == a and A[len(A)-2] == a:
            A.pop()
            A.pop()
            a += 2
        else:
            return 0
    return ans

def main():
    N = int(input())
    A = list(map(int,input().split()))
    M = 10**9 + 7

    print(solve(A,N,M))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def solve(n,A):
    MOD = 10**9+7

    freq = [0 for i in range(n)]
    for x in A:
        freq[x] += 1

    ans = 1
    if n&1:
        if freq[0] != 1:
            return 0

    for pos in range(n//2):
        r = abs(pos-(n-1-pos))
        if freq[r]==0:
            ans = (ans*1)%MOD
        elif freq[r]==2:
            ans = (ans*2)%MOD
        else:
            return 0
    return ans

n = int(input())
A = [int(x) for x in input().split()]
print(solve(n,A))

Submission status: Accepted

Solution code:
from collections import Counter


def is_valid():
    if N % 2:
        return A[0] == 1 and all(A[2 * i + 2] == 2 for i in range(N // 2))
    else:
        return all(A[2 * i + 1] == 2 for i in range(N // 2))


N = int(input())
A = Counter(map(int, input().split()))
print(pow(2, N // 2, 10 ** 9 + 7)) if is_valid() else print(0)

Submission status: Accepted

Solution code:
from collections import Counter


def is_valid():
    if N % 2:
        return A.get(0, 0) == 1 and all(A.get(2 * i + 2, 0) == 2 for i in range(N // 2))
    else:
        return all(A.get(2 * i + 1, 0) == 2 for i in range(N // 2))


N = int(input())
A = Counter(map(int, input().split()))
MOD = 10 ** 9 + 7
print(pow(2, N // 2, MOD)) if is_valid() else print(0)

Submission status: Accepted

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

if n==1:
  if a[0]==0:
    print(1)
    exit()
  exit(print(0))
mod=10**9+7
a.sort()
t=0
ans=1
if n%2==0:
  t=1
  for i in range(n):
    if i==0 or i==1:
      if a[i]!=1:exit(print(0))
      continue
    if i%2==0:t+=2
    if a[i]!=t:exit(print(0))
  for i in range(n//2):
    ans*=2
    ans%=mod
else:
  for i in range(n):
    if i==0 and a[i]!=0:exit(print(0))
    if i%2==1:
      t+=2
    if a[i]!=t:exit(print(0))
  for i in range(n//2):
    ans*=2
    ans%=mod
print(ans)

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
from collections import Counter
x=Counter(a)
MOD=10**9+7
# print(x)
if n%2==1:
  ng=False
  if x[0]!=1:ng=True
  for i in range(1,n):
    if i%2==0 and x[i]==2:continue
    if i%2==1 and x[i]==0:continue
    ng=True
  if ng:
    print(0)
  else:
    print(pow(2,n//2,MOD))

if n%2==0:
  ng=False
  for i in range(n):
    if i%2==0 and x[i]==0:continue
    if i%2==1 and x[i]==2:continue
    ng=True  
  
  if ng:
    print(0)
  else:
    print(pow(2,n//2,MOD))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
count = [0]*n
for i in a:
    count[i] += 1
    
ans = 0
if n%2 == 0:
    if all(count[2*f]==0 for f in range(n//2)) and all(count[2*k-1]==2 for k in range(1,n//2)):  
        ans = 1
else:
    if count[0] == 1 and all(count[2*f]==2 for f in range(1,n//2)) and all(count[2*k-1]==0 for k in range(1,n//2)):
        ans = 1
        
if ans == 1:
    for i in range(n//2):
        ans = (ans*2) % (1e+9+7)

print(int(ans))

Submission status: Accepted

Solution code:
from collections import Counter

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

mono = sorted(set(a))
dic = Counter(a)

if n % 2 == 1:
    last = 0
else:
    last = 1

res = 0
Cond = True
for x in mono:
    if x == 0 and a.count(0) == 1: last = 2
    elif x == last and dic[x] == 2:
        res += 1
        last += 2
    else: Cond = False

if Cond:
    print(2**res % MOD)
else:
    print(0)

Submission status: Accepted

Solution code:
from collections import Counter
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    A = list(map(int, input().split()))

    cnt = Counter(A)
    n = N
    if N % 2:
        if cnt[0] != 1:
            print(0)
            return
        n = N - 1
    for i in range(1, n, 2):
        if cnt[N-i] != 2:
            print(0)
            return
    print(pow(2, n // 2, 1000000007))


main()

Submission status: Accepted

Solution code:
MOD = 10**9+7

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

def ii():
    return int(input())

def main():
    N = ii()
    A = list(mi())
    A.sort()
    if N%2:
        for i in range(N):
            if A[i] != i+(i%2):
                print(0)
                return
    else:
        for i in range(N):
            if A[i] != i+((i+1)%2):
                print(0)
                return
    print(pow(2, N//2, MOD))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
mod = 10**9+7

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

chk = []
if N % 2 == 1:
    chk.append(0)
    for i in range(N // 2):
        chk.append((i+1)*2)
        chk.append((i+1)*2)
else:
    for i in range(N // 2):
        chk.append(i*2+1)
        chk.append(i*2+1)
#print(chk)

A.sort()

if A != chk:
    print(0)
else:
    print(pow(2, N // 2,mod))