Problem:


Score : 300 points

Problem Statement

There are N people, conveniently numbered 1 through N.
They were standing in a row yesterday, but now they are unsure of the order in which they were standing.
However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person.
According to their reports, the difference above for person i is A_i.

Based on these reports, find the number of the possible orders in which they were standing.
Since it can be extremely large, print the answer modulo 10^9+7.
Note that the reports may be incorrect and thus there may be no consistent order.
In such a case, print 0.

Constraints

1≦N≦10^5

0≦A_i≦N-1

Input

The input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the number of the possible orders in which they were standing, modulo 10^9+7.

Sample Input 1

5
2 4 4 0 2

Sample Output 1

4

There are four possible orders, as follows:

2,1,4,5,3

2,5,4,1,3

3,1,4,5,2

3,5,4,1,2

Sample Input 2

7
6 4 0 2 4 0 2

Sample Output 2

0

Any order would be inconsistent with the reports, thus the answer is 0.

Sample Input 3

8
7 5 1 1 7 3 5 3

Sample Output 3

16



Sample input:
5
2 4 4 0 2


Sample output:
4

Submission status: Wrong Answer

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


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


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

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

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

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

Submission status: Wrong Answer

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


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


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

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

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

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

Submission status: Wrong Answer

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


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


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

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

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

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
n = int(input())
a = list(map(int,input().split()))

b = Counter(a)

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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


def solve():
    if not validate():
        return 0
    return 2 ** (N//2)


print(solve())

Submission status: Wrong Answer

Solution code:
import math
import collections

N = int(input())
A_lis = list(input().split())
r = 10 ** 9 + 7
count = 2 ** (int(math.floor(N/2)))
B = collections.Counter(A_lis)

for i in range(N):
    if N % 2 == i % 2:
        if B[str(i)] != 0:
            count = 0
            break
        else:
            continue
    else:
        if i == 0:
            if B[str(i)] == 1:
                continue
            else:
                count = 0
                break
        elif B[str(i)] != 2:
            count = 0
            break
        else:
            continue
        
print(count)

Submission status: Wrong Answer

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

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


resolve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

print(check())

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
mod = 10 ** 9 + 7
ans = 0
n = int(input())
A = list(map(int, input().split()))
c = Counter(A).most_common()
val, cnt = zip(*c)
val = sorted(list(val))
cnt = sorted(list(cnt))
if n % 2 == 0:
    if cnt == [2] * (n // 2) and val == [i for i in range(n) if i % 2 != 0]:
        ans = (n // 2) ** 2
else:
    if cnt.count(0) == 1 and cnt == [1] + [2] * (n // 2) and val == [i for i in range(n) if i % 2 == 0]:
        ans = (n // 2) ** 2
print(ans % mod)

Submission status: Wrong Answer

Solution code:
from collections import Counter
mod = 10 ** 9 + 7
ans = 0
n = int(input())
A = list(map(int, input().split()))
c = Counter(A).most_common()
val, cnt = zip(*c)
val = sorted(list(val))
cnt = sorted(list(cnt))
if n % 2 == 0:
    if cnt == [2] * (n // 2) and val == [i for i in range(n) if i % 2 != 0]:
        ans = (n // 2) ** 2
else:
    if cnt == [1] + [2] * (n // 2) and val == [i for i in range(n) if i % 2 == 0]:
        ans = (n // 2) ** 2
print(ans % mod)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

    if cnt[a] == 0:
        cnt[a] = 1
    elif cnt[a] == 1:
        ans = ans * 2 % mod
    else:
        ans = 0
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

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

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

print(2**(N//2))

Submission status: Wrong Answer

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


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


def S(): return input()


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


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


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


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


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


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


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


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


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


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

show_flg = False
# show_flg = True


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

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

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

    if N % 2 == 1:
        print(2 ** ((N - 1) // 2))
    else:
        print(2 ** (N // 2))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


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


def S(): return input()


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


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


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


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


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


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


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


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


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


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

show_flg = False
# show_flg = True


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

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

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

    if N % 2 == 1:
        print(2 ** ((N - 1) // 2))
    else:
        print(2 ** (N // 2))



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
c = a.count(0)
    
if(n%2 == 1):
    if(c != 1):
        print(0)
        exit()
else:
    if(c != 0):
        print(0)
        exit()
        
m = 1000000007
p = n//2
ans = 1
for _ in range(0,p):
    ans = 2*ans % m
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
l = input().split(" ")
l1=defaultdict(int)
for i in range(len(l)):
    l[i]=int(l[i])
    l1[l[i]]+=1
if l1[0]>=1 and n%2==0:
    print(0)
elif l1[0]>1 and n%2==1:
    print(0)
else:
    prod=1
    for key in l1.keys():
        if key%2==1 and key!=0:
            print(0)
            exit()
        if(key!=0):    
            prod*=l1[key]
        
    print(prod%(1000000000+7))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
l = input().split(" ")
l1=defaultdict(int)
for i in range(len(l)):
    l[i]=int(l[i])
    l1[l[i]]+=1
if l1[0]>=1 and n%2==0:
    print(0)
elif l1[0]>1 and n%2==1:
    print(0)
else:
    prod=1
    for key in l1.keys():
        if key%2==1:
            print(0)
            exit()
        prod*=l1[key]
        
    print(prod%(1000000000+7))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
l = input().split(" ")
l1=defaultdict(int)
for i in range(len(l)):
    l[i]=int(l[i])
    l1[l[i]]+=1
if l1[0]>=1 and n%2==0:
    print(0)
elif l1[0]>1 and n%2==1:
    print(0)
else:
    prod=1
    for key in l1.keys():
        if key!=0:
            prod*=l1[key]
    print(prod%(1000000000+7))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
l = input().split(" ")
l1=defaultdict(int)
for i in range(len(l)):
    l[i]=int(l[i])
    l1[l[i]]+=1
if l1[0]>=1 and n%2==0:
    print(0)
elif l1[0]>1 and n%2==1:
    print(0)
else:
    prod=1
    for key in l1.keys():
        prod*=l1[key]
    print(prod%(1000000000+7))

Submission status: Wrong Answer

Solution code:
import math
n=input()
mod = int(1e9) + 7
a=list(map(int,raw_input().split()))
if(len(a)%2==0 and a.count(0)>0):
    print(0)
elif(len(a)%2!=0 and a.count(0)>1):
    print(0)
else:    
    res=0
    b=set(a)
    if(a.count(0)):
        print(pow(2,len(b)-1,mod))
    else:
        print(pow(2,len(b),mod))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()

s_list = []

for item in s:
    if item == '.':
        s_list.append(0)
    else:
        s_list.append(1)

min_val = s_list.count(0)

left_val = 0
right_val = s_list.count(0)

for i in range(len(s_list)):
    if s_list[i] == 0:
        right_val -= 1
        min_val = min(left_val + right_val, min_val)
    else:
        left_val += 1

print(min_val)

Submission status: Wrong Answer

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

from collections import Counter
ca = Counter(a)
d = n % 2
if d == 1:
    z = ca.pop(0) if 0 in ca else 0
    if z != 1:
        print(0)
        exit()

for i in range(1 + d, n + d, 2):
    if ca[i] != 2:
        print(0)
        exit()

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
Alist = list(map(int, input().split()))
Ac = Counter(Alist)
flg = True
if N%2==0:
    for i in range(1, N, 2):
        if Ac[i] != 2:
            print(0)
            break
    else:
        print(2**(N//2))
else:
    if Ac[0] != 1:
        print(0)
    else:
        for i in range(2, N, 2):
            if Ac[i] != 2:
                print(0)
                break
        else:
            print(2**(N//2))

Submission status: Wrong Answer

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

if n%2:
    a = a[1:]

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

from collections import Counter

Acnt = Counter(A)
Acnt = sorted(Acnt.items(), key=lambda x:x[0])

if N % 2 == 0:
    ans = 1
    num = 1
    for key,cnt in Acnt:
        if cnt != 2:
            print(0)
            exit()
        if key != num:
            print(0)
            exit()
        num += 2
        ans *= 2
    print(ans)
else:
    ans = 1
    num = 0
    for key,cnt in Acnt:
        if cnt != 2:
            if key != 0:
                print(0)
                exit()
            else:
                num += 2
                continue
        if key != num:
            print(0)
            exit()
        num += 2
        ans *= 2
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

from collections import Counter

Acnt = Counter(A)
Acnt = sorted(Acnt.items(), key=lambda x:x[0])

ans = 1
if N % 2 == 0:
    num = 1
    for key,cnt in Acnt:
        if cnt != 2:
            print(0)
            exit()
        if key != num:
            print(0)
            exit()
        num += 2
        ans *= 2
else:
    num = 0
    for key,cnt in Acnt:
        if cnt != 2:
            if key != 0:
                print(0)
                exit()
            else:
                num += 2
                continue
        if key != num:
            print(0)
            exit()
        num += 2
        ans *= 2

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N=int(input())
    A=list(map(int,input().split()))
    t={}
    flag=True
    for i in range(N):
        if str(A[i]) not in t:
            t[str(A[i])]=1
        elif t[str(A[i])]==1:
            t[str(A[i])]=2
        elif t[str(A[i])]==2:
            flag=False
            break
    if flag==False:
        print(0)
    if flag and N%2==1:
        if t["0"]!=1:
            print(0)
            flag=False
        if flag:
            count_zero=0
            for v in t.values():
                if v==1:
                    count_zero+=1
                    if count_zero>=2:
                        print(0)
                        flag=False
                        break
        if flag:
            print(2**(N//2))

    elif flag and N%2==0:
        for v in t.values():
            if v==1:
                print(0)
                flag=False
                break
        if flag:
            print(2**(N//2))
    
if __name__=="__main__":
    main()

Submission status: Wrong Answer

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

from itertools import groupby

gr = groupby(A)

ans = 1
if N % 2 == 0:
    for _,group in gr:
        if len(tuple(group)) != 2:
            print(0)
            exit()
        else:
            ans *= 2
else:
    for key,group in gr:
        if len(tuple(group)) != 2:
            if key == 0 and len(tuple(group)) == 1:
                continue
            else:
                print(0)
                exit()
        else:
            ans *= 2

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N=int(input())
    A=list(map(int,input().split()))
    t={}
    flag=True
    for i in range(N):
        if str(A[i]) not in t:
            t[str(A[i])]=1
        elif t[str(A[i])]==1:
            t[str(A[i])]=2
        elif t[str(A[i])]==2:
            flag=False
            break
    if flag==False:
        print(0)
    if flag and N%2==1:
        if t["0"]!=1:
            print(0)
            flag=False
        if flag:
            count_zero=0
            for v in t.values():
                if v==1:
                    count_zero+=1
                    if count_zero>=2:
                        print(0)
                        flag=False
                        break
        if flag:
            print((N//2)**2)

    elif flag and N%2==0:
        for v in t.values():
            if v==1:
                print(0)
                flag=False
                break
        if flag:
            print((N//2)**2)
    
if __name__=="__main__":
    main()

Submission status: Wrong Answer

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

from itertools import groupby

gr = groupby(A)

ans = 1
if N % 2 == 0:
    for _,group in gr:
        if len(tuple(group)) != 2:
            print(0)
            exit()
        else:
            ans *= 2
else:
    for key,group in gr:
        if len(tuple(group)) != 2:
            if key == 0:
                continue
            else:
                print(0)
                exit()
        else:
            ans *= 2

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr0=limii()

arr=Counter(arr0)

ai=list(arr.items())
ai.sort()
if n%2==0:
    cnt=0
    for p,i in enumerate(range(1,n,2)):

        if ai[p][0]==i and ai[p][1]==2:
            cnt+=1
    if cnt==n//2:
        print(2**(n//2))
    else:
        print(0)
else:
    cnt=0
    for p,i in enumerate(range(0,n,2)):
        if p==0:
            if ai[p][0]==i and ai[p][1]==1:
                cnt+=1
        else:        
            if ai[p][0]==i and ai[p][1]==2:
                cnt+=1
    if (n+1)//2==cnt:
        print(2**(cnt-1))
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr0=limii()

arr=Counter(arr0)

ai=list(arr.items())
ai.sort()

if n%2==0:
    cnt=0
    for p,i in enumerate(range(1,n,2)):
        if ai[p][0]==i and ai[p][1]==2:
            cnt+=1
    if cnt==n//2:
        print(2**(n//2))
    else:
        print(0)
else:
    cnt=0
    for p,i in enumerate(range(0,n,2)):
        if ai[p][0]==i and ai[p][1]==2:
            cnt+=1
    if (n+1)//2==cnt:
        print(2**cnt)
    else:
        print(0)