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:
a = int(input())
b = list(map(int, input().split()))
b.sort()
if a % 2 == 0:
    c = 1
    for i in range(len(b)):
        if i > 0 and i % 2 == 0:
            c += 2
        if b[i] != c:
            print(0)
            exit()
    print((2 ** (a // 2)) % (10 ** 9 + 7))
else:
    c = 0
    for i in range(len(b)):
        if i > 0 and i % 2 == 1:
            c += 2
        if b[i] != c:
            print(0)
            exit()
    print((2 ** ((a-1) // 2)) % (10 ** 9 + 7))

Submission status: Accepted

Solution code:
from sys import exit, stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
A.sort()
for i, a in enumerate(A):
    if N % 2 == 1:
        try:
            assert a == (i + 1) // 2 * 2
        except AssertionError:
            print(0)
            exit()
    else:
        try:
            assert a == i // 2 * 2 + 1
        except AssertionError:
            print(0)
            exit()
ans = pow(2, N // 2, 10 ** 9 + 7)
print(ans)

Submission status: Accepted

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

mod=10**9+7
A=sorted(A)
possible=1
if N%2==1:
    if A[0]!=0:
        possible=0
    for i in range(1,N):
        if A[i]!=i+i%2:
            possible=0
            break
    if possible==1:
        ans=2**((N-1)//2)%mod
    else:
        ans=0
else:
    for i in range(N):
        if A[i]!=i+(i+1)%2:
            possible=0
            break
    if possible==1:
        ans=2**(N//2)%mod
    else:
        ans=0
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
def solve():
    if N % 2 == 1:
        if counter[0] != 1:
            return 0
        else:
            for i in range(2, N, 2):
                if counter[i] != 2:
                    return 0
            return (2 ** (N // 2)) % mod
    else:
        for i in range(1, N, 2):
            if counter[i] != 2:
                return 0
        return (2 ** (N // 2)) % mod

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
dic = {}
for a in A:
    if a in dic:
        dic[a] += 1
        if N % 2 == 1 and a == 0:
            print(0)
            exit()
        elif dic[a] > 2:
            print(0)
            exit()
    else:
        dic[a] = 1
        if N % 2 == 1:
            if a % 2 == 1 or a >= N:
                print(0)
                exit()
        elif N % 2 == 0:
            if a % 2 == 0 or a >= N:
                print(0)
                exit()

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

Submission status: Accepted

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

if A == B:
    print(2 ** ( N // 2) % mod)
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
arr = list(map(int, input().split()))
arr.sort(reverse = True)

valid = True
t = n-1
for i in range(n):
	if arr[i] != t :
		valid = False
	if i % 2 == 1 :
		t -= 2 

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

Submission status: Accepted

Solution code:
n =int(input())
a = list(map(str,input().split()))
from collections import defaultdict
d = defaultdict(int)


if n%2==0:
    for i in range(n):
        d[a[i]]+=1
    if all(int(x)==2 for x in d.values()):
        print((2**(n//2))%(10**9+7))
        exit()
    else:
        print(0)
        exit()

else:
    d["0"]+=1
    for i in range(n):
        d[a[i]]+=1
    if all(int(x)==2 for x in d.values()):
        print((2**((n-1)//2))%(10**9+7))
        exit()
    else:
        print(0)
        exit()

Submission status: Accepted

Solution code:
n = int(input())
dp = [2]*n
dp[0] = 1
mod = 10**9+7
an = [int(i) for i in input().split()]

if n % 2 == 1:
  for i in an:
    if i % 2 == 1 or dp[i] == 0:
      print(0)
      exit()
    else:
      dp[i] -= 1
  print(2**((n-1)//2)%mod)
else:
  for i in an:
    if i % 2 == 0 or dp[i] == 0:
      print(0)
      exit()
    else:
      dp[i] -= 1
  print(2**(n//2)%mod)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
# ARC066C - Lining Up (ABC050C)
from collections import Counter


def main():
    n = int(input())
    a = sorted(Counter(map(int, input().rstrip().split())).items())
    MOD = 10 ** 9 + 7
    if n % 2 == 1 and a[0][1] != 1:
        print(0)
    elif not all(i[1] == 2 for i in a[1:]):
        print(0)
    else:
        if n % 2 == 0:
            print(2 ** len(a) % MOD)
        else:
            print(2 ** (len(a) - 1) % MOD)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
mod = 10**9+7
c = 1-N%2
flag = True
di = {}
if(N==1):
    if(A[0]==0):
        print(1)
    else:
        print(0)
else:
    for i in A:
        if(i not in di):
            di[i]=1
        else:
            di[i]+=1
    for i in range(N//2):
        if(i+c==0):
            if(0 not in di):
                flag = False
            else:
                flag &= (di[i]==1)
        else:
            if(i*2+c not in di):
                flag = False
            else:
                flag &= (di[i*2+c]==2)
        if(not flag):
            print(0)
            break
    else:
        print((2<<(N//2-1))%mod)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
A = [int(i) for i in input().split()]
zz = Counter(A)

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

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

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    A = LI()
    c = Counter(A)
    if N % 2 != 0 and c[0] != 1:
        print(0)
        exit()
        
    for i in range(1,(N + 1) // 2):
        if c[i*2-(N%2==0)] != 2:
            print(0)
            exit()
    print(pow(2,N//2,mod))
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    A = LI()
    c = Counter(A)
    if N % 2 != 0 and c[0] != 1:
        print(0)
        exit()
        
    for i in range(1,(N + 1) // 2):
        if c[i*2-(N%2==0)] != 2:
            print(0)
            exit()
    print(pow(2,N//2,mod))
if __name__ == '__main__':
    main()

Submission status: Accepted

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

import collections
c=collections.Counter(a)
l=len(c)
ans=1

for i in range((n-1)%2,n,2):
    if i==0:
        if c[0]!=1:
            ans=0
    elif c[i]==2:
        ans*=2
    else:
        ans=0
    ans=ans%(10**9+7)


print(ans)

Submission status: Accepted

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

def check():
    if N % 2 == 0:
        for i in range(1,N)[::2]:
            if A[i-1] != i or A[i] != i:    return 0
        return int(2**(N//2)) % int(1e9+7)
    else:
        if A[0] != 0:   return 0
        else:
            for i in range(2,N)[::2]:
                if A[i-1] != i or A[i] != i:    return 0
            return int(2**((N-1)//2)) % int(1e9+7)
        
print(check())

Submission status: Accepted

Solution code:
"""
自分の左に並んでいた人数と自分の右に並んでいた人数の差の絶対値はAi
元の並び方が何通りあるか

N = 3
並び    1 2 3
As      2 0 2

N = 4
並び    1 2 3 4
As      3 1 1 3

2^n通りだろう
"""
N = int(input())
As = list(map(int,input().split()))
As = sorted(As)
mod = 10**9 + 7

if N % 2 == 0:
    A = [(i)//2*2+1 for i in range(N)]
    if As == A:
        print(2**(N//2)%mod)
    else:
        print(0)
else:
    A = [0] + [(i+1)//2*2 for i in range(1,N)]
    if As == A:
        print(2**((N-1)//2)%mod)
    else:
        print(0)

Submission status: Accepted

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

A.sort()
B = [abs(a-b) for a,b in zip(range(N-1,-1,-1),range(N))]
B.sort()

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

Submission status: Accepted

Solution code:
from collections import Counter

def main():
    N = int(input())
    A = list(map(int,input().split()))
    for a in A:
        if (a + N + 1)%2:
            return 0
    for k,v in Counter(A).items():
        if k == 0 and v != 1:
            return 0
        if k != 0 and v != 2:
            return 0
    ans = 1
    mod = 10**9 + 7
    for i in range(N//2):
        ans *= 2
        ans %= mod
    return ans

print(main())

Submission status: Accepted

Solution code:
import sys
from sys import stdin

mod = 1000000007

n = int(input())
# s = stdin.readline().rstrip()
# A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(x) for x in input().split()]

a = sorted(a)
predict = [n - (((n - i + 1) // 2) * 2) + 1 for i in range(0, n)]
if a != predict:
    print(0)
    sys.exit()
print(pow(2, (n // 2), mod))
# print(*data, sep='\n')

Submission status: Accepted

Solution code:
import sys
from sys import stdin

mod = 1000000007

n = int(stdin.readline().rstrip())
# s = stdin.readline().rstrip()
# A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(x) for x in stdin.readline().rstrip().split()]

a = sorted(a)
predict = [n - (((n - i + 1) // 2) * 2) + 1 for i in range(0, n)]
if a != predict:
    print(0)
    sys.exit()
print(pow(2, (n // 2), mod))
# print(*data, sep='\n')

Submission status: Accepted

Solution code:
from sys import stdin


def resolve():
    n = int(stdin.readline().rstrip())
    # s = stdin.readline().rstrip()
    # A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
    a = [int(x) for x in stdin.readline().rstrip().split()]

    a = sorted(a)
    predict = [n - (((n - i + 1) // 2) * 2) + 1 for i in range(0, n)]
    if a != predict:
        return 0

    ret = 1
    for i in range(0, n // 2):
        ret = (ret * 2) % 1000000007
    return ret


print(resolve(), '\n')
# print(*data, sep='\n')

Submission status: Accepted

Solution code:
N = int(input())
As = list(map(int, input().split()))
As.sort()
ans = 0
mod = 10**9+7
flag = True
if N%2 == 1:
    x = 0
    for i in range(N):
        if i%2 == 0:
            if As[i] != x:
                flag = False
                break
        else:
            x += 2
            if As[i] != x:
                flag = False
                break
    if flag:
        ans = pow(2, (N-1)//2, mod)
else:
    x = -1
    for i in range(N):
        if i%2 == 0:
            x += 2
            if As[i] != x:
                flag = False
                break
        else:
            if As[i] != x:
                flag = False
                break
    if flag:
        ans = pow(2, N//2, mod)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
C - Lining Up
https://atcoder.jp/contests/arc066/tasks/arc066_a

"""
import sys

from collections import Counter

def solve(N, array):
    cnt = Counter(array)
    res = []
    for k, v in cnt.items():
        if k == 0 and v > 1:
            return 0
        if k != 0 and v != 2:
            return 0
        if N%2:
            if k%2:
                return 0
            res.append(v)
        else:
            if k%2 == 0:
                return 0
            res.append(v)
    ans = 1
    MOD = 10**9 + 7
    for r in res:
        ans = (ans * r) % MOD
    return ans


def main(args):
    N = int(input())
    array = [int(a) for a in input().split()]
    ans = solve(N, array)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

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

if l[0] != n%2:
    print(0)
    exit()

for i in l[1:]:
    if i!=0 and i!=2:
        print(0)
        exit()
print(2**(n//2)%m)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
INF=int(1e9+7)
if N%2==1:
    if A[0]!=0:
        print(0)
        quit()
    for i in range((N-1)//2):
        if A[2*i+1]!=2*(i+1) or A[2*i+2]!=2*(i+1):
            print(0)
            quit()
    print(2**((N-1)//2)%INF)
else:
    for i in range(N//2):
        if A[2*i]!=2*i+1 or A[2*i+1]!=2*i+1:
            print(0)
            quit()
    print(2**(N//2)%INF)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
 
A.sort(reverse=True)
 
if N % 2 == 1:
    if A[-1] == 0:
        A.pop()
    else:
        print(0)
        quit()
 
for i in range(0, N - 2, 2):
    if A[i] != N - i - 1 or A[i] != A[i + 1]:
        print(0)
        quit()
 
print(2 ** (N // 2) % (10 ** 9 + 7))

Submission status: Accepted

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

A.sort(reverse=True)

if N % 2 == 1:
    if A[-1] == 0:
        A.pop()
    else:
        print(0)
        quit()

for i in range(0, N - 2, 2):
    if A[i] != N - i - 1 or A[i] != A[i + 1]:
        print(0)
        quit()

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

Submission status: Accepted

Solution code:
def A_validation(A, N):
    '''
    input
    A, N: abs_list, population
    output
    True/False: can you line up?
    '''
    A = sorted(A)
    num = N - 1
    
    if N % 2 == 0:
        while A:
            tmp1 = A.pop()
            tmp2 = A.pop()
            if tmp1 != tmp2 or tmp1 != num:
                return False
            num = num - 2
        return True
    
    else:
        if A.pop(0) != 0:
            return False
        while A:
            tmp1 = A.pop()
            tmp2 = A.pop()
            if tmp1 != tmp2 or tmp1 != num:
                return False
            num = num - 2
        return True

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

mod = 1000000007
if A_validation(A, N):
    ans = 2 ** (N // 2) % mod
else:
    ans = 0
print(ans)

Submission status: Accepted

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

from collections import Counter

def solve(N, A):
    flag = False
    A_counter = Counter(A)

    if(N%2==1):
        if(A_counter[0]==1 and all(A_counter[i]==2 for i in range(2, N, 2))):
            flag = True
    else:
        if(all(A_counter[i]==2 for i in range(1, N, 2))):
            flag = True
    
    print(pow(2, N//2, 10**9+7) if flag else 0)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def judge_lie(n): return sum([abs(n + 1 -2*i) for i in range(1, n+1)])
n = int(input())
import sys
a = list(map(int,sys.stdin.readline().split()))
if sum(a) != judge_lie(n):
    print(0)
else:
    print((2 ** (n//2) % (10 ** 9 + 7)))

Submission status: Accepted

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

cnt = dict()

for i in range(n):
    cnt[i] = 0
for d in dat:
    cnt[d]+=1

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
a = sorted(a)
MOD = 10 ** 9 + 7
if N % 2 == 0:
    b = [i for i in range(N - 1, 0, -2)] * 2
    b = sorted(b)
else:
    b = [i for i in range(N - 1, 0, -2)] * 2 + [0]
    b = sorted(b)

if a == b:
    print(2 ** (N // 2) % MOD)
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
if N % 2 == 0:
    B = [i for i in range(1, N, 2)]
    B = B + B
    B = sorted(B)
else:
    B = [i for i in range(2, N, 2)]
    B = B + [0] + B
    B = sorted(B)

if A != B:
    print(0)
else:
    print(2 ** (len(B) // 2) % (10 ** 9 + 7))

Submission status: Accepted

Solution code:
from collections import Counter


N = int(input())
lstA = list(map(int, input().split()))
mod = 10**9 + 7
countA = Counter(lstA)
ans = 0

if N % 2:
    if countA[0] == 1 and all(countA[i] == 2 for i in range(2, N, 2)):
        ans = 2**(N//2) % mod
else:
    if all(countA[i] == 2 for i in range(1, N, 2)):
        ans = 2**(N//2) % mod


print(ans)

Submission status: Accepted

Solution code:
from collections import Counter


N = int(input())
lstA = list(map(int, input().split()))
mod = 10**9 + 7
countA = Counter(lstA)
ans = 0

if N % 2:
    if countA[0] == 1 and all(countA[i] == 2 for i in range(2, N, 2)):
        ans = pow(2, N//2) % mod
else:
    if all(countA[i] == 2 for i in range(1, N, 2)):
        ans = pow(2, N//2) % mod


print(ans)

Submission status: Accepted

Solution code:
from collections import Counter


N = int(input())
lstA = list(map(int, input().split()))
mod = 10**9 + 7
countA = Counter(lstA)
ans = 0

if N % 2:
    if countA[0] == 1 and all(countA[i] == 2 for i in range(2, N, 2)):
        ans = pow(2, N//2, mod)
else:
    if all(countA[i] == 2 for i in range(1, N, 2)):
        ans = pow(2, N//2, mod)


print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
from collections import Counter
C = Counter(a)
if n%2==0 and not a.count(0)==0:
    print(0)
    exit()
elif n%2==1 and not a.count(0)==1:
    print(0)
    exit()
for c in set(a):
    if not c==0 and not C[c]==2:
        print(0)
        exit()
print(2**(n//2)%(10**9+7))

Submission status: Accepted

Solution code:
n=int(input())
#ne,[7,5,3,1,1,3,5,7]8
#no,[8,6,4,2,0,2,4,6,8]9
m=[0]*n
for i in map(int,input().split()):
  m[i]+=1
ans=1
for i in range(n-1,0,-2):
  if m[i]!=2:
    ans=0
if m[0]!=n%2:
  ans=0
if ans:
  print(2**(n//2)%1000000007)
else:
  print(0)

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
A = list(map(int, input().split()))
MOD = 1000000007

ndict = defaultdict(int)

for n in A:
  ndict[n] += 1

count = 1

for k, v in ndict.items():
  if v == 1 and k != 0:
    count = 0
    break
  else:
    count *= v
    count %= MOD

print(count)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = True
mod = 10 ** 9 + 7
for i,j in enumerate(a):
  if n % 2:
    if j != ((i+1) // 2) * 2:
      b = False
      break
  else:
    if j != (i // 2) * 2 + 1:
      b = False
      break
if b == True:
  print(pow(2,n//2,mod))
else:
  print(0)

Submission status: Accepted

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

people_num = int(input())
line_list = list(map(int, input().split()))

num_odd = True
bool_false = True

line_list.sort()

if(people_num%2 == 0):
    num_odd = False

for i in range(people_num):

    if(num_odd):
        if(line_list[i] == 2*((i+1)//2)):
            continue
        else:
            bool_false = False
            break
    else:
        if(line_list[i] == 2*(i//2) +1):
            continue
        else:
            bool_false = False
            break

if(people_num == 1):
    print(1)
elif(bool_false):
    print((2**(people_num // 2) % (10**9 +7)))
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A1 = {}
judge = 1

if(N%2 == 1):
  for i in range(N):
    if(A[i] in A1): A1[A[i]] += 1
    else: A1[A[i]] = 1
  count = -1
  for k, v in sorted(A1.items()):
    count += 1
    if(count == 0):
      if((k == 0)and(v == 1)):
        continue
      else: 
        judge = 0
        break
    else:
      if((k == 2*count)and(v == 2)):
        continue
      else:
        judge = 0
        break
    
 
else:
  for i in range(N):
    if(A[i] in A1): A1[A[i]] += 1
    else: A1[A[i]] = 1
  count = -1
  for k, v in sorted(A1.items()):
    count += 1
    if((k == 2*count+1)and(v == 2)):
       continue
    else:
        judge = 0
        break
    count += 1

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter
sys.setrecursionlimit(10**7)
mo=10**9+7
n=10**5

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

ans=pow(2,(n//2),mo)
for i in range(n):
    if a[i]!=b[i]:
        ans=0
#print(a,b)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())))
B = []


mod = 10**9+7
if N % 2 == 0:
    for i in range(1,N,2):
        B.append(i)
        B.append(i)
    for i in range(N):
        if A[i] != B[i]:
            print(0)
            exit()

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

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

Submission status: Accepted

Solution code:
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n = ni()
a = nl()

c = collections.Counter(a)
mod = 10 ** 9 + 7

val = list(c.values())
key = list(c.keys())
check = len(a) % 2
if check == 1:
    if val.count(1) != 1:
        print(0)
        exit()
    if key[val.index(1)] != 0:
        print(0)
        exit()
    else:
        if val.count(2) != len(val) - 1:
            print(0)
            exit()
        else:
            print(2 ** (val.count(2)) % mod)
else:
    if val.count(2) != len(val):
        print(0)
        exit()
    else:
        print(2 ** (len(val)) % mod)

Submission status: Accepted

Solution code:
import collections
mod=10**9+7
p=int(input())
a=[int(i) for i in input().split()]
diff=collections.Counter(a)
def modpower(n):
    ret=1
    for k in range(n):
        ret=(2*ret)%mod
    return(ret)
if p==1:#one
    ans=1-bool(a[0])
elif p%2:#odd
    if all([diff[i]==2 for i in range(2,p,2)]) and diff[0]==1:
        ans=modpower(p//2)
    else:ans=0
else:#even
    if all([diff[i]==2 for i in range(1,p+1,2)]):
        ans=modpower(p//2)
    else:ans=0
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
A=sorted(list(map(int,input().split(' '))))
if N%2==1:
	B=[ ((i+1)//2)*2 for i in range(N) ]
	C=[ 0 if A[i]==B[i] else 1 for i in range(N) ]
	flag=True if sum(C)==0 else False
elif N%2==0:
	B=[ (i//2)*2+1 for i in range(N) ]
	C=[ 0 if A[i]==B[i] else 1 for i in range(N) ]
	flag=True if sum(C)==0 else False
print((2**(N//2))%(10**9+7)) if flag else print(0)

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys

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

counts = defaultdict(int)
mod = N % 2

for a in A:
    if a % 2 == mod:
        print(0)
        sys.exit()
    counts[a] += 1
    if a == 0 and counts[a] > 1:
        print(0)
        sys.exit()
    if a > 0 and counts[a] > 2:
        print(0)
        sys.exit()

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

Submission status: Accepted

Solution code:
N=int(input())

mp=[0 for i in range(N)]
for a in input().split():
    mp[int(a)]+=1

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
count = [0 for _ in range(N+1)]

if N % 2 == 0:
    if len(set(A)) != int(N/2):
        print(0)
        exit()
else:
    if len(set(A)) != int(N/2)+1:
        print(0)
        exit()

for i in A:
    count[i] += 1

#print(count)

res = 1
for i in range(N+1):
    if count[i] == 2:
        res *= 2
    else:
        if count[i] != 0:
            if N % 2 == 1 and i != 0: 
                print(0)
                exit()

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

Submission status: Accepted

Solution code:
import math

N = int(input())
A = [int(_) for _ in input().split()]
A = sorted(A)
List = []

if N % 2 == 0:
    for i in range(N):
        List.append(i//2 * 2 + 1)
else:
    for i in range(N):
        List.append(math.ceil(i/2) * 2)

if A != List:
    print(0)
else:
    print(2**(N//2) % (10**9+7))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    N = II()
    A = LI()
    from collections import Counter
    cnt = Counter(A)
    if N % 2 and cnt[0] < 0:
        return 0
    for i in range(N % 2 + 1, N, 2):
        if cnt[i] != 2:
            return 0
    ans = (2 ** (N // 2)) % MOD

    return ans

print(main())