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 math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l.sort()

  if n%2==0:
    for i in range(n):
      if (i//2)*2+1!=l[i]:
        return 0
    return pow(2,n//2)%mod

  else:
    if l[0]!=0:
      return 0
    l.remove(0)
    for i in range(n-1):
      if (i//2)*2+2!=l[i]:
        return 0
    return pow(2,n//2)%mod

print(main())

Submission status: Accepted

Solution code:
a=1000000007
n=int(input())
l=list(map(int,input().split()))
l.sort()
if n%2==1:
  if l[0]!=0:
    print(0)
    exit()
  else:
    l.remove(0)
    sh=2
    f=0
    for i in l:
      if f==0:
        if i!=sh:
          print(0)
          exit()
        else:
          f=1
      else:
        if i!=sh:
          print(0)
          exit()
        else:
          sh+=2
          f=0
  sh=(n-1)//2
  b=1
  for i in range(sh):
    b*=2
    b%=a
  print(b)
else:
  sh=1
  f=0
  for i in l:
    if f==0:
      if i!=sh:
        print(0)
        exit()
      else:
        f=1
    else:
      if i!=sh:
        print(0)
        exit()
      else:
        sh+=2
        f=0
  sh=n//2
  b=1
  for i in range(sh):
    b*=2
    b%=a
  print(b)

Submission status: Accepted

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

A.sort()
flag = True

if N%2==1:
    b=[0]
    for i in range(1, N):
        c=i
        if i%2==1:
            c += 1
        b.append(c)
    if A != b:
        print(0)
    else:
        if N==1:
            print(1)
        else:
            ans = 2
            for i in range((N-1)//2-1):
                ans *= 2
                ans = ans % (10**9+7)
            print(ans)
    
else:
    d=[]
    for i in range(N):
        e=i
        if i%2==0:
            e += 1
        d.append(e)
    
    if A != d:
        print(0)
    else:
        ans = 2
        for i in range(N//2-1):
            ans *= 2
            ans = ans % (10**9+7)
        print(ans)

Submission status: Accepted

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



MOD = 1000000007
def solve_odd(an):
  l = len(an)
  dif = (l+1)%2
  # False pattern
  for i in range(l):
    if math.ceil((i+dif)/2)*2 != an[i]+dif:
      return 0
  ans = 1  
  # True pattern
  for _ in range(l//2):
    ans = (ans*2) % MOD
  return ans


N = int(input())
An = list(map(int, input().split()))
An = sorted(An)
print(solve_odd(An))

Submission status: Accepted

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


# 最初(N//2)**2にしていた、それぞれの場合の数ではなくなってしまう
print((2**(N // 2))%(10**9+7))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
N, *A = map(int, open(0).read().split())
l = [v for _, v in sorted(Counter(A).items())]
if all(v == 2 for v in l[N % 2:]) and (N % 2 == 0 or l[0] == 1):
    print(2 ** (N // 2) % (10 ** 9 + 7))
else:
    print(0)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
A = Counter(map(int, input().split()))
A[0] = 2
mod = 10 ** 9 + 7


def n_power_m_mod(n, m, mod):
    ret = 1
    for _ in range(m):
        ret *= n
        ret %= mod
    return ret


if all(v == 2 for v in A.values()):
    print(n_power_m_mod(2, n//2, mod))
else:
    print(0)

Submission status: Accepted

Solution code:
from collections import defaultdict


def is_valid(xs):
    d = defaultdict(lambda: 0)
    for x in xs:
        d[x] += 1

    if len(xs) % 2 == 0:
        for v in range(1, len(xs), 2):
            if d[v] != 2:
                return False
    else:
        if d[0] != 1:
            return False
        for v in range(2, len(xs), 2):
            if d[v] != 2:
                return False

    return True


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

if is_valid(xs):
    print(2 ** (n // 2) % 1000000007)
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = 0
flag = True
if N % 2 == 1:
  # 奇数個の場合、0,2,2,4,4,～みたいに並んでるはず
  if A[0] == 0:
    for i in range(1, N, 2):
      if A[i] != i+1 or A[i+1] != i+1:
        flag = False
        break
    if flag:
      ans = 2**(N//2) % (10**9+7)
else:  
  # 偶数個の場合、1,1,3,3,5,5,～のように並んでるはず
  if A[0] != 0:
    for i in range(0, N, 2):
      if A[i] != i+1 or A[i+1] != i+1:
        flag = False
        break
    if flag:
      ans = 2**(N//2) % (10**9+7)
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 ai in a:
    d[ai] += 1
ans = 1
if n % 2:
    for k, v in d.items():
        if k > 0 and v == 2:
            ans *= 2
        elif k == 0 and v == 1:
            ans *= 1
        else:
            ans = 0
            break
        ans = ans % MOD
else:
    for v in d.values():
        if v == 2:
            ans *= 2
        else:
            ans = 0
            break
        ans = ans % MOD
print(ans)

Submission status: Accepted

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

MOD = 10 ** 9 + 7

ex = []
if N % 2 == 1:
    ex.append(0)
    for i in range(1, N//2 + 1):
        ex.append(i*2)
        ex.append(i*2)
    ans = 2 ** (N//2)
    ans %= MOD
else:
    for i in range(N//2):
        ex.append(i*2 + 1)
        ex.append(i*2 + 1)
    ans = 2 ** (N//2)
    ans %= MOD

A.sort()
if A != ex:
    ans = 0


print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A=sorted(map(int,input().split()))
mod=10**9+7
cnt = [0]*N
for a in A:
    if (1+a+N)%2:
        print(0)
        break
    cnt[a]+=1
    if cnt[a]>2:
        print(0)
        break
else:
    if cnt[0]>1:
        print(0)
    elif cnt[1:].count(1)>1:
        print(0)
    else:
        ans = 1
        for _ in range(N//2): ans=(ans*2)%mod
        print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

c = defaultdict(int)
for a in A:
    c[a] += 1

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = 0
flag = True
if N % 2 == 1:
  # 奇数個の場合、0,2,2,4,4,～みたいに並んでるはず
  if A[0] == 0:
    for i in range(1,N,2):
      if A[i] != i+1 or A[i+1] != i+1:
        flag = False
        break
    if flag: ans = 2**(N//2) % (10**9 + 7)

else:
  # 偶数個の場合、1,1,3,3,5,5,～のように並んでるはず
  if A[0] != 0:
    for i in range(0,N,2):
      if A[i] != i+1 or A[i+1] != i+1:
        flag = False
        break
    if flag: ans = 2**(N//2) % (10**9 + 7)
    
print(ans)

Submission status: Accepted

Solution code:
import math
N = int(input())


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

A.sort()
ans = 0
flag = True
if N % 2 == 1:
  # 0,2,2,4,4,～みたいに並んでるはず
  if A[0] == 0:
    for i in range(1,N,2):
      if A[i] != i+1 or A[i+1] != i+1:
        flag = False
        break
  
    if flag: ans = 2**(N//2) % (10**9 + 7)

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

Submission status: Accepted

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

if N % 2 == 1:
    if A.count(0) != 1:
        print(0)
        quit()

c = {}
for e in A:
    if e == 0:
        continue
    if e in c.keys():
        c[e] += 1
    else:
        c[e] = 1
if all([x == 2 for x in c.values()]):
    print(2**(N//2)%(10**9+7))
else:
    print(0)

Submission status: Accepted

Solution code:
def main():
	N = int(input())
	A = list(map(int, input().split()))
	DIV = 10**9+7
	ans = 0
	lie = False
	count = [0]*N
	odd = N % 2 == 1
	for i in range(N):
		if A[i] > N-1:
			lie = True
			break
		if (A[i]%2 == 0) ^ odd:
			lie = True
			break
		count[A[i]] += 1
		if count[A[i]] > 2:
			lie = True
			break

	if odd and count[0] != 1:
		lie = True
	if not(odd) and count[0] > 0:
		lie = True

	if lie:
		print(0)
	else:
		print((2**(N//2))%DIV)


if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
n = int(input())
odd = n % 2 == 1

if sorted(list(input().split())) == ["0"] * odd + sorted([str(i) for i in range(1 + odd, n, 2)] * 2):
    cnt = 1
    for i in range(n//2):
        cnt *= 2
        cnt = cnt % (10 ** 9 + 7)
    print(cnt)
else:
    print(0)

Submission status: Accepted

Solution code:


def read_input():
    n = int(input())
    alist = list(map(int, input().split()))

    return n, alist


def possibility_check(n, alist):
    alist.sort()

    if n % 2:
        even = [x for x in range(2, n) if x % 2 == 0]
        comp = [0] + even + even
        comp.sort()

    else:
        odd = [x for x in range(1, n) if x % 2 == 1]
        comp = odd + odd
        comp.sort()

    if alist == comp:
        return True
    else:
        return False


def submit():
    n, alist = read_input()

    if possibility_check(n, alist):
        # ans = (2 ** (n // 2)) % (10**9 + 7)
        ans = 1
        for i in range(n // 2):
            ans *= 2
            if ans > 10**9 + 7:
                ans %= (10**9 + 7)
        print(ans)
    else:
        print(0)


if __name__ == '__main__':
    submit()

Submission status: Accepted

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

if n%2==0:
    if sorted(a) != [(k//2)*2+1 for k in range(n)]:
        print(0)
    else:
        ans = 2**(n//2)
        print(ans % (10**9+7))
else:
    if sorted(a)!= [0]+[(k//2+1)*2 for k in range(n-1)]:
        print(0)
    else:
        ans = 2**(n//2)
        print(ans % (10**9+7))

Submission status: Accepted

Solution code:
from collections import Counter

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

flg = 0
if N % 2:
    if c[0] != 1:
        flg = 1
    else:
        for i in range(2, N, 2):
            if c[i] != 2:
                flg = 1
                break
else:
    for i in range(1, N, 2):
        if c[i] != 2:
            flg = 1
            break

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = sorted(Counter(list(map(int, input().split()))).items(), key=lambda x: x[0])
if len(A) != (N + 1) // 2:
    print(0)
    exit()
if N % 2 == 1:
    if A[0][0] != 0 or A[0][1] != 1:
        print(0)
        exit()
    for (a, n), i in zip(A[1:], range(2, N + 1, 2)):
        if a != i or n != 2:
            print(0)
            exit()
else:
    for (a, n), i in zip(A, range(1, N + 1, 2)):
        if a != i or n != 2:
            print(0)
            exit()
print(2 ** (N // 2) % (10 ** 9 + 7))

Submission status: Accepted

Solution code:
MOD = 10**9 + 7
from collections import Counter
n = int(input())
a = [int(item) for item in input().split()]
cnt = Counter(a)

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

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))

    MOD = 10**9 + 7
    d = defaultdict(lambda: 0)
    for a in A:
        d[a] += 1
        if d[a] >= 3:
            return 0

    if not (d[0] == 0 or d[0] == 1):
        return 0

    cnt = 0
    A = set(A)
    for a in A:
        if a == 0:
            continue

        if d[a] != 2:
            return 0
        else:
            cnt += 1

    return (2**cnt) % MOD


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

Submission status: Accepted

Solution code:
n=int(input())
A=[int(i) for i in input().split()]
B=[]
if n%2==0:
  for i in range(n//2):
    B.append(2*i+1)
    B.append(2*i+1)
  print(pow(2,n//2,10**9+7) if B==sorted(A) else 0)
else:
  B=[0]
  for i in range((n-1)//2):
    B.append(2*(i+1))
    B.append(2*(i+1))
  print(pow(2,(n-1)//2,10**9+7) if B==sorted(A) else 0)

Submission status: Accepted

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

if N % 2: 
    T = [int(i+1) //2 * 2 for i in range(N)]
    if sorted(A) == T:
        print (2**(N//2) % (10 ** 9 + 7))
    else: 
        print(0)
        
else: 
    T = [int(i // 2 * 2 + 1)  for i in range(N)]
    if sorted(A) == T:
        print (2**(N//2) % (10 ** 9 + 7))
    else: 
        print(0)

Submission status: Accepted

Solution code:
import collections
import sys
l = int(input())
inputs = [int(j) for j in input().split(' ')]
cs = collections.Counter(inputs)
if l % 2 == 0:
  for v,c in cs.items():
    if v % 2 == 0 or c != 2:
      print(0)
      sys.exit()
else:
  for v,c in cs.items():
    if v % 2 != 0 or (c != 2 and v != 0):
      print(0)
      sys.exit()
print(2**int(l/2)%(10**9+7))

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

dic = {}
def power(x, y):
   if y == 0:
       return 1
   elif y == 1:
       return x % mod
   elif y % 2 == 0:
       return power(x, y/2) ** 2 % mod
   else:
       return power(x, (y-1)/2) ** 2 * x % mod

for i in range(N):
	if not A[i] in dic:
		dic[A[i]] = 1
	else:
		dic[A[i]] += 1

if N%2 == 0: # 偶数の時
	for i in range(N//2):
		if N-1-2*i not in dic:
			print(0)
			break
		elif dic[N-1-2*i] != 2:
			print(0)
			break
		else:
			pass
	else:
		print(power(2,(N//2)))
else: # 奇数の時
	if A.count(0) != 1:
		print(0)
	else:
		for i in range(N//2-1):
			if N-1-2*i not in dic:
				print(0)
				break
			elif dic[N-1-2*i] != 2:
				print(0)
				break
			else:
				pass
		else:
			print(power(2,(N//2)))

Submission status: Accepted

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

import itertools
count = 0
check = [int(abs((N-i+1)- i)) for i in range(1,N+1)]
flag = sorted(A) == sorted(check)
if flag:
    print(2 ** (N//2) % (10 ** 9 + 7))
else:
    print(0)

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
ans=0
if N%2!=0:
    c=list(Counter(A).items())
    c.sort(reverse=True)
    for a,b in c:
        if a!=0 and b==2:
            ans+=1
        elif a==0 and b==1:
            print(2**ans%(10**9+7))
        else:
            print(0)
            break
else:
    if A.count(0)>0:
        print(0)
    else:
        c=list(Counter(A).items())
        c.sort(reverse=True)
        for a,b in c:
            if a!=1 and b==2:
                ans+=1
            elif a==1 and b==2:
                ans+=1
                print(2**ans%(10**9+7))
            else:
                print(0)
                break

Submission status: Accepted

Solution code:

from collections import Counter
import sys
input = sys.stdin.readline

def main():
    MOD = 10**9 + 7
    N = int(input())
    A = list(map(int, input().split()))
    C = Counter(A)
    if N % 2:
        if C[0] != 1:
            return 0
        for key in C:
            if key == 0:
                continue
            if key % 2 or C[key] != 2:
                return 0
        ret = 1
        for i in range(N // 2):
            ret = ret * 2 % MOD
    else:
        for key in C:
            if key % 2 == 0 or C[key] != 2:
                return 0
    ret = 1
    for i in range(N // 2):
        ret = ret * 2 % MOD
    return ret

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

Submission status: Accepted

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

count = dict()
if N % 2:
	for a in A:
		if a % 2:
			print(0)
			exit()
		if a in count:
			count[a] += 1
		else:
			count[a] = 1
	if count[0] != 1:
		print(0)
		exit()
	del count[0]
	for c in count.values():
		if c != 2:
			print(0)
			exit()
else:
	for a in A:
		if not(a % 2):
			print(0)
			exit()
		if a in count:
			count[a] += 1
		else:
			count[a] = 1
	for c in count.values():
		if c != 2:
			print(0)
			exit()

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
from collections import Counter
MOD = 10**9+7
def is_ok(n, a_list):
    if N%2==0:
        # even
        c = Counter(a_list)
        for a in a_list:
            if a%2==0:
                return False
            elif c[a] != 2:
                return False
    else:
        # odd
        c = Counter(a_list)
        for a in a_list:
            if a%2==1:
                return False
            elif a == 0:
                if c[a]!=1:
                    return False
            elif c[a] != 2:
                return False
    
    return True


if (is_ok(N, A)):
    print((2**(N//2))%MOD if N%2==0 else (2**((N-1)//2))%MOD)
else:
    print(0)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
if n %2 == 0:
    s = [2]*(n//2)
else:
    s = [2]*(n//2+1)
    s[0] = 1
if n%2 == 0:
    for a in A:
        if s[(a-1)//2] >0:
            s[(a-1)//2] -= 1
        else:
            continue
    if sum(s)==0:
        print(2**(n//2)%(10**9+7))
    else:
        print(0)
else:
    for a in A:
        if s[a//2] >0:
            s[a//2] -= 1
        else:
            continue
    if sum(s) == 0:
        print(2**((n-1)//2)%(10**9+7))
    else:
        print(0)

Submission status: Accepted

Solution code:
import math


def mod_pow(a: int, n: int, mod: int)->int:
    ret = 1
    for _ in range(n):
        ret = (ret * a) % mod
    return ret


def lining_up(N: int, A: list)->int:
    pos = [0] * math.ceil(N / 2)

    for a in A:
        i = (N-a-1)//2
        pos[i] += 1

        if pos[i] > 2:
            return 0

    if N % 2 == 0 and any(p != 2 for p in pos):
        return 0
    if N % 2 == 1 and any(p != 2 for p in pos[:-1]) and pos[-1] != 1:
        return 0

    return mod_pow(2, N // 2, 10**9+7)


if __name__ == "__main__":
    N = int(input())
    A = [int(s) for s in input().split()]
    ans = lining_up(N, A)
    print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
import bisect

def main():
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10

    # mod用
    p=10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    

    N = int(input().rstrip())
    A = list(map(int, input().split()))
    # A = list(int(_) for _ in input().split())
    # A = list(input().split())
    A.sort()
    flag = False
    if A[0] == 0 and N%2 == 1:
        flag = True
        for i in range(N):
            if A[i] != (i + 1) // 2 * 2:
                flag = False
                break
    if A[0] == 1 and N%2 == 0:
        flag = True
        for i in range(N):
            if A[i] != i // 2 * 2 + 1:
                flag = False
                break
    if flag:
        print(2**(N//2) % p)
    else:
        print(0)
        
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from functools import reduce
import bisect

def main():
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10

    # mod用
    p=10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    

    N = int(input().rstrip())
    # A = list(map(int, input().split()))
    A = list(int(_) for _ in input().split())
    # A = list(input().split())
    A.sort()
    flag = False
    if A[0] == 0 and N%2 == 1:
        flag = True
        for i in range(N):
            if A[i] != (i + 1) // 2 * 2:
                flag = False
                break
    if A[0] == 1 and N%2 == 0:
        flag = True
        for i in range(N):
            if A[i] != i // 2 * 2 + 1:
                flag = False
                break
    if flag:
        print(2**(N//2) % p)
    else:
        print(0)
        
if __name__ == '__main__':
    main()

Submission status: Accepted

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

A.sort()
ok = False
if A[0] == 0 and N % 2 == 1:
    ok = True
    for i in range(N):
        if A[i] != (i + 1) // 2 * 2:
            ok = False
            break
elif A[0] == 1 and N % 2 == 0:
    ok = True
    for i in range(N):
        if A[i] != i // 2 * 2 + 1:
            ok = False

if ok:
    print(2 ** (N // 2) % MOD)
else:
    print(0)

Submission status: Accepted

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

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

a.sort()

can = True

if a[0] == 0:
    for i in range(1,n):
        if i % 2 != 1:
            if a[i] != i:
                can = False
                break
        else:
            if a[i] != i + 1:
                can = False
                break
    if can:
        print((2 ** int((n-1)/2))% (10 ** 9 + 7))
    else:
        print(0)
elif a[0] == 1:
    for i in range(0,n):
        if i % 2 != 1:
            if a[i] != i + 1:
                can = False
                break
        else:
            if a[i] != i:
                can = False
                break
    if can:
        print((2 ** int(n/2))% (10 ** 9 + 7))
    else:
        print(0)
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N = int(input())
alist = list(map(int,input().split()))
flg = True
if N == 1:
    if alist[0] == 0:
        print(1)
    else:
        print(0)
    sys.exit()
inf = 10 ** 9 + 7
alist.sort()
if N % 2 == 0:
    for i in range(N)[1::2]:
        if alist[i-1] != i or alist[i] != i:
            flg = False
            break
else:
    if alist[0] != 0:
        flg = False
    for i in range(N)[2::2]:
        if alist[i-1] != i or alist[i] != i:
            flg = False
            break
if flg:
    print((2 ** (N // 2)) %  inf)
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

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

if n % 2 == 1:
    num = 0
    for i, v in c:
        k = 2
        if i == 0:
            k = 1
        
        if (i, v) != (num, k):
            print(0)
            exit()
        num += 2
else:
    num = 1
    for i, v in c:
        if (i, v) != (num, 2):
            print(0)
            exit()
        num += 2
print(2 ** (n//2) % mod)

Submission status: Accepted

Solution code:
from collections import Counter
mod = 10**9+7
n = int(input())
a = list(map(int,input().split()))
c = Counter(a)
c = c.most_common()
c.sort()
if n % 2 == 1:
    if c[0] != (0, 1):
        print(0)
        exit()
        
    num = 2
    for i, v in c[1:]:
        if (i, v) != (num, 2):
            print(0)
            exit()
        num += 2
else:
    num = 1
    for i, v in c:
        if (i, v) != (num, 2):
            print(0)
            exit()
        num += 2
print(2 ** (n//2) % mod)

Submission status: Accepted

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

if n%2==0 and a[::2] == a[1::2]:
  print(2**(n//2) % (10**9+7))
elif n%2==1 and a[1::2] == a[2::2]:
  print(2**(n//2) % (10**9+7))
else:
  print(0)

Submission status: Accepted

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict, Counter
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def s_inpl(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
INF = float("inf")

N = int(input())
A = inpl()

ans_l = []
if N % 2 == 0:
    for i in range(1, N):
        if i % 2 == 1:
            ans_l.append(i)
            ans_l.append(i)
else:
    for i in range(1, N):
        if i % 2 == 0:
            ans_l.append(i)
            ans_l.append(i)
    ans_l.append(0)

A.sort()
ans_l.sort()

if A == ans_l:
    print((2**(N//2))%(1000000007))
else:
    print(0)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
mod=int(1e9+7)

memo={i:0 for i in range(n)}
for a in A:
  memo[a]=memo.get(a,0)+1

answer=1
if n%2:
  if memo[0]!=1:
    print(0)
    exit()
  for i in range(1, (n+1)//2):
    if memo[2*i]!=2:
      print(0)
      exit()
    else:
      answer = 2*answer %mod
elif not n%2:
  for i in range(n//2):
    if memo[2*i+1]!=2:
      print(0)
      exit()
    else:
      answer = 2*answer %mod
      
print(answer)

Submission status: Accepted

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

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 num in A:
    d[num] += 1
d[0] += 1

if all(d[i] == 2 for i in range((N + 1) % 2, N, 2)):
    print(2 ** (N // 2) % MOD)
else:
    print(0)